| OLD | NEW |
| 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 |
| 11 /* | 11 /* |
| 12 ** A header comment placed at the beginning of generated code. | 12 ** A header comment placed at the beginning of generated code. |
| 13 */ | 13 */ |
| 14 static const char zHdr[] = | 14 static const char zHdr[] = |
| 15 "/***** This file contains automatically generated code ******\n" | 15 "/***** This file contains automatically generated code ******\n" |
| 16 "**\n" | 16 "**\n" |
| 17 "** The code in this file has been automatically generated by\n" | 17 "** The code in this file has been automatically generated by\n" |
| 18 "**\n" | 18 "**\n" |
| 19 "** $Header: /home/drh/sqlite/trans/cvs/sqlite/sqlite/tool/mkkeywordhash.c
,v 1.38 2009/06/09 14:27:41 drh Exp $\n" | 19 "** sqlite/tool/mkkeywordhash.c\n" |
| 20 "**\n" | 20 "**\n" |
| 21 "** The code in this file implements a function that determines whether\n" | 21 "** The code in this file implements a function that determines whether\n" |
| 22 "** or not a given identifier is really an SQL keyword. The same thing\n" | 22 "** or not a given identifier is really an SQL keyword. The same thing\n" |
| 23 "** might be implemented more directly using a hand-written hash table.\n" | 23 "** might be implemented more directly using a hand-written hash table.\n" |
| 24 "** But by using this automatically generated code, the size of the code\n" | 24 "** But by using this automatically generated code, the size of the code\n" |
| 25 "** is substantially reduced. This is important for embedded applications\n" | 25 "** is substantially reduced. This is important for embedded applications\n" |
| 26 "** on platforms with limited memory.\n" | 26 "** on platforms with limited memory.\n" |
| 27 "*/\n" | 27 "*/\n" |
| 28 ; | 28 ; |
| 29 | 29 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 # define AUTOVACUUM 0 | 137 # define AUTOVACUUM 0 |
| 138 #else | 138 #else |
| 139 # define AUTOVACUUM 0x00020000 | 139 # define AUTOVACUUM 0x00020000 |
| 140 #endif | 140 #endif |
| 141 | 141 |
| 142 /* | 142 /* |
| 143 ** These are the keywords | 143 ** These are the keywords |
| 144 */ | 144 */ |
| 145 static Keyword aKeywordTable[] = { | 145 static Keyword aKeywordTable[] = { |
| 146 { "ABORT", "TK_ABORT", CONFLICT|TRIGGER }, | 146 { "ABORT", "TK_ABORT", CONFLICT|TRIGGER }, |
| 147 { "ACTION", "TK_ACTION", FKEY }, |
| 147 { "ADD", "TK_ADD", ALTER }, | 148 { "ADD", "TK_ADD", ALTER }, |
| 148 { "AFTER", "TK_AFTER", TRIGGER }, | 149 { "AFTER", "TK_AFTER", TRIGGER }, |
| 149 { "ALL", "TK_ALL", ALWAYS }, | 150 { "ALL", "TK_ALL", ALWAYS }, |
| 150 { "ALTER", "TK_ALTER", ALTER }, | 151 { "ALTER", "TK_ALTER", ALTER }, |
| 151 { "ANALYZE", "TK_ANALYZE", ANALYZE }, | 152 { "ANALYZE", "TK_ANALYZE", ANALYZE }, |
| 152 { "AND", "TK_AND", ALWAYS }, | 153 { "AND", "TK_AND", ALWAYS }, |
| 153 { "AS", "TK_AS", ALWAYS }, | 154 { "AS", "TK_AS", ALWAYS }, |
| 154 { "ASC", "TK_ASC", ALWAYS }, | 155 { "ASC", "TK_ASC", ALWAYS }, |
| 155 { "ATTACH", "TK_ATTACH", ATTACH }, | 156 { "ATTACH", "TK_ATTACH", ATTACH }, |
| 156 { "AUTOINCREMENT", "TK_AUTOINCR", AUTOINCR }, | 157 { "AUTOINCREMENT", "TK_AUTOINCR", AUTOINCR }, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 { "INTO", "TK_INTO", ALWAYS }, | 212 { "INTO", "TK_INTO", ALWAYS }, |
| 212 { "IS", "TK_IS", ALWAYS }, | 213 { "IS", "TK_IS", ALWAYS }, |
| 213 { "ISNULL", "TK_ISNULL", ALWAYS }, | 214 { "ISNULL", "TK_ISNULL", ALWAYS }, |
| 214 { "JOIN", "TK_JOIN", ALWAYS }, | 215 { "JOIN", "TK_JOIN", ALWAYS }, |
| 215 { "KEY", "TK_KEY", ALWAYS }, | 216 { "KEY", "TK_KEY", ALWAYS }, |
| 216 { "LEFT", "TK_JOIN_KW", ALWAYS }, | 217 { "LEFT", "TK_JOIN_KW", ALWAYS }, |
| 217 { "LIKE", "TK_LIKE_KW", ALWAYS }, | 218 { "LIKE", "TK_LIKE_KW", ALWAYS }, |
| 218 { "LIMIT", "TK_LIMIT", ALWAYS }, | 219 { "LIMIT", "TK_LIMIT", ALWAYS }, |
| 219 { "MATCH", "TK_MATCH", ALWAYS }, | 220 { "MATCH", "TK_MATCH", ALWAYS }, |
| 220 { "NATURAL", "TK_JOIN_KW", ALWAYS }, | 221 { "NATURAL", "TK_JOIN_KW", ALWAYS }, |
| 222 { "NO", "TK_NO", FKEY }, |
| 221 { "NOT", "TK_NOT", ALWAYS }, | 223 { "NOT", "TK_NOT", ALWAYS }, |
| 222 { "NOTNULL", "TK_NOTNULL", ALWAYS }, | 224 { "NOTNULL", "TK_NOTNULL", ALWAYS }, |
| 223 { "NULL", "TK_NULL", ALWAYS }, | 225 { "NULL", "TK_NULL", ALWAYS }, |
| 224 { "OF", "TK_OF", ALWAYS }, | 226 { "OF", "TK_OF", ALWAYS }, |
| 225 { "OFFSET", "TK_OFFSET", ALWAYS }, | 227 { "OFFSET", "TK_OFFSET", ALWAYS }, |
| 226 { "ON", "TK_ON", ALWAYS }, | 228 { "ON", "TK_ON", ALWAYS }, |
| 227 { "OR", "TK_OR", ALWAYS }, | 229 { "OR", "TK_OR", ALWAYS }, |
| 228 { "ORDER", "TK_ORDER", ALWAYS }, | 230 { "ORDER", "TK_ORDER", ALWAYS }, |
| 229 { "OUTER", "TK_JOIN_KW", ALWAYS }, | 231 { "OUTER", "TK_JOIN_KW", ALWAYS }, |
| 230 { "PLAN", "TK_PLAN", EXPLAIN }, | 232 { "PLAN", "TK_PLAN", EXPLAIN }, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 /* | 294 /* |
| 293 ** Comparision function for two Keyword records | 295 ** Comparision function for two Keyword records |
| 294 */ | 296 */ |
| 295 static int keywordCompare1(const void *a, const void *b){ | 297 static int keywordCompare1(const void *a, const void *b){ |
| 296 const Keyword *pA = (Keyword*)a; | 298 const Keyword *pA = (Keyword*)a; |
| 297 const Keyword *pB = (Keyword*)b; | 299 const Keyword *pB = (Keyword*)b; |
| 298 int n = pA->len - pB->len; | 300 int n = pA->len - pB->len; |
| 299 if( n==0 ){ | 301 if( n==0 ){ |
| 300 n = strcmp(pA->zName, pB->zName); | 302 n = strcmp(pA->zName, pB->zName); |
| 301 } | 303 } |
| 304 assert( n!=0 ); |
| 302 return n; | 305 return n; |
| 303 } | 306 } |
| 304 static int keywordCompare2(const void *a, const void *b){ | 307 static int keywordCompare2(const void *a, const void *b){ |
| 305 const Keyword *pA = (Keyword*)a; | 308 const Keyword *pA = (Keyword*)a; |
| 306 const Keyword *pB = (Keyword*)b; | 309 const Keyword *pB = (Keyword*)b; |
| 307 int n = pB->longestSuffix - pA->longestSuffix; | 310 int n = pB->longestSuffix - pA->longestSuffix; |
| 308 if( n==0 ){ | 311 if( n==0 ){ |
| 309 n = strcmp(pA->zName, pB->zName); | 312 n = strcmp(pA->zName, pB->zName); |
| 310 } | 313 } |
| 314 assert( n!=0 ); |
| 311 return n; | 315 return n; |
| 312 } | 316 } |
| 313 static int keywordCompare3(const void *a, const void *b){ | 317 static int keywordCompare3(const void *a, const void *b){ |
| 314 const Keyword *pA = (Keyword*)a; | 318 const Keyword *pA = (Keyword*)a; |
| 315 const Keyword *pB = (Keyword*)b; | 319 const Keyword *pB = (Keyword*)b; |
| 316 int n = pA->offset - pB->offset; | 320 int n = pA->offset - pB->offset; |
| 321 if( n==0 ) n = pB->id - pA->id; |
| 322 assert( n!=0 ); |
| 317 return n; | 323 return n; |
| 318 } | 324 } |
| 319 | 325 |
| 320 /* | 326 /* |
| 321 ** Return a KeywordTable entry with the given id | 327 ** Return a KeywordTable entry with the given id |
| 322 */ | 328 */ |
| 323 static Keyword *findById(int id){ | 329 static Keyword *findById(int id){ |
| 324 int i; | 330 int i; |
| 325 for(i=0; i<nKeyword; i++){ | 331 for(i=0; i<nKeyword; i++){ |
| 326 if( aKeywordTable[i].id==id ) break; | 332 if( aKeywordTable[i].id==id ) break; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 i, aKeywordTable[i].zOrigName); | 589 i, aKeywordTable[i].zOrigName); |
| 584 } | 590 } |
| 585 printf(" return aCode[i];\n"); | 591 printf(" return aCode[i];\n"); |
| 586 printf(" }\n"); | 592 printf(" }\n"); |
| 587 printf(" }\n"); | 593 printf(" }\n"); |
| 588 printf(" return TK_ID;\n"); | 594 printf(" return TK_ID;\n"); |
| 589 printf("}\n"); | 595 printf("}\n"); |
| 590 printf("int sqlite3KeywordCode(const unsigned char *z, int n){\n"); | 596 printf("int sqlite3KeywordCode(const unsigned char *z, int n){\n"); |
| 591 printf(" return keywordCode((char*)z, n);\n"); | 597 printf(" return keywordCode((char*)z, n);\n"); |
| 592 printf("}\n"); | 598 printf("}\n"); |
| 599 printf("#define SQLITE_N_KEYWORD %d\n", nKeyword); |
| 593 | 600 |
| 594 return 0; | 601 return 0; |
| 595 } | 602 } |
| OLD | NEW |