| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_TOKEN_H_ | 5 #ifndef VM_TOKEN_H_ |
| 6 #define VM_TOKEN_H_ | 6 #define VM_TOKEN_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" |
| 9 | 10 |
| 10 namespace dart { | 11 namespace dart { |
| 11 | 12 |
| 12 // Operator precedence table | 13 // Operator precedence table |
| 13 // | 14 // |
| 14 // 14 multiplicative * / ~/ % | 15 // 14 multiplicative * / ~/ % |
| 15 // 13 additive + - | 16 // 13 additive + - |
| 16 // 12 shift << >> | 17 // 12 shift << >> |
| 17 // 11 bitwise and & | 18 // 11 bitwise and & |
| 18 // 10 bitwise xor ^ | 19 // 10 bitwise xor ^ |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 enum Attribute { | 210 enum Attribute { |
| 210 kNoAttribute = 0, | 211 kNoAttribute = 0, |
| 211 kKeyword = 1 << 0, | 212 kKeyword = 1 << 0, |
| 212 kPseudoKeyword = 1 << 1, | 213 kPseudoKeyword = 1 << 1, |
| 213 }; | 214 }; |
| 214 | 215 |
| 215 static const Kind kFirstKeyword = kABSTRACT; | 216 static const Kind kFirstKeyword = kABSTRACT; |
| 216 static const Kind kLastKeyword = kWITH; | 217 static const Kind kLastKeyword = kWITH; |
| 217 static const int kNumKeywords = kLastKeyword - kFirstKeyword + 1; | 218 static const int kNumKeywords = kLastKeyword - kFirstKeyword + 1; |
| 218 | 219 |
| 220 static const intptr_t kNoSourcePos = -1; |
| 221 |
| 219 static bool IsAssignmentOperator(Kind tok) { | 222 static bool IsAssignmentOperator(Kind tok) { |
| 220 return kASSIGN <= tok && tok <= kASSIGN_COND; | 223 return kASSIGN <= tok && tok <= kASSIGN_COND; |
| 221 } | 224 } |
| 222 | 225 |
| 223 static bool IsRelationalOperator(Kind tok) { | 226 static bool IsRelationalOperator(Kind tok) { |
| 224 return kLT <= tok && tok <= kGTE; | 227 return kLT <= tok && tok <= kGTE; |
| 225 } | 228 } |
| 226 | 229 |
| 227 static bool IsEqualityOperator(Kind tok) { | 230 static bool IsEqualityOperator(Kind tok) { |
| 228 return kEQ <= tok && tok <= kNE_STRICT; | 231 return kEQ <= tok && tok <= kNE_STRICT; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 325 } |
| 323 | 326 |
| 324 private: | 327 private: |
| 325 static const char* name_[]; | 328 static const char* name_[]; |
| 326 static const char* tok_str_[]; | 329 static const char* tok_str_[]; |
| 327 static const uint8_t precedence_[]; | 330 static const uint8_t precedence_[]; |
| 328 static const Attribute attributes_[]; | 331 static const Attribute attributes_[]; |
| 329 }; | 332 }; |
| 330 | 333 |
| 331 | 334 |
| 335 // These token positions are used to classify instructions that can't be |
| 336 // directly tied to an actual source position. |
| 337 #define CLASSIFYING_TOKEN_POSITIONS(V) \ |
| 338 V(Private, -2) \ |
| 339 V(Box, -3) \ |
| 340 V(ParallelMove, -4) \ |
| 341 V(TempMove, -5) \ |
| 342 V(Constant, -6) \ |
| 343 V(PushArgument, -7) \ |
| 344 V(ControlFlow, -8) \ |
| 345 V(Context, -9) \ |
| 346 V(MethodExtractor, -10) |
| 347 |
| 348 // COMPILE_ASSERT that all CLASSIFYING_TOKEN_POSITIONS are less than |
| 349 // Token::kNoSourcePos. |
| 350 #define SANITY_CHECK_VALUES(name, value) \ |
| 351 COMPILE_ASSERT(value < Token::kNoSourcePos); |
| 352 CLASSIFYING_TOKEN_POSITIONS(SANITY_CHECK_VALUES); |
| 353 #undef SANITY_CHECK_VALUES |
| 354 |
| 355 class ClassifyingTokenPositions : public AllStatic { |
| 356 public: |
| 357 #define DEFINE_VALUES(name, value) \ |
| 358 static const intptr_t k##name = value; |
| 359 CLASSIFYING_TOKEN_POSITIONS(DEFINE_VALUES); |
| 360 #undef DEFINE_VALUES |
| 361 |
| 362 static const char* ToCString(intptr_t token_pos) { |
| 363 ASSERT(token_pos < 0); |
| 364 switch (token_pos) { |
| 365 case Token::kNoSourcePos: return "NoSource"; |
| 366 #define DEFINE_CASE(name, value) \ |
| 367 case value: return #name; |
| 368 CLASSIFYING_TOKEN_POSITIONS(DEFINE_CASE); |
| 369 #undef DEFINE_CASE |
| 370 default: |
| 371 UNIMPLEMENTED(); |
| 372 return NULL; |
| 373 } |
| 374 } |
| 375 }; |
| 376 |
| 332 } // namespace dart | 377 } // namespace dart |
| 333 | 378 |
| 334 #endif // VM_TOKEN_H_ | 379 #endif // VM_TOKEN_H_ |
| OLD | NEW |