MXS-3404 Extend sqlite3 op-size from u8 to u16

To make it possible to have more tokens than 255.

Parsers operators (i.e. tokens) is one thing and opcodes
for the virtual machine of sqlite3 is another. Unfortunately
they are not completely separate, but some of the opcodes
in <build-directory>/opcodes.h are the same as the tokens in
<build-directory>/parse.h. And while the parser tokens are now
16-bit, the VM opcodes are 8-bit. However, this is probably not
a problem even if some of the parser tokens that are duplicated
in the opcodes are > 256 as we only use sqlite3 for parsing and
not for executing anything (on the sqlite3 VM).
This commit is contained in:
Johan Wikman 2021-02-15 10:30:49 +02:00
parent 5f42ee88c9
commit 797d7812cc
8 changed files with 21 additions and 21 deletions

View File

@ -464,7 +464,7 @@ Expr *sqlite3ExprAlloc(
pNew = sqlite3DbMallocRawNN(db, sizeof(Expr)+nExtra);
if( pNew ){
memset(pNew, 0, sizeof(Expr));
pNew->op = (u8)op;
pNew->op = (u16)op;
pNew->iAgg = -1;
if( pToken ){
if( nExtra==0 ){
@ -1544,7 +1544,7 @@ int sqlite3ExprIsInteger(Expr *p, int *pValue){
** TRUE.
*/
int sqlite3ExprCanBeNull(const Expr *p){
u8 op;
u16 op;
while( p->op==TK_UPLUS || p->op==TK_UMINUS ){ p = p->pLeft; }
op = p->op;
if( op==TK_REGISTER ) op = p->op2;
@ -1574,7 +1574,7 @@ int sqlite3ExprCanBeNull(const Expr *p){
** answer.
*/
int sqlite3ExprNeedsNoAffinityChange(const Expr *p, char aff){
u8 op;
u16 op;
if( aff==SQLITE_AFF_BLOB ) return 1;
while( p->op==TK_UPLUS || p->op==TK_UMINUS ){ p = p->pLeft; }
op = p->op;

View File

@ -1073,7 +1073,7 @@ selectnowith(A) ::= selectnowith(X) multiselect_op(Y) oneselect(Z). {
#endif
}
if( pRhs ){
pRhs->op = (u8)Y;
pRhs->op = (u16)Y;
pRhs->pPrior = pLhs;
if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
pRhs->selFlags &= ~SF_MultiValue;
@ -1327,7 +1327,7 @@ from(A) ::= FROM seltablist(X). {
//
stl_prefix(A) ::= seltablist(X) joinop(Y). {
A = X;
if( ALWAYS(A && A->nSrc>0) ) A->a[A->nSrc-1].fg.jointype = (u8)Y;
if( ALWAYS(A && A->nSrc>0) ) A->a[A->nSrc-1].fg.jointype = (u16)Y;
}
stl_prefix(A) ::= . {A = 0;}
seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I)
@ -2233,7 +2233,7 @@ expr(A) ::= expr(X) NOT NULL(E). {spanUnaryPostfix(&A,pParse,TK_NOTNULL,&X,&E);}
static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){
sqlite3 *db = pParse->db;
if( pA && pY && pY->op==TK_NULL ){
pA->op = (u8)op;
pA->op = (u16)op;
sqlite3ExprDelete(db, pA->pRight);
pA->pRight = 0;
}

View File

@ -2136,7 +2136,7 @@ typedef int ynVar;
** allocated, regardless of whether or not EP_Reduced is set.
*/
struct Expr {
u8 op; /* Operation performed by this node */
u16 op; /* Operation performed by this node */
char affinity; /* The affinity of the column or 0 if not a column */
u32 flags; /* Various flags. EP_* See below */
union {
@ -2172,7 +2172,7 @@ struct Expr {
** TK_VARIABLE: variable number (always >= 1). */
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
u8 op2; /* TK_REGISTER: original value of Expr.op
u16 op2; /* TK_REGISTER: original value of Expr.op
** TK_COLUMN: the value of p5 for OP_Column
** TK_AGG_FUNCTION: nesting depth */
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
@ -2499,7 +2499,7 @@ struct NameContext {
*/
struct Select {
ExprList *pEList; /* The fields of the result */
u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
u16 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
u16 selFlags; /* Various SF_* values */
int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
#if SELECTTRACE_ENABLED
@ -2887,7 +2887,7 @@ struct AuthContext {
struct Trigger {
char *zName; /* The name of the trigger */
char *table; /* The table or view to which the trigger applies */
u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
u16 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
Expr *pWhen; /* The WHEN clause of the expression (may be NULL) */
IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
@ -2947,7 +2947,7 @@ struct Trigger {
*
*/
struct TriggerStep {
u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
u16 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
u8 orconf; /* OE_Rollback etc. */
Trigger *pTrig; /* The trigger that this step is a part of */
Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */

View File

@ -366,7 +366,7 @@ TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
*/
static TriggerStep *triggerStepAllocate(
sqlite3 *db, /* Database connection */
u8 op, /* Trigger opcode */
u16 op, /* Trigger opcode */
Token *pName /* The target name */
){
TriggerStep *pTriggerStep;

View File

@ -74,7 +74,7 @@ struct WhereLevel {
int addrLikeRep; /* LIKE range processing address */
#endif
u8 iFrom; /* Which entry in the FROM clause */
u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
u16 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
int p1, p2; /* Operands of the opcode used to ends the loop */
union { /* Information that depends on pWLoop->wsFlags */
struct {
@ -314,7 +314,7 @@ struct WhereScan {
struct WhereClause {
WhereInfo *pWInfo; /* WHERE clause processing context */
WhereClause *pOuter; /* Outer conjunction */
u8 op; /* Split operator. TK_AND or TK_OR */
u16 op; /* Split operator. TK_AND or TK_OR */
int nTerm; /* Number of terms */
int nSlot; /* Number of entries in a[] */
WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */
@ -476,7 +476,7 @@ Bitmask sqlite3WhereCodeOneLoopStart(
/* whereexpr.c: */
void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
void sqlite3WhereClauseClear(WhereClause*);
void sqlite3WhereSplit(WhereClause*,Expr*,u8);
void sqlite3WhereSplit(WhereClause*,Expr*,u16);
Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);

View File

@ -999,7 +999,7 @@ static void exprAnalyze(
else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){
ExprList *pList = pExpr->x.pList;
int i;
static const u8 ops[] = {TK_GE, TK_LE};
static const u16 ops[] = {TK_GE, TK_LE};
assert( pList!=0 );
assert( pList->nExpr==2 );
for(i=0; i<2; i++){
@ -1216,7 +1216,7 @@ static void exprAnalyze(
** the WhereClause.a[] array. The slot[] array grows as needed to contain
** all terms of the WHERE clause.
*/
void sqlite3WhereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
void sqlite3WhereSplit(WhereClause *pWC, Expr *pExpr, u16 op){
Expr *pE2 = sqlite3ExprSkipCollate(pExpr);
pWC->op = op;
if( pE2==0 ) return;

View File

@ -52,12 +52,12 @@ foreach x $extras {
# 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/* The token codes above must all fit in 12 bits */"
puts [format "#define %-20s %-6s" TKFLG_MASK 0xfff]
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 */}
TKFLG_DONTFOLD 0x1000 {/* Omit constant folding optimizations */}
} {
puts [format "#define %-20s %-6s %s" $fg $val $comment]
}

View File

@ -804,7 +804,7 @@ int main(int argc, char **argv){
}
printf("%s };\n", j==0 ? "" : "\n");
printf(" static const unsigned char aCode[%d] = {\n", nKeyword);
printf(" static const unsigned short aCode[%d] = {\n", nKeyword);
for(i=j=0; i<nKeyword; i++){
char *zToken = aKeywordTable[i].zTokenType;
if( j==0 ) printf(" ");