5#ifndef RUNTIME_VM_TOKEN_H_
6#define RUNTIME_VM_TOKEN_H_
34#define DART_TOKEN_LIST(TOK) \
35 TOK(kEOS, "", 0, kNoAttribute) \
37 TOK(kLPAREN, "(", 0, kNoAttribute) \
38 TOK(kRPAREN, ")", 0, kNoAttribute) \
39 TOK(kLBRACK, "[", 0, kNoAttribute) \
40 TOK(kRBRACK, "]", 0, kNoAttribute) \
41 TOK(kLBRACE, "{", 0, kNoAttribute) \
42 TOK(kRBRACE, "}", 0, kNoAttribute) \
43 TOK(kARROW, "=>", 0, kNoAttribute) \
44 TOK(kCOLON, ":", 0, kNoAttribute) \
45 TOK(kSEMICOLON, ";", 0, kNoAttribute) \
46 TOK(kPERIOD, ".", 0, kNoAttribute) \
47 TOK(kQM_PERIOD, "?.", 0, kNoAttribute) \
48 TOK(kINCR, "++", 0, kNoAttribute) \
49 TOK(kDECR, "--", 0, kNoAttribute) \
54 TOK(kASSIGN, "=", 2, kNoAttribute) \
55 TOK(kASSIGN_OR, "|=", 2, kNoAttribute) \
56 TOK(kASSIGN_XOR, "^=", 2, kNoAttribute) \
57 TOK(kASSIGN_AND, "&=", 2, kNoAttribute) \
58 TOK(kASSIGN_SHL, "<<=", 2, kNoAttribute) \
59 TOK(kASSIGN_SHR, ">>=", 2, kNoAttribute) \
60 TOK(kASSIGN_USHR, ">>>=", 2, kNoAttribute) \
61 TOK(kASSIGN_ADD, "+=", 2, kNoAttribute) \
62 TOK(kASSIGN_SUB, "-=", 2, kNoAttribute) \
63 TOK(kASSIGN_MUL, "*=", 2, kNoAttribute) \
64 TOK(kASSIGN_TRUNCDIV, "~/=", 2, kNoAttribute) \
65 TOK(kASSIGN_DIV, "/=", 2, kNoAttribute) \
66 TOK(kASSIGN_MOD, "%=", 2, kNoAttribute) \
68 TOK(kASSIGN_COND, "?\?=", 2, kNoAttribute) \
70 TOK(kCASCADE, "..", 2, kNoAttribute) \
72 TOK(kCOMMA, ",", 1, kNoAttribute) \
73 TOK(kOR, "||", 5, kNoAttribute) \
74 TOK(kAND, "&&", 6, kNoAttribute) \
75 TOK(kBIT_OR, "|", 9, kNoAttribute) \
76 TOK(kBIT_XOR, "^", 10, kNoAttribute) \
77 TOK(kBIT_AND, "&", 11, kNoAttribute) \
78 TOK(kBIT_NOT, "~", 0, kNoAttribute) \
81 TOK(kSHL, "<<", 12, kNoAttribute) \
82 TOK(kSHR, ">>", 12, kNoAttribute) \
83 TOK(kUSHR, ">>>", 12, kNoAttribute) \
86 TOK(kADD, "+", 13, kNoAttribute) \
87 TOK(kSUB, "-", 13, kNoAttribute) \
90 TOK(kMUL, "*", 14, kNoAttribute) \
91 TOK(kDIV, "/", 14, kNoAttribute) \
92 TOK(kTRUNCDIV, "~/", 14, kNoAttribute) \
93 TOK(kMOD, "%", 14, kNoAttribute) \
95 TOK(kNOT, "!", 0, kNoAttribute) \
96 TOK(kCONDITIONAL, "?", 3, kNoAttribute) \
97 TOK(kIFnullptr, "??", 4, kNoAttribute) \
102 TOK(kEQ, "==", 7, kNoAttribute) \
103 TOK(kNE, "!=", 7, kNoAttribute) \
104 TOK(kEQ_STRICT, "===", 7, kNoAttribute) \
105 TOK(kNE_STRICT, "!==", 7, kNoAttribute) \
110 TOK(kLT, "<", 8, kNoAttribute) \
111 TOK(kGT, ">", 8, kNoAttribute) \
112 TOK(kLTE, "<=", 8, kNoAttribute) \
113 TOK(kGTE, ">=", 8, kNoAttribute) \
116 TOK(kISNOT, "", 11, kNoAttribute) \
118 TOK(kINDEX, "[]", 0, kNoAttribute) \
119 TOK(kASSIGN_INDEX, "[]=", 0, kNoAttribute) \
120 TOK(kNEGATE, "unary-", 0, kNoAttribute) \
122 TOK(kIDENT, "", 0, kNoAttribute) \
123 TOK(kSTRING, "", 0, kNoAttribute) \
124 TOK(kINTEGER, "", 0, kNoAttribute) \
125 TOK(kDOUBLE, "", 0, kNoAttribute) \
127 TOK(kINTERPOL_VAR, "$", 0, kNoAttribute) \
128 TOK(kINTERPOL_START, "${", 0, kNoAttribute) \
129 TOK(kINTERPOL_END, "}", 0, kNoAttribute) \
131 TOK(kAT, "@", 0, kNoAttribute) \
132 TOK(kHASH, "#", 0, kNoAttribute) \
134 TOK(kNEWLINE, "\n", 0, kNoAttribute) \
135 TOK(kWHITESP, "", 0, kNoAttribute) \
136 TOK(kERROR, "", 0, kNoAttribute) \
137 TOK(kILLEGAL, "", 0, kNoAttribute) \
140 TOK(kSCRIPTTAG, "#!", 0, kNoAttribute) \
143 TOK(kREM, "rem", 0, kNoAttribute) \
144 TOK(kABS, "abs", 0, kNoAttribute) \
145 TOK(kSQRT, "sqrt", 0, kNoAttribute) \
146 TOK(kMIN, "min", 0, kNoAttribute) \
147 TOK(kMAX, "max", 0, kNoAttribute) \
148 TOK(kRECIPROCAL, "reciprocal", 0, kNoAttribute) \
149 TOK(kRECIPROCAL_SQRT, "reciprocal-sqrt", 0, kNoAttribute) \
150 TOK(kSQUARE, "square", 0, kNoAttribute) \
151 TOK(kTRUNCATE, "truncate", 0, kNoAttribute) \
152 TOK(kFLOOR, "floor", 0, kNoAttribute) \
153 TOK(kCEILING, "ceiling", 0, kNoAttribute)
159#define DART_KEYWORD_LIST(KW) \
160 KW(kABSTRACT, "abstract", 0, kPseudoKeyword)
\
161 KW(kAS, "as", 11, kPseudoKeyword) \
162 KW(kASSERT, "assert", 0, kKeyword) \
163 KW(kBREAK, "break", 0, kKeyword) \
164 KW(kCASE, "case", 0, kKeyword) \
165 KW(kCATCH, "catch", 0, kKeyword) \
166 KW(kCLASS, "class", 0, kKeyword) \
167 KW(kCONST, "const", 0, kKeyword) \
168 KW(kCONTINUE, "continue", 0, kKeyword) \
169 KW(kCOVARIANT, "covariant", 0, kPseudoKeyword) \
170 KW(kDEFAULT, "default", 0, kKeyword) \
171 KW(kDEFERRED, "deferred", 0, kPseudoKeyword) \
172 KW(kDO, "do", 0, kKeyword) \
173 KW(kELSE, "else", 0, kKeyword) \
174 KW(kENUM, "enum", 0, kKeyword) \
175 KW(kEXPORT, "export", 0, kPseudoKeyword) \
176 KW(kEXTENDS, "extends", 0, kKeyword) \
177 KW(kEXTERNAL, "external", 0, kPseudoKeyword) \
178 KW(kFACTORY, "factory", 0, kPseudoKeyword) \
179 KW(kFALSE, "false", 0, kKeyword) \
180 KW(kFINAL, "final", 0, kKeyword) \
181 KW(kFINALLY, "finally", 0, kKeyword) \
182 KW(kFOR, "for", 0, kKeyword) \
183 KW(kGET, "get", 0, kPseudoKeyword) \
184 KW(kIF, "if", 0, kKeyword) \
185 KW(kIMPLEMENTS, "implements", 0, kPseudoKeyword) \
186 KW(kIMPORT, "import", 0, kPseudoKeyword) \
187 KW(kIN, "in", 0, kKeyword) \
188 KW(kIS, "is", 11, kKeyword) \
189 KW(kLIBRARY, "library", 0, kPseudoKeyword) \
190 KW(kNEW, "new", 0, kKeyword) \
191 KW(knullptr, "null", 0, kKeyword) \
192 KW(kOPERATOR, "operator", 0, kPseudoKeyword) \
193 KW(kPART, "part", 0, kPseudoKeyword) \
194 KW(kRETHROW, "rethrow", 0, kKeyword) \
195 KW(kRETURN, "return", 0, kKeyword) \
196 KW(kSET, "set", 0, kPseudoKeyword) \
197 KW(kSTATIC, "static", 0, kPseudoKeyword) \
198 KW(kSUPER, "super", 0, kKeyword) \
199 KW(kSWITCH, "switch", 0, kKeyword) \
200 KW(kTHIS, "this", 0, kKeyword) \
201 KW(kTHROW, "throw", 0, kKeyword) \
202 KW(kTRUE, "true", 0, kKeyword) \
203 KW(kTRY, "try", 0, kKeyword) \
204 KW(kTYPEDEF, "typedef", 0, kPseudoKeyword) \
205 KW(kVAR, "var", 0, kKeyword) \
206 KW(kVOID, "void", 0, kKeyword) \
207 KW(kWHILE, "while", 0, kKeyword) \
208 KW(kWITH, "with", 0, kKeyword)
214#define T(t, s, p, a) t,
229 return kASSIGN <= tok && tok <= kASSIGN_COND;
233 return kLT <= tok && tok <= kGTE;
237 return kEQ <= tok && tok <= kNE_STRICT;
241 return (tok == kEQ_STRICT) || (tok == kNE_STRICT);
245 return (tok == kIS) || (tok == kISNOT);
251 return tok == kINDEX || tok == kASSIGN_INDEX;
271 return tok_str_[tok];
275 ASSERT(str !=
nullptr &&
out !=
nullptr);
276#define TOK_CASE(t, s, p, a) \
277 if (strcmp(str, tok_str_[(t)]) == 0) { \
289 return precedence_[tok];
294 return attributes_[tok];
300 (tok >= kADD && tok <= kMOD) ||
301 (tok >= kBIT_OR && tok <= kUSHR) ||
302 (tok == kINDEX) || (tok == kASSIGN_INDEX);
307 return ((tok == Token::kINTEGER) || (tok == Token::kSTRING) ||
308 (tok == Token::kINTERPOL_VAR) || (tok == Token::kERROR) ||
309 (tok == Token::kDOUBLE));
336 case Token::kEQ_STRICT:
337 return Token::kNE_STRICT;
338 case Token::kNE_STRICT:
339 return Token::kEQ_STRICT;
341 return Token::kISNOT;
346 return Token::kILLEGAL;
366 case Token::kEQ_STRICT:
367 return Token::kEQ_STRICT;
368 case Token::kNE_STRICT:
369 return Token::kNE_STRICT;
372 return Token::kILLEGAL;
377 static const char*
const name_[];
378 static const char*
const tok_str_[];
379 static const uint8_t precedence_[];
static bool IsTypeTestOperator(Kind tok)
static const Kind kLastKeyword
static bool NeedsLiteralToken(Kind tok)
static bool IsKeyword(Kind tok)
static Token::Kind FlipComparison(Token::Kind op)
static bool IsAssignmentOperator(Kind tok)
static bool IsBinaryArithmeticOperator(Token::Kind token)
static bool IsTypeCastOperator(Kind tok)
static bool IsIndexOperator(Kind tok)
static int Precedence(Kind tok)
static bool IsRelationalOperator(Kind tok)
static const char * Name(Kind tok)
static Token::Kind NegateComparison(Token::Kind op)
static bool IsPseudoKeyword(Kind tok)
static const char * Str(Kind tok)
static bool IsBinaryOperator(Token::Kind token)
static bool IsIdentifier(Kind tok)
static const Kind kFirstKeyword
static Attribute Attributes(Kind tok)
static constexpr int kNumKeywords
static bool IsEqualityOperator(Kind tok)
static bool IsUnaryOperator(Token::Kind token)
static bool IsStrictEqualityOperator(Kind tok)
static bool CanBeOverloaded(Kind tok)
static bool IsBinaryBitwiseOperator(Token::Kind token)
static bool FromStr(const char *str, Kind *out)
static bool IsUnaryArithmeticOperator(Token::Kind token)
#define DART_KEYWORD_LIST(KW)
#define TOK_CASE(t, s, p, a)