| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 K(TRUE_LITERAL, "true", 0) \ | 141 K(TRUE_LITERAL, "true", 0) \ |
| 142 K(FALSE_LITERAL, "false", 0) \ | 142 K(FALSE_LITERAL, "false", 0) \ |
| 143 T(NUMBER, NULL, 0) \ | 143 T(NUMBER, NULL, 0) \ |
| 144 T(SMI, NULL, 0) \ | 144 T(SMI, NULL, 0) \ |
| 145 T(STRING, NULL, 0) \ | 145 T(STRING, NULL, 0) \ |
| 146 \ | 146 \ |
| 147 /* Identifiers (not keywords or future reserved words). */ \ | 147 /* Identifiers (not keywords or future reserved words). */ \ |
| 148 T(IDENTIFIER, NULL, 0) \ | 148 T(IDENTIFIER, NULL, 0) \ |
| 149 \ | 149 \ |
| 150 /* Future reserved words (ECMA-262, section 7.6.1.2). */ \ | 150 /* Future reserved words (ECMA-262, section 7.6.1.2). */ \ |
| 151 T(FUTURE_RESERVED_WORD, NULL, 0) \ | |
| 152 T(FUTURE_STRICT_RESERVED_WORD, NULL, 0) \ | 151 T(FUTURE_STRICT_RESERVED_WORD, NULL, 0) \ |
| 152 /* `await` is a reserved word in module code only */ \ |
| 153 K(AWAIT, "await", 0) \ |
| 153 K(CLASS, "class", 0) \ | 154 K(CLASS, "class", 0) \ |
| 154 K(CONST, "const", 0) \ | 155 K(CONST, "const", 0) \ |
| 156 K(ENUM, "enum", 0) \ |
| 155 K(EXPORT, "export", 0) \ | 157 K(EXPORT, "export", 0) \ |
| 156 K(EXTENDS, "extends", 0) \ | 158 K(EXTENDS, "extends", 0) \ |
| 157 K(IMPORT, "import", 0) \ | 159 K(IMPORT, "import", 0) \ |
| 158 K(LET, "let", 0) \ | 160 K(LET, "let", 0) \ |
| 159 K(STATIC, "static", 0) \ | 161 K(STATIC, "static", 0) \ |
| 160 K(YIELD, "yield", 0) \ | 162 K(YIELD, "yield", 0) \ |
| 161 K(SUPER, "super", 0) \ | 163 K(SUPER, "super", 0) \ |
| 162 \ | 164 \ |
| 163 /* Illegal token - not able to scan. */ \ | 165 /* Illegal token - not able to scan. */ \ |
| 164 T(ILLEGAL, "ILLEGAL", 0) \ | 166 T(ILLEGAL, "ILLEGAL", 0) \ |
| 165 T(ESCAPED_KEYWORD, NULL, 0) \ | 167 T(ESCAPED_KEYWORD, NULL, 0) \ |
| 166 T(ESCAPED_STRICT_RESERVED_WORD, NULL, 0) \ | 168 T(ESCAPED_STRICT_RESERVED_WORD, NULL, 0) \ |
| 167 \ | 169 \ |
| 168 /* Scanner-internal use only. */ \ | 170 /* Scanner-internal use only. */ \ |
| 169 T(WHITESPACE, NULL, 0) \ | 171 T(WHITESPACE, NULL, 0) \ |
| 170 T(UNINITIALIZED, NULL, 0) \ | 172 T(UNINITIALIZED, NULL, 0) \ |
| 171 \ | 173 \ |
| 172 /* ES6 Template Literals */ \ | 174 /* ES6 Template Literals */ \ |
| 173 T(TEMPLATE_SPAN, NULL, 0) \ | 175 T(TEMPLATE_SPAN, NULL, 0) \ |
| 174 T(TEMPLATE_TAIL, NULL, 0) | 176 T(TEMPLATE_TAIL, NULL, 0) |
| 175 | 177 |
| 176 | |
| 177 class Token { | 178 class Token { |
| 178 public: | 179 public: |
| 179 // All token values. | 180 // All token values. |
| 180 #define T(name, string, precedence) name, | 181 #define T(name, string, precedence) name, |
| 181 enum Value { | 182 enum Value { |
| 182 TOKEN_LIST(T, T) | 183 TOKEN_LIST(T, T) |
| 183 NUM_TOKENS | 184 NUM_TOKENS |
| 184 }; | 185 }; |
| 185 #undef T | 186 #undef T |
| 186 | 187 |
| 187 // Returns a string corresponding to the C++ token name | 188 // Returns a string corresponding to the C++ token name |
| 188 // (e.g. "LT" for the token LT). | 189 // (e.g. "LT" for the token LT). |
| 189 static const char* Name(Value tok) { | 190 static const char* Name(Value tok) { |
| 190 DCHECK(tok < NUM_TOKENS); // tok is unsigned | 191 DCHECK(tok < NUM_TOKENS); // tok is unsigned |
| 191 return name_[tok]; | 192 return name_[tok]; |
| 192 } | 193 } |
| 193 | 194 |
| 194 // Predicates | 195 // Predicates |
| 195 static bool IsKeyword(Value tok) { | 196 static bool IsKeyword(Value tok) { |
| 196 return token_type[tok] == 'K'; | 197 return token_type[tok] == 'K'; |
| 197 } | 198 } |
| 198 | 199 |
| 199 static bool IsIdentifier(Value tok, LanguageMode language_mode, | 200 static bool IsIdentifier(Value tok, LanguageMode language_mode, |
| 200 bool is_generator) { | 201 bool is_generator, bool is_module) { |
| 201 switch (tok) { | 202 switch (tok) { |
| 202 case IDENTIFIER: | 203 case IDENTIFIER: |
| 203 return true; | 204 return true; |
| 204 case ESCAPED_STRICT_RESERVED_WORD: | 205 case ESCAPED_STRICT_RESERVED_WORD: |
| 205 case FUTURE_STRICT_RESERVED_WORD: | 206 case FUTURE_STRICT_RESERVED_WORD: |
| 206 case LET: | 207 case LET: |
| 207 case STATIC: | 208 case STATIC: |
| 208 return is_sloppy(language_mode); | 209 return is_sloppy(language_mode); |
| 209 case YIELD: | 210 case YIELD: |
| 210 return !is_generator && is_sloppy(language_mode); | 211 return !is_generator && is_sloppy(language_mode); |
| 212 case AWAIT: |
| 213 return !is_module; |
| 211 default: | 214 default: |
| 212 return false; | 215 return false; |
| 213 } | 216 } |
| 214 UNREACHABLE(); | 217 UNREACHABLE(); |
| 215 return false; | 218 return false; |
| 216 } | 219 } |
| 217 | 220 |
| 218 static bool IsAssignmentOp(Value tok) { | 221 static bool IsAssignmentOp(Value tok) { |
| 219 return INIT <= tok && tok <= ASSIGN_EXP; | 222 return INIT <= tok && tok <= ASSIGN_EXP; |
| 220 } | 223 } |
| (...skipping 110 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 |