-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtoken.cc
99 lines (86 loc) · 2.49 KB
/
token.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/token.h"
#include "vm/object.h"
namespace dart {
#define TOKEN_NAME(t, s, p, a) #t,
const char* const Token::name_[] = {DART_TOKEN_LIST(TOKEN_NAME)
DART_KEYWORD_LIST(TOKEN_NAME)};
#undef TOKEN_NAME
#define TOKEN_STRING(t, s, p, a) s,
const char* const Token::tok_str_[] = {DART_TOKEN_LIST(TOKEN_STRING)
DART_KEYWORD_LIST(TOKEN_STRING)};
#undef TOKEN_STRING
#define TOKEN_PRECEDENCE(t, s, p, a) p,
const uint8_t Token::precedence_[] = {DART_TOKEN_LIST(TOKEN_PRECEDENCE)
DART_KEYWORD_LIST(TOKEN_PRECEDENCE)};
#undef TOKEN_PRECEDENCE
#define TOKEN_ATTRIBUTE(t, s, p, a) a,
const Token::Attribute Token::attributes_[] = {
DART_TOKEN_LIST(TOKEN_ATTRIBUTE) DART_KEYWORD_LIST(TOKEN_ATTRIBUTE)};
#undef TOKEN_ATTRIBUTE
bool Token::IsBinaryOperator(Token::Kind token) {
switch (token) {
case Token::kOR:
case Token::kAND:
return true;
default:
return IsBinaryArithmeticOperator(token);
}
}
bool Token::IsUnaryOperator(Token::Kind token) {
return (token == kNOT) || IsUnaryArithmeticOperator(token);
}
bool Token::IsBinaryArithmeticOperator(Token::Kind token) {
switch (token) {
case Token::kADD:
case Token::kSUB:
case Token::kMUL:
case Token::kDIV:
case Token::kTRUNCDIV:
case Token::kMOD:
case Token::kBIT_OR:
case Token::kBIT_XOR:
case Token::kBIT_AND:
case Token::kSHL:
case Token::kSHR:
case Token::kUSHR:
case Token::kMAX:
case Token::kMIN:
return true;
default:
return false;
}
}
bool Token::IsUnaryArithmeticOperator(Token::Kind token) {
switch (token) {
case Token::kBIT_NOT:
case Token::kNEGATE:
case Token::kABS:
case Token::kSQRT:
case Token::kSQUARE:
case Token::kRECIPROCAL:
case Token::kRECIPROCAL_SQRT:
case Token::kTRUNCATE:
case Token::kFLOOR:
case Token::kCEILING:
return true;
default:
return false;
}
}
bool Token::IsBinaryBitwiseOperator(Token::Kind token) {
switch (token) {
case Token::kBIT_OR:
case Token::kBIT_XOR:
case Token::kBIT_AND:
case Token::kSHL:
case Token::kSHR:
case Token::kUSHR:
return true;
default:
return false;
}
}
} // namespace dart