From a0c3927510c8c92925f602c999d75c3e86c165b0 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 6 Jul 2017 16:33:14 +0000 Subject: [PATCH] Change the (machine-generated) keywordhash.h file to increase the scope of the tables used for keyword matching, so that the tables are accessible to functions other then keywordCode(). FossilOrigin-Name: c5ed5ebdf660501fde7cc8aefaaaeae2a68e5899a64ac93f26684842a235281d --- manifest | 12 +++--- manifest.uuid | 2 +- tool/mkkeywordhash.c | 90 ++++++++++++++++++++++++-------------------- 3 files changed, 57 insertions(+), 47 deletions(-) diff --git a/manifest b/manifest index b35c0c6bbe..a6685636f4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\scompact\simplementation\sof\sthe\stypeof()\sSQL\sfunction. -D 2017-07-06T13:51:50.091 +C Change\sthe\s(machine-generated)\skeywordhash.h\sfile\sto\sincrease\sthe\sscope\sof\sthe\ntables\sused\sfor\skeyword\smatching,\sso\sthat\sthe\stables\sare\saccessible\sto\nfunctions\sother\sthen\skeywordCode(). +D 2017-07-06T16:33:14.765 F Makefile.in 081e48dfe7f995d57ce1a88ddf4d2917b4349158648a6cd45b42beae30de3a12 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 4ebb1d257cac7fb1bcb4ba59278416d410ff1c4bf59447a9c37a415f3516056a @@ -1561,7 +1561,7 @@ F tool/logest.c 11346aa019e2e77a00902aa7d0cabd27bd2e8cca F tool/max-limits.c cbb635fbb37ae4d05f240bfb5b5270bb63c54439 F tool/mkautoconfamal.sh e855df211ecbcc7131dee817110ff386cfb112f7 F tool/mkctimec.tcl dd183b73ae1c28249669741c250525f0407e579a70482371668fd5f130d9feb3 -F tool/mkkeywordhash.c f7f3b342211ac6a14258b9726d5b97cf4f548f22 +F tool/mkkeywordhash.c 2e852ac0dfdc5af18886dc1ce7e9676d11714ae3df0a282dc7d90b3a0fe2033c F tool/mkmsvcmin.tcl cbd93f1cfa3a0a9ae56fc958510aa3fc3ac65e29cb111716199e3d0e66eefaa4 F tool/mkopcodec.tcl d1b6362bd3aa80d5520d4d6f3765badf01f6c43c F tool/mkopcodeh.tcl a01d2c1d8a6205b03fc635adf3735b4c523befd3 @@ -1628,7 +1628,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 06269257647db51fbc9f8cda88abac5db28b6f917a509768af7686dfa2b94511 -R 8d88458ca1178062a686c7622fab862c +P efb4aab0caa4145732a5438cc2a193bc12c455b4007220564d240e75900ea8ad +R 77ecc187246c1c337a58790c9818d2e8 U drh -Z 16d02781d00f9c4bbd9708369c77eae3 +Z a448086e00aa693e2477a7bd0d12a0df diff --git a/manifest.uuid b/manifest.uuid index 4e696488e9..eed343f04b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -efb4aab0caa4145732a5438cc2a193bc12c455b4007220564d240e75900ea8ad \ No newline at end of file +c5ed5ebdf660501fde7cc8aefaaaeae2a68e5899a64ac93f26684842a235281d \ No newline at end of file diff --git a/tool/mkkeywordhash.c b/tool/mkkeywordhash.c index 7e5287ea54..42112718da 100644 --- a/tool/mkkeywordhash.c +++ b/tool/mkkeywordhash.c @@ -336,8 +336,8 @@ int main(int argc, char **argv){ int count; int nChar; int totalLen = 0; - int aHash[1000]; /* 1000 is much bigger than nKeyword */ - char zText[2000]; + int aKWHash[1000]; /* 1000 is much bigger than nKeyword */ + char zKWText[2000]; /* Remove entries from the list of keywords that have mask==0 */ for(i=j=0; isubstrId ) continue; - memcpy(&zText[k], p->zName, p->len); + memcpy(&zKWText[k], p->zName, p->len); k += p->len; if( j+p->len>70 ){ printf("%*s */\n", 74-j, ""); j = 0; } if( j==0 ){ - printf(" /* "); + printf("/* "); j = 8; } printf("%s", p->zName); @@ -487,16 +486,16 @@ int main(int argc, char **argv){ if( j>0 ){ printf("%*s */\n", 74-j, ""); } - printf(" static const char zText[%d] = {\n", nChar); - zText[nChar] = 0; + printf("static const char zKWText[%d] = {\n", nChar); + zKWText[nChar] = 0; for(i=j=0; i68 ){ @@ -505,23 +504,27 @@ int main(int argc, char **argv){ } } if( j>0 ) printf("\n"); - printf(" };\n"); + printf("};\n"); - printf(" static const unsigned char aHash[%d] = {\n", bestSize); + printf("/* aKWHash[i] is the hash value for the i-th keyword */\n"); + printf("static const unsigned char aKWHash[%d] = {\n", bestSize); for(i=j=0; i12 ){ printf("\n"); j = 0; } } - printf("%s };\n", j==0 ? "" : "\n"); + printf("%s};\n", j==0 ? "" : "\n"); - printf(" static const unsigned char aNext[%d] = {\n", nKeyword); + printf("/* aKWNext[] forms the hash collision chain. If aKWHash[i]==0\n"); + printf("** then the i-th keyword has no more hash collisions. Otherwise,\n"); + printf("** the next keyword with the same hash is aKWHash[i]-1. */\n"); + printf("static const unsigned char aKWNext[%d] = {\n", nKeyword); for(i=j=0; i12 ){ @@ -529,11 +532,12 @@ int main(int argc, char **argv){ j = 0; } } - printf("%s };\n", j==0 ? "" : "\n"); + printf("%s};\n", j==0 ? "" : "\n"); - printf(" static const unsigned char aLen[%d] = {\n", nKeyword); + printf("/* aKWLen[i] is the length (in bytes) of the i-th keyword */\n"); + printf("static const unsigned char aKWLen[%d] = {\n", nKeyword); for(i=j=0; i12 ){ @@ -541,11 +545,13 @@ int main(int argc, char **argv){ j = 0; } } - printf("%s };\n", j==0 ? "" : "\n"); + printf("%s};\n", j==0 ? "" : "\n"); - printf(" static const unsigned short int aOffset[%d] = {\n", nKeyword); + printf("/* aKWOffset[i] is the index into zKWText[] of the start of\n"); + printf("** the text for the i-th keyword. */\n"); + printf("static const unsigned short int aKWOffset[%d] = {\n", nKeyword); for(i=j=0; i12 ){ @@ -553,12 +559,13 @@ int main(int argc, char **argv){ j = 0; } } - printf("%s };\n", j==0 ? "" : "\n"); + printf("%s};\n", j==0 ? "" : "\n"); - printf(" static const unsigned char aCode[%d] = {\n", nKeyword); + printf("/* aKWCode[i] is the parser symbol code for the i-th keyword */\n"); + printf("static const unsigned char aKWCode[%d] = {\n", nKeyword); for(i=j=0; i=5 ){ @@ -566,17 +573,20 @@ int main(int argc, char **argv){ j = 0; } } - printf("%s };\n", j==0 ? "" : "\n"); - + printf("%s};\n", j==0 ? "" : "\n"); + printf("/* Check to see if z[0..n-1] is a keyword. If it is, write the\n"); + printf("** parser symbol code for that keyword into *pType. Always\n"); + printf("** return the integer n (the length of the token). */\n"); + printf("static int keywordCode(const char *z, int n, int *pType){\n"); printf(" int i, j;\n"); printf(" const char *zKW;\n"); printf(" if( n>=2 ){\n"); printf(" i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) %% %d;\n", bestSize); - printf(" for(i=((int)aHash[i])-1; i>=0; i=((int)aNext[i])-1){\n"); - printf(" if( aLen[i]!=n ) continue;\n"); + printf(" for(i=((int)aKWHash[i])-1; i>=0; i=((int)aKWNext[i])-1){\n"); + printf(" if( aKWLen[i]!=n ) continue;\n"); printf(" j = 0;\n"); - printf(" zKW = &zText[aOffset[i]];\n"); + printf(" zKW = &zKWText[aKWOffset[i]];\n"); printf("#ifdef SQLITE_ASCII\n"); printf(" while( j