1/**
2 * Copyright (c) 2021-2024 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#ifndef ES2PANDA_PARSER_PARSER_FLAGS_H
17#define ES2PANDA_PARSER_PARSER_FLAGS_H
18
19#include <cstdint>
20#include "util/enumbitops.h"
21
22namespace ark::es2panda::parser {
23
24using ENUMBITOPS_OPERATORS;
25
26enum class LexicalScopeType {
27    BLOCK,
28    STRICT_BLOCK,
29    CATCH,
30    FUNCTION_PARAM,
31    TS_TYPE_LITERAL,
32};
33
34enum class VariableParsingFlags : uint32_t {
35    NO_OPTS = 0U,
36    NO_SKIP_VAR_KIND = 1U << 0U,
37    ACCEPT_CONST_NO_INIT = 1U << 1U,
38    DISALLOW_INIT = 1U << 2U,
39    VAR = 1U << 3U,
40    LET = 1U << 4U,
41    CONST = 1U << 5U,
42    STOP_AT_IN = 1U << 6U,
43    IN_FOR = 1U << 7U,
44    FOR_OF = 1U << 8U
45};
46
47enum class ExpressionParseFlags : uint32_t {
48    NO_OPTS = 0U,
49    ACCEPT_COMMA = 1U << 0U,
50    ACCEPT_REST = 1U << 1U,
51    EXP_DISALLOW_AS = 1U << 2U,
52    DISALLOW_ASSIGNMENT = 1U << 3U,
53    DISALLOW_YIELD = 1U << 4U,
54    STOP_AT_IN = 1U << 5U,
55    MUST_BE_PATTERN = 1U << 6U,
56    POTENTIALLY_IN_PATTERN = 1U << 7U,
57    OBJECT_PATTERN = 1U << 8U,
58    IN_REST = 1U << 9U,
59    IMPORT = 1U << 10U,
60    POTENTIAL_CLASS_LITERAL = 1U << 11U,
61    IN_FOR = 1U << 12U,
62    INSTANCEOF = 1U << 13U,
63    POTENTIAL_NEW_ARRAY = 1U << 14U
64};
65
66enum class StatementParsingFlags : uint32_t {
67    NONE = 0U,
68    ALLOW_LEXICAL = 1U << 0U,
69    GLOBAL = 1U << 1U,
70    IF_ELSE = 1U << 2U,
71    LABELLED = 1U << 3U,
72
73    STMT_LEXICAL_SCOPE_NEEDED = IF_ELSE | LABELLED,
74    STMT_GLOBAL_LEXICAL = GLOBAL | ALLOW_LEXICAL,
75};
76
77enum class ForStatementKind {
78    UPDATE,
79    IN,
80    OF,
81};
82}  // namespace ark::es2panda::parser
83
84namespace enumbitops {
85
86template <>
87struct IsAllowedType<ark::es2panda::parser::LexicalScopeType> : std::true_type {
88};
89
90template <>
91struct IsAllowedType<ark::es2panda::parser::VariableParsingFlags> : std::true_type {
92};
93
94template <>
95struct IsAllowedType<ark::es2panda::parser::ExpressionParseFlags> : std::true_type {
96};
97
98template <>
99struct IsAllowedType<ark::es2panda::parser::StatementParsingFlags> : std::true_type {
100};
101
102}  // namespace enumbitops
103
104#endif
105