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 153 matching lines...) Loading... |
164 K(SUPER, "super", 0) \ | 164 K(SUPER, "super", 0) \ |
165 \ | 165 \ |
166 /* Illegal token - not able to scan. */ \ | 166 /* Illegal token - not able to scan. */ \ |
167 T(ILLEGAL, "ILLEGAL", 0) \ | 167 T(ILLEGAL, "ILLEGAL", 0) \ |
168 T(ESCAPED_KEYWORD, NULL, 0) \ | 168 T(ESCAPED_KEYWORD, NULL, 0) \ |
169 T(ESCAPED_STRICT_RESERVED_WORD, NULL, 0) \ | 169 T(ESCAPED_STRICT_RESERVED_WORD, NULL, 0) \ |
170 \ | 170 \ |
171 /* Scanner-internal use only. */ \ | 171 /* Scanner-internal use only. */ \ |
172 T(WHITESPACE, NULL, 0) \ | 172 T(WHITESPACE, NULL, 0) \ |
173 T(UNINITIALIZED, NULL, 0) \ | 173 T(UNINITIALIZED, NULL, 0) \ |
| 174 T(REGEXP_LITERAL, NULL, 0) \ |
174 \ | 175 \ |
175 /* ES6 Template Literals */ \ | 176 /* ES6 Template Literals */ \ |
176 T(TEMPLATE_SPAN, NULL, 0) \ | 177 T(TEMPLATE_SPAN, NULL, 0) \ |
177 T(TEMPLATE_TAIL, NULL, 0) | 178 T(TEMPLATE_TAIL, NULL, 0) |
178 | 179 |
179 class Token { | 180 class Token { |
180 public: | 181 public: |
181 // All token values. | 182 // All token values. |
182 #define T(name, string, precedence) name, | 183 #define T(name, string, precedence) name, |
183 enum Value { | 184 enum Value { |
(...skipping 134 matching lines...) Loading... |
318 } | 319 } |
319 | 320 |
320 // Returns a string corresponding to the JS token string | 321 // Returns a string corresponding to the JS token string |
321 // (.e., "<" for the token LT) or NULL if the token doesn't | 322 // (.e., "<" for the token LT) or NULL if the token doesn't |
322 // have a (unique) string (e.g. an IDENTIFIER). | 323 // have a (unique) string (e.g. an IDENTIFIER). |
323 static const char* String(Value tok) { | 324 static const char* String(Value tok) { |
324 DCHECK(tok < NUM_TOKENS); // tok is unsigned. | 325 DCHECK(tok < NUM_TOKENS); // tok is unsigned. |
325 return string_[tok]; | 326 return string_[tok]; |
326 } | 327 } |
327 | 328 |
| 329 static uint8_t StringLength(Value tok) { |
| 330 DCHECK(tok < NUM_TOKENS); |
| 331 return string_length_[tok]; |
| 332 } |
| 333 |
328 // Returns the precedence > 0 for binary and compare | 334 // Returns the precedence > 0 for binary and compare |
329 // operators; returns 0 otherwise. | 335 // operators; returns 0 otherwise. |
330 static int Precedence(Value tok) { | 336 static int Precedence(Value tok) { |
331 DCHECK(tok < NUM_TOKENS); // tok is unsigned. | 337 DCHECK(tok < NUM_TOKENS); // tok is unsigned. |
332 return precedence_[tok]; | 338 return precedence_[tok]; |
333 } | 339 } |
334 | 340 |
335 private: | 341 private: |
336 static const char* const name_[NUM_TOKENS]; | 342 static const char* const name_[NUM_TOKENS]; |
337 static const char* const string_[NUM_TOKENS]; | 343 static const char* const string_[NUM_TOKENS]; |
| 344 static const uint8_t string_length_[NUM_TOKENS]; |
338 static const int8_t precedence_[NUM_TOKENS]; | 345 static const int8_t precedence_[NUM_TOKENS]; |
339 static const char token_type[NUM_TOKENS]; | 346 static const char token_type[NUM_TOKENS]; |
340 }; | 347 }; |
341 | 348 |
342 } // namespace internal | 349 } // namespace internal |
343 } // namespace v8 | 350 } // namespace v8 |
344 | 351 |
345 #endif // V8_PARSING_TOKEN_H_ | 352 #endif // V8_PARSING_TOKEN_H_ |
OLD | NEW |