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_IR_EXPRESSION_CHAIN_EXPRESSION_H
17#define ES2PANDA_IR_EXPRESSION_CHAIN_EXPRESSION_H
18
19#include "ir/expression.h"
20#include "ir/irnode.h"
21
22namespace ark::es2panda::checker {
23class TSAnalyzer;
24}  // namespace ark::es2panda::checker
25
26namespace ark::es2panda::ir {
27class ChainExpression : public Expression {
28public:
29    ChainExpression() = delete;
30    ~ChainExpression() override = default;
31
32    NO_COPY_SEMANTIC(ChainExpression);
33    NO_MOVE_SEMANTIC(ChainExpression);
34
35    explicit ChainExpression(Expression *expression)
36        : Expression(AstNodeType::CHAIN_EXPRESSION), expression_(expression)
37    {
38    }
39
40    // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields
41    friend class checker::TSAnalyzer;
42
43    const Expression *GetExpression() const noexcept
44    {
45        return expression_;
46    }
47
48    Expression *GetExpression() noexcept
49    {
50        return expression_;
51    }
52
53    [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override;
54
55    void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
56    void Iterate(const NodeTraverser &cb) const override;
57    void Dump(ir::AstDumper *dumper) const override;
58    void Dump(ir::SrcDumper *dumper) const override;
59    void Compile(compiler::PandaGen *pg) const override;
60    void Compile(compiler::ETSGen *etsg) const override;
61    void CompileToReg(compiler::PandaGen *pg, compiler::VReg &objReg) const;
62    checker::Type *Check(checker::TSChecker *checker) override;
63    checker::Type *Check(checker::ETSChecker *checker) override;
64
65    void Accept(ASTVisitorT *v) override
66    {
67        v->Accept(this);
68    }
69
70private:
71    Expression *expression_;
72};
73}  // namespace ark::es2panda::ir
74
75#endif
76