• 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_BREAK_STATEMENT_H
17 #define ES2PANDA_IR_STATEMENT_BREAK_STATEMENT_H
18 
19 #include "ir/statement.h"
20 
21 namespace ark::es2panda::checker {
22 class ETSAnalyzer;
23 }  // namespace ark::es2panda::checker
24 
25 namespace ark::es2panda::compiler {
26 class ETSCompiler;
27 }  // namespace ark::es2panda::compiler
28 
29 namespace ark::es2panda::ir {
30 class Identifier;
31 
32 class BreakStatement : public Statement {
33 public:
34     ~BreakStatement() override = default;
35 
36     NO_COPY_SEMANTIC(BreakStatement);
37     NO_MOVE_SEMANTIC(BreakStatement);
38 
BreakStatement()39     explicit BreakStatement() : Statement(AstNodeType::BREAK_STATEMENT) {}
BreakStatement(Identifier * ident)40     explicit BreakStatement(Identifier *ident) : Statement(AstNodeType::BREAK_STATEMENT), ident_(ident) {}
41 
Ident()42     [[nodiscard]] const Identifier *Ident() const noexcept
43     {
44         return ident_;
45     }
46 
Ident()47     Identifier *Ident() noexcept
48     {
49         return ident_;
50     }
51 
Target()52     [[nodiscard]] const ir::AstNode *Target() const
53     {
54         if (target_.has_value()) {
55             return target_.value();
56         }
57 
58         return nullptr;
59     }
60 
HasTarget()61     [[nodiscard]] bool HasTarget() const noexcept
62     {
63         return target_.has_value();
64     }
65 
SetTarget(ir::AstNode const * target)66     void SetTarget(ir::AstNode const *target) noexcept
67     {
68         target_ = target;
69     }
70 
71     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
72     void Iterate(const NodeTraverser &cb) const override;
73     void Dump(ir::AstDumper *dumper) const override;
74     void Dump(ir::SrcDumper *dumper) const override;
75     void Compile([[maybe_unused]] compiler::PandaGen *pg) const override;
76     void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override;
77     checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override;
78     checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override;
79 
Accept(ASTVisitorT * v)80     void Accept(ASTVisitorT *v) override
81     {
82         v->Accept(this);
83     }
84 
85     [[nodiscard]] BreakStatement *Clone(ArenaAllocator *allocator, AstNode *parent) override;
86 
87 private:
88     Identifier *ident_ {};
89     std::optional<const ir::AstNode *> target_ {};
90 };
91 }  // namespace ark::es2panda::ir
92 
93 #endif
94