Chromium Code Reviews| 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 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 // Operator precedence table | 12 // Operator precedence table |
| 13 // | 13 // |
| 14 // 13 multiplicative * / ~/ % | 14 // 14 multiplicative * / ~/ % |
| 15 // 12 additive + - | 15 // 13 additive + - |
| 16 // 11 shift << >> | 16 // 12 shift << >> |
| 17 // 10 bitwise and & | 17 // 11 bitwise and & |
| 18 // 9 bitwise xor ^ | 18 // 10 bitwise xor ^ |
| 19 // 8 bitwise or | | 19 // 9 bitwise or | |
| 20 // 7 relational >= > <= < is as | 20 // 8 relational >= > <= < is as |
| 21 // 6 equality == != === !== | 21 // 7 equality == != === !== |
| 22 // 5 logical and && | 22 // 6 logical and && |
| 23 // 4 logical or || | 23 // 5 logical or || |
| 24 // 4 null check ?? | |
| 24 // 3 conditional ? | 25 // 3 conditional ? |
| 25 // 2 assignment = *= /= ~/= %= += -= <<= >>= &= ^= |= | 26 // 2 assignment = *= /= ~/= %= += -= <<= >>= &= ^= |= ??= |
| 26 // 1 comma , | 27 // 1 comma , |
| 27 | 28 |
| 28 | 29 |
| 29 // Token definitions. | 30 // Token definitions. |
| 30 // Some operator tokens appear in blocks, e.g. assignment operators. | 31 // Some operator tokens appear in blocks, e.g. assignment operators. |
| 31 // There is code that depends on the values within a block to be | 32 // There is code that depends on the values within a block to be |
| 32 // contiguous, and on the order of values. | 33 // contiguous, and on the order of values. |
| 33 #define DART_TOKEN_LIST(TOK) \ | 34 #define DART_TOKEN_LIST(TOK) \ |
| 34 TOK(kEOS, "", 0, kNoAttribute) \ | 35 TOK(kEOS, "", 0, kNoAttribute) \ |
| 35 \ | 36 \ |
| 36 TOK(kLPAREN, "(", 0, kNoAttribute) \ | 37 TOK(kLPAREN, "(", 0, kNoAttribute) \ |
| 37 TOK(kRPAREN, ")", 0, kNoAttribute) \ | 38 TOK(kRPAREN, ")", 0, kNoAttribute) \ |
| 38 TOK(kLBRACK, "[", 0, kNoAttribute) \ | 39 TOK(kLBRACK, "[", 0, kNoAttribute) \ |
| 39 TOK(kRBRACK, "]", 0, kNoAttribute) \ | 40 TOK(kRBRACK, "]", 0, kNoAttribute) \ |
| 40 TOK(kLBRACE, "{", 0, kNoAttribute) \ | 41 TOK(kLBRACE, "{", 0, kNoAttribute) \ |
| 41 TOK(kRBRACE, "}", 0, kNoAttribute) \ | 42 TOK(kRBRACE, "}", 0, kNoAttribute) \ |
| 42 TOK(kARROW, "=>", 0, kNoAttribute) \ | 43 TOK(kARROW, "=>", 0, kNoAttribute) \ |
| 43 TOK(kCOLON, ":", 0, kNoAttribute) \ | 44 TOK(kCOLON, ":", 0, kNoAttribute) \ |
| 44 TOK(kSEMICOLON, ";", 0, kNoAttribute) \ | 45 TOK(kSEMICOLON, ";", 0, kNoAttribute) \ |
| 45 TOK(kPERIOD, ".", 0, kNoAttribute) \ | 46 TOK(kPERIOD, ".", 0, kNoAttribute) \ |
| 47 TOK(kQM_PERIOD, "?.", 0, kNoAttribute) \ | |
| 46 TOK(kINCR, "++", 0, kNoAttribute) \ | 48 TOK(kINCR, "++", 0, kNoAttribute) \ |
| 47 TOK(kDECR, "--", 0, kNoAttribute) \ | 49 TOK(kDECR, "--", 0, kNoAttribute) \ |
| 48 \ | 50 \ |
| 49 /* Assignment operators. */ \ | 51 /* Assignment operators. */ \ |
| 50 /* Please update IsAssignmentOperator() if you make */ \ | 52 /* Please update IsAssignmentOperator() if you make */ \ |
| 51 /* any changes to this block. */ \ | 53 /* any changes to this block. */ \ |
| 52 TOK(kASSIGN, "=", 2, kNoAttribute) \ | 54 TOK(kASSIGN, "=", 2, kNoAttribute) \ |
| 53 TOK(kASSIGN_OR, "|=", 2, kNoAttribute) \ | 55 TOK(kASSIGN_OR, "|=", 2, kNoAttribute) \ |
| 54 TOK(kASSIGN_XOR, "^=", 2, kNoAttribute) \ | 56 TOK(kASSIGN_XOR, "^=", 2, kNoAttribute) \ |
| 55 TOK(kASSIGN_AND, "&=", 2, kNoAttribute) \ | 57 TOK(kASSIGN_AND, "&=", 2, kNoAttribute) \ |
| 56 TOK(kASSIGN_SHL, "<<=", 2, kNoAttribute) \ | 58 TOK(kASSIGN_SHL, "<<=", 2, kNoAttribute) \ |
| 57 TOK(kASSIGN_SHR, ">>=", 2, kNoAttribute) \ | 59 TOK(kASSIGN_SHR, ">>=", 2, kNoAttribute) \ |
| 58 TOK(kASSIGN_ADD, "+=", 2, kNoAttribute) \ | 60 TOK(kASSIGN_ADD, "+=", 2, kNoAttribute) \ |
| 59 TOK(kASSIGN_SUB, "-=", 2, kNoAttribute) \ | 61 TOK(kASSIGN_SUB, "-=", 2, kNoAttribute) \ |
| 60 TOK(kASSIGN_MUL, "*=", 2, kNoAttribute) \ | 62 TOK(kASSIGN_MUL, "*=", 2, kNoAttribute) \ |
| 61 TOK(kASSIGN_TRUNCDIV, "~/=", 2, kNoAttribute) \ | 63 TOK(kASSIGN_TRUNCDIV, "~/=", 2, kNoAttribute) \ |
| 62 TOK(kASSIGN_DIV, "/=", 2, kNoAttribute) \ | 64 TOK(kASSIGN_DIV, "/=", 2, kNoAttribute) \ |
| 63 TOK(kASSIGN_MOD, "%=", 2, kNoAttribute) \ | 65 TOK(kASSIGN_MOD, "%=", 2, kNoAttribute) \ |
| 66 /* Avoid trigraph ??= below. */ \ | |
|
rmacnak
2015/05/20 23:42:43
=> Avoid C preprocessor replacing trigraph ??= bel
hausner
2015/05/21 16:07:18
Will do in follow-up CL.
| |
| 67 TOK(kASSIGN_COND, "?\?=", 2, kNoAttribute) \ | |
| 64 \ | 68 \ |
| 65 TOK(kCASCADE, "..", 2, kNoAttribute) \ | 69 TOK(kCASCADE, "..", 2, kNoAttribute) \ |
| 66 \ | 70 \ |
| 67 TOK(kCOMMA, ",", 1, kNoAttribute) \ | 71 TOK(kCOMMA, ",", 1, kNoAttribute) \ |
| 68 TOK(kOR, "||", 4, kNoAttribute) \ | 72 TOK(kOR, "||", 5, kNoAttribute) \ |
| 69 TOK(kAND, "&&", 5, kNoAttribute) \ | 73 TOK(kAND, "&&", 6, kNoAttribute) \ |
| 70 TOK(kBIT_OR, "|", 8, kNoAttribute) \ | 74 TOK(kBIT_OR, "|", 9, kNoAttribute) \ |
| 71 TOK(kBIT_XOR, "^", 9, kNoAttribute) \ | 75 TOK(kBIT_XOR, "^", 10, kNoAttribute) \ |
| 72 TOK(kBIT_AND, "&", 10, kNoAttribute) \ | 76 TOK(kBIT_AND, "&", 11, kNoAttribute) \ |
| 73 TOK(kBIT_NOT, "~", 0, kNoAttribute) \ | 77 TOK(kBIT_NOT, "~", 0, kNoAttribute) \ |
| 74 \ | 78 \ |
| 75 /* Shift operators. */ \ | 79 /* Shift operators. */ \ |
| 76 TOK(kSHL, "<<", 11, kNoAttribute) \ | 80 TOK(kSHL, "<<", 12, kNoAttribute) \ |
| 77 TOK(kSHR, ">>", 11, kNoAttribute) \ | 81 TOK(kSHR, ">>", 12, kNoAttribute) \ |
| 78 \ | 82 \ |
| 79 /* Additive operators. */ \ | 83 /* Additive operators. */ \ |
| 80 TOK(kADD, "+", 12, kNoAttribute) \ | 84 TOK(kADD, "+", 13, kNoAttribute) \ |
| 81 TOK(kSUB, "-", 12, kNoAttribute) \ | 85 TOK(kSUB, "-", 13, kNoAttribute) \ |
| 82 \ | 86 \ |
| 83 /* Multiplicative operators */ \ | 87 /* Multiplicative operators */ \ |
| 84 TOK(kMUL, "*", 13, kNoAttribute) \ | 88 TOK(kMUL, "*", 14, kNoAttribute) \ |
| 85 TOK(kDIV, "/", 13, kNoAttribute) \ | 89 TOK(kDIV, "/", 14, kNoAttribute) \ |
| 86 TOK(kTRUNCDIV, "~/", 13, kNoAttribute) \ | 90 TOK(kTRUNCDIV, "~/", 14, kNoAttribute) \ |
| 87 TOK(kMOD, "%", 13, kNoAttribute) \ | 91 TOK(kMOD, "%", 14, kNoAttribute) \ |
| 88 \ | 92 \ |
| 89 TOK(kNOT, "!", 0, kNoAttribute) \ | 93 TOK(kNOT, "!", 0, kNoAttribute) \ |
| 90 TOK(kCONDITIONAL, "?", 3, kNoAttribute) \ | 94 TOK(kCONDITIONAL, "?", 3, kNoAttribute) \ |
| 95 TOK(kIFNULL, "??", 4, kNoAttribute) \ | |
| 91 \ | 96 \ |
| 92 /* Equality operators. */ \ | 97 /* Equality operators. */ \ |
| 93 /* Please update IsEqualityOperator() if you make */ \ | 98 /* Please update IsEqualityOperator() if you make */ \ |
| 94 /* any changes to this block. */ \ | 99 /* any changes to this block. */ \ |
| 95 TOK(kEQ, "==", 6, kNoAttribute) \ | 100 TOK(kEQ, "==", 7, kNoAttribute) \ |
| 96 TOK(kNE, "!=", 6, kNoAttribute) \ | 101 TOK(kNE, "!=", 7, kNoAttribute) \ |
| 97 TOK(kEQ_STRICT, "===", 6, kNoAttribute) \ | 102 TOK(kEQ_STRICT, "===", 7, kNoAttribute) \ |
| 98 TOK(kNE_STRICT, "!==", 6, kNoAttribute) \ | 103 TOK(kNE_STRICT, "!==", 7, kNoAttribute) \ |
| 99 \ | 104 \ |
| 100 /* Relational operators. */ \ | 105 /* Relational operators. */ \ |
| 101 /* Please update IsRelationalOperator() if you make */ \ | 106 /* Please update IsRelationalOperator() if you make */ \ |
| 102 /* any changes to this block. */ \ | 107 /* any changes to this block. */ \ |
| 103 TOK(kLT, "<", 7, kNoAttribute) \ | 108 TOK(kLT, "<", 8, kNoAttribute) \ |
| 104 TOK(kGT, ">", 7, kNoAttribute) \ | 109 TOK(kGT, ">", 8, kNoAttribute) \ |
| 105 TOK(kLTE, "<=", 7, kNoAttribute) \ | 110 TOK(kLTE, "<=", 8, kNoAttribute) \ |
| 106 TOK(kGTE, ">=", 7, kNoAttribute) \ | 111 TOK(kGTE, ">=", 8, kNoAttribute) \ |
| 107 \ | 112 \ |
| 108 /* Internal token for !(expr is Type) negative type test operator */ \ | 113 /* Internal token for !(expr is Type) negative type test operator */ \ |
| 109 TOK(kISNOT, "", 10, kNoAttribute) \ | 114 TOK(kISNOT, "", 11, kNoAttribute) \ |
| 110 \ | 115 \ |
| 111 TOK(kINDEX, "[]", 0, kNoAttribute) \ | 116 TOK(kINDEX, "[]", 0, kNoAttribute) \ |
| 112 TOK(kASSIGN_INDEX, "[]=", 0, kNoAttribute) \ | 117 TOK(kASSIGN_INDEX, "[]=", 0, kNoAttribute) \ |
| 113 TOK(kNEGATE, "unary-", 0, kNoAttribute) \ | 118 TOK(kNEGATE, "unary-", 0, kNoAttribute) \ |
| 114 \ | 119 \ |
| 115 TOK(kIDENT, "", 0, kNoAttribute) \ | 120 TOK(kIDENT, "", 0, kNoAttribute) \ |
| 116 TOK(kSTRING, "", 0, kNoAttribute) \ | 121 TOK(kSTRING, "", 0, kNoAttribute) \ |
| 117 TOK(kINTEGER, "", 0, kNoAttribute) \ | 122 TOK(kINTEGER, "", 0, kNoAttribute) \ |
| 118 TOK(kDOUBLE, "", 0, kNoAttribute) \ | 123 TOK(kDOUBLE, "", 0, kNoAttribute) \ |
| 119 \ | 124 \ |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 134 \ | 139 \ |
| 135 /* Support for optimized code */ \ | 140 /* Support for optimized code */ \ |
| 136 TOK(kREM, "", 0, kNoAttribute) \ | 141 TOK(kREM, "", 0, kNoAttribute) \ |
| 137 | 142 |
| 138 // List of keywords. The list must be alphabetically ordered. The | 143 // List of keywords. The list must be alphabetically ordered. The |
| 139 // keyword recognition code depends on the ordering. | 144 // keyword recognition code depends on the ordering. |
| 140 // If you add a keyword at the beginning or end of this list, make sure | 145 // If you add a keyword at the beginning or end of this list, make sure |
| 141 // to update kFirstKeyword and kLastKeyword below. | 146 // to update kFirstKeyword and kLastKeyword below. |
| 142 #define DART_KEYWORD_LIST(KW) \ | 147 #define DART_KEYWORD_LIST(KW) \ |
| 143 KW(kABSTRACT, "abstract", 0, kPseudoKeyword) /* == kFirstKeyword */ \ | 148 KW(kABSTRACT, "abstract", 0, kPseudoKeyword) /* == kFirstKeyword */ \ |
| 144 KW(kAS, "as", 10, kPseudoKeyword) \ | 149 KW(kAS, "as", 11, kPseudoKeyword) \ |
| 145 KW(kASSERT, "assert", 10, kKeyword) \ | 150 KW(kASSERT, "assert", 11, kKeyword) \ |
| 146 KW(kBREAK, "break", 0, kKeyword) \ | 151 KW(kBREAK, "break", 0, kKeyword) \ |
| 147 KW(kCASE, "case", 0, kKeyword) \ | 152 KW(kCASE, "case", 0, kKeyword) \ |
| 148 KW(kCATCH, "catch", 0, kKeyword) \ | 153 KW(kCATCH, "catch", 0, kKeyword) \ |
| 149 KW(kCLASS, "class", 0, kKeyword) \ | 154 KW(kCLASS, "class", 0, kKeyword) \ |
| 150 KW(kCONST, "const", 0, kKeyword) \ | 155 KW(kCONST, "const", 0, kKeyword) \ |
| 151 KW(kCONTINUE, "continue", 0, kKeyword) \ | 156 KW(kCONTINUE, "continue", 0, kKeyword) \ |
| 152 KW(kDEFAULT, "default", 0, kKeyword) \ | 157 KW(kDEFAULT, "default", 0, kKeyword) \ |
| 153 KW(kDO, "do", 0, kKeyword) \ | 158 KW(kDO, "do", 0, kKeyword) \ |
| 154 KW(kELSE, "else", 0, kKeyword) \ | 159 KW(kELSE, "else", 0, kKeyword) \ |
| 155 KW(kENUM, "enum", 0, kKeyword) \ | 160 KW(kENUM, "enum", 0, kKeyword) \ |
| 156 KW(kEXPORT, "export", 0, kPseudoKeyword) \ | 161 KW(kEXPORT, "export", 0, kPseudoKeyword) \ |
| 157 KW(kEXTENDS, "extends", 0, kKeyword) \ | 162 KW(kEXTENDS, "extends", 0, kKeyword) \ |
| 158 KW(kEXTERNAL, "external", 0, kPseudoKeyword) \ | 163 KW(kEXTERNAL, "external", 0, kPseudoKeyword) \ |
| 159 KW(kFACTORY, "factory", 0, kPseudoKeyword) \ | 164 KW(kFACTORY, "factory", 0, kPseudoKeyword) \ |
| 160 KW(kFALSE, "false", 0, kKeyword) \ | 165 KW(kFALSE, "false", 0, kKeyword) \ |
| 161 KW(kFINAL, "final", 0, kKeyword) \ | 166 KW(kFINAL, "final", 0, kKeyword) \ |
| 162 KW(kFINALLY, "finally", 0, kKeyword) \ | 167 KW(kFINALLY, "finally", 0, kKeyword) \ |
| 163 KW(kFOR, "for", 0, kKeyword) \ | 168 KW(kFOR, "for", 0, kKeyword) \ |
| 164 KW(kGET, "get", 0, kPseudoKeyword) \ | 169 KW(kGET, "get", 0, kPseudoKeyword) \ |
| 165 KW(kIF, "if", 0, kKeyword) \ | 170 KW(kIF, "if", 0, kKeyword) \ |
| 166 KW(kIMPLEMENTS, "implements", 0, kPseudoKeyword) \ | 171 KW(kIMPLEMENTS, "implements", 0, kPseudoKeyword) \ |
| 167 KW(kIMPORT, "import", 0, kPseudoKeyword) \ | 172 KW(kIMPORT, "import", 0, kPseudoKeyword) \ |
| 168 KW(kIN, "in", 0, kKeyword) \ | 173 KW(kIN, "in", 0, kKeyword) \ |
| 169 KW(kIS, "is", 10, kKeyword) \ | 174 KW(kIS, "is", 11, kKeyword) \ |
| 170 KW(kLIBRARY, "library", 0, kPseudoKeyword) \ | 175 KW(kLIBRARY, "library", 0, kPseudoKeyword) \ |
| 171 KW(kNEW, "new", 0, kKeyword) \ | 176 KW(kNEW, "new", 0, kKeyword) \ |
| 172 KW(kNULL, "null", 0, kKeyword) \ | 177 KW(kNULL, "null", 0, kKeyword) \ |
| 173 KW(kOPERATOR, "operator", 0, kPseudoKeyword) \ | 178 KW(kOPERATOR, "operator", 0, kPseudoKeyword) \ |
| 174 KW(kPART, "part", 0, kPseudoKeyword) \ | 179 KW(kPART, "part", 0, kPseudoKeyword) \ |
| 175 KW(kRETHROW, "rethrow", 0, kKeyword) \ | 180 KW(kRETHROW, "rethrow", 0, kKeyword) \ |
| 176 KW(kRETURN, "return", 0, kKeyword) \ | 181 KW(kRETURN, "return", 0, kKeyword) \ |
| 177 KW(kSET, "set", 0, kPseudoKeyword) \ | 182 KW(kSET, "set", 0, kPseudoKeyword) \ |
| 178 KW(kSTATIC, "static", 0, kPseudoKeyword) \ | 183 KW(kSTATIC, "static", 0, kPseudoKeyword) \ |
| 179 KW(kSUPER, "super", 0, kKeyword) \ | 184 KW(kSUPER, "super", 0, kKeyword) \ |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 205 kNoAttribute = 0, | 210 kNoAttribute = 0, |
| 206 kKeyword = 1 << 0, | 211 kKeyword = 1 << 0, |
| 207 kPseudoKeyword = 1 << 1, | 212 kPseudoKeyword = 1 << 1, |
| 208 }; | 213 }; |
| 209 | 214 |
| 210 static const Kind kFirstKeyword = kABSTRACT; | 215 static const Kind kFirstKeyword = kABSTRACT; |
| 211 static const Kind kLastKeyword = kWITH; | 216 static const Kind kLastKeyword = kWITH; |
| 212 static const int kNumKeywords = kLastKeyword - kFirstKeyword + 1; | 217 static const int kNumKeywords = kLastKeyword - kFirstKeyword + 1; |
| 213 | 218 |
| 214 static bool IsAssignmentOperator(Kind tok) { | 219 static bool IsAssignmentOperator(Kind tok) { |
| 215 return kASSIGN <= tok && tok <= kASSIGN_MOD; | 220 return kASSIGN <= tok && tok <= kASSIGN_COND; |
| 216 } | 221 } |
| 217 | 222 |
| 218 static bool IsRelationalOperator(Kind tok) { | 223 static bool IsRelationalOperator(Kind tok) { |
| 219 return kLT <= tok && tok <= kGTE; | 224 return kLT <= tok && tok <= kGTE; |
| 220 } | 225 } |
| 221 | 226 |
| 222 static bool IsEqualityOperator(Kind tok) { | 227 static bool IsEqualityOperator(Kind tok) { |
| 223 return kEQ <= tok && tok <= kNE_STRICT; | 228 return kEQ <= tok && tok <= kNE_STRICT; |
| 224 } | 229 } |
| 225 | 230 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 static const char* name_[]; | 325 static const char* name_[]; |
| 321 static const char* tok_str_[]; | 326 static const char* tok_str_[]; |
| 322 static const uint8_t precedence_[]; | 327 static const uint8_t precedence_[]; |
| 323 static const Attribute attributes_[]; | 328 static const Attribute attributes_[]; |
| 324 }; | 329 }; |
| 325 | 330 |
| 326 | 331 |
| 327 } // namespace dart | 332 } // namespace dart |
| 328 | 333 |
| 329 #endif // VM_TOKEN_H_ | 334 #endif // VM_TOKEN_H_ |
| OLD | NEW |