1 // Copyright 2018 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This file is automatically generated by gen-keywords-gen-h.py and should not
6 // be modified manually.
7
8 #ifndef V8_PARSING_KEYWORDS_GEN_H_
9 #define V8_PARSING_KEYWORDS_GEN_H_
10
11 #include "src/parsing/token.h"
12
13 namespace v8 {
14 namespace internal {
15
16 /* C++ code produced by gperf version 3.1 */
17 /* Command-line: gperf -m100 src/parsing/keywords.txt */
18 /* Computed positions: -k'1-2' */
19
20 #if !( \
21 (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) && ('%' == 37) && \
22 ('&' == 38) && ('\'' == 39) && ('(' == 40) && (')' == 41) && \
23 ('*' == 42) && ('+' == 43) && (',' == 44) && ('-' == 45) && ('.' == 46) && \
24 ('/' == 47) && ('0' == 48) && ('1' == 49) && ('2' == 50) && ('3' == 51) && \
25 ('4' == 52) && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) && \
26 ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) && ('=' == 61) && \
27 ('>' == 62) && ('?' == 63) && ('A' == 65) && ('B' == 66) && ('C' == 67) && \
28 ('D' == 68) && ('E' == 69) && ('F' == 70) && ('G' == 71) && ('H' == 72) && \
29 ('I' == 73) && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) && \
30 ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) && ('R' == 82) && \
31 ('S' == 83) && ('T' == 84) && ('U' == 85) && ('V' == 86) && ('W' == 87) && \
32 ('X' == 88) && ('Y' == 89) && ('Z' == 90) && ('[' == 91) && \
33 ('\\' == 92) && (']' == 93) && ('^' == 94) && ('_' == 95) && \
34 ('a' == 97) && ('b' == 98) && ('c' == 99) && ('d' == 100) && \
35 ('e' == 101) && ('f' == 102) && ('g' == 103) && ('h' == 104) && \
36 ('i' == 105) && ('j' == 106) && ('k' == 107) && ('l' == 108) && \
37 ('m' == 109) && ('n' == 110) && ('o' == 111) && ('p' == 112) && \
38 ('q' == 113) && ('r' == 114) && ('s' == 115) && ('t' == 116) && \
39 ('u' == 117) && ('v' == 118) && ('w' == 119) && ('x' == 120) && \
40 ('y' == 121) && ('z' == 122) && ('{' == 123) && ('|' == 124) && \
41 ('}' == 125) && ('~' == 126))
42 /* The character set is not based on ISO-646. */
43 #error "gperf generated tables don't work with this execution character set."
44 // If you see this error, please report a bug to <bug-gperf@gnu.org>.
45 #endif
46
47 struct PerfectKeywordHashTableEntry {
48 const char* name;
49 Token::Value value;
50 };
51 enum {
52 TOTAL_KEYWORDS = 49,
53 MIN_WORD_LENGTH = 2,
54 MAX_WORD_LENGTH = 10,
55 MIN_HASH_VALUE = 2,
56 MAX_HASH_VALUE = 55
57 };
58
59 /* maximum key range = 54, duplicates = 0 */
60
61 class PerfectKeywordHash {
62 private:
63 static inline unsigned int Hash(const char* str, int len);
64
65 public:
66 static inline Token::Value GetToken(const char* str, int len);
67 };
68
Hash(const char * str,int len)69 inline unsigned int PerfectKeywordHash::Hash(const char* str, int len) {
70 DCHECK_LT(str[1], 128);
71 DCHECK_LT(str[0], 128);
72 static const unsigned char asso_values[128] = {
73 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
74 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
75 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
76 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
77 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
78 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
79 56, 8, 0, 6, 0, 0, 9, 9, 9, 0, 56, 56, 34, 41, 0, 3,
80 6, 56, 19, 10, 13, 16, 39, 26, 37, 36, 56, 56, 56, 56, 56, 56};
81 return len + asso_values[static_cast<unsigned char>(str[1])] +
82 asso_values[static_cast<unsigned char>(str[0])];
83 }
84
85 static const unsigned char kPerfectKeywordLengthTable[64] = {
86 0, 0, 2, 3, 4, 2, 6, 7, 8, 9, 10, 2, 3, 3, 5, 3, 7, 8, 4, 5, 4, 7,
87 5, 5, 5, 6, 4, 5, 6, 6, 4, 5, 7, 8, 9, 3, 4, 3, 4, 5, 5, 5, 6, 6,
88 7, 5, 4, 6, 0, 0, 3, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0};
89
90 static const struct PerfectKeywordHashTableEntry kPerfectKeywordHashTable[64] =
91 {{"", Token::IDENTIFIER},
92 {"", Token::IDENTIFIER},
93 {"in", Token::IN},
94 {"new", Token::NEW},
95 {"enum", Token::ENUM},
96 {"do", Token::DO},
97 {"delete", Token::DELETE},
98 {"default", Token::DEFAULT},
99 {"debugger", Token::DEBUGGER},
100 {"interface", Token::FUTURE_STRICT_RESERVED_WORD},
101 {"instanceof", Token::INSTANCEOF},
102 {"if", Token::IF},
103 {"get", Token::GET},
104 {"set", Token::SET},
105 {"const", Token::CONST},
106 {"for", Token::FOR},
107 {"finally", Token::FINALLY},
108 {"continue", Token::CONTINUE},
109 {"case", Token::CASE},
110 {"catch", Token::CATCH},
111 {"null", Token::NULL_LITERAL},
112 {"package", Token::FUTURE_STRICT_RESERVED_WORD},
113 {"false", Token::FALSE_LITERAL},
114 {"async", Token::ASYNC},
115 {"break", Token::BREAK},
116 {"return", Token::RETURN},
117 {"this", Token::THIS},
118 {"throw", Token::THROW},
119 {"public", Token::FUTURE_STRICT_RESERVED_WORD},
120 {"static", Token::STATIC},
121 {"with", Token::WITH},
122 {"super", Token::SUPER},
123 {"private", Token::FUTURE_STRICT_RESERVED_WORD},
124 {"function", Token::FUNCTION},
125 {"protected", Token::FUTURE_STRICT_RESERVED_WORD},
126 {"try", Token::TRY},
127 {"true", Token::TRUE_LITERAL},
128 {"let", Token::LET},
129 {"else", Token::ELSE},
130 {"await", Token::AWAIT},
131 {"while", Token::WHILE},
132 {"yield", Token::YIELD},
133 {"switch", Token::SWITCH},
134 {"export", Token::EXPORT},
135 {"extends", Token::EXTENDS},
136 {"class", Token::CLASS},
137 {"void", Token::VOID},
138 {"import", Token::IMPORT},
139 {"", Token::IDENTIFIER},
140 {"", Token::IDENTIFIER},
141 {"var", Token::VAR},
142 {"implements", Token::FUTURE_STRICT_RESERVED_WORD},
143 {"", Token::IDENTIFIER},
144 {"", Token::IDENTIFIER},
145 {"", Token::IDENTIFIER},
146 {"typeof", Token::TYPEOF},
147 {"", Token::IDENTIFIER},
148 {"", Token::IDENTIFIER},
149 {"", Token::IDENTIFIER},
150 {"", Token::IDENTIFIER},
151 {"", Token::IDENTIFIER},
152 {"", Token::IDENTIFIER},
153 {"", Token::IDENTIFIER},
154 {"", Token::IDENTIFIER}};
155
GetToken(const char * str,int len)156 inline Token::Value PerfectKeywordHash::GetToken(const char* str, int len) {
157 if (base::IsInRange(len, MIN_WORD_LENGTH, MAX_WORD_LENGTH)) {
158 unsigned int key = Hash(str, len) & 0x3f;
159
160 DCHECK_LT(key, arraysize(kPerfectKeywordLengthTable));
161 DCHECK_LT(key, arraysize(kPerfectKeywordHashTable));
162 if (len == kPerfectKeywordLengthTable[key]) {
163 const char* s = kPerfectKeywordHashTable[key].name;
164
165 while (*s != 0) {
166 if (*s++ != *str++) return Token::IDENTIFIER;
167 }
168 return kPerfectKeywordHashTable[key].value;
169 }
170 }
171 return Token::IDENTIFIER;
172 }
173
174 } // namespace internal
175 } // namespace v8
176
177 #endif // V8_PARSING_KEYWORDS_GEN_H_
178