1// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5#include "vm/token.h"
6
7#include "vm/object.h"
8
9namespace dart {
10
11#define TOKEN_NAME(t, s, p, a) #t,
12const char* Token::name_[] = {DART_TOKEN_LIST(TOKEN_NAME)
13 DART_KEYWORD_LIST(TOKEN_NAME)};
14#undef TOKEN_NAME
15
16#define TOKEN_STRING(t, s, p, a) s,
17const char* Token::tok_str_[] = {DART_TOKEN_LIST(TOKEN_STRING)
18 DART_KEYWORD_LIST(TOKEN_STRING)};
19#undef TOKEN_STRING
20
21#define TOKEN_PRECEDENCE(t, s, p, a) p,
22const uint8_t Token::precedence_[] = {DART_TOKEN_LIST(TOKEN_PRECEDENCE)
23 DART_KEYWORD_LIST(TOKEN_PRECEDENCE)};
24#undef TOKEN_PRECEDENCE
25
26#define TOKEN_ATTRIBUTE(t, s, p, a) a,
27const Token::Attribute Token::attributes_[] = {
28 DART_TOKEN_LIST(TOKEN_ATTRIBUTE) DART_KEYWORD_LIST(TOKEN_ATTRIBUTE)};
29#undef TOKEN_ATTRIBUTE
30
31bool Token::IsBinaryOperator(Token::Kind token) {
32 switch (token) {
33 case Token::kOR:
34 case Token::kAND:
35 return true;
36 default:
37 return IsBinaryArithmeticOperator(token);
38 }
39}
40
41bool Token::IsUnaryOperator(Token::Kind token) {
42 return (token == kNOT) || IsUnaryArithmeticOperator(token);
43}
44
45bool Token::IsBinaryArithmeticOperator(Token::Kind token) {
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 return true;
59 default:
60 return false;
61 }
62}
63
64bool Token::IsUnaryArithmeticOperator(Token::Kind token) {
65 return (token == kBIT_NOT) || (token == kNEGATE);
66}
67
68bool Token::IsBinaryBitwiseOperator(Token::Kind token) {
69 switch (token) {
70 case Token::kBIT_OR:
71 case Token::kBIT_XOR:
72 case Token::kBIT_AND:
73 case Token::kSHL:
74 case Token::kSHR:
75 return true;
76 default:
77 return false;
78 }
79}
80
81} // namespace dart
82