Files
sdk/runtime/vm/token.cc
T
John McCutchan 77101d63e3 Source positions for constructors and lots of async machinery
- Rework token position address space.
- Use ClassifyingTokenPositions::kMethodExtractor for the token position of a method extractor.
- Plumb token positions through all of Ast Transformer.
- Plumb token positions for temporary expressions, etc in Flow Graph Builder.
- Add token positions for parts of the await machinery.
- Move ClassifyingTokenPositions into token.h.
- Remove default token position of Scanner::kNoSourcePos for many IR instructions.
- A couple of unit tests.
- Use synthetic token positions for synthetic AstNodes.
- Fix SLEB128 encoding / decoding + test
- s/Scanner::kNoSourcePos/Token::kNoSourcePos.
- Remove >= 0 and < 0 checks against token positions and use helpers instead.

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/1589643002 .
2016-01-19 15:01:08 -08:00

99 lines
2.3 KiB
C++

// 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* 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* 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:
return true;
default:
return false;
}
}
bool Token::IsUnaryArithmeticOperator(Token::Kind token) {
return (token == kBIT_NOT) || (token == kNEGATE);
}
const char* ClassifyingTokenPositions::ToCString(intptr_t token_pos) {
ASSERT(token_pos < Token::kMinSourcePos);
COMPILE_ASSERT(ClassifyingTokenPositions::kPrivate ==
(Token::kNoSourcePos - 1));
COMPILE_ASSERT(kLast < kPrivate);
switch (token_pos) {
case Token::kNoSourcePos: return "NoSource";
#define DEFINE_CASE(name, value) \
case value: return #name;
CLASSIFYING_TOKEN_POSITIONS(DEFINE_CASE);
#undef DEFINE_CASE
default:
UNIMPLEMENTED();
return NULL;
}
}
} // namespace dart