Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/sqlite/src/tool/mkkeywordhash.c

Issue 2751253002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: also clang on Linux i386 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** Compile and run this standalone program in order to generate code that 2 ** Compile and run this standalone program in order to generate code that
3 ** implements a function that will translate alphabetic identifiers into 3 ** implements a function that will translate alphabetic identifiers into
4 ** parser token codes. 4 ** parser token codes.
5 */ 5 */
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <assert.h> 9 #include <assert.h>
10 10
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 { "VIRTUAL", "TK_VIRTUAL", VTAB }, 270 { "VIRTUAL", "TK_VIRTUAL", VTAB },
271 { "WITH", "TK_WITH", CTE }, 271 { "WITH", "TK_WITH", CTE },
272 { "WITHOUT", "TK_WITHOUT", ALWAYS }, 272 { "WITHOUT", "TK_WITHOUT", ALWAYS },
273 { "WHEN", "TK_WHEN", ALWAYS }, 273 { "WHEN", "TK_WHEN", ALWAYS },
274 { "WHERE", "TK_WHERE", ALWAYS }, 274 { "WHERE", "TK_WHERE", ALWAYS },
275 }; 275 };
276 276
277 /* Number of keywords */ 277 /* Number of keywords */
278 static int nKeyword = (sizeof(aKeywordTable)/sizeof(aKeywordTable[0])); 278 static int nKeyword = (sizeof(aKeywordTable)/sizeof(aKeywordTable[0]));
279 279
280 /* Map all alphabetic characters into the same case */ 280 /* Map all alphabetic characters into lower-case for hashing. This is
281 ** only valid for alphabetics. In particular it does not work for '_'
282 ** and so the hash cannot be on a keyword position that might be an '_'.
283 */
281 #define charMap(X) (0x20|(X)) 284 #define charMap(X) (0x20|(X))
282 285
283 /* 286 /*
284 ** Comparision function for two Keyword records 287 ** Comparision function for two Keyword records
285 */ 288 */
286 static int keywordCompare1(const void *a, const void *b){ 289 static int keywordCompare1(const void *a, const void *b){
287 const Keyword *pA = (Keyword*)a; 290 const Keyword *pA = (Keyword*)a;
288 const Keyword *pB = (Keyword*)b; 291 const Keyword *pB = (Keyword*)b;
289 int n = pA->len - pB->len; 292 int n = pA->len - pB->len;
290 if( n==0 ){ 293 if( n==0 ){
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 if( j==0 ) printf(" "); 561 if( j==0 ) printf(" ");
559 printf("%s,%*s", zToken, (int)(14-strlen(zToken)), ""); 562 printf("%s,%*s", zToken, (int)(14-strlen(zToken)), "");
560 j++; 563 j++;
561 if( j>=5 ){ 564 if( j>=5 ){
562 printf("\n"); 565 printf("\n");
563 j = 0; 566 j = 0;
564 } 567 }
565 } 568 }
566 printf("%s };\n", j==0 ? "" : "\n"); 569 printf("%s };\n", j==0 ? "" : "\n");
567 570
568 printf(" int h, i;\n"); 571 printf(" int i, j;\n");
572 printf(" const char *zKW;\n");
569 printf(" if( n>=2 ){\n"); 573 printf(" if( n>=2 ){\n");
570 printf(" h = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) %% %d;\n", 574 printf(" i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) %% %d;\n",
571 bestSize); 575 bestSize);
572 printf(" for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){\n"); 576 printf(" for(i=((int)aHash[i])-1; i>=0; i=((int)aNext[i])-1){\n");
573 printf(" if( aLen[i]==n &&" 577 printf(" if( aLen[i]!=n ) continue;\n");
574 " sqlite3StrNICmp(&zText[aOffset[i]],z,n)==0 ){\n"); 578 printf(" j = 0;\n");
579 printf(" zKW = &zText[aOffset[i]];\n");
580 printf("#ifdef SQLITE_ASCII\n");
581 printf(" while( j<n && (z[j]&~0x20)==zKW[j] ){ j++; }\n");
582 printf("#endif\n");
583 printf("#ifdef SQLITE_EBCDIC\n");
584 printf(" while( j<n && toupper(z[j])==zKW[j] ){ j++; }\n");
585 printf("#endif\n");
586 printf(" if( j<n ) continue;\n");
575 for(i=0; i<nKeyword; i++){ 587 for(i=0; i<nKeyword; i++){
576 printf(" testcase( i==%d ); /* %s */\n", 588 printf(" testcase( i==%d ); /* %s */\n",
577 i, aKeywordTable[i].zOrigName); 589 i, aKeywordTable[i].zOrigName);
578 } 590 }
579 printf(" *pType = aCode[i];\n"); 591 printf(" *pType = aCode[i];\n");
580 printf(" break;\n"); 592 printf(" break;\n");
581 printf(" }\n");
582 printf(" }\n"); 593 printf(" }\n");
583 printf(" }\n"); 594 printf(" }\n");
584 printf(" return n;\n"); 595 printf(" return n;\n");
585 printf("}\n"); 596 printf("}\n");
586 printf("int sqlite3KeywordCode(const unsigned char *z, int n){\n"); 597 printf("int sqlite3KeywordCode(const unsigned char *z, int n){\n");
587 printf(" int id = TK_ID;\n"); 598 printf(" int id = TK_ID;\n");
588 printf(" keywordCode((char*)z, n, &id);\n"); 599 printf(" keywordCode((char*)z, n, &id);\n");
589 printf(" return id;\n"); 600 printf(" return id;\n");
590 printf("}\n"); 601 printf("}\n");
591 printf("#define SQLITE_N_KEYWORD %d\n", nKeyword); 602 printf("#define SQLITE_N_KEYWORD %d\n", nKeyword);
592 603
593 return 0; 604 return 0;
594 } 605 }
OLDNEW
« no previous file with comments | « third_party/sqlite/src/tool/mkautoconfamal.sh ('k') | third_party/sqlite/src/tool/mkmsvcmin.tcl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698