/ Check-in [3eab7bdc]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Remove the ExprSpan object. Instead, keep track of the test of subphrases in the parse using the "scanpt" non-terminal.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | span-refactor
Files: files | file ages | folders
SHA3-256: 3eab7bdc44e0878b83dc86f27058a40c2ffafeacadc566f03693f6dc7e40a504
User & Date: drh 2017-12-24 00:18:47
Context
2017-12-24
14:14
Improved parser tracing output. check-in: c4951833 user: drh tags: span-refactor
00:18
Remove the ExprSpan object. Instead, keep track of the test of subphrases in the parse using the "scanpt" non-terminal. check-in: 3eab7bdc user: drh tags: span-refactor
2017-12-23
14:39
Simplification to the error handling logic in the extension loader. check-in: 07c77314 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/build.c.

  1217   1217   **
  1218   1218   ** Default value expressions must be constant.  Raise an exception if this
  1219   1219   ** is not the case.
  1220   1220   **
  1221   1221   ** This routine is called by the parser while in the middle of
  1222   1222   ** parsing a CREATE TABLE statement.
  1223   1223   */
  1224         -void sqlite3AddDefaultValue(Parse *pParse, ExprSpan *pSpan){
         1224  +void sqlite3AddDefaultValue(
         1225  +  Parse *pParse,           /* Parsing context */
         1226  +  Expr *pExpr,             /* The parsed expression of the default value */
         1227  +  const char *zStart,      /* Start of the default value text */
         1228  +  const char *zEnd         /* First character past end of defaut value text */
         1229  +){
  1225   1230     Table *p;
  1226   1231     Column *pCol;
  1227   1232     sqlite3 *db = pParse->db;
  1228   1233     p = pParse->pNewTable;
  1229   1234     if( p!=0 ){
  1230   1235       pCol = &(p->aCol[p->nCol-1]);
  1231         -    if( !sqlite3ExprIsConstantOrFunction(pSpan->pExpr, db->init.busy) ){
         1236  +    if( !sqlite3ExprIsConstantOrFunction(pExpr, db->init.busy) ){
  1232   1237         sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
  1233   1238             pCol->zName);
  1234   1239       }else{
  1235   1240         /* A copy of pExpr is used instead of the original, as pExpr contains
  1236         -      ** tokens that point to volatile memory. The 'span' of the expression
  1237         -      ** is required by pragma table_info.
         1241  +      ** tokens that point to volatile memory.	
  1238   1242         */
  1239   1243         Expr x;
         1244  +      int n;
  1240   1245         sqlite3ExprDelete(db, pCol->pDflt);
  1241   1246         memset(&x, 0, sizeof(x));
  1242   1247         x.op = TK_SPAN;
  1243         -      x.u.zToken = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
  1244         -                                    (int)(pSpan->zEnd - pSpan->zStart));
  1245         -      x.pLeft = pSpan->pExpr;
         1248  +      while( sqlite3Isspace(zStart[0]) ) zStart++;
         1249  +      n = (int)(zEnd - zStart);
         1250  +      while( n>0 && sqlite3Isspace(zStart[n-1]) ) n--;
         1251  +      x.u.zToken = sqlite3DbStrNDup(db, zStart, n);
         1252  +      x.pLeft = pExpr;
  1246   1253         x.flags = EP_Skip;
  1247   1254         pCol->pDflt = sqlite3ExprDup(db, &x, EXPRDUP_REDUCE);
  1248   1255         sqlite3DbFree(db, x.u.zToken);
  1249   1256       }
  1250   1257     }
  1251         -  sqlite3ExprDelete(db, pSpan->pExpr);
         1258  +  sqlite3ExprDelete(db, pExpr);
  1252   1259   }
  1253   1260   
  1254   1261   /*
  1255   1262   ** Backwards Compatibility Hack:
  1256   1263   ** 
  1257   1264   ** Historical versions of SQLite accepted strings as column names in
  1258   1265   ** indexes and PRIMARY KEY constraints and in UNIQUE constraints.  Example:

Changes to src/expr.c.

  1650   1650   ** pList might be NULL following an OOM error.  But pSpan should never be
  1651   1651   ** NULL.  If a memory allocation fails, the pParse->db->mallocFailed flag
  1652   1652   ** is set.
  1653   1653   */
  1654   1654   void sqlite3ExprListSetSpan(
  1655   1655     Parse *pParse,          /* Parsing context */
  1656   1656     ExprList *pList,        /* List to which to add the span. */
  1657         -  ExprSpan *pSpan         /* The span to be added */
         1657  +  const char *zStart,     /* Start of the span */
         1658  +  const char *zEnd        /* End of the span */
  1658   1659   ){
  1659   1660     sqlite3 *db = pParse->db;
  1660   1661     assert( pList!=0 || db->mallocFailed!=0 );
  1661   1662     if( pList ){
  1662   1663       struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
         1664  +    int n;
  1663   1665       assert( pList->nExpr>0 );
  1664         -    assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr );
  1665   1666       sqlite3DbFree(db, pItem->zSpan);
  1666         -    pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
  1667         -                                    (int)(pSpan->zEnd - pSpan->zStart));
         1667  +    while( sqlite3Isspace(zStart[0]) ) zStart++;
         1668  +    n = (int)(zEnd - zStart);
         1669  +    while( n>0 && sqlite3Isspace(zStart[n-1]) ) n--;
         1670  +    pItem->zSpan = sqlite3DbStrNDup(db, zStart, n);
  1668   1671     }
  1669   1672   }
  1670   1673   
  1671   1674   /*
  1672   1675   ** If the expression list pEList contains more than iLimit elements,
  1673   1676   ** leave an error message in pParse.
  1674   1677   */

Changes to src/parse.y.

   268    268     A.n = (int)(&Y.z[Y.n] - A.z);
   269    269   }
   270    270   %type typename {Token}
   271    271   typename(A) ::= ids(A).
   272    272   typename(A) ::= typename(A) ids(Y). {A.n=Y.n+(int)(Y.z-A.z);}
   273    273   signed ::= plus_num.
   274    274   signed ::= minus_num.
          275  +
          276  +// The scanpt non-terminal takes a value which is a pointer to the
          277  +// input text just past the last token that has been shifted into
          278  +// the parser.  By surrounding some phrase in the grammar with two
          279  +// scanpt non-terminals, we can capture the input text for that phrase.
          280  +// For example:
          281  +//
          282  +//      something ::= .... scanpt(A) phrase scanpt(Z).
          283  +//
          284  +// The text that is parsed as "phrase" is a string starting at A
          285  +// and containing (int)(Z-A) characters.  There might be some extra
          286  +// whitespace on either end of the text, but that can be removed in
          287  +// post-processing, if needed.
          288  +//
          289  +%type scanpt {const char*}
          290  +scanpt(A) ::= . {
          291  +  if( yyLookahead!=YYNOCODE ){
          292  +    A = yyLookaheadToken.z;
          293  +  }else{
          294  +    A = pParse->sLastToken.z + pParse->sLastToken.n;
          295  +  }
          296  +}
   275    297   
   276    298   // "carglist" is a list of additional constraints that come after the
   277    299   // column name and column type in a CREATE TABLE statement.
   278    300   //
   279    301   carglist ::= carglist ccons.
   280    302   carglist ::= .
   281    303   ccons ::= CONSTRAINT nm(X).           {pParse->constraintName = X;}
   282         -ccons ::= DEFAULT term(X).            {sqlite3AddDefaultValue(pParse,&X);}
   283         -ccons ::= DEFAULT LP expr(X) RP.      {sqlite3AddDefaultValue(pParse,&X);}
   284         -ccons ::= DEFAULT PLUS term(X).       {sqlite3AddDefaultValue(pParse,&X);}
   285         -ccons ::= DEFAULT MINUS(A) term(X).      {
   286         -  ExprSpan v;
   287         -  v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, X.pExpr, 0);
   288         -  v.zStart = A.z;
   289         -  v.zEnd = X.zEnd;
   290         -  sqlite3AddDefaultValue(pParse,&v);
          304  +ccons ::= DEFAULT scanpt(A) term(X) scanpt(Z).
          305  +                            {sqlite3AddDefaultValue(pParse,X,A,Z);}
          306  +ccons ::= DEFAULT LP(A) expr(X) RP(Z).
          307  +                            {sqlite3AddDefaultValue(pParse,X,A.z+1,Z.z);}
          308  +ccons ::= DEFAULT PLUS(A) term(X) scanpt(Z).
          309  +                            {sqlite3AddDefaultValue(pParse,X,A.z,Z);}
          310  +ccons ::= DEFAULT MINUS(A) term(X) scanpt(Z).      {
          311  +  Expr *p = sqlite3PExpr(pParse, TK_UMINUS, X, 0);
          312  +  sqlite3AddDefaultValue(pParse,p,A.z,Z);
   291    313   }
   292         -ccons ::= DEFAULT id(X).              {
   293         -  ExprSpan v;
   294         -  spanExpr(&v, pParse, TK_STRING, X);
   295         -  sqlite3AddDefaultValue(pParse,&v);
          314  +ccons ::= DEFAULT scanpt id(X).       {
          315  +  Expr *p = tokenExpr(pParse, TK_STRING, X);
          316  +  sqlite3AddDefaultValue(pParse,p,X.z,X.z+X.n);
   296    317   }
   297    318   
   298    319   // In addition to the type name, we also care about the primary key and
   299    320   // UNIQUE constraints.
   300    321   //
   301    322   ccons ::= NULL onconf.
   302    323   ccons ::= NOT NULL onconf(R).    {sqlite3AddNotNull(pParse, R);}
   303    324   ccons ::= PRIMARY KEY sortorder(Z) onconf(R) autoinc(I).
   304    325                                    {sqlite3AddPrimaryKey(pParse,0,R,I,Z);}
   305    326   ccons ::= UNIQUE onconf(R).      {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0,0,0,
   306    327                                      SQLITE_IDXTYPE_UNIQUE);}
   307         -ccons ::= CHECK LP expr(X) RP.   {sqlite3AddCheckConstraint(pParse,X.pExpr);}
          328  +ccons ::= CHECK LP expr(X) RP.   {sqlite3AddCheckConstraint(pParse,X);}
   308    329   ccons ::= REFERENCES nm(T) eidlist_opt(TA) refargs(R).
   309    330                                    {sqlite3CreateForeignKey(pParse,0,&T,TA,R);}
   310    331   ccons ::= defer_subclause(D).    {sqlite3DeferForeignKey(pParse,D);}
   311    332   ccons ::= COLLATE ids(C).        {sqlite3AddCollateType(pParse, &C);}
   312    333   
   313    334   // The optional AUTOINCREMENT keyword
   314    335   %type autoinc {int}
................................................................................
   351    372   tcons ::= CONSTRAINT nm(X).      {pParse->constraintName = X;}
   352    373   tcons ::= PRIMARY KEY LP sortlist(X) autoinc(I) RP onconf(R).
   353    374                                    {sqlite3AddPrimaryKey(pParse,X,R,I,0);}
   354    375   tcons ::= UNIQUE LP sortlist(X) RP onconf(R).
   355    376                                    {sqlite3CreateIndex(pParse,0,0,0,X,R,0,0,0,0,
   356    377                                          SQLITE_IDXTYPE_UNIQUE);}
   357    378   tcons ::= CHECK LP expr(E) RP onconf.
   358         -                                 {sqlite3AddCheckConstraint(pParse,E.pExpr);}
          379  +                                 {sqlite3AddCheckConstraint(pParse,E);}
   359    380   tcons ::= FOREIGN KEY LP eidlist(FA) RP
   360    381             REFERENCES nm(T) eidlist_opt(TA) refargs(R) defer_subclause_opt(D). {
   361    382       sqlite3CreateForeignKey(pParse, FA, &T, TA, R);
   362    383       sqlite3DeferForeignKey(pParse, D);
   363    384   }
   364    385   %type defer_subclause_opt {int}
   365    386   defer_subclause_opt(A) ::= .                    {A = 0;}
................................................................................
   545    566   //
   546    567   %type selcollist {ExprList*}
   547    568   %destructor selcollist {sqlite3ExprListDelete(pParse->db, $$);}
   548    569   %type sclp {ExprList*}
   549    570   %destructor sclp {sqlite3ExprListDelete(pParse->db, $$);}
   550    571   sclp(A) ::= selcollist(A) COMMA.
   551    572   sclp(A) ::= .                                {A = 0;}
   552         -selcollist(A) ::= sclp(A) expr(X) as(Y).     {
   553         -   A = sqlite3ExprListAppend(pParse, A, X.pExpr);
          573  +selcollist(A) ::= sclp(A) scanpt(B) expr(X) scanpt(Z) as(Y).     {
          574  +   A = sqlite3ExprListAppend(pParse, A, X);
   554    575      if( Y.n>0 ) sqlite3ExprListSetName(pParse, A, &Y, 1);
   555         -   sqlite3ExprListSetSpan(pParse,A,&X);
          576  +   sqlite3ExprListSetSpan(pParse,A,B,Z);
   556    577   }
   557    578   selcollist(A) ::= sclp(A) STAR. {
   558    579     Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
   559    580     A = sqlite3ExprListAppend(pParse, A, p);
   560    581   }
   561         -selcollist(A) ::= sclp(A) nm(X) DOT STAR. {
          582  +selcollist(A) ::= sclp(A) scanpt nm(X) DOT STAR. {
   562    583     Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
   563    584     Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
   564    585     Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
   565    586     A = sqlite3ExprListAppend(pParse,A, pDot);
   566    587   }
   567    588   
   568    589   // An option "AS <id>" phrase that can follow one of the expressions that
................................................................................
   652    673   joinop(X) ::= JOIN_KW(A) nm(B) JOIN.
   653    674                     {X = sqlite3JoinType(pParse,&A,&B,0); /*X-overwrites-A*/}
   654    675   joinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN.
   655    676                     {X = sqlite3JoinType(pParse,&A,&B,&C);/*X-overwrites-A*/}
   656    677   
   657    678   %type on_opt {Expr*}
   658    679   %destructor on_opt {sqlite3ExprDelete(pParse->db, $$);}
   659         -on_opt(N) ::= ON expr(E).   {N = E.pExpr;}
          680  +on_opt(N) ::= ON expr(E).   {N = E;}
   660    681   on_opt(N) ::= .             {N = 0;}
   661    682   
   662    683   // Note that this block abuses the Token type just a little. If there is
   663    684   // no "INDEXED BY" clause, the returned token is empty (z==0 && n==0). If
   664    685   // there is an INDEXED BY clause, then the token is populated as per normal,
   665    686   // with z pointing to the token data and n containing the number of bytes
   666    687   // in the token.
................................................................................
   689    710   //
   690    711   %type sortlist {ExprList*}
   691    712   %destructor sortlist {sqlite3ExprListDelete(pParse->db, $$);}
   692    713   
   693    714   orderby_opt(A) ::= .                          {A = 0;}
   694    715   orderby_opt(A) ::= ORDER BY sortlist(X).      {A = X;}
   695    716   sortlist(A) ::= sortlist(A) COMMA expr(Y) sortorder(Z). {
   696         -  A = sqlite3ExprListAppend(pParse,A,Y.pExpr);
          717  +  A = sqlite3ExprListAppend(pParse,A,Y);
   697    718     sqlite3ExprListSetSortOrder(A,Z);
   698    719   }
   699    720   sortlist(A) ::= expr(Y) sortorder(Z). {
   700         -  A = sqlite3ExprListAppend(pParse,0,Y.pExpr); /*A-overwrites-Y*/
          721  +  A = sqlite3ExprListAppend(pParse,0,Y); /*A-overwrites-Y*/
   701    722     sqlite3ExprListSetSortOrder(A,Z);
   702    723   }
   703    724   
   704    725   %type sortorder {int}
   705    726   
   706    727   sortorder(A) ::= ASC.           {A = SQLITE_SO_ASC;}
   707    728   sortorder(A) ::= DESC.          {A = SQLITE_SO_DESC;}
................................................................................
   711    732   %destructor groupby_opt {sqlite3ExprListDelete(pParse->db, $$);}
   712    733   groupby_opt(A) ::= .                      {A = 0;}
   713    734   groupby_opt(A) ::= GROUP BY nexprlist(X). {A = X;}
   714    735   
   715    736   %type having_opt {Expr*}
   716    737   %destructor having_opt {sqlite3ExprDelete(pParse->db, $$);}
   717    738   having_opt(A) ::= .                {A = 0;}
   718         -having_opt(A) ::= HAVING expr(X).  {A = X.pExpr;}
          739  +having_opt(A) ::= HAVING expr(X).  {A = X;}
   719    740   
   720    741   %type limit_opt {Expr*}
   721    742   
   722    743   // The destructor for limit_opt will never fire in the current grammar.
   723    744   // The limit_opt non-terminal only occurs at the end of a single production
   724    745   // rule for SELECT statements.  As soon as the rule that create the 
   725    746   // limit_opt non-terminal reduces, the SELECT statement rule will also
   726    747   // reduce.  So there is never a limit_opt non-terminal on the stack 
   727    748   // except as a transient.  So there is never anything to destroy.
   728    749   //
   729    750   //%destructor limit_opt {sqlite3ExprDelete(pParse->db, $$);}
   730    751   limit_opt(A) ::= .       {A = 0;}
   731    752   limit_opt(A) ::= LIMIT expr(X).
   732         -                         {A = sqlite3PExpr(pParse,TK_LIMIT,X.pExpr,0);}
          753  +                         {A = sqlite3PExpr(pParse,TK_LIMIT,X,0);}
   733    754   limit_opt(A) ::= LIMIT expr(X) OFFSET expr(Y). 
   734         -                         {A = sqlite3PExpr(pParse,TK_LIMIT,X.pExpr,Y.pExpr);}
          755  +                         {A = sqlite3PExpr(pParse,TK_LIMIT,X,Y);}
   735    756   limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y). 
   736         -                         {A = sqlite3PExpr(pParse,TK_LIMIT,Y.pExpr,X.pExpr);}
          757  +                         {A = sqlite3PExpr(pParse,TK_LIMIT,Y,X);}
   737    758   
   738    759   /////////////////////////// The DELETE statement /////////////////////////////
   739    760   //
   740    761   %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   741    762   cmd ::= with(C) DELETE FROM fullname(X) indexed_opt(I) where_opt(W) 
   742    763           orderby_opt(O) limit_opt(L). {
   743    764     sqlite3WithPush(pParse, C, 1);
................................................................................
   753    774   }
   754    775   %endif
   755    776   
   756    777   %type where_opt {Expr*}
   757    778   %destructor where_opt {sqlite3ExprDelete(pParse->db, $$);}
   758    779   
   759    780   where_opt(A) ::= .                    {A = 0;}
   760         -where_opt(A) ::= WHERE expr(X).       {A = X.pExpr;}
          781  +where_opt(A) ::= WHERE expr(X).       {A = X;}
   761    782   
   762    783   ////////////////////////// The UPDATE command ////////////////////////////////
   763    784   //
   764    785   %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   765    786   cmd ::= with(C) UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y)
   766    787           where_opt(W) orderby_opt(O) limit_opt(L).  {
   767    788     sqlite3WithPush(pParse, C, 1);
................................................................................
   780    801   }
   781    802   %endif
   782    803   
   783    804   %type setlist {ExprList*}
   784    805   %destructor setlist {sqlite3ExprListDelete(pParse->db, $$);}
   785    806   
   786    807   setlist(A) ::= setlist(A) COMMA nm(X) EQ expr(Y). {
   787         -  A = sqlite3ExprListAppend(pParse, A, Y.pExpr);
          808  +  A = sqlite3ExprListAppend(pParse, A, Y);
   788    809     sqlite3ExprListSetName(pParse, A, &X, 1);
   789    810   }
   790    811   setlist(A) ::= setlist(A) COMMA LP idlist(X) RP EQ expr(Y). {
   791         -  A = sqlite3ExprListAppendVector(pParse, A, X, Y.pExpr);
          812  +  A = sqlite3ExprListAppendVector(pParse, A, X, Y);
   792    813   }
   793    814   setlist(A) ::= nm(X) EQ expr(Y). {
   794         -  A = sqlite3ExprListAppend(pParse, 0, Y.pExpr);
          815  +  A = sqlite3ExprListAppend(pParse, 0, Y);
   795    816     sqlite3ExprListSetName(pParse, A, &X, 1);
   796    817   }
   797    818   setlist(A) ::= LP idlist(X) RP EQ expr(Y). {
   798         -  A = sqlite3ExprListAppendVector(pParse, 0, X, Y.pExpr);
          819  +  A = sqlite3ExprListAppendVector(pParse, 0, X, Y);
   799    820   }
   800    821   
   801    822   ////////////////////////// The INSERT command /////////////////////////////////
   802    823   //
   803    824   cmd ::= with(W) insert_cmd(R) INTO fullname(X) idlist_opt(F) select(S). {
   804    825     sqlite3WithPush(pParse, W, 1);
   805    826     sqlite3Insert(pParse, X, S, F, R);
................................................................................
   825    846       {A = sqlite3IdListAppend(pParse->db,A,&Y);}
   826    847   idlist(A) ::= nm(Y).
   827    848       {A = sqlite3IdListAppend(pParse->db,0,&Y); /*A-overwrites-Y*/}
   828    849   
   829    850   /////////////////////////// Expression Processing /////////////////////////////
   830    851   //
   831    852   
   832         -%type expr {ExprSpan}
   833         -%destructor expr {sqlite3ExprDelete(pParse->db, $$.pExpr);}
   834         -%type term {ExprSpan}
   835         -%destructor term {sqlite3ExprDelete(pParse->db, $$.pExpr);}
          853  +%type expr {Expr*}
          854  +%destructor expr {sqlite3ExprDelete(pParse->db, $$);}
          855  +%type term {Expr*}
          856  +%destructor term {sqlite3ExprDelete(pParse->db, $$);}
   836    857   
   837    858   %include {
   838         -  /* This is a utility routine used to set the ExprSpan.zStart and
   839         -  ** ExprSpan.zEnd values of pOut so that the span covers the complete
   840         -  ** range of text beginning with pStart and going to the end of pEnd.
   841         -  */
   842         -  static void spanSet(ExprSpan *pOut, Token *pStart, Token *pEnd){
   843         -    pOut->zStart = pStart->z;
   844         -    pOut->zEnd = &pEnd->z[pEnd->n];
   845         -  }
   846    859   
   847    860     /* Construct a new Expr object from a single identifier.  Use the
   848    861     ** new Expr to populate pOut.  Set the span of pOut to be the identifier
   849    862     ** that created the expression.
   850    863     */
   851         -  static void spanExpr(ExprSpan *pOut, Parse *pParse, int op, Token t){
          864  +  static Expr *tokenExpr(Parse *pParse, int op, Token t){
   852    865       Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
   853    866       if( p ){
   854    867         memset(p, 0, sizeof(Expr));
   855    868         p->op = (u8)op;
   856    869         p->flags = EP_Leaf;
   857    870         p->iAgg = -1;
   858    871         p->u.zToken = (char*)&p[1];
................................................................................
   862    875           if( p->u.zToken[0]=='"' ) p->flags |= EP_DblQuoted;
   863    876           sqlite3Dequote(p->u.zToken);
   864    877         }
   865    878   #if SQLITE_MAX_EXPR_DEPTH>0
   866    879         p->nHeight = 1;
   867    880   #endif  
   868    881       }
   869         -    pOut->pExpr = p;
   870         -    pOut->zStart = t.z;
   871         -    pOut->zEnd = &t.z[t.n];
          882  +    return p;
   872    883     }
   873    884   }
   874    885   
   875    886   expr(A) ::= term(A).
   876         -expr(A) ::= LP(B) expr(X) RP(E).
   877         -            {spanSet(&A,&B,&E); /*A-overwrites-B*/  A.pExpr = X.pExpr;}
   878         -expr(A) ::= id(X).          {spanExpr(&A,pParse,TK_ID,X); /*A-overwrites-X*/}
   879         -expr(A) ::= JOIN_KW(X).     {spanExpr(&A,pParse,TK_ID,X); /*A-overwrites-X*/}
          887  +expr(A) ::= LP expr(X) RP. {A = X;}
          888  +expr(A) ::= id(X).          {A=tokenExpr(pParse,TK_ID,X); /*A-overwrites-X*/}
          889  +expr(A) ::= JOIN_KW(X).     {A=tokenExpr(pParse,TK_ID,X); /*A-overwrites-X*/}
   880    890   expr(A) ::= nm(X) DOT nm(Y). {
   881    891     Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
   882    892     Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &Y, 1);
   883         -  spanSet(&A,&X,&Y); /*A-overwrites-X*/
   884         -  A.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
          893  +  A = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
   885    894   }
   886    895   expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
   887    896     Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
   888    897     Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &Y, 1);
   889    898     Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &Z, 1);
   890    899     Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
   891         -  spanSet(&A,&X,&Z); /*A-overwrites-X*/
   892         -  A.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
          900  +  A = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
   893    901   }
   894         -term(A) ::= NULL|FLOAT|BLOB(X). {spanExpr(&A,pParse,@X,X); /*A-overwrites-X*/}
   895         -term(A) ::= STRING(X).          {spanExpr(&A,pParse,@X,X); /*A-overwrites-X*/}
          902  +term(A) ::= NULL|FLOAT|BLOB(X). {A=tokenExpr(pParse,@X,X); /*A-overwrites-X*/}
          903  +term(A) ::= STRING(X).          {A=tokenExpr(pParse,@X,X); /*A-overwrites-X*/}
   896    904   term(A) ::= INTEGER(X). {
   897         -  A.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &X, 1);
   898         -  A.zStart = X.z;
   899         -  A.zEnd = X.z + X.n;
          905  +  A = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &X, 1);
   900    906   }
   901    907   expr(A) ::= VARIABLE(X).     {
   902    908     if( !(X.z[0]=='#' && sqlite3Isdigit(X.z[1])) ){
   903    909       u32 n = X.n;
   904         -    spanExpr(&A, pParse, TK_VARIABLE, X);
   905         -    sqlite3ExprAssignVarNumber(pParse, A.pExpr, n);
          910  +    A = tokenExpr(pParse, TK_VARIABLE, X);
          911  +    sqlite3ExprAssignVarNumber(pParse, A, n);
   906    912     }else{
   907    913       /* When doing a nested parse, one can include terms in an expression
   908    914       ** that look like this:   #1 #2 ...  These terms refer to registers
   909    915       ** in the virtual machine.  #N is the N-th register. */
   910    916       Token t = X; /*A-overwrites-X*/
   911    917       assert( t.n>=2 );
   912         -    spanSet(&A, &t, &t);
   913    918       if( pParse->nested==0 ){
   914    919         sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
   915         -      A.pExpr = 0;
          920  +      A = 0;
   916    921       }else{
   917         -      A.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
   918         -      if( A.pExpr ) sqlite3GetInt32(&t.z[1], &A.pExpr->iTable);
          922  +      A = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
          923  +      if( A ) sqlite3GetInt32(&t.z[1], &A->iTable);
   919    924       }
   920    925     }
   921    926   }
   922    927   expr(A) ::= expr(A) COLLATE ids(C). {
   923         -  A.pExpr = sqlite3ExprAddCollateToken(pParse, A.pExpr, &C, 1);
   924         -  A.zEnd = &C.z[C.n];
          928  +  A = sqlite3ExprAddCollateToken(pParse, A, &C, 1);
   925    929   }
   926    930   %ifndef SQLITE_OMIT_CAST
   927         -expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). {
   928         -  spanSet(&A,&X,&Y); /*A-overwrites-X*/
   929         -  A.pExpr = sqlite3ExprAlloc(pParse->db, TK_CAST, &T, 1);
   930         -  sqlite3ExprAttachSubtrees(pParse->db, A.pExpr, E.pExpr, 0);
          931  +expr(A) ::= CAST LP expr(E) AS typetoken(T) RP. {
          932  +  A = sqlite3ExprAlloc(pParse->db, TK_CAST, &T, 1);
          933  +  sqlite3ExprAttachSubtrees(pParse->db, A, E, 0);
   931    934   }
   932    935   %endif  SQLITE_OMIT_CAST
   933         -expr(A) ::= id(X) LP distinct(D) exprlist(Y) RP(E). {
          936  +expr(A) ::= id(X) LP distinct(D) exprlist(Y) RP. {
   934    937     if( Y && Y->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
   935    938       sqlite3ErrorMsg(pParse, "too many arguments on function %T", &X);
   936    939     }
   937         -  A.pExpr = sqlite3ExprFunction(pParse, Y, &X);
   938         -  spanSet(&A,&X,&E);
   939         -  if( D==SF_Distinct && A.pExpr ){
   940         -    A.pExpr->flags |= EP_Distinct;
          940  +  A = sqlite3ExprFunction(pParse, Y, &X);
          941  +  if( D==SF_Distinct && A ){
          942  +    A->flags |= EP_Distinct;
   941    943     }
   942    944   }
   943         -expr(A) ::= id(X) LP STAR RP(E). {
   944         -  A.pExpr = sqlite3ExprFunction(pParse, 0, &X);
   945         -  spanSet(&A,&X,&E);
          945  +expr(A) ::= id(X) LP STAR RP. {
          946  +  A = sqlite3ExprFunction(pParse, 0, &X);
   946    947   }
   947    948   term(A) ::= CTIME_KW(OP). {
   948         -  A.pExpr = sqlite3ExprFunction(pParse, 0, &OP);
   949         -  spanSet(&A, &OP, &OP);
          949  +  A = sqlite3ExprFunction(pParse, 0, &OP);
   950    950   }
   951    951   
   952         -%include {
   953         -  /* This routine constructs a binary expression node out of two ExprSpan
   954         -  ** objects and uses the result to populate a new ExprSpan object.
   955         -  */
   956         -  static void spanBinaryExpr(
   957         -    Parse *pParse,      /* The parsing context.  Errors accumulate here */
   958         -    int op,             /* The binary operation */
   959         -    ExprSpan *pLeft,    /* The left operand, and output */
   960         -    ExprSpan *pRight    /* The right operand */
   961         -  ){
   962         -    pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr);
   963         -    pLeft->zEnd = pRight->zEnd;
   964         -  }
   965         -
   966         -  /* If doNot is true, then add a TK_NOT Expr-node wrapper around the
   967         -  ** outside of *ppExpr.
   968         -  */
   969         -  static void exprNot(Parse *pParse, int doNot, ExprSpan *pSpan){
   970         -    if( doNot ){
   971         -      pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0);
   972         -    }
   973         -  }
   974         -}
   975         -
   976         -expr(A) ::= LP(L) nexprlist(X) COMMA expr(Y) RP(R). {
   977         -  ExprList *pList = sqlite3ExprListAppend(pParse, X, Y.pExpr);
   978         -  A.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
   979         -  if( A.pExpr ){
   980         -    A.pExpr->x.pList = pList;
   981         -    spanSet(&A, &L, &R);
          952  +expr(A) ::= LP nexprlist(X) COMMA expr(Y) RP. {
          953  +  ExprList *pList = sqlite3ExprListAppend(pParse, X, Y);
          954  +  A = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
          955  +  if( A ){
          956  +    A->x.pList = pList;
   982    957     }else{
   983    958       sqlite3ExprListDelete(pParse->db, pList);
   984    959     }
   985    960   }
   986    961   
   987         -expr(A) ::= expr(A) AND(OP) expr(Y).    {spanBinaryExpr(pParse,@OP,&A,&Y);}
   988         -expr(A) ::= expr(A) OR(OP) expr(Y).     {spanBinaryExpr(pParse,@OP,&A,&Y);}
          962  +expr(A) ::= expr(A) AND(OP) expr(Y).    {A=sqlite3PExpr(pParse,@OP,A,Y);}
          963  +expr(A) ::= expr(A) OR(OP) expr(Y).     {A=sqlite3PExpr(pParse,@OP,A,Y);}
   989    964   expr(A) ::= expr(A) LT|GT|GE|LE(OP) expr(Y).
   990         -                                        {spanBinaryExpr(pParse,@OP,&A,&Y);}
   991         -expr(A) ::= expr(A) EQ|NE(OP) expr(Y).  {spanBinaryExpr(pParse,@OP,&A,&Y);}
          965  +                                        {A=sqlite3PExpr(pParse,@OP,A,Y);}
          966  +expr(A) ::= expr(A) EQ|NE(OP) expr(Y).  {A=sqlite3PExpr(pParse,@OP,A,Y);}
   992    967   expr(A) ::= expr(A) BITAND|BITOR|LSHIFT|RSHIFT(OP) expr(Y).
   993         -                                        {spanBinaryExpr(pParse,@OP,&A,&Y);}
          968  +                                        {A=sqlite3PExpr(pParse,@OP,A,Y);}
   994    969   expr(A) ::= expr(A) PLUS|MINUS(OP) expr(Y).
   995         -                                        {spanBinaryExpr(pParse,@OP,&A,&Y);}
          970  +                                        {A=sqlite3PExpr(pParse,@OP,A,Y);}
   996    971   expr(A) ::= expr(A) STAR|SLASH|REM(OP) expr(Y).
   997         -                                        {spanBinaryExpr(pParse,@OP,&A,&Y);}
   998         -expr(A) ::= expr(A) CONCAT(OP) expr(Y). {spanBinaryExpr(pParse,@OP,&A,&Y);}
          972  +                                        {A=sqlite3PExpr(pParse,@OP,A,Y);}
          973  +expr(A) ::= expr(A) CONCAT(OP) expr(Y). {A=sqlite3PExpr(pParse,@OP,A,Y);}
   999    974   %type likeop {Token}
  1000    975   likeop(A) ::= LIKE_KW|MATCH(A).
  1001    976   likeop(A) ::= NOT LIKE_KW|MATCH(X). {A=X; A.n|=0x80000000; /*A-overwrite-X*/}
  1002    977   expr(A) ::= expr(A) likeop(OP) expr(Y).  [LIKE_KW]  {
  1003    978     ExprList *pList;
  1004    979     int bNot = OP.n & 0x80000000;
  1005    980     OP.n &= 0x7fffffff;
  1006         -  pList = sqlite3ExprListAppend(pParse,0, Y.pExpr);
  1007         -  pList = sqlite3ExprListAppend(pParse,pList, A.pExpr);
  1008         -  A.pExpr = sqlite3ExprFunction(pParse, pList, &OP);
  1009         -  exprNot(pParse, bNot, &A);
  1010         -  A.zEnd = Y.zEnd;
  1011         -  if( A.pExpr ) A.pExpr->flags |= EP_InfixFunc;
          981  +  pList = sqlite3ExprListAppend(pParse,0, Y);
          982  +  pList = sqlite3ExprListAppend(pParse,pList, A);
          983  +  A = sqlite3ExprFunction(pParse, pList, &OP);
          984  +  if( bNot ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
          985  +  if( A ) A->flags |= EP_InfixFunc;
  1012    986   }
  1013    987   expr(A) ::= expr(A) likeop(OP) expr(Y) ESCAPE expr(E).  [LIKE_KW]  {
  1014    988     ExprList *pList;
  1015    989     int bNot = OP.n & 0x80000000;
  1016    990     OP.n &= 0x7fffffff;
  1017         -  pList = sqlite3ExprListAppend(pParse,0, Y.pExpr);
  1018         -  pList = sqlite3ExprListAppend(pParse,pList, A.pExpr);
  1019         -  pList = sqlite3ExprListAppend(pParse,pList, E.pExpr);
  1020         -  A.pExpr = sqlite3ExprFunction(pParse, pList, &OP);
  1021         -  exprNot(pParse, bNot, &A);
  1022         -  A.zEnd = E.zEnd;
  1023         -  if( A.pExpr ) A.pExpr->flags |= EP_InfixFunc;
          991  +  pList = sqlite3ExprListAppend(pParse,0, Y);
          992  +  pList = sqlite3ExprListAppend(pParse,pList, A);
          993  +  pList = sqlite3ExprListAppend(pParse,pList, E);
          994  +  A = sqlite3ExprFunction(pParse, pList, &OP);
          995  +  if( bNot ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
          996  +  if( A ) A->flags |= EP_InfixFunc;
  1024    997   }
  1025    998   
  1026         -%include {
  1027         -  /* Construct an expression node for a unary postfix operator
  1028         -  */
  1029         -  static void spanUnaryPostfix(
  1030         -    Parse *pParse,         /* Parsing context to record errors */
  1031         -    int op,                /* The operator */
  1032         -    ExprSpan *pOperand,    /* The operand, and output */
  1033         -    Token *pPostOp         /* The operand token for setting the span */
  1034         -  ){
  1035         -    pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
  1036         -    pOperand->zEnd = &pPostOp->z[pPostOp->n];
  1037         -  }                           
  1038         -}
  1039         -
  1040         -expr(A) ::= expr(A) ISNULL|NOTNULL(E).   {spanUnaryPostfix(pParse,@E,&A,&E);}
  1041         -expr(A) ::= expr(A) NOT NULL(E). {spanUnaryPostfix(pParse,TK_NOTNULL,&A,&E);}
          999  +expr(A) ::= expr(A) ISNULL|NOTNULL(E).   {A = sqlite3PExpr(pParse,@E,A,0);}
         1000  +expr(A) ::= expr(A) NOT NULL.    {A = sqlite3PExpr(pParse,TK_NOTNULL,A,0);}
  1042   1001   
  1043   1002   %include {
  1044   1003     /* A routine to convert a binary TK_IS or TK_ISNOT expression into a
  1045   1004     ** unary TK_ISNULL or TK_NOTNULL expression. */
  1046   1005     static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
  1047   1006       sqlite3 *db = pParse->db;
  1048   1007       if( pA && pY && pY->op==TK_NULL ){
................................................................................
  1056   1015   //    expr1 IS expr2
  1057   1016   //    expr1 IS NOT expr2
  1058   1017   //
  1059   1018   // If expr2 is NULL then code as TK_ISNULL or TK_NOTNULL.  If expr2
  1060   1019   // is any other expression, code as TK_IS or TK_ISNOT.
  1061   1020   // 
  1062   1021   expr(A) ::= expr(A) IS expr(Y).     {
  1063         -  spanBinaryExpr(pParse,TK_IS,&A,&Y);
  1064         -  binaryToUnaryIfNull(pParse, Y.pExpr, A.pExpr, TK_ISNULL);
         1022  +  A = sqlite3PExpr(pParse,TK_IS,A,Y);
         1023  +  binaryToUnaryIfNull(pParse, Y, A, TK_ISNULL);
  1065   1024   }
  1066   1025   expr(A) ::= expr(A) IS NOT expr(Y). {
  1067         -  spanBinaryExpr(pParse,TK_ISNOT,&A,&Y);
  1068         -  binaryToUnaryIfNull(pParse, Y.pExpr, A.pExpr, TK_NOTNULL);
         1026  +  A = sqlite3PExpr(pParse,TK_ISNOT,A,Y);
         1027  +  binaryToUnaryIfNull(pParse, Y, A, TK_NOTNULL);
  1069   1028   }
  1070         -
  1071         -%include {
  1072         -  /* Construct an expression node for a unary prefix operator
  1073         -  */
  1074         -  static void spanUnaryPrefix(
  1075         -    ExprSpan *pOut,        /* Write the new expression node here */
  1076         -    Parse *pParse,         /* Parsing context to record errors */
  1077         -    int op,                /* The operator */
  1078         -    ExprSpan *pOperand,    /* The operand */
  1079         -    Token *pPreOp         /* The operand token for setting the span */
  1080         -  ){
  1081         -    pOut->zStart = pPreOp->z;
  1082         -    pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
  1083         -    pOut->zEnd = pOperand->zEnd;
  1084         -  }
  1085         -}
  1086         -
  1087         -
  1088   1029   
  1089   1030   expr(A) ::= NOT(B) expr(X).  
  1090         -              {spanUnaryPrefix(&A,pParse,@B,&X,&B);/*A-overwrites-B*/}
         1031  +              {A = sqlite3PExpr(pParse, @B, X, 0);/*A-overwrites-B*/}
  1091   1032   expr(A) ::= BITNOT(B) expr(X).
  1092         -              {spanUnaryPrefix(&A,pParse,@B,&X,&B);/*A-overwrites-B*/}
  1093         -expr(A) ::= MINUS(B) expr(X). [BITNOT]
  1094         -              {spanUnaryPrefix(&A,pParse,TK_UMINUS,&X,&B);/*A-overwrites-B*/}
  1095         -expr(A) ::= PLUS(B) expr(X). [BITNOT]
  1096         -              {spanUnaryPrefix(&A,pParse,TK_UPLUS,&X,&B);/*A-overwrites-B*/}
         1033  +              {A = sqlite3PExpr(pParse, @B, X, 0);/*A-overwrites-B*/}
         1034  +expr(A) ::= MINUS expr(X). [BITNOT]
         1035  +              {A = sqlite3PExpr(pParse, TK_UMINUS, X, 0);}
         1036  +expr(A) ::= PLUS expr(X). [BITNOT]
         1037  +              {A = sqlite3PExpr(pParse, TK_UPLUS, X, 0);}
  1097   1038   
  1098   1039   %type between_op {int}
  1099   1040   between_op(A) ::= BETWEEN.     {A = 0;}
  1100   1041   between_op(A) ::= NOT BETWEEN. {A = 1;}
  1101   1042   expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
  1102         -  ExprList *pList = sqlite3ExprListAppend(pParse,0, X.pExpr);
  1103         -  pList = sqlite3ExprListAppend(pParse,pList, Y.pExpr);
  1104         -  A.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, A.pExpr, 0);
  1105         -  if( A.pExpr ){
  1106         -    A.pExpr->x.pList = pList;
         1043  +  ExprList *pList = sqlite3ExprListAppend(pParse,0, X);
         1044  +  pList = sqlite3ExprListAppend(pParse,pList, Y);
         1045  +  A = sqlite3PExpr(pParse, TK_BETWEEN, A, 0);
         1046  +  if( A ){
         1047  +    A->x.pList = pList;
  1107   1048     }else{
  1108   1049       sqlite3ExprListDelete(pParse->db, pList);
  1109   1050     } 
  1110         -  exprNot(pParse, N, &A);
  1111         -  A.zEnd = Y.zEnd;
         1051  +  if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
  1112   1052   }
  1113   1053   %ifndef SQLITE_OMIT_SUBQUERY
  1114   1054     %type in_op {int}
  1115   1055     in_op(A) ::= IN.      {A = 0;}
  1116   1056     in_op(A) ::= NOT IN.  {A = 1;}
  1117         -  expr(A) ::= expr(A) in_op(N) LP exprlist(Y) RP(E). [IN] {
         1057  +  expr(A) ::= expr(A) in_op(N) LP exprlist(Y) RP. [IN] {
  1118   1058       if( Y==0 ){
  1119   1059         /* Expressions of the form
  1120   1060         **
  1121   1061         **      expr1 IN ()
  1122   1062         **      expr1 NOT IN ()
  1123   1063         **
  1124   1064         ** simplify to constants 0 (false) and 1 (true), respectively,
  1125   1065         ** regardless of the value of expr1.
  1126   1066         */
  1127         -      sqlite3ExprDelete(pParse->db, A.pExpr);
  1128         -      A.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[N],1);
         1067  +      sqlite3ExprDelete(pParse->db, A);
         1068  +      A = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[N],1);
  1129   1069       }else if( Y->nExpr==1 ){
  1130   1070         /* Expressions of the form:
  1131   1071         **
  1132   1072         **      expr1 IN (?1)
  1133   1073         **      expr1 NOT IN (?2)
  1134   1074         **
  1135   1075         ** with exactly one value on the RHS can be simplified to something
................................................................................
  1148   1088         sqlite3ExprListDelete(pParse->db, Y);
  1149   1089         /* pRHS cannot be NULL because a malloc error would have been detected
  1150   1090         ** before now and control would have never reached this point */
  1151   1091         if( ALWAYS(pRHS) ){
  1152   1092           pRHS->flags &= ~EP_Collate;
  1153   1093           pRHS->flags |= EP_Generic;
  1154   1094         }
  1155         -      A.pExpr = sqlite3PExpr(pParse, N ? TK_NE : TK_EQ, A.pExpr, pRHS);
         1095  +      A = sqlite3PExpr(pParse, N ? TK_NE : TK_EQ, A, pRHS);
  1156   1096       }else{
  1157         -      A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0);
  1158         -      if( A.pExpr ){
  1159         -        A.pExpr->x.pList = Y;
  1160         -        sqlite3ExprSetHeightAndFlags(pParse, A.pExpr);
         1097  +      A = sqlite3PExpr(pParse, TK_IN, A, 0);
         1098  +      if( A ){
         1099  +        A->x.pList = Y;
         1100  +        sqlite3ExprSetHeightAndFlags(pParse, A);
  1161   1101         }else{
  1162   1102           sqlite3ExprListDelete(pParse->db, Y);
  1163   1103         }
  1164         -      exprNot(pParse, N, &A);
         1104  +      if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
  1165   1105       }
  1166         -    A.zEnd = &E.z[E.n];
  1167   1106     }
  1168         -  expr(A) ::= LP(B) select(X) RP(E). {
  1169         -    spanSet(&A,&B,&E); /*A-overwrites-B*/
  1170         -    A.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
  1171         -    sqlite3PExprAddSelect(pParse, A.pExpr, X);
         1107  +  expr(A) ::= LP select(X) RP. {
         1108  +    A = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
         1109  +    sqlite3PExprAddSelect(pParse, A, X);
  1172   1110     }
  1173         -  expr(A) ::= expr(A) in_op(N) LP select(Y) RP(E).  [IN] {
  1174         -    A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0);
  1175         -    sqlite3PExprAddSelect(pParse, A.pExpr, Y);
  1176         -    exprNot(pParse, N, &A);
  1177         -    A.zEnd = &E.z[E.n];
         1111  +  expr(A) ::= expr(A) in_op(N) LP select(Y) RP.  [IN] {
         1112  +    A = sqlite3PExpr(pParse, TK_IN, A, 0);
         1113  +    sqlite3PExprAddSelect(pParse, A, Y);
         1114  +    if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
  1178   1115     }
  1179   1116     expr(A) ::= expr(A) in_op(N) nm(Y) dbnm(Z) paren_exprlist(E). [IN] {
  1180   1117       SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&Y,&Z);
  1181   1118       Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
  1182   1119       if( E )  sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, E);
  1183         -    A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0);
  1184         -    sqlite3PExprAddSelect(pParse, A.pExpr, pSelect);
  1185         -    exprNot(pParse, N, &A);
  1186         -    A.zEnd = Z.z ? &Z.z[Z.n] : &Y.z[Y.n];
         1120  +    A = sqlite3PExpr(pParse, TK_IN, A, 0);
         1121  +    sqlite3PExprAddSelect(pParse, A, pSelect);
         1122  +    if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
  1187   1123     }
  1188         -  expr(A) ::= EXISTS(B) LP select(Y) RP(E). {
         1124  +  expr(A) ::= EXISTS LP select(Y) RP. {
  1189   1125       Expr *p;
  1190         -    spanSet(&A,&B,&E); /*A-overwrites-B*/
  1191         -    p = A.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
         1126  +    p = A = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
  1192   1127       sqlite3PExprAddSelect(pParse, p, Y);
  1193   1128     }
  1194   1129   %endif SQLITE_OMIT_SUBQUERY
  1195   1130   
  1196   1131   /* CASE expressions */
  1197         -expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
  1198         -  spanSet(&A,&C,&E);  /*A-overwrites-C*/
  1199         -  A.pExpr = sqlite3PExpr(pParse, TK_CASE, X, 0);
  1200         -  if( A.pExpr ){
  1201         -    A.pExpr->x.pList = Z ? sqlite3ExprListAppend(pParse,Y,Z) : Y;
  1202         -    sqlite3ExprSetHeightAndFlags(pParse, A.pExpr);
         1132  +expr(A) ::= CASE case_operand(X) case_exprlist(Y) case_else(Z) END. {
         1133  +  A = sqlite3PExpr(pParse, TK_CASE, X, 0);
         1134  +  if( A ){
         1135  +    A->x.pList = Z ? sqlite3ExprListAppend(pParse,Y,Z) : Y;
         1136  +    sqlite3ExprSetHeightAndFlags(pParse, A);
  1203   1137     }else{
  1204   1138       sqlite3ExprListDelete(pParse->db, Y);
  1205   1139       sqlite3ExprDelete(pParse->db, Z);
  1206   1140     }
  1207   1141   }
  1208   1142   %type case_exprlist {ExprList*}
  1209   1143   %destructor case_exprlist {sqlite3ExprListDelete(pParse->db, $$);}
  1210   1144   case_exprlist(A) ::= case_exprlist(A) WHEN expr(Y) THEN expr(Z). {
  1211         -  A = sqlite3ExprListAppend(pParse,A, Y.pExpr);
  1212         -  A = sqlite3ExprListAppend(pParse,A, Z.pExpr);
         1145  +  A = sqlite3ExprListAppend(pParse,A, Y);
         1146  +  A = sqlite3ExprListAppend(pParse,A, Z);
  1213   1147   }
  1214   1148   case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). {
  1215         -  A = sqlite3ExprListAppend(pParse,0, Y.pExpr);
  1216         -  A = sqlite3ExprListAppend(pParse,A, Z.pExpr);
         1149  +  A = sqlite3ExprListAppend(pParse,0, Y);
         1150  +  A = sqlite3ExprListAppend(pParse,A, Z);
  1217   1151   }
  1218   1152   %type case_else {Expr*}
  1219   1153   %destructor case_else {sqlite3ExprDelete(pParse->db, $$);}
  1220         -case_else(A) ::=  ELSE expr(X).         {A = X.pExpr;}
         1154  +case_else(A) ::=  ELSE expr(X).         {A = X;}
  1221   1155   case_else(A) ::=  .                     {A = 0;} 
  1222   1156   %type case_operand {Expr*}
  1223   1157   %destructor case_operand {sqlite3ExprDelete(pParse->db, $$);}
  1224         -case_operand(A) ::= expr(X).            {A = X.pExpr; /*A-overwrites-X*/} 
         1158  +case_operand(A) ::= expr(X).            {A = X; /*A-overwrites-X*/} 
  1225   1159   case_operand(A) ::= .                   {A = 0;} 
  1226   1160   
  1227   1161   %type exprlist {ExprList*}
  1228   1162   %destructor exprlist {sqlite3ExprListDelete(pParse->db, $$);}
  1229   1163   %type nexprlist {ExprList*}
  1230   1164   %destructor nexprlist {sqlite3ExprListDelete(pParse->db, $$);}
  1231   1165   
  1232   1166   exprlist(A) ::= nexprlist(A).
  1233   1167   exprlist(A) ::= .                            {A = 0;}
  1234   1168   nexprlist(A) ::= nexprlist(A) COMMA expr(Y).
  1235         -    {A = sqlite3ExprListAppend(pParse,A,Y.pExpr);}
         1169  +    {A = sqlite3ExprListAppend(pParse,A,Y);}
  1236   1170   nexprlist(A) ::= expr(Y).
  1237         -    {A = sqlite3ExprListAppend(pParse,0,Y.pExpr); /*A-overwrites-Y*/}
         1171  +    {A = sqlite3ExprListAppend(pParse,0,Y); /*A-overwrites-Y*/}
  1238   1172   
  1239   1173   %ifndef SQLITE_OMIT_SUBQUERY
  1240   1174   /* A paren_exprlist is an optional expression list contained inside
  1241   1175   ** of parenthesis */
  1242   1176   %type paren_exprlist {ExprList*}
  1243   1177   %destructor paren_exprlist {sqlite3ExprListDelete(pParse->db, $$);}
  1244   1178   paren_exprlist(A) ::= .   {A = 0;}
................................................................................
  1384   1318   
  1385   1319   foreach_clause ::= .
  1386   1320   foreach_clause ::= FOR EACH ROW.
  1387   1321   
  1388   1322   %type when_clause {Expr*}
  1389   1323   %destructor when_clause {sqlite3ExprDelete(pParse->db, $$);}
  1390   1324   when_clause(A) ::= .             { A = 0; }
  1391         -when_clause(A) ::= WHEN expr(X). { A = X.pExpr; }
         1325  +when_clause(A) ::= WHEN expr(X). { A = X; }
  1392   1326   
  1393   1327   %type trigger_cmd_list {TriggerStep*}
  1394   1328   %destructor trigger_cmd_list {sqlite3DeleteTriggerStep(pParse->db, $$);}
  1395   1329   trigger_cmd_list(A) ::= trigger_cmd_list(A) trigger_cmd(X) SEMI. {
  1396   1330     assert( A!=0 );
  1397   1331     A->pLast->pNext = X;
  1398   1332     A->pLast = X;
................................................................................
  1449   1383      {A = sqlite3TriggerDeleteStep(pParse->db, &X, Y);}
  1450   1384   
  1451   1385   // SELECT
  1452   1386   trigger_cmd(A) ::= select(X).
  1453   1387      {A = sqlite3TriggerSelectStep(pParse->db, X); /*A-overwrites-X*/}
  1454   1388   
  1455   1389   // The special RAISE expression that may occur in trigger programs
  1456         -expr(A) ::= RAISE(X) LP IGNORE RP(Y).  {
  1457         -  spanSet(&A,&X,&Y);  /*A-overwrites-X*/
  1458         -  A.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0); 
  1459         -  if( A.pExpr ){
  1460         -    A.pExpr->affinity = OE_Ignore;
         1390  +expr(A) ::= RAISE LP IGNORE RP.  {
         1391  +  A = sqlite3PExpr(pParse, TK_RAISE, 0, 0); 
         1392  +  if( A ){
         1393  +    A->affinity = OE_Ignore;
  1461   1394     }
  1462   1395   }
  1463         -expr(A) ::= RAISE(X) LP raisetype(T) COMMA nm(Z) RP(Y).  {
  1464         -  spanSet(&A,&X,&Y);  /*A-overwrites-X*/
  1465         -  A.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &Z, 1); 
  1466         -  if( A.pExpr ) {
  1467         -    A.pExpr->affinity = (char)T;
         1396  +expr(A) ::= RAISE LP raisetype(T) COMMA nm(Z) RP.  {
         1397  +  A = sqlite3ExprAlloc(pParse->db, TK_RAISE, &Z, 1); 
         1398  +  if( A ) {
         1399  +    A->affinity = (char)T;
  1468   1400     }
  1469   1401   }
  1470   1402   %endif  !SQLITE_OMIT_TRIGGER
  1471   1403   
  1472   1404   %type raisetype {int}
  1473   1405   raisetype(A) ::= ROLLBACK.  {A = OE_Rollback;}
  1474   1406   raisetype(A) ::= ABORT.     {A = OE_Abort;}
................................................................................
  1481   1413     sqlite3DropTrigger(pParse,X,NOERR);
  1482   1414   }
  1483   1415   %endif  !SQLITE_OMIT_TRIGGER
  1484   1416   
  1485   1417   //////////////////////// ATTACH DATABASE file AS name /////////////////////////
  1486   1418   %ifndef SQLITE_OMIT_ATTACH
  1487   1419   cmd ::= ATTACH database_kw_opt expr(F) AS expr(D) key_opt(K). {
  1488         -  sqlite3Attach(pParse, F.pExpr, D.pExpr, K);
         1420  +  sqlite3Attach(pParse, F, D, K);
  1489   1421   }
  1490   1422   cmd ::= DETACH database_kw_opt expr(D). {
  1491         -  sqlite3Detach(pParse, D.pExpr);
         1423  +  sqlite3Detach(pParse, D);
  1492   1424   }
  1493   1425   
  1494   1426   %type key_opt {Expr*}
  1495   1427   %destructor key_opt {sqlite3ExprDelete(pParse->db, $$);}
  1496   1428   key_opt(A) ::= .                     { A = 0; }
  1497         -key_opt(A) ::= KEY expr(X).          { A = X.pExpr; }
         1429  +key_opt(A) ::= KEY expr(X).          { A = X; }
  1498   1430   
  1499   1431   database_kw_opt ::= DATABASE.
  1500   1432   database_kw_opt ::= .
  1501   1433   %endif SQLITE_OMIT_ATTACH
  1502   1434   
  1503   1435   ////////////////////////// REINDEX collation //////////////////////////////////
  1504   1436   %ifndef SQLITE_OMIT_REINDEX

Changes to src/sqliteInt.h.

  1059   1059   typedef struct Bitvec Bitvec;
  1060   1060   typedef struct CollSeq CollSeq;
  1061   1061   typedef struct Column Column;
  1062   1062   typedef struct Db Db;
  1063   1063   typedef struct Schema Schema;
  1064   1064   typedef struct Expr Expr;
  1065   1065   typedef struct ExprList ExprList;
  1066         -typedef struct ExprSpan ExprSpan;
  1067   1066   typedef struct FKey FKey;
  1068   1067   typedef struct FuncDestructor FuncDestructor;
  1069   1068   typedef struct FuncDef FuncDef;
  1070   1069   typedef struct FuncDefHash FuncDefHash;
  1071   1070   typedef struct IdList IdList;
  1072   1071   typedef struct Index Index;
  1073   1072   typedef struct IndexSample IndexSample;
................................................................................
  2500   2499           u16 iAlias;           /* Index into Parse.aAlias[] for zName */
  2501   2500         } x;
  2502   2501         int iConstExprReg;      /* Register in which Expr value is cached */
  2503   2502       } u;
  2504   2503     } a[1];                  /* One slot for each expression in the list */
  2505   2504   };
  2506   2505   
  2507         -/*
  2508         -** An instance of this structure is used by the parser to record both
  2509         -** the parse tree for an expression and the span of input text for an
  2510         -** expression.
  2511         -*/
  2512         -struct ExprSpan {
  2513         -  Expr *pExpr;          /* The expression parse tree */
  2514         -  const char *zStart;   /* First character of input text */
  2515         -  const char *zEnd;     /* One character past the end of input text */
  2516         -};
  2517         -
  2518   2506   /*
  2519   2507   ** An instance of this structure can hold a simple list of identifiers,
  2520   2508   ** such as the list "a,b,c" in the following statements:
  2521   2509   **
  2522   2510   **      INSERT INTO t(a,b,c) VALUES ...;
  2523   2511   **      CREATE INDEX idx ON t(a,b,c);
  2524   2512   **      CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
................................................................................
  3659   3647   Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
  3660   3648   void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
  3661   3649   void sqlite3ExprDelete(sqlite3*, Expr*);
  3662   3650   ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
  3663   3651   ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
  3664   3652   void sqlite3ExprListSetSortOrder(ExprList*,int);
  3665   3653   void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
  3666         -void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
         3654  +void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
  3667   3655   void sqlite3ExprListDelete(sqlite3*, ExprList*);
  3668   3656   u32 sqlite3ExprListFlags(const ExprList*);
  3669   3657   int sqlite3Init(sqlite3*, char**);
  3670   3658   int sqlite3InitCallback(void*, int, char**, char**);
  3671   3659   void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
  3672   3660   #ifndef SQLITE_OMIT_VIRTUALTABLE
  3673   3661   Module *sqlite3PragmaVtabRegister(sqlite3*,const char *zName);
................................................................................
  3689   3677   #else
  3690   3678   # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */
  3691   3679   #endif
  3692   3680   void sqlite3AddColumn(Parse*,Token*,Token*);
  3693   3681   void sqlite3AddNotNull(Parse*, int);
  3694   3682   void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
  3695   3683   void sqlite3AddCheckConstraint(Parse*, Expr*);
  3696         -void sqlite3AddDefaultValue(Parse*,ExprSpan*);
         3684  +void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
  3697   3685   void sqlite3AddCollateType(Parse*, Token*);
  3698   3686   void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
  3699   3687   int sqlite3ParseUri(const char*,const char*,unsigned int*,
  3700   3688                       sqlite3_vfs**,char**,char **);
  3701   3689   Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
  3702   3690   
  3703   3691   #ifdef SQLITE_UNTESTABLE