| 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_TOKEN_H_ | 5 #ifndef V8_TOKEN_H_ |
| 6 #define V8_TOKEN_H_ | 6 #define V8_TOKEN_H_ |
| 7 | 7 |
| 8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 #define T(name, string, precedence) name, | 167 #define T(name, string, precedence) name, |
| 168 enum Value { | 168 enum Value { |
| 169 TOKEN_LIST(T, T) | 169 TOKEN_LIST(T, T) |
| 170 NUM_TOKENS | 170 NUM_TOKENS |
| 171 }; | 171 }; |
| 172 #undef T | 172 #undef T |
| 173 | 173 |
| 174 // Returns a string corresponding to the C++ token name | 174 // Returns a string corresponding to the C++ token name |
| 175 // (e.g. "LT" for the token LT). | 175 // (e.g. "LT" for the token LT). |
| 176 static const char* Name(Value tok) { | 176 static const char* Name(Value tok) { |
| 177 ASSERT(tok < NUM_TOKENS); // tok is unsigned | 177 DCHECK(tok < NUM_TOKENS); // tok is unsigned |
| 178 return name_[tok]; | 178 return name_[tok]; |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Predicates | 181 // Predicates |
| 182 static bool IsKeyword(Value tok) { | 182 static bool IsKeyword(Value tok) { |
| 183 return token_type[tok] == 'K'; | 183 return token_type[tok] == 'K'; |
| 184 } | 184 } |
| 185 | 185 |
| 186 static bool IsAssignmentOp(Value tok) { | 186 static bool IsAssignmentOp(Value tok) { |
| 187 return INIT_VAR <= tok && tok <= ASSIGN_MOD; | 187 return INIT_VAR <= tok && tok <= ASSIGN_MOD; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 210 static bool IsInequalityOp(Value op) { | 210 static bool IsInequalityOp(Value op) { |
| 211 return op == NE || op == NE_STRICT; | 211 return op == NE || op == NE_STRICT; |
| 212 } | 212 } |
| 213 | 213 |
| 214 static bool IsArithmeticCompareOp(Value op) { | 214 static bool IsArithmeticCompareOp(Value op) { |
| 215 return IsOrderedRelationalCompareOp(op) || | 215 return IsOrderedRelationalCompareOp(op) || |
| 216 IsEqualityOp(op) || IsInequalityOp(op); | 216 IsEqualityOp(op) || IsInequalityOp(op); |
| 217 } | 217 } |
| 218 | 218 |
| 219 static Value NegateCompareOp(Value op) { | 219 static Value NegateCompareOp(Value op) { |
| 220 ASSERT(IsArithmeticCompareOp(op)); | 220 DCHECK(IsArithmeticCompareOp(op)); |
| 221 switch (op) { | 221 switch (op) { |
| 222 case EQ: return NE; | 222 case EQ: return NE; |
| 223 case NE: return EQ; | 223 case NE: return EQ; |
| 224 case EQ_STRICT: return NE_STRICT; | 224 case EQ_STRICT: return NE_STRICT; |
| 225 case NE_STRICT: return EQ_STRICT; | 225 case NE_STRICT: return EQ_STRICT; |
| 226 case LT: return GTE; | 226 case LT: return GTE; |
| 227 case GT: return LTE; | 227 case GT: return LTE; |
| 228 case LTE: return GT; | 228 case LTE: return GT; |
| 229 case GTE: return LT; | 229 case GTE: return LT; |
| 230 default: | 230 default: |
| 231 UNREACHABLE(); | 231 UNREACHABLE(); |
| 232 return op; | 232 return op; |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 static Value ReverseCompareOp(Value op) { | 236 static Value ReverseCompareOp(Value op) { |
| 237 ASSERT(IsArithmeticCompareOp(op)); | 237 DCHECK(IsArithmeticCompareOp(op)); |
| 238 switch (op) { | 238 switch (op) { |
| 239 case EQ: return EQ; | 239 case EQ: return EQ; |
| 240 case NE: return NE; | 240 case NE: return NE; |
| 241 case EQ_STRICT: return EQ_STRICT; | 241 case EQ_STRICT: return EQ_STRICT; |
| 242 case NE_STRICT: return NE_STRICT; | 242 case NE_STRICT: return NE_STRICT; |
| 243 case LT: return GT; | 243 case LT: return GT; |
| 244 case GT: return LT; | 244 case GT: return LT; |
| 245 case LTE: return GTE; | 245 case LTE: return GTE; |
| 246 case GTE: return LTE; | 246 case GTE: return LTE; |
| 247 default: | 247 default: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 263 } | 263 } |
| 264 | 264 |
| 265 static bool IsShiftOp(Value op) { | 265 static bool IsShiftOp(Value op) { |
| 266 return (SHL <= op) && (op <= SHR); | 266 return (SHL <= op) && (op <= SHR); |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Returns a string corresponding to the JS token string | 269 // Returns a string corresponding to the JS token string |
| 270 // (.e., "<" for the token LT) or NULL if the token doesn't | 270 // (.e., "<" for the token LT) or NULL if the token doesn't |
| 271 // have a (unique) string (e.g. an IDENTIFIER). | 271 // have a (unique) string (e.g. an IDENTIFIER). |
| 272 static const char* String(Value tok) { | 272 static const char* String(Value tok) { |
| 273 ASSERT(tok < NUM_TOKENS); // tok is unsigned. | 273 DCHECK(tok < NUM_TOKENS); // tok is unsigned. |
| 274 return string_[tok]; | 274 return string_[tok]; |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Returns the precedence > 0 for binary and compare | 277 // Returns the precedence > 0 for binary and compare |
| 278 // operators; returns 0 otherwise. | 278 // operators; returns 0 otherwise. |
| 279 static int Precedence(Value tok) { | 279 static int Precedence(Value tok) { |
| 280 ASSERT(tok < NUM_TOKENS); // tok is unsigned. | 280 DCHECK(tok < NUM_TOKENS); // tok is unsigned. |
| 281 return precedence_[tok]; | 281 return precedence_[tok]; |
| 282 } | 282 } |
| 283 | 283 |
| 284 private: | 284 private: |
| 285 static const char* const name_[NUM_TOKENS]; | 285 static const char* const name_[NUM_TOKENS]; |
| 286 static const char* const string_[NUM_TOKENS]; | 286 static const char* const string_[NUM_TOKENS]; |
| 287 static const int8_t precedence_[NUM_TOKENS]; | 287 static const int8_t precedence_[NUM_TOKENS]; |
| 288 static const char token_type[NUM_TOKENS]; | 288 static const char token_type[NUM_TOKENS]; |
| 289 }; | 289 }; |
| 290 | 290 |
| 291 } } // namespace v8::internal | 291 } } // namespace v8::internal |
| 292 | 292 |
| 293 #endif // V8_TOKEN_H_ | 293 #endif // V8_TOKEN_H_ |
| OLD | NEW |