| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #include "vm/token.h" | 5 #include "vm/token.h" |
| 6 | 6 |
| 7 #include "vm/object.h" |
| 8 |
| 7 namespace dart { | 9 namespace dart { |
| 8 | 10 |
| 9 #define TOKEN_NAME(t, s, p, a) #t, | 11 #define TOKEN_NAME(t, s, p, a) #t, |
| 10 const char* Token::name_[] = { | 12 const char* Token::name_[] = { |
| 11 DART_TOKEN_LIST(TOKEN_NAME) | 13 DART_TOKEN_LIST(TOKEN_NAME) |
| 12 DART_KEYWORD_LIST(TOKEN_NAME) | 14 DART_KEYWORD_LIST(TOKEN_NAME) |
| 13 }; | 15 }; |
| 14 #undef TOKEN_NAME | 16 #undef TOKEN_NAME |
| 15 | 17 |
| 16 #define TOKEN_STRING(t, s, p, a) s, | 18 #define TOKEN_STRING(t, s, p, a) s, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 #undef TOKEN_PRECEDENCE | 30 #undef TOKEN_PRECEDENCE |
| 29 | 31 |
| 30 #define TOKEN_ATTRIBUTE(t, s, p, a) a, | 32 #define TOKEN_ATTRIBUTE(t, s, p, a) a, |
| 31 const Token::Attribute Token::attributes_[] = { | 33 const Token::Attribute Token::attributes_[] = { |
| 32 DART_TOKEN_LIST(TOKEN_ATTRIBUTE) | 34 DART_TOKEN_LIST(TOKEN_ATTRIBUTE) |
| 33 DART_KEYWORD_LIST(TOKEN_ATTRIBUTE) | 35 DART_KEYWORD_LIST(TOKEN_ATTRIBUTE) |
| 34 }; | 36 }; |
| 35 #undef TOKEN_ATTRIBUTE | 37 #undef TOKEN_ATTRIBUTE |
| 36 | 38 |
| 37 | 39 |
| 40 Token::Kind Token::GetBinaryOp(const String& name) { |
| 41 if (name.Length() == 1) { |
| 42 switch (name.CharAt(0)) { |
| 43 case '+' : return Token::kADD; |
| 44 case '-' : return Token::kSUB; |
| 45 case '*' : return Token::kMUL; |
| 46 case '/' : return Token::kDIV; |
| 47 case '%' : return Token::kMOD; |
| 48 case '|' : return Token::kBIT_OR; |
| 49 case '^' : return Token::kBIT_XOR; |
| 50 case '&' : return Token::kBIT_AND; |
| 51 default: return Token::kILLEGAL; // Not a binary operation. |
| 52 } |
| 53 } |
| 54 if (name.Length() == 2) { |
| 55 switch (name.CharAt(0)) { |
| 56 case '|' : return name.CharAt(1) == '|' ? Token::kOR : Token::kILLEGAL; |
| 57 case '&' : return name.CharAt(1) == '&' ? Token::kAND : Token::kILLEGAL; |
| 58 case '<' : return name.CharAt(1) == '<' ? Token::kSHL : Token::kILLEGAL; |
| 59 case '>' : return name.CharAt(1) == '>' ? Token::kSHR : Token::kILLEGAL; |
| 60 case '~' : |
| 61 return name.CharAt(1) == '/' ? Token::kTRUNCDIV : Token::kILLEGAL; |
| 62 default: return Token::kILLEGAL; // Not a binary operation. |
| 63 } |
| 64 } |
| 65 return Token::kILLEGAL; |
| 66 } |
| 67 |
| 68 |
| 38 } // namespace dart | 69 } // namespace dart |
| OLD | NEW |