Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PARSING_TOKEN_H_ | 5 #ifndef V8_PARSING_TOKEN_H_ |
| 6 #define V8_PARSING_TOKEN_H_ | 6 #define V8_PARSING_TOKEN_H_ |
| 7 | 7 |
| 8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
| 9 #include "src/globals.h" | 9 #include "src/globals.h" |
| 10 | 10 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 K(TRUE_LITERAL, "true", 0) \ | 139 K(TRUE_LITERAL, "true", 0) \ |
| 140 K(FALSE_LITERAL, "false", 0) \ | 140 K(FALSE_LITERAL, "false", 0) \ |
| 141 T(NUMBER, NULL, 0) \ | 141 T(NUMBER, NULL, 0) \ |
| 142 T(SMI, NULL, 0) \ | 142 T(SMI, NULL, 0) \ |
| 143 T(STRING, NULL, 0) \ | 143 T(STRING, NULL, 0) \ |
| 144 \ | 144 \ |
| 145 /* Identifiers (not keywords or future reserved words). */ \ | 145 /* Identifiers (not keywords or future reserved words). */ \ |
| 146 T(IDENTIFIER, NULL, 0) \ | 146 T(IDENTIFIER, NULL, 0) \ |
| 147 \ | 147 \ |
| 148 /* Future reserved words (ECMA-262, section 7.6.1.2). */ \ | 148 /* Future reserved words (ECMA-262, section 7.6.1.2). */ \ |
| 149 T(FUTURE_RESERVED_WORD, NULL, 0) \ | |
| 150 T(FUTURE_STRICT_RESERVED_WORD, NULL, 0) \ | 149 T(FUTURE_STRICT_RESERVED_WORD, NULL, 0) \ |
| 150 /* `await` is a reserved word in module code only */ \ | |
| 151 K(AWAIT, "await", 0) \ | |
| 151 K(CLASS, "class", 0) \ | 152 K(CLASS, "class", 0) \ |
| 152 K(CONST, "const", 0) \ | 153 K(CONST, "const", 0) \ |
| 154 K(ENUM, "enum", 0) \ | |
| 153 K(EXPORT, "export", 0) \ | 155 K(EXPORT, "export", 0) \ |
| 154 K(EXTENDS, "extends", 0) \ | 156 K(EXTENDS, "extends", 0) \ |
| 155 K(IMPORT, "import", 0) \ | 157 K(IMPORT, "import", 0) \ |
| 156 K(LET, "let", 0) \ | 158 K(LET, "let", 0) \ |
| 157 K(STATIC, "static", 0) \ | 159 K(STATIC, "static", 0) \ |
| 158 K(YIELD, "yield", 0) \ | 160 K(YIELD, "yield", 0) \ |
| 159 K(SUPER, "super", 0) \ | 161 K(SUPER, "super", 0) \ |
| 160 \ | 162 \ |
| 161 /* Illegal token - not able to scan. */ \ | 163 /* Illegal token - not able to scan. */ \ |
| 162 T(ILLEGAL, "ILLEGAL", 0) \ | 164 T(ILLEGAL, "ILLEGAL", 0) \ |
| 163 T(ESCAPED_KEYWORD, NULL, 0) \ | 165 T(ESCAPED_KEYWORD, NULL, 0) \ |
| 164 T(ESCAPED_STRICT_RESERVED_WORD, NULL, 0) \ | 166 T(ESCAPED_STRICT_RESERVED_WORD, NULL, 0) \ |
| 165 \ | 167 \ |
| 166 /* Scanner-internal use only. */ \ | 168 /* Scanner-internal use only. */ \ |
| 167 T(WHITESPACE, NULL, 0) \ | 169 T(WHITESPACE, NULL, 0) \ |
| 168 T(UNINITIALIZED, NULL, 0) \ | 170 T(UNINITIALIZED, NULL, 0) \ |
| 169 \ | 171 \ |
| 170 /* ES6 Template Literals */ \ | 172 /* ES6 Template Literals */ \ |
| 171 T(TEMPLATE_SPAN, NULL, 0) \ | 173 T(TEMPLATE_SPAN, NULL, 0) \ |
| 172 T(TEMPLATE_TAIL, NULL, 0) | 174 T(TEMPLATE_TAIL, NULL, 0) |
| 173 | 175 |
| 174 | |
| 175 class Token { | 176 class Token { |
| 176 public: | 177 public: |
| 177 // All token values. | 178 // All token values. |
| 178 #define T(name, string, precedence) name, | 179 #define T(name, string, precedence) name, |
| 179 enum Value { | 180 enum Value { |
| 180 TOKEN_LIST(T, T) | 181 TOKEN_LIST(T, T) |
| 181 NUM_TOKENS | 182 NUM_TOKENS |
| 182 }; | 183 }; |
| 183 #undef T | 184 #undef T |
| 184 | 185 |
| 185 // Returns a string corresponding to the C++ token name | 186 // Returns a string corresponding to the C++ token name |
| 186 // (e.g. "LT" for the token LT). | 187 // (e.g. "LT" for the token LT). |
| 187 static const char* Name(Value tok) { | 188 static const char* Name(Value tok) { |
| 188 DCHECK(tok < NUM_TOKENS); // tok is unsigned | 189 DCHECK(tok < NUM_TOKENS); // tok is unsigned |
| 189 return name_[tok]; | 190 return name_[tok]; |
| 190 } | 191 } |
| 191 | 192 |
| 192 // Predicates | 193 // Predicates |
| 193 static bool IsKeyword(Value tok) { | 194 static bool IsKeyword(Value tok) { |
| 194 return token_type[tok] == 'K'; | 195 return token_type[tok] == 'K'; |
| 195 } | 196 } |
| 196 | 197 |
| 197 static bool IsIdentifier(Value tok, LanguageMode language_mode, | 198 static bool IsIdentifier(Value tok, LanguageMode language_mode, |
| 198 bool is_generator) { | 199 bool is_generator, bool is_module) { |
|
mike3
2016/02/23 19:29:44
This method is starting to succumb to the boolean
| |
| 199 switch (tok) { | 200 switch (tok) { |
| 200 case IDENTIFIER: | 201 case IDENTIFIER: |
| 201 return true; | 202 return true; |
| 202 case ESCAPED_STRICT_RESERVED_WORD: | 203 case ESCAPED_STRICT_RESERVED_WORD: |
| 203 case FUTURE_STRICT_RESERVED_WORD: | 204 case FUTURE_STRICT_RESERVED_WORD: |
| 204 case LET: | 205 case LET: |
| 205 case STATIC: | 206 case STATIC: |
| 206 return is_sloppy(language_mode); | 207 return is_sloppy(language_mode); |
| 207 case YIELD: | 208 case YIELD: |
| 208 return !is_generator && is_sloppy(language_mode); | 209 return !is_generator && is_sloppy(language_mode); |
| 210 case AWAIT: | |
| 211 return !is_module; | |
| 209 default: | 212 default: |
| 210 return false; | 213 return false; |
| 211 } | 214 } |
| 212 UNREACHABLE(); | 215 UNREACHABLE(); |
| 213 return false; | 216 return false; |
| 214 } | 217 } |
| 215 | 218 |
| 216 static bool IsAssignmentOp(Value tok) { | 219 static bool IsAssignmentOp(Value tok) { |
| 217 return INIT <= tok && tok <= ASSIGN_MOD; | 220 return INIT <= tok && tok <= ASSIGN_MOD; |
| 218 } | 221 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 static const char* const name_[NUM_TOKENS]; | 334 static const char* const name_[NUM_TOKENS]; |
| 332 static const char* const string_[NUM_TOKENS]; | 335 static const char* const string_[NUM_TOKENS]; |
| 333 static const int8_t precedence_[NUM_TOKENS]; | 336 static const int8_t precedence_[NUM_TOKENS]; |
| 334 static const char token_type[NUM_TOKENS]; | 337 static const char token_type[NUM_TOKENS]; |
| 335 }; | 338 }; |
| 336 | 339 |
| 337 } // namespace internal | 340 } // namespace internal |
| 338 } // namespace v8 | 341 } // namespace v8 |
| 339 | 342 |
| 340 #endif // V8_PARSING_TOKEN_H_ | 343 #endif // V8_PARSING_TOKEN_H_ |
| OLD | NEW |