Flutter Engine
The Flutter Engine
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
dart::Token Class Reference

#include <token.h>

Public Types

enum  Kind { DART_TOKEN_LIST =(T) DART_KEYWORD_LIST(T) kNumTokens }
 
enum  Attribute { kNoAttribute = 0 , kKeyword = 1 << 0 , kPseudoKeyword = 1 << 1 }
 

Static Public Member Functions

static bool IsAssignmentOperator (Kind tok)
 
static bool IsRelationalOperator (Kind tok)
 
static bool IsEqualityOperator (Kind tok)
 
static bool IsStrictEqualityOperator (Kind tok)
 
static bool IsTypeTestOperator (Kind tok)
 
static bool IsTypeCastOperator (Kind tok)
 
static bool IsIndexOperator (Kind tok)
 
static bool IsPseudoKeyword (Kind tok)
 
static bool IsKeyword (Kind tok)
 
static bool IsIdentifier (Kind tok)
 
static const char * Name (Kind tok)
 
static const char * Str (Kind tok)
 
static bool FromStr (const char *str, Kind *out)
 
static int Precedence (Kind tok)
 
static Attribute Attributes (Kind tok)
 
static bool CanBeOverloaded (Kind tok)
 
static bool NeedsLiteralToken (Kind tok)
 
static bool IsBinaryOperator (Token::Kind token)
 
static bool IsUnaryOperator (Token::Kind token)
 
static bool IsBinaryArithmeticOperator (Token::Kind token)
 
static bool IsUnaryArithmeticOperator (Token::Kind token)
 
static bool IsBinaryBitwiseOperator (Token::Kind token)
 
static Token::Kind NegateComparison (Token::Kind op)
 
static Token::Kind FlipComparison (Token::Kind op)
 

Static Public Attributes

static const Kind kFirstKeyword = kABSTRACT
 
static const Kind kLastKeyword = kWITH
 
static constexpr int kNumKeywords = kLastKeyword - kFirstKeyword + 1
 

Detailed Description

Definition at line 212 of file token.h.

Member Enumeration Documentation

◆ Attribute

Enumerator
kNoAttribute 
kKeyword 
kPseudoKeyword 

Definition at line 218 of file token.h.

218 {
219 kNoAttribute = 0,
220 kKeyword = 1 << 0,
221 kPseudoKeyword = 1 << 1,
222 };
@ kPseudoKeyword
Definition: token.h:221
@ kNoAttribute
Definition: token.h:219
@ kKeyword
Definition: token.h:220

◆ Kind

Enumerator
DART_TOKEN_LIST 

Definition at line 215 of file token.h.

215{ DART_TOKEN_LIST(T) DART_KEYWORD_LIST(T) kNumTokens };
@ DART_TOKEN_LIST
Definition: token.h:215
#define DART_KEYWORD_LIST(KW)
Definition: token.h:159
#define T(t, s, p, a)
Definition: token.h:214

Member Function Documentation

◆ Attributes()

static Attribute dart::Token::Attributes ( Kind  tok)
inlinestatic

Definition at line 292 of file token.h.

292 {
293 ASSERT(tok < kNumTokens);
294 return attributes_[tok];
295 }
#define ASSERT(E)

◆ CanBeOverloaded()

static bool dart::Token::CanBeOverloaded ( Kind  tok)
inlinestatic

Definition at line 297 of file token.h.

297 {
298 ASSERT(tok < kNumTokens);
299 return IsRelationalOperator(tok) || (tok == kEQ) ||
300 (tok >= kADD && tok <= kMOD) || // Arithmetic operations.
301 (tok >= kBIT_OR && tok <= kUSHR) || // Bit operations.
302 (tok == kINDEX) || (tok == kASSIGN_INDEX);
303 }
static bool IsRelationalOperator(Kind tok)
Definition: token.h:232

◆ FlipComparison()

static Token::Kind dart::Token::FlipComparison ( Token::Kind  op)
inlinestatic

Definition at line 352 of file token.h.

352 {
353 switch (op) {
354 case Token::kEQ:
355 return Token::kEQ;
356 case Token::kNE:
357 return Token::kNE;
358 case Token::kLT:
359 return Token::kGT;
360 case Token::kGT:
361 return Token::kLT;
362 case Token::kLTE:
363 return Token::kGTE;
364 case Token::kGTE:
365 return Token::kLTE;
366 case Token::kEQ_STRICT:
367 return Token::kEQ_STRICT;
368 case Token::kNE_STRICT:
369 return Token::kNE_STRICT;
370 default:
371 UNREACHABLE();
372 return Token::kILLEGAL;
373 }
374 }
#define UNREACHABLE()
Definition: assert.h:248

◆ FromStr()

static bool dart::Token::FromStr ( const char *  str,
Kind out 
)
inlinestatic

Definition at line 274 of file token.h.

274 {
275 ASSERT(str != nullptr && out != nullptr);
276#define TOK_CASE(t, s, p, a) \
277 if (strcmp(str, tok_str_[(t)]) == 0) { \
278 *out = (t); \
279 return true; \
280 }
283#undef TOK_CASE
284 return false;
285 }
#define TOK_CASE(t, s, p, a)

◆ IsAssignmentOperator()

static bool dart::Token::IsAssignmentOperator ( Kind  tok)
inlinestatic

Definition at line 228 of file token.h.

228 {
229 return kASSIGN <= tok && tok <= kASSIGN_COND;
230 }

◆ IsBinaryArithmeticOperator()

bool dart::Token::IsBinaryArithmeticOperator ( Token::Kind  token)
static

Definition at line 45 of file token.cc.

45 {
46 switch (token) {
47 case Token::kADD:
48 case Token::kSUB:
49 case Token::kMUL:
50 case Token::kDIV:
51 case Token::kTRUNCDIV:
52 case Token::kMOD:
53 case Token::kBIT_OR:
54 case Token::kBIT_XOR:
55 case Token::kBIT_AND:
56 case Token::kSHL:
57 case Token::kSHR:
58 case Token::kUSHR:
59 case Token::kMAX:
60 case Token::kMIN:
61 return true;
62 default:
63 return false;
64 }
65}

◆ IsBinaryBitwiseOperator()

bool dart::Token::IsBinaryBitwiseOperator ( Token::Kind  token)
static

Definition at line 85 of file token.cc.

85 {
86 switch (token) {
87 case Token::kBIT_OR:
88 case Token::kBIT_XOR:
89 case Token::kBIT_AND:
90 case Token::kSHL:
91 case Token::kSHR:
92 case Token::kUSHR:
93 return true;
94 default:
95 return false;
96 }
97}

◆ IsBinaryOperator()

bool dart::Token::IsBinaryOperator ( Token::Kind  token)
static

Definition at line 31 of file token.cc.

31 {
32 switch (token) {
33 case Token::kOR:
34 case Token::kAND:
35 return true;
36 default:
37 return IsBinaryArithmeticOperator(token);
38 }
39}
static bool IsBinaryArithmeticOperator(Token::Kind token)
Definition: token.cc:45

◆ IsEqualityOperator()

static bool dart::Token::IsEqualityOperator ( Kind  tok)
inlinestatic

Definition at line 236 of file token.h.

236 {
237 return kEQ <= tok && tok <= kNE_STRICT;
238 }

◆ IsIdentifier()

static bool dart::Token::IsIdentifier ( Kind  tok)
inlinestatic

Definition at line 260 of file token.h.

260 {
261 return (tok == kIDENT) || IsPseudoKeyword(tok);
262 }
static bool IsPseudoKeyword(Kind tok)
Definition: token.h:254

◆ IsIndexOperator()

static bool dart::Token::IsIndexOperator ( Kind  tok)
inlinestatic

Definition at line 250 of file token.h.

250 {
251 return tok == kINDEX || tok == kASSIGN_INDEX;
252 }

◆ IsKeyword()

static bool dart::Token::IsKeyword ( Kind  tok)
inlinestatic

Definition at line 258 of file token.h.

258{ return (Attributes(tok) & kKeyword) != 0; }
static Attribute Attributes(Kind tok)
Definition: token.h:292

◆ IsPseudoKeyword()

static bool dart::Token::IsPseudoKeyword ( Kind  tok)
inlinestatic

Definition at line 254 of file token.h.

254 {
255 return (Attributes(tok) & kPseudoKeyword) != 0;
256 }

◆ IsRelationalOperator()

static bool dart::Token::IsRelationalOperator ( Kind  tok)
inlinestatic

Definition at line 232 of file token.h.

232 {
233 return kLT <= tok && tok <= kGTE;
234 }

◆ IsStrictEqualityOperator()

static bool dart::Token::IsStrictEqualityOperator ( Kind  tok)
inlinestatic

Definition at line 240 of file token.h.

240 {
241 return (tok == kEQ_STRICT) || (tok == kNE_STRICT);
242 }

◆ IsTypeCastOperator()

static bool dart::Token::IsTypeCastOperator ( Kind  tok)
inlinestatic

Definition at line 248 of file token.h.

248{ return tok == kAS; }

◆ IsTypeTestOperator()

static bool dart::Token::IsTypeTestOperator ( Kind  tok)
inlinestatic

Definition at line 244 of file token.h.

244 {
245 return (tok == kIS) || (tok == kISNOT);
246 }

◆ IsUnaryArithmeticOperator()

bool dart::Token::IsUnaryArithmeticOperator ( Token::Kind  token)
static

Definition at line 67 of file token.cc.

67 {
68 switch (token) {
69 case Token::kBIT_NOT:
70 case Token::kNEGATE:
71 case Token::kABS:
72 case Token::kSQRT:
73 case Token::kSQUARE:
74 case Token::kRECIPROCAL:
75 case Token::kRECIPROCAL_SQRT:
76 case Token::kTRUNCATE:
77 case Token::kFLOOR:
78 case Token::kCEILING:
79 return true;
80 default:
81 return false;
82 }
83}

◆ IsUnaryOperator()

bool dart::Token::IsUnaryOperator ( Token::Kind  token)
static

Definition at line 41 of file token.cc.

41 {
42 return (token == kNOT) || IsUnaryArithmeticOperator(token);
43}
static bool IsUnaryArithmeticOperator(Token::Kind token)
Definition: token.cc:67

◆ Name()

static const char * dart::Token::Name ( Kind  tok)
inlinestatic

Definition at line 264 of file token.h.

264 {
265 ASSERT(tok < kNumTokens);
266 return name_[tok];
267 }

◆ NeedsLiteralToken()

static bool dart::Token::NeedsLiteralToken ( Kind  tok)
inlinestatic

Definition at line 305 of file token.h.

305 {
306 ASSERT(tok < kNumTokens);
307 return ((tok == Token::kINTEGER) || (tok == Token::kSTRING) ||
308 (tok == Token::kINTERPOL_VAR) || (tok == Token::kERROR) ||
309 (tok == Token::kDOUBLE));
310 }

◆ NegateComparison()

static Token::Kind dart::Token::NegateComparison ( Token::Kind  op)
inlinestatic

Definition at line 322 of file token.h.

322 {
323 switch (op) {
324 case Token::kEQ:
325 return Token::kNE;
326 case Token::kNE:
327 return Token::kEQ;
328 case Token::kLT:
329 return Token::kGTE;
330 case Token::kGT:
331 return Token::kLTE;
332 case Token::kLTE:
333 return Token::kGT;
334 case Token::kGTE:
335 return Token::kLT;
336 case Token::kEQ_STRICT:
337 return Token::kNE_STRICT;
338 case Token::kNE_STRICT:
339 return Token::kEQ_STRICT;
340 case Token::kIS:
341 return Token::kISNOT;
342 case Token::kISNOT:
343 return Token::kIS;
344 default:
345 UNREACHABLE();
346 return Token::kILLEGAL;
347 }
348 }

◆ Precedence()

static int dart::Token::Precedence ( Kind  tok)
inlinestatic

Definition at line 287 of file token.h.

287 {
288 ASSERT(tok < kNumTokens);
289 return precedence_[tok];
290 }

◆ Str()

static const char * dart::Token::Str ( Kind  tok)
inlinestatic

Definition at line 269 of file token.h.

269 {
270 ASSERT(tok < kNumTokens);
271 return tok_str_[tok];
272 }

Member Data Documentation

◆ kFirstKeyword

const Kind dart::Token::kFirstKeyword = kABSTRACT
static

Definition at line 224 of file token.h.

◆ kLastKeyword

const Kind dart::Token::kLastKeyword = kWITH
static

Definition at line 225 of file token.h.

◆ kNumKeywords

constexpr int dart::Token::kNumKeywords = kLastKeyword - kFirstKeyword + 1
staticconstexpr

Definition at line 226 of file token.h.


The documentation for this class was generated from the following files: