• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-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 #ifndef ES2PANDA_IR_STATEMENT_SWITCH_CASE_STATEMENT_H
17 #define ES2PANDA_IR_STATEMENT_SWITCH_CASE_STATEMENT_H
18 
19 #include "ir/expression.h"
20 #include "ir/statement.h"
21 
22 namespace ark::es2panda::ir {
23 class Expression;
24 
25 class SwitchCaseStatement : public Statement {
26 public:
27     SwitchCaseStatement() = delete;
28     ~SwitchCaseStatement() override = default;
29 
30     NO_COPY_SEMANTIC(SwitchCaseStatement);
31     NO_MOVE_SEMANTIC(SwitchCaseStatement);
32 
SwitchCaseStatement(Expression * test,ArenaVector<Statement * > && consequent)33     explicit SwitchCaseStatement(Expression *test, ArenaVector<Statement *> &&consequent)
34         : Statement(AstNodeType::SWITCH_CASE_STATEMENT), test_(test), consequent_(std::move(consequent))
35     {
36     }
37 
Test()38     [[nodiscard]] Expression *Test() noexcept
39     {
40         return test_;
41     }
42 
Test()43     [[nodiscard]] const Expression *Test() const noexcept
44     {
45         return test_;
46     }
47 
SetTest(Expression * test)48     void SetTest(Expression *test) noexcept
49     {
50         if (test != nullptr) {
51             test->SetParent(this);
52         }
53         test_ = test;
54     }
55 
Consequent()56     [[nodiscard]] const ArenaVector<Statement *> &Consequent() const noexcept
57     {
58         return consequent_;
59     }
60 
61     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
62 
63     void Iterate(const NodeTraverser &cb) const override;
64     void Dump(ir::AstDumper *dumper) const override;
65     void Dump(ir::SrcDumper *dumper) const override;
66     void Compile(compiler::PandaGen *pg) const override;
67     void Compile(compiler::ETSGen *etsg) const override;
68     checker::Type *Check(checker::TSChecker *checker) override;
69     checker::VerifiedType Check(checker::ETSChecker *checker) override;
70 
71     void CheckAndTestCase(checker::ETSChecker *checker, checker::Type *comparedExprType, checker::Type *unboxedDiscType,
72                           ir::Expression *node, bool &isDefaultCase);
73 
Accept(ASTVisitorT * v)74     void Accept(ASTVisitorT *v) override
75     {
76         v->Accept(this);
77     }
78 
79     [[nodiscard]] SwitchCaseStatement *Clone(ArenaAllocator *allocator, AstNode *parent) override;
80 
81 private:
82     Expression *test_;
83     ArenaVector<Statement *> consequent_;
84 };
85 }  // namespace ark::es2panda::ir
86 
87 #endif
88