/ Check-in [457e0b24]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Modifications to the parser to eliminate unreachable code. (CVS 6749)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 457e0b245b1833c0d297bc6f4ff9785e6a2cee02
User & Date: drh 2009-06-12 02:27:15
Context
2009-06-12
03:27
Make sure nested queries with USING clauses do not leak memory. Preliminary fix for ticket #3911. (CVS 6750) check-in: bd341a10 user: drh tags: trunk
02:27
Modifications to the parser to eliminate unreachable code. (CVS 6749) check-in: 457e0b24 user: drh tags: trunk
2009-06-11
17:32
Honor the SQLITE_OPEN_READONLY flag even on a :memory: or temporary database, even though such a database is pointless. Ticket #3908. (CVS 6748) check-in: 73ba841a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/parse.y.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains SQLite's grammar for SQL.  Process this file
    13     13   ** using the lemon parser generator to generate C code that runs
    14     14   ** the parser.  Lemon will also generate a header file containing
    15     15   ** numeric codes for all of the tokens.
    16     16   **
    17         -** @(#) $Id: parse.y,v 1.278 2009/05/28 01:00:55 drh Exp $
           17  +** @(#) $Id: parse.y,v 1.279 2009/06/12 02:27:15 drh Exp $
    18     18   */
    19     19   
    20     20   // All token codes are small integers with #defines that begin with "TK_"
    21     21   %token_prefix TK_
    22     22   
    23     23   // The type of the data attached to each token is Token.  This is also the
    24     24   // default type for non-terminals.
................................................................................
    49     49   
    50     50   // The following text is included near the beginning of the C source
    51     51   // code file that implements the parser.
    52     52   //
    53     53   %include {
    54     54   #include "sqliteInt.h"
    55     55   
           56  +/*
           57  +** Disable all error recovery processing in the parser push-down
           58  +** automaton.
           59  +*/
           60  +#define YYNOERRORRECOVERY 1
           61  +
    56     62   /*
    57     63   ** An instance of this structure holds information about the
    58     64   ** LIMIT clause of a SELECT statement.
    59     65   */
    60     66   struct LimitVal {
    61     67     Expr *pLimit;    /* The LIMIT expression.  NULL if there is no limit */
    62     68     Expr *pOffset;   /* The OFFSET expression.  NULL if there is none */
................................................................................
   475    481   }
   476    482   
   477    483   // "seltablist" is a "Select Table List" - the content of the FROM clause
   478    484   // in a SELECT statement.  "stl_prefix" is a prefix of this list.
   479    485   //
   480    486   stl_prefix(A) ::= seltablist(X) joinop(Y).    {
   481    487      A = X;
   482         -   if( A && A->nSrc>0 ) A->a[A->nSrc-1].jointype = (u8)Y;
          488  +   if( ALWAYS(A && A->nSrc>0) ) A->a[A->nSrc-1].jointype = (u8)Y;
   483    489   }
   484    490   stl_prefix(A) ::= .                           {A = 0;}
   485    491   seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I) on_opt(N) using_opt(U). {
   486    492     A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U);
   487    493     sqlite3SrcListIndexedBy(pParse, A, &I);
   488    494   }
   489    495   %ifndef SQLITE_OMIT_SUBQUERY
................................................................................
   569    575   orderby_opt(A) ::= ORDER BY sortlist(X).      {A = X;}
   570    576   sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
   571    577     A = sqlite3ExprListAppend(pParse,X,Y);
   572    578     if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z;
   573    579   }
   574    580   sortlist(A) ::= sortitem(Y) sortorder(Z). {
   575    581     A = sqlite3ExprListAppend(pParse,0,Y);
   576         -  if( A && A->a ) A->a[0].sortOrder = (u8)Z;
          582  +  if( A && ALWAYS(A->a) ) A->a[0].sortOrder = (u8)Z;
   577    583   }
   578    584   sortitem(A) ::= expr(X).   {A = X.pExpr;}
   579    585   
   580    586   %type sortorder {int}
   581    587   
   582    588   sortorder(A) ::= ASC.           {A = SQLITE_SO_ASC;}
   583    589   sortorder(A) ::= DESC.          {A = SQLITE_SO_DESC;}

Changes to tool/lempar.c.

   604    604       yy_accept(yypParser);
   605    605     }
   606    606   }
   607    607   
   608    608   /*
   609    609   ** The following code executes when the parse fails
   610    610   */
          611  +#ifndef YYNOERRORRECOVERY
   611    612   static void yy_parse_failed(
   612    613     yyParser *yypParser           /* The parser */
   613    614   ){
   614    615     ParseARG_FETCH;
   615    616   #ifndef NDEBUG
   616    617     if( yyTraceFILE ){
   617    618       fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
................................................................................
   619    620   #endif
   620    621     while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
   621    622     /* Here code is inserted which will be executed whenever the
   622    623     ** parser fails */
   623    624   %%
   624    625     ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
   625    626   }
          627  +#endif /* YYNOERRORRECOVERY */
   626    628   
   627    629   /*
   628    630   ** The following code executes when a syntax error first occurs.
   629    631   */
   630    632   static void yy_syntax_error(
   631    633     yyParser *yypParser,           /* The parser */
   632    634     int yymajor,                   /* The major type of the error token */
................................................................................
   786    788             YYMINORTYPE u2;
   787    789             u2.YYERRSYMDT = 0;
   788    790             yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
   789    791           }
   790    792         }
   791    793         yypParser->yyerrcnt = 3;
   792    794         yyerrorhit = 1;
          795  +#elif defined(YYNOERRORRECOVERY)
          796  +      /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
          797  +      ** do any kind of error recovery.  Instead, simply invoke the syntax
          798  +      ** error routine and continue going as if nothing had happened.
          799  +      **
          800  +      ** Applications can set this macro (for example inside %include) if
          801  +      ** they intend to abandon the parse upon the first syntax error seen.
          802  +      */
          803  +      yy_syntax_error(yypParser,yymajor,yyminorunion);
          804  +      yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
          805  +      yymajor = YYNOCODE;
          806  +      
   793    807   #else  /* YYERRORSYMBOL is not defined */
   794    808         /* This is what we do if the grammar does not define ERROR:
   795    809         **
   796    810         **  * Report an error message, and throw away the input token.
   797    811         **
   798    812         **  * If the input token is $, then fail the parse.
   799    813         **