CUBRID Engine  latest
esql_host_variable.h
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 /*
21  * esql_host_variable.h - Generic definitions and prototypes for the parser
22  * component of the esql preprocessor.
23  */
24 
25 #ifndef _ESQL_HOST_VARIABLE_H_
26 #define _ESQL_HOST_VARIABLE_H_
27 
28 #ident "$Id$"
29 
30 #include "config.h"
31 
32 #include <stdio.h>
33 #include "esql_hash.h"
34 #include "variable_string.h"
35 
36 #define PTR_VEC_CHUNK_SIZE 4
37 /* The first C_TYPE that is NOT a valid host variable type */
38 #define NUM_C_VARIABLE_TYPES C_TYPE_SQLDA
39 
40 
41 typedef enum c_pype
42 {
43  C_TYPE_SHORT = 0, /* should start from 0 */
61  C_TYPE_BIT = 18,
65  C_TYPE_STRING_CONST = 22, /* for string constant, not variable */
68  NUM_C_TYPES = 25 /* for # of elements in C_TYPE */
69 } C_TYPE;
70 
71 typedef enum specifier_noun
72 {
73  N_INT = 0,
74  N_CHR = 1,
75  N_VOID = 2,
76  N_FLOAT = 3,
78  N_LABEL = 5,
79  N_VARCHAR = 6,
80  N_BIT = 7,
83 
84 typedef enum storage_class
85 {
86  C_FIXED = 0, /* Fixed address */
87  C_REGISTER = 1, /* In a register */
88  C_AUTO = 2, /* On run-time stack */
89  C_TYPEDEF = 3, /* typedef */
90  C_CONSTANT = 4 /* Const decl */
92 
93 typedef enum alias_class
94 {
95  A_DIRECT = 0, /* Specifier supplied directly */
96  A_TYPEDEF = 1, /* Specifier supplied via typedef */
97  A_STRUCT = 2 /* Specifier supplied via tagged struct ref */
98 } ALIAS_CLASS;
99 
100 typedef enum dcl_type
101 {
102  D_POINTER = 0, /* If declarator is pointer */
103  D_ARRAY = 1, /* If declarator is an array */
104  D_FUNCTION = 2 /* If declarator is a function */
105 } DCL_TYPE;
106 
107 typedef struct ptr_vec PTR_VEC;
108 typedef struct link LINK;
109 typedef struct host_var HOST_VAR;
110 typedef struct host_ref HOST_REF;
111 typedef struct symbol SYMBOL;
112 typedef struct specifier specifier;
113 typedef struct declarator declarator;
114 typedef struct structdef STRUCTDEF;
115 //typedef union yystype YYSTYPE;
116 typedef HASH_TAB SYMTAB;
117 typedef struct cursor CURSOR;
118 typedef struct stmt STMT;
119 typedef struct host_lod HOST_LOD;
120 
121 struct host_lod /* list or descriptor */
122 {
123  unsigned char *desc;
124  int n_refs;
126 
127  int max_refs;
130 
131  HOST_LOD *next; /* Link to previous descriptor */
132 };
133 
134 /*
135 union yystype
136 {
137  char *p_char;
138  SYMBOL *p_sym;
139  LINK *p_link;
140  STRUCTDEF *p_sdef;
141  HOST_VAR *p_hv;
142  HOST_REF *p_hr;
143  HOST_LOD *p_lod;
144  CURSOR *p_cs;
145  STMT *p_stmt;
146  PTR_VEC *p_pv;
147  int num;
148  int ascii;
149 };
150 */
151 
152 
153 struct structdef
154 {
155  unsigned char *tag; /* Tag part of struct def */
156  const unsigned char *type_string; /* "struct" or "union" */
157  unsigned char type; /* 1 if a struct, 0 if a union */
158  unsigned char level; /* Nesting level of struct decl */
159  SYMBOL *fields; /* Linked list of field decls */
160  size_t size; /* Size of the struct in bytes */
161  int by_name; /* See note below */
162  STRUCTDEF *next; /* Link to next structdef at this level */
163 
164 
165 };
166 
167 struct ptr_vec
168 {
169  int n_elems;
171  void **elems;
172 
174  size_t chunk_size;
175  void *inline_elems[PTR_VEC_CHUNK_SIZE];
176 };
177 
179 {
180  DCL_TYPE dcl_type; /* POINTER, ARRAY, or FUNCTION */
181  char *num_ele; /* # of elements for ARRAY */
182  SYMBOL *args; /* arg decls for a FUNCTION */
183 };
184 
185 struct specifier
186 {
187  SPECIFIER_NOUN noun; /* INT CHR VOID STRUCTURE LABEL */
188  STORAGE_CLASS sclass; /* FIXED REGISTER AUTO TYPEDEF CONSTANT */
189  unsigned char is_long; /* 1 = long. */
190  unsigned char is_short; /* 1 = short. */
191  unsigned char is_unsigned; /* 1 = unsigned. 0 = signed. */
192  unsigned char is_static; /* 1 if static keyword in declaration */
193  unsigned char is_extern; /* 1 if extern keyword in declaration */
194  unsigned char is_volatile; /* 1 if volatile keyword in declaration */
195  unsigned char is_const; /* 1 if const keyword in declaration */
196  unsigned char is_auto; /* 1 if auto keyword in declaration */
197  unsigned char is_register; /* 1 if register keyword in declaration */
198  unsigned char is_by_name; /* 1 if this is a STRUCTURE specifier */
199 
200  union
201  { /* Value if constant: */
202  int v_int; /* Int & char values. If a string, */
203  /* is numeric component of the label. */
204  unsigned int v_uint; /* Unsigned int constant value. */
205  long v_long; /* Signed long constant value. */
206  unsigned long v_ulong; /* Unsigned long constant value. */
207 
208  STRUCTDEF *v_struct; /* If this is a struct or a varchar, */
209  /* points at a structure-table element */
210 
211  SYMBOL *v_tdef; /* The typedef-table entry for this */
212  /* link if it belongs to a typedef. */
213  } val;
214 };
215 
217 {
220 };
221 typedef enum link_class LINK_CLASS;
222 
223 struct link
224 {
225  LINK_CLASS class_; /* DECLARATOR or SPECIFIER */
226  SYMBOL *tdef; /* Points to typedef used to create the */
227  SYMBOL *from_tdef; /* link if it was created by cloning a */
228  /* typedef. */
229  union
230  {
231  specifier s; /* If class == SPECIFIER */
232  declarator d; /* if class == DECLARATOR */
233  } decl; /* declaration */
234 
235  LINK *next; /* Next element of chain. */
236 };
237 
238 struct host_var
239 {
245 };
246 
247 struct host_ref
248 {
259 };
260 
261 typedef enum when_condition
262 {
263  SQLWARNING = 0, /* warning */
264  SQLERROR = 1, /* error */
265  NOT_FOUND = 2 /* no object affected / end of search */
267 
268 typedef enum when_action
269 {
270  CONTINUE = 0, /* continue */
271  STOP = 1, /* stop and exit program */
272  GOTO = 2, /* goto specified label */
273  CALL = 3 /* call specified procedure */
274 } WHEN_ACTION;
275 
276 struct symbol
277 {
278  unsigned char *name; /* Input variable name. */
279  int level; /* Decl level, field offset */
280  LINK *type; /* First link in declarator chain */
281  LINK *etype; /* Last link in declarator chain */
282  SYMBOL *args; /* If a func decl, the arg list */
283  /* If a var, the initializer */
284  SYMBOL *next; /* Cross link to next variable at the */
285  /* current nesting level */
286 };
287 
288 struct cursor
289 {
290  unsigned char *name; /* The name of the cursor */
291  int cid; /* A unique cursor id */
292  int level; /* The nesting level of the declaration */
293  CURSOR *next; /* A pointer to the next cursor at the */
294  /* same nesting level */
295 
296  unsigned char *static_stmt; /* The prepared SELECT statement */
298  HOST_LOD *host_refs; /* The host variables */
299  STMT *dynamic_stmt; /* The dynamic statement */
300 };
301 
302 struct stmt
303 {
304  unsigned char *name;
305  int sid;
306 };
307 
308 #ifdef __cplusplus
309 extern "C"
310 {
311 #endif
312 
313  extern C_TYPE pp_get_type (HOST_REF * ref);
314  extern char *pp_get_precision (HOST_REF * ref);
315  extern char *pp_get_input_size (HOST_REF * ref);
316  extern char *pp_get_output_size (HOST_REF * ref);
317  extern char *pp_get_expr (HOST_REF * ref);
318  extern char *pp_get_addr_expr (HOST_REF * ref);
319  extern char *pp_get_ind_expr (HOST_REF * ref);
320  extern char *pp_get_ind_addr_expr (HOST_REF * ref);
321  extern void pp_print_host_ref (HOST_REF * ref, FILE * fp);
322 
323 #ifdef __cplusplus
324 }
325 #endif
326 
327 #endif /* _ESQL_HOST_VARIABLE_H_ */
char * pp_get_ind_addr_expr(HOST_REF *ref)
STORAGE_CLASS sclass
enum storage_class STORAGE_CLASS
char * pp_get_ind_expr(HOST_REF *ref)
unsigned char is_volatile
unsigned char is_unsigned
when_condition
STRUCTDEF * v_struct
unsigned char level
unsigned char * static_stmt
SPECIFIER_NOUN noun
varstring * ind_addr_expr_buf
unsigned char * tag
char * pp_get_expr(HOST_REF *ref)
unsigned char is_extern
STRUCTDEF * next
C_TYPE pp_get_type(HOST_REF *ref)
SYMBOL * args
char * pp_get_output_size(HOST_REF *ref)
unsigned char is_long
varstring * ind_expr_buf
varstring * precision_buf
void pp_print_host_ref(HOST_REF *ref, FILE *fp)
unsigned char * desc
HOST_REF * refs
#define PTR_VEC_CHUNK_SIZE
unsigned char is_by_name
unsigned char type
enum when_action WHEN_ACTION
varstring * expr_buf
varstring * output_size_buf
enum specifier_noun SPECIFIER_NOUN
unsigned char is_const
char * pp_get_precision(HOST_REF *ref)
alias_class
CURSOR * next
unsigned char * name
size_t chunk_size
unsigned char is_short
varstring addr_expr
enum link_class LINK_CLASS
varstring * addr_expr_buf
varstring expr
unsigned char is_register
HOST_REF * real_refs
storage_class
char * pp_get_input_size(HOST_REF *ref)
unsigned int v_uint
enum when_condition WHEN_CONDITION
unsigned char is_auto
HASH_TAB SYMTAB
HOST_LOD * host_refs
unsigned char is_static
enum alias_class ALIAS_CLASS
char * pp_get_addr_expr(HOST_REF *ref)
HOST_VAR * var
unsigned char * name
varstring * input_size_buf
SYMBOL * next
HOST_VAR * ind
unsigned char * name
enum c_pype C_TYPE
enum dcl_type DCL_TYPE
unsigned long v_ulong
HOST_LOD * next
STMT * dynamic_stmt
specifier_noun
const unsigned char * type_string