/ Check-in [a7d0817c]
Login

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

Overview
Comment:Modify mkkeywordhash.c so that it puts the original text of each token in a comment beside the "testcase()" macros. (CVS 6736)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a7d0817c176832a88788cc973c0aae8dcab57364
User & Date: drh 2009-06-09 14:27:41
Context
2009-06-09
15:25
Change savepoint4.test to limit database growth. Otherwise the test can take a very long time to run, depending on the prng. (CVS 6737) check-in: ed1d4f47 user: danielk1977 tags: trunk
14:27
Modify mkkeywordhash.c so that it puts the original text of each token in a comment beside the "testcase()" macros. (CVS 6736) check-in: a7d0817c user: drh tags: trunk
13:42
Enable cell overflow checking in sqlite3BtreeInitPage() using the compile-time option SQLITE_ENABLE_OVERSIZE_CELL_CHECK. Change the tests so that they recognize different error messages depending on the setting of this macro. (CVS 6735) check-in: 56bff6eb user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/mkkeywordhash.c.

     2      2   ** Compile and run this standalone program in order to generate code that
     3      3   ** implements a function that will translate alphabetic identifiers into
     4      4   ** parser token codes.
     5      5   */
     6      6   #include <stdio.h>
     7      7   #include <string.h>
     8      8   #include <stdlib.h>
            9  +#include <assert.h>
     9     10   
    10     11   /*
    11     12   ** A header comment placed at the beginning of generated code.
    12     13   */
    13     14   static const char zHdr[] = 
    14     15     "/***** This file contains automatically generated code ******\n"
    15     16     "**\n"
    16     17     "** The code in this file has been automatically generated by\n"
    17     18     "**\n"
    18         -  "**     $Header: /home/drh/sqlite/trans/cvs/sqlite/sqlite/tool/mkkeywordhash.c,v 1.37 2009/02/01 00:00:46 drh Exp $\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     20     "**\n"
    20     21     "** The code in this file implements a function that determines whether\n"
    21     22     "** or not a given identifier is really an SQL keyword.  The same thing\n"
    22     23     "** might be implemented more directly using a hand-written hash table.\n"
    23     24     "** But by using this automatically generated code, the size of the code\n"
    24     25     "** is substantially reduced.  This is important for embedded applications\n"
    25     26     "** on platforms with limited memory.\n"
................................................................................
    40     41     int offset;          /* Offset to start of name string */
    41     42     int len;             /* Length of this keyword, not counting final \000 */
    42     43     int prefix;          /* Number of characters in prefix */
    43     44     int longestSuffix;   /* Longest suffix that is a prefix on another word */
    44     45     int iNext;           /* Index in aKeywordTable[] of next with same hash */
    45     46     int substrId;        /* Id to another keyword this keyword is embedded in */
    46     47     int substrOffset;    /* Offset into substrId for start of this keyword */
           48  +  char zOrigName[20];  /* Original keyword name before processing */
    47     49   };
    48     50   
    49     51   /*
    50     52   ** Define masks used to determine which keywords are allowed
    51     53   */
    52     54   #ifdef SQLITE_OMIT_ALTERTABLE
    53     55   #  define ALTER      0
................................................................................
   349    351     }
   350    352     nKeyword = j;
   351    353   
   352    354     /* Fill in the lengths of strings and hashes for all entries. */
   353    355     for(i=0; i<nKeyword; i++){
   354    356       Keyword *p = &aKeywordTable[i];
   355    357       p->len = strlen(p->zName);
          358  +    assert( p->len<sizeof(p->zOrigName) );
          359  +    strcpy(p->zOrigName, p->zName);
   356    360       totalLen += p->len;
   357    361       p->hash = (UpperToLower[(int)p->zName[0]]*4) ^
   358    362                 (UpperToLower[(int)p->zName[p->len-1]]*3) ^ p->len;
   359    363       p->id = i+1;
   360    364     }
   361    365   
   362    366     /* Sort the table from shortest to longest keyword */
................................................................................
   572    576            "      (charMap(z[n-1])*3) ^\n"
   573    577            "      n) %% %d;\n", bestSize);
   574    578     printf("  for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){\n");
   575    579     printf("    if( aLen[i]==n &&"
   576    580                      " sqlite3StrNICmp(&zText[aOffset[i]],z,n)==0 ){\n");
   577    581     for(i=0; i<nKeyword; i++){
   578    582       printf("      testcase( i==%d ); /* %s */\n",
   579         -           i, aKeywordTable[i].zTokenType);
          583  +           i, aKeywordTable[i].zOrigName);
   580    584     }
   581    585     printf("      return aCode[i];\n");
   582    586     printf("    }\n");
   583    587     printf("  }\n");
   584    588     printf("  return TK_ID;\n");
   585    589     printf("}\n");
   586    590     printf("int sqlite3KeywordCode(const unsigned char *z, int n){\n");
   587    591     printf("  return keywordCode((char*)z, n);\n");
   588    592     printf("}\n");
   589    593   
   590    594     return 0;
   591    595   }