diff options
Diffstat (limited to 'storage/innobase/pars')
-rw-r--r-- | storage/innobase/pars/lexyy.cc | 2841 | ||||
-rwxr-xr-x | storage/innobase/pars/make_bison.sh | 32 | ||||
-rwxr-xr-x | storage/innobase/pars/make_flex.sh | 50 | ||||
-rw-r--r-- | storage/innobase/pars/pars0grm.cc | 2504 | ||||
-rw-r--r-- | storage/innobase/pars/pars0grm.y | 609 | ||||
-rw-r--r-- | storage/innobase/pars/pars0lex.l | 614 | ||||
-rw-r--r-- | storage/innobase/pars/pars0opt.cc | 1263 | ||||
-rw-r--r-- | storage/innobase/pars/pars0pars.cc | 2381 | ||||
-rw-r--r-- | storage/innobase/pars/pars0sym.cc | 413 |
9 files changed, 10707 insertions, 0 deletions
diff --git a/storage/innobase/pars/lexyy.cc b/storage/innobase/pars/lexyy.cc new file mode 100644 index 00000000..e57a28ce --- /dev/null +++ b/storage/innobase/pars/lexyy.cc @@ -0,0 +1,2841 @@ +#include "univ.i" +#line 2 "lexyy.cc" + +#line 4 "lexyy.cc" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 4 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <stdlib.h> + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include <inttypes.h> +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ + +/* TODO: this is always defined, so inline it */ +#define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) +#else +#define yynoreturn +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an + * integer in range [0..255] for use as an array index. + */ +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + + + + + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : 0) +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +static int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = NULL; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +static void yyrestart ( FILE *input_file ); +MY_ATTRIBUTE((unused)) static void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); +static YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); +static void yy_delete_buffer ( YY_BUFFER_STATE b ); +static void yy_flush_buffer ( YY_BUFFER_STATE b ); +MY_ATTRIBUTE((unused)) static void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); +MY_ATTRIBUTE((unused)) static void yypop_buffer_state ( void ); + +static void yyensure_buffer_stack ( void ); +static void yy_load_buffer_state ( void ); +static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); + +static void *yyalloc ( yy_size_t ); +static void *yyrealloc ( void *, yy_size_t ); +static void yyfree ( void * ); + +#define yy_new_buffer yy_create_buffer +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define yywrap() (/*CONSTCOND*/1) +#define YY_SKIP_YYWRAP +typedef flex_uint8_t YY_CHAR; + +static FILE *yyin = NULL, *yyout = NULL; + +typedef int yy_state_type; + + +static int yylineno = 1; + + +#ifdef yytext_ptr +#undef yytext_ptr +#endif +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state ( void ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); +static int yy_get_next_buffer ( void ); +static void yynoreturn yy_fatal_error ( const char* msg ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; +#define YY_NUM_RULES 102 +#define YY_END_OF_BUFFER 103 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static const flex_int16_t yy_accept[307] = + { 0, + 0, 0, 97, 97, 0, 0, 0, 0, 103, 101, + 100, 100, 8, 101, 92, 5, 81, 87, 90, 88, + 85, 89, 101, 91, 1, 101, 86, 84, 82, 83, + 95, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 93, 94, 97, 98, 6, 7, 9, 10, 100, 4, + 76, 96, 2, 1, 3, 77, 78, 80, 79, 0, + 74, 0, 74, 74, 74, 74, 36, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 23, 17, 20, 74, 74, 74, 74, 74, 74, 46, + + 52, 74, 14, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 97, 98, + 98, 99, 6, 7, 9, 10, 2, 0, 75, 13, + 37, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 22, 74, 74, 34, 74, + 74, 74, 74, 18, 74, 74, 74, 74, 74, 15, + 74, 74, 74, 74, 74, 74, 74, 43, 74, 12, + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 0, 75, 74, 74, 19, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 38, 25, 74, 67, 74, + + 32, 74, 74, 74, 74, 40, 74, 72, 69, 27, + 71, 74, 11, 55, 74, 74, 74, 74, 74, 74, + 74, 74, 24, 74, 74, 74, 74, 74, 74, 66, + 0, 21, 74, 57, 74, 74, 74, 31, 74, 74, + 74, 74, 74, 26, 56, 74, 49, 74, 62, 74, + 74, 35, 74, 74, 74, 74, 70, 74, 48, 74, + 74, 74, 74, 33, 28, 0, 73, 74, 64, 61, + 47, 74, 54, 74, 44, 74, 39, 63, 74, 74, + 29, 74, 30, 60, 74, 50, 42, 41, 74, 45, + 53, 74, 74, 74, 74, 74, 74, 68, 58, 74, + + 65, 74, 51, 16, 59, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 5, 6, 7, 1, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 34, + 1, 1, 1, 1, 50, 1, 34, 34, 34, 34, + + 34, 34, 34, 34, 34, 34, 34, 51, 34, 34, + 34, 34, 52, 34, 53, 34, 34, 34, 34, 34, + 34, 34, 54, 1, 55, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[56] = + { 0, + 1, 1, 1, 2, 3, 1, 1, 4, 1, 1, + 5, 1, 1, 1, 1, 6, 7, 1, 1, 1, + 8, 1, 1, 6, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 1, 1 + } ; + +static const flex_int16_t yy_base[320] = + { 0, + 0, 0, 262, 259, 249, 244, 239, 234, 236, 960, + 54, 56, 960, 0, 960, 960, 960, 960, 960, 960, + 960, 960, 217, 220, 45, 186, 960, 42, 960, 184, + 960, 45, 49, 55, 51, 65, 80, 50, 69, 94, + 90, 92, 104, 60, 114, 116, 131, 134, 135, 149, + 960, 960, 0, 61, 0, 194, 0, 197, 133, 0, + 960, 960, 163, 53, 143, 960, 960, 960, 960, 147, + 125, 123, 138, 151, 152, 153, 155, 166, 169, 173, + 170, 171, 176, 180, 193, 182, 200, 204, 206, 209, + 210, 211, 213, 224, 225, 226, 235, 240, 242, 245, + + 251, 252, 255, 256, 258, 261, 270, 274, 272, 277, + 289, 288, 276, 294, 295, 300, 304, 305, 0, 79, + 110, 960, 0, 116, 0, 113, 98, 58, 0, 306, + 315, 316, 318, 319, 322, 328, 329, 332, 334, 338, + 344, 353, 351, 354, 366, 360, 367, 369, 376, 378, + 381, 385, 388, 382, 394, 400, 403, 404, 406, 407, + 410, 417, 423, 424, 426, 429, 433, 440, 442, 443, + 444, 445, 454, 456, 459, 461, 472, 473, 474, 477, + 53, 0, 475, 478, 479, 490, 502, 504, 505, 507, + 508, 509, 511, 518, 520, 523, 524, 525, 529, 538, + + 541, 542, 543, 545, 547, 544, 556, 557, 558, 559, + 560, 569, 572, 574, 578, 581, 579, 583, 588, 590, + 600, 601, 602, 607, 611, 613, 612, 618, 622, 629, + 41, 634, 636, 638, 639, 643, 645, 648, 649, 650, + 655, 659, 661, 660, 670, 675, 676, 679, 680, 682, + 686, 689, 691, 696, 693, 700, 705, 706, 709, 711, + 712, 716, 722, 723, 726, 72, 727, 736, 737, 738, + 739, 740, 742, 743, 752, 753, 755, 757, 758, 759, + 764, 770, 769, 771, 774, 784, 785, 786, 787, 789, + 790, 791, 796, 801, 802, 803, 806, 807, 812, 817, + + 816, 823, 826, 828, 832, 960, 872, 881, 890, 893, + 896, 900, 909, 918, 927, 936, 943, 947, 950 + } ; + +static const flex_int16_t yy_def[320] = + { 0, + 306, 1, 307, 307, 308, 308, 309, 309, 306, 306, + 306, 306, 306, 310, 306, 306, 306, 306, 306, 306, + 306, 306, 306, 306, 306, 311, 306, 306, 306, 306, + 306, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 306, 306, 313, 314, 315, 306, 316, 306, 306, 310, + 306, 306, 306, 306, 311, 306, 306, 306, 306, 317, + 312, 318, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 313, 314, + 314, 306, 315, 306, 316, 306, 306, 306, 319, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 306, 319, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 306, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 306, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + + 312, 312, 312, 312, 312, 0, 306, 306, 306, 306, + 306, 306, 306, 306, 306, 306, 306, 306, 306 + } ; + +static const flex_int16_t yy_nxt[1016] = + { 0, + 10, 11, 12, 13, 10, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 10, 32, 33, 34, 35, 36, 37, + 38, 38, 39, 38, 38, 40, 41, 42, 43, 44, + 38, 45, 46, 47, 48, 49, 50, 38, 38, 38, + 38, 38, 38, 51, 52, 59, 59, 59, 59, 63, + 70, 64, 67, 68, 70, 70, 70, 63, 72, 64, + 70, 121, 72, 72, 72, 70, 122, 75, 72, 83, + 70, 76, 73, 72, 70, 129, 78, 74, 72, 306, + 79, 266, 72, 80, 306, 70, 81, 77, 91, 82, + + 84, 104, 85, 72, 231, 70, 92, 70, 87, 70, + 181, 93, 86, 72, 127, 72, 126, 72, 88, 70, + 121, 89, 94, 124, 90, 122, 95, 72, 97, 70, + 98, 70, 96, 100, 59, 59, 99, 72, 70, 72, + 70, 101, 105, 102, 107, 103, 70, 108, 72, 70, + 70, 128, 106, 70, 72, 111, 109, 72, 72, 116, + 110, 72, 112, 306, 70, 130, 70, 70, 70, 113, + 70, 114, 72, 115, 72, 72, 72, 131, 72, 127, + 117, 70, 132, 133, 70, 70, 70, 118, 70, 72, + 134, 70, 72, 72, 72, 70, 72, 70, 140, 72, + + 126, 124, 142, 72, 69, 72, 66, 135, 70, 137, + 138, 143, 141, 136, 147, 70, 72, 139, 144, 70, + 146, 70, 145, 72, 70, 70, 70, 72, 70, 72, + 62, 61, 72, 72, 72, 306, 72, 58, 152, 70, + 70, 70, 58, 148, 150, 149, 151, 72, 72, 72, + 70, 56, 157, 153, 154, 70, 56, 70, 72, 156, + 70, 155, 159, 72, 158, 72, 70, 70, 72, 54, + 70, 70, 54, 70, 72, 72, 70, 161, 72, 72, + 162, 72, 163, 160, 72, 70, 306, 70, 306, 70, + 306, 70, 70, 72, 164, 72, 166, 72, 169, 72, + + 72, 165, 171, 70, 70, 167, 306, 170, 306, 70, + 70, 72, 72, 168, 172, 70, 173, 72, 72, 70, + 70, 70, 176, 72, 306, 174, 175, 72, 72, 72, + 70, 70, 178, 70, 70, 177, 179, 70, 72, 72, + 306, 72, 72, 70, 70, 72, 180, 70, 183, 70, + 184, 72, 72, 70, 306, 72, 306, 72, 189, 70, + 185, 72, 191, 306, 186, 188, 70, 72, 70, 70, + 187, 190, 306, 306, 72, 70, 72, 72, 306, 195, + 196, 70, 70, 72, 70, 192, 193, 306, 194, 72, + 72, 70, 72, 70, 197, 200, 70, 70, 198, 72, + + 70, 72, 306, 70, 72, 72, 306, 202, 72, 70, + 199, 72, 306, 203, 201, 70, 204, 72, 70, 70, + 206, 70, 70, 72, 207, 70, 72, 72, 208, 72, + 72, 205, 70, 72, 211, 306, 212, 209, 70, 70, + 72, 70, 306, 210, 70, 213, 72, 72, 70, 72, + 216, 215, 72, 306, 214, 70, 72, 70, 70, 70, + 70, 219, 306, 72, 218, 72, 72, 72, 72, 70, + 217, 70, 306, 306, 70, 306, 70, 72, 306, 72, + 222, 224, 72, 220, 72, 226, 221, 70, 70, 70, + 70, 223, 70, 70, 70, 72, 72, 72, 72, 225, + + 72, 72, 72, 306, 306, 70, 306, 306, 306, 229, + 306, 230, 232, 72, 228, 233, 227, 70, 234, 70, + 70, 306, 70, 70, 70, 72, 70, 72, 72, 237, + 72, 72, 72, 70, 72, 70, 236, 240, 70, 70, + 70, 72, 242, 72, 70, 235, 72, 72, 72, 241, + 238, 239, 72, 70, 244, 306, 70, 70, 70, 70, + 70, 72, 70, 243, 72, 72, 72, 72, 72, 245, + 72, 70, 70, 70, 70, 70, 306, 306, 306, 72, + 72, 72, 72, 72, 70, 246, 248, 70, 249, 70, + 247, 306, 72, 70, 70, 72, 70, 72, 70, 250, + + 306, 72, 72, 70, 72, 70, 72, 251, 255, 253, + 306, 72, 306, 72, 256, 70, 70, 70, 257, 252, + 254, 306, 70, 72, 72, 72, 70, 70, 70, 259, + 72, 306, 306, 70, 72, 72, 72, 70, 306, 260, + 263, 72, 306, 258, 70, 72, 264, 306, 306, 70, + 265, 70, 72, 70, 70, 261, 262, 72, 70, 72, + 70, 72, 72, 70, 70, 70, 72, 268, 72, 306, + 70, 72, 72, 72, 70, 70, 70, 271, 72, 267, + 306, 306, 72, 72, 72, 70, 269, 272, 270, 275, + 70, 70, 306, 72, 70, 70, 273, 70, 72, 72, + + 274, 70, 72, 72, 70, 72, 70, 276, 70, 72, + 306, 70, 72, 278, 72, 70, 72, 282, 280, 72, + 70, 70, 277, 72, 70, 306, 70, 70, 72, 72, + 279, 70, 72, 281, 72, 72, 306, 70, 70, 72, + 286, 70, 70, 283, 287, 72, 72, 284, 285, 72, + 72, 70, 70, 70, 70, 70, 306, 70, 70, 72, + 72, 72, 72, 72, 288, 72, 72, 70, 70, 306, + 70, 291, 70, 70, 70, 72, 72, 289, 72, 70, + 72, 72, 72, 290, 70, 70, 70, 72, 306, 70, + 306, 292, 72, 72, 72, 293, 295, 72, 296, 70, + + 70, 70, 70, 294, 70, 70, 70, 72, 72, 72, + 72, 70, 72, 72, 72, 297, 70, 70, 70, 72, + 306, 70, 70, 299, 72, 72, 72, 70, 298, 72, + 72, 70, 70, 303, 306, 72, 301, 306, 70, 72, + 72, 70, 300, 70, 302, 304, 72, 70, 306, 72, + 306, 72, 306, 306, 306, 72, 306, 306, 306, 306, + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + 306, 305, 53, 53, 53, 53, 53, 53, 53, 53, + 53, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 57, 57, 57, 57, 57, 57, 57, 57, 57, 60, + + 306, 60, 65, 65, 65, 71, 71, 306, 71, 119, + 119, 119, 119, 306, 119, 119, 119, 119, 120, 120, + 120, 120, 120, 120, 120, 120, 120, 123, 123, 123, + 306, 123, 123, 123, 123, 123, 125, 306, 125, 125, + 125, 125, 125, 125, 125, 129, 306, 306, 306, 306, + 306, 129, 72, 72, 306, 72, 182, 306, 182, 9, + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + 306, 306, 306, 306, 306 + } ; + +static const flex_int16_t yy_chk[1016] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 11, 11, 12, 12, 25, + 32, 25, 28, 28, 33, 38, 35, 64, 32, 64, + 34, 54, 33, 38, 35, 44, 54, 33, 34, 35, + 36, 33, 32, 44, 39, 266, 34, 32, 36, 120, + 34, 231, 39, 34, 120, 37, 34, 33, 39, 34, + + 36, 44, 36, 37, 181, 41, 39, 42, 37, 40, + 128, 39, 36, 41, 127, 42, 126, 40, 37, 43, + 121, 37, 40, 124, 37, 121, 40, 43, 41, 45, + 42, 46, 40, 43, 59, 59, 42, 45, 72, 46, + 71, 43, 45, 43, 46, 43, 47, 46, 71, 48, + 49, 70, 45, 73, 47, 47, 46, 48, 49, 49, + 46, 73, 47, 65, 50, 73, 74, 75, 76, 47, + 77, 48, 50, 48, 74, 75, 76, 74, 77, 63, + 50, 78, 75, 76, 79, 81, 82, 50, 80, 78, + 78, 83, 79, 81, 82, 84, 80, 86, 81, 83, + + 58, 56, 83, 84, 30, 86, 26, 79, 85, 80, + 80, 83, 82, 79, 86, 87, 85, 80, 83, 88, + 85, 89, 84, 87, 90, 91, 92, 88, 93, 89, + 24, 23, 90, 91, 92, 9, 93, 8, 92, 94, + 95, 96, 7, 87, 89, 88, 90, 94, 95, 96, + 97, 6, 96, 92, 92, 98, 5, 99, 97, 95, + 100, 94, 97, 98, 96, 99, 101, 102, 100, 4, + 103, 104, 3, 105, 101, 102, 106, 99, 103, 104, + 102, 105, 103, 98, 106, 107, 0, 109, 0, 108, + 0, 113, 110, 107, 104, 109, 106, 108, 108, 113, + + 110, 105, 110, 112, 111, 107, 0, 109, 0, 114, + 115, 112, 111, 107, 111, 116, 112, 114, 115, 117, + 118, 130, 115, 116, 0, 113, 114, 117, 118, 130, + 131, 132, 117, 133, 134, 116, 117, 135, 131, 132, + 0, 133, 134, 136, 137, 135, 118, 138, 132, 139, + 133, 136, 137, 140, 0, 138, 0, 139, 138, 141, + 134, 140, 140, 0, 135, 137, 143, 141, 142, 144, + 136, 139, 0, 0, 143, 146, 142, 144, 0, 143, + 144, 145, 147, 146, 148, 141, 141, 0, 142, 145, + 147, 149, 148, 150, 145, 148, 151, 154, 145, 149, + + 152, 150, 0, 153, 151, 154, 0, 151, 152, 155, + 147, 153, 0, 152, 150, 156, 153, 155, 157, 158, + 154, 159, 160, 156, 155, 161, 157, 158, 156, 159, + 160, 153, 162, 161, 159, 0, 160, 157, 163, 164, + 162, 165, 0, 158, 166, 161, 163, 164, 167, 165, + 164, 163, 166, 0, 162, 168, 167, 169, 170, 171, + 172, 167, 0, 168, 166, 169, 170, 171, 172, 173, + 165, 174, 0, 0, 175, 0, 176, 173, 0, 174, + 172, 174, 175, 169, 176, 176, 171, 177, 178, 179, + 183, 173, 180, 184, 185, 177, 178, 179, 183, 175, + + 180, 184, 185, 0, 0, 186, 0, 0, 0, 179, + 0, 180, 183, 186, 178, 184, 177, 187, 186, 188, + 189, 0, 190, 191, 192, 187, 193, 188, 189, 189, + 190, 191, 192, 194, 193, 195, 188, 192, 196, 197, + 198, 194, 194, 195, 199, 187, 196, 197, 198, 193, + 190, 191, 199, 200, 198, 0, 201, 202, 203, 206, + 204, 200, 205, 195, 201, 202, 203, 206, 204, 200, + 205, 207, 208, 209, 210, 211, 0, 0, 0, 207, + 208, 209, 210, 211, 212, 202, 204, 213, 205, 214, + 203, 0, 212, 215, 217, 213, 216, 214, 218, 207, + + 0, 215, 217, 219, 216, 220, 218, 212, 218, 216, + 0, 219, 0, 220, 219, 221, 222, 223, 220, 215, + 217, 0, 224, 221, 222, 223, 225, 227, 226, 222, + 224, 0, 0, 228, 225, 227, 226, 229, 0, 224, + 227, 228, 0, 221, 230, 229, 228, 0, 0, 232, + 229, 233, 230, 234, 235, 225, 226, 232, 236, 233, + 237, 234, 235, 238, 239, 240, 236, 235, 237, 0, + 241, 238, 239, 240, 242, 244, 243, 239, 241, 233, + 0, 0, 242, 244, 243, 245, 236, 240, 237, 243, + 246, 247, 0, 245, 248, 249, 241, 250, 246, 247, + + 242, 251, 248, 249, 252, 250, 253, 246, 255, 251, + 0, 254, 252, 250, 253, 256, 255, 255, 253, 254, + 257, 258, 248, 256, 259, 0, 260, 261, 257, 258, + 251, 262, 259, 254, 260, 261, 0, 263, 264, 262, + 261, 265, 267, 256, 262, 263, 264, 258, 260, 265, + 267, 268, 269, 270, 271, 272, 0, 273, 274, 268, + 269, 270, 271, 272, 263, 273, 274, 275, 276, 0, + 277, 274, 278, 279, 280, 275, 276, 268, 277, 281, + 278, 279, 280, 272, 283, 282, 284, 281, 0, 285, + 0, 276, 283, 282, 284, 279, 282, 285, 285, 286, + + 287, 288, 289, 280, 290, 291, 292, 286, 287, 288, + 289, 293, 290, 291, 292, 289, 294, 295, 296, 293, + 0, 297, 298, 293, 294, 295, 296, 299, 292, 297, + 298, 301, 300, 297, 0, 299, 295, 0, 302, 301, + 300, 303, 294, 304, 296, 300, 302, 305, 0, 303, + 0, 304, 0, 0, 0, 305, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 302, 307, 307, 307, 307, 307, 307, 307, 307, + 307, 308, 308, 308, 308, 308, 308, 308, 308, 308, + 309, 309, 309, 309, 309, 309, 309, 309, 309, 310, + + 0, 310, 311, 311, 311, 312, 312, 0, 312, 313, + 313, 313, 313, 0, 313, 313, 313, 313, 314, 314, + 314, 314, 314, 314, 314, 314, 314, 315, 315, 315, + 0, 315, 315, 315, 315, 315, 316, 0, 316, 316, + 316, 316, 316, 316, 316, 317, 0, 0, 0, 0, + 0, 317, 318, 318, 0, 318, 319, 0, 319, 306, + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + + 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, + 306, 306, 306, 306, 306 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + + +static int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +static char *yytext; +#line 1 "pars0lex.l" +/***************************************************************************** + +Copyright (c) 1997, 2014, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2017, 2019, MariaDB Corporation. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + +*****************************************************************************/ +/****************************************************** +SQL parser lexical analyzer: input file for the GNU Flex lexer generator + +The InnoDB parser is frozen because MySQL takes care of SQL parsing. +Therefore we normally keep the InnoDB parser C files as they are, and do +not automatically generate them from pars0grm.y and pars0lex.l. + +How to make the InnoDB parser and lexer C files: + +1. Run ./make_flex.sh to generate lexer files. + +2. Run ./make_bison.sh to generate parser files. + +These instructions seem to work at least with bison-1.875d and flex-2.5.31 on +Linux. + +Created 12/14/1997 Heikki Tuuri +*******************************************************/ +#define YY_NO_INPUT 1 +#define YY_NO_UNISTD_H 1 +#line 54 "pars0lex.l" +#define YYSTYPE que_node_t* + +#include "univ.i" +#include "pars0pars.h" +#include "pars0grm.h" +#include "pars0sym.h" +#include "mem0mem.h" + +#define malloc(A) ut_malloc_nokey(A) +#define free(A) ut_free(A) +#define realloc(P, A) ut_realloc(P, A) +#define exit(A) ut_error + +#define YY_INPUT(buf, result, max_size) \ + result = pars_get_lex_chars(buf, max_size) + +/* String buffer for removing quotes */ +static ulint stringbuf_len_alloc = 0; /* Allocated length */ +static ulint stringbuf_len = 0; /* Current length */ +static char* stringbuf; /* Start of buffer */ +/** Appends a string to the buffer. */ +static +void +string_append( +/*==========*/ + const char* str, /*!< in: string to be appended */ + ulint len) /*!< in: length of the string */ +{ + if (stringbuf == NULL) { + stringbuf = static_cast<char*>(malloc(1)); + stringbuf_len_alloc = 1; + } + + if (stringbuf_len + len > stringbuf_len_alloc) { + while (stringbuf_len + len > stringbuf_len_alloc) { + stringbuf_len_alloc <<= 1; + } + + stringbuf = static_cast<char*>( + realloc(stringbuf, stringbuf_len_alloc)); + } + + memcpy(stringbuf + stringbuf_len, str, len); + stringbuf_len += len; +} + +#line 859 "lexyy.cc" + +#line 861 "lexyy.cc" + +#define INITIAL 0 +#define comment 1 +#define quoted 2 +#define id 3 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include <unistd.h> +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals ( void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +MY_ATTRIBUTE((unused)) static int yylex_destroy ( void ); + +MY_ATTRIBUTE((unused)) static int yyget_debug ( void ); + +MY_ATTRIBUTE((unused)) static void yyset_debug ( int debug_flag ); + +YY_EXTRA_TYPE yyget_extra ( void ); + + + +MY_ATTRIBUTE((unused)) static FILE *yyget_in ( void ); + +MY_ATTRIBUTE((unused)) static void yyset_in ( FILE * _in_str ); + +MY_ATTRIBUTE((unused)) static FILE *yyget_out ( void ); + +MY_ATTRIBUTE((unused)) static void yyset_out ( FILE * _out_str ); + + MY_ATTRIBUTE((unused)) static int yyget_leng ( void ); + +MY_ATTRIBUTE((unused)) static char *yyget_text ( void ); + +MY_ATTRIBUTE((unused)) static int yyget_lineno ( void ); + +MY_ATTRIBUTE((unused)) static void yyset_lineno ( int _line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap ( void ); +#else +extern int yywrap ( void ); +#endif +#endif + +#ifndef YY_NO_UNPUT + +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy ( char *, const char *, int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen ( const char * ); +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus +static int yyinput ( void ); +#else +static int input ( void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + int n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK /*LINTED*/break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + { +#line 112 "pars0lex.l" + + +#line 1082 "lexyy.cc" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 307 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_current_state != 306 ); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 114 "pars0lex.l" +{ + yylval = sym_tab_add_int_lit(pars_sym_tab_global, + atoi(yytext)); + return(PARS_INT_LIT); +} + YY_BREAK +case 2: +YY_RULE_SETUP +#line 120 "pars0lex.l" +{ + ut_error; /* not implemented */ + + return(PARS_FLOAT_LIT); +} + YY_BREAK +case 3: +YY_RULE_SETUP +#line 126 "pars0lex.l" +{ + ulint type; + + yylval = sym_tab_add_bound_lit(pars_sym_tab_global, + yytext + 1, &type); + + return((int) type); +} + YY_BREAK +case 4: +YY_RULE_SETUP +#line 135 "pars0lex.l" +{ + yylval = sym_tab_add_bound_id(pars_sym_tab_global, + yytext + 1); + + return(PARS_ID_TOKEN); +} + YY_BREAK +case 5: +YY_RULE_SETUP +#line 142 "pars0lex.l" +{ +/* Quoted character string literals are handled in an explicit +start state 'quoted'. This state is entered and the buffer for +the scanned string is emptied upon encountering a starting quote. + +In the state 'quoted', only two actions are possible (defined below). */ + BEGIN(quoted); + stringbuf_len = 0; +} + YY_BREAK +case 6: +/* rule 6 can match eol */ +YY_RULE_SETUP +#line 151 "pars0lex.l" +{ + /* Got a sequence of characters other than "'": + append to string buffer */ + string_append(yytext, yyleng); +} + YY_BREAK +case 7: +YY_RULE_SETUP +#line 156 "pars0lex.l" +{ + /* Got a sequence of "'" characters: + append half of them to string buffer, + as "''" represents a single "'". + We apply truncating division, + so that "'''" will result in "'". */ + + string_append(yytext, yyleng / 2); + + /* If we got an odd number of quotes, then the + last quote we got is the terminating quote. + At the end of the string, we return to the + initial start state and report the scanned + string literal. */ + + if (yyleng % 2) { + BEGIN(INITIAL); + yylval = sym_tab_add_str_lit( + pars_sym_tab_global, + (byte*) stringbuf, stringbuf_len); + return(PARS_STR_LIT); + } +} + YY_BREAK +case 8: +YY_RULE_SETUP +#line 180 "pars0lex.l" +{ +/* Quoted identifiers are handled in an explicit start state 'id'. +This state is entered and the buffer for the scanned string is emptied +upon encountering a starting quote. + +In the state 'id', only two actions are possible (defined below). */ + BEGIN(id); + stringbuf_len = 0; +} + YY_BREAK +case 9: +/* rule 9 can match eol */ +YY_RULE_SETUP +#line 189 "pars0lex.l" +{ + /* Got a sequence of characters other than '"': + append to string buffer */ + string_append(yytext, yyleng); +} + YY_BREAK +case 10: +YY_RULE_SETUP +#line 194 "pars0lex.l" +{ + /* Got a sequence of '"' characters: + append half of them to string buffer, + as '""' represents a single '"'. + We apply truncating division, + so that '"""' will result in '"'. */ + + string_append(yytext, yyleng / 2); + + /* If we got an odd number of quotes, then the + last quote we got is the terminating quote. + At the end of the string, we return to the + initial start state and report the scanned + identifier. */ + + if (yyleng % 2) { + BEGIN(INITIAL); + yylval = sym_tab_add_id( + pars_sym_tab_global, + (byte*) stringbuf, stringbuf_len); + + return(PARS_ID_TOKEN); + } +} + YY_BREAK +case 11: +YY_RULE_SETUP +#line 219 "pars0lex.l" +{ + yylval = sym_tab_add_null_lit(pars_sym_tab_global); + + return(PARS_NULL_LIT); +} + YY_BREAK +case 12: +YY_RULE_SETUP +#line 225 "pars0lex.l" +{ + /* Implicit cursor name */ + yylval = sym_tab_add_str_lit(pars_sym_tab_global, + (byte*) yytext, yyleng); + return(PARS_SQL_TOKEN); +} + YY_BREAK +case 13: +YY_RULE_SETUP +#line 232 "pars0lex.l" +{ + return(PARS_AND_TOKEN); +} + YY_BREAK +case 14: +YY_RULE_SETUP +#line 236 "pars0lex.l" +{ + return(PARS_OR_TOKEN); +} + YY_BREAK +case 15: +YY_RULE_SETUP +#line 240 "pars0lex.l" +{ + return(PARS_NOT_TOKEN); +} + YY_BREAK +case 16: +YY_RULE_SETUP +#line 244 "pars0lex.l" +{ + return(PARS_PROCEDURE_TOKEN); +} + YY_BREAK +case 17: +YY_RULE_SETUP +#line 248 "pars0lex.l" +{ + return(PARS_IN_TOKEN); +} + YY_BREAK +case 18: +YY_RULE_SETUP +#line 252 "pars0lex.l" +{ + return(PARS_INT_TOKEN); +} + YY_BREAK +case 19: +YY_RULE_SETUP +#line 256 "pars0lex.l" +{ + return(PARS_CHAR_TOKEN); +} + YY_BREAK +case 20: +YY_RULE_SETUP +#line 260 "pars0lex.l" +{ + return(PARS_IS_TOKEN); +} + YY_BREAK +case 21: +YY_RULE_SETUP +#line 264 "pars0lex.l" +{ + return(PARS_BEGIN_TOKEN); +} + YY_BREAK +case 22: +YY_RULE_SETUP +#line 268 "pars0lex.l" +{ + return(PARS_END_TOKEN); +} + YY_BREAK +case 23: +YY_RULE_SETUP +#line 272 "pars0lex.l" +{ + return(PARS_IF_TOKEN); +} + YY_BREAK +case 24: +YY_RULE_SETUP +#line 276 "pars0lex.l" +{ + return(PARS_THEN_TOKEN); +} + YY_BREAK +case 25: +YY_RULE_SETUP +#line 280 "pars0lex.l" +{ + return(PARS_ELSE_TOKEN); +} + YY_BREAK +case 26: +YY_RULE_SETUP +#line 284 "pars0lex.l" +{ + return(PARS_ELSIF_TOKEN); +} + YY_BREAK +case 27: +YY_RULE_SETUP +#line 288 "pars0lex.l" +{ + return(PARS_LOOP_TOKEN); +} + YY_BREAK +case 28: +YY_RULE_SETUP +#line 292 "pars0lex.l" +{ + return(PARS_WHILE_TOKEN); +} + YY_BREAK +case 29: +YY_RULE_SETUP +#line 296 "pars0lex.l" +{ + return(PARS_RETURN_TOKEN); +} + YY_BREAK +case 30: +YY_RULE_SETUP +#line 300 "pars0lex.l" +{ + return(PARS_SELECT_TOKEN); +} + YY_BREAK +case 31: +YY_RULE_SETUP +#line 304 "pars0lex.l" +{ + return(PARS_COUNT_TOKEN); +} + YY_BREAK +case 32: +YY_RULE_SETUP +#line 308 "pars0lex.l" +{ + return(PARS_FROM_TOKEN); +} + YY_BREAK +case 33: +YY_RULE_SETUP +#line 312 "pars0lex.l" +{ + return(PARS_WHERE_TOKEN); +} + YY_BREAK +case 34: +YY_RULE_SETUP +#line 316 "pars0lex.l" +{ + return(PARS_FOR_TOKEN); +} + YY_BREAK +case 35: +YY_RULE_SETUP +#line 320 "pars0lex.l" +{ + return(PARS_ORDER_TOKEN); +} + YY_BREAK +case 36: +YY_RULE_SETUP +#line 324 "pars0lex.l" +{ + return(PARS_BY_TOKEN); +} + YY_BREAK +case 37: +YY_RULE_SETUP +#line 328 "pars0lex.l" +{ + return(PARS_ASC_TOKEN); +} + YY_BREAK +case 38: +YY_RULE_SETUP +#line 332 "pars0lex.l" +{ + return(PARS_DESC_TOKEN); +} + YY_BREAK +case 39: +YY_RULE_SETUP +#line 336 "pars0lex.l" +{ + return(PARS_INSERT_TOKEN); +} + YY_BREAK +case 40: +YY_RULE_SETUP +#line 340 "pars0lex.l" +{ + return(PARS_INTO_TOKEN); +} + YY_BREAK +case 41: +YY_RULE_SETUP +#line 344 "pars0lex.l" +{ + return(PARS_VALUES_TOKEN); +} + YY_BREAK +case 42: +YY_RULE_SETUP +#line 348 "pars0lex.l" +{ + return(PARS_UPDATE_TOKEN); +} + YY_BREAK +case 43: +YY_RULE_SETUP +#line 352 "pars0lex.l" +{ + return(PARS_SET_TOKEN); +} + YY_BREAK +case 44: +YY_RULE_SETUP +#line 356 "pars0lex.l" +{ + return(PARS_DELETE_TOKEN); +} + YY_BREAK +case 45: +YY_RULE_SETUP +#line 360 "pars0lex.l" +{ + return(PARS_CURRENT_TOKEN); +} + YY_BREAK +case 46: +YY_RULE_SETUP +#line 364 "pars0lex.l" +{ + return(PARS_OF_TOKEN); +} + YY_BREAK +case 47: +YY_RULE_SETUP +#line 368 "pars0lex.l" +{ + return(PARS_CREATE_TOKEN); +} + YY_BREAK +case 48: +YY_RULE_SETUP +#line 372 "pars0lex.l" +{ + return(PARS_TABLE_TOKEN); +} + YY_BREAK +case 49: +YY_RULE_SETUP +#line 376 "pars0lex.l" +{ + return(PARS_INDEX_TOKEN); +} + YY_BREAK +case 50: +YY_RULE_SETUP +#line 380 "pars0lex.l" +{ + return(PARS_UNIQUE_TOKEN); +} + YY_BREAK +case 51: +YY_RULE_SETUP +#line 384 "pars0lex.l" +{ + return(PARS_CLUSTERED_TOKEN); +} + YY_BREAK +case 52: +YY_RULE_SETUP +#line 388 "pars0lex.l" +{ + return(PARS_ON_TOKEN); +} + YY_BREAK +case 53: +YY_RULE_SETUP +#line 392 "pars0lex.l" +{ + return(PARS_DECLARE_TOKEN); +} + YY_BREAK +case 54: +YY_RULE_SETUP +#line 396 "pars0lex.l" +{ + return(PARS_CURSOR_TOKEN); +} + YY_BREAK +case 55: +YY_RULE_SETUP +#line 400 "pars0lex.l" +{ + return(PARS_OPEN_TOKEN); +} + YY_BREAK +case 56: +YY_RULE_SETUP +#line 404 "pars0lex.l" +{ + return(PARS_FETCH_TOKEN); +} + YY_BREAK +case 57: +YY_RULE_SETUP +#line 408 "pars0lex.l" +{ + return(PARS_CLOSE_TOKEN); +} + YY_BREAK +case 58: +YY_RULE_SETUP +#line 412 "pars0lex.l" +{ + return(PARS_NOTFOUND_TOKEN); +} + YY_BREAK +case 59: +YY_RULE_SETUP +#line 416 "pars0lex.l" +{ + return(PARS_TO_BINARY_TOKEN); +} + YY_BREAK +case 60: +YY_RULE_SETUP +#line 420 "pars0lex.l" +{ + return(PARS_SUBSTR_TOKEN); +} + YY_BREAK +case 61: +YY_RULE_SETUP +#line 424 "pars0lex.l" +{ + return(PARS_CONCAT_TOKEN); +} + YY_BREAK +case 62: +YY_RULE_SETUP +#line 428 "pars0lex.l" +{ + return(PARS_INSTR_TOKEN); +} + YY_BREAK +case 63: +YY_RULE_SETUP +#line 432 "pars0lex.l" +{ + return(PARS_LENGTH_TOKEN); +} + YY_BREAK +case 64: +YY_RULE_SETUP +#line 436 "pars0lex.l" +{ + return(PARS_COMMIT_TOKEN); +} + YY_BREAK +case 65: +YY_RULE_SETUP +#line 440 "pars0lex.l" +{ + return(PARS_ROLLBACK_TOKEN); +} + YY_BREAK +case 66: +YY_RULE_SETUP +#line 444 "pars0lex.l" +{ + return(PARS_WORK_TOKEN); +} + YY_BREAK +case 67: +YY_RULE_SETUP +#line 448 "pars0lex.l" +{ + return(PARS_EXIT_TOKEN); +} + YY_BREAK +case 68: +YY_RULE_SETUP +#line 452 "pars0lex.l" +{ + return(PARS_FUNCTION_TOKEN); +} + YY_BREAK +case 69: +YY_RULE_SETUP +#line 456 "pars0lex.l" +{ + return(PARS_LOCK_TOKEN); +} + YY_BREAK +case 70: +YY_RULE_SETUP +#line 460 "pars0lex.l" +{ + return(PARS_SHARE_TOKEN); +} + YY_BREAK +case 71: +YY_RULE_SETUP +#line 464 "pars0lex.l" +{ + return(PARS_MODE_TOKEN); +} + YY_BREAK +case 72: +YY_RULE_SETUP +#line 468 "pars0lex.l" +{ + return(PARS_LIKE_TOKEN); +} + YY_BREAK +case 73: +YY_RULE_SETUP +#line 472 "pars0lex.l" +{ + return(PARS_BIGINT_TOKEN); +} + YY_BREAK +case 74: +YY_RULE_SETUP +#line 476 "pars0lex.l" +{ + yylval = sym_tab_add_id(pars_sym_tab_global, + (byte*) yytext, + strlen(yytext)); + return(PARS_ID_TOKEN); +} + YY_BREAK +case 75: +YY_RULE_SETUP +#line 483 "pars0lex.l" +{ + yylval = sym_tab_add_id(pars_sym_tab_global, + (byte*) yytext, + strlen(yytext)); + return(PARS_TABLE_NAME_TOKEN); +} + YY_BREAK +case 76: +YY_RULE_SETUP +#line 490 "pars0lex.l" +{ + return(PARS_DDOT_TOKEN); +} + YY_BREAK +case 77: +YY_RULE_SETUP +#line 494 "pars0lex.l" +{ + return(PARS_ASSIGN_TOKEN); +} + YY_BREAK +case 78: +YY_RULE_SETUP +#line 498 "pars0lex.l" +{ + return(PARS_LE_TOKEN); +} + YY_BREAK +case 79: +YY_RULE_SETUP +#line 502 "pars0lex.l" +{ + return(PARS_GE_TOKEN); +} + YY_BREAK +case 80: +YY_RULE_SETUP +#line 506 "pars0lex.l" +{ + return(PARS_NE_TOKEN); +} + YY_BREAK +case 81: +YY_RULE_SETUP +#line 510 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 82: +YY_RULE_SETUP +#line 515 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 83: +YY_RULE_SETUP +#line 520 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 84: +YY_RULE_SETUP +#line 525 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 85: +YY_RULE_SETUP +#line 530 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 86: +YY_RULE_SETUP +#line 535 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 87: +YY_RULE_SETUP +#line 540 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 88: +YY_RULE_SETUP +#line 545 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 89: +YY_RULE_SETUP +#line 550 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 90: +YY_RULE_SETUP +#line 555 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 91: +YY_RULE_SETUP +#line 560 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 92: +YY_RULE_SETUP +#line 565 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 93: +YY_RULE_SETUP +#line 570 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 94: +YY_RULE_SETUP +#line 575 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 95: +YY_RULE_SETUP +#line 580 "pars0lex.l" +{ + + return((int)(*yytext)); +} + YY_BREAK +case 96: +YY_RULE_SETUP +#line 585 "pars0lex.l" +BEGIN(comment); /* eat up comment */ + YY_BREAK +case 97: +/* rule 97 can match eol */ +YY_RULE_SETUP +#line 587 "pars0lex.l" + + YY_BREAK +case 98: +/* rule 98 can match eol */ +YY_RULE_SETUP +#line 588 "pars0lex.l" + + YY_BREAK +case 99: +YY_RULE_SETUP +#line 589 "pars0lex.l" +BEGIN(INITIAL); + YY_BREAK +case 100: +/* rule 100 can match eol */ +YY_RULE_SETUP +#line 591 "pars0lex.l" +/* eat up whitespace */ + YY_BREAK +case 101: +YY_RULE_SETUP +#line 594 "pars0lex.l" +{ + fprintf(stderr,"Unrecognized character: %02x\n", + *yytext); + + ut_error; + + return(0); +} + YY_BREAK +case 102: +YY_RULE_SETUP +#line 603 "pars0lex.l" +YY_FATAL_ERROR( "flex scanner jammed" ); + YY_BREAK +#line 1942 "lexyy.cc" +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(comment): +case YY_STATE_EOF(quoted): +case YY_STATE_EOF(id): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc( (void *) b->yy_ch_buf, + (yy_size_t) (b->yy_buf_size + 2) ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + yy_state_type yy_current_state; + char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 307 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 307 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 306); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_UNPUT + +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return 0; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + static void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_init_buffer( YY_CURRENT_BUFFER, input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + MY_ATTRIBUTE((unused)) static void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + static YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + static void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree( (void *) b->yy_ch_buf ); + + yyfree( (void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + static void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +MY_ATTRIBUTE((unused)) static void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +MY_ATTRIBUTE((unused)) static void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yynoreturn yy_fatal_error (const char* msg ) +{ + fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +MY_ATTRIBUTE((unused)) static int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +MY_ATTRIBUTE((unused)) static FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +MY_ATTRIBUTE((unused)) static FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +MY_ATTRIBUTE((unused)) static int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +MY_ATTRIBUTE((unused)) static char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param _line_number line number + * + */ +MY_ATTRIBUTE((unused)) static void yyset_lineno (int _line_number ) +{ + + yylineno = _line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param _in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +MY_ATTRIBUTE((unused)) static void yyset_in (FILE * _in_str ) +{ + yyin = _in_str ; +} + +MY_ATTRIBUTE((unused)) static void yyset_out (FILE * _out_str ) +{ + yyout = _out_str ; +} + +MY_ATTRIBUTE((unused)) static int yyget_debug (void) +{ + return yy_flex_debug; +} + +MY_ATTRIBUTE((unused)) static void yyset_debug (int _bdebug ) +{ + yy_flex_debug = _bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = NULL; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = NULL; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = NULL; + yyout = NULL; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +MY_ATTRIBUTE((unused)) static int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer( YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, const char * s2, int n ) +{ + + int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (const char * s ) +{ + int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +static void *yyalloc (yy_size_t size ) +{ + return malloc(size); +} + +static void *yyrealloc (void * ptr, yy_size_t size ) +{ + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return realloc(ptr, size); +} + +static void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 603 "pars0lex.l" + + +/********************************************************************** +Release any resources used by the lexer. */ +void +pars_lexer_close(void) +/*==================*/ +{ + yylex_destroy(); + free(stringbuf); + stringbuf = NULL; + stringbuf_len_alloc = stringbuf_len = 0; +} + diff --git a/storage/innobase/pars/make_bison.sh b/storage/innobase/pars/make_bison.sh new file mode 100755 index 00000000..25c967ac --- /dev/null +++ b/storage/innobase/pars/make_bison.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Copyright (c) 1994, 2013, Oracle and/or its affiliates. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA +# +# generate parser files from bison input files. + +set -eu +TMPFILE=pars0grm.tab.c +OUTFILE=pars0grm.cc + +bison -d pars0grm.y +mv pars0grm.tab.h ../include/pars0grm.h + +sed -e ' +s/'"$TMPFILE"'/'"$OUTFILE"'/; +s/'"pars0grm.tab.h"'/'"pars0grm.h"'/; +s/^\(\(YYSTYPE\|int\) yy\(char\|nerrs\)\)/static \1/; +' < "$TMPFILE" > "$OUTFILE" + +rm "$TMPFILE" diff --git a/storage/innobase/pars/make_flex.sh b/storage/innobase/pars/make_flex.sh new file mode 100755 index 00000000..2baae9c9 --- /dev/null +++ b/storage/innobase/pars/make_flex.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# +# Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved. +# Copyright (c) 2017, 2019, MariaDB Corporation. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA +# +# generate lexer files from flex input files. + +set -eu + +TMPFILE=_flex_tmp.cc +OUTFILE=lexyy.cc + +flex -o $TMPFILE pars0lex.l + +# The Microsoft compiler needs its includes done in a certain order. +echo '#include "univ.i"' > $OUTFILE + +# flex assigns a pointer to an int in one place without a cast, resulting in +# a warning on Win64. Add the cast. Also define some symbols as static. +sed -e ' +s/'"$TMPFILE"'/'"$OUTFILE"'/; +s/^void *yyset_extra *( *YY_EXTRA_TYPE *user_defined *) *;// +s/\(int offset = \)\((yy_c_buf_p) - (yytext_ptr)\);/\1(int)(\2);/; +s/\(void yy\(restart\|_\(delete\|flush\)_buffer\)\)/static \1/; +s/\(void yy_switch_to_buffer\)/MY_ATTRIBUTE((unused)) static \1/; +s/\(void yy\(push\|pop\)_buffer_state\)/MY_ATTRIBUTE((unused)) static \1/; +s/\(YY_BUFFER_STATE yy_create_buffer\)/static \1/; +s/\(\(int\|void\) yy[gs]et_\)/MY_ATTRIBUTE((unused)) static \1/; +s/\(void \*\?yy\(\(re\)\?alloc\|free\)\)/static \1/; +s/extern int yy\(leng\|_flex_debug\|lineno\);//; +s/\(int yy\(leng\|lineno\|_flex_debug\)\)/static \1/; +s/\(int yylex_destroy\)/MY_ATTRIBUTE((unused)) static \1/; +s/^\(\(FILE\|char\) *\* *yyget\)/MY_ATTRIBUTE((unused)) static \1/; +s/^extern \(\(FILE\|char\) *\* *yy\).*//; +s/^\(FILE\|char\) *\* *yy/static &/; +' < $TMPFILE >> $OUTFILE + +rm $TMPFILE diff --git a/storage/innobase/pars/pars0grm.cc b/storage/innobase/pars/pars0grm.cc new file mode 100644 index 00000000..c4d855e2 --- /dev/null +++ b/storage/innobase/pars/pars0grm.cc @@ -0,0 +1,2504 @@ +/* A Bison parser, made by GNU Bison 3.7.6. */ + +/* Bison implementation for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output, and Bison version. */ +#define YYBISON 30706 + +/* Bison version string. */ +#define YYBISON_VERSION "3.7.6" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + + + + +/* First part of user prologue. */ +#line 29 "pars0grm.y" + +/* The value of the semantic attribute is a pointer to a query tree node +que_node_t */ + +#include "univ.i" +#include <math.h> +#include "pars0pars.h" +#include "mem0mem.h" +#include "que0types.h" +#include "que0que.h" +#include "row0sel.h" +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wpragmas" +# pragma GCC diagnostic ignored "-Wunknown-warning-option" +# pragma GCC diagnostic ignored "-Wfree-nonheap-object" +# pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif +#define YYSTYPE que_node_t* +/* #define __STDC__ */ +int +yylex(void); + +#line 90 "pars0grm.cc" + +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast<Type> (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif +# ifndef YY_NULLPTR +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# else +# define YY_NULLPTR ((void*)0) +# endif +# endif + +#include "pars0grm.h" +/* Symbol kind. */ +enum yysymbol_kind_t +{ + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_PARS_INT_LIT = 3, /* PARS_INT_LIT */ + YYSYMBOL_PARS_FLOAT_LIT = 4, /* PARS_FLOAT_LIT */ + YYSYMBOL_PARS_STR_LIT = 5, /* PARS_STR_LIT */ + YYSYMBOL_PARS_NULL_LIT = 6, /* PARS_NULL_LIT */ + YYSYMBOL_PARS_ID_TOKEN = 7, /* PARS_ID_TOKEN */ + YYSYMBOL_PARS_AND_TOKEN = 8, /* PARS_AND_TOKEN */ + YYSYMBOL_PARS_OR_TOKEN = 9, /* PARS_OR_TOKEN */ + YYSYMBOL_PARS_NOT_TOKEN = 10, /* PARS_NOT_TOKEN */ + YYSYMBOL_PARS_GE_TOKEN = 11, /* PARS_GE_TOKEN */ + YYSYMBOL_PARS_LE_TOKEN = 12, /* PARS_LE_TOKEN */ + YYSYMBOL_PARS_NE_TOKEN = 13, /* PARS_NE_TOKEN */ + YYSYMBOL_PARS_PROCEDURE_TOKEN = 14, /* PARS_PROCEDURE_TOKEN */ + YYSYMBOL_PARS_IN_TOKEN = 15, /* PARS_IN_TOKEN */ + YYSYMBOL_PARS_INT_TOKEN = 16, /* PARS_INT_TOKEN */ + YYSYMBOL_PARS_CHAR_TOKEN = 17, /* PARS_CHAR_TOKEN */ + YYSYMBOL_PARS_IS_TOKEN = 18, /* PARS_IS_TOKEN */ + YYSYMBOL_PARS_BEGIN_TOKEN = 19, /* PARS_BEGIN_TOKEN */ + YYSYMBOL_PARS_END_TOKEN = 20, /* PARS_END_TOKEN */ + YYSYMBOL_PARS_IF_TOKEN = 21, /* PARS_IF_TOKEN */ + YYSYMBOL_PARS_THEN_TOKEN = 22, /* PARS_THEN_TOKEN */ + YYSYMBOL_PARS_ELSE_TOKEN = 23, /* PARS_ELSE_TOKEN */ + YYSYMBOL_PARS_ELSIF_TOKEN = 24, /* PARS_ELSIF_TOKEN */ + YYSYMBOL_PARS_LOOP_TOKEN = 25, /* PARS_LOOP_TOKEN */ + YYSYMBOL_PARS_WHILE_TOKEN = 26, /* PARS_WHILE_TOKEN */ + YYSYMBOL_PARS_RETURN_TOKEN = 27, /* PARS_RETURN_TOKEN */ + YYSYMBOL_PARS_SELECT_TOKEN = 28, /* PARS_SELECT_TOKEN */ + YYSYMBOL_PARS_COUNT_TOKEN = 29, /* PARS_COUNT_TOKEN */ + YYSYMBOL_PARS_FROM_TOKEN = 30, /* PARS_FROM_TOKEN */ + YYSYMBOL_PARS_WHERE_TOKEN = 31, /* PARS_WHERE_TOKEN */ + YYSYMBOL_PARS_FOR_TOKEN = 32, /* PARS_FOR_TOKEN */ + YYSYMBOL_PARS_DDOT_TOKEN = 33, /* PARS_DDOT_TOKEN */ + YYSYMBOL_PARS_ORDER_TOKEN = 34, /* PARS_ORDER_TOKEN */ + YYSYMBOL_PARS_BY_TOKEN = 35, /* PARS_BY_TOKEN */ + YYSYMBOL_PARS_ASC_TOKEN = 36, /* PARS_ASC_TOKEN */ + YYSYMBOL_PARS_DESC_TOKEN = 37, /* PARS_DESC_TOKEN */ + YYSYMBOL_PARS_INSERT_TOKEN = 38, /* PARS_INSERT_TOKEN */ + YYSYMBOL_PARS_INTO_TOKEN = 39, /* PARS_INTO_TOKEN */ + YYSYMBOL_PARS_VALUES_TOKEN = 40, /* PARS_VALUES_TOKEN */ + YYSYMBOL_PARS_UPDATE_TOKEN = 41, /* PARS_UPDATE_TOKEN */ + YYSYMBOL_PARS_SET_TOKEN = 42, /* PARS_SET_TOKEN */ + YYSYMBOL_PARS_DELETE_TOKEN = 43, /* PARS_DELETE_TOKEN */ + YYSYMBOL_PARS_CURRENT_TOKEN = 44, /* PARS_CURRENT_TOKEN */ + YYSYMBOL_PARS_OF_TOKEN = 45, /* PARS_OF_TOKEN */ + YYSYMBOL_PARS_CREATE_TOKEN = 46, /* PARS_CREATE_TOKEN */ + YYSYMBOL_PARS_TABLE_TOKEN = 47, /* PARS_TABLE_TOKEN */ + YYSYMBOL_PARS_INDEX_TOKEN = 48, /* PARS_INDEX_TOKEN */ + YYSYMBOL_PARS_UNIQUE_TOKEN = 49, /* PARS_UNIQUE_TOKEN */ + YYSYMBOL_PARS_CLUSTERED_TOKEN = 50, /* PARS_CLUSTERED_TOKEN */ + YYSYMBOL_PARS_ON_TOKEN = 51, /* PARS_ON_TOKEN */ + YYSYMBOL_PARS_ASSIGN_TOKEN = 52, /* PARS_ASSIGN_TOKEN */ + YYSYMBOL_PARS_DECLARE_TOKEN = 53, /* PARS_DECLARE_TOKEN */ + YYSYMBOL_PARS_CURSOR_TOKEN = 54, /* PARS_CURSOR_TOKEN */ + YYSYMBOL_PARS_SQL_TOKEN = 55, /* PARS_SQL_TOKEN */ + YYSYMBOL_PARS_OPEN_TOKEN = 56, /* PARS_OPEN_TOKEN */ + YYSYMBOL_PARS_FETCH_TOKEN = 57, /* PARS_FETCH_TOKEN */ + YYSYMBOL_PARS_CLOSE_TOKEN = 58, /* PARS_CLOSE_TOKEN */ + YYSYMBOL_PARS_NOTFOUND_TOKEN = 59, /* PARS_NOTFOUND_TOKEN */ + YYSYMBOL_PARS_TO_BINARY_TOKEN = 60, /* PARS_TO_BINARY_TOKEN */ + YYSYMBOL_PARS_SUBSTR_TOKEN = 61, /* PARS_SUBSTR_TOKEN */ + YYSYMBOL_PARS_CONCAT_TOKEN = 62, /* PARS_CONCAT_TOKEN */ + YYSYMBOL_PARS_INSTR_TOKEN = 63, /* PARS_INSTR_TOKEN */ + YYSYMBOL_PARS_LENGTH_TOKEN = 64, /* PARS_LENGTH_TOKEN */ + YYSYMBOL_PARS_COMMIT_TOKEN = 65, /* PARS_COMMIT_TOKEN */ + YYSYMBOL_PARS_ROLLBACK_TOKEN = 66, /* PARS_ROLLBACK_TOKEN */ + YYSYMBOL_PARS_WORK_TOKEN = 67, /* PARS_WORK_TOKEN */ + YYSYMBOL_PARS_EXIT_TOKEN = 68, /* PARS_EXIT_TOKEN */ + YYSYMBOL_PARS_FUNCTION_TOKEN = 69, /* PARS_FUNCTION_TOKEN */ + YYSYMBOL_PARS_LOCK_TOKEN = 70, /* PARS_LOCK_TOKEN */ + YYSYMBOL_PARS_SHARE_TOKEN = 71, /* PARS_SHARE_TOKEN */ + YYSYMBOL_PARS_MODE_TOKEN = 72, /* PARS_MODE_TOKEN */ + YYSYMBOL_PARS_LIKE_TOKEN = 73, /* PARS_LIKE_TOKEN */ + YYSYMBOL_PARS_LIKE_TOKEN_EXACT = 74, /* PARS_LIKE_TOKEN_EXACT */ + YYSYMBOL_PARS_LIKE_TOKEN_PREFIX = 75, /* PARS_LIKE_TOKEN_PREFIX */ + YYSYMBOL_PARS_LIKE_TOKEN_SUFFIX = 76, /* PARS_LIKE_TOKEN_SUFFIX */ + YYSYMBOL_PARS_LIKE_TOKEN_SUBSTR = 77, /* PARS_LIKE_TOKEN_SUBSTR */ + YYSYMBOL_PARS_TABLE_NAME_TOKEN = 78, /* PARS_TABLE_NAME_TOKEN */ + YYSYMBOL_PARS_BIGINT_TOKEN = 79, /* PARS_BIGINT_TOKEN */ + YYSYMBOL_80_ = 80, /* '=' */ + YYSYMBOL_81_ = 81, /* '<' */ + YYSYMBOL_82_ = 82, /* '>' */ + YYSYMBOL_83_ = 83, /* '-' */ + YYSYMBOL_84_ = 84, /* '+' */ + YYSYMBOL_85_ = 85, /* '*' */ + YYSYMBOL_86_ = 86, /* '/' */ + YYSYMBOL_NEG = 87, /* NEG */ + YYSYMBOL_88_ = 88, /* '%' */ + YYSYMBOL_89_ = 89, /* ';' */ + YYSYMBOL_90_ = 90, /* '(' */ + YYSYMBOL_91_ = 91, /* ')' */ + YYSYMBOL_92_ = 92, /* ',' */ + YYSYMBOL_YYACCEPT = 93, /* $accept */ + YYSYMBOL_top_statement = 94, /* top_statement */ + YYSYMBOL_statement = 95, /* statement */ + YYSYMBOL_statement_list = 96, /* statement_list */ + YYSYMBOL_exp = 97, /* exp */ + YYSYMBOL_function_name = 98, /* function_name */ + YYSYMBOL_user_function_call = 99, /* user_function_call */ + YYSYMBOL_table_list = 100, /* table_list */ + YYSYMBOL_variable_list = 101, /* variable_list */ + YYSYMBOL_exp_list = 102, /* exp_list */ + YYSYMBOL_select_item = 103, /* select_item */ + YYSYMBOL_select_item_list = 104, /* select_item_list */ + YYSYMBOL_select_list = 105, /* select_list */ + YYSYMBOL_search_condition = 106, /* search_condition */ + YYSYMBOL_for_update_clause = 107, /* for_update_clause */ + YYSYMBOL_lock_shared_clause = 108, /* lock_shared_clause */ + YYSYMBOL_order_direction = 109, /* order_direction */ + YYSYMBOL_order_by_clause = 110, /* order_by_clause */ + YYSYMBOL_select_statement = 111, /* select_statement */ + YYSYMBOL_insert_statement_start = 112, /* insert_statement_start */ + YYSYMBOL_insert_statement = 113, /* insert_statement */ + YYSYMBOL_column_assignment = 114, /* column_assignment */ + YYSYMBOL_column_assignment_list = 115, /* column_assignment_list */ + YYSYMBOL_cursor_positioned = 116, /* cursor_positioned */ + YYSYMBOL_update_statement_start = 117, /* update_statement_start */ + YYSYMBOL_update_statement_searched = 118, /* update_statement_searched */ + YYSYMBOL_update_statement_positioned = 119, /* update_statement_positioned */ + YYSYMBOL_delete_statement_start = 120, /* delete_statement_start */ + YYSYMBOL_delete_statement_searched = 121, /* delete_statement_searched */ + YYSYMBOL_delete_statement_positioned = 122, /* delete_statement_positioned */ + YYSYMBOL_assignment_statement = 123, /* assignment_statement */ + YYSYMBOL_elsif_element = 124, /* elsif_element */ + YYSYMBOL_elsif_list = 125, /* elsif_list */ + YYSYMBOL_else_part = 126, /* else_part */ + YYSYMBOL_if_statement = 127, /* if_statement */ + YYSYMBOL_while_statement = 128, /* while_statement */ + YYSYMBOL_for_statement = 129, /* for_statement */ + YYSYMBOL_exit_statement = 130, /* exit_statement */ + YYSYMBOL_return_statement = 131, /* return_statement */ + YYSYMBOL_open_cursor_statement = 132, /* open_cursor_statement */ + YYSYMBOL_close_cursor_statement = 133, /* close_cursor_statement */ + YYSYMBOL_fetch_statement = 134, /* fetch_statement */ + YYSYMBOL_column_def = 135, /* column_def */ + YYSYMBOL_column_def_list = 136, /* column_def_list */ + YYSYMBOL_opt_column_len = 137, /* opt_column_len */ + YYSYMBOL_opt_not_null = 138, /* opt_not_null */ + YYSYMBOL_create_table = 139, /* create_table */ + YYSYMBOL_column_list = 140, /* column_list */ + YYSYMBOL_unique_def = 141, /* unique_def */ + YYSYMBOL_clustered_def = 142, /* clustered_def */ + YYSYMBOL_create_index = 143, /* create_index */ + YYSYMBOL_table_name = 144, /* table_name */ + YYSYMBOL_commit_statement = 145, /* commit_statement */ + YYSYMBOL_rollback_statement = 146, /* rollback_statement */ + YYSYMBOL_type_name = 147, /* type_name */ + YYSYMBOL_variable_declaration = 148, /* variable_declaration */ + YYSYMBOL_variable_declaration_list = 149, /* variable_declaration_list */ + YYSYMBOL_cursor_declaration = 150, /* cursor_declaration */ + YYSYMBOL_function_declaration = 151, /* function_declaration */ + YYSYMBOL_declaration = 152, /* declaration */ + YYSYMBOL_declaration_list = 153, /* declaration_list */ + YYSYMBOL_procedure_definition = 154 /* procedure_definition */ +}; +typedef enum yysymbol_kind_t yysymbol_kind_t; + + + + +#ifdef short +# undef short +#endif + +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + <limits.h> and (if available) <stdint.h> are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include <limits.h> /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include <stdint.h> /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif +#endif + +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; +#endif + +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; +#else +typedef short yytype_int16; +#endif + +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned +# endif +#endif + +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + + +/* Stored state numbers (used for stacks). */ +typedef yytype_int16 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + + +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YY_USE(E) ((void) (E)) +#else +# define YY_USE(E) /* empty */ +#endif + +#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_INITIAL_VALUE(Value) Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + + +#define YY_ASSERT(E) ((void) (0 && (E))) + +#if !defined yyoverflow + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include <alloca.h> /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include <malloc.h> /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* !defined yyoverflow */ + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yy_state_t yyss_alloc; + YYSTYPE yyvs_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +# define YYCOPY_NEEDED 1 + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYPTRDIFF_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ + } \ + while (0) + +#endif + +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYPTRDIFF_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 5 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 611 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 93 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 62 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 145 +/* YYNSTATES -- Number of states. */ +#define YYNSTATES 290 + +/* YYMAXUTOK -- Last valid token kind. */ +#define YYMAXUTOK 335 + + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ +static const yytype_int8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 88, 2, 2, + 90, 91, 85, 84, 92, 83, 2, 86, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 89, + 81, 80, 82, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 87 +}; + +#if YYDEBUG + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_int16 yyrline[] = +{ + 0, 140, 140, 143, 144, 145, 146, 147, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 165, 166, 171, 172, 174, 175, 176, 177, + 178, 179, 180, 181, 182, 183, 184, 185, 186, 188, + 189, 190, 191, 192, 193, 194, 195, 196, 198, 203, + 204, 205, 206, 207, 211, 215, 216, 221, 222, 223, + 228, 229, 230, 234, 235, 243, 244, 245, 250, 252, + 255, 259, 260, 264, 265, 270, 271, 276, 277, 278, + 282, 283, 290, 305, 310, 313, 321, 327, 328, 333, + 339, 348, 356, 364, 371, 379, 387, 394, 400, 401, + 406, 407, 409, 413, 420, 426, 436, 440, 444, 451, + 458, 462, 470, 479, 480, 485, 486, 491, 492, 498, + 506, 507, 512, 513, 517, 518, 522, 536, 537, 541, + 546, 551, 552, 553, 557, 563, 565, 566, 570, 578, + 584, 585, 588, 590, 591, 595 +}; +#endif + +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if YYDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "\"end of file\"", "error", "\"invalid token\"", "PARS_INT_LIT", + "PARS_FLOAT_LIT", "PARS_STR_LIT", "PARS_NULL_LIT", "PARS_ID_TOKEN", + "PARS_AND_TOKEN", "PARS_OR_TOKEN", "PARS_NOT_TOKEN", "PARS_GE_TOKEN", + "PARS_LE_TOKEN", "PARS_NE_TOKEN", "PARS_PROCEDURE_TOKEN", + "PARS_IN_TOKEN", "PARS_INT_TOKEN", "PARS_CHAR_TOKEN", "PARS_IS_TOKEN", + "PARS_BEGIN_TOKEN", "PARS_END_TOKEN", "PARS_IF_TOKEN", "PARS_THEN_TOKEN", + "PARS_ELSE_TOKEN", "PARS_ELSIF_TOKEN", "PARS_LOOP_TOKEN", + "PARS_WHILE_TOKEN", "PARS_RETURN_TOKEN", "PARS_SELECT_TOKEN", + "PARS_COUNT_TOKEN", "PARS_FROM_TOKEN", "PARS_WHERE_TOKEN", + "PARS_FOR_TOKEN", "PARS_DDOT_TOKEN", "PARS_ORDER_TOKEN", "PARS_BY_TOKEN", + "PARS_ASC_TOKEN", "PARS_DESC_TOKEN", "PARS_INSERT_TOKEN", + "PARS_INTO_TOKEN", "PARS_VALUES_TOKEN", "PARS_UPDATE_TOKEN", + "PARS_SET_TOKEN", "PARS_DELETE_TOKEN", "PARS_CURRENT_TOKEN", + "PARS_OF_TOKEN", "PARS_CREATE_TOKEN", "PARS_TABLE_TOKEN", + "PARS_INDEX_TOKEN", "PARS_UNIQUE_TOKEN", "PARS_CLUSTERED_TOKEN", + "PARS_ON_TOKEN", "PARS_ASSIGN_TOKEN", "PARS_DECLARE_TOKEN", + "PARS_CURSOR_TOKEN", "PARS_SQL_TOKEN", "PARS_OPEN_TOKEN", + "PARS_FETCH_TOKEN", "PARS_CLOSE_TOKEN", "PARS_NOTFOUND_TOKEN", + "PARS_TO_BINARY_TOKEN", "PARS_SUBSTR_TOKEN", "PARS_CONCAT_TOKEN", + "PARS_INSTR_TOKEN", "PARS_LENGTH_TOKEN", "PARS_COMMIT_TOKEN", + "PARS_ROLLBACK_TOKEN", "PARS_WORK_TOKEN", "PARS_EXIT_TOKEN", + "PARS_FUNCTION_TOKEN", "PARS_LOCK_TOKEN", "PARS_SHARE_TOKEN", + "PARS_MODE_TOKEN", "PARS_LIKE_TOKEN", "PARS_LIKE_TOKEN_EXACT", + "PARS_LIKE_TOKEN_PREFIX", "PARS_LIKE_TOKEN_SUFFIX", + "PARS_LIKE_TOKEN_SUBSTR", "PARS_TABLE_NAME_TOKEN", "PARS_BIGINT_TOKEN", + "'='", "'<'", "'>'", "'-'", "'+'", "'*'", "'/'", "NEG", "'%'", "';'", + "'('", "')'", "','", "$accept", "top_statement", "statement", + "statement_list", "exp", "function_name", "user_function_call", + "table_list", "variable_list", "exp_list", "select_item", + "select_item_list", "select_list", "search_condition", + "for_update_clause", "lock_shared_clause", "order_direction", + "order_by_clause", "select_statement", "insert_statement_start", + "insert_statement", "column_assignment", "column_assignment_list", + "cursor_positioned", "update_statement_start", + "update_statement_searched", "update_statement_positioned", + "delete_statement_start", "delete_statement_searched", + "delete_statement_positioned", "assignment_statement", "elsif_element", + "elsif_list", "else_part", "if_statement", "while_statement", + "for_statement", "exit_statement", "return_statement", + "open_cursor_statement", "close_cursor_statement", "fetch_statement", + "column_def", "column_def_list", "opt_column_len", "opt_not_null", + "create_table", "column_list", "unique_def", "clustered_def", + "create_index", "table_name", "commit_statement", "rollback_statement", + "type_name", "variable_declaration", "variable_declaration_list", + "cursor_declaration", "function_declaration", "declaration", + "declaration_list", "procedure_definition", YY_NULLPTR +}; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} +#endif + +#ifdef YYPRINT +/* YYTOKNUM[NUM] -- (External) token number corresponding to the + (internal) symbol number NUM (which must be that of a token). */ +static const yytype_int16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, + 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, + 61, 60, 62, 45, 43, 42, 47, 335, 37, 59, + 40, 41, 44 +}; +#endif + +#define YYPACT_NINF (-146) + +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) + +#define YYTABLE_NINF (-1) + +#define yytable_value_is_error(Yyn) \ + 0 + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int16 yypact[] = +{ + 8, 25, 40, -44, -43, -146, -146, -41, 37, 54, + 9, -146, 44, -146, -146, -146, -24, -30, -146, -146, + -146, -146, -5, -146, 63, 97, 543, -146, 93, 24, + 79, 148, 148, -146, 13, 126, 98, 0, 111, -3, + 135, 136, 138, 80, 83, -146, -146, 414, 67, -7, + 70, 130, 84, 85, 130, 86, 87, 88, 89, 90, + 91, 92, 94, 95, 99, 100, 104, 105, 107, 108, + 141, -146, 148, -146, -146, -146, -146, 112, 148, 119, + -146, -146, -146, -146, -146, 148, 148, 193, 123, 208, + 124, -146, 304, -146, -26, 152, 172, 0, -146, -146, + 181, 0, 0, -146, 174, -146, 186, -146, -146, -146, + -146, -146, -146, 137, -146, -146, 102, -146, -146, -146, + -146, -146, -146, -146, -146, -146, -146, -146, -146, -146, + -146, -146, -146, -146, -146, -146, -146, -146, 139, 304, + 167, -1, 170, 17, 159, 148, 148, 148, 148, 148, + 543, 225, 148, 148, 148, 148, 148, 148, 148, 148, + 543, 149, 228, 31, 0, 148, -146, 229, -146, 147, + -146, 198, 240, 148, 203, 304, -146, -146, -146, -146, + -1, -1, 16, 16, 304, 371, -146, 16, 16, 16, + 49, 49, 17, 17, 304, -64, 457, 158, -146, 160, + -146, -25, -146, 247, 171, -146, 161, 250, 254, 164, + -146, 160, -38, 255, 543, 148, -146, 239, 244, -146, + 148, 242, -146, 258, 148, 0, 236, 148, 148, 229, + 9, -146, -33, 218, 179, -146, -146, 543, 274, -146, + 251, 304, -146, -146, -146, 230, 214, 289, 304, -146, + 205, -146, 250, 0, -146, 543, -146, -146, 284, 269, + 543, 301, 295, -146, 216, 543, 237, 272, -146, 500, + 219, 303, -146, 311, 249, 312, 286, -146, -146, -146, + -28, -146, 103, -146, -146, 315, -146, -146, -146, -146 +}; + + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 0, 0, 0, 0, 0, 1, 2, 0, 0, 135, + 0, 136, 142, 131, 133, 132, 0, 0, 137, 140, + 141, 143, 0, 134, 0, 0, 0, 144, 0, 0, + 0, 0, 0, 107, 65, 0, 0, 0, 0, 122, + 0, 0, 0, 0, 0, 106, 22, 0, 0, 0, + 0, 71, 0, 0, 71, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 139, 0, 26, 27, 28, 29, 24, 0, 30, + 49, 50, 51, 52, 53, 0, 0, 0, 0, 0, + 0, 68, 63, 66, 70, 0, 0, 0, 127, 128, + 0, 0, 0, 123, 124, 108, 0, 109, 129, 130, + 145, 23, 9, 0, 85, 10, 0, 91, 92, 13, + 14, 94, 95, 11, 12, 8, 6, 3, 4, 5, + 7, 15, 17, 16, 20, 21, 18, 19, 0, 96, + 0, 46, 0, 35, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, + 0, 0, 57, 0, 0, 0, 83, 0, 93, 0, + 125, 0, 57, 60, 0, 72, 138, 47, 48, 36, + 44, 45, 41, 42, 43, 100, 38, 37, 39, 40, + 32, 31, 33, 34, 61, 0, 0, 0, 58, 69, + 67, 71, 55, 0, 0, 87, 90, 0, 0, 58, + 111, 110, 0, 0, 0, 0, 98, 102, 0, 25, + 0, 0, 64, 0, 0, 0, 73, 0, 0, 0, + 0, 113, 0, 0, 0, 84, 89, 101, 0, 99, + 0, 62, 104, 59, 56, 0, 75, 0, 86, 88, + 115, 119, 0, 0, 54, 0, 103, 74, 0, 80, + 0, 0, 117, 114, 0, 97, 0, 0, 82, 0, + 0, 0, 112, 0, 0, 0, 0, 116, 118, 120, + 0, 76, 77, 105, 126, 0, 78, 79, 81, 121 +}; + + /* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = +{ + -146, -146, -47, -145, -29, -146, -146, -146, 151, 153, + 162, -146, -146, -53, -146, -146, -146, -146, -18, -146, + -146, 106, -146, 270, -146, -146, -146, -146, -146, -146, + -146, 117, -146, -146, -146, -146, -146, -146, -146, -146, + -146, -146, 96, -146, -146, -146, -146, -146, -146, -146, + -146, -93, -146, -146, 109, 324, -146, -146, -146, 316, + -146, -146 +}; + + /* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + 0, 2, 46, 47, 92, 88, 210, 201, 199, 195, + 93, 94, 95, 117, 246, 259, 288, 268, 48, 49, + 50, 205, 206, 118, 51, 52, 53, 54, 55, 56, + 57, 216, 217, 218, 58, 59, 60, 61, 62, 63, + 64, 65, 231, 232, 262, 272, 66, 280, 104, 171, + 67, 100, 68, 69, 16, 11, 12, 19, 20, 21, + 22, 3 +}; + + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int16 yytable[] = +{ + 111, 121, 87, 89, 166, 185, 224, 98, 168, 169, + 147, 148, 149, 162, 26, 196, 73, 74, 75, 76, + 77, 34, 1, 78, 24, 13, 14, 219, 220, 149, + 149, 114, 4, 113, 73, 74, 75, 76, 77, 25, + 5, 78, 90, 139, 102, 6, 103, 7, 17, 141, + 8, 10, 138, 235, 220, 9, 143, 144, 251, 252, + 90, 10, 149, 284, 285, 23, 163, 225, 79, 237, + 28, 202, 151, 80, 81, 82, 83, 84, 99, 152, + 153, 154, 155, 156, 157, 158, 79, 175, 15, 151, + 151, 80, 81, 82, 83, 84, 85, 17, 91, 155, + 156, 157, 158, 86, 29, 73, 74, 75, 76, 77, + 265, 70, 78, 71, 85, 269, 180, 181, 182, 183, + 184, 86, 151, 187, 188, 189, 190, 191, 192, 193, + 194, 72, 244, 96, 157, 158, 203, 97, 111, 286, + 287, 101, 105, 106, 194, 107, 174, 108, 226, 111, + 109, 73, 74, 75, 76, 77, 112, 79, 78, 115, + 264, 116, 80, 81, 82, 83, 84, 145, 146, 34, + 147, 148, 149, 119, 120, 123, 124, 125, 126, 127, + 128, 129, 164, 130, 131, 85, 238, 165, 132, 133, + 111, 241, 86, 134, 135, 175, 136, 137, 247, 248, + 140, 145, 146, 79, 147, 148, 149, 142, 80, 81, + 82, 83, 84, 159, 161, 150, 145, 146, 111, 147, + 148, 149, 111, 167, 170, 172, 177, 173, 176, 178, + 186, 85, 151, 160, 197, 198, 204, 207, 86, 152, + 153, 154, 155, 156, 157, 158, 208, 209, 213, 222, + 179, 228, 223, 229, 234, 145, 146, 230, 147, 148, + 149, 233, 236, 215, 240, 243, 151, 242, 245, 253, + 254, 257, 256, 152, 153, 154, 155, 156, 157, 158, + 227, 151, 145, 146, 258, 147, 148, 149, 152, 153, + 154, 155, 156, 157, 158, 261, 255, 145, 146, 266, + 147, 148, 149, 267, 270, 271, 273, 275, 274, 278, + 277, 283, 145, 146, 260, 147, 148, 149, 279, 282, + 151, 281, 289, 211, 122, 200, 212, 152, 153, 154, + 155, 156, 157, 158, 239, 249, 18, 0, 27, 250, + 0, 0, 0, 0, 0, 0, 0, 151, 263, 0, + 0, 0, 0, 0, 152, 153, 154, 155, 156, 157, + 158, 0, 151, 0, 0, 0, 0, 0, 0, 152, + 153, 154, 155, 156, 157, 158, 0, 151, 30, 0, + 0, 0, 0, 0, 152, 153, 154, 155, 156, 157, + 158, 0, 31, 0, 214, 215, 0, 32, 33, 34, + 0, 0, 0, 35, 0, 0, 0, 0, 0, 36, + 0, 0, 37, 0, 38, 0, 0, 39, 0, 0, + 0, 30, 0, 0, 0, 0, 0, 40, 41, 42, + 0, 0, 0, 0, 110, 31, 43, 44, 0, 45, + 32, 33, 34, 0, 0, 0, 35, 0, 0, 0, + 0, 0, 36, 0, 0, 37, 0, 38, 0, 0, + 39, 0, 0, 0, 30, 0, 0, 0, 0, 0, + 40, 41, 42, 0, 0, 0, 0, 221, 31, 43, + 44, 0, 45, 32, 33, 34, 0, 0, 0, 35, + 0, 0, 0, 0, 0, 36, 0, 0, 37, 0, + 38, 0, 0, 39, 0, 0, 0, 30, 0, 0, + 0, 0, 0, 40, 41, 42, 0, 0, 0, 0, + 276, 31, 43, 44, 0, 45, 32, 33, 34, 0, + 0, 0, 35, 0, 0, 0, 0, 0, 36, 0, + 0, 37, 0, 38, 0, 0, 39, 0, 0, 0, + 30, 0, 0, 0, 0, 0, 40, 41, 42, 0, + 0, 0, 0, 0, 31, 43, 44, 0, 45, 32, + 33, 34, 0, 0, 0, 35, 0, 0, 0, 0, + 0, 36, 0, 0, 37, 0, 38, 0, 0, 39, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, + 41, 42, 0, 0, 0, 0, 0, 0, 43, 44, + 0, 45 +}; + +static const yytype_int16 yycheck[] = +{ + 47, 54, 31, 32, 97, 150, 31, 7, 101, 102, + 11, 12, 13, 39, 19, 160, 3, 4, 5, 6, + 7, 28, 14, 10, 54, 16, 17, 91, 92, 13, + 13, 49, 7, 40, 3, 4, 5, 6, 7, 69, + 0, 10, 29, 72, 47, 89, 49, 90, 53, 78, + 91, 7, 70, 91, 92, 18, 85, 86, 91, 92, + 29, 7, 13, 91, 92, 89, 92, 92, 55, 214, + 7, 164, 73, 60, 61, 62, 63, 64, 78, 80, + 81, 82, 83, 84, 85, 86, 55, 116, 79, 73, + 73, 60, 61, 62, 63, 64, 83, 53, 85, 83, + 84, 85, 86, 90, 7, 3, 4, 5, 6, 7, + 255, 18, 10, 89, 83, 260, 145, 146, 147, 148, + 149, 90, 73, 152, 153, 154, 155, 156, 157, 158, + 159, 52, 225, 7, 85, 86, 165, 39, 185, 36, + 37, 30, 7, 7, 173, 7, 44, 67, 201, 196, + 67, 3, 4, 5, 6, 7, 89, 55, 10, 89, + 253, 31, 60, 61, 62, 63, 64, 8, 9, 28, + 11, 12, 13, 89, 89, 89, 89, 89, 89, 89, + 89, 89, 30, 89, 89, 83, 215, 15, 89, 89, + 237, 220, 90, 89, 89, 224, 89, 89, 227, 228, + 88, 8, 9, 55, 11, 12, 13, 88, 60, 61, + 62, 63, 64, 90, 90, 22, 8, 9, 265, 11, + 12, 13, 269, 42, 50, 39, 59, 90, 89, 59, + 5, 83, 73, 25, 85, 7, 7, 90, 90, 80, + 81, 82, 83, 84, 85, 86, 48, 7, 45, 91, + 91, 80, 92, 92, 90, 8, 9, 7, 11, 12, + 13, 7, 7, 24, 20, 7, 73, 25, 32, 51, + 91, 41, 21, 80, 81, 82, 83, 84, 85, 86, + 33, 73, 8, 9, 70, 11, 12, 13, 80, 81, + 82, 83, 84, 85, 86, 90, 22, 8, 9, 15, + 11, 12, 13, 34, 3, 10, 90, 35, 71, 6, + 91, 25, 8, 9, 25, 11, 12, 13, 7, 7, + 73, 72, 7, 172, 54, 163, 173, 80, 81, 82, + 83, 84, 85, 86, 217, 229, 12, -1, 22, 230, + -1, -1, -1, -1, -1, -1, -1, 73, 252, -1, + -1, -1, -1, -1, 80, 81, 82, 83, 84, 85, + 86, -1, 73, -1, -1, -1, -1, -1, -1, 80, + 81, 82, 83, 84, 85, 86, -1, 73, 7, -1, + -1, -1, -1, -1, 80, 81, 82, 83, 84, 85, + 86, -1, 21, -1, 23, 24, -1, 26, 27, 28, + -1, -1, -1, 32, -1, -1, -1, -1, -1, 38, + -1, -1, 41, -1, 43, -1, -1, 46, -1, -1, + -1, 7, -1, -1, -1, -1, -1, 56, 57, 58, + -1, -1, -1, -1, 20, 21, 65, 66, -1, 68, + 26, 27, 28, -1, -1, -1, 32, -1, -1, -1, + -1, -1, 38, -1, -1, 41, -1, 43, -1, -1, + 46, -1, -1, -1, 7, -1, -1, -1, -1, -1, + 56, 57, 58, -1, -1, -1, -1, 20, 21, 65, + 66, -1, 68, 26, 27, 28, -1, -1, -1, 32, + -1, -1, -1, -1, -1, 38, -1, -1, 41, -1, + 43, -1, -1, 46, -1, -1, -1, 7, -1, -1, + -1, -1, -1, 56, 57, 58, -1, -1, -1, -1, + 20, 21, 65, 66, -1, 68, 26, 27, 28, -1, + -1, -1, 32, -1, -1, -1, -1, -1, 38, -1, + -1, 41, -1, 43, -1, -1, 46, -1, -1, -1, + 7, -1, -1, -1, -1, -1, 56, 57, 58, -1, + -1, -1, -1, -1, 21, 65, 66, -1, 68, 26, + 27, 28, -1, -1, -1, 32, -1, -1, -1, -1, + -1, 38, -1, -1, 41, -1, 43, -1, -1, 46, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 56, + 57, 58, -1, -1, -1, -1, -1, -1, 65, 66, + -1, 68 +}; + + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 14, 94, 154, 7, 0, 89, 90, 91, 18, + 7, 148, 149, 16, 17, 79, 147, 53, 148, 150, + 151, 152, 153, 89, 54, 69, 19, 152, 7, 7, + 7, 21, 26, 27, 28, 32, 38, 41, 43, 46, + 56, 57, 58, 65, 66, 68, 95, 96, 111, 112, + 113, 117, 118, 119, 120, 121, 122, 123, 127, 128, + 129, 130, 131, 132, 133, 134, 139, 143, 145, 146, + 18, 89, 52, 3, 4, 5, 6, 7, 10, 55, + 60, 61, 62, 63, 64, 83, 90, 97, 98, 97, + 29, 85, 97, 103, 104, 105, 7, 39, 7, 78, + 144, 30, 47, 49, 141, 7, 7, 7, 67, 67, + 20, 95, 89, 40, 111, 89, 31, 106, 116, 89, + 89, 106, 116, 89, 89, 89, 89, 89, 89, 89, + 89, 89, 89, 89, 89, 89, 89, 89, 111, 97, + 88, 97, 88, 97, 97, 8, 9, 11, 12, 13, + 22, 73, 80, 81, 82, 83, 84, 85, 86, 90, + 25, 90, 39, 92, 30, 15, 144, 42, 144, 144, + 50, 142, 39, 90, 44, 97, 89, 59, 59, 91, + 97, 97, 97, 97, 97, 96, 5, 97, 97, 97, + 97, 97, 97, 97, 97, 102, 96, 85, 7, 101, + 103, 100, 144, 97, 7, 114, 115, 90, 48, 7, + 99, 101, 102, 45, 23, 24, 124, 125, 126, 91, + 92, 20, 91, 92, 31, 92, 106, 33, 80, 92, + 7, 135, 136, 7, 90, 91, 7, 96, 97, 124, + 20, 97, 25, 7, 144, 32, 107, 97, 97, 114, + 147, 91, 92, 51, 91, 22, 21, 41, 70, 108, + 25, 90, 137, 135, 144, 96, 15, 34, 110, 96, + 3, 10, 138, 90, 71, 35, 20, 91, 6, 7, + 140, 72, 7, 25, 91, 92, 36, 37, 109, 7 +}; + + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 93, 94, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 96, 96, 97, 97, 97, 97, 97, 97, + 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, + 97, 97, 97, 97, 97, 97, 97, 97, 97, 98, + 98, 98, 98, 98, 99, 100, 100, 101, 101, 101, + 102, 102, 102, 103, 103, 104, 104, 104, 105, 105, + 105, 106, 106, 107, 107, 108, 108, 109, 109, 109, + 110, 110, 111, 112, 113, 113, 114, 115, 115, 116, + 117, 118, 119, 120, 121, 122, 123, 124, 125, 125, + 126, 126, 126, 127, 128, 129, 130, 131, 132, 133, + 134, 134, 135, 136, 136, 137, 137, 138, 138, 139, + 140, 140, 141, 141, 142, 142, 143, 144, 144, 145, + 146, 147, 147, 147, 148, 149, 149, 149, 150, 151, + 152, 152, 153, 153, 153, 154 +}; + + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_int8 yyr2[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 1, 2, 1, 4, 1, 1, 1, 1, + 1, 3, 3, 3, 3, 2, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 2, 3, 3, 1, + 1, 1, 1, 1, 3, 1, 3, 0, 1, 3, + 0, 1, 3, 1, 4, 0, 1, 3, 1, 3, + 1, 0, 2, 0, 2, 0, 4, 0, 1, 1, + 0, 4, 8, 3, 5, 2, 3, 1, 3, 4, + 4, 2, 2, 3, 2, 2, 3, 4, 1, 2, + 0, 2, 1, 7, 6, 10, 1, 1, 2, 2, + 4, 4, 4, 1, 3, 0, 3, 0, 2, 6, + 1, 3, 0, 1, 0, 1, 10, 1, 1, 2, + 2, 1, 1, 1, 3, 0, 1, 2, 6, 4, + 1, 1, 0, 1, 2, 10 +}; + + +enum { YYENOMEM = -2 }; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) + +/* Backward compatibility with an undocumented macro. + Use YYerror or YYUNDEF. */ +#define YYERRCODE YYUNDEF + + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +/* This macro is provided for backward compatibility. */ +# ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif + + +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Kind, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + + +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ + +static void +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +{ + FILE *yyoutput = yyo; + YY_USE (yyoutput); + if (!yyvaluep) + return; +# ifdef YYPRINT + if (yykind < YYNTOKENS) + YYPRINT (yyo, yytoknum[yykind], *yyvaluep); +# endif + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ + +static void +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +{ + YYFPRINTF (yyo, "%s %s (", + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); + + yy_symbol_value_print (yyo, yykind, yyvaluep); + YYFPRINTF (yyo, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +static void +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +static void +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, + int yyrule) +{ + int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; + int yyi; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)]); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + + + + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +static void +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep) +{ + YY_USE (yyvaluep); + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + +/* Lookahead token kind. */ +static int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; +/* Number of syntax errors so far. */ +static int yynerrs; + + + + +/*----------. +| yyparse. | +`----------*/ + +int +yyparse (void) +{ + yy_state_fast_t yystate = 0; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus = 0; + + /* Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; + + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; + + /* The semantic value stack: array, bottom, top. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; + + int yyn; + /* The return value of yyparse. */ + int yyresult; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + + + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yychar = YYEMPTY; /* Cause a token to be read. */ + goto yysetstate; + + +/*------------------------------------------------------------. +| yynewstate -- push a new state, which is found in yystate. | +`------------------------------------------------------------*/ +yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + +/*--------------------------------------------------------------------. +| yysetstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); + + if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + goto yyexhaustedlab; +#else + { + /* Get the current used size of the three stacks, in elements. */ + YYPTRDIFF_T yysize = yyssp - yyss + 1; + +# if defined yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yystacksize); + yyss = yyss1; + yyvs = yyvs1; + } +# else /* defined YYSTACK_RELOCATE */ + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yy_state_t *yyss1 = yyss; + union yyalloc *yyptr = + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token\n")); + yychar = yylex (); + } + + if (yychar <= YYEOF) + { + yychar = YYEOF; + yytoken = YYSYMBOL_YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else if (yychar == YYerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = YYUNDEF; + yytoken = YYSYMBOL_YYerror; + goto yyerrlab1; + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + /* Discard the shifted token. */ + yychar = YYEMPTY; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 22: /* statement_list: statement */ +#line 165 "pars0grm.y" + { yyval = que_node_list_add_last(NULL, yyvsp[0]); } +#line 1545 "pars0grm.cc" + break; + + case 23: /* statement_list: statement_list statement */ +#line 167 "pars0grm.y" + { yyval = que_node_list_add_last(yyvsp[-1], yyvsp[0]); } +#line 1551 "pars0grm.cc" + break; + + case 24: /* exp: PARS_ID_TOKEN */ +#line 171 "pars0grm.y" + { yyval = yyvsp[0];} +#line 1557 "pars0grm.cc" + break; + + case 25: /* exp: function_name '(' exp_list ')' */ +#line 173 "pars0grm.y" + { yyval = pars_func(yyvsp[-3], yyvsp[-1]); } +#line 1563 "pars0grm.cc" + break; + + case 26: /* exp: PARS_INT_LIT */ +#line 174 "pars0grm.y" + { yyval = yyvsp[0];} +#line 1569 "pars0grm.cc" + break; + + case 27: /* exp: PARS_FLOAT_LIT */ +#line 175 "pars0grm.y" + { yyval = yyvsp[0];} +#line 1575 "pars0grm.cc" + break; + + case 28: /* exp: PARS_STR_LIT */ +#line 176 "pars0grm.y" + { yyval = yyvsp[0];} +#line 1581 "pars0grm.cc" + break; + + case 29: /* exp: PARS_NULL_LIT */ +#line 177 "pars0grm.y" + { yyval = yyvsp[0];} +#line 1587 "pars0grm.cc" + break; + + case 30: /* exp: PARS_SQL_TOKEN */ +#line 178 "pars0grm.y" + { yyval = yyvsp[0];} +#line 1593 "pars0grm.cc" + break; + + case 31: /* exp: exp '+' exp */ +#line 179 "pars0grm.y" + { yyval = pars_op('+', yyvsp[-2], yyvsp[0]); } +#line 1599 "pars0grm.cc" + break; + + case 32: /* exp: exp '-' exp */ +#line 180 "pars0grm.y" + { yyval = pars_op('-', yyvsp[-2], yyvsp[0]); } +#line 1605 "pars0grm.cc" + break; + + case 33: /* exp: exp '*' exp */ +#line 181 "pars0grm.y" + { yyval = pars_op('*', yyvsp[-2], yyvsp[0]); } +#line 1611 "pars0grm.cc" + break; + + case 34: /* exp: exp '/' exp */ +#line 182 "pars0grm.y" + { yyval = pars_op('/', yyvsp[-2], yyvsp[0]); } +#line 1617 "pars0grm.cc" + break; + + case 35: /* exp: '-' exp */ +#line 183 "pars0grm.y" + { yyval = pars_op('-', yyvsp[0], NULL); } +#line 1623 "pars0grm.cc" + break; + + case 36: /* exp: '(' exp ')' */ +#line 184 "pars0grm.y" + { yyval = yyvsp[-1]; } +#line 1629 "pars0grm.cc" + break; + + case 37: /* exp: exp '=' exp */ +#line 185 "pars0grm.y" + { yyval = pars_op('=', yyvsp[-2], yyvsp[0]); } +#line 1635 "pars0grm.cc" + break; + + case 38: /* exp: exp PARS_LIKE_TOKEN PARS_STR_LIT */ +#line 187 "pars0grm.y" + { yyval = pars_op(PARS_LIKE_TOKEN, yyvsp[-2], yyvsp[0]); } +#line 1641 "pars0grm.cc" + break; + + case 39: /* exp: exp '<' exp */ +#line 188 "pars0grm.y" + { yyval = pars_op('<', yyvsp[-2], yyvsp[0]); } +#line 1647 "pars0grm.cc" + break; + + case 40: /* exp: exp '>' exp */ +#line 189 "pars0grm.y" + { yyval = pars_op('>', yyvsp[-2], yyvsp[0]); } +#line 1653 "pars0grm.cc" + break; + + case 41: /* exp: exp PARS_GE_TOKEN exp */ +#line 190 "pars0grm.y" + { yyval = pars_op(PARS_GE_TOKEN, yyvsp[-2], yyvsp[0]); } +#line 1659 "pars0grm.cc" + break; + + case 42: /* exp: exp PARS_LE_TOKEN exp */ +#line 191 "pars0grm.y" + { yyval = pars_op(PARS_LE_TOKEN, yyvsp[-2], yyvsp[0]); } +#line 1665 "pars0grm.cc" + break; + + case 43: /* exp: exp PARS_NE_TOKEN exp */ +#line 192 "pars0grm.y" + { yyval = pars_op(PARS_NE_TOKEN, yyvsp[-2], yyvsp[0]); } +#line 1671 "pars0grm.cc" + break; + + case 44: /* exp: exp PARS_AND_TOKEN exp */ +#line 193 "pars0grm.y" + { yyval = pars_op(PARS_AND_TOKEN, yyvsp[-2], yyvsp[0]); } +#line 1677 "pars0grm.cc" + break; + + case 45: /* exp: exp PARS_OR_TOKEN exp */ +#line 194 "pars0grm.y" + { yyval = pars_op(PARS_OR_TOKEN, yyvsp[-2], yyvsp[0]); } +#line 1683 "pars0grm.cc" + break; + + case 46: /* exp: PARS_NOT_TOKEN exp */ +#line 195 "pars0grm.y" + { yyval = pars_op(PARS_NOT_TOKEN, yyvsp[0], NULL); } +#line 1689 "pars0grm.cc" + break; + + case 47: /* exp: PARS_ID_TOKEN '%' PARS_NOTFOUND_TOKEN */ +#line 197 "pars0grm.y" + { yyval = pars_op(PARS_NOTFOUND_TOKEN, yyvsp[-2], NULL); } +#line 1695 "pars0grm.cc" + break; + + case 48: /* exp: PARS_SQL_TOKEN '%' PARS_NOTFOUND_TOKEN */ +#line 199 "pars0grm.y" + { yyval = pars_op(PARS_NOTFOUND_TOKEN, yyvsp[-2], NULL); } +#line 1701 "pars0grm.cc" + break; + + case 49: /* function_name: PARS_TO_BINARY_TOKEN */ +#line 203 "pars0grm.y" + { yyval = &pars_to_binary_token; } +#line 1707 "pars0grm.cc" + break; + + case 50: /* function_name: PARS_SUBSTR_TOKEN */ +#line 204 "pars0grm.y" + { yyval = &pars_substr_token; } +#line 1713 "pars0grm.cc" + break; + + case 51: /* function_name: PARS_CONCAT_TOKEN */ +#line 205 "pars0grm.y" + { yyval = &pars_concat_token; } +#line 1719 "pars0grm.cc" + break; + + case 52: /* function_name: PARS_INSTR_TOKEN */ +#line 206 "pars0grm.y" + { yyval = &pars_instr_token; } +#line 1725 "pars0grm.cc" + break; + + case 53: /* function_name: PARS_LENGTH_TOKEN */ +#line 207 "pars0grm.y" + { yyval = &pars_length_token; } +#line 1731 "pars0grm.cc" + break; + + case 54: /* user_function_call: PARS_ID_TOKEN '(' ')' */ +#line 211 "pars0grm.y" + { yyval = yyvsp[-2]; } +#line 1737 "pars0grm.cc" + break; + + case 55: /* table_list: table_name */ +#line 215 "pars0grm.y" + { yyval = que_node_list_add_last(NULL, yyvsp[0]); } +#line 1743 "pars0grm.cc" + break; + + case 56: /* table_list: table_list ',' table_name */ +#line 217 "pars0grm.y" + { yyval = que_node_list_add_last(yyvsp[-2], yyvsp[0]); } +#line 1749 "pars0grm.cc" + break; + + case 57: /* variable_list: %empty */ +#line 221 "pars0grm.y" + { yyval = NULL; } +#line 1755 "pars0grm.cc" + break; + + case 58: /* variable_list: PARS_ID_TOKEN */ +#line 222 "pars0grm.y" + { yyval = que_node_list_add_last(NULL, yyvsp[0]); } +#line 1761 "pars0grm.cc" + break; + + case 59: /* variable_list: variable_list ',' PARS_ID_TOKEN */ +#line 224 "pars0grm.y" + { yyval = que_node_list_add_last(yyvsp[-2], yyvsp[0]); } +#line 1767 "pars0grm.cc" + break; + + case 60: /* exp_list: %empty */ +#line 228 "pars0grm.y" + { yyval = NULL; } +#line 1773 "pars0grm.cc" + break; + + case 61: /* exp_list: exp */ +#line 229 "pars0grm.y" + { yyval = que_node_list_add_last(NULL, yyvsp[0]);} +#line 1779 "pars0grm.cc" + break; + + case 62: /* exp_list: exp_list ',' exp */ +#line 230 "pars0grm.y" + { yyval = que_node_list_add_last(yyvsp[-2], yyvsp[0]); } +#line 1785 "pars0grm.cc" + break; + + case 63: /* select_item: exp */ +#line 234 "pars0grm.y" + { yyval = yyvsp[0]; } +#line 1791 "pars0grm.cc" + break; + + case 64: /* select_item: PARS_COUNT_TOKEN '(' '*' ')' */ +#line 236 "pars0grm.y" + { yyval = pars_func(&pars_count_token, + que_node_list_add_last(NULL, + sym_tab_add_int_lit( + pars_sym_tab_global, 1))); } +#line 1800 "pars0grm.cc" + break; + + case 65: /* select_item_list: %empty */ +#line 243 "pars0grm.y" + { yyval = NULL; } +#line 1806 "pars0grm.cc" + break; + + case 66: /* select_item_list: select_item */ +#line 244 "pars0grm.y" + { yyval = que_node_list_add_last(NULL, yyvsp[0]); } +#line 1812 "pars0grm.cc" + break; + + case 67: /* select_item_list: select_item_list ',' select_item */ +#line 246 "pars0grm.y" + { yyval = que_node_list_add_last(yyvsp[-2], yyvsp[0]); } +#line 1818 "pars0grm.cc" + break; + + case 68: /* select_list: '*' */ +#line 250 "pars0grm.y" + { yyval = pars_select_list(&pars_star_denoter, + NULL); } +#line 1825 "pars0grm.cc" + break; + + case 69: /* select_list: select_item_list PARS_INTO_TOKEN variable_list */ +#line 253 "pars0grm.y" + { yyval = pars_select_list( + yyvsp[-2], static_cast<sym_node_t*>(yyvsp[0])); } +#line 1832 "pars0grm.cc" + break; + + case 70: /* select_list: select_item_list */ +#line 255 "pars0grm.y" + { yyval = pars_select_list(yyvsp[0], NULL); } +#line 1838 "pars0grm.cc" + break; + + case 71: /* search_condition: %empty */ +#line 259 "pars0grm.y" + { yyval = NULL; } +#line 1844 "pars0grm.cc" + break; + + case 72: /* search_condition: PARS_WHERE_TOKEN exp */ +#line 260 "pars0grm.y" + { yyval = yyvsp[0]; } +#line 1850 "pars0grm.cc" + break; + + case 73: /* for_update_clause: %empty */ +#line 264 "pars0grm.y" + { yyval = NULL; } +#line 1856 "pars0grm.cc" + break; + + case 74: /* for_update_clause: PARS_FOR_TOKEN PARS_UPDATE_TOKEN */ +#line 266 "pars0grm.y" + { yyval = &pars_update_token; } +#line 1862 "pars0grm.cc" + break; + + case 75: /* lock_shared_clause: %empty */ +#line 270 "pars0grm.y" + { yyval = NULL; } +#line 1868 "pars0grm.cc" + break; + + case 76: /* lock_shared_clause: PARS_LOCK_TOKEN PARS_IN_TOKEN PARS_SHARE_TOKEN PARS_MODE_TOKEN */ +#line 272 "pars0grm.y" + { yyval = &pars_share_token; } +#line 1874 "pars0grm.cc" + break; + + case 77: /* order_direction: %empty */ +#line 276 "pars0grm.y" + { yyval = &pars_asc_token; } +#line 1880 "pars0grm.cc" + break; + + case 78: /* order_direction: PARS_ASC_TOKEN */ +#line 277 "pars0grm.y" + { yyval = &pars_asc_token; } +#line 1886 "pars0grm.cc" + break; + + case 79: /* order_direction: PARS_DESC_TOKEN */ +#line 278 "pars0grm.y" + { yyval = &pars_desc_token; } +#line 1892 "pars0grm.cc" + break; + + case 80: /* order_by_clause: %empty */ +#line 282 "pars0grm.y" + { yyval = NULL; } +#line 1898 "pars0grm.cc" + break; + + case 81: /* order_by_clause: PARS_ORDER_TOKEN PARS_BY_TOKEN PARS_ID_TOKEN order_direction */ +#line 284 "pars0grm.y" + { yyval = pars_order_by( + static_cast<sym_node_t*>(yyvsp[-1]), + static_cast<pars_res_word_t*>(yyvsp[0])); } +#line 1906 "pars0grm.cc" + break; + + case 82: /* select_statement: PARS_SELECT_TOKEN select_list PARS_FROM_TOKEN table_list search_condition for_update_clause lock_shared_clause order_by_clause */ +#line 295 "pars0grm.y" + { yyval = pars_select_statement( + static_cast<sel_node_t*>(yyvsp[-6]), + static_cast<sym_node_t*>(yyvsp[-4]), + static_cast<que_node_t*>(yyvsp[-3]), + static_cast<pars_res_word_t*>(yyvsp[-2]), + static_cast<pars_res_word_t*>(yyvsp[-1]), + static_cast<order_node_t*>(yyvsp[0])); } +#line 1918 "pars0grm.cc" + break; + + case 83: /* insert_statement_start: PARS_INSERT_TOKEN PARS_INTO_TOKEN table_name */ +#line 306 "pars0grm.y" + { yyval = yyvsp[0]; } +#line 1924 "pars0grm.cc" + break; + + case 84: /* insert_statement: insert_statement_start PARS_VALUES_TOKEN '(' exp_list ')' */ +#line 311 "pars0grm.y" + { yyval = pars_insert_statement( + static_cast<sym_node_t*>(yyvsp[-4]), yyvsp[-1], NULL); } +#line 1931 "pars0grm.cc" + break; + + case 85: /* insert_statement: insert_statement_start select_statement */ +#line 314 "pars0grm.y" + { yyval = pars_insert_statement( + static_cast<sym_node_t*>(yyvsp[-1]), + NULL, + static_cast<sel_node_t*>(yyvsp[0])); } +#line 1940 "pars0grm.cc" + break; + + case 86: /* column_assignment: PARS_ID_TOKEN '=' exp */ +#line 321 "pars0grm.y" + { yyval = pars_column_assignment( + static_cast<sym_node_t*>(yyvsp[-2]), + static_cast<que_node_t*>(yyvsp[0])); } +#line 1948 "pars0grm.cc" + break; + + case 87: /* column_assignment_list: column_assignment */ +#line 327 "pars0grm.y" + { yyval = que_node_list_add_last(NULL, yyvsp[0]); } +#line 1954 "pars0grm.cc" + break; + + case 88: /* column_assignment_list: column_assignment_list ',' column_assignment */ +#line 329 "pars0grm.y" + { yyval = que_node_list_add_last(yyvsp[-2], yyvsp[0]); } +#line 1960 "pars0grm.cc" + break; + + case 89: /* cursor_positioned: PARS_WHERE_TOKEN PARS_CURRENT_TOKEN PARS_OF_TOKEN PARS_ID_TOKEN */ +#line 335 "pars0grm.y" + { yyval = yyvsp[0]; } +#line 1966 "pars0grm.cc" + break; + + case 90: /* update_statement_start: PARS_UPDATE_TOKEN table_name PARS_SET_TOKEN column_assignment_list */ +#line 341 "pars0grm.y" + { yyval = pars_update_statement_start( + FALSE, + static_cast<sym_node_t*>(yyvsp[-2]), + static_cast<col_assign_node_t*>(yyvsp[0])); } +#line 1975 "pars0grm.cc" + break; + + case 91: /* update_statement_searched: update_statement_start search_condition */ +#line 349 "pars0grm.y" + { yyval = pars_update_statement( + static_cast<upd_node_t*>(yyvsp[-1]), + NULL, + static_cast<que_node_t*>(yyvsp[0])); } +#line 1984 "pars0grm.cc" + break; + + case 92: /* update_statement_positioned: update_statement_start cursor_positioned */ +#line 357 "pars0grm.y" + { yyval = pars_update_statement( + static_cast<upd_node_t*>(yyvsp[-1]), + static_cast<sym_node_t*>(yyvsp[0]), + NULL); } +#line 1993 "pars0grm.cc" + break; + + case 93: /* delete_statement_start: PARS_DELETE_TOKEN PARS_FROM_TOKEN table_name */ +#line 365 "pars0grm.y" + { yyval = pars_update_statement_start( + TRUE, + static_cast<sym_node_t*>(yyvsp[0]), NULL); } +#line 2001 "pars0grm.cc" + break; + + case 94: /* delete_statement_searched: delete_statement_start search_condition */ +#line 372 "pars0grm.y" + { yyval = pars_update_statement( + static_cast<upd_node_t*>(yyvsp[-1]), + NULL, + static_cast<que_node_t*>(yyvsp[0])); } +#line 2010 "pars0grm.cc" + break; + + case 95: /* delete_statement_positioned: delete_statement_start cursor_positioned */ +#line 380 "pars0grm.y" + { yyval = pars_update_statement( + static_cast<upd_node_t*>(yyvsp[-1]), + static_cast<sym_node_t*>(yyvsp[0]), + NULL); } +#line 2019 "pars0grm.cc" + break; + + case 96: /* assignment_statement: PARS_ID_TOKEN PARS_ASSIGN_TOKEN exp */ +#line 388 "pars0grm.y" + { yyval = pars_assignment_statement( + static_cast<sym_node_t*>(yyvsp[-2]), + static_cast<que_node_t*>(yyvsp[0])); } +#line 2027 "pars0grm.cc" + break; + + case 97: /* elsif_element: PARS_ELSIF_TOKEN exp PARS_THEN_TOKEN statement_list */ +#line 396 "pars0grm.y" + { yyval = pars_elsif_element(yyvsp[-2], yyvsp[0]); } +#line 2033 "pars0grm.cc" + break; + + case 98: /* elsif_list: elsif_element */ +#line 400 "pars0grm.y" + { yyval = que_node_list_add_last(NULL, yyvsp[0]); } +#line 2039 "pars0grm.cc" + break; + + case 99: /* elsif_list: elsif_list elsif_element */ +#line 402 "pars0grm.y" + { yyval = que_node_list_add_last(yyvsp[-1], yyvsp[0]); } +#line 2045 "pars0grm.cc" + break; + + case 100: /* else_part: %empty */ +#line 406 "pars0grm.y" + { yyval = NULL; } +#line 2051 "pars0grm.cc" + break; + + case 101: /* else_part: PARS_ELSE_TOKEN statement_list */ +#line 408 "pars0grm.y" + { yyval = yyvsp[0]; } +#line 2057 "pars0grm.cc" + break; + + case 102: /* else_part: elsif_list */ +#line 409 "pars0grm.y" + { yyval = yyvsp[0]; } +#line 2063 "pars0grm.cc" + break; + + case 103: /* if_statement: PARS_IF_TOKEN exp PARS_THEN_TOKEN statement_list else_part PARS_END_TOKEN PARS_IF_TOKEN */ +#line 416 "pars0grm.y" + { yyval = pars_if_statement(yyvsp[-5], yyvsp[-3], yyvsp[-2]); } +#line 2069 "pars0grm.cc" + break; + + case 104: /* while_statement: PARS_WHILE_TOKEN exp PARS_LOOP_TOKEN statement_list PARS_END_TOKEN PARS_LOOP_TOKEN */ +#line 422 "pars0grm.y" + { yyval = pars_while_statement(yyvsp[-4], yyvsp[-2]); } +#line 2075 "pars0grm.cc" + break; + + case 105: /* for_statement: PARS_FOR_TOKEN PARS_ID_TOKEN PARS_IN_TOKEN exp PARS_DDOT_TOKEN exp PARS_LOOP_TOKEN statement_list PARS_END_TOKEN PARS_LOOP_TOKEN */ +#line 430 "pars0grm.y" + { yyval = pars_for_statement( + static_cast<sym_node_t*>(yyvsp[-8]), + yyvsp[-6], yyvsp[-4], yyvsp[-2]); } +#line 2083 "pars0grm.cc" + break; + + case 106: /* exit_statement: PARS_EXIT_TOKEN */ +#line 436 "pars0grm.y" + { yyval = pars_exit_statement(); } +#line 2089 "pars0grm.cc" + break; + + case 107: /* return_statement: PARS_RETURN_TOKEN */ +#line 440 "pars0grm.y" + { yyval = pars_return_statement(); } +#line 2095 "pars0grm.cc" + break; + + case 108: /* open_cursor_statement: PARS_OPEN_TOKEN PARS_ID_TOKEN */ +#line 445 "pars0grm.y" + { yyval = pars_open_statement( + ROW_SEL_OPEN_CURSOR, + static_cast<sym_node_t*>(yyvsp[0])); } +#line 2103 "pars0grm.cc" + break; + + case 109: /* close_cursor_statement: PARS_CLOSE_TOKEN PARS_ID_TOKEN */ +#line 452 "pars0grm.y" + { yyval = pars_open_statement( + ROW_SEL_CLOSE_CURSOR, + static_cast<sym_node_t*>(yyvsp[0])); } +#line 2111 "pars0grm.cc" + break; + + case 110: /* fetch_statement: PARS_FETCH_TOKEN PARS_ID_TOKEN PARS_INTO_TOKEN variable_list */ +#line 459 "pars0grm.y" + { yyval = pars_fetch_statement( + static_cast<sym_node_t*>(yyvsp[-2]), + static_cast<sym_node_t*>(yyvsp[0]), NULL); } +#line 2119 "pars0grm.cc" + break; + + case 111: /* fetch_statement: PARS_FETCH_TOKEN PARS_ID_TOKEN PARS_INTO_TOKEN user_function_call */ +#line 463 "pars0grm.y" + { yyval = pars_fetch_statement( + static_cast<sym_node_t*>(yyvsp[-2]), + NULL, + static_cast<sym_node_t*>(yyvsp[0])); } +#line 2128 "pars0grm.cc" + break; + + case 112: /* column_def: PARS_ID_TOKEN type_name opt_column_len opt_not_null */ +#line 471 "pars0grm.y" + { yyval = pars_column_def( + static_cast<sym_node_t*>(yyvsp[-3]), + static_cast<pars_res_word_t*>(yyvsp[-2]), + static_cast<sym_node_t*>(yyvsp[-1]), + yyvsp[0]); } +#line 2138 "pars0grm.cc" + break; + + case 113: /* column_def_list: column_def */ +#line 479 "pars0grm.y" + { yyval = que_node_list_add_last(NULL, yyvsp[0]); } +#line 2144 "pars0grm.cc" + break; + + case 114: /* column_def_list: column_def_list ',' column_def */ +#line 481 "pars0grm.y" + { yyval = que_node_list_add_last(yyvsp[-2], yyvsp[0]); } +#line 2150 "pars0grm.cc" + break; + + case 115: /* opt_column_len: %empty */ +#line 485 "pars0grm.y" + { yyval = NULL; } +#line 2156 "pars0grm.cc" + break; + + case 116: /* opt_column_len: '(' PARS_INT_LIT ')' */ +#line 487 "pars0grm.y" + { yyval = yyvsp[-1]; } +#line 2162 "pars0grm.cc" + break; + + case 117: /* opt_not_null: %empty */ +#line 491 "pars0grm.y" + { yyval = NULL; } +#line 2168 "pars0grm.cc" + break; + + case 118: /* opt_not_null: PARS_NOT_TOKEN PARS_NULL_LIT */ +#line 493 "pars0grm.y" + { yyval = &pars_int_token; + /* pass any non-NULL pointer */ } +#line 2175 "pars0grm.cc" + break; + + case 119: /* create_table: PARS_CREATE_TOKEN PARS_TABLE_TOKEN table_name '(' column_def_list ')' */ +#line 500 "pars0grm.y" + { yyval = pars_create_table( + static_cast<sym_node_t*>(yyvsp[-3]), + static_cast<sym_node_t*>(yyvsp[-1])); } +#line 2183 "pars0grm.cc" + break; + + case 120: /* column_list: PARS_ID_TOKEN */ +#line 506 "pars0grm.y" + { yyval = que_node_list_add_last(NULL, yyvsp[0]); } +#line 2189 "pars0grm.cc" + break; + + case 121: /* column_list: column_list ',' PARS_ID_TOKEN */ +#line 508 "pars0grm.y" + { yyval = que_node_list_add_last(yyvsp[-2], yyvsp[0]); } +#line 2195 "pars0grm.cc" + break; + + case 122: /* unique_def: %empty */ +#line 512 "pars0grm.y" + { yyval = NULL; } +#line 2201 "pars0grm.cc" + break; + + case 123: /* unique_def: PARS_UNIQUE_TOKEN */ +#line 513 "pars0grm.y" + { yyval = &pars_unique_token; } +#line 2207 "pars0grm.cc" + break; + + case 124: /* clustered_def: %empty */ +#line 517 "pars0grm.y" + { yyval = NULL; } +#line 2213 "pars0grm.cc" + break; + + case 125: /* clustered_def: PARS_CLUSTERED_TOKEN */ +#line 518 "pars0grm.y" + { yyval = &pars_clustered_token; } +#line 2219 "pars0grm.cc" + break; + + case 126: /* create_index: PARS_CREATE_TOKEN unique_def clustered_def PARS_INDEX_TOKEN PARS_ID_TOKEN PARS_ON_TOKEN table_name '(' column_list ')' */ +#line 527 "pars0grm.y" + { yyval = pars_create_index( + static_cast<pars_res_word_t*>(yyvsp[-8]), + static_cast<pars_res_word_t*>(yyvsp[-7]), + static_cast<sym_node_t*>(yyvsp[-5]), + static_cast<sym_node_t*>(yyvsp[-3]), + static_cast<sym_node_t*>(yyvsp[-1])); } +#line 2230 "pars0grm.cc" + break; + + case 127: /* table_name: PARS_ID_TOKEN */ +#line 536 "pars0grm.y" + { yyval = yyvsp[0]; } +#line 2236 "pars0grm.cc" + break; + + case 128: /* table_name: PARS_TABLE_NAME_TOKEN */ +#line 537 "pars0grm.y" + { yyval = yyvsp[0]; } +#line 2242 "pars0grm.cc" + break; + + case 129: /* commit_statement: PARS_COMMIT_TOKEN PARS_WORK_TOKEN */ +#line 542 "pars0grm.y" + { yyval = pars_commit_statement(); } +#line 2248 "pars0grm.cc" + break; + + case 130: /* rollback_statement: PARS_ROLLBACK_TOKEN PARS_WORK_TOKEN */ +#line 547 "pars0grm.y" + { yyval = pars_rollback_statement(); } +#line 2254 "pars0grm.cc" + break; + + case 131: /* type_name: PARS_INT_TOKEN */ +#line 551 "pars0grm.y" + { yyval = &pars_int_token; } +#line 2260 "pars0grm.cc" + break; + + case 132: /* type_name: PARS_BIGINT_TOKEN */ +#line 552 "pars0grm.y" + { yyval = &pars_bigint_token; } +#line 2266 "pars0grm.cc" + break; + + case 133: /* type_name: PARS_CHAR_TOKEN */ +#line 553 "pars0grm.y" + { yyval = &pars_char_token; } +#line 2272 "pars0grm.cc" + break; + + case 134: /* variable_declaration: PARS_ID_TOKEN type_name ';' */ +#line 558 "pars0grm.y" + { yyval = pars_variable_declaration( + static_cast<sym_node_t*>(yyvsp[-2]), + static_cast<pars_res_word_t*>(yyvsp[-1])); } +#line 2280 "pars0grm.cc" + break; + + case 138: /* cursor_declaration: PARS_DECLARE_TOKEN PARS_CURSOR_TOKEN PARS_ID_TOKEN PARS_IS_TOKEN select_statement ';' */ +#line 572 "pars0grm.y" + { yyval = pars_cursor_declaration( + static_cast<sym_node_t*>(yyvsp[-3]), + static_cast<sel_node_t*>(yyvsp[-1])); } +#line 2288 "pars0grm.cc" + break; + + case 139: /* function_declaration: PARS_DECLARE_TOKEN PARS_FUNCTION_TOKEN PARS_ID_TOKEN ';' */ +#line 579 "pars0grm.y" + { yyval = pars_function_declaration( + static_cast<sym_node_t*>(yyvsp[-1])); } +#line 2295 "pars0grm.cc" + break; + + case 145: /* procedure_definition: PARS_PROCEDURE_TOKEN PARS_ID_TOKEN '(' ')' PARS_IS_TOKEN variable_declaration_list declaration_list PARS_BEGIN_TOKEN statement_list PARS_END_TOKEN */ +#line 601 "pars0grm.y" + { yyval = pars_procedure_definition( + static_cast<sym_node_t*>(yyvsp[-8]), yyvsp[-1]); } +#line 2302 "pars0grm.cc" + break; + + +#line 2306 "pars0grm.cc" + + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + + *++yyvsp = yyval; + + /* Now 'shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } + + goto yynewstate; + + +/*--------------------------------------. +| yyerrlab -- here on detecting error. | +`--------------------------------------*/ +yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; + yyerror (YY_("syntax error")); + } + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; + + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + /* Pop stack until we find a state that shifts the error token. */ + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + YY_ACCESSING_SYMBOL (yystate), yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + + +#if !defined yyoverflow +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + goto yyreturn; +#endif + + +/*-------------------------------------------------------. +| yyreturn -- parsing is finished, clean up and return. | +`-------------------------------------------------------*/ +yyreturn: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif + + return yyresult; +} + +#line 605 "pars0grm.y" + diff --git a/storage/innobase/pars/pars0grm.y b/storage/innobase/pars/pars0grm.y new file mode 100644 index 00000000..c23d6844 --- /dev/null +++ b/storage/innobase/pars/pars0grm.y @@ -0,0 +1,609 @@ +/***************************************************************************** + +Copyright (c) 1997, 2014, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2017, 2021, MariaDB Corporation. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + +*****************************************************************************/ + +/****************************************************** +SQL parser: input file for the GNU Bison parser generator + +Look from pars0lex.l for instructions how to generate the C files for +the InnoDB parser. + +Created 12/14/1997 Heikki Tuuri +*******************************************************/ + +%{ +/* The value of the semantic attribute is a pointer to a query tree node +que_node_t */ + +#include "univ.i" +#include <math.h> +#include "pars0pars.h" +#include "mem0mem.h" +#include "que0types.h" +#include "que0que.h" +#include "row0sel.h" +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wpragmas" +# pragma GCC diagnostic ignored "-Wunknown-warning-option" +# pragma GCC diagnostic ignored "-Wfree-nonheap-object" +# pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif +#define YYSTYPE que_node_t* +/* #define __STDC__ */ +int +yylex(void); +%} + +%token PARS_INT_LIT +%token PARS_FLOAT_LIT +%token PARS_STR_LIT +%token PARS_NULL_LIT +%token PARS_ID_TOKEN +%token PARS_AND_TOKEN +%token PARS_OR_TOKEN +%token PARS_NOT_TOKEN +%token PARS_GE_TOKEN +%token PARS_LE_TOKEN +%token PARS_NE_TOKEN +%token PARS_PROCEDURE_TOKEN +%token PARS_IN_TOKEN +%token PARS_INT_TOKEN +%token PARS_CHAR_TOKEN +%token PARS_IS_TOKEN +%token PARS_BEGIN_TOKEN +%token PARS_END_TOKEN +%token PARS_IF_TOKEN +%token PARS_THEN_TOKEN +%token PARS_ELSE_TOKEN +%token PARS_ELSIF_TOKEN +%token PARS_LOOP_TOKEN +%token PARS_WHILE_TOKEN +%token PARS_RETURN_TOKEN +%token PARS_SELECT_TOKEN +%token PARS_COUNT_TOKEN +%token PARS_FROM_TOKEN +%token PARS_WHERE_TOKEN +%token PARS_FOR_TOKEN +%token PARS_DDOT_TOKEN +%token PARS_ORDER_TOKEN +%token PARS_BY_TOKEN +%token PARS_ASC_TOKEN +%token PARS_DESC_TOKEN +%token PARS_INSERT_TOKEN +%token PARS_INTO_TOKEN +%token PARS_VALUES_TOKEN +%token PARS_UPDATE_TOKEN +%token PARS_SET_TOKEN +%token PARS_DELETE_TOKEN +%token PARS_CURRENT_TOKEN +%token PARS_OF_TOKEN +%token PARS_CREATE_TOKEN +%token PARS_TABLE_TOKEN +%token PARS_INDEX_TOKEN +%token PARS_UNIQUE_TOKEN +%token PARS_CLUSTERED_TOKEN +%token PARS_ON_TOKEN +%token PARS_ASSIGN_TOKEN +%token PARS_DECLARE_TOKEN +%token PARS_CURSOR_TOKEN +%token PARS_SQL_TOKEN +%token PARS_OPEN_TOKEN +%token PARS_FETCH_TOKEN +%token PARS_CLOSE_TOKEN +%token PARS_NOTFOUND_TOKEN +%token PARS_TO_BINARY_TOKEN +%token PARS_SUBSTR_TOKEN +%token PARS_CONCAT_TOKEN +%token PARS_INSTR_TOKEN +%token PARS_LENGTH_TOKEN +%token PARS_COMMIT_TOKEN +%token PARS_ROLLBACK_TOKEN +%token PARS_WORK_TOKEN +%token PARS_EXIT_TOKEN +%token PARS_FUNCTION_TOKEN +%token PARS_LOCK_TOKEN +%token PARS_SHARE_TOKEN +%token PARS_MODE_TOKEN +%token PARS_LIKE_TOKEN +%token PARS_LIKE_TOKEN_EXACT +%token PARS_LIKE_TOKEN_PREFIX +%token PARS_LIKE_TOKEN_SUFFIX +%token PARS_LIKE_TOKEN_SUBSTR +%token PARS_TABLE_NAME_TOKEN +%token PARS_BIGINT_TOKEN + +%left PARS_AND_TOKEN PARS_OR_TOKEN +%left PARS_NOT_TOKEN +%left '=' '<' '>' PARS_GE_TOKEN PARS_LE_TOKEN +%left '-' '+' +%left '*' '/' +%left NEG /* negation--unary minus */ +%left '%' + +%expect 41 + +/* Grammar follows */ +%% + +top_statement: + procedure_definition ';' + +statement: + while_statement ';' + | for_statement ';' + | exit_statement ';' + | if_statement ';' + | return_statement ';' + | assignment_statement ';' + | select_statement ';' + | insert_statement ';' + | delete_statement_searched ';' + | delete_statement_positioned ';' + | update_statement_searched ';' + | update_statement_positioned ';' + | open_cursor_statement ';' + | fetch_statement ';' + | close_cursor_statement ';' + | commit_statement ';' + | rollback_statement ';' + | create_table ';' + | create_index ';' +; + +statement_list: + statement { $$ = que_node_list_add_last(NULL, $1); } + | statement_list statement + { $$ = que_node_list_add_last($1, $2); } +; + +exp: + PARS_ID_TOKEN { $$ = $1;} + | function_name '(' exp_list ')' + { $$ = pars_func($1, $3); } + | PARS_INT_LIT { $$ = $1;} + | PARS_FLOAT_LIT { $$ = $1;} + | PARS_STR_LIT { $$ = $1;} + | PARS_NULL_LIT { $$ = $1;} + | PARS_SQL_TOKEN { $$ = $1;} + | exp '+' exp { $$ = pars_op('+', $1, $3); } + | exp '-' exp { $$ = pars_op('-', $1, $3); } + | exp '*' exp { $$ = pars_op('*', $1, $3); } + | exp '/' exp { $$ = pars_op('/', $1, $3); } + | '-' exp %prec NEG { $$ = pars_op('-', $2, NULL); } + | '(' exp ')' { $$ = $2; } + | exp '=' exp { $$ = pars_op('=', $1, $3); } + | exp PARS_LIKE_TOKEN PARS_STR_LIT + { $$ = pars_op(PARS_LIKE_TOKEN, $1, $3); } + | exp '<' exp { $$ = pars_op('<', $1, $3); } + | exp '>' exp { $$ = pars_op('>', $1, $3); } + | exp PARS_GE_TOKEN exp { $$ = pars_op(PARS_GE_TOKEN, $1, $3); } + | exp PARS_LE_TOKEN exp { $$ = pars_op(PARS_LE_TOKEN, $1, $3); } + | exp PARS_NE_TOKEN exp { $$ = pars_op(PARS_NE_TOKEN, $1, $3); } + | exp PARS_AND_TOKEN exp{ $$ = pars_op(PARS_AND_TOKEN, $1, $3); } + | exp PARS_OR_TOKEN exp { $$ = pars_op(PARS_OR_TOKEN, $1, $3); } + | PARS_NOT_TOKEN exp { $$ = pars_op(PARS_NOT_TOKEN, $2, NULL); } + | PARS_ID_TOKEN '%' PARS_NOTFOUND_TOKEN + { $$ = pars_op(PARS_NOTFOUND_TOKEN, $1, NULL); } + | PARS_SQL_TOKEN '%' PARS_NOTFOUND_TOKEN + { $$ = pars_op(PARS_NOTFOUND_TOKEN, $1, NULL); } +; + +function_name: + PARS_TO_BINARY_TOKEN { $$ = &pars_to_binary_token; } + | PARS_SUBSTR_TOKEN { $$ = &pars_substr_token; } + | PARS_CONCAT_TOKEN { $$ = &pars_concat_token; } + | PARS_INSTR_TOKEN { $$ = &pars_instr_token; } + | PARS_LENGTH_TOKEN { $$ = &pars_length_token; } +; + +user_function_call: + PARS_ID_TOKEN '(' ')' { $$ = $1; } +; + +table_list: + table_name { $$ = que_node_list_add_last(NULL, $1); } + | table_list ',' table_name + { $$ = que_node_list_add_last($1, $3); } +; + +variable_list: + /* Nothing */ { $$ = NULL; } + | PARS_ID_TOKEN { $$ = que_node_list_add_last(NULL, $1); } + | variable_list ',' PARS_ID_TOKEN + { $$ = que_node_list_add_last($1, $3); } +; + +exp_list: + /* Nothing */ { $$ = NULL; } + | exp { $$ = que_node_list_add_last(NULL, $1);} + | exp_list ',' exp { $$ = que_node_list_add_last($1, $3); } +; + +select_item: + exp { $$ = $1; } + | PARS_COUNT_TOKEN '(' '*' ')' + { $$ = pars_func(&pars_count_token, + que_node_list_add_last(NULL, + sym_tab_add_int_lit( + pars_sym_tab_global, 1))); } +; + +select_item_list: + /* Nothing */ { $$ = NULL; } + | select_item { $$ = que_node_list_add_last(NULL, $1); } + | select_item_list ',' select_item + { $$ = que_node_list_add_last($1, $3); } +; + +select_list: + '*' { $$ = pars_select_list(&pars_star_denoter, + NULL); } + | select_item_list PARS_INTO_TOKEN variable_list + { $$ = pars_select_list( + $1, static_cast<sym_node_t*>($3)); } + | select_item_list { $$ = pars_select_list($1, NULL); } +; + +search_condition: + /* Nothing */ { $$ = NULL; } + | PARS_WHERE_TOKEN exp { $$ = $2; } +; + +for_update_clause: + /* Nothing */ { $$ = NULL; } + | PARS_FOR_TOKEN PARS_UPDATE_TOKEN + { $$ = &pars_update_token; } +; + +lock_shared_clause: + /* Nothing */ { $$ = NULL; } + | PARS_LOCK_TOKEN PARS_IN_TOKEN PARS_SHARE_TOKEN PARS_MODE_TOKEN + { $$ = &pars_share_token; } +; + +order_direction: + /* Nothing */ { $$ = &pars_asc_token; } + | PARS_ASC_TOKEN { $$ = &pars_asc_token; } + | PARS_DESC_TOKEN { $$ = &pars_desc_token; } +; + +order_by_clause: + /* Nothing */ { $$ = NULL; } + | PARS_ORDER_TOKEN PARS_BY_TOKEN PARS_ID_TOKEN order_direction + { $$ = pars_order_by( + static_cast<sym_node_t*>($3), + static_cast<pars_res_word_t*>($4)); } +; + +select_statement: + PARS_SELECT_TOKEN select_list + PARS_FROM_TOKEN table_list + search_condition + for_update_clause + lock_shared_clause + order_by_clause { $$ = pars_select_statement( + static_cast<sel_node_t*>($2), + static_cast<sym_node_t*>($4), + static_cast<que_node_t*>($5), + static_cast<pars_res_word_t*>($6), + static_cast<pars_res_word_t*>($7), + static_cast<order_node_t*>($8)); } +; + +insert_statement_start: + PARS_INSERT_TOKEN PARS_INTO_TOKEN + table_name { $$ = $3; } +; + +insert_statement: + insert_statement_start PARS_VALUES_TOKEN '(' exp_list ')' + { $$ = pars_insert_statement( + static_cast<sym_node_t*>($1), $4, NULL); } + | insert_statement_start select_statement + { $$ = pars_insert_statement( + static_cast<sym_node_t*>($1), + NULL, + static_cast<sel_node_t*>($2)); } +; + +column_assignment: + PARS_ID_TOKEN '=' exp { $$ = pars_column_assignment( + static_cast<sym_node_t*>($1), + static_cast<que_node_t*>($3)); } +; + +column_assignment_list: + column_assignment { $$ = que_node_list_add_last(NULL, $1); } + | column_assignment_list ',' column_assignment + { $$ = que_node_list_add_last($1, $3); } +; + +cursor_positioned: + PARS_WHERE_TOKEN + PARS_CURRENT_TOKEN PARS_OF_TOKEN + PARS_ID_TOKEN { $$ = $4; } +; + +update_statement_start: + PARS_UPDATE_TOKEN table_name + PARS_SET_TOKEN + column_assignment_list { $$ = pars_update_statement_start( + FALSE, + static_cast<sym_node_t*>($2), + static_cast<col_assign_node_t*>($4)); } +; + +update_statement_searched: + update_statement_start + search_condition { $$ = pars_update_statement( + static_cast<upd_node_t*>($1), + NULL, + static_cast<que_node_t*>($2)); } +; + +update_statement_positioned: + update_statement_start + cursor_positioned { $$ = pars_update_statement( + static_cast<upd_node_t*>($1), + static_cast<sym_node_t*>($2), + NULL); } +; + +delete_statement_start: + PARS_DELETE_TOKEN PARS_FROM_TOKEN + table_name { $$ = pars_update_statement_start( + TRUE, + static_cast<sym_node_t*>($3), NULL); } +; + +delete_statement_searched: + delete_statement_start + search_condition { $$ = pars_update_statement( + static_cast<upd_node_t*>($1), + NULL, + static_cast<que_node_t*>($2)); } +; + +delete_statement_positioned: + delete_statement_start + cursor_positioned { $$ = pars_update_statement( + static_cast<upd_node_t*>($1), + static_cast<sym_node_t*>($2), + NULL); } +; + +assignment_statement: + PARS_ID_TOKEN PARS_ASSIGN_TOKEN exp + { $$ = pars_assignment_statement( + static_cast<sym_node_t*>($1), + static_cast<que_node_t*>($3)); } +; + +elsif_element: + PARS_ELSIF_TOKEN + exp PARS_THEN_TOKEN statement_list + { $$ = pars_elsif_element($2, $4); } +; + +elsif_list: + elsif_element { $$ = que_node_list_add_last(NULL, $1); } + | elsif_list elsif_element + { $$ = que_node_list_add_last($1, $2); } +; + +else_part: + /* Nothing */ { $$ = NULL; } + | PARS_ELSE_TOKEN statement_list + { $$ = $2; } + | elsif_list { $$ = $1; } +; + +if_statement: + PARS_IF_TOKEN exp PARS_THEN_TOKEN statement_list + else_part + PARS_END_TOKEN PARS_IF_TOKEN + { $$ = pars_if_statement($2, $4, $5); } +; + +while_statement: + PARS_WHILE_TOKEN exp PARS_LOOP_TOKEN statement_list + PARS_END_TOKEN PARS_LOOP_TOKEN + { $$ = pars_while_statement($2, $4); } +; + +for_statement: + PARS_FOR_TOKEN PARS_ID_TOKEN PARS_IN_TOKEN + exp PARS_DDOT_TOKEN exp + PARS_LOOP_TOKEN statement_list + PARS_END_TOKEN PARS_LOOP_TOKEN + { $$ = pars_for_statement( + static_cast<sym_node_t*>($2), + $4, $6, $8); } +; + +exit_statement: + PARS_EXIT_TOKEN { $$ = pars_exit_statement(); } +; + +return_statement: + PARS_RETURN_TOKEN { $$ = pars_return_statement(); } +; + +open_cursor_statement: + PARS_OPEN_TOKEN PARS_ID_TOKEN + { $$ = pars_open_statement( + ROW_SEL_OPEN_CURSOR, + static_cast<sym_node_t*>($2)); } +; + +close_cursor_statement: + PARS_CLOSE_TOKEN PARS_ID_TOKEN + { $$ = pars_open_statement( + ROW_SEL_CLOSE_CURSOR, + static_cast<sym_node_t*>($2)); } +; + +fetch_statement: + PARS_FETCH_TOKEN PARS_ID_TOKEN PARS_INTO_TOKEN variable_list + { $$ = pars_fetch_statement( + static_cast<sym_node_t*>($2), + static_cast<sym_node_t*>($4), NULL); } + | PARS_FETCH_TOKEN PARS_ID_TOKEN PARS_INTO_TOKEN user_function_call + { $$ = pars_fetch_statement( + static_cast<sym_node_t*>($2), + NULL, + static_cast<sym_node_t*>($4)); } +; + +column_def: + PARS_ID_TOKEN type_name opt_column_len opt_not_null + { $$ = pars_column_def( + static_cast<sym_node_t*>($1), + static_cast<pars_res_word_t*>($2), + static_cast<sym_node_t*>($3), + $4); } +; + +column_def_list: + column_def { $$ = que_node_list_add_last(NULL, $1); } + | column_def_list ',' column_def + { $$ = que_node_list_add_last($1, $3); } +; + +opt_column_len: + /* Nothing */ { $$ = NULL; } + | '(' PARS_INT_LIT ')' + { $$ = $2; } +; + +opt_not_null: + /* Nothing */ { $$ = NULL; } + | PARS_NOT_TOKEN PARS_NULL_LIT + { $$ = &pars_int_token; + /* pass any non-NULL pointer */ } +; + +create_table: + PARS_CREATE_TOKEN PARS_TABLE_TOKEN + table_name '(' column_def_list ')' + { $$ = pars_create_table( + static_cast<sym_node_t*>($3), + static_cast<sym_node_t*>($5)); } +; + +column_list: + PARS_ID_TOKEN { $$ = que_node_list_add_last(NULL, $1); } + | column_list ',' PARS_ID_TOKEN + { $$ = que_node_list_add_last($1, $3); } +; + +unique_def: + /* Nothing */ { $$ = NULL; } + | PARS_UNIQUE_TOKEN { $$ = &pars_unique_token; } +; + +clustered_def: + /* Nothing */ { $$ = NULL; } + | PARS_CLUSTERED_TOKEN { $$ = &pars_clustered_token; } +; + +create_index: + PARS_CREATE_TOKEN unique_def + clustered_def + PARS_INDEX_TOKEN + PARS_ID_TOKEN PARS_ON_TOKEN + table_name + '(' column_list ')' { $$ = pars_create_index( + static_cast<pars_res_word_t*>($2), + static_cast<pars_res_word_t*>($3), + static_cast<sym_node_t*>($5), + static_cast<sym_node_t*>($7), + static_cast<sym_node_t*>($9)); } +; + +table_name: + PARS_ID_TOKEN { $$ = $1; } + | PARS_TABLE_NAME_TOKEN { $$ = $1; } +; + +commit_statement: + PARS_COMMIT_TOKEN PARS_WORK_TOKEN + { $$ = pars_commit_statement(); } +; + +rollback_statement: + PARS_ROLLBACK_TOKEN PARS_WORK_TOKEN + { $$ = pars_rollback_statement(); } +; + +type_name: + PARS_INT_TOKEN { $$ = &pars_int_token; } + | PARS_BIGINT_TOKEN { $$ = &pars_bigint_token; } + | PARS_CHAR_TOKEN { $$ = &pars_char_token; } +; + +variable_declaration: + PARS_ID_TOKEN type_name ';' + { $$ = pars_variable_declaration( + static_cast<sym_node_t*>($1), + static_cast<pars_res_word_t*>($2)); } +; + +variable_declaration_list: + /* Nothing */ + | variable_declaration + | variable_declaration_list variable_declaration +; + +cursor_declaration: + PARS_DECLARE_TOKEN PARS_CURSOR_TOKEN PARS_ID_TOKEN + PARS_IS_TOKEN select_statement ';' + { $$ = pars_cursor_declaration( + static_cast<sym_node_t*>($3), + static_cast<sel_node_t*>($5)); } +; + +function_declaration: + PARS_DECLARE_TOKEN PARS_FUNCTION_TOKEN PARS_ID_TOKEN ';' + { $$ = pars_function_declaration( + static_cast<sym_node_t*>($3)); } +; + +declaration: + cursor_declaration + | function_declaration +; + +declaration_list: + /* Nothing */ + | declaration + | declaration_list declaration +; + +procedure_definition: + PARS_PROCEDURE_TOKEN PARS_ID_TOKEN '(' ')' + PARS_IS_TOKEN + variable_declaration_list + declaration_list + PARS_BEGIN_TOKEN + statement_list + PARS_END_TOKEN { $$ = pars_procedure_definition( + static_cast<sym_node_t*>($2), $9); } +; + +%% diff --git a/storage/innobase/pars/pars0lex.l b/storage/innobase/pars/pars0lex.l new file mode 100644 index 00000000..1ddc5132 --- /dev/null +++ b/storage/innobase/pars/pars0lex.l @@ -0,0 +1,614 @@ +/***************************************************************************** + +Copyright (c) 1997, 2014, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2017, 2019, MariaDB Corporation. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + +*****************************************************************************/ + +/****************************************************** +SQL parser lexical analyzer: input file for the GNU Flex lexer generator + +The InnoDB parser is frozen because MySQL takes care of SQL parsing. +Therefore we normally keep the InnoDB parser C files as they are, and do +not automatically generate them from pars0grm.y and pars0lex.l. + +How to make the InnoDB parser and lexer C files: + +1. Run ./make_flex.sh to generate lexer files. + +2. Run ./make_bison.sh to generate parser files. + +These instructions seem to work at least with bison-1.875d and flex-2.5.31 on +Linux. + +Created 12/14/1997 Heikki Tuuri +*******************************************************/ + +%option nostdinit +%option 8bit +%option warn +%option pointer +%option never-interactive +%option nodefault +%option noinput +%option nounput +%option noyywrap +%option noyy_scan_buffer +%option noyy_scan_bytes +%option noyy_scan_string +%option nounistd + +%{ +#define YYSTYPE que_node_t* + +#include "univ.i" +#include "pars0pars.h" +#include "pars0grm.h" +#include "pars0sym.h" +#include "mem0mem.h" + +#define malloc(A) ut_malloc_nokey(A) +#define free(A) ut_free(A) +#define realloc(P, A) ut_realloc(P, A) +#define exit(A) ut_error + +#define YY_INPUT(buf, result, max_size) \ + result = pars_get_lex_chars(buf, max_size) + +/* String buffer for removing quotes */ +static ulint stringbuf_len_alloc = 0; /* Allocated length */ +static ulint stringbuf_len = 0; /* Current length */ +static char* stringbuf; /* Start of buffer */ +/** Appends a string to the buffer. */ +static +void +string_append( +/*==========*/ + const char* str, /*!< in: string to be appended */ + ulint len) /*!< in: length of the string */ +{ + if (stringbuf == NULL) { + stringbuf = static_cast<char*>(malloc(1)); + stringbuf_len_alloc = 1; + } + + if (stringbuf_len + len > stringbuf_len_alloc) { + while (stringbuf_len + len > stringbuf_len_alloc) { + stringbuf_len_alloc <<= 1; + } + + stringbuf = static_cast<char*>( + realloc(stringbuf, stringbuf_len_alloc)); + } + + memcpy(stringbuf + stringbuf_len, str, len); + stringbuf_len += len; +} + +%} + +DIGIT [0-9] +ID [a-z_A-Z][a-z_A-Z0-9]* +TABLE_NAME [a-z_A-Z][@a-z_A-Z0-9]*\/(#sql-|[a-z_A-Z])[a-z_A-Z0-9]* +BOUND_LIT \:[a-z_A-Z0-9]+ +BOUND_ID \$[a-z_A-Z0-9]+ + +%x comment +%x quoted +%x id +%% + +{DIGIT}+ { + yylval = sym_tab_add_int_lit(pars_sym_tab_global, + atoi(yytext)); + return(PARS_INT_LIT); +} + +{DIGIT}+"."{DIGIT}* { + ut_error; /* not implemented */ + + return(PARS_FLOAT_LIT); +} + +{BOUND_LIT} { + ulint type; + + yylval = sym_tab_add_bound_lit(pars_sym_tab_global, + yytext + 1, &type); + + return((int) type); +} + +{BOUND_ID} { + yylval = sym_tab_add_bound_id(pars_sym_tab_global, + yytext + 1); + + return(PARS_ID_TOKEN); +} + +"'" { +/* Quoted character string literals are handled in an explicit +start state 'quoted'. This state is entered and the buffer for +the scanned string is emptied upon encountering a starting quote. + +In the state 'quoted', only two actions are possible (defined below). */ + BEGIN(quoted); + stringbuf_len = 0; +} +<quoted>[^\']+ { + /* Got a sequence of characters other than "'": + append to string buffer */ + string_append(yytext, yyleng); +} +<quoted>"'"+ { + /* Got a sequence of "'" characters: + append half of them to string buffer, + as "''" represents a single "'". + We apply truncating division, + so that "'''" will result in "'". */ + + string_append(yytext, yyleng / 2); + + /* If we got an odd number of quotes, then the + last quote we got is the terminating quote. + At the end of the string, we return to the + initial start state and report the scanned + string literal. */ + + if (yyleng % 2) { + BEGIN(INITIAL); + yylval = sym_tab_add_str_lit( + pars_sym_tab_global, + (byte*) stringbuf, stringbuf_len); + return(PARS_STR_LIT); + } +} + +\" { +/* Quoted identifiers are handled in an explicit start state 'id'. +This state is entered and the buffer for the scanned string is emptied +upon encountering a starting quote. + +In the state 'id', only two actions are possible (defined below). */ + BEGIN(id); + stringbuf_len = 0; +} +<id>[^\"]+ { + /* Got a sequence of characters other than '"': + append to string buffer */ + string_append(yytext, yyleng); +} +<id>\"+ { + /* Got a sequence of '"' characters: + append half of them to string buffer, + as '""' represents a single '"'. + We apply truncating division, + so that '"""' will result in '"'. */ + + string_append(yytext, yyleng / 2); + + /* If we got an odd number of quotes, then the + last quote we got is the terminating quote. + At the end of the string, we return to the + initial start state and report the scanned + identifier. */ + + if (yyleng % 2) { + BEGIN(INITIAL); + yylval = sym_tab_add_id( + pars_sym_tab_global, + (byte*) stringbuf, stringbuf_len); + + return(PARS_ID_TOKEN); + } +} + +"NULL" { + yylval = sym_tab_add_null_lit(pars_sym_tab_global); + + return(PARS_NULL_LIT); +} + +"SQL" { + /* Implicit cursor name */ + yylval = sym_tab_add_str_lit(pars_sym_tab_global, + (byte*) yytext, yyleng); + return(PARS_SQL_TOKEN); +} + +"AND" { + return(PARS_AND_TOKEN); +} + +"OR" { + return(PARS_OR_TOKEN); +} + +"NOT" { + return(PARS_NOT_TOKEN); +} + +"PROCEDURE" { + return(PARS_PROCEDURE_TOKEN); +} + +"IN" { + return(PARS_IN_TOKEN); +} + +"INT" { + return(PARS_INT_TOKEN); +} + +"CHAR" { + return(PARS_CHAR_TOKEN); +} + +"IS" { + return(PARS_IS_TOKEN); +} + +"BEGIN" { + return(PARS_BEGIN_TOKEN); +} + +"END" { + return(PARS_END_TOKEN); +} + +"IF" { + return(PARS_IF_TOKEN); +} + +"THEN" { + return(PARS_THEN_TOKEN); +} + +"ELSE" { + return(PARS_ELSE_TOKEN); +} + +"ELSIF" { + return(PARS_ELSIF_TOKEN); +} + +"LOOP" { + return(PARS_LOOP_TOKEN); +} + +"WHILE" { + return(PARS_WHILE_TOKEN); +} + +"RETURN" { + return(PARS_RETURN_TOKEN); +} + +"SELECT" { + return(PARS_SELECT_TOKEN); +} + +"COUNT" { + return(PARS_COUNT_TOKEN); +} + +"FROM" { + return(PARS_FROM_TOKEN); +} + +"WHERE" { + return(PARS_WHERE_TOKEN); +} + +"FOR" { + return(PARS_FOR_TOKEN); +} + +"ORDER" { + return(PARS_ORDER_TOKEN); +} + +"BY" { + return(PARS_BY_TOKEN); +} + +"ASC" { + return(PARS_ASC_TOKEN); +} + +"DESC" { + return(PARS_DESC_TOKEN); +} + +"INSERT" { + return(PARS_INSERT_TOKEN); +} + +"INTO" { + return(PARS_INTO_TOKEN); +} + +"VALUES" { + return(PARS_VALUES_TOKEN); +} + +"UPDATE" { + return(PARS_UPDATE_TOKEN); +} + +"SET" { + return(PARS_SET_TOKEN); +} + +"DELETE" { + return(PARS_DELETE_TOKEN); +} + +"CURRENT" { + return(PARS_CURRENT_TOKEN); +} + +"OF" { + return(PARS_OF_TOKEN); +} + +"CREATE" { + return(PARS_CREATE_TOKEN); +} + +"TABLE" { + return(PARS_TABLE_TOKEN); +} + +"INDEX" { + return(PARS_INDEX_TOKEN); +} + +"UNIQUE" { + return(PARS_UNIQUE_TOKEN); +} + +"CLUSTERED" { + return(PARS_CLUSTERED_TOKEN); +} + +"ON" { + return(PARS_ON_TOKEN); +} + +"DECLARE" { + return(PARS_DECLARE_TOKEN); +} + +"CURSOR" { + return(PARS_CURSOR_TOKEN); +} + +"OPEN" { + return(PARS_OPEN_TOKEN); +} + +"FETCH" { + return(PARS_FETCH_TOKEN); +} + +"CLOSE" { + return(PARS_CLOSE_TOKEN); +} + +"NOTFOUND" { + return(PARS_NOTFOUND_TOKEN); +} + +"TO_BINARY" { + return(PARS_TO_BINARY_TOKEN); +} + +"SUBSTR" { + return(PARS_SUBSTR_TOKEN); +} + +"CONCAT" { + return(PARS_CONCAT_TOKEN); +} + +"INSTR" { + return(PARS_INSTR_TOKEN); +} + +"LENGTH" { + return(PARS_LENGTH_TOKEN); +} + +"COMMIT" { + return(PARS_COMMIT_TOKEN); +} + +"ROLLBACK" { + return(PARS_ROLLBACK_TOKEN); +} + +"WORK" { + return(PARS_WORK_TOKEN); +} + +"EXIT" { + return(PARS_EXIT_TOKEN); +} + +"FUNCTION" { + return(PARS_FUNCTION_TOKEN); +} + +"LOCK" { + return(PARS_LOCK_TOKEN); +} + +"SHARE" { + return(PARS_SHARE_TOKEN); +} + +"MODE" { + return(PARS_MODE_TOKEN); +} + +"LIKE" { + return(PARS_LIKE_TOKEN); +} + +"BIGINT" { + return(PARS_BIGINT_TOKEN); +} + +{ID} { + yylval = sym_tab_add_id(pars_sym_tab_global, + (byte*) yytext, + strlen(yytext)); + return(PARS_ID_TOKEN); +} + +{TABLE_NAME} { + yylval = sym_tab_add_id(pars_sym_tab_global, + (byte*) yytext, + strlen(yytext)); + return(PARS_TABLE_NAME_TOKEN); +} + +".." { + return(PARS_DDOT_TOKEN); +} + +":=" { + return(PARS_ASSIGN_TOKEN); +} + +"<=" { + return(PARS_LE_TOKEN); +} + +">=" { + return(PARS_GE_TOKEN); +} + +"<>" { + return(PARS_NE_TOKEN); +} + +"(" { + + return((int)(*yytext)); +} + +"=" { + + return((int)(*yytext)); +} + +">" { + + return((int)(*yytext)); +} + +"<" { + + return((int)(*yytext)); +} + +"," { + + return((int)(*yytext)); +} + +";" { + + return((int)(*yytext)); +} + +")" { + + return((int)(*yytext)); +} + +"+" { + + return((int)(*yytext)); +} + +"-" { + + return((int)(*yytext)); +} + +"*" { + + return((int)(*yytext)); +} + +"/" { + + return((int)(*yytext)); +} + +"%" { + + return((int)(*yytext)); +} + +"{" { + + return((int)(*yytext)); +} + +"}" { + + return((int)(*yytext)); +} + +"?" { + + return((int)(*yytext)); +} + +"/*" BEGIN(comment); /* eat up comment */ + +<comment>[^*]* +<comment>"*"+[^*/]* +<comment>"*"+"/" BEGIN(INITIAL); + +[ \t\n]+ /* eat up whitespace */ + + +. { + fprintf(stderr,"Unrecognized character: %02x\n", + *yytext); + + ut_error; + + return(0); +} + +%% + +/********************************************************************** +Release any resources used by the lexer. */ +void +pars_lexer_close(void) +/*==================*/ +{ + yylex_destroy(); + free(stringbuf); + stringbuf = NULL; + stringbuf_len_alloc = stringbuf_len = 0; +} diff --git a/storage/innobase/pars/pars0opt.cc b/storage/innobase/pars/pars0opt.cc new file mode 100644 index 00000000..44949ad0 --- /dev/null +++ b/storage/innobase/pars/pars0opt.cc @@ -0,0 +1,1263 @@ +/***************************************************************************** + +Copyright (c) 1997, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2019, 2022, MariaDB Corporation. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + +*****************************************************************************/ + +/**************************************************//** +@file pars/pars0opt.cc +Simple SQL optimizer + +Created 12/21/1997 Heikki Tuuri +*******************************************************/ + +#include "pars0opt.h" +#include "row0sel.h" +#include "row0ins.h" +#include "row0upd.h" +#include "dict0boot.h" +#include "dict0dict.h" +#include "dict0mem.h" +#include "que0que.h" +#include "pars0grm.h" +#include "pars0pars.h" + +#define OPT_EQUAL 1 /* comparison by = */ +#define OPT_COMPARISON 2 /* comparison by <, >, <=, or >= */ + +#define OPT_NOT_COND 1 +#define OPT_END_COND 2 +#define OPT_TEST_COND 3 +#define OPT_SCROLL_COND 4 + + +/*******************************************************************//** +Inverts a comparison operator. +@return the equivalent operator when the order of the arguments is switched */ +static +int +opt_invert_cmp_op( +/*==============*/ + int op) /*!< in: operator */ +{ + if (op == '<') { + return('>'); + } else if (op == '>') { + return('<'); + } else if (op == '=') { + return('='); + } else if (op == PARS_LE_TOKEN) { + return(PARS_GE_TOKEN); + } else if (op == PARS_GE_TOKEN) { + return(PARS_LE_TOKEN); + } else { + /* TODO: LIKE operator */ + ut_error; + } + + return(0); +} + +/*******************************************************************//** +Checks if the value of an expression can be calculated BEFORE the nth table +in a join is accessed. If this is the case, it can possibly be used in an +index search for the nth table. +@return TRUE if already determined */ +static +ibool +opt_check_exp_determined_before( +/*============================*/ + que_node_t* exp, /*!< in: expression */ + sel_node_t* sel_node, /*!< in: select node */ + ulint nth_table) /*!< in: nth table will be accessed */ +{ + func_node_t* func_node; + sym_node_t* sym_node; + dict_table_t* table; + que_node_t* arg; + ulint i; + + ut_ad(exp && sel_node); + + if (que_node_get_type(exp) == QUE_NODE_FUNC) { + func_node = static_cast<func_node_t*>(exp); + + arg = func_node->args; + + while (arg) { + if (!opt_check_exp_determined_before(arg, sel_node, + nth_table)) { + return(FALSE); + } + + arg = que_node_get_next(arg); + } + + return(TRUE); + } + + ut_a(que_node_get_type(exp) == QUE_NODE_SYMBOL); + + sym_node = static_cast<sym_node_t*>(exp); + + if (sym_node->token_type != SYM_COLUMN) { + + return(TRUE); + } + + for (i = 0; i < nth_table; i++) { + + table = sel_node_get_nth_plan(sel_node, i)->table; + + if (sym_node->table == table) { + + return(TRUE); + } + } + + return(FALSE); +} + +/*******************************************************************//** +Looks in a comparison condition if a column value is already restricted by +it BEFORE the nth table is accessed. +@return expression restricting the value of the column, or NULL if not known */ +static +que_node_t* +opt_look_for_col_in_comparison_before( +/*==================================*/ + ulint cmp_type, /*!< in: OPT_EQUAL, OPT_COMPARISON */ + ulint col_no, /*!< in: column number */ + func_node_t* search_cond, /*!< in: comparison condition */ + sel_node_t* sel_node, /*!< in: select node */ + ulint nth_table, /*!< in: nth table in a join (a query + from a single table is considered a + join of 1 table) */ + ulint* op) /*!< out: comparison operator ('=', + PARS_GE_TOKEN, ... ); this is inverted + if the column appears on the right + side */ +{ + sym_node_t* sym_node; + dict_table_t* table; + que_node_t* exp; + que_node_t* arg; + + ut_ad(search_cond); + + ut_a((search_cond->func == '<') + || (search_cond->func == '>') + || (search_cond->func == '=') + || (search_cond->func == PARS_GE_TOKEN) + || (search_cond->func == PARS_LE_TOKEN) + || (search_cond->func == PARS_LIKE_TOKEN_EXACT) + || (search_cond->func == PARS_LIKE_TOKEN_PREFIX) + || (search_cond->func == PARS_LIKE_TOKEN_SUFFIX) + || (search_cond->func == PARS_LIKE_TOKEN_SUBSTR)); + + table = sel_node_get_nth_plan(sel_node, nth_table)->table; + + if ((cmp_type == OPT_EQUAL) + && (search_cond->func != '=') + && (search_cond->func != PARS_LIKE_TOKEN_EXACT) + && (search_cond->func != PARS_LIKE_TOKEN_PREFIX)) { + + return(NULL); + + } else if ((cmp_type == OPT_COMPARISON) + && (search_cond->func != '<') + && (search_cond->func != '>') + && (search_cond->func != PARS_GE_TOKEN) + && (search_cond->func != PARS_LE_TOKEN) + && (search_cond->func != PARS_LIKE_TOKEN_PREFIX) + && (search_cond->func != PARS_LIKE_TOKEN_SUFFIX)) { + + return(NULL); + } + + arg = search_cond->args; + + if (que_node_get_type(arg) == QUE_NODE_SYMBOL) { + sym_node = static_cast<sym_node_t*>(arg); + + if ((sym_node->token_type == SYM_COLUMN) + && (sym_node->table == table) + && (sym_node->col_no == col_no)) { + + /* sym_node contains the desired column id */ + + /* Check if the expression on the right side of the + operator is already determined */ + + exp = que_node_get_next(arg); + + if (opt_check_exp_determined_before(exp, sel_node, + nth_table)) { + *op = ulint(search_cond->func); + + return(exp); + } + } + } + + exp = search_cond->args; + arg = que_node_get_next(arg); + + if (que_node_get_type(arg) == QUE_NODE_SYMBOL) { + sym_node = static_cast<sym_node_t*>(arg); + + if ((sym_node->token_type == SYM_COLUMN) + && (sym_node->table == table) + && (sym_node->col_no == col_no)) { + + if (opt_check_exp_determined_before(exp, sel_node, + nth_table)) { + *op = ulint(opt_invert_cmp_op( + search_cond->func)); + + return(exp); + } + } + } + + return(NULL); +} + +/*******************************************************************//** +Looks in a search condition if a column value is already restricted by the +search condition BEFORE the nth table is accessed. Takes into account that +if we will fetch in an ascending order, we cannot utilize an upper limit for +a column value; in a descending order, respectively, a lower limit. +@return expression restricting the value of the column, or NULL if not known */ +static +que_node_t* +opt_look_for_col_in_cond_before( +/*============================*/ + ulint cmp_type, /*!< in: OPT_EQUAL, OPT_COMPARISON */ + ulint col_no, /*!< in: column number */ + func_node_t* search_cond, /*!< in: search condition or NULL */ + sel_node_t* sel_node, /*!< in: select node */ + ulint nth_table, /*!< in: nth table in a join (a query + from a single table is considered a + join of 1 table) */ + ulint* op) /*!< out: comparison operator ('=', + PARS_GE_TOKEN, ... ) */ +{ + func_node_t* new_cond; + que_node_t* exp; + + if (search_cond == NULL) { + + return(NULL); + } + + ut_a(que_node_get_type(search_cond) == QUE_NODE_FUNC); + ut_a(search_cond->func != PARS_OR_TOKEN); + ut_a(search_cond->func != PARS_NOT_TOKEN); + + if (search_cond->func == PARS_AND_TOKEN) { + new_cond = static_cast<func_node_t*>(search_cond->args); + + exp = opt_look_for_col_in_cond_before(cmp_type, col_no, + new_cond, sel_node, + nth_table, op); + if (exp) { + + return(exp); + } + + new_cond = static_cast<func_node_t*>( + que_node_get_next(new_cond)); + + exp = opt_look_for_col_in_cond_before(cmp_type, col_no, + new_cond, sel_node, + nth_table, op); + return(exp); + } + + exp = opt_look_for_col_in_comparison_before(cmp_type, col_no, + search_cond, sel_node, + nth_table, op); + if (exp == NULL) { + + return(NULL); + } + + /* If we will fetch in an ascending order, we cannot utilize an upper + limit for a column value; in a descending order, respectively, a lower + limit */ + + if (sel_node->asc && ((*op == '<') || (*op == PARS_LE_TOKEN))) { + + return(NULL); + + } else if (!sel_node->asc + && ((*op == '>') || (*op == PARS_GE_TOKEN))) { + + return(NULL); + } + + return(exp); +} + +/*******************************************************************//** +Calculates the goodness for an index according to a select node. The +goodness is 4 times the number of first fields in index whose values we +already know exactly in the query. If we have a comparison condition for +an additional field, 2 point are added. If the index is unique, and we know +all the unique fields for the index we add 1024 points. For a clustered index +we add 1 point. +@return goodness */ +static +ulint +opt_calc_index_goodness( +/*====================*/ + dict_index_t* index, /*!< in: index */ + sel_node_t* sel_node, /*!< in: parsed select node */ + ulint nth_table, /*!< in: nth table in a join */ + que_node_t** index_plan, /*!< in/out: comparison expressions for + this index */ + ulint* last_op) /*!< out: last comparison operator, if + goodness > 1 */ +{ + que_node_t* exp; + ulint goodness; + ulint n_fields; + ulint col_no; + ulint op; + ulint j; + + /* At least for now we don't support using FTS indexes for queries + done through InnoDB's own SQL parser. */ + if (dict_index_is_online_ddl(index) || (index->type & DICT_FTS)) { + return(0); + } + + goodness = 0; + + /* Note that as higher level node pointers in the B-tree contain + page addresses as the last field, we must not put more fields in + the search tuple than dict_index_get_n_unique_in_tree(index); see + the note in btr_cur_search_to_nth_level. */ + + n_fields = dict_index_get_n_unique_in_tree(index); + + for (j = 0; j < n_fields; j++) { + if (UNIV_UNLIKELY(index->fields[j].descending)) { + /* The internal InnoDB SQL parser does not + work with indexes that use DESC order. */ + return 0; + } + + col_no = dict_index_get_nth_col_no(index, j); + + exp = opt_look_for_col_in_cond_before( + OPT_EQUAL, col_no, + static_cast<func_node_t*>(sel_node->search_cond), + sel_node, nth_table, &op); + if (exp) { + /* The value for this column is exactly known already + at this stage of the join */ + + index_plan[j] = exp; + *last_op = op; + goodness += 4; + } else { + /* Look for non-equality comparisons */ + + exp = opt_look_for_col_in_cond_before( + OPT_COMPARISON, col_no, + static_cast<func_node_t*>( + sel_node->search_cond), + sel_node, nth_table, &op); + if (exp) { + index_plan[j] = exp; + *last_op = op; + goodness += 2; + } + + break; + } + } + + if (goodness / 4 >= dict_index_get_n_unique(index)) { + goodness += 1024; + + if (dict_index_is_clust(index)) { + + goodness += 1024; + } + } + + /* We have to test for goodness here, as last_op may not be set */ + if (goodness && dict_index_is_clust(index)) { + + goodness++; + } + + return(goodness); +} + +/*******************************************************************//** +Calculates the number of matched fields based on an index goodness. +@return number of excatly or partially matched fields */ +UNIV_INLINE +ulint +opt_calc_n_fields_from_goodness( +/*============================*/ + ulint goodness) /*!< in: goodness */ +{ + return(((goodness % 1024) + 2) / 4); +} + +/*******************************************************************//** +Converts a comparison operator to the corresponding search mode PAGE_CUR_GE, +... +@return search mode */ +UNIV_INLINE +page_cur_mode_t +opt_op_to_search_mode( +/*==================*/ + ibool asc, /*!< in: TRUE if the rows should be fetched in an + ascending order */ + ulint op) /*!< in: operator '=', PARS_GE_TOKEN, ... */ +{ + if (op == '=' + || op == PARS_LIKE_TOKEN_EXACT + || op == PARS_LIKE_TOKEN_PREFIX + || op == PARS_LIKE_TOKEN_SUFFIX + || op == PARS_LIKE_TOKEN_SUBSTR) { + + if (asc) { + return(PAGE_CUR_GE); + } else { + return(PAGE_CUR_LE); + } + } else if (op == '<') { + ut_a(!asc); + return(PAGE_CUR_L); + } else if (op == '>') { + ut_a(asc); + return(PAGE_CUR_G); + } else if (op == PARS_GE_TOKEN) { + ut_a(asc); + return(PAGE_CUR_GE); + } else if (op == PARS_LE_TOKEN) { + ut_a(!asc); + return(PAGE_CUR_LE); + } else { + ut_error; + } + + return(PAGE_CUR_UNSUPP); +} + +/*******************************************************************//** +Determines if a node is an argument node of a function node. +@return TRUE if is an argument */ +static +ibool +opt_is_arg( +/*=======*/ + que_node_t* arg_node, /*!< in: possible argument node */ + func_node_t* func_node) /*!< in: function node */ +{ + que_node_t* arg; + + arg = func_node->args; + + while (arg) { + if (arg == arg_node) { + + return(TRUE); + } + + arg = que_node_get_next(arg); + } + + return(FALSE); +} + +/*******************************************************************//** +Decides if the fetching of rows should be made in a descending order, and +also checks that the chosen query plan produces a result which satisfies +the order-by. */ +static +void +opt_check_order_by( +/*===============*/ + sel_node_t* sel_node) /*!< in: select node; asserts an error + if the plan does not agree with the + order-by */ +{ + order_node_t* order_node; + dict_table_t* order_table; + ulint order_col_no; + plan_t* plan; + ulint i; + + if (!sel_node->order_by) { + + return; + } + + order_node = sel_node->order_by; + order_col_no = order_node->column->col_no; + order_table = order_node->column->table; + + /* If there is an order-by clause, the first non-exactly matched field + in the index used for the last table in the table list should be the + column defined in the order-by clause, and for all the other tables + we should get only at most a single row, otherwise we cannot presently + calculate the order-by, as we have no sort utility */ + + for (i = 0; i < sel_node->n_tables; i++) { + + plan = sel_node_get_nth_plan(sel_node, i); + + if (i < sel_node->n_tables - 1) { + ut_a(dict_index_get_n_unique(plan->index) + <= plan->n_exact_match); + } else { + ut_a(plan->table == order_table); + + ut_a((dict_index_get_n_unique(plan->index) + <= plan->n_exact_match) + || (dict_index_get_nth_col_no(plan->index, + plan->n_exact_match) + == order_col_no)); + } + } +} + +/*******************************************************************//** +Optimizes a select. Decides which indexes to tables to use. The tables +are accessed in the order that they were written to the FROM part in the +select statement. */ +static +void +opt_search_plan_for_table( +/*======================*/ + sel_node_t* sel_node, /*!< in: parsed select node */ + ulint i, /*!< in: this is the ith table */ + dict_table_t* table) /*!< in: table */ +{ + plan_t* plan; + dict_index_t* index; + ulint n_fields; + ulint best_last_op; + que_node_t* index_plan[256]; + que_node_t* best_index_plan[256]; + + plan = sel_node_get_nth_plan(sel_node, i); + + plan->table = table; + plan->asc = sel_node->asc; + plan->pcur_is_open = FALSE; + plan->cursor_at_end = FALSE; + + /* Calculate goodness for each index of the table */ + + plan->index = index = dict_table_get_first_index(table); + ulint best_goodness = opt_calc_index_goodness( + index, sel_node, i, best_index_plan, &best_last_op); + + while ((index = dict_table_get_next_index(index))) { + if (!index->is_btree()) { + continue; + } + ulint last_op; + ulint goodness = opt_calc_index_goodness(index, sel_node, i, + index_plan, &last_op); + if (goodness > best_goodness) { + best_goodness = goodness; + plan->index = index; + n_fields = opt_calc_n_fields_from_goodness(goodness); + + memcpy(best_index_plan, index_plan, + n_fields * sizeof *index_plan); + best_last_op = last_op; + } + } + + n_fields = opt_calc_n_fields_from_goodness(best_goodness); + + if (n_fields == 0) { + plan->tuple = NULL; + plan->n_exact_match = 0; + } else { + plan->tuple = dtuple_create(pars_sym_tab_global->heap, + n_fields); + dict_index_copy_types(plan->tuple, plan->index, n_fields); + + plan->tuple_exps = static_cast<que_node_t**>( + mem_heap_alloc( + pars_sym_tab_global->heap, + n_fields * sizeof(void*))); + + memcpy(plan->tuple_exps, best_index_plan, + n_fields * sizeof *best_index_plan); + + switch (best_last_op) { + case '=': + case PARS_LIKE_TOKEN_EXACT: + case PARS_LIKE_TOKEN_PREFIX: + case PARS_LIKE_TOKEN_SUFFIX: + case PARS_LIKE_TOKEN_SUBSTR: + break; + default: + n_fields--; + } + + plan->n_exact_match = n_fields; + plan->mode = opt_op_to_search_mode(sel_node->asc, + best_last_op); + } + + plan->unique_search = plan->index->is_clust() + && plan->n_exact_match >= plan->index->n_uniq; + + plan->old_vers_heap = NULL; + + btr_pcur_init(&(plan->pcur)); + btr_pcur_init(&(plan->clust_pcur)); +} + +/*******************************************************************//** +Looks at a comparison condition and decides if it can, and need, be tested for +a table AFTER the table has been accessed. +@return OPT_NOT_COND if not for this table, else OPT_END_COND, +OPT_TEST_COND, or OPT_SCROLL_COND, where the last means that the +condition need not be tested, except when scroll cursors are used */ +static +ulint +opt_classify_comparison( +/*====================*/ + sel_node_t* sel_node, /*!< in: select node */ + ulint i, /*!< in: ith table in the join */ + func_node_t* cond) /*!< in: comparison condition */ +{ + plan_t* plan; + ulint n_fields; + ulint op; + ulint j; + + ut_ad(cond && sel_node); + + plan = sel_node_get_nth_plan(sel_node, i); + + /* Check if the condition is determined after the ith table has been + accessed, but not after the i - 1:th */ + + if (!opt_check_exp_determined_before(cond, sel_node, i + 1)) { + + return(OPT_NOT_COND); + } + + if ((i > 0) && opt_check_exp_determined_before(cond, sel_node, i)) { + + return(OPT_NOT_COND); + } + + /* If the condition is an exact match condition used in constructing + the search tuple, it is classified as OPT_END_COND */ + + if (plan->tuple) { + n_fields = dtuple_get_n_fields(plan->tuple); + } else { + n_fields = 0; + } + + for (j = 0; j < plan->n_exact_match; j++) { + + if (opt_is_arg(plan->tuple_exps[j], cond)) { + + return(OPT_END_COND); + } + } + + /* If the condition is an non-exact match condition used in + constructing the search tuple, it is classified as OPT_SCROLL_COND. + When the cursor is positioned, and if a non-scroll cursor is used, + there is no need to test this condition; if a scroll cursor is used + the testing is necessary when the cursor is reversed. */ + + if ((n_fields > plan->n_exact_match) + && opt_is_arg(plan->tuple_exps[n_fields - 1], cond)) { + + return(OPT_SCROLL_COND); + } + + /* If the condition is a non-exact match condition on the first field + in index for which there is no exact match, and it limits the search + range from the opposite side of the search tuple already BEFORE we + access the table, it is classified as OPT_END_COND */ + + if ((dict_index_get_n_fields(plan->index) > plan->n_exact_match) + && opt_look_for_col_in_comparison_before( + OPT_COMPARISON, + dict_index_get_nth_col_no(plan->index, + plan->n_exact_match), + cond, sel_node, i, &op)) { + + if (sel_node->asc && ((op == '<') || (op == PARS_LE_TOKEN))) { + + return(OPT_END_COND); + } + + if (!sel_node->asc && ((op == '>') || (op == PARS_GE_TOKEN))) { + + return(OPT_END_COND); + } + } + + /* Otherwise, cond is classified as OPT_TEST_COND */ + + return(OPT_TEST_COND); +} + +/*******************************************************************//** +Recursively looks for test conditions for a table in a join. */ +static +void +opt_find_test_conds( +/*================*/ + sel_node_t* sel_node, /*!< in: select node */ + ulint i, /*!< in: ith table in the join */ + func_node_t* cond) /*!< in: conjunction of search + conditions or NULL */ +{ + func_node_t* new_cond; + ulint fclass; + plan_t* plan; + + if (cond == NULL) { + + return; + } + + if (cond->func == PARS_AND_TOKEN) { + new_cond = static_cast<func_node_t*>(cond->args); + + opt_find_test_conds(sel_node, i, new_cond); + + new_cond = static_cast<func_node_t*>( + que_node_get_next(new_cond)); + + opt_find_test_conds(sel_node, i, new_cond); + + return; + } + + plan = sel_node_get_nth_plan(sel_node, i); + + fclass = opt_classify_comparison(sel_node, i, cond); + + if (fclass == OPT_END_COND) { + UT_LIST_ADD_LAST(plan->end_conds, cond); + + } else if (fclass == OPT_TEST_COND) { + UT_LIST_ADD_LAST(plan->other_conds, cond); + + } +} + +/*******************************************************************//** +Normalizes a list of comparison conditions so that a column of the table +appears on the left side of the comparison if possible. This is accomplished +by switching the arguments of the operator. */ +static +void +opt_normalize_cmp_conds( +/*====================*/ + func_node_t* cond, /*!< in: first in a list of comparison + conditions, or NULL */ + dict_table_t* table) /*!< in: table */ +{ + que_node_t* arg1; + que_node_t* arg2; + sym_node_t* sym_node; + + while (cond) { + arg1 = cond->args; + arg2 = que_node_get_next(arg1); + + if (que_node_get_type(arg2) == QUE_NODE_SYMBOL) { + + sym_node = static_cast<sym_node_t*>(arg2); + + if ((sym_node->token_type == SYM_COLUMN) + && (sym_node->table == table)) { + + /* Switch the order of the arguments */ + + cond->args = arg2; + que_node_list_add_last(NULL, arg2); + que_node_list_add_last(arg2, arg1); + + /* Invert the operator */ + cond->func = opt_invert_cmp_op(cond->func); + } + } + + cond = UT_LIST_GET_NEXT(cond_list, cond); + } +} + +/*******************************************************************//** +Finds out the search condition conjuncts we can, and need, to test as the ith +table in a join is accessed. The search tuple can eliminate the need to test +some conjuncts. */ +static +void +opt_determine_and_normalize_test_conds( +/*===================================*/ + sel_node_t* sel_node, /*!< in: select node */ + ulint i) /*!< in: ith table in the join */ +{ + plan_t* plan; + + plan = sel_node_get_nth_plan(sel_node, i); + + UT_LIST_INIT(plan->end_conds, &func_node_t::cond_list); + UT_LIST_INIT(plan->other_conds, &func_node_t::cond_list); + + /* Recursively go through the conjuncts and classify them */ + + opt_find_test_conds( + sel_node, + i, + static_cast<func_node_t*>(sel_node->search_cond)); + + opt_normalize_cmp_conds(UT_LIST_GET_FIRST(plan->end_conds), + plan->table); + + ut_a(UT_LIST_GET_LEN(plan->end_conds) >= plan->n_exact_match); +} + +/*******************************************************************//** +Looks for occurrences of the columns of the table in the query subgraph and +adds them to the list of columns if an occurrence of the same column does not +already exist in the list. If the column is already in the list, puts a value +indirection to point to the occurrence in the column list, except if the +column occurrence we are looking at is in the column list, in which case +nothing is done. */ +void +opt_find_all_cols( +/*==============*/ + ibool copy_val, /*!< in: if TRUE, new found columns are + added as columns to copy */ + dict_index_t* index, /*!< in: index of the table to use */ + sym_node_list_t* col_list, /*!< in: base node of a list where + to add new found columns */ + plan_t* plan, /*!< in: plan or NULL */ + que_node_t* exp) /*!< in: expression or condition or + NULL */ +{ + func_node_t* func_node; + que_node_t* arg; + sym_node_t* sym_node; + sym_node_t* col_node; + ulint col_pos; + + if (exp == NULL) { + + return; + } + + if (que_node_get_type(exp) == QUE_NODE_FUNC) { + func_node = static_cast<func_node_t*>(exp); + + for (arg = func_node->args; + arg != 0; + arg = que_node_get_next(arg)) { + + opt_find_all_cols( + copy_val, index, col_list, plan, arg); + } + + return; + } + + ut_a(que_node_get_type(exp) == QUE_NODE_SYMBOL); + + sym_node = static_cast<sym_node_t*>(exp); + + if (sym_node->token_type != SYM_COLUMN) { + + return; + } + + if (sym_node->table != index->table) { + + return; + } + + /* Look for an occurrence of the same column in the plan column + list */ + + col_node = UT_LIST_GET_FIRST(*col_list); + + while (col_node) { + if (col_node->col_no == sym_node->col_no) { + + if (col_node == sym_node) { + /* sym_node was already in a list: do + nothing */ + + return; + } + + /* Put an indirection */ + sym_node->indirection = col_node; + sym_node->alias = col_node; + + return; + } + + col_node = UT_LIST_GET_NEXT(col_var_list, col_node); + } + + /* The same column did not occur in the list: add it */ + + UT_LIST_ADD_LAST(*col_list, sym_node); + + sym_node->copy_val = copy_val; + + /* Fill in the field_no fields in sym_node */ + + sym_node->field_nos[SYM_CLUST_FIELD_NO] = dict_index_get_nth_col_pos( + dict_table_get_first_index(index->table), sym_node->col_no, + NULL); + if (!dict_index_is_clust(index)) { + + ut_a(plan); + + col_pos = dict_index_get_nth_col_pos(index, sym_node->col_no, + NULL); + + if (col_pos == ULINT_UNDEFINED) { + + plan->must_get_clust = TRUE; + } + + sym_node->field_nos[SYM_SEC_FIELD_NO] = col_pos; + } +} + +/*******************************************************************//** +Looks for occurrences of the columns of the table in conditions which are +not yet determined AFTER the join operation has fetched a row in the ith +table. The values for these column must be copied to dynamic memory for +later use. */ +static +void +opt_find_copy_cols( +/*===============*/ + sel_node_t* sel_node, /*!< in: select node */ + ulint i, /*!< in: ith table in the join */ + func_node_t* search_cond) /*!< in: search condition or NULL */ +{ + func_node_t* new_cond; + plan_t* plan; + + if (search_cond == NULL) { + + return; + } + + ut_ad(que_node_get_type(search_cond) == QUE_NODE_FUNC); + + if (search_cond->func == PARS_AND_TOKEN) { + new_cond = static_cast<func_node_t*>(search_cond->args); + + opt_find_copy_cols(sel_node, i, new_cond); + + new_cond = static_cast<func_node_t*>( + que_node_get_next(new_cond)); + + opt_find_copy_cols(sel_node, i, new_cond); + + return; + } + + if (!opt_check_exp_determined_before(search_cond, sel_node, i + 1)) { + + /* Any ith table columns occurring in search_cond should be + copied, as this condition cannot be tested already on the + fetch from the ith table */ + + plan = sel_node_get_nth_plan(sel_node, i); + + opt_find_all_cols(TRUE, plan->index, &(plan->columns), plan, + search_cond); + } +} + +/*******************************************************************//** +Classifies the table columns according to whether we use the column only while +holding the latch on the page, or whether we have to copy the column value to +dynamic memory. Puts the first occurrence of a column to either list in the +plan node, and puts indirections to later occurrences of the column. */ +static +void +opt_classify_cols( +/*==============*/ + sel_node_t* sel_node, /*!< in: select node */ + ulint i) /*!< in: ith table in the join */ +{ + plan_t* plan; + que_node_t* exp; + + plan = sel_node_get_nth_plan(sel_node, i); + + /* The final value of the following field will depend on the + environment of the select statement: */ + + plan->must_get_clust = FALSE; + + UT_LIST_INIT(plan->columns, &sym_node_t::col_var_list); + + /* All select list columns should be copied: therefore TRUE as the + first argument */ + + for (exp = sel_node->select_list; + exp != 0; + exp = que_node_get_next(exp)) { + + opt_find_all_cols( + TRUE, plan->index, &(plan->columns), plan, exp); + } + + opt_find_copy_cols( + sel_node, i, static_cast<func_node_t*>(sel_node->search_cond)); + + /* All remaining columns in the search condition are temporary + columns: therefore FALSE */ + + opt_find_all_cols( + FALSE, plan->index, &plan->columns, plan, + static_cast<func_node_t*>(sel_node->search_cond)); +} + +/*******************************************************************//** +Fills in the info in plan which is used in accessing a clustered index +record. The columns must already be classified for the plan node. */ +static +void +opt_clust_access( +/*=============*/ + sel_node_t* sel_node, /*!< in: select node */ + ulint n) /*!< in: nth table in select */ +{ + plan_t* plan; + dict_table_t* table; + dict_index_t* clust_index; + dict_index_t* index; + mem_heap_t* heap; + ulint n_fields; + ulint pos; + ulint i; + + plan = sel_node_get_nth_plan(sel_node, n); + + index = plan->index; + + /* The final value of the following field depends on the environment + of the select statement: */ + + plan->no_prefetch = FALSE; + + if (dict_index_is_clust(index)) { + plan->clust_map = NULL; + plan->clust_ref = NULL; + + return; + } + + table = index->table; + + clust_index = dict_table_get_first_index(table); + + n_fields = dict_index_get_n_unique(clust_index); + + heap = pars_sym_tab_global->heap; + + plan->clust_ref = dtuple_create(heap, n_fields); + + dict_index_copy_types(plan->clust_ref, clust_index, n_fields); + + plan->clust_map = static_cast<ulint*>( + mem_heap_alloc(heap, n_fields * sizeof(ulint))); + + for (i = 0; i < n_fields; i++) { + pos = dict_index_get_nth_field_pos(index, clust_index, i); + + ut_a(pos != ULINT_UNDEFINED); + + /* We optimize here only queries to InnoDB's internal system + tables, and they should not contain column prefix indexes. */ + + if (dict_is_sys_table(index->table->id) + && (dict_index_get_nth_field(index, pos)->prefix_len != 0 + || dict_index_get_nth_field(clust_index, i) + ->prefix_len != 0)) { + ib::error() << "Error in pars0opt.cc: table " + << index->table->name + << " has prefix_len != 0"; + } + + *(plan->clust_map + i) = pos; + + ut_ad(pos != ULINT_UNDEFINED); + } +} + +#ifdef UNIV_SQL_DEBUG +/** Print info of a query plan. +@param[in,out] sel_node select node */ +static +void +opt_print_query_plan( + sel_node_t* sel_node); +#endif + +/*******************************************************************//** +Optimizes a select. Decides which indexes to tables to use. The tables +are accessed in the order that they were written to the FROM part in the +select statement. */ +void +opt_search_plan( +/*============*/ + sel_node_t* sel_node) /*!< in: parsed select node */ +{ + sym_node_t* table_node; + dict_table_t* table; + order_node_t* order_by; + ulint i; + + sel_node->plans = static_cast<plan_t*>( + mem_heap_alloc( + pars_sym_tab_global->heap, + sel_node->n_tables * sizeof(plan_t))); + + /* Analyze the search condition to find out what we know at each + join stage about the conditions that the columns of a table should + satisfy */ + + table_node = sel_node->table_list; + + if (sel_node->order_by == NULL) { + sel_node->asc = TRUE; + } else { + order_by = sel_node->order_by; + + sel_node->asc = order_by->asc; + } + + for (i = 0; i < sel_node->n_tables; i++) { + + table = table_node->table; + + /* Choose index through which to access the table */ + + opt_search_plan_for_table(sel_node, i, table); + + /* Determine the search condition conjuncts we can test at + this table; normalize the end conditions */ + + opt_determine_and_normalize_test_conds(sel_node, i); + + table_node = static_cast<sym_node_t*>( + que_node_get_next(table_node)); + } + + table_node = sel_node->table_list; + + for (i = 0; i < sel_node->n_tables; i++) { + + /* Classify the table columns into those we only need to access + but not copy, and to those we must copy to dynamic memory */ + + opt_classify_cols(sel_node, i); + + /* Calculate possible info for accessing the clustered index + record */ + + opt_clust_access(sel_node, i); + + table_node = static_cast<sym_node_t*>( + que_node_get_next(table_node)); + } + + /* Check that the plan obeys a possible order-by clause: if not, + an assertion error occurs */ + + opt_check_order_by(sel_node); + +#ifdef UNIV_SQL_DEBUG + opt_print_query_plan(sel_node); +#endif +} + +#ifdef UNIV_SQL_DEBUG +/** Print info of a query plan. +@param[in,out] sel_node select node */ +static +void +opt_print_query_plan( + sel_node_t* sel_node) +{ + plan_t* plan; + ulint n_fields; + ulint i; + + fputs("QUERY PLAN FOR A SELECT NODE\n", stderr); + + fputs(sel_node->asc ? "Asc. search; " : "Desc. search; ", stderr); + + if (sel_node->set_x_locks) { + fputs("sets row x-locks; ", stderr); + ut_a(sel_node->row_lock_mode == LOCK_X); + ut_a(!sel_node->consistent_read); + } else if (sel_node->consistent_read) { + fputs("consistent read; ", stderr); + } else { + ut_a(sel_node->row_lock_mode == LOCK_S); + fputs("sets row s-locks; ", stderr); + } + + putc('\n', stderr); + + for (i = 0; i < sel_node->n_tables; i++) { + plan = sel_node_get_nth_plan(sel_node, i); + + if (plan->tuple) { + n_fields = dtuple_get_n_fields(plan->tuple); + } else { + n_fields = 0; + } + + fprintf(stderr, + "Index %s of table %s" + "; exact m. %lu, match %lu, end conds %lu\n", + plan->index->name(), plan->index->table->name.m_name, + (unsigned long) plan->n_exact_match, + (unsigned long) n_fields, + (unsigned long) UT_LIST_GET_LEN(plan->end_conds)); + } +} +#endif /* UNIV_SQL_DEBUG */ diff --git a/storage/innobase/pars/pars0pars.cc b/storage/innobase/pars/pars0pars.cc new file mode 100644 index 00000000..61614007 --- /dev/null +++ b/storage/innobase/pars/pars0pars.cc @@ -0,0 +1,2381 @@ +/***************************************************************************** + +Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2018, 2021, MariaDB Corporation. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, +Fifth Floor, Boston, MA 02110-1335 USA + +*****************************************************************************/ + +/**************************************************//** +@file pars/pars0pars.c +SQL parser + +Created 11/19/1996 Heikki Tuuri +*******************************************************/ + +/* Historical note: Innobase executed its first SQL string (CREATE TABLE) +on 1/27/1998 */ + +#include "pars0pars.h" +#include "row0sel.h" +#include "row0ins.h" +#include "row0upd.h" +#include "dict0dict.h" +#include "dict0mem.h" +#include "dict0crea.h" +#include "que0que.h" +#include "pars0grm.h" +#include "pars0opt.h" +#include "data0data.h" +#include "data0type.h" +#include "trx0trx.h" +#include "trx0roll.h" +#include "eval0eval.h" + +/* Global variable used while parsing a single procedure or query : the code is +NOT re-entrant */ +sym_tab_t* pars_sym_tab_global; + +/* Global variables used to denote certain reserved words, used in +constructing the parsing tree */ + +pars_res_word_t pars_to_binary_token = {PARS_TO_BINARY_TOKEN}; +pars_res_word_t pars_substr_token = {PARS_SUBSTR_TOKEN}; +pars_res_word_t pars_concat_token = {PARS_CONCAT_TOKEN}; +pars_res_word_t pars_instr_token = {PARS_INSTR_TOKEN}; +pars_res_word_t pars_length_token = {PARS_LENGTH_TOKEN}; +pars_res_word_t pars_count_token = {PARS_COUNT_TOKEN}; +pars_res_word_t pars_int_token = {PARS_INT_TOKEN}; +pars_res_word_t pars_bigint_token = {PARS_BIGINT_TOKEN}; +pars_res_word_t pars_char_token = {PARS_CHAR_TOKEN}; +pars_res_word_t pars_update_token = {PARS_UPDATE_TOKEN}; +pars_res_word_t pars_asc_token = {PARS_ASC_TOKEN}; +pars_res_word_t pars_desc_token = {PARS_DESC_TOKEN}; +pars_res_word_t pars_open_token = {PARS_OPEN_TOKEN}; +pars_res_word_t pars_close_token = {PARS_CLOSE_TOKEN}; +pars_res_word_t pars_share_token = {PARS_SHARE_TOKEN}; +pars_res_word_t pars_unique_token = {PARS_UNIQUE_TOKEN}; +pars_res_word_t pars_clustered_token = {PARS_CLUSTERED_TOKEN}; + +/** Global variable used to denote the '*' in SELECT * FROM.. */ +ulint pars_star_denoter = 12345678; + +/******************************************************************** +Get user function with the given name.*/ +UNIV_INLINE +pars_user_func_t* +pars_info_lookup_user_func( +/*=======================*/ + /* out: user func, or NULL if not + found */ + pars_info_t* info, /* in: info struct */ + const char* name) /* in: function name to find*/ +{ + if (info && info->funcs) { + ulint i; + ib_vector_t* vec = info->funcs; + + for (i = 0; i < ib_vector_size(vec); i++) { + pars_user_func_t* puf; + + puf = static_cast<pars_user_func_t*>( + ib_vector_get(vec, i)); + + if (strcmp(puf->name, name) == 0) { + return(puf); + } + } + } + + return(NULL); +} + +/******************************************************************** +Get bound identifier with the given name.*/ +UNIV_INLINE +pars_bound_id_t* +pars_info_lookup_bound_id( +/*======================*/ + /* out: bound literal, or NULL if + not found */ + pars_info_t* info, /* in: info struct */ + const char* name) /* in: bound literal name to find */ +{ + if (info && info->bound_ids) { + ulint i; + ib_vector_t* vec = info->bound_ids; + + for (i = 0; i < ib_vector_size(vec); i++) { + pars_bound_id_t* bid; + + bid = static_cast<pars_bound_id_t*>( + ib_vector_get(vec, i)); + + if (strcmp(bid->name, name) == 0) { + return(bid); + } + } + } + + return(NULL); +} + +/******************************************************************** +Get bound literal with the given name.*/ +UNIV_INLINE +pars_bound_lit_t* +pars_info_lookup_bound_lit( +/*=======================*/ + /* out: bound literal, or NULL if + not found */ + pars_info_t* info, /* in: info struct */ + const char* name) /* in: bound literal name to find */ +{ + if (info && info->bound_lits) { + ulint i; + ib_vector_t* vec = info->bound_lits; + + for (i = 0; i < ib_vector_size(vec); i++) { + pars_bound_lit_t* pbl; + + pbl = static_cast<pars_bound_lit_t*>( + ib_vector_get(vec, i)); + + if (strcmp(pbl->name, name) == 0) { + return(pbl); + } + } + } + + return(NULL); +} + +/*********************************************************************//** +Determines the class of a function code. +@return function class: PARS_FUNC_ARITH, ... */ +static +ulint +pars_func_get_class( +/*================*/ + int func) /*!< in: function code: '=', PARS_GE_TOKEN, ... */ +{ + switch (func) { + case '+': case '-': case '*': case '/': + return(PARS_FUNC_ARITH); + + case '=': case '<': case '>': + case PARS_GE_TOKEN: case PARS_LE_TOKEN: case PARS_NE_TOKEN: + return(PARS_FUNC_CMP); + + case PARS_AND_TOKEN: case PARS_OR_TOKEN: case PARS_NOT_TOKEN: + return(PARS_FUNC_LOGICAL); + + case PARS_COUNT_TOKEN: + return(PARS_FUNC_AGGREGATE); + + case PARS_TO_BINARY_TOKEN: + case PARS_SUBSTR_TOKEN: + case PARS_CONCAT_TOKEN: + case PARS_LENGTH_TOKEN: + case PARS_INSTR_TOKEN: + case PARS_NOTFOUND_TOKEN: + return(PARS_FUNC_PREDEFINED); + + default: + return(PARS_FUNC_OTHER); + } +} + +/*********************************************************************//** +Parses an operator or predefined function expression. +@return own: function node in a query tree */ +static +func_node_t* +pars_func_low( +/*==========*/ + int func, /*!< in: function token code */ + que_node_t* arg) /*!< in: first argument in the argument list */ +{ + func_node_t* node; + + node = static_cast<func_node_t*>( + mem_heap_alloc(pars_sym_tab_global->heap, sizeof(func_node_t))); + + node->common.type = QUE_NODE_FUNC; + dfield_set_data(&(node->common.val), NULL, 0); + node->common.val_buf_size = 0; + + node->func = func; + + node->fclass = pars_func_get_class(func); + + node->args = arg; + + UT_LIST_ADD_LAST(pars_sym_tab_global->func_node_list, node); + + return(node); +} + +/*********************************************************************//** +Parses a function expression. +@return own: function node in a query tree */ +func_node_t* +pars_func( +/*======*/ + que_node_t* res_word,/*!< in: function name reserved word */ + que_node_t* arg) /*!< in: first argument in the argument list */ +{ + return(pars_func_low(((pars_res_word_t*) res_word)->code, arg)); +} + +/************************************************************************* +Rebind a LIKE search string. NOTE: We ignore any '%' characters embedded +within the search string.*/ +int +pars_like_rebind( +/*=============*/ + /* out, own: function node in a query tree */ + sym_node_t* node, /* in: The search string node.*/ + const byte* ptr, /* in: literal to (re) bind */ + ulint ptr_len)/* in: length of literal to (re) bind*/ +{ + dtype_t* dtype; + dfield_t* dfield; + ib_like_t op_check; + sym_node_t* like_node; + sym_node_t* str_node = NULL; + ib_like_t op = IB_LIKE_EXACT; + int func = PARS_LIKE_TOKEN_EXACT; + + /* Is this a STRING% ? */ + if (ptr[ptr_len - 1] == '%') { + op = IB_LIKE_PREFIX; + } + + /* Is this a '%STRING' or %STRING% ?*/ + ut_ad(*ptr != '%'); + + if (node->like_node == NULL) { + /* Add the LIKE operator info node to the node list. + This will be used during the comparison phase to determine + how to match.*/ + like_node = sym_tab_add_int_lit(node->sym_table, op); + que_node_list_add_last(NULL, like_node); + node->like_node = like_node; + str_node = sym_tab_add_str_lit(node->sym_table, ptr, ptr_len); + que_node_list_add_last(like_node, str_node); + } else { + like_node = node->like_node; + + /* Change the value of the string in the existing + string node of like node */ + str_node = static_cast<sym_node_t*>( + que_node_list_get_last(like_node)); + + /* Must find the string node */ + ut_a(str_node); + ut_a(str_node != like_node); + ut_a(str_node->token_type == SYM_LIT); + + dfield = que_node_get_val(str_node); + dfield_set_data(dfield, ptr, ptr_len); + } + + dfield = que_node_get_val(like_node); + dtype = dfield_get_type(dfield); + + ut_a(dtype_get_mtype(dtype) == DATA_INT); + op_check = static_cast<ib_like_t>( + mach_read_from_4(static_cast<byte*>(dfield_get_data(dfield)))); + + switch (op_check) { + case IB_LIKE_PREFIX: + case IB_LIKE_EXACT: + break; + + default: + ut_error; + } + + mach_write_to_4(static_cast<byte*>(dfield_get_data(dfield)), op); + + dfield = que_node_get_val(node); + + /* Adjust the length of the search value so the '%' is not + visible. Then create and add a search string node to the + search value node. Searching for %SUFFIX and %SUBSTR% requires + a full table scan and so we set the search value to ''. + For PREFIX% we simply remove the trailing '%'.*/ + + switch (op) { + case IB_LIKE_EXACT: + dfield = que_node_get_val(str_node); + dtype = dfield_get_type(dfield); + + ut_a(dtype_get_mtype(dtype) == DATA_VARCHAR); + + dfield_set_data(dfield, ptr, ptr_len); + break; + + case IB_LIKE_PREFIX: + func = PARS_LIKE_TOKEN_PREFIX; + + /* Modify the original node */ + dfield_set_len(dfield, ptr_len - 1); + + dfield = que_node_get_val(str_node); + dtype = dfield_get_type(dfield); + + ut_a(dtype_get_mtype(dtype) == DATA_VARCHAR); + + dfield_set_data(dfield, ptr, ptr_len - 1); + break; + + default: + ut_error; + } + + return(func); +} + +/************************************************************************* +Parses a LIKE operator expression. */ +static +int +pars_like_op( +/*=========*/ + /* out, own: function node in a query tree */ + que_node_t* arg) /* in: LIKE comparison string.*/ +{ + char* ptr; + ulint ptr_len; + int func = PARS_LIKE_TOKEN_EXACT; + dfield_t* dfield = que_node_get_val(arg); + dtype_t* dtype = dfield_get_type(dfield); + + ut_a(dtype_get_mtype(dtype) == DATA_CHAR + || dtype_get_mtype(dtype) == DATA_VARCHAR); + + ptr = static_cast<char*>(dfield_get_data(dfield)); + ptr_len = strlen(ptr); + + if (ptr_len) { + + func = pars_like_rebind( + static_cast<sym_node_t*>(arg), (byte*) ptr, ptr_len); + } + + return(func); +} +/*********************************************************************//** +Parses an operator expression. +@return own: function node in a query tree */ +func_node_t* +pars_op( +/*====*/ + int func, /*!< in: operator token code */ + que_node_t* arg1, /*!< in: first argument */ + que_node_t* arg2) /*!< in: second argument or NULL for an unary + operator */ +{ + que_node_list_add_last(NULL, arg1); + + if (arg2) { + que_node_list_add_last(arg1, arg2); + } + + /* We need to parse the string and determine whether it's a + PREFIX, SUFFIX or SUBSTRING comparison */ + if (func == PARS_LIKE_TOKEN) { + + ut_a(que_node_get_type(arg2) == QUE_NODE_SYMBOL); + + func = pars_like_op(arg2); + + ut_a(func == PARS_LIKE_TOKEN_EXACT + || func == PARS_LIKE_TOKEN_PREFIX + || func == PARS_LIKE_TOKEN_SUFFIX + || func == PARS_LIKE_TOKEN_SUBSTR); + } + + return(pars_func_low(func, arg1)); +} + +/*********************************************************************//** +Parses an ORDER BY clause. Order by a single column only is supported. +@return own: order-by node in a query tree */ +order_node_t* +pars_order_by( +/*==========*/ + sym_node_t* column, /*!< in: column name */ + pars_res_word_t* asc) /*!< in: &pars_asc_token or pars_desc_token */ +{ + order_node_t* node; + + node = static_cast<order_node_t*>( + mem_heap_alloc( + pars_sym_tab_global->heap, sizeof(order_node_t))); + + node->common.type = QUE_NODE_ORDER; + + node->column = column; + + if (asc == &pars_asc_token) { + node->asc = TRUE; + } else { + ut_a(asc == &pars_desc_token); + node->asc = FALSE; + } + + return(node); +} + +/*********************************************************************//** +Determine if a data type is a built-in string data type of the InnoDB +SQL parser. +@return TRUE if string data type */ +static +ibool +pars_is_string_type( +/*================*/ + ulint mtype) /*!< in: main data type */ +{ + switch (mtype) { + case DATA_VARCHAR: case DATA_CHAR: + case DATA_FIXBINARY: case DATA_BINARY: + return(TRUE); + } + + return(FALSE); +} + +/*********************************************************************//** +Resolves the data type of a function in an expression. The argument data +types must already be resolved. */ +static +void +pars_resolve_func_data_type( +/*========================*/ + func_node_t* node) /*!< in: function node */ +{ + que_node_t* arg; + + ut_a(que_node_get_type(node) == QUE_NODE_FUNC); + + arg = node->args; + + switch (node->func) { + case '+': case '-': case '*': case '/': + /* Inherit the data type from the first argument (which must + not be the SQL null literal whose type is DATA_ERROR) */ + + dtype_copy(que_node_get_data_type(node), + que_node_get_data_type(arg)); + + ut_a(dtype_get_mtype(que_node_get_data_type(node)) + == DATA_INT); + break; + + case PARS_COUNT_TOKEN: + ut_a(arg); + dtype_set(que_node_get_data_type(node), DATA_INT, 0, 4); + break; + + case PARS_TO_BINARY_TOKEN: + if (dtype_get_mtype(que_node_get_data_type(arg)) == DATA_INT) { + dtype_set(que_node_get_data_type(node), DATA_VARCHAR, + DATA_ENGLISH, 0); + } else { + dtype_set(que_node_get_data_type(node), DATA_BINARY, + 0, 0); + } + break; + + case PARS_LENGTH_TOKEN: + case PARS_INSTR_TOKEN: + ut_a(pars_is_string_type(que_node_get_data_type(arg)->mtype)); + dtype_set(que_node_get_data_type(node), DATA_INT, 0, 4); + break; + + case PARS_SUBSTR_TOKEN: + case PARS_CONCAT_TOKEN: + ut_a(pars_is_string_type(que_node_get_data_type(arg)->mtype)); + dtype_set(que_node_get_data_type(node), DATA_VARCHAR, + DATA_ENGLISH, 0); + break; + + case '>': case '<': case '=': + case PARS_GE_TOKEN: + case PARS_LE_TOKEN: + case PARS_NE_TOKEN: + case PARS_AND_TOKEN: + case PARS_OR_TOKEN: + case PARS_NOT_TOKEN: + case PARS_NOTFOUND_TOKEN: + + /* We currently have no iboolean type: use integer type */ + dtype_set(que_node_get_data_type(node), DATA_INT, 0, 4); + break; + + case PARS_LIKE_TOKEN_EXACT: + case PARS_LIKE_TOKEN_PREFIX: + case PARS_LIKE_TOKEN_SUFFIX: + case PARS_LIKE_TOKEN_SUBSTR: + dtype_set(que_node_get_data_type(node), DATA_VARCHAR, + DATA_ENGLISH, 0); + break; + + default: + ut_error; + } +} + +/*********************************************************************//** +Resolves the meaning of variables in an expression and the data types of +functions. It is an error if some identifier cannot be resolved here. */ +static +void +pars_resolve_exp_variables_and_types( +/*=================================*/ + sel_node_t* select_node, /*!< in: select node or NULL; if + this is not NULL then the variable + sym nodes are added to the + copy_variables list of select_node */ + que_node_t* exp_node) /*!< in: expression */ +{ + func_node_t* func_node; + que_node_t* arg; + sym_node_t* sym_node; + sym_node_t* node; + + ut_a(exp_node); + + if (que_node_get_type(exp_node) == QUE_NODE_FUNC) { + func_node = static_cast<func_node_t*>(exp_node); + + arg = func_node->args; + + while (arg) { + pars_resolve_exp_variables_and_types(select_node, arg); + + arg = que_node_get_next(arg); + } + + pars_resolve_func_data_type(func_node); + + return; + } + + ut_a(que_node_get_type(exp_node) == QUE_NODE_SYMBOL); + + sym_node = static_cast<sym_node_t*>(exp_node); + + if (sym_node->resolved) { + + return; + } + + /* Not resolved yet: look in the symbol table for a variable + or a cursor or a function with the same name */ + + node = UT_LIST_GET_FIRST(pars_sym_tab_global->sym_list); + + while (node) { + if (node->resolved + && ((node->token_type == SYM_VAR) + || (node->token_type == SYM_CURSOR) + || (node->token_type == SYM_FUNCTION)) + && node->name + && sym_node->name_len == node->name_len + && !memcmp(sym_node->name, node->name, node->name_len)) { + + /* Found a variable or a cursor declared with + the same name */ + + break; + } + + node = UT_LIST_GET_NEXT(sym_list, node); + } + + if (!node) { + fprintf(stderr, "PARSER ERROR: Unresolved identifier %s\n", + sym_node->name); + } + + ut_a(node); + + sym_node->resolved = TRUE; + sym_node->token_type = SYM_IMPLICIT_VAR; + sym_node->alias = node; + sym_node->indirection = node; + + if (select_node) { + UT_LIST_ADD_LAST(select_node->copy_variables, sym_node); + } + + dfield_set_type(que_node_get_val(sym_node), + que_node_get_data_type(node)); +} + +/*********************************************************************//** +Resolves the meaning of variables in an expression list. It is an error if +some identifier cannot be resolved here. Resolves also the data types of +functions. */ +static +void +pars_resolve_exp_list_variables_and_types( +/*======================================*/ + sel_node_t* select_node, /*!< in: select node or NULL */ + que_node_t* exp_node) /*!< in: expression list first node, or + NULL */ +{ + while (exp_node) { + pars_resolve_exp_variables_and_types(select_node, exp_node); + + exp_node = que_node_get_next(exp_node); + } +} + +/*********************************************************************//** +Resolves the columns in an expression. */ +static +void +pars_resolve_exp_columns( +/*=====================*/ + sym_node_t* table_node, /*!< in: first node in a table list */ + que_node_t* exp_node) /*!< in: expression */ +{ + func_node_t* func_node; + que_node_t* arg; + sym_node_t* sym_node; + dict_table_t* table; + sym_node_t* t_node; + ulint n_cols; + ulint i; + + ut_a(exp_node); + + if (que_node_get_type(exp_node) == QUE_NODE_FUNC) { + func_node = static_cast<func_node_t*>(exp_node); + + arg = func_node->args; + + while (arg) { + pars_resolve_exp_columns(table_node, arg); + + arg = que_node_get_next(arg); + } + + return; + } + + ut_a(que_node_get_type(exp_node) == QUE_NODE_SYMBOL); + + sym_node = static_cast<sym_node_t*>(exp_node); + + if (sym_node->resolved) { + + return; + } + + /* Not resolved yet: look in the table list for a column with the + same name */ + + t_node = table_node; + + while (t_node) { + table = t_node->table; + + n_cols = dict_table_get_n_cols(table); + + for (i = 0; i < n_cols; i++) { + const dict_col_t* col + = dict_table_get_nth_col(table, i); + const char* col_name + = dict_table_get_col_name(table, i); + + if (sym_node->name_len == strlen(col_name) + && !memcmp(sym_node->name, col_name, + sym_node->name_len)) { + /* Found */ + sym_node->resolved = TRUE; + sym_node->token_type = SYM_COLUMN; + sym_node->table = table; + sym_node->col_no = i; + sym_node->prefetch_buf = NULL; + + dict_col_copy_type( + col, + dfield_get_type(&sym_node + ->common.val)); + + return; + } + } + + t_node = static_cast<sym_node_t*>(que_node_get_next(t_node)); + } +} + +/*********************************************************************//** +Resolves the meaning of columns in an expression list. */ +static +void +pars_resolve_exp_list_columns( +/*==========================*/ + sym_node_t* table_node, /*!< in: first node in a table list */ + que_node_t* exp_node) /*!< in: expression list first node, or + NULL */ +{ + while (exp_node) { + pars_resolve_exp_columns(table_node, exp_node); + + exp_node = que_node_get_next(exp_node); + } +} + +/*********************************************************************//** +Retrieves the table definition for a table name id. */ +static +void +pars_retrieve_table_def( +/*====================*/ + sym_node_t* sym_node) /*!< in: table node */ +{ + ut_a(sym_node); + ut_a(que_node_get_type(sym_node) == QUE_NODE_SYMBOL); + + /* Open the table only if it is not already opened. */ + if (sym_node->token_type != SYM_TABLE_REF_COUNTED) { + + ut_a(sym_node->table == NULL); + + sym_node->resolved = TRUE; + sym_node->token_type = SYM_TABLE_REF_COUNTED; + + sym_node->table = dict_table_open_on_name( + sym_node->name, true, DICT_ERR_IGNORE_NONE); + + ut_a(sym_node->table != NULL); + } +} + +/*********************************************************************//** +Retrieves the table definitions for a list of table name ids. +@return number of tables */ +static +ulint +pars_retrieve_table_list_defs( +/*==========================*/ + sym_node_t* sym_node) /*!< in: first table node in list */ +{ + ulint count = 0; + + if (sym_node == NULL) { + + return(count); + } + + while (sym_node) { + pars_retrieve_table_def(sym_node); + + count++; + + sym_node = static_cast<sym_node_t*>( + que_node_get_next(sym_node)); + } + + return(count); +} + +/*********************************************************************//** +Adds all columns to the select list if the query is SELECT * FROM ... */ +static +void +pars_select_all_columns( +/*====================*/ + sel_node_t* select_node) /*!< in: select node already containing + the table list */ +{ + sym_node_t* col_node; + sym_node_t* table_node; + dict_table_t* table; + ulint i; + + select_node->select_list = NULL; + + table_node = select_node->table_list; + + while (table_node) { + table = table_node->table; + + for (i = 0; i < dict_table_get_n_user_cols(table); i++) { + const char* col_name = dict_table_get_col_name( + table, i); + + col_node = sym_tab_add_id(pars_sym_tab_global, + (byte*) col_name, + strlen(col_name)); + + select_node->select_list = que_node_list_add_last( + select_node->select_list, col_node); + } + + table_node = static_cast<sym_node_t*>( + que_node_get_next(table_node)); + } +} + +/*********************************************************************//** +Parses a select list; creates a query graph node for the whole SELECT +statement. +@return own: select node in a query tree */ +sel_node_t* +pars_select_list( +/*=============*/ + que_node_t* select_list, /*!< in: select list */ + sym_node_t* into_list) /*!< in: variables list or NULL */ +{ + sel_node_t* node; + + node = sel_node_create(pars_sym_tab_global->heap); + + node->select_list = select_list; + node->into_list = into_list; + + pars_resolve_exp_list_variables_and_types(NULL, into_list); + + return(node); +} + +/*********************************************************************//** +Checks if the query is an aggregate query, in which case the selct list must +contain only aggregate function items. */ +static +void +pars_check_aggregate( +/*=================*/ + sel_node_t* select_node) /*!< in: select node already containing + the select list */ +{ + que_node_t* exp_node; + func_node_t* func_node; + ulint n_nodes = 0; + ulint n_aggregate_nodes = 0; + + exp_node = select_node->select_list; + + while (exp_node) { + + n_nodes++; + + if (que_node_get_type(exp_node) == QUE_NODE_FUNC) { + + func_node = static_cast<func_node_t*>(exp_node); + + if (func_node->fclass == PARS_FUNC_AGGREGATE) { + + n_aggregate_nodes++; + } + } + + exp_node = que_node_get_next(exp_node); + } + + if (n_aggregate_nodes > 0) { + ut_a(n_nodes == n_aggregate_nodes); + + select_node->is_aggregate = TRUE; + } else { + select_node->is_aggregate = FALSE; + } +} + +/*********************************************************************//** +Parses a select statement. +@return own: select node in a query tree */ +sel_node_t* +pars_select_statement( +/*==================*/ + sel_node_t* select_node, /*!< in: select node already containing + the select list */ + sym_node_t* table_list, /*!< in: table list */ + que_node_t* search_cond, /*!< in: search condition or NULL */ + pars_res_word_t* for_update, /*!< in: NULL or &pars_update_token */ + pars_res_word_t* lock_shared, /*!< in: NULL or &pars_share_token */ + order_node_t* order_by) /*!< in: NULL or an order-by node */ +{ + select_node->state = SEL_NODE_OPEN; + + select_node->table_list = table_list; + select_node->n_tables = pars_retrieve_table_list_defs(table_list); + + if (select_node->select_list == &pars_star_denoter) { + + /* SELECT * FROM ... */ + pars_select_all_columns(select_node); + } + + if (select_node->into_list) { + ut_a(que_node_list_get_len(select_node->into_list) + == que_node_list_get_len(select_node->select_list)); + } + + UT_LIST_INIT(select_node->copy_variables, &sym_node_t::col_var_list); + + pars_resolve_exp_list_columns(table_list, select_node->select_list); + pars_resolve_exp_list_variables_and_types(select_node, + select_node->select_list); + pars_check_aggregate(select_node); + + select_node->search_cond = search_cond; + + if (search_cond) { + pars_resolve_exp_columns(table_list, search_cond); + pars_resolve_exp_variables_and_types(select_node, search_cond); + } + + if (for_update) { + ut_a(!lock_shared); + + select_node->set_x_locks = TRUE; + select_node->row_lock_mode = LOCK_X; + + select_node->consistent_read = FALSE; + select_node->read_view = NULL; + } else if (lock_shared){ + select_node->set_x_locks = FALSE; + select_node->row_lock_mode = LOCK_S; + + select_node->consistent_read = FALSE; + select_node->read_view = NULL; + } else { + select_node->set_x_locks = FALSE; + select_node->row_lock_mode = LOCK_S; + + select_node->consistent_read = TRUE; + } + + select_node->order_by = order_by; + + if (order_by) { + pars_resolve_exp_columns(table_list, order_by->column); + } + + /* The final value of the following fields depend on the environment + where the select statement appears: */ + + select_node->can_get_updated = FALSE; + select_node->explicit_cursor = NULL; + + opt_search_plan(select_node); + + return(select_node); +} + +/*********************************************************************//** +Parses a cursor declaration. +@return sym_node */ +que_node_t* +pars_cursor_declaration( +/*====================*/ + sym_node_t* sym_node, /*!< in: cursor id node in the symbol + table */ + sel_node_t* select_node) /*!< in: select node */ +{ + sym_node->resolved = TRUE; + sym_node->token_type = SYM_CURSOR; + sym_node->cursor_def = select_node; + + select_node->state = SEL_NODE_CLOSED; + select_node->explicit_cursor = sym_node; + + return(sym_node); +} + +/*********************************************************************//** +Parses a function declaration. +@return sym_node */ +que_node_t* +pars_function_declaration( +/*======================*/ + sym_node_t* sym_node) /*!< in: function id node in the symbol + table */ +{ + sym_node->resolved = TRUE; + sym_node->token_type = SYM_FUNCTION; + + /* Check that the function exists. */ + ut_a(pars_info_lookup_user_func( + pars_sym_tab_global->info, sym_node->name)); + + return(sym_node); +} + +/*********************************************************************//** +Parses a delete or update statement start. +@return own: update node in a query tree */ +upd_node_t* +pars_update_statement_start( +/*========================*/ + ibool is_delete, /*!< in: TRUE if delete */ + sym_node_t* table_sym, /*!< in: table name node */ + col_assign_node_t* col_assign_list)/*!< in: column assignment list, NULL + if delete */ +{ + upd_node_t* node; + + node = upd_node_create(pars_sym_tab_global->heap); + + node->is_delete = is_delete ? PLAIN_DELETE : NO_DELETE; + + node->table_sym = table_sym; + node->col_assign_list = col_assign_list; + + return(node); +} + +/*********************************************************************//** +Parses a column assignment in an update. +@return column assignment node */ +col_assign_node_t* +pars_column_assignment( +/*===================*/ + sym_node_t* column, /*!< in: column to assign */ + que_node_t* exp) /*!< in: value to assign */ +{ + col_assign_node_t* node; + + node = static_cast<col_assign_node_t*>( + mem_heap_alloc(pars_sym_tab_global->heap, + sizeof(col_assign_node_t))); + node->common.type = QUE_NODE_COL_ASSIGNMENT; + + node->col = column; + node->val = exp; + + return(node); +} + +/*********************************************************************//** +Processes an update node assignment list. */ +static +void +pars_process_assign_list( +/*=====================*/ + upd_node_t* node) /*!< in: update node */ +{ + col_assign_node_t* col_assign_list; + sym_node_t* table_sym; + col_assign_node_t* assign_node; + upd_field_t* upd_field; + dict_index_t* clust_index; + sym_node_t* col_sym; + ulint changes_ord_field; + ulint changes_field_size; + ulint n_assigns; + ulint i; + + table_sym = node->table_sym; + col_assign_list = static_cast<col_assign_node_t*>( + node->col_assign_list); + clust_index = dict_table_get_first_index(node->table); + + assign_node = col_assign_list; + n_assigns = 0; + + while (assign_node) { + pars_resolve_exp_columns(table_sym, assign_node->col); + pars_resolve_exp_columns(table_sym, assign_node->val); + pars_resolve_exp_variables_and_types(NULL, assign_node->val); +#if 0 + ut_a(dtype_get_mtype( + dfield_get_type(que_node_get_val( + assign_node->col))) + == dtype_get_mtype( + dfield_get_type(que_node_get_val( + assign_node->val)))); +#endif + + /* Add to the update node all the columns found in assignment + values as columns to copy: therefore, TRUE */ + + opt_find_all_cols(TRUE, clust_index, &(node->columns), NULL, + assign_node->val); + n_assigns++; + + assign_node = static_cast<col_assign_node_t*>( + que_node_get_next(assign_node)); + } + + node->update = upd_create(n_assigns, pars_sym_tab_global->heap); + + assign_node = col_assign_list; + + changes_field_size = UPD_NODE_NO_SIZE_CHANGE; + + for (i = 0; i < n_assigns; i++) { + upd_field = upd_get_nth_field(node->update, i); + + col_sym = assign_node->col; + + ulint field_no = dict_index_get_nth_col_pos( + clust_index, col_sym->col_no, NULL); + ut_ad(field_no < clust_index->n_fields); + upd_field_set_field_no(upd_field, + static_cast<uint16_t>(field_no), + clust_index); + upd_field->exp = assign_node->val; + + if (!dict_col_get_fixed_size( + dict_index_get_nth_col(clust_index, + upd_field->field_no), + dict_table_is_comp(node->table))) { + changes_field_size = 0; + } + + assign_node = static_cast<col_assign_node_t*>( + que_node_get_next(assign_node)); + } + + /* Find out if the update can modify an ordering field in any index */ + + changes_ord_field = UPD_NODE_NO_ORD_CHANGE; + + if (row_upd_changes_some_index_ord_field_binary(node->table, + node->update)) { + changes_ord_field = 0; + } + + node->cmpl_info = changes_ord_field | changes_field_size; +} + +/*********************************************************************//** +Parses an update or delete statement. +@return own: update node in a query tree */ +upd_node_t* +pars_update_statement( +/*==================*/ + upd_node_t* node, /*!< in: update node */ + sym_node_t* cursor_sym, /*!< in: pointer to a cursor entry in + the symbol table or NULL */ + que_node_t* search_cond) /*!< in: search condition or NULL */ +{ + sym_node_t* table_sym; + sel_node_t* sel_node; + plan_t* plan; + + table_sym = node->table_sym; + + pars_retrieve_table_def(table_sym); + node->table = table_sym->table; + + UT_LIST_INIT(node->columns, &sym_node_t::col_var_list); + + /* Make the single table node into a list of table nodes of length 1 */ + + que_node_list_add_last(NULL, table_sym); + + if (cursor_sym) { + pars_resolve_exp_variables_and_types(NULL, cursor_sym); + + sel_node = cursor_sym->alias->cursor_def; + + node->searched_update = FALSE; + } else { + sel_node = pars_select_list(NULL, NULL); + + pars_select_statement(sel_node, table_sym, search_cond, NULL, + &pars_share_token, NULL); + node->searched_update = TRUE; + sel_node->common.parent = node; + } + + node->select = sel_node; + + ut_a(!node->is_delete || (node->col_assign_list == NULL)); + ut_a(node->is_delete == PLAIN_DELETE || node->col_assign_list != NULL); + + if (node->is_delete == PLAIN_DELETE) { + node->cmpl_info = 0; + } else { + pars_process_assign_list(node); + } + + if (node->searched_update) { + node->has_clust_rec_x_lock = TRUE; + sel_node->set_x_locks = TRUE; + sel_node->row_lock_mode = LOCK_X; + } else { + node->has_clust_rec_x_lock = sel_node->set_x_locks; + ut_ad(node->has_clust_rec_x_lock); + } + + ut_a(sel_node->n_tables == 1); + ut_a(sel_node->consistent_read == FALSE); + ut_a(sel_node->order_by == NULL); + ut_a(sel_node->is_aggregate == FALSE); + + sel_node->can_get_updated = TRUE; + + node->state = UPD_NODE_UPDATE_CLUSTERED; + + plan = sel_node_get_nth_plan(sel_node, 0); + + plan->no_prefetch = TRUE; + + if (!dict_index_is_clust(plan->index)) { + + plan->must_get_clust = TRUE; + + node->pcur = &(plan->clust_pcur); + } else { + node->pcur = &(plan->pcur); + } + + return(node); +} + +/*********************************************************************//** +Parses an insert statement. +@return own: update node in a query tree */ +ins_node_t* +pars_insert_statement( +/*==================*/ + sym_node_t* table_sym, /*!< in: table name node */ + que_node_t* values_list, /*!< in: value expression list or NULL */ + sel_node_t* select) /*!< in: select condition or NULL */ +{ + ins_node_t* node; + dtuple_t* row; + ulint ins_type; + + ut_a(values_list || select); + ut_a(!values_list || !select); + + if (values_list) { + ins_type = INS_VALUES; + } else { + ins_type = INS_SEARCHED; + } + + pars_retrieve_table_def(table_sym); + + node = ins_node_create(ins_type, table_sym->table, + pars_sym_tab_global->heap); + + row = dtuple_create(pars_sym_tab_global->heap, + dict_table_get_n_cols(node->table)); + + dict_table_copy_types(row, table_sym->table); + + ins_node_set_new_row(node, row); + + node->select = select; + + if (select) { + select->common.parent = node; + + ut_a(que_node_list_get_len(select->select_list) + == dict_table_get_n_user_cols(table_sym->table)); + } + + node->values_list = values_list; + + if (node->values_list) { + pars_resolve_exp_list_variables_and_types(NULL, values_list); + + ut_a(que_node_list_get_len(values_list) + == dict_table_get_n_user_cols(table_sym->table)); + } + + return(node); +} + +/*********************************************************************//** +Set the type of a dfield. */ +static +void +pars_set_dfield_type( +/*=================*/ + dfield_t* dfield, /*!< in: dfield */ + pars_res_word_t* type, /*!< in: pointer to a type + token */ + ulint len, /*!< in: length, or 0 */ + bool is_not_null) /*!< in: whether the column is + NOT NULL. */ +{ + ulint flags = 0; + + if (is_not_null) { + flags |= DATA_NOT_NULL; + } + + if (type == &pars_bigint_token) { + ut_a(len == 0); + + dtype_set(dfield_get_type(dfield), DATA_INT, flags, 8); + } else if (type == &pars_int_token) { + ut_a(len == 0); + + dtype_set(dfield_get_type(dfield), DATA_INT, flags, 4); + + } else if (type == &pars_char_token) { + //ut_a(len == 0); + + dtype_set(dfield_get_type(dfield), DATA_VARCHAR, + DATA_ENGLISH | flags, len); + } else { + ut_error; + } +} + +/*********************************************************************//** +Parses a variable declaration. +@return own: symbol table node of type SYM_VAR */ +sym_node_t* +pars_variable_declaration( +/*======================*/ + sym_node_t* node, /*!< in: symbol table node allocated for the + id of the variable */ + pars_res_word_t* type) /*!< in: pointer to a type token */ +{ + node->resolved = TRUE; + node->token_type = SYM_VAR; + + node->param_type = PARS_NOT_PARAM; + + pars_set_dfield_type(que_node_get_val(node), type, 0, false); + + return(node); +} + +/*********************************************************************//** +Sets the parent field in a query node list. */ +static +void +pars_set_parent_in_list( +/*====================*/ + que_node_t* node_list, /*!< in: first node in a list */ + que_node_t* parent) /*!< in: parent value to set in all + nodes of the list */ +{ + que_common_t* common; + + common = static_cast<que_common_t*>(node_list); + + while (common) { + common->parent = parent; + + common = static_cast<que_common_t*>(que_node_get_next(common)); + } +} + +/*********************************************************************//** +Parses an elsif element. +@return elsif node */ +elsif_node_t* +pars_elsif_element( +/*===============*/ + que_node_t* cond, /*!< in: if-condition */ + que_node_t* stat_list) /*!< in: statement list */ +{ + elsif_node_t* node; + + node = static_cast<elsif_node_t*>( + mem_heap_alloc( + pars_sym_tab_global->heap, sizeof(elsif_node_t))); + + node->common.type = QUE_NODE_ELSIF; + + node->cond = cond; + + pars_resolve_exp_variables_and_types(NULL, cond); + + node->stat_list = stat_list; + + return(node); +} + +/*********************************************************************//** +Parses an if-statement. +@return if-statement node */ +if_node_t* +pars_if_statement( +/*==============*/ + que_node_t* cond, /*!< in: if-condition */ + que_node_t* stat_list, /*!< in: statement list */ + que_node_t* else_part) /*!< in: else-part statement list + or elsif element list */ +{ + if_node_t* node; + elsif_node_t* elsif_node; + + node = static_cast<if_node_t*>( + mem_heap_alloc( + pars_sym_tab_global->heap, sizeof(if_node_t))); + + node->common.type = QUE_NODE_IF; + + node->cond = cond; + + pars_resolve_exp_variables_and_types(NULL, cond); + + node->stat_list = stat_list; + + if (else_part && (que_node_get_type(else_part) == QUE_NODE_ELSIF)) { + + /* There is a list of elsif conditions */ + + node->else_part = NULL; + node->elsif_list = static_cast<elsif_node_t*>(else_part); + + elsif_node = static_cast<elsif_node_t*>(else_part); + + while (elsif_node) { + pars_set_parent_in_list(elsif_node->stat_list, node); + + elsif_node = static_cast<elsif_node_t*>( + que_node_get_next(elsif_node)); + } + } else { + node->else_part = else_part; + node->elsif_list = NULL; + + pars_set_parent_in_list(else_part, node); + } + + pars_set_parent_in_list(stat_list, node); + + return(node); +} + +/*********************************************************************//** +Parses a while-statement. +@return while-statement node */ +while_node_t* +pars_while_statement( +/*=================*/ + que_node_t* cond, /*!< in: while-condition */ + que_node_t* stat_list) /*!< in: statement list */ +{ + while_node_t* node; + + node = static_cast<while_node_t*>( + mem_heap_alloc( + pars_sym_tab_global->heap, sizeof(while_node_t))); + + node->common.type = QUE_NODE_WHILE; + + node->cond = cond; + + pars_resolve_exp_variables_and_types(NULL, cond); + + node->stat_list = stat_list; + + pars_set_parent_in_list(stat_list, node); + + return(node); +} + +/*********************************************************************//** +Parses a for-loop-statement. +@return for-statement node */ +for_node_t* +pars_for_statement( +/*===============*/ + sym_node_t* loop_var, /*!< in: loop variable */ + que_node_t* loop_start_limit,/*!< in: loop start expression */ + que_node_t* loop_end_limit, /*!< in: loop end expression */ + que_node_t* stat_list) /*!< in: statement list */ +{ + for_node_t* node; + + node = static_cast<for_node_t*>( + mem_heap_alloc(pars_sym_tab_global->heap, sizeof(for_node_t))); + + node->common.type = QUE_NODE_FOR; + + pars_resolve_exp_variables_and_types(NULL, loop_var); + pars_resolve_exp_variables_and_types(NULL, loop_start_limit); + pars_resolve_exp_variables_and_types(NULL, loop_end_limit); + + node->loop_var = loop_var->indirection; + + ut_a(loop_var->indirection); + + node->loop_start_limit = loop_start_limit; + node->loop_end_limit = loop_end_limit; + + node->stat_list = stat_list; + + pars_set_parent_in_list(stat_list, node); + + return(node); +} + +/*********************************************************************//** +Parses an exit statement. +@return exit statement node */ +exit_node_t* +pars_exit_statement(void) +/*=====================*/ +{ + exit_node_t* node; + + node = static_cast<exit_node_t*>( + mem_heap_alloc(pars_sym_tab_global->heap, sizeof(exit_node_t))); + node->common.type = QUE_NODE_EXIT; + + return(node); +} + +/*********************************************************************//** +Parses a return-statement. +@return return-statement node */ +return_node_t* +pars_return_statement(void) +/*=======================*/ +{ + return_node_t* node; + + node = static_cast<return_node_t*>( + mem_heap_alloc( + pars_sym_tab_global->heap, sizeof(return_node_t))); + node->common.type = QUE_NODE_RETURN; + + return(node); +} + +/*********************************************************************//** +Parses an assignment statement. +@return assignment statement node */ +assign_node_t* +pars_assignment_statement( +/*======================*/ + sym_node_t* var, /*!< in: variable to assign */ + que_node_t* val) /*!< in: value to assign */ +{ + assign_node_t* node; + + node = static_cast<assign_node_t*>( + mem_heap_alloc( + pars_sym_tab_global->heap, sizeof(assign_node_t))); + node->common.type = QUE_NODE_ASSIGNMENT; + + node->var = var; + node->val = val; + + pars_resolve_exp_variables_and_types(NULL, var); + pars_resolve_exp_variables_and_types(NULL, val); + + ut_a(dtype_get_mtype(dfield_get_type(que_node_get_val(var))) + == dtype_get_mtype(dfield_get_type(que_node_get_val(val)))); + + return(node); +} + +/*********************************************************************//** +Parses a procedure call. +@return function node */ +func_node_t* +pars_procedure_call( +/*================*/ + que_node_t* res_word,/*!< in: procedure name reserved word */ + que_node_t* args) /*!< in: argument list */ +{ + func_node_t* node; + + node = pars_func(res_word, args); + + pars_resolve_exp_list_variables_and_types(NULL, args); + + return(node); +} + +/*********************************************************************//** +Parses a fetch statement. into_list or user_func (but not both) must be +non-NULL. +@return fetch statement node */ +fetch_node_t* +pars_fetch_statement( +/*=================*/ + sym_node_t* cursor, /*!< in: cursor node */ + sym_node_t* into_list, /*!< in: variables to set, or NULL */ + sym_node_t* user_func) /*!< in: user function name, or NULL */ +{ + sym_node_t* cursor_decl; + fetch_node_t* node; + + /* Logical XOR. */ + ut_a(!into_list != !user_func); + + node = static_cast<fetch_node_t*>( + mem_heap_alloc( + pars_sym_tab_global->heap, sizeof(fetch_node_t))); + + node->common.type = QUE_NODE_FETCH; + + pars_resolve_exp_variables_and_types(NULL, cursor); + + if (into_list) { + pars_resolve_exp_list_variables_and_types(NULL, into_list); + node->into_list = into_list; + node->func = NULL; + } else { + pars_resolve_exp_variables_and_types(NULL, user_func); + + node->func = pars_info_lookup_user_func( + pars_sym_tab_global->info, user_func->name); + + ut_a(node->func); + + node->into_list = NULL; + } + + cursor_decl = cursor->alias; + + ut_a(cursor_decl->token_type == SYM_CURSOR); + + node->cursor_def = cursor_decl->cursor_def; + + if (into_list) { + ut_a(que_node_list_get_len(into_list) + == que_node_list_get_len(node->cursor_def->select_list)); + } + + return(node); +} + +/*********************************************************************//** +Parses an open or close cursor statement. +@return fetch statement node */ +open_node_t* +pars_open_statement( +/*================*/ + ulint type, /*!< in: ROW_SEL_OPEN_CURSOR + or ROW_SEL_CLOSE_CURSOR */ + sym_node_t* cursor) /*!< in: cursor node */ +{ + sym_node_t* cursor_decl; + open_node_t* node; + + node = static_cast<open_node_t*>( + mem_heap_alloc( + pars_sym_tab_global->heap, sizeof(open_node_t))); + + node->common.type = QUE_NODE_OPEN; + + pars_resolve_exp_variables_and_types(NULL, cursor); + + cursor_decl = cursor->alias; + + ut_a(cursor_decl->token_type == SYM_CURSOR); + + node->op_type = static_cast<open_node_op>(type); + node->cursor_def = cursor_decl->cursor_def; + + return(node); +} + +/*********************************************************************//** +Parses a row_printf-statement. +@return row_printf-statement node */ +row_printf_node_t* +pars_row_printf_statement( +/*======================*/ + sel_node_t* sel_node) /*!< in: select node */ +{ + row_printf_node_t* node; + + node = static_cast<row_printf_node_t*>( + mem_heap_alloc( + pars_sym_tab_global->heap, sizeof(row_printf_node_t))); + node->common.type = QUE_NODE_ROW_PRINTF; + + node->sel_node = sel_node; + + sel_node->common.parent = node; + + return(node); +} + +/*********************************************************************//** +Parses a commit statement. +@return own: commit node struct */ +commit_node_t* +pars_commit_statement(void) +/*=======================*/ +{ + return(trx_commit_node_create(pars_sym_tab_global->heap)); +} + +/*********************************************************************//** +Parses a rollback statement. +@return own: rollback node struct */ +roll_node_t* +pars_rollback_statement(void) +/*=========================*/ +{ + return(roll_node_create(pars_sym_tab_global->heap)); +} + +/*********************************************************************//** +Parses a column definition at a table creation. +@return column sym table node */ +sym_node_t* +pars_column_def( +/*============*/ + sym_node_t* sym_node, /*!< in: column node in the + symbol table */ + pars_res_word_t* type, /*!< in: data type */ + sym_node_t* len, /*!< in: length of column, or + NULL */ + void* is_not_null) /*!< in: if not NULL, column + is of type NOT NULL. */ +{ + ulint len2; + + if (len) { + len2 = ulint(eval_node_get_int_val(len)); + } else { + len2 = 0; + } + + pars_set_dfield_type(que_node_get_val(sym_node), type, len2, + is_not_null != NULL); + + return(sym_node); +} + +/*********************************************************************//** +Parses a table creation operation. +@return table create subgraph */ +tab_node_t* +pars_create_table( +/*==============*/ + sym_node_t* table_sym, /*!< in: table name node in the symbol + table */ + sym_node_t* column_defs) /*!< in: list of column names */ +{ + dict_table_t* table; + sym_node_t* column; + tab_node_t* node; + const dtype_t* dtype; + ulint n_cols; + ulint flags = 0; + ulint flags2 = DICT_TF2_FTS_AUX_HEX_NAME; + + DBUG_EXECUTE_IF("innodb_test_wrong_fts_aux_table_name", + flags2 &= ~DICT_TF2_FTS_AUX_HEX_NAME;); + + n_cols = que_node_list_get_len(column_defs); + + table = dict_table_t::create( + {table_sym->name, strlen(table_sym->name)}, + nullptr, n_cols, 0, flags, flags2); + + mem_heap_t* heap = pars_sym_tab_global->heap; + column = column_defs; + + while (column) { + dtype = dfield_get_type(que_node_get_val(column)); + + dict_mem_table_add_col(table, heap, + column->name, dtype->mtype, + dtype->prtype, dtype->len); + column->resolved = TRUE; + column->token_type = SYM_COLUMN; + + column = static_cast<sym_node_t*>(que_node_get_next(column)); + } + + dict_table_add_system_columns(table, heap); + node = tab_create_graph_create(table, heap); + + table_sym->resolved = TRUE; + table_sym->token_type = SYM_TABLE; + + return(node); +} + +/*********************************************************************//** +Parses an index creation operation. +@return index create subgraph */ +ind_node_t* +pars_create_index( +/*==============*/ + pars_res_word_t* unique_def, /*!< in: not NULL if a unique index */ + pars_res_word_t* clustered_def, /*!< in: not NULL if a clustered index */ + sym_node_t* index_sym, /*!< in: index name node in the symbol + table */ + sym_node_t* table_sym, /*!< in: table name node in the symbol + table */ + sym_node_t* column_list) /*!< in: list of column names */ +{ + dict_index_t* index; + sym_node_t* column; + ind_node_t* node; + ulint n_fields; + ulint ind_type; + + n_fields = que_node_list_get_len(column_list); + + ind_type = 0; + + if (unique_def) { + ind_type = ind_type | DICT_UNIQUE; + } + + if (clustered_def) { + ind_type = ind_type | DICT_CLUSTERED; + } + + index = dict_mem_index_create(NULL, index_sym->name, + ind_type, n_fields); + column = column_list; + + while (column) { + dict_mem_index_add_field(index, column->name, 0); + + column->resolved = TRUE; + column->token_type = SYM_COLUMN; + + column = static_cast<sym_node_t*>(que_node_get_next(column)); + } + + node = ind_create_graph_create(index, table_sym->name, + pars_sym_tab_global->heap, + FIL_ENCRYPTION_DEFAULT, + FIL_DEFAULT_ENCRYPTION_KEY); + + table_sym->resolved = TRUE; + table_sym->token_type = SYM_TABLE; + + index_sym->resolved = TRUE; + index_sym->token_type = SYM_TABLE; + + return(node); +} + +/*********************************************************************//** +Parses a procedure definition. +@return query fork node */ +que_fork_t* +pars_procedure_definition( +/*======================*/ + sym_node_t* sym_node, /*!< in: procedure id node in the symbol + table */ + que_node_t* stat_list) /*!< in: statement list */ +{ + proc_node_t* node; + que_fork_t* fork; + que_thr_t* thr; + mem_heap_t* heap; + + heap = pars_sym_tab_global->heap; + + fork = que_fork_create(heap); + fork->trx = NULL; + + thr = que_thr_create(fork, heap, NULL); + + node = static_cast<proc_node_t*>( + mem_heap_alloc(heap, sizeof(proc_node_t))); + + node->common.type = QUE_NODE_PROC; + node->common.parent = thr; + + sym_node->token_type = SYM_PROCEDURE_NAME; + sym_node->resolved = TRUE; + + node->proc_id = sym_node; + node->stat_list = stat_list; + + pars_set_parent_in_list(stat_list, node); + + node->sym_tab = pars_sym_tab_global; + + thr->child = node; + + pars_sym_tab_global->query_graph = fork; + + return(fork); +} + +/*************************************************************//** +Retrieves characters to the lexical analyzer. */ +int +pars_get_lex_chars( +/*===============*/ + char* buf, /*!< in/out: buffer where to copy */ + size_t max_size) /*!< in: maximum number of characters which fit + in the buffer */ +{ + size_t len = pars_sym_tab_global->string_len + - pars_sym_tab_global->next_char_pos; + if (len == 0) { + return(0); + } + + if (len > max_size) { + len = max_size; + } + + memcpy(buf, pars_sym_tab_global->sql_string + + pars_sym_tab_global->next_char_pos, len); + + pars_sym_tab_global->next_char_pos += len; + + return static_cast<int>(len); +} + +/*************************************************************//** +Called by yyparse on error. */ +void +yyerror( +/*====*/ + const char* s MY_ATTRIBUTE((unused))) + /*!< in: error message string */ +{ + ut_ad(s); + + ib::fatal() << "PARSER: Syntax error in SQL string"; +} + +/*************************************************************//** +Parses an SQL string returning the query graph. +@return own: the query graph */ +que_t* +pars_sql( +/*=====*/ + pars_info_t* info, /*!< in: extra information, or NULL */ + const char* str) /*!< in: SQL string */ +{ + sym_node_t* sym_node; + mem_heap_t* heap; + que_t* graph; + + ut_ad(str); + + heap = mem_heap_create(16000); + + /* Currently, the parser is not reentrant: */ + ut_ad(dict_sys.locked()); + + pars_sym_tab_global = sym_tab_create(heap); + + pars_sym_tab_global->string_len = strlen(str); + pars_sym_tab_global->sql_string = static_cast<char*>( + mem_heap_dup(heap, str, pars_sym_tab_global->string_len + 1)); + pars_sym_tab_global->next_char_pos = 0; + pars_sym_tab_global->info = info; + + yyparse(); + + sym_node = UT_LIST_GET_FIRST(pars_sym_tab_global->sym_list); + + while (sym_node) { + ut_a(sym_node->resolved); + + sym_node = UT_LIST_GET_NEXT(sym_list, sym_node); + } + + graph = pars_sym_tab_global->query_graph; + + graph->sym_tab = pars_sym_tab_global; + graph->info = info; + + pars_sym_tab_global = NULL; + + /* fprintf(stderr, "SQL graph size %lu\n", mem_heap_get_size(heap)); */ + + return(graph); +} + +/** Completes a query graph by adding query thread and fork nodes +above it and prepares the graph for running. +@param[in] node root node for an incomplete query + graph, or NULL for dummy graph +@param[in] trx transaction handle +@param[in] heap memory heap from which allocated +@param[in] prebuilt row prebuilt structure +@return query thread node to run */ +que_thr_t* +pars_complete_graph_for_exec( + que_node_t* node, + trx_t* trx, + mem_heap_t* heap, + row_prebuilt_t* prebuilt) +{ + que_fork_t* fork; + que_thr_t* thr; + + fork = que_fork_create(heap); + fork->trx = trx; + + thr = que_thr_create(fork, heap, prebuilt); + + thr->child = node; + + if (node) { + que_node_set_parent(node, thr); + } + + trx->graph = NULL; + + return(thr); +} + +/****************************************************************//** +Create parser info struct. +@return own: info struct */ +pars_info_t* +pars_info_create(void) +/*==================*/ +{ + pars_info_t* info; + mem_heap_t* heap; + + heap = mem_heap_create(512); + + info = static_cast<pars_info_t*>(mem_heap_zalloc(heap, sizeof(*info))); + + info->heap = heap; + + return(info); +} + +/****************************************************************//** +Add bound literal. */ +void +pars_info_add_literal( +/*==================*/ + pars_info_t* info, /*!< in: info struct */ + const char* name, /*!< in: name */ + const void* address, /*!< in: address */ + ulint length, /*!< in: length of data */ + ulint type, /*!< in: type, e.g. DATA_FIXBINARY */ + ulint prtype) /*!< in: precise type, e.g. + DATA_UNSIGNED */ +{ + pars_bound_lit_t* pbl; + + ut_ad(!pars_info_get_bound_lit(info, name)); + + pbl = static_cast<pars_bound_lit_t*>( + mem_heap_alloc(info->heap, sizeof(*pbl))); + + pbl->name = name; + + pbl->address = address; + pbl->length = length; + pbl->type = type; + pbl->prtype = prtype; + + if (!info->bound_lits) { + ib_alloc_t* heap_alloc; + + heap_alloc = ib_heap_allocator_create(info->heap); + + info->bound_lits = ib_vector_create(heap_alloc, sizeof(*pbl), 8); + } + + ib_vector_push(info->bound_lits, pbl); +} + +/****************************************************************//** +Equivalent to pars_info_add_literal(info, name, str, strlen(str), +DATA_VARCHAR, DATA_ENGLISH). */ +void +pars_info_add_str_literal( +/*======================*/ + pars_info_t* info, /*!< in: info struct */ + const char* name, /*!< in: name */ + const char* str) /*!< in: string */ +{ + pars_info_add_literal(info, name, str, strlen(str), + DATA_VARCHAR, DATA_ENGLISH); +} + +/******************************************************************** +If the literal value already exists then it rebinds otherwise it +creates a new entry.*/ +void +pars_info_bind_literal( +/*===================*/ + pars_info_t* info, /* in: info struct */ + const char* name, /* in: name */ + const void* address, /* in: address */ + ulint length, /* in: length of data */ + ulint type, /* in: type, e.g. DATA_FIXBINARY */ + ulint prtype) /* in: precise type, e.g. */ +{ + pars_bound_lit_t* pbl; + + pbl = pars_info_lookup_bound_lit(info, name); + + if (!pbl) { + pars_info_add_literal( + info, name, address, length, type, prtype); + } else { + pbl->address = address; + pbl->length = length; + + sym_tab_rebind_lit(pbl->node, address, length); + } +} + +/******************************************************************** +If the literal value already exists then it rebinds otherwise it +creates a new entry.*/ +void +pars_info_bind_varchar_literal( +/*===========================*/ + pars_info_t* info, /*!< in: info struct */ + const char* name, /*!< in: name */ + const byte* str, /*!< in: string */ + ulint str_len) /*!< in: string length */ +{ + pars_bound_lit_t* pbl; + + pbl = pars_info_lookup_bound_lit(info, name); + + if (!pbl) { + pars_info_add_literal( + info, name, str, str_len, DATA_VARCHAR, DATA_ENGLISH); + } else { + + pbl->address = str; + pbl->length = str_len; + + sym_tab_rebind_lit(pbl->node, str, str_len); + } +} + +/****************************************************************//** +Equivalent to: + +char buf[4]; +mach_write_to_4(buf, val); +pars_info_add_literal(info, name, buf, 4, DATA_INT, 0); + +except that the buffer is dynamically allocated from the info struct's +heap. */ +void +pars_info_add_int4_literal( +/*=======================*/ + pars_info_t* info, /*!< in: info struct */ + const char* name, /*!< in: name */ + ulint val) /*!< in: value */ +{ + byte* buf = static_cast<byte*>(mem_heap_alloc(info->heap, 4)); + + mach_write_to_4(buf, val); + pars_info_add_literal(info, name, buf, 4, DATA_INT, 0); +} + +/******************************************************************** +If the literal value already exists then it rebinds otherwise it +creates a new entry. */ +void +pars_info_bind_int4_literal( +/*========================*/ + pars_info_t* info, /* in: info struct */ + const char* name, /* in: name */ + const ib_uint32_t* val) /* in: value */ +{ + pars_bound_lit_t* pbl; + + pbl = pars_info_lookup_bound_lit(info, name); + + if (!pbl) { + pars_info_add_literal(info, name, val, 4, DATA_INT, 0); + } else { + + pbl->address = val; + pbl->length = sizeof(*val); + + sym_tab_rebind_lit(pbl->node, val, sizeof(*val)); + } +} + +/******************************************************************** +If the literal value already exists then it rebinds otherwise it +creates a new entry. */ +void +pars_info_bind_int8_literal( +/*========================*/ + pars_info_t* info, /* in: info struct */ + const char* name, /* in: name */ + const ib_uint64_t* val) /* in: value */ +{ + pars_bound_lit_t* pbl; + + pbl = pars_info_lookup_bound_lit(info, name); + + if (!pbl) { + pars_info_add_literal( + info, name, val, sizeof(*val), DATA_INT, 0); + } else { + + pbl->address = val; + pbl->length = sizeof(*val); + + sym_tab_rebind_lit(pbl->node, val, sizeof(*val)); + } +} + +/****************************************************************//** +Equivalent to: + +char buf[8]; +mach_write_to_8(buf, val); +pars_info_add_literal(info, name, buf, 8, DATA_FIXBINARY, 0); + +except that the buffer is dynamically allocated from the info struct's +heap. */ +void +pars_info_add_ull_literal( +/*======================*/ + pars_info_t* info, /*!< in: info struct */ + const char* name, /*!< in: name */ + ib_uint64_t val) /*!< in: value */ +{ + byte* buf = static_cast<byte*>(mem_heap_alloc(info->heap, 8)); + + mach_write_to_8(buf, val); + + pars_info_add_literal(info, name, buf, 8, DATA_FIXBINARY, 0); +} + +/****************************************************************//** +If the literal value already exists then it rebinds otherwise it +creates a new entry. */ +void +pars_info_bind_ull_literal( +/*=======================*/ + pars_info_t* info, /*!< in: info struct */ + const char* name, /*!< in: name */ + const ib_uint64_t* val) /*!< in: value */ +{ + pars_bound_lit_t* pbl; + + pbl = pars_info_lookup_bound_lit(info, name); + + if (!pbl) { + pars_info_add_literal( + info, name, val, sizeof(*val), DATA_FIXBINARY, 0); + } else { + + pbl->address = val; + pbl->length = sizeof(*val); + + sym_tab_rebind_lit(pbl->node, val, sizeof(*val)); + } +} + +/****************************************************************//** +Add user function. */ +void +pars_info_bind_function( +/*====================*/ + pars_info_t* info, /*!< in: info struct */ + const char* name, /*!< in: function name */ + pars_user_func_cb_t func, /*!< in: function address */ + void* arg) /*!< in: user-supplied argument */ +{ + pars_user_func_t* puf; + + puf = pars_info_lookup_user_func(info, name); + + if (!puf) { + if (!info->funcs) { + ib_alloc_t* heap_alloc; + + heap_alloc = ib_heap_allocator_create(info->heap); + + info->funcs = ib_vector_create( + heap_alloc, sizeof(*puf), 8); + } + + /* Create a "new" element */ + puf = static_cast<pars_user_func_t*>( + ib_vector_push(info->funcs, NULL)); + puf->name = name; + } + + puf->arg = arg; + puf->func = func; +} + +/******************************************************************** +Add bound id. */ +void +pars_info_bind_id( +/*==============*/ + pars_info_t* info, /*!< in: info struct */ + const char* name, /*!< in: name */ + const char* id) /*!< in: id */ +{ + pars_bound_id_t* bid; + + bid = pars_info_lookup_bound_id(info, name); + + if (!bid) { + + if (!info->bound_ids) { + ib_alloc_t* heap_alloc; + + heap_alloc = ib_heap_allocator_create(info->heap); + + info->bound_ids = ib_vector_create( + heap_alloc, sizeof(*bid), 8); + } + + /* Create a "new" element */ + bid = static_cast<pars_bound_id_t*>( + ib_vector_push(info->bound_ids, NULL)); + + bid->name = name; + } + + bid->id = id; +} + +/******************************************************************** +Get bound identifier with the given name.*/ +pars_bound_id_t* +pars_info_get_bound_id( +/*===================*/ + /* out: bound id, or NULL if not + found */ + pars_info_t* info, /* in: info struct */ + const char* name) /* in: bound id name to find */ +{ + return(pars_info_lookup_bound_id(info, name)); +} + +/****************************************************************//** +Get bound literal with the given name. +@return bound literal, or NULL if not found */ +pars_bound_lit_t* +pars_info_get_bound_lit( +/*====================*/ + pars_info_t* info, /*!< in: info struct */ + const char* name) /*!< in: bound literal name to find */ +{ + return(pars_info_lookup_bound_lit(info, name)); +} diff --git a/storage/innobase/pars/pars0sym.cc b/storage/innobase/pars/pars0sym.cc new file mode 100644 index 00000000..03541584 --- /dev/null +++ b/storage/innobase/pars/pars0sym.cc @@ -0,0 +1,413 @@ +/***************************************************************************** + +Copyright (c) 1997, 2016, Oracle and/or its affiliates. All Rights Reserved. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + +*****************************************************************************/ + +/**************************************************//** +@file pars/pars0sym.cc +SQL parser symbol table + +Created 12/15/1997 Heikki Tuuri +*******************************************************/ + +#include "pars0sym.h" +#include "mem0mem.h" +#include "data0type.h" +#include "data0data.h" +#include "pars0grm.h" +#include "pars0pars.h" +#include "que0que.h" +#include "eval0eval.h" +#include "row0sel.h" + +/******************************************************************//** +Creates a symbol table for a single stored procedure or query. +@return own: symbol table */ +sym_tab_t* +sym_tab_create( +/*===========*/ + mem_heap_t* heap) /*!< in: memory heap where to create */ +{ + sym_tab_t* sym_tab; + + sym_tab = static_cast<sym_tab_t*>( + mem_heap_alloc(heap, sizeof(sym_tab_t))); + + UT_LIST_INIT(sym_tab->sym_list, &sym_node_t::sym_list); + UT_LIST_INIT(sym_tab->func_node_list, &func_node_t::func_node_list); + + sym_tab->heap = heap; + + return(sym_tab); +} + + +/******************************************************************//** +Frees the memory allocated dynamically AFTER parsing phase for variables +etc. in the symbol table. Does not free the mem heap where the table was +originally created. Frees also SQL explicit cursor definitions. */ +void +sym_tab_free_private( +/*=================*/ + sym_tab_t* sym_tab) /*!< in, own: symbol table */ +{ + sym_node_t* sym; + func_node_t* func; + + for (sym = UT_LIST_GET_FIRST(sym_tab->sym_list); + sym != NULL; + sym = UT_LIST_GET_NEXT(sym_list, sym)) { + + /* Close the tables opened in pars_retrieve_table_def(). */ + + if (sym->token_type == SYM_TABLE_REF_COUNTED) { + sym->table->release(); + + sym->table = NULL; + sym->resolved = FALSE; + sym->token_type = SYM_UNSET; + } + + eval_node_free_val_buf(sym); + + if (sym->prefetch_buf) { + sel_col_prefetch_buf_free(sym->prefetch_buf); + } + + if (sym->cursor_def) { + que_graph_free_recursive(sym->cursor_def); + } + } + + for (func = UT_LIST_GET_FIRST(sym_tab->func_node_list); + func != NULL; + func = UT_LIST_GET_NEXT(func_node_list, func)) { + + eval_node_free_val_buf(func); + } +} + +/******************************************************************//** +Adds an integer literal to a symbol table. +@return symbol table node */ +sym_node_t* +sym_tab_add_int_lit( +/*================*/ + sym_tab_t* sym_tab, /*!< in: symbol table */ + ulint val) /*!< in: integer value */ +{ + sym_node_t* node; + byte* data; + + node = static_cast<sym_node_t*>( + mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t))); + + node->common.type = QUE_NODE_SYMBOL; + + node->table = NULL; + node->resolved = TRUE; + node->token_type = SYM_LIT; + + node->indirection = NULL; + + dtype_set(dfield_get_type(&node->common.val), DATA_INT, 0, 4); + + data = static_cast<byte*>(mem_heap_alloc(sym_tab->heap, 4)); + mach_write_to_4(data, val); + + dfield_set_data(&(node->common.val), data, 4); + + node->common.val_buf_size = 0; + node->prefetch_buf = NULL; + node->cursor_def = NULL; + + UT_LIST_ADD_LAST(sym_tab->sym_list, node); + + node->like_node = NULL; + + node->sym_table = sym_tab; + + return(node); +} + +/******************************************************************//** +Adds a string literal to a symbol table. +@return symbol table node */ +sym_node_t* +sym_tab_add_str_lit( +/*================*/ + sym_tab_t* sym_tab, /*!< in: symbol table */ + const byte* str, /*!< in: string with no quotes around + it */ + ulint len) /*!< in: string length */ +{ + sym_node_t* node; + byte* data; + + node = static_cast<sym_node_t*>( + mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t))); + + node->common.type = QUE_NODE_SYMBOL; + + node->table = NULL; + node->resolved = TRUE; + node->token_type = SYM_LIT; + + node->indirection = NULL; + + dtype_set(dfield_get_type(&node->common.val), + DATA_VARCHAR, DATA_ENGLISH, 0); + + data = (len) ? static_cast<byte*>(mem_heap_dup(sym_tab->heap, str, len)) + : NULL; + + dfield_set_data(&(node->common.val), data, len); + + node->common.val_buf_size = 0; + node->prefetch_buf = NULL; + node->cursor_def = NULL; + + UT_LIST_ADD_LAST(sym_tab->sym_list, node); + + node->like_node = NULL; + + node->sym_table = sym_tab; + + return(node); +} + +/******************************************************************//** +Add a bound literal to a symbol table. +@return symbol table node */ +sym_node_t* +sym_tab_add_bound_lit( +/*==================*/ + sym_tab_t* sym_tab, /*!< in: symbol table */ + const char* name, /*!< in: name of bound literal */ + ulint* lit_type) /*!< out: type of literal (PARS_*_LIT) */ +{ + sym_node_t* node; + pars_bound_lit_t* blit; + ulint len = 0; + + blit = pars_info_get_bound_lit(sym_tab->info, name); + ut_a(blit); + + node = static_cast<sym_node_t*>( + mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t))); + + node->common.type = QUE_NODE_SYMBOL; + node->common.brother = node->common.parent = NULL; + + node->table = NULL; + node->resolved = TRUE; + node->token_type = SYM_LIT; + + node->indirection = NULL; + + switch (blit->type) { + case DATA_FIXBINARY: + case DATA_CHAR: + ut_ad(blit->length > 0); + len = blit->length; + /* fall through */ + case DATA_BLOB: + case DATA_VARCHAR: + *lit_type = PARS_STR_LIT; + break; + + case DATA_INT: + ut_a(blit->length > 0); + ut_a(blit->length <= 8); + + len = blit->length; + *lit_type = PARS_INT_LIT; + break; + + default: + ut_error; + } + + dtype_set(dfield_get_type(&node->common.val), + blit->type, blit->prtype, len); + + dfield_set_data(&(node->common.val), blit->address, blit->length); + + node->common.val_buf_size = 0; + node->prefetch_buf = NULL; + node->cursor_def = NULL; + + UT_LIST_ADD_LAST(sym_tab->sym_list, node); + + blit->node = node; + node->like_node = NULL; + node->sym_table = sym_tab; + + return(node); +} + +/********************************************************************** +Rebind literal to a node in the symbol table. */ +sym_node_t* +sym_tab_rebind_lit( +/*===============*/ + /* out: symbol table node */ + sym_node_t* node, /* in: node that is bound to literal*/ + const void* address, /* in: pointer to data */ + ulint length) /* in: length of data */ +{ + dfield_t* dfield = que_node_get_val(node); + dtype_t* dtype = dfield_get_type(dfield); + + ut_a(node->token_type == SYM_LIT); + + dfield_set_data(&node->common.val, address, length); + + if (node->like_node) { + + ut_a(dtype_get_mtype(dtype) == DATA_CHAR + || dtype_get_mtype(dtype) == DATA_VARCHAR); + + /* Don't force [FALSE] creation of sub-nodes (for LIKE) */ + pars_like_rebind( + node,static_cast<const byte*>(address), length); + } + + /* FIXME: What's this ? */ + node->common.val_buf_size = 0; + + if (node->prefetch_buf) { + sel_col_prefetch_buf_free(node->prefetch_buf); + node->prefetch_buf = NULL; + } + + if (node->cursor_def) { + que_graph_free_recursive(node->cursor_def); + node->cursor_def = NULL; + } + + return(node); +} + +/******************************************************************//** +Adds an SQL null literal to a symbol table. +@return symbol table node */ +sym_node_t* +sym_tab_add_null_lit( +/*=================*/ + sym_tab_t* sym_tab) /*!< in: symbol table */ +{ + sym_node_t* node; + + node = static_cast<sym_node_t*>( + mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t))); + + node->common.type = QUE_NODE_SYMBOL; + + node->table = NULL; + node->resolved = TRUE; + node->token_type = SYM_LIT; + + node->indirection = NULL; + + dfield_get_type(&node->common.val)->mtype = DATA_ERROR; + + dfield_set_null(&node->common.val); + + node->common.val_buf_size = 0; + node->prefetch_buf = NULL; + node->cursor_def = NULL; + + UT_LIST_ADD_LAST(sym_tab->sym_list, node); + + node->like_node = NULL; + + node->sym_table = sym_tab; + + return(node); +} + +/******************************************************************//** +Adds an identifier to a symbol table. +@return symbol table node */ +sym_node_t* +sym_tab_add_id( +/*===========*/ + sym_tab_t* sym_tab, /*!< in: symbol table */ + byte* name, /*!< in: identifier name */ + ulint len) /*!< in: identifier length */ +{ + sym_node_t* node; + + node = static_cast<sym_node_t*>( + mem_heap_zalloc(sym_tab->heap, sizeof(*node))); + + node->common.type = QUE_NODE_SYMBOL; + + node->name = mem_heap_strdupl(sym_tab->heap, (char*) name, len); + node->name_len = len; + + UT_LIST_ADD_LAST(sym_tab->sym_list, node); + + dfield_set_null(&node->common.val); + + node->sym_table = sym_tab; + + return(node); +} + +/******************************************************************//** +Add a bound identifier to a symbol table. +@return symbol table node */ +sym_node_t* +sym_tab_add_bound_id( +/*=================*/ + sym_tab_t* sym_tab, /*!< in: symbol table */ + const char* name) /*!< in: name of bound id */ +{ + sym_node_t* node; + pars_bound_id_t* bid; + + bid = pars_info_get_bound_id(sym_tab->info, name); + ut_a(bid); + + node = static_cast<sym_node_t*>( + mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t))); + + node->common.type = QUE_NODE_SYMBOL; + + node->table = NULL; + node->resolved = FALSE; + node->token_type = SYM_UNSET; + node->indirection = NULL; + + node->name = mem_heap_strdup(sym_tab->heap, bid->id); + node->name_len = strlen(node->name); + + UT_LIST_ADD_LAST(sym_tab->sym_list, node); + + dfield_set_null(&node->common.val); + + node->common.val_buf_size = 0; + node->prefetch_buf = NULL; + node->cursor_def = NULL; + + node->like_node = NULL; + + node->sym_table = sym_tab; + + return(node); +} |