Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros
token.h File Reference
#include "platform/assert.h"
#include "vm/allocation.h"

Go to the source code of this file.

Classes

class  dart::Token
 

Namespaces

namespace  dart
 

Macros

#define DART_TOKEN_LIST(TOK)
 
#define DART_KEYWORD_LIST(KW)
 
#define T(t, s, p, a)   t,
 
#define TOK_CASE(t, s, p, a)
 

Macro Definition Documentation

◆ DART_KEYWORD_LIST

#define DART_KEYWORD_LIST (   KW)

Definition at line 159 of file token.h.

211 {
212 public:
213#define T(t, s, p, a) t,
214 enum Kind { DART_TOKEN_LIST(T) DART_KEYWORD_LIST(T) kNumTokens };
215#undef T
216
217 enum Attribute {
218 kNoAttribute = 0,
219 kKeyword = 1 << 0,
220 kPseudoKeyword = 1 << 1,
221 };
222
223 static const Kind kFirstKeyword = kABSTRACT;
224 static const Kind kLastKeyword = kWITH;
225 static constexpr int kNumKeywords = kLastKeyword - kFirstKeyword + 1;
226
227 static bool IsAssignmentOperator(Kind tok) {
228 return kASSIGN <= tok && tok <= kASSIGN_COND;
229 }
230
231 static bool IsRelationalOperator(Kind tok) {
232 return kLT <= tok && tok <= kGTE;
233 }
234
235 static bool IsEqualityOperator(Kind tok) {
236 return kEQ <= tok && tok <= kNE_STRICT;
237 }
238
239 static bool IsStrictEqualityOperator(Kind tok) {
240 return (tok == kEQ_STRICT) || (tok == kNE_STRICT);
241 }
242
243 static bool IsTypeTestOperator(Kind tok) {
244 return (tok == kIS) || (tok == kISNOT);
245 }
246
247 static bool IsTypeCastOperator(Kind tok) { return tok == kAS; }
248
249 static bool IsIndexOperator(Kind tok) {
250 return tok == kINDEX || tok == kASSIGN_INDEX;
251 }
252
253 static bool IsPseudoKeyword(Kind tok) {
254 return (Attributes(tok) & kPseudoKeyword) != 0;
255 }
256
257 static bool IsKeyword(Kind tok) { return (Attributes(tok) & kKeyword) != 0; }
258
259 static bool IsIdentifier(Kind tok) {
260 return (tok == kIDENT) || IsPseudoKeyword(tok);
261 }
262
263 static const char* Name(Kind tok) {
264 ASSERT(tok < kNumTokens);
265 return name_[tok];
266 }
267
268 static const char* Str(Kind tok) {
269 ASSERT(tok < kNumTokens);
270 return tok_str_[tok];
271 }
272
273 static bool FromStr(const char* str, Kind* out) {
274 ASSERT(str != nullptr && out != nullptr);
275#define TOK_CASE(t, s, p, a) \
276 if (strcmp(str, tok_str_[(t)]) == 0) { \
277 *out = (t); \
278 return true; \
279 }
282#undef TOK_CASE
283 return false;
284 }
285
286 static int Precedence(Kind tok) {
287 ASSERT(tok < kNumTokens);
288 return precedence_[tok];
289 }
290
291 static Attribute Attributes(Kind tok) {
292 ASSERT(tok < kNumTokens);
293 return attributes_[tok];
294 }
295
296 static bool CanBeOverloaded(Kind tok) {
297 ASSERT(tok < kNumTokens);
298 return IsRelationalOperator(tok) || (tok == kEQ) ||
299 (tok >= kADD && tok <= kMOD) || // Arithmetic operations.
300 (tok >= kBIT_OR && tok <= kUSHR) || // Bit operations.
301 (tok == kINDEX) || (tok == kASSIGN_INDEX);
302 }
303
304 static bool NeedsLiteralToken(Kind tok) {
305 ASSERT(tok < kNumTokens);
306 return ((tok == Token::kINTEGER) || (tok == Token::kSTRING) ||
307 (tok == Token::kINTERPOL_VAR) || (tok == Token::kERROR) ||
308 (tok == Token::kDOUBLE));
309 }
310
311 static bool IsBinaryOperator(Token::Kind token);
312 static bool IsUnaryOperator(Token::Kind token);
313
314 static bool IsBinaryArithmeticOperator(Token::Kind token);
315 static bool IsUnaryArithmeticOperator(Token::Kind token);
316
317 static bool IsBinaryBitwiseOperator(Token::Kind token);
318
319 // For a comparison operation return an operation for the negated comparison:
320 // !(a (op) b) === a (op') b
321 static Token::Kind NegateComparison(Token::Kind op) {
322 switch (op) {
323 case Token::kEQ:
324 return Token::kNE;
325 case Token::kNE:
326 return Token::kEQ;
327 case Token::kLT:
328 return Token::kGTE;
329 case Token::kGT:
330 return Token::kLTE;
331 case Token::kLTE:
332 return Token::kGT;
333 case Token::kGTE:
334 return Token::kLT;
335 case Token::kEQ_STRICT:
336 return Token::kNE_STRICT;
337 case Token::kNE_STRICT:
338 return Token::kEQ_STRICT;
339 case Token::kIS:
340 return Token::kISNOT;
341 case Token::kISNOT:
342 return Token::kIS;
343 default:
344 UNREACHABLE();
345 return Token::kILLEGAL;
346 }
347 }
348
349 // For a comparison operation return an operation for the equivalent flipped
350 // comparison: a (op) b === b (op') a.
351 static Token::Kind FlipComparison(Token::Kind op) {
352 switch (op) {
353 case Token::kEQ:
354 return Token::kEQ;
355 case Token::kNE:
356 return Token::kNE;
357 case Token::kLT:
358 return Token::kGT;
359 case Token::kGT:
360 return Token::kLT;
361 case Token::kLTE:
362 return Token::kGTE;
363 case Token::kGTE:
364 return Token::kLTE;
365 case Token::kEQ_STRICT:
366 return Token::kEQ_STRICT;
367 case Token::kNE_STRICT:
368 return Token::kNE_STRICT;
369 default:
370 UNREACHABLE();
371 return Token::kILLEGAL;
372 }
373 }
374
375 private:
376 static const char* const name_[];
377 static const char* const tok_str_[];
378 static const uint8_t precedence_[];
379 static const Attribute attributes_[];
380};
381
382} // namespace dart
383
384#endif // RUNTIME_VM_TOKEN_H_
#define UNREACHABLE()
Definition assert.h:248
#define ASSERT(E)
ImplicitString Name
Definition DMSrcSink.h:38
#define DART_KEYWORD_LIST(KW)
Definition token.h:159
#define TOK_CASE(t, s, p, a)
#define DART_TOKEN_LIST(TOK)
Definition token.h:34
#define T(t, s, p, a)
Definition token.h:214

◆ DART_TOKEN_LIST

#define DART_TOKEN_LIST (   TOK)

Definition at line 34 of file token.h.

41 {", 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) \
50 \
51 /* Assignment operators. */ \
52 /* Please update IsAssignmentOperator() if you make */ \
53 /* any changes to this block. */ \
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) \
67 /* Avoid trigraph ??= below. */ \
68 TOK(kASSIGN_COND, "?\?=", 2, kNoAttribute) \
69 \
70 TOK(kCASCADE, "..", 2, kNoAttribute) \
71 \
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) \
79 \
80 /* Shift operators. */ \
81 TOK(kSHL, "<<", 12, kNoAttribute) \
82 TOK(kSHR, ">>", 12, kNoAttribute) \
83 TOK(kUSHR, ">>>", 12, kNoAttribute) \
84 \
85 /* Additive operators. */ \
86 TOK(kADD, "+", 13, kNoAttribute) \
87 TOK(kSUB, "-", 13, kNoAttribute) \
88 \
89 /* Multiplicative operators */ \
90 TOK(kMUL, "*", 14, kNoAttribute) \
91 TOK(kDIV, "/", 14, kNoAttribute) \
92 TOK(kTRUNCDIV, "~/", 14, kNoAttribute) \
93 TOK(kMOD, "%", 14, kNoAttribute) \
94 \
95 TOK(kNOT, "!", 0, kNoAttribute) \
96 TOK(kCONDITIONAL, "?", 3, kNoAttribute) \
97 TOK(kIFnullptr, "??", 4, kNoAttribute) \
98 \
99 /* Equality operators. */ \
100 /* Please update IsEqualityOperator() if you make */ \
101 /* any changes to this block. */ \
102 TOK(kEQ, "==", 7, kNoAttribute) \
103 TOK(kNE, "!=", 7, kNoAttribute) \
104 TOK(kEQ_STRICT, "===", 7, kNoAttribute) \
105 TOK(kNE_STRICT, "!==", 7, kNoAttribute) \
106 \
107 /* Relational operators. */ \
108 /* Please update IsRelationalOperator() if you make */ \
109 /* any changes to this block. */ \
110 TOK(kLT, "<", 8, kNoAttribute) \
111 TOK(kGT, ">", 8, kNoAttribute) \
112 TOK(kLTE, "<=", 8, kNoAttribute) \
113 TOK(kGTE, ">=", 8, kNoAttribute) \
114 \
115 /* Internal token for !(expr is Type) negative type test operator */ \
116 TOK(kISNOT, "", 11, kNoAttribute) \
117 \
118 TOK(kINDEX, "[]", 0, kNoAttribute) \
119 TOK(kASSIGN_INDEX, "[]=", 0, kNoAttribute) \
120 TOK(kNEGATE, "unary-", 0, kNoAttribute) \
121 \
122 TOK(kIDENT, "", 0, kNoAttribute) \
123 TOK(kSTRING, "", 0, kNoAttribute) \
124 TOK(kINTEGER, "", 0, kNoAttribute) \
125 TOK(kDOUBLE, "", 0, kNoAttribute) \
126 \
127 TOK(kINTERPOL_VAR, "$", 0, kNoAttribute) \
128 TOK(kINTERPOL_START, "${", 0, kNoAttribute) \
129 TOK(kINTERPOL_END, "}", 0, kNoAttribute) \
130 \
131 TOK(kAT, "@", 0, kNoAttribute) \
132 TOK(kHASH, "#", 0, kNoAttribute) \
133 \
134 TOK(kNEWLINE, "\n", 0, kNoAttribute) \
135 TOK(kWHITESP, "", 0, kNoAttribute) \
136 TOK(kERROR, "", 0, kNoAttribute) \
137 TOK(kILLEGAL, "", 0, kNoAttribute) \
138 \
139 /* Support for Dart scripts. */ \
140 TOK(kSCRIPTTAG, "#!", 0, kNoAttribute) \
141 \
142 /* Support for optimized code */ \
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)
static int square(int x)
Definition etc1.cpp:302
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48
SIN Vec< N, float > abs(const Vec< N, float > &x)
Definition SkVx.h:707
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition SkVx.h:706
SIN Vec< N, float > floor(const Vec< N, float > &x)
Definition SkVx.h:703

◆ T

#define T (   t,
  s,
  p,
  a 
)    t,

Definition at line 214 of file token.h.

◆ TOK_CASE

#define TOK_CASE (   t,
  s,
  p,
  a 
)
Value:
if (strcmp(str, tok_str_[(t)]) == 0) { \
*out = (t); \
return true; \
}