From 589a251ed7ca69f5dea5c147a3ae8d964758c082 Mon Sep 17 00:00:00 2001 From: Pedro Date: Sat, 11 Mar 2017 13:47:35 +0100 Subject: [PATCH 1/4] add copy header files to install rule --- Makefile | 3 +++ README.md | 4 ++-- test/test.sh | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3ab260f..bab6e21 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,9 @@ cleanall: clean cleanparser install: cp $(TARGET) $(INSTALL)/lib/$(TARGET) + cp -r src $(INSTALL)/include/hsql + find $(INSTALL)/include/hsql -not -name '*.h' -type f | xargs rm + format: astyle --options=astyle.options $(ALLLIB) diff --git a/README.md b/README.md index 5f8ea54..8056e5e 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ To use the SQL parser in your own projects you simply have to follow these few s First step to extending this parser is cloning the repository `git clone git@github.com:hyrise/sql-parser.git` and making sure everything works by running the following steps: -``` +```bash make parser # builds the bison parser and flex lexer make library # builds the libsqlparser.so make test # runs the tests with the library @@ -44,7 +44,7 @@ make test # runs the tests with the library Rerun these steps whenever you change part of the parse. To execute the entire pipeline automatically you can run: -``` +```bash make cleanall # cleans the parser build and library build make test # build parser, library and runs the tests ``` diff --git a/test/test.sh b/test/test.sh index 73b3262..b9d2dc1 100755 --- a/test/test.sh +++ b/test/test.sh @@ -32,6 +32,7 @@ fi printf "\n${GREEN}Running memory leak checks...${NC}\n" valgrind --leak-check=full --error-exitcode=200 --log-fd=3 \ ./bin/sql_tests -f "test/valid_queries.sql" 3>&1 >/dev/null 2>/dev/null +MEM_LEAK_RET=$? if [ $MEM_LEAK_RET -ne 200 ]; then printf "${GREEN}Memory leak check succeeded!${NC}\n" From 745f4dd816aeea5a2a2ba5f8dbf8f80df3a46bdf Mon Sep 17 00:00:00 2001 From: Nan Xiao Date: Wed, 5 Apr 2017 17:56:17 +0800 Subject: [PATCH 2/4] Check NULL value of result. --- example/example.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/example/example.cpp b/example/example.cpp index 62a5077..2b67c90 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -19,6 +19,10 @@ int main(int argc, char *argv[]) { hsql::SQLParserResult* result = hsql::SQLParser::parseSQLString(query); // check whether the parsing was successful + if (!result) { + return -1; + } + if (result->isValid()) { printf("Parsed successfully!\n"); printf("Number of statements: %lu\n", result->size()); From ccf791eee2f939fcf06922b1440edb092833be96 Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Thu, 6 Apr 2017 17:02:40 +0200 Subject: [PATCH 3/4] change make dependendencies for parser so parser rebuild is not invoked on make: Nothing to be done for 'library'. --- Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index bab6e21..8504f8c 100644 --- a/Makefile +++ b/Makefile @@ -27,15 +27,17 @@ library: $(TARGET) $(TARGET): $(LIBOBJ) $(CXX) $(LIBFLAGS) -o $(TARGET) $(LIBOBJ) - %.o: %.cpp $(PARSERFILES) $(CXX) $(CFLAGS) -c -o $@ $< -$(SRCPARSER)/bison_parser.cpp: parser -$(SRCPARSER)/flex_lexer.cpp: parser +$(SRCPARSER)/bison_parser.cpp: + make -C $(SRCPARSER)/ bison_parser.cpp + +$(SRCPARSER)/flex_lexer.cpp: + make -C $(SRCPARSER)/ flex_lexer.cpp parser: - make -C $(SRCPARSER)/ + make -C $(SRCPARSER) all clean: rm -f $(TARGET) @@ -52,7 +54,6 @@ install: cp -r src $(INSTALL)/include/hsql find $(INSTALL)/include/hsql -not -name '*.h' -type f | xargs rm - format: astyle --options=astyle.options $(ALLLIB) astyle --options=astyle.options $(ALLTEST) From 4d1278cb1ff48f446f57a90cf5941e1fe2f8984f Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Thu, 6 Apr 2017 17:02:54 +0200 Subject: [PATCH 4/4] update lexer --- src/parser/flex_lexer.cpp | 244 ++++++++++++++++++++------------------ src/parser/flex_lexer.h | 46 +++---- 2 files changed, 149 insertions(+), 141 deletions(-) diff --git a/src/parser/flex_lexer.cpp b/src/parser/flex_lexer.cpp index 0da323a..cf6073b 100644 --- a/src/parser/flex_lexer.cpp +++ b/src/parser/flex_lexer.cpp @@ -8,8 +8,8 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 1 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -88,25 +88,13 @@ typedef unsigned int flex_uint32_t; #endif /* ! FLEXINT_H */ -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST +/* TODO: this is always defined, so inline it */ #define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) #else -#define yyconst +#define yynoreturn #endif /* Returned upon end-of-file. */ @@ -179,11 +167,17 @@ typedef void* yyscan_t; 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) \ @@ -201,11 +195,6 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state @@ -218,7 +207,7 @@ struct yy_buffer_state /* Size of input buffer in bytes, not including room for EOB * characters. */ - yy_size_t yy_buf_size; + int yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. @@ -246,7 +235,7 @@ struct yy_buffer_state 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. */ @@ -334,7 +323,7 @@ void hsql_free (void * ,yyscan_t yyscanner ); /* Begin user sect3 */ -#define hsql_wrap(n) 1 +#define hsql_wrap(yyscanner) (/*CONSTCOND*/1) #define YY_SKIP_YYWRAP typedef unsigned char YY_CHAR; @@ -346,14 +335,14 @@ typedef int yy_state_type; static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); static int yy_get_next_buffer (yyscan_t yyscanner ); -static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); +static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ yyg->yytext_ptr = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ + yyleng = (int) (yy_cp - yy_bp); \ yyg->yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ yyg->yy_c_buf_p = yy_cp; @@ -472,7 +461,7 @@ static yyconst flex_int16_t yy_accept[914] = 2, 2, 0 } ; -static yyconst flex_int32_t yy_ec[256] = +static yyconst 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, @@ -504,7 +493,7 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[66] = +static yyconst YY_CHAR yy_meta[66] = { 0, 1, 1, 2, 3, 1, 1, 1, 1, 4, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, @@ -515,7 +504,7 @@ static yyconst flex_int32_t yy_meta[66] = 4, 4, 4, 4, 4 } ; -static yyconst flex_int16_t yy_base[921] = +static yyconst flex_uint16_t yy_base[921] = { 0, 0, 0, 65, 0, 349, 3639, 129, 131, 0, 3639, 338, 332, 310, 127, 126, 305, 123, 123, 131, 177, @@ -725,7 +714,7 @@ static yyconst flex_int16_t yy_def[921] = 52, 52, 0, 913, 913, 913, 913, 913, 913, 913 } ; -static yyconst flex_int16_t yy_nxt[3705] = +static yyconst flex_uint16_t yy_nxt[3705] = { 0, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 16, 17, 18, 19, 20, 21, 22, 23, 24, @@ -1585,7 +1574,7 @@ static yyconst flex_int16_t yy_chk[3705] = /*************************** ** Section 3: Rules ***************************/ -#line 1589 "flex_lexer.cpp" +#line 1578 "flex_lexer.cpp" #define INITIAL 0 #define COMMENT 1 @@ -1667,19 +1656,23 @@ void hsql_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); FILE *hsql_get_in (yyscan_t yyscanner ); -void hsql_set_in (FILE * in_str ,yyscan_t yyscanner ); +void hsql_set_in (FILE * _in_str ,yyscan_t yyscanner ); FILE *hsql_get_out (yyscan_t yyscanner ); -void hsql_set_out (FILE * out_str ,yyscan_t yyscanner ); +void hsql_set_out (FILE * _out_str ,yyscan_t yyscanner ); -int hsql_get_leng (yyscan_t yyscanner ); + int hsql_get_leng (yyscan_t yyscanner ); char *hsql_get_text (yyscan_t yyscanner ); int hsql_get_lineno (yyscan_t yyscanner ); -void hsql_set_lineno (int line_number ,yyscan_t yyscanner ); +void hsql_set_lineno (int _line_number ,yyscan_t yyscanner ); + +int hsql_get_column (yyscan_t yyscanner ); + +void hsql_set_column (int _column_no ,yyscan_t yyscanner ); YYSTYPE * hsql_get_lval (yyscan_t yyscanner ); @@ -1701,6 +1694,10 @@ extern int hsql_wrap (yyscan_t yyscanner ); #endif #endif +#ifndef YY_NO_UNPUT + +#endif + #ifndef yytext_ptr static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); #endif @@ -1734,7 +1731,7 @@ static int input (yyscan_t yyscanner ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#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, @@ -1758,7 +1755,7 @@ static int input (yyscan_t yyscanner ); else \ { \ errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ { \ if( errno != EINTR) \ { \ @@ -1815,7 +1812,7 @@ extern int hsql_lex \ /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK break; +#define YY_BREAK /*LINTED*/break; #endif #define YY_RULE_SETUP \ @@ -1825,16 +1822,11 @@ extern int hsql_lex \ */ YY_DECL { - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; -#line 51 "flex_lexer.l" - - -#line 1837 "flex_lexer.cpp" - yylval = yylval_param; yylloc = yylloc_param; @@ -1865,7 +1857,13 @@ YY_DECL hsql__load_buffer_state(yyscanner ); } - while ( 1 ) /* loops until end-of-file is reached */ + { +#line 51 "flex_lexer.l" + + +#line 1865 "flex_lexer.cpp" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { yy_cp = yyg->yy_c_buf_p; @@ -1881,7 +1879,7 @@ YY_DECL yy_match: do { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; if ( yy_accept[yy_current_state] ) { yyg->yy_last_accepting_state = yy_current_state; @@ -1893,7 +1891,7 @@ yy_match: if ( yy_current_state >= 914 ) yy_c = yy_meta[(unsigned int) yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; ++yy_cp; } while ( yy_current_state != 913 ); @@ -2592,7 +2590,7 @@ YY_RULE_SETUP #line 213 "flex_lexer.l" ECHO; YY_BREAK -#line 2596 "flex_lexer.cpp" +#line 2594 "flex_lexer.cpp" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(COMMENT): yyterminate(); @@ -2725,6 +2723,7 @@ case YY_STATE_EOF(COMMENT): "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ + } /* end of user's declarations */ } /* end of hsql_lex */ /* yy_get_next_buffer - try to read in a new buffer @@ -2737,9 +2736,9 @@ case YY_STATE_EOF(COMMENT): static int yy_get_next_buffer (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = yyg->yytext_ptr; - register int number_to_move, i; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = yyg->yytext_ptr; + yy_size_t number_to_move, i; int ret_val; if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) @@ -2768,7 +2767,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; + number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -2788,7 +2787,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) { /* Not enough room in the buffer - grow it. */ /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; int yy_c_buf_p_offset = (int) (yyg->yy_c_buf_p - b->yy_ch_buf); @@ -2808,7 +2807,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) } else /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; + b->yy_ch_buf = NULL; if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( @@ -2826,7 +2825,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, (size_t) num_to_read ); + yyg->yy_n_chars, num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } @@ -2850,9 +2849,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else ret_val = EOB_ACT_CONTINUE_SCAN; - if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) hsql_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); @@ -2871,15 +2870,15 @@ static int yy_get_next_buffer (yyscan_t yyscanner) static yy_state_type yy_get_previous_state (yyscan_t yyscanner) { - register yy_state_type yy_current_state; - register char *yy_cp; + yy_state_type yy_current_state; + char *yy_cp; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; yy_current_state = yyg->yy_start; for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { yyg->yy_last_accepting_state = yy_current_state; @@ -2891,7 +2890,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) if ( yy_current_state >= 914 ) yy_c = yy_meta[(unsigned int) yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; } return yy_current_state; @@ -2904,11 +2903,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner) */ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) { - register int yy_is_jam; + int yy_is_jam; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ - register char *yy_cp = yyg->yy_c_buf_p; + char *yy_cp = yyg->yy_c_buf_p; - register YY_CHAR yy_c = 1; + YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { yyg->yy_last_accepting_state = yy_current_state; @@ -2920,12 +2919,17 @@ static int yy_get_next_buffer (yyscan_t yyscanner) if ( yy_current_state >= 914 ) yy_c = yy_meta[(unsigned int) yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; yy_is_jam = (yy_current_state == 913); + (void)yyg; return yy_is_jam ? 0 : yy_current_state; } +#ifndef YY_NO_UNPUT + +#endif + #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (yyscan_t yyscanner) @@ -2975,7 +2979,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) case EOB_ACT_END_OF_FILE: { if ( hsql_wrap(yyscanner ) ) - return EOF; + return 0; if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; @@ -3079,7 +3083,7 @@ static void hsql__load_buffer_state (yyscan_t yyscanner) if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in hsql__create_buffer()" ); - b->yy_buf_size = size; + b->yy_buf_size = (yy_size_t)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. @@ -3240,15 +3244,15 @@ static void hsql_ensure_buffer_stack (yyscan_t yyscanner) * 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; + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ yyg->yy_buffer_stack = (struct yy_buffer_state**)hsql_alloc (num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in hsql_ensure_buffer_stack()" ); - + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - + yyg->yy_buffer_stack_max = num_to_alloc; yyg->yy_buffer_stack_top = 0; return; @@ -3257,7 +3261,7 @@ static void hsql_ensure_buffer_stack (yyscan_t yyscanner) if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; + yy_size_t grow_size = 8 /* arbitrary grow size */; num_to_alloc = yyg->yy_buffer_stack_max + grow_size; yyg->yy_buffer_stack = (struct yy_buffer_state**)hsql_realloc @@ -3277,7 +3281,7 @@ static void hsql_ensure_buffer_stack (yyscan_t yyscanner) * @param base the character buffer * @param size the size in bytes of the character buffer * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. + * @return the newly allocated buffer state object. */ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) { @@ -3287,7 +3291,7 @@ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yysc base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ - return 0; + return NULL; b = (YY_BUFFER_STATE) hsql_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); if ( ! b ) @@ -3296,7 +3300,7 @@ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yysc b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; - b->yy_input_file = 0; + b->yy_input_file = NULL; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; @@ -3319,7 +3323,7 @@ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yysc YY_BUFFER_STATE hsql__scan_string (yyconst char * yystr , yyscan_t yyscanner) { - return hsql__scan_bytes(yystr,strlen(yystr) ,yyscanner); + return hsql__scan_bytes(yystr,(int) strlen(yystr) ,yyscanner); } /** Setup the input buffer state to scan the given bytes. The next call to hsql_lex() will @@ -3334,10 +3338,10 @@ YY_BUFFER_STATE hsql__scan_bytes (yyconst char * yybytes, int _yybytes_len , y YY_BUFFER_STATE b; char *buf; yy_size_t n; - int i; + yy_size_t i; /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; + n = (yy_size_t) _yybytes_len + 2; buf = (char *) hsql_alloc(n ,yyscanner ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in hsql__scan_bytes()" ); @@ -3363,9 +3367,11 @@ YY_BUFFER_STATE hsql__scan_bytes (yyconst char * yybytes, int _yybytes_len , y #define YY_EXIT_FAILURE 2 #endif -static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) +static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) { - (void) fprintf( stderr, "%s\n", msg ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } @@ -3403,7 +3409,7 @@ YY_EXTRA_TYPE hsql_get_extra (yyscan_t yyscanner) int hsql_get_lineno (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - + if (! YY_CURRENT_BUFFER) return 0; @@ -3416,7 +3422,7 @@ int hsql_get_lineno (yyscan_t yyscanner) int hsql_get_column (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - + if (! YY_CURRENT_BUFFER) return 0; @@ -3471,51 +3477,51 @@ void hsql_set_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) } /** Set the current line number. - * @param line_number + * @param _line_number line number * @param yyscanner The scanner object. */ -void hsql_set_lineno (int line_number , yyscan_t yyscanner) +void hsql_set_lineno (int _line_number , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* lineno is only valid if an input buffer exists. */ if (! YY_CURRENT_BUFFER ) - yy_fatal_error( "hsql_set_lineno called with no buffer" , yyscanner); + YY_FATAL_ERROR( "hsql_set_lineno called with no buffer" ); - yylineno = line_number; + yylineno = _line_number; } /** Set the current column. - * @param line_number + * @param _column_no column number * @param yyscanner The scanner object. */ -void hsql_set_column (int column_no , yyscan_t yyscanner) +void hsql_set_column (int _column_no , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* column is only valid if an input buffer exists. */ if (! YY_CURRENT_BUFFER ) - yy_fatal_error( "hsql_set_column called with no buffer" , yyscanner); + YY_FATAL_ERROR( "hsql_set_column called with no buffer" ); - yycolumn = column_no; + yycolumn = _column_no; } /** Set the input stream. This does not discard the current * input buffer. - * @param in_str A readable stream. + * @param _in_str A readable stream. * @param yyscanner The scanner object. * @see hsql__switch_to_buffer */ -void hsql_set_in (FILE * in_str , yyscan_t yyscanner) +void hsql_set_in (FILE * _in_str , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyin = in_str ; + yyin = _in_str ; } -void hsql_set_out (FILE * out_str , yyscan_t yyscanner) +void hsql_set_out (FILE * _out_str , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyout = out_str ; + yyout = _out_str ; } int hsql_get_debug (yyscan_t yyscanner) @@ -3524,10 +3530,10 @@ int hsql_get_debug (yyscan_t yyscanner) return yy_flex_debug; } -void hsql_set_debug (int bdebug , yyscan_t yyscanner) +void hsql_set_debug (int _bdebug , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yy_flex_debug = bdebug ; + yy_flex_debug = _bdebug ; } /* Accessor methods for yylval and yylloc */ @@ -3603,20 +3609,20 @@ int hsql_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) errno = EINVAL; return 1; } - + *ptr_yy_globals = (yyscan_t) hsql_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); - + if (*ptr_yy_globals == NULL){ errno = ENOMEM; return 1; } - + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); - + hsql_set_extra (yy_user_defined, *ptr_yy_globals); - + return yy_init_globals ( *ptr_yy_globals ); } @@ -3627,10 +3633,10 @@ static int yy_init_globals (yyscan_t yyscanner) * This function is called from hsql_lex_destroy(), so don't allocate here. */ - yyg->yy_buffer_stack = 0; + yyg->yy_buffer_stack = NULL; yyg->yy_buffer_stack_top = 0; yyg->yy_buffer_stack_max = 0; - yyg->yy_c_buf_p = (char *) 0; + yyg->yy_c_buf_p = NULL; yyg->yy_init = 0; yyg->yy_start = 0; @@ -3643,8 +3649,8 @@ static int yy_init_globals (yyscan_t yyscanner) yyin = stdin; yyout = stdout; #else - yyin = (FILE *) 0; - yyout = (FILE *) 0; + yyin = NULL; + yyout = NULL; #endif /* For future reference: Set errno on error, since we are called by @@ -3690,7 +3696,10 @@ int hsql_lex_destroy (yyscan_t yyscanner) #ifndef yytext_ptr static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) { - register int i; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + + int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } @@ -3699,7 +3708,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yysca #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) { - register int n; + int n; for ( n = 0; s[n]; ++n ) ; @@ -3709,11 +3718,16 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) void *hsql_alloc (yy_size_t size , yyscan_t yyscanner) { - return (void *) malloc( size ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + return malloc(size); } void *hsql_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + /* 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 @@ -3721,11 +3735,13 @@ void *hsql_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner) * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ - return (void *) realloc( (char *) ptr, size ); + return realloc(ptr, size); } void hsql_free (void * ptr , yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; free( (char *) ptr ); /* see hsql_realloc() for (char *) cast */ } diff --git a/src/parser/flex_lexer.h b/src/parser/flex_lexer.h index 6a80353..548c672 100644 --- a/src/parser/flex_lexer.h +++ b/src/parser/flex_lexer.h @@ -12,8 +12,8 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 1 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -92,25 +92,13 @@ typedef unsigned int flex_uint32_t; #endif /* ! FLEXINT_H */ -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST +/* TODO: this is always defined, so inline it */ #define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) #else -#define yyconst +#define yynoreturn #endif /* An opaque pointer. */ @@ -165,7 +153,7 @@ struct yy_buffer_state /* Size of input buffer in bytes, not including room for EOB * characters. */ - yy_size_t yy_buf_size; + int yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. @@ -193,7 +181,7 @@ struct yy_buffer_state 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. */ @@ -222,7 +210,7 @@ void hsql_free (void * ,yyscan_t yyscanner ); /* Begin user sect3 */ -#define hsql_wrap(n) 1 +#define hsql_wrap(yyscanner) (/*CONSTCOND*/1) #define YY_SKIP_YYWRAP #define yytext_ptr yytext_r @@ -264,19 +252,23 @@ void hsql_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); FILE *hsql_get_in (yyscan_t yyscanner ); -void hsql_set_in (FILE * in_str ,yyscan_t yyscanner ); +void hsql_set_in (FILE * _in_str ,yyscan_t yyscanner ); FILE *hsql_get_out (yyscan_t yyscanner ); -void hsql_set_out (FILE * out_str ,yyscan_t yyscanner ); +void hsql_set_out (FILE * _out_str ,yyscan_t yyscanner ); -int hsql_get_leng (yyscan_t yyscanner ); + int hsql_get_leng (yyscan_t yyscanner ); char *hsql_get_text (yyscan_t yyscanner ); int hsql_get_lineno (yyscan_t yyscanner ); -void hsql_set_lineno (int line_number ,yyscan_t yyscanner ); +void hsql_set_lineno (int _line_number ,yyscan_t yyscanner ); + +int hsql_get_column (yyscan_t yyscanner ); + +void hsql_set_column (int _column_no ,yyscan_t yyscanner ); YYSTYPE * hsql_get_lval (yyscan_t yyscanner ); @@ -355,6 +347,6 @@ extern int hsql_lex \ #line 213 "flex_lexer.l" -#line 359 "flex_lexer.h" +#line 351 "flex_lexer.h" #undef hsql_IN_HEADER #endif /* hsql_HEADER_H */