Index: Makefile.in ================================================================== --- Makefile.in +++ Makefile.in @@ -1049,16 +1049,13 @@ # Rules to build parse.c and parse.h - the outputs of lemon. # parse.h: parse.c -parse.c: $(TOP)/src/parse.y lemon$(BEXE) $(TOP)/tool/addopcodes.tcl +parse.c: $(TOP)/src/parse.y lemon$(BEXE) cp $(TOP)/src/parse.y . - rm -f parse.h ./lemon$(BEXE) $(OPT_FEATURE_FLAGS) $(OPTS) parse.y - mv parse.h parse.h.temp - $(TCLSH_CMD) $(TOP)/tool/addopcodes.tcl parse.h.temp >parse.h sqlite3.h: $(TOP)/src/sqlite.h.in $(TOP)/manifest mksourceid$(BEXE) $(TOP)/VERSION $(TCLSH_CMD) $(TOP)/tool/mksqlite3h.tcl $(TOP) >sqlite3.h keywordhash.h: $(TOP)/tool/mkkeywordhash.c Index: Makefile.msc ================================================================== --- Makefile.msc +++ Makefile.msc @@ -2137,16 +2137,14 @@ # Rules to build parse.c and parse.h - the outputs of lemon. # parse.h: parse.c -parse.c: $(TOP)\src\parse.y lemon.exe $(TOP)\tool\addopcodes.tcl +parse.c: $(TOP)\src\parse.y lemon.exe del /Q parse.y parse.h parse.h.temp 2>NUL copy $(TOP)\src\parse.y . .\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) $(OPTS) parse.y - move parse.h parse.h.temp - $(TCLSH_CMD) $(TOP)\tool\addopcodes.tcl parse.h.temp > parse.h $(SQLITE3H): $(TOP)\src\sqlite.h.in $(TOP)\manifest mksourceid.exe $(TOP)\VERSION $(TCLSH_CMD) $(TOP)\tool\mksqlite3h.tcl $(TOP:\=/) > $(SQLITE3H) $(MKSQLITE3H_ARGS) sqlite3ext.h: .target_source Index: main.mk ================================================================== --- main.mk +++ main.mk @@ -714,16 +714,13 @@ # Rules to build parse.c and parse.h - the outputs of lemon. # parse.h: parse.c -parse.c: $(TOP)/src/parse.y lemon $(TOP)/tool/addopcodes.tcl +parse.c: $(TOP)/src/parse.y lemon cp $(TOP)/src/parse.y . - rm -f parse.h ./lemon -s $(OPTS) parse.y - mv parse.h parse.h.temp - tclsh $(TOP)/tool/addopcodes.tcl parse.h.temp >parse.h sqlite3.h: $(TOP)/src/sqlite.h.in $(TOP)/manifest mksourceid $(TOP)/VERSION $(TOP)/ext/rtree/sqlite3rtree.h tclsh $(TOP)/tool/mksqlite3h.tcl $(TOP) >sqlite3.h keywordhash.h: $(TOP)/tool/mkkeywordhash.c Index: src/expr.c ================================================================== --- src/expr.c +++ src/expr.c @@ -855,11 +855,11 @@ p = sqlite3ExprAnd(pParse->db, pLeft, pRight); }else{ p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)); if( p ){ memset(p, 0, sizeof(Expr)); - p->op = op & TKFLG_MASK; + p->op = op & 0xff; p->iAgg = -1; } sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight); } if( p ) { Index: src/parse.y ================================================================== --- src/parse.y +++ src/parse.y @@ -1742,5 +1742,45 @@ } filter_opt(A) ::= . { A = 0; } filter_opt(A) ::= FILTER LP WHERE expr(X) RP. { A = X; } %endif /* SQLITE_OMIT_WINDOWFUNC */ + +/* +** The code generator needs some extra TK_ token values for tokens that +** are synthesized and do not actually appear in the grammar: +*/ +%token + TRUEFALSE /* True or false keyword */ + ISNOT /* Combination of IS and NOT */ + FUNCTION /* A function invocation */ + COLUMN /* Reference to a table column */ + AGG_FUNCTION /* An aggregate function */ + AGG_COLUMN /* An aggregated column */ + UMINUS /* Unary minus */ + UPLUS /* Unary plus */ + TRUTH /* IS TRUE or IS FALSE or IS NOT TRUE or IS NOT FALSE */ + REGISTER /* Reference to a VDBE register */ + VECTOR /* Vector */ + SELECT_COLUMN /* Choose a single column from a multi-column SELECT */ + IF_NULL_ROW /* the if-null-row operator */ + ASTERISK /* The "*" in count(*) and similar */ + SPAN /* The span operator */ +. +/* There must be no more than 255 tokens defined above. If this grammar +** is extended with new rules and tokens, they must either be so few in +** number that TK_SPAN is no more than 255, or else the new tokens must +** appear after this line. +*/ +%include { +#if TK_SPAN>255 +# error too many tokens in the grammar +#endif +} + +/* +** The TK_SPACE and TK_ILLEGAL tokens must be the last two tokens. The +** parser depends on this. Those tokens are not used in any grammar rule. +** They are only used by the tokenizer. Declare them last so that they +** are guaranteed to be the last two tokens +*/ +%token SPACE ILLEGAL. Index: src/wherecode.c ================================================================== --- src/wherecode.c +++ src/wherecode.c @@ -1965,11 +1965,16 @@ testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); pExpr = sqlite3ExprDup(db, pExpr, 0); pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr); } if( pAndExpr ){ - pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr); + /* The extra 0x10000 bit on the opcode is masked off and does not + ** become part of the new Expr.op. However, it does make the + ** op==TK_AND comparison inside of sqlite3PExpr() false, and this + ** prevents sqlite3PExpr() from implementing AND short-circuit + ** optimization, which we do not want here. */ + pAndExpr = sqlite3PExpr(pParse, TK_AND|0x10000, 0, pAndExpr); } } /* Run a separate WHERE clause for each term of the OR clause. After ** eliminating duplicates from other WHERE clauses, the action for each DELETED tool/addopcodes.tcl Index: tool/addopcodes.tcl ================================================================== --- tool/addopcodes.tcl +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/tclsh -# -# This script appends additional token codes to the end of the -# parse.h file that lemon generates. These extra token codes are -# not used by the parser. But they are used by the tokenizer and/or -# the code generator. -# -# -set in [open [lindex $argv 0] rb] -set max 0 -while {![eof $in]} { - set line [gets $in] - if {[regexp {^#define TK_} $line]} { - puts $line - set x [lindex $line 2] - if {$x>$max} {set max $x} - } -} -close $in - -# The following are the extra token codes to be added. SPACE and -# ILLEGAL *must* be the last two token codes and they must be in that order. -# -set extras { - TRUEFALSE - ISNOT - FUNCTION - COLUMN - AGG_FUNCTION - AGG_COLUMN - UMINUS - UPLUS - TRUTH - REGISTER - VECTOR - SELECT_COLUMN - IF_NULL_ROW - ASTERISK - SPAN - END_OF_FILE - UNCLOSED_STRING - SPACE - ILLEGAL -} -if {[lrange $extras end-1 end]!="SPACE ILLEGAL"} { - error "SPACE and ILLEGAL must be the last two token codes and they\ - must be in that order" -} -foreach x $extras { - incr max - puts [format "#define TK_%-29s %4d" $x $max] -} - -# Some additional #defines related to token codes. -# -puts "\n/* The token codes above must all fit in 8 bits */" -puts [format "#define %-20s %-6s" TKFLG_MASK 0xff] -puts "\n/* Flags that can be added to a token code when it is not" -puts "** being stored in a u8: */" -foreach {fg val comment} { - TKFLG_DONTFOLD 0x100 {/* Omit constant folding optimizations */} -} { - puts [format "#define %-20s %-6s %s" $fg $val $comment] -}