| 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" | 7 #include "vm/object.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #undef TOKEN_PRECEDENCE | 30 #undef TOKEN_PRECEDENCE |
| 31 | 31 |
| 32 #define TOKEN_ATTRIBUTE(t, s, p, a) a, | 32 #define TOKEN_ATTRIBUTE(t, s, p, a) a, |
| 33 const Token::Attribute Token::attributes_[] = { | 33 const Token::Attribute Token::attributes_[] = { |
| 34 DART_TOKEN_LIST(TOKEN_ATTRIBUTE) | 34 DART_TOKEN_LIST(TOKEN_ATTRIBUTE) |
| 35 DART_KEYWORD_LIST(TOKEN_ATTRIBUTE) | 35 DART_KEYWORD_LIST(TOKEN_ATTRIBUTE) |
| 36 }; | 36 }; |
| 37 #undef TOKEN_ATTRIBUTE | 37 #undef TOKEN_ATTRIBUTE |
| 38 | 38 |
| 39 | 39 |
| 40 Token::Kind Token::GetBinaryOp(const String& name) { | 40 bool Token::IsBinaryToken(Token::Kind token) { |
| 41 if (name.Length() == 1) { | 41 switch (token) { |
| 42 switch (name.CharAt(0)) { | 42 case Token::kADD: |
| 43 case '+' : return Token::kADD; | 43 case Token::kSUB: |
| 44 case '-' : return Token::kSUB; | 44 case Token::kMUL: |
| 45 case '*' : return Token::kMUL; | 45 case Token::kDIV: |
| 46 case '/' : return Token::kDIV; | 46 case Token::kTRUNCDIV: |
| 47 case '%' : return Token::kMOD; | 47 case Token::kMOD: |
| 48 case '|' : return Token::kBIT_OR; | 48 case Token::kBIT_OR: |
| 49 case '^' : return Token::kBIT_XOR; | 49 case Token::kBIT_XOR: |
| 50 case '&' : return Token::kBIT_AND; | 50 case Token::kBIT_AND: |
| 51 default: return Token::kILLEGAL; // Not a binary operation. | 51 case Token::kOR: |
| 52 } | 52 case Token::kAND: |
| 53 case Token::kSHL: |
| 54 case Token::kSHR: |
| 55 return true; |
| 56 default: |
| 57 return false; |
| 53 } | 58 } |
| 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 } | 59 } |
| 67 | 60 |
| 68 | 61 |
| 69 Token::Kind Token::GetUnaryOp(const String& name) { | 62 bool Token::IsUnaryToken(Token::Kind token) { |
| 70 if (name.Equals(Str(Token::kNEGATE))) { | 63 return (token == Token::kNEGATE) || (token == kBIT_NOT); |
| 71 return Token::kNEGATE; | |
| 72 } | |
| 73 if ((name.Length() == 1) && (name.CharAt(0) == '~')) { | |
| 74 return Token::kBIT_NOT; | |
| 75 } | |
| 76 return Token::kILLEGAL; | |
| 77 } | 64 } |
| 78 | 65 |
| 79 | |
| 80 } // namespace dart | 66 } // namespace dart |
| OLD | NEW |