token.cc 1.4 KB
Newer Older
1
// Copyright 2006-2008 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5
#include <stdint.h>
6 7

#include "src/parsing/token.h"
8

9 10
namespace v8 {
namespace internal {
11 12

#define T(name, string, precedence) #name,
13
const char* const Token::name_[NUM_TOKENS] = {TOKEN_LIST(T, T)};
14 15 16 17
#undef T


#define T(name, string, precedence) string,
18
const char* const Token::string_[NUM_TOKENS] = {TOKEN_LIST(T, T)};
19 20
#undef T

21
constexpr uint8_t length(const char* str) {
22 23 24
  return str ? static_cast<uint8_t>(strlen(str)) : 0;
}
#define T(name, string, precedence) length(string),
25
const uint8_t Token::string_length_[NUM_TOKENS] = {TOKEN_LIST(T, T)};
26
#undef T
27

28 29 30 31
#define T1(name, string, precedence) \
  ((Token::name == Token::IN) ? 0 : precedence),
#define T2(name, string, precedence) precedence,
// precedence_[0] for accept_IN == false, precedence_[1] for accept_IN = true.
32 33
const int8_t Token::precedence_[2][NUM_TOKENS] = {{TOKEN_LIST(T1, T1)},
                                                  {TOKEN_LIST(T2, T2)}};
34 35
#undef T2
#undef T1
36

37 38
#define KT(a, b, c) \
  IsPropertyNameBits::encode(Token::IsAnyIdentifier(a) || a == ESCAPED_KEYWORD),
39 40 41
#define KK(a, b, c) \
  IsKeywordBits::encode(true) | IsPropertyNameBits::encode(true),
const uint8_t Token::token_flags[] = {TOKEN_LIST(KT, KK)};
42 43 44
#undef KT
#undef KK

45 46
}  // namespace internal
}  // namespace v8