• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16// Autogenerated file -- DO NOT EDIT!
17
18// CC-OFFNXT(huge_method,huge_cyclomatic_complexity,G.FUN.01-CPP) big switch-case, solid logic
19const char *TokenToString(TokenType type)  // NOLINT(readability-function-size)
20{
21    switch (type) {
22%   allTokens = Tokens::tokens + Keywords::keywords
23%   allTokens.each do |token|
24        case TokenType::<%= token.token %>:
25            return "<%= token.string %>";
26%   end
27        case TokenType::LITERAL_IDENT:
28            return "identification literal";
29        case TokenType::LITERAL_NUMBER:
30            return "number literal";
31        case TokenType::LITERAL_STRING:
32            return "string literal";
33        case TokenType::LITERAL_CHAR:
34            return "char literal";
35        case TokenType::JS_DOC_START:
36            return "/**";
37        case TokenType::JS_DOC_END:
38            return "*/";
39        case TokenType::EOS:
40            return "end of stream";
41        default:
42            ES2PANDA_UNREACHABLE();
43    }
44}
45
46% genSwitch = lambda do |var, tokens, flag|
47    switch (<%= var %>) {
48%   tokens.select { |token| token.flags&.include? flag }.each do |token|
49        case TokenType::<%= token.token %>:
50%   end
51            return true;
52        default:
53            return false;
54    }
55% end
56
57bool Token::IsUnary() const
58{
59%    genSwitch['type_', allTokens, 'unary']
60}
61
62bool Token::IsReservedTypeName() const
63{
64%    genSwitch['keywordType_', Keywords::keywords, 'reserved_type_name']
65}
66
67bool Token::IsDefinableTypeName() const
68{
69%    genSwitch['keywordType_', Keywords::keywords, 'definable_type_name']
70}
71
72bool Token::IsBinaryToken(TokenType type)
73{
74%    genSwitch['type', allTokens, 'binary']
75}
76
77bool Token::IsBinaryLvalueToken(TokenType type)
78{
79%    genSwitch['type', Tokens::tokens, 'binary_lvalue']
80}
81
82bool Token::IsPredefinedType() const
83{
84%    genSwitch['keywordType_', Keywords::keywords, 'predefined_type']
85}
86