| 72 | } |
| 73 | |
| 74 | void asCTokenizer::InitJumpTable() |
| 75 | { |
| 76 | FreeJumpTable(); |
| 77 | |
| 78 | // Initialize the jump table |
| 79 | for (asUINT n = 0; n < numTokenWords; n++) |
| 80 | { |
| 81 | const sTokenWord& current = tokenWords[n]; |
| 82 | |
| 83 | // Check if a token must be skipped due to engine properties |
| 84 | if (current.tokenType == ttForEach && engine && !engine->ep.foreachSupport) |
| 85 | continue; |
| 86 | |
| 87 | unsigned char start = current.word[0]; |
| 88 | |
| 89 | // Create new jump table entry if none exists |
| 90 | if (!keywordTable[start]) |
| 91 | { |
| 92 | // Surely there won't ever be more than 32 keywords starting with |
| 93 | // the same character. Right? |
| 94 | keywordTable[start] = asNEWARRAY(const sTokenWord*, 32); |
| 95 | memset(keywordTable[start], 0, sizeof(sTokenWord*) * 32); |
| 96 | } |
| 97 | |
| 98 | // Add the token sorted from longest to shortest so |
| 99 | // we check keywords greedily. |
| 100 | const sTokenWord** tok = keywordTable[start]; |
| 101 | unsigned insert = 0, index = 0; |
| 102 | while (tok[index]) |
| 103 | { |
| 104 | if (tok[index]->wordLength >= current.wordLength) |
| 105 | ++insert; |
| 106 | ++index; |
| 107 | } |
| 108 | |
| 109 | while (index > insert) |
| 110 | { |
| 111 | tok[index] = tok[index - 1]; |
| 112 | --index; |
| 113 | } |
| 114 | |
| 115 | tok[insert] = ¤t; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // static |
| 120 | const char *asCTokenizer::GetDefinition(int tokenType) |