OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 #define T(name, string, precedence) name, | 210 #define T(name, string, precedence) name, |
211 enum Value { | 211 enum Value { |
212 TOKEN_LIST(T, T, IGNORE_TOKEN) | 212 TOKEN_LIST(T, T, IGNORE_TOKEN) |
213 NUM_TOKENS | 213 NUM_TOKENS |
214 }; | 214 }; |
215 #undef T | 215 #undef T |
216 | 216 |
217 // Returns a string corresponding to the C++ token name | 217 // Returns a string corresponding to the C++ token name |
218 // (e.g. "LT" for the token LT). | 218 // (e.g. "LT" for the token LT). |
219 static const char* Name(Value tok) { | 219 static const char* Name(Value tok) { |
220 ASSERT(0 <= tok && tok < NUM_TOKENS); | 220 ASSERT(tok < NUM_TOKENS); // tok is unsigned |
221 return name_[tok]; | 221 return name_[tok]; |
222 } | 222 } |
223 | 223 |
224 // Predicates | 224 // Predicates |
225 static bool IsKeyword(Value tok) { | 225 static bool IsKeyword(Value tok) { |
226 return token_type[tok] == 'K'; | 226 return token_type[tok] == 'K'; |
227 } | 227 } |
228 | 228 |
229 static bool IsAssignmentOp(Value tok) { | 229 static bool IsAssignmentOp(Value tok) { |
230 return INIT_VAR <= tok && tok <= ASSIGN_MOD; | 230 return INIT_VAR <= tok && tok <= ASSIGN_MOD; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 285 } |
286 | 286 |
287 static bool IsShiftOp(Value op) { | 287 static bool IsShiftOp(Value op) { |
288 return (SHL <= op) && (op <= SHR); | 288 return (SHL <= op) && (op <= SHR); |
289 } | 289 } |
290 | 290 |
291 // Returns a string corresponding to the JS token string | 291 // Returns a string corresponding to the JS token string |
292 // (.e., "<" for the token LT) or NULL if the token doesn't | 292 // (.e., "<" for the token LT) or NULL if the token doesn't |
293 // have a (unique) string (e.g. an IDENTIFIER). | 293 // have a (unique) string (e.g. an IDENTIFIER). |
294 static const char* String(Value tok) { | 294 static const char* String(Value tok) { |
295 ASSERT(0 <= tok && tok < NUM_TOKENS); | 295 ASSERT(tok < NUM_TOKENS); // tok is unsigned. |
296 return string_[tok]; | 296 return string_[tok]; |
297 } | 297 } |
298 | 298 |
299 // Returns the precedence > 0 for binary and compare | 299 // Returns the precedence > 0 for binary and compare |
300 // operators; returns 0 otherwise. | 300 // operators; returns 0 otherwise. |
301 static int Precedence(Value tok) { | 301 static int Precedence(Value tok) { |
302 ASSERT(0 <= tok && tok < NUM_TOKENS); | 302 ASSERT(tok < NUM_TOKENS); // tok is unsigned. |
303 return precedence_[tok]; | 303 return precedence_[tok]; |
304 } | 304 } |
305 | 305 |
306 private: | 306 private: |
307 static const char* name_[NUM_TOKENS]; | 307 static const char* name_[NUM_TOKENS]; |
308 static const char* string_[NUM_TOKENS]; | 308 static const char* string_[NUM_TOKENS]; |
309 static int8_t precedence_[NUM_TOKENS]; | 309 static int8_t precedence_[NUM_TOKENS]; |
310 static const char token_type[NUM_TOKENS]; | 310 static const char token_type[NUM_TOKENS]; |
311 }; | 311 }; |
312 | 312 |
313 } } // namespace v8::internal | 313 } } // namespace v8::internal |
314 | 314 |
315 #endif // V8_TOKEN_H_ | 315 #endif // V8_TOKEN_H_ |
OLD | NEW |