Replace automatically generated code with a more friendly equivalent
This commit is contained in:
parent
f577943861
commit
dff0a5c968
289
lex.c
289
lex.c
|
@ -560,206 +560,99 @@ static sxi32 TokenizePHP(SyStream *pStream,SyToken *pToken,void *pUserData,void
|
||||||
/* Tell the upper-layer to save the extracted token for later processing */
|
/* Tell the upper-layer to save the extracted token for later processing */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/***** This file contains automatically generated code ******
|
|
||||||
**
|
|
||||||
** The code in this file has been automatically generated by
|
|
||||||
**
|
|
||||||
** $Header: /sqlite/sqlite/tool/mkkeywordhash.c
|
|
||||||
**
|
|
||||||
** Sligthly modified by Chems mrad <chm@symisc.net> for the PH7 engine.
|
|
||||||
**
|
|
||||||
** The code in this file implements a function that determines whether
|
|
||||||
** or not a given identifier is really a PHP keyword. The same thing
|
|
||||||
** might be implemented more directly using a hand-written hash table.
|
|
||||||
** But by using this automatically generated code, the size of the code
|
|
||||||
** is substantially reduced. This is important for embedded applications
|
|
||||||
** on platforms with limited memory.
|
|
||||||
*/
|
|
||||||
/* Hash score: 103 */
|
|
||||||
static sxu32 KeywordCode(const char *z, int n){
|
static sxu32 KeywordCode(const char *z, int n){
|
||||||
/* zText[] encodes 532 bytes of keywords in 333 bytes */
|
typedef struct {
|
||||||
/* extendswitchprintegerequire_oncenddeclareturnamespacechobject */
|
char *token;
|
||||||
/* hrowbooleandefaultrycaselfinalistaticlonewconstringlobaluse */
|
int value;
|
||||||
/* lseifloatvarrayANDIEchoUSECHOabstractclasscontinuendifunction */
|
} ph7_token;
|
||||||
/* diendwhilevaldoexitgotoimplementsinclude_oncemptyinstanceof */
|
static ph7_token pTokenLookup[] = {
|
||||||
/* interfacendforeachissetparentprivateprotectedpublicatchunset */
|
{"extends", PH7_TKWRD_EXTENDS},
|
||||||
/* xorARRAYASArrayEXITUNSETXORbreak */
|
{"endswitch", PH7_TKWRD_ENDSWITCH},
|
||||||
static const char zText[332] = {
|
{"switch", PH7_TKWRD_SWITCH},
|
||||||
'e','x','t','e','n','d','s','w','i','t','c','h','p','r','i','n','t','e',
|
{"print", PH7_TKWRD_PRINT},
|
||||||
'g','e','r','e','q','u','i','r','e','_','o','n','c','e','n','d','d','e',
|
{"int", PH7_TKWRD_INT},
|
||||||
'c','l','a','r','e','t','u','r','n','a','m','e','s','p','a','c','e','c',
|
{"require_once", PH7_TKWRD_REQONCE},
|
||||||
'h','o','b','j','e','c','t','h','r','o','w','b','o','o','l','e','a','n',
|
{"require", PH7_TKWRD_REQUIRE},
|
||||||
'd','e','f','a','u','l','t','r','y','c','a','s','e','l','f','i','n','a',
|
{"eq", PH7_TKWRD_SEQ},
|
||||||
'l','i','s','t','a','t','i','c','l','o','n','e','w','c','o','n','s','t',
|
{"ne", PH7_TKWRD_SNE},
|
||||||
'r','i','n','g','l','o','b','a','l','u','s','e','l','s','e','i','f','l',
|
{"enddeclare", PH7_TKWRD_ENDDEC},
|
||||||
'o','a','t','v','a','r','r','a','y','A','N','D','I','E','c','h','o','U',
|
{"declare", PH7_TKWRD_DECLARE},
|
||||||
'S','E','C','H','O','a','b','s','t','r','a','c','t','c','l','a','s','s',
|
{"return", PH7_TKWRD_RETURN},
|
||||||
'c','o','n','t','i','n','u','e','n','d','i','f','u','n','c','t','i','o',
|
{"namespace", PH7_TKWRD_NAMESPACE},
|
||||||
'n','d','i','e','n','d','w','h','i','l','e','v','a','l','d','o','e','x',
|
{"echo", PH7_TKWRD_ECHO},
|
||||||
'i','t','g','o','t','o','i','m','p','l','e','m','e','n','t','s','i','n',
|
{"object", PH7_TKWRD_OBJECT},
|
||||||
'c','l','u','d','e','_','o','n','c','e','m','p','t','y','i','n','s','t',
|
{"throw", PH7_TKWRD_THROW},
|
||||||
'a','n','c','e','o','f','i','n','t','e','r','f','a','c','e','n','d','f',
|
{"bool", PH7_TKWRD_BOOL},
|
||||||
'o','r','e','a','c','h','i','s','s','e','t','p','a','r','e','n','t','p',
|
{"boolean", PH7_TKWRD_BOOL},
|
||||||
'r','i','v','a','t','e','p','r','o','t','e','c','t','e','d','p','u','b',
|
{"and", PH7_TKWRD_AND},
|
||||||
'l','i','c','a','t','c','h','u','n','s','e','t','x','o','r','A','R','R',
|
{"default", PH7_TKWRD_DEFAULT},
|
||||||
'A','Y','A','S','A','r','r','a','y','E','X','I','T','U','N','S','E','T',
|
{"try", PH7_TKWRD_TRY},
|
||||||
'X','O','R','b','r','e','a','k'
|
{"case", PH7_TKWRD_CASE},
|
||||||
};
|
{"self", PH7_TKWRD_SELF},
|
||||||
static const unsigned char aHash[151] = {
|
{"final", PH7_TKWRD_FINAL},
|
||||||
0, 0, 4, 83, 0, 61, 39, 12, 0, 33, 77, 0, 48,
|
{"list", PH7_TKWRD_LIST},
|
||||||
0, 2, 65, 67, 0, 0, 0, 47, 0, 0, 40, 0, 15,
|
{"static", PH7_TKWRD_STATIC},
|
||||||
74, 0, 51, 0, 76, 0, 0, 20, 0, 0, 0, 50, 0,
|
{"clone", PH7_TKWRD_CLONE},
|
||||||
80, 34, 0, 36, 0, 0, 64, 16, 0, 0, 17, 0, 1,
|
{"new", PH7_TKWRD_NEW},
|
||||||
19, 84, 66, 0, 43, 45, 78, 0, 0, 53, 56, 0, 0,
|
{"const", PH7_TKWRD_CONST},
|
||||||
0, 23, 49, 0, 0, 13, 31, 54, 7, 0, 0, 25, 0,
|
{"string", PH7_TKWRD_STRING},
|
||||||
72, 14, 0, 71, 0, 38, 6, 0, 0, 0, 73, 0, 0,
|
{"global", PH7_TKWRD_GLOBAL},
|
||||||
3, 0, 41, 5, 52, 57, 32, 0, 60, 63, 0, 69, 82,
|
{"use", PH7_TKWRD_USE},
|
||||||
30, 0, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
{"elseif", PH7_TKWRD_ELIF},
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 81, 0, 0,
|
{"elif", PH7_TKWRD_ELIF},
|
||||||
62, 0, 11, 0, 0, 58, 0, 0, 0, 0, 59, 75, 0,
|
{"else", PH7_TKWRD_ELSE},
|
||||||
0, 0, 0, 0, 0, 35, 27, 0
|
{"if", PH7_TKWRD_IF},
|
||||||
};
|
{"double", PH7_TKWRD_FLOAT},
|
||||||
static const unsigned char aNext[84] = {
|
{"float", PH7_TKWRD_FLOAT},
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
{"var", PH7_TKWRD_VAR},
|
||||||
0, 0, 8, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0,
|
{"array", PH7_TKWRD_ARRAY},
|
||||||
0, 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0,
|
{"die", PH7_TKWRD_DIE},
|
||||||
0, 0, 0, 0, 0, 44, 0, 18, 0, 0, 0, 0, 0,
|
{"abstract", PH7_TKWRD_ABSTRACT},
|
||||||
0, 46, 0, 29, 0, 0, 0, 22, 0, 0, 0, 0, 26,
|
{"class", PH7_TKWRD_CLASS},
|
||||||
0, 21, 24, 0, 0, 68, 0, 0, 9, 37, 0, 0, 0,
|
{"as", PH7_TKWRD_AS},
|
||||||
42, 0, 0, 0, 70, 55
|
{"continue", PH7_TKWRD_CONTINUE},
|
||||||
};
|
{"endif", PH7_TKWRD_ENDIF},
|
||||||
static const unsigned char aLen[84] = {
|
{"function", PH7_TKWRD_FUNCTION},
|
||||||
7, 9, 6, 5, 7, 12, 7, 2, 10, 7, 6, 9, 4,
|
{"endwhile", PH7_TKWRD_ENDWHILE},
|
||||||
6, 5, 7, 4, 3, 7, 3, 4, 4, 5, 4, 6, 5,
|
{"while", PH7_TKWRD_WHILE},
|
||||||
2, 3, 5, 6, 6, 3, 6, 4, 2, 5, 3, 5, 3,
|
{"eval", PH7_TKWRD_EVAL},
|
||||||
3, 4, 3, 4, 8, 5, 2, 8, 5, 8, 3, 8, 5,
|
{"do", PH7_TKWRD_DO},
|
||||||
4, 2, 4, 4, 10, 12, 7, 5, 10, 9, 3, 6, 10,
|
{"exit", PH7_TKWRD_EXIT},
|
||||||
3, 7, 2, 5, 6, 7, 9, 6, 5, 5, 3, 5, 2,
|
{"goto", PH7_TKWRD_GOTO},
|
||||||
5, 4, 5, 3, 2, 5
|
{"implements", PH7_TKWRD_IMPLEMENTS},
|
||||||
};
|
{"include_once", PH7_TKWRD_INCONCE},
|
||||||
static const sxu16 aOffset[84] = {
|
{"include", PH7_TKWRD_INCLUDE},
|
||||||
0, 3, 6, 12, 14, 20, 20, 21, 31, 34, 39, 44, 52,
|
{"empty", PH7_TKWRD_EMPTY},
|
||||||
55, 60, 65, 65, 70, 72, 78, 81, 83, 86, 90, 92, 97,
|
{"instanceof", PH7_TKWRD_INSTANCEOF},
|
||||||
100, 100, 103, 106, 111, 117, 119, 119, 123, 124, 129, 130, 135,
|
{"interface", PH7_TKWRD_INTERFACE},
|
||||||
137, 139, 143, 145, 149, 157, 159, 162, 169, 173, 181, 183, 186,
|
{"integer", PH7_TKWRD_INT},
|
||||||
190, 194, 196, 200, 204, 214, 214, 225, 230, 240, 240, 248, 248,
|
{"endfor", PH7_TKWRD_ENDFOR},
|
||||||
251, 251, 252, 258, 263, 269, 276, 285, 290, 295, 300, 303, 308,
|
{"endforeach", PH7_TKWRD_END4EACH},
|
||||||
310, 315, 319, 324, 325, 327
|
{"for", PH7_TKWRD_FOR},
|
||||||
};
|
{"foreach", PH7_TKWRD_FOREACH},
|
||||||
static const sxu32 aCode[84] = {
|
{"or", PH7_TKWRD_OR},
|
||||||
PH7_TKWRD_EXTENDS, PH7_TKWRD_ENDSWITCH, PH7_TKWRD_SWITCH, PH7_TKWRD_PRINT, PH7_TKWRD_INT,
|
{"isset", PH7_TKWRD_ISSET},
|
||||||
PH7_TKWRD_REQONCE, PH7_TKWRD_REQUIRE, PH7_TKWRD_SEQ, PH7_TKWRD_ENDDEC, PH7_TKWRD_DECLARE,
|
{"parent", PH7_TKWRD_PARENT},
|
||||||
PH7_TKWRD_RETURN, PH7_TKWRD_NAMESPACE, PH7_TKWRD_ECHO, PH7_TKWRD_OBJECT, PH7_TKWRD_THROW,
|
{"private", PH7_TKWRD_PRIVATE},
|
||||||
PH7_TKWRD_BOOL, PH7_TKWRD_BOOL, PH7_TKWRD_AND, PH7_TKWRD_DEFAULT, PH7_TKWRD_TRY,
|
{"protected", PH7_TKWRD_PROTECTED},
|
||||||
PH7_TKWRD_CASE, PH7_TKWRD_SELF, PH7_TKWRD_FINAL, PH7_TKWRD_LIST, PH7_TKWRD_STATIC,
|
{"public", PH7_TKWRD_PUBLIC},
|
||||||
PH7_TKWRD_CLONE, PH7_TKWRD_SNE, PH7_TKWRD_NEW, PH7_TKWRD_CONST, PH7_TKWRD_STRING,
|
{"catch", PH7_TKWRD_CATCH},
|
||||||
PH7_TKWRD_GLOBAL, PH7_TKWRD_USE, PH7_TKWRD_ELIF, PH7_TKWRD_ELSE, PH7_TKWRD_IF,
|
{"unset", PH7_TKWRD_UNSET},
|
||||||
PH7_TKWRD_FLOAT, PH7_TKWRD_VAR, PH7_TKWRD_ARRAY, PH7_TKWRD_AND, PH7_TKWRD_DIE,
|
{"xor", PH7_TKWRD_XOR},
|
||||||
PH7_TKWRD_ECHO, PH7_TKWRD_USE, PH7_TKWRD_ECHO, PH7_TKWRD_ABSTRACT, PH7_TKWRD_CLASS,
|
{"break", PH7_TKWRD_BREAK}
|
||||||
PH7_TKWRD_AS, PH7_TKWRD_CONTINUE, PH7_TKWRD_ENDIF, PH7_TKWRD_FUNCTION, PH7_TKWRD_DIE,
|
};
|
||||||
PH7_TKWRD_ENDWHILE, PH7_TKWRD_WHILE, PH7_TKWRD_EVAL, PH7_TKWRD_DO, PH7_TKWRD_EXIT,
|
if(n < 2) {
|
||||||
PH7_TKWRD_GOTO, PH7_TKWRD_IMPLEMENTS, PH7_TKWRD_INCONCE, PH7_TKWRD_INCLUDE, PH7_TKWRD_EMPTY,
|
return PH7_TK_ID;
|
||||||
PH7_TKWRD_INSTANCEOF,PH7_TKWRD_INTERFACE, PH7_TKWRD_INT, PH7_TKWRD_ENDFOR, PH7_TKWRD_END4EACH,
|
} else {
|
||||||
PH7_TKWRD_FOR, PH7_TKWRD_FOREACH, PH7_TKWRD_OR, PH7_TKWRD_ISSET, PH7_TKWRD_PARENT,
|
for(ph7_token *pToken = pTokenLookup; pToken != pTokenLookup + sizeof(pTokenLookup) / sizeof(pTokenLookup[0]); pToken++) {
|
||||||
PH7_TKWRD_PRIVATE, PH7_TKWRD_PROTECTED, PH7_TKWRD_PUBLIC, PH7_TKWRD_CATCH, PH7_TKWRD_UNSET,
|
if(SyMemcmp(pToken->token, z, n) == 0) {
|
||||||
PH7_TKWRD_XOR, PH7_TKWRD_ARRAY, PH7_TKWRD_AS, PH7_TKWRD_ARRAY, PH7_TKWRD_EXIT,
|
return pToken->value;
|
||||||
PH7_TKWRD_UNSET, PH7_TKWRD_XOR, PH7_TKWRD_OR, PH7_TKWRD_BREAK
|
}
|
||||||
};
|
}
|
||||||
int h, i;
|
return PH7_TK_ID;
|
||||||
if( n<2 ) return PH7_TK_ID;
|
}
|
||||||
h = (((int)z[0]*4) ^ ((int)z[n-1]*3) ^ n) % 151;
|
|
||||||
for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){
|
|
||||||
if( (int)aLen[i]==n && SyMemcmp(&zText[aOffset[i]],z,n)==0 ){
|
|
||||||
/* PH7_TKWRD_EXTENDS */
|
|
||||||
/* PH7_TKWRD_ENDSWITCH */
|
|
||||||
/* PH7_TKWRD_SWITCH */
|
|
||||||
/* PH7_TKWRD_PRINT */
|
|
||||||
/* PH7_TKWRD_INT */
|
|
||||||
/* PH7_TKWRD_REQONCE */
|
|
||||||
/* PH7_TKWRD_REQUIRE */
|
|
||||||
/* PH7_TKWRD_SEQ */
|
|
||||||
/* PH7_TKWRD_ENDDEC */
|
|
||||||
/* PH7_TKWRD_DECLARE */
|
|
||||||
/* PH7_TKWRD_RETURN */
|
|
||||||
/* PH7_TKWRD_NAMESPACE */
|
|
||||||
/* PH7_TKWRD_ECHO */
|
|
||||||
/* PH7_TKWRD_OBJECT */
|
|
||||||
/* PH7_TKWRD_THROW */
|
|
||||||
/* PH7_TKWRD_BOOL */
|
|
||||||
/* PH7_TKWRD_BOOL */
|
|
||||||
/* PH7_TKWRD_AND */
|
|
||||||
/* PH7_TKWRD_DEFAULT */
|
|
||||||
/* PH7_TKWRD_TRY */
|
|
||||||
/* PH7_TKWRD_CASE */
|
|
||||||
/* PH7_TKWRD_SELF */
|
|
||||||
/* PH7_TKWRD_FINAL */
|
|
||||||
/* PH7_TKWRD_LIST */
|
|
||||||
/* PH7_TKWRD_STATIC */
|
|
||||||
/* PH7_TKWRD_CLONE */
|
|
||||||
/* PH7_TKWRD_SNE */
|
|
||||||
/* PH7_TKWRD_NEW */
|
|
||||||
/* PH7_TKWRD_CONST */
|
|
||||||
/* PH7_TKWRD_STRING */
|
|
||||||
/* PH7_TKWRD_GLOBAL */
|
|
||||||
/* PH7_TKWRD_USE */
|
|
||||||
/* PH7_TKWRD_ELIF */
|
|
||||||
/* PH7_TKWRD_ELSE */
|
|
||||||
/* PH7_TKWRD_IF */
|
|
||||||
/* PH7_TKWRD_FLOAT */
|
|
||||||
/* PH7_TKWRD_VAR */
|
|
||||||
/* PH7_TKWRD_ARRAY */
|
|
||||||
/* PH7_TKWRD_AND */
|
|
||||||
/* PH7_TKWRD_DIE */
|
|
||||||
/* PH7_TKWRD_ECHO */
|
|
||||||
/* PH7_TKWRD_USE */
|
|
||||||
/* PH7_TKWRD_ECHO */
|
|
||||||
/* PH7_TKWRD_ABSTRACT */
|
|
||||||
/* PH7_TKWRD_CLASS */
|
|
||||||
/* PH7_TKWRD_AS */
|
|
||||||
/* PH7_TKWRD_CONTINUE */
|
|
||||||
/* PH7_TKWRD_ENDIF */
|
|
||||||
/* PH7_TKWRD_FUNCTION */
|
|
||||||
/* PH7_TKWRD_DIE */
|
|
||||||
/* PH7_TKWRD_ENDWHILE */
|
|
||||||
/* PH7_TKWRD_WHILE */
|
|
||||||
/* PH7_TKWRD_EVAL */
|
|
||||||
/* PH7_TKWRD_DO */
|
|
||||||
/* PH7_TKWRD_EXIT */
|
|
||||||
/* PH7_TKWRD_GOTO */
|
|
||||||
/* PH7_TKWRD_IMPLEMENTS */
|
|
||||||
/* PH7_TKWRD_INCONCE */
|
|
||||||
/* PH7_TKWRD_INCLUDE */
|
|
||||||
/* PH7_TKWRD_EMPTY */
|
|
||||||
/* PH7_TKWRD_INSTANCEOF */
|
|
||||||
/* PH7_TKWRD_INTERFACE */
|
|
||||||
/* PH7_TKWRD_INT */
|
|
||||||
/* PH7_TKWRD_ENDFOR */
|
|
||||||
/* PH7_TKWRD_END4EACH */
|
|
||||||
/* PH7_TKWRD_FOR */
|
|
||||||
/* PH7_TKWRD_FOREACH */
|
|
||||||
/* PH7_TKWRD_OR */
|
|
||||||
/* PH7_TKWRD_ISSET */
|
|
||||||
/* PH7_TKWRD_PARENT */
|
|
||||||
/* PH7_TKWRD_PRIVATE */
|
|
||||||
/* PH7_TKWRD_PROTECTED */
|
|
||||||
/* PH7_TKWRD_PUBLIC */
|
|
||||||
/* PH7_TKWRD_CATCH */
|
|
||||||
/* PH7_TKWRD_UNSET */
|
|
||||||
/* PH7_TKWRD_XOR */
|
|
||||||
/* PH7_TKWRD_ARRAY */
|
|
||||||
/* PH7_TKWRD_AS */
|
|
||||||
/* PH7_TKWRD_ARRAY */
|
|
||||||
/* PH7_TKWRD_EXIT */
|
|
||||||
/* PH7_TKWRD_UNSET */
|
|
||||||
/* PH7_TKWRD_XOR */
|
|
||||||
/* PH7_TKWRD_OR */
|
|
||||||
/* PH7_TKWRD_BREAK */
|
|
||||||
return aCode[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PH7_TK_ID;
|
|
||||||
}
|
}
|
||||||
/* --- End of Automatically generated code --- */
|
|
||||||
/*
|
/*
|
||||||
* Extract a heredoc/nowdoc text from a raw PHP input.
|
* Extract a heredoc/nowdoc text from a raw PHP input.
|
||||||
* According to the PHP language reference manual:
|
* According to the PHP language reference manual:
|
||||||
|
|
Loading…
Reference in New Issue