CUBRID Engine  latest
load_semantic_helper.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * load_semantic_helper.hpp - Helper class for building loaddb types
21  */
22 
23 #ifndef _LOAD_SEMANTIC_HELPER_HPP_
24 #define _LOAD_SEMANTIC_HELPER_HPP_
25 
26 #include "load_common.hpp"
27 #include "mem_block.hpp"
28 
29 #include <forward_list>
30 
31 namespace cubload
32 {
33  // Constants sizes
34  static const std::size_t STRING_POOL_SIZE = 1024;
35  static const std::size_t MAX_COPY_BUF_SIZE = 256;
36  static const std::size_t COPY_BUF_POOL_SIZE = 512;
37  static const std::size_t CONSTANT_POOL_SIZE = 1024;
38  static const std::size_t QUOTED_STR_BUF_POOL_SIZE = 512;
39  static const std::size_t MAX_QUOTED_STR_BUF_SIZE = 32 * 1024;
40 
41  /*
42  * cubload::semantic_helper
43  *
44  * description
45  * A helper class for building semantic types, see cubload::parser::semantic_type union for more details.
46  * The class contains ported functionality from old C lexer & grammar. Be aware that copy constructor and
47  * assignment operator are disable since class make use of buffers/pools which use almost 17 Megabytes of memory
48  *
49  * The class contains all legacy functions of the old C lexer & grammar implementation.
50  *
51  * TODO
52  * Normally all functionality from semantic_helper should be used only by grammar and not by both lexer & grammar,
53  * Since it is used now by both (legacy behaviour) it is included into driver. Later as improvement we can add a
54  * subclass of cubload::parser (see load_grammar.hpp) and move functionality of this class into parser subclass.
55  *
56  * how to use
57  * Interaction with semantic_helper class is done through an instance of driver e.g.
58  *
59  * cubload::driver driver;
60  * constant_type *null_const = driver.get_semantic_helper ()->make_constant (LDR_NULL, NULL);
61  */
63  {
64  public:
65  semantic_helper ();
66 
67  // Copy constructor (disabled).
68  semantic_helper (const semantic_helper &copy) = delete;
69 
70  // Copy assignment operator (disabled)
71  semantic_helper &operator= (const semantic_helper &other) = delete;
72 
73  // Destructor
75 
76  void append_char (char c);
79 
82  string_type *make_string_by_yytext (const char *text, int text_size);
83 
84  constant_type *make_constant (int type, void *val);
86  constant_type *make_monetary_constant (int currency_type, string_type *amount);
87 
88  void reset_after_line ();
89  void reset_after_batch ();
90 
91  bool in_instance_line ();
92  void set_in_instance_line (bool in_instance_line);
93 
94  private:
96 
97  std::size_t m_string_pool_idx;
99  std::forward_list<string_type *> m_string_list;
100 
101  // buffer pool for copying yytext and qstr_buffer
102  std::size_t m_copy_buf_pool_idx;
104 
105  // constant pool
106  std::size_t m_constant_pool_idx;
108  std::forward_list<constant_type *> m_constant_list;
109 
110  // quoted string buffer pool
112 
113  cubmem::extensible_block m_qstr_buf; // using when pool overflow
115  std::size_t m_qstr_buf_idx;
116 
118  std::size_t m_qstr_buf_pool_idx;
119 
120  /* private functions */
121  string_type *make_string (char *val, std::size_t size, bool need_free_val);
122  string_type *make_string_and_copy (const char *src, size_t str_size);
123 
124  void extend_quoted_string_buffer (size_t new_size);
125 
126  bool is_utf8_valid (string_type *str);
127  bool use_copy_buf_pool (std::size_t str_size);
128 
129  void clear ();
130 
131  // template private functions
132  template<typename T>
133  T *append_list (T *head, T *tail);
134  }; // class semantic_helper
135 }
136 
137 #endif /* _LOAD_SEMANTIC_HELPER_HPP_ */
static const std::size_t MAX_QUOTED_STR_BUF_SIZE
semantic_helper & operator=(const semantic_helper &other)=delete
constant_type * make_real(string_type *str)
cubmem::extensible_block m_qstr_buf
std::forward_list< string_type * > m_string_list
constant_type * make_constant(int type, void *val)
char m_copy_buf_pool[COPY_BUF_POOL_SIZE][MAX_COPY_BUF_SIZE]
constant_type m_constant_pool[CONSTANT_POOL_SIZE]
static const std::size_t STRING_POOL_SIZE
static const std::size_t MAX_COPY_BUF_SIZE
bool is_utf8_valid(string_type *str)
string_type m_string_pool[STRING_POOL_SIZE]
string_type * make_string_by_yytext(const char *text, int text_size)
string_type * append_string_list(string_type *head, string_type *tail)
string_type * make_string(char *val, std::size_t size, bool need_free_val)
std::forward_list< constant_type * > m_constant_list
char m_qstr_buf_pool[QUOTED_STR_BUF_POOL_SIZE][MAX_QUOTED_STR_BUF_SIZE]
constant_type * make_monetary_constant(int currency_type, string_type *amount)
static const std::size_t COPY_BUF_POOL_SIZE
static const std::size_t QUOTED_STR_BUF_POOL_SIZE
void extend_quoted_string_buffer(size_t new_size)
constant_type * append_constant_list(constant_type *head, constant_type *tail)
void set_in_instance_line(bool in_instance_line)
bool use_copy_buf_pool(std::size_t str_size)
T * append_list(T *head, T *tail)
string_type * make_string_and_copy(const char *src, size_t str_size)
static const std::size_t CONSTANT_POOL_SIZE