00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #include "pars0sym.h"
00027
00028 #ifdef UNIV_NONINL
00029 #include "pars0sym.ic"
00030 #endif
00031
00032 #include "mem0mem.h"
00033 #include "data0type.h"
00034 #include "data0data.h"
00035 #ifndef PARS0GRM_H
00036 # define PARS0GRM_H
00037 # include "pars0grm.hh"
00038 #endif
00039 #include "pars0pars.h"
00040 #include "que0que.h"
00041 #include "eval0eval.h"
00042 #include "row0sel.h"
00043
00044
00047 UNIV_INTERN
00048 sym_tab_t*
00049 sym_tab_create(
00050
00051 mem_heap_t* heap)
00052 {
00053 sym_tab_t* sym_tab;
00054
00055 sym_tab = static_cast<sym_tab_t *>(mem_heap_alloc(heap, sizeof(sym_tab_t)));
00056
00057 UT_LIST_INIT(sym_tab->sym_list);
00058 UT_LIST_INIT(sym_tab->func_node_list);
00059
00060 sym_tab->heap = heap;
00061
00062 return(sym_tab);
00063 }
00064
00065
00069 UNIV_INTERN
00070 void
00071 sym_tab_free_private(
00072
00073 sym_tab_t* sym_tab)
00074 {
00075 sym_node_t* sym;
00076 func_node_t* func;
00077
00078 sym = UT_LIST_GET_FIRST(sym_tab->sym_list);
00079
00080 while (sym) {
00081 eval_node_free_val_buf(sym);
00082
00083 if (sym->prefetch_buf) {
00084 sel_col_prefetch_buf_free(sym->prefetch_buf);
00085 }
00086
00087 if (sym->cursor_def) {
00088 que_graph_free_recursive(sym->cursor_def);
00089 }
00090
00091 sym = UT_LIST_GET_NEXT(sym_list, sym);
00092 }
00093
00094 func = UT_LIST_GET_FIRST(sym_tab->func_node_list);
00095
00096 while (func) {
00097 eval_node_free_val_buf(func);
00098
00099 func = UT_LIST_GET_NEXT(func_node_list, func);
00100 }
00101 }
00102
00103
00106 #ifdef __cplusplus
00107 extern "C"
00108 #endif
00109 UNIV_INTERN
00110 sym_node_t*
00111 sym_tab_add_int_lit(
00112
00113 sym_tab_t* sym_tab,
00114 ulint val)
00115 {
00116 sym_node_t* node;
00117 byte* data;
00118
00119 node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
00120
00121 node->common.type = QUE_NODE_SYMBOL;
00122
00123 node->resolved = TRUE;
00124 node->token_type = SYM_LIT;
00125
00126 node->indirection = NULL;
00127
00128 dtype_set(dfield_get_type(&node->common.val), DATA_INT, 0, 4);
00129
00130 data = static_cast<byte *>(mem_heap_alloc(sym_tab->heap, 4));
00131 mach_write_to_4(data, val);
00132
00133 dfield_set_data(&(node->common.val), data, 4);
00134
00135 node->common.val_buf_size = 0;
00136 node->prefetch_buf = NULL;
00137 node->cursor_def = NULL;
00138
00139 UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
00140
00141 node->sym_table = sym_tab;
00142
00143 return(node);
00144 }
00145
00146
00149 #ifdef __cplusplus
00150 extern "C"
00151 #endif
00152 UNIV_INTERN
00153 sym_node_t*
00154 sym_tab_add_str_lit(
00155
00156 sym_tab_t* sym_tab,
00157 byte* str,
00159 ulint len)
00160 {
00161 sym_node_t* node;
00162 byte* data;
00163
00164 node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
00165
00166 node->common.type = QUE_NODE_SYMBOL;
00167
00168 node->resolved = TRUE;
00169 node->token_type = SYM_LIT;
00170
00171 node->indirection = NULL;
00172
00173 dtype_set(dfield_get_type(&node->common.val),
00174 DATA_VARCHAR, DATA_ENGLISH, 0);
00175
00176 if (len) {
00177 data = static_cast<byte *>(mem_heap_alloc(sym_tab->heap, len));
00178 ut_memcpy(data, str, len);
00179 } else {
00180 data = NULL;
00181 }
00182
00183 dfield_set_data(&(node->common.val), data, len);
00184
00185 node->common.val_buf_size = 0;
00186 node->prefetch_buf = NULL;
00187 node->cursor_def = NULL;
00188
00189 UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
00190
00191 node->sym_table = sym_tab;
00192
00193 return(node);
00194 }
00195
00196
00199 #ifdef __cplusplus
00200 extern "C"
00201 #endif
00202 UNIV_INTERN
00203 sym_node_t*
00204 sym_tab_add_bound_lit(
00205
00206 sym_tab_t* sym_tab,
00207 const char* name,
00208 ulint* lit_type)
00209 {
00210 sym_node_t* node;
00211 pars_bound_lit_t* blit;
00212 ulint len = 0;
00213
00214 blit = pars_info_get_bound_lit(sym_tab->info, name);
00215 ut_a(blit);
00216
00217 node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
00218
00219 node->common.type = QUE_NODE_SYMBOL;
00220
00221 node->resolved = TRUE;
00222 node->token_type = SYM_LIT;
00223
00224 node->indirection = NULL;
00225
00226 switch (blit->type) {
00227 case DATA_FIXBINARY:
00228 len = blit->length;
00229 *lit_type = PARS_FIXBINARY_LIT;
00230 break;
00231
00232 case DATA_BLOB:
00233 *lit_type = PARS_BLOB_LIT;
00234 break;
00235
00236 case DATA_VARCHAR:
00237 *lit_type = PARS_STR_LIT;
00238 break;
00239
00240 case DATA_CHAR:
00241 ut_a(blit->length > 0);
00242
00243 len = blit->length;
00244 *lit_type = PARS_STR_LIT;
00245 break;
00246
00247 case DATA_INT:
00248 ut_a(blit->length > 0);
00249 ut_a(blit->length <= 8);
00250
00251 len = blit->length;
00252 *lit_type = PARS_INT_LIT;
00253 break;
00254
00255 default:
00256 ut_error;
00257 }
00258
00259 dtype_set(dfield_get_type(&node->common.val),
00260 blit->type, blit->prtype, len);
00261
00262 dfield_set_data(&(node->common.val), blit->address, blit->length);
00263
00264 node->common.val_buf_size = 0;
00265 node->prefetch_buf = NULL;
00266 node->cursor_def = NULL;
00267
00268 UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
00269
00270 node->sym_table = sym_tab;
00271
00272 return(node);
00273 }
00274
00275
00278 #ifdef __cplusplus
00279 extern "C"
00280 #endif
00281 UNIV_INTERN
00282 sym_node_t*
00283 sym_tab_add_null_lit(
00284
00285 sym_tab_t* sym_tab)
00286 {
00287 sym_node_t* node;
00288
00289 node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
00290
00291 node->common.type = QUE_NODE_SYMBOL;
00292
00293 node->resolved = TRUE;
00294 node->token_type = SYM_LIT;
00295
00296 node->indirection = NULL;
00297
00298 dfield_get_type(&node->common.val)->mtype = DATA_ERROR;
00299
00300 dfield_set_null(&node->common.val);
00301
00302 node->common.val_buf_size = 0;
00303 node->prefetch_buf = NULL;
00304 node->cursor_def = NULL;
00305
00306 UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
00307
00308 node->sym_table = sym_tab;
00309
00310 return(node);
00311 }
00312
00313
00316 #ifdef __cplusplus
00317 extern "C"
00318 #endif
00319 UNIV_INTERN
00320 sym_node_t*
00321 sym_tab_add_id(
00322
00323 sym_tab_t* sym_tab,
00324 byte* name,
00325 ulint len)
00326 {
00327 sym_node_t* node;
00328
00329 node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
00330
00331 node->common.type = QUE_NODE_SYMBOL;
00332
00333 node->resolved = FALSE;
00334 node->indirection = NULL;
00335
00336 node->name = mem_heap_strdupl(sym_tab->heap, (char*) name, len);
00337 node->name_len = len;
00338
00339 UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
00340
00341 dfield_set_null(&node->common.val);
00342
00343 node->common.val_buf_size = 0;
00344 node->prefetch_buf = NULL;
00345 node->cursor_def = NULL;
00346
00347 node->sym_table = sym_tab;
00348
00349 return(node);
00350 }
00351
00352
00355 #ifdef __cplusplus
00356 extern "C"
00357 #endif
00358 UNIV_INTERN
00359 sym_node_t*
00360 sym_tab_add_bound_id(
00361
00362 sym_tab_t* sym_tab,
00363 const char* name)
00364 {
00365 sym_node_t* node;
00366 pars_bound_id_t* bid;
00367
00368 bid = pars_info_get_bound_id(sym_tab->info, name);
00369 ut_a(bid);
00370
00371 node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
00372
00373 node->common.type = QUE_NODE_SYMBOL;
00374
00375 node->resolved = FALSE;
00376 node->indirection = NULL;
00377
00378 node->name = mem_heap_strdup(sym_tab->heap, bid->id);
00379 node->name_len = strlen(node->name);
00380
00381 UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
00382
00383 dfield_set_null(&node->common.val);
00384
00385 node->common.val_buf_size = 0;
00386 node->prefetch_buf = NULL;
00387 node->cursor_def = NULL;
00388
00389 node->sym_table = sym_tab;
00390
00391 return(node);
00392 }