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_INCLUDE_AST_TS_INDEX_SIGNATURE_H
17 #define ES2PANDA_PARSER_INCLUDE_AST_TS_INDEX_SIGNATURE_H
18 
19 #include "ir/typeNode.h"
20 
21 namespace ark::es2panda::checker {
22 class TSAnalyzer;
23 }  // namespace ark::es2panda::checker
24 
25 namespace ark::es2panda::ir {
26 class TSIndexSignature : public TypedAstNode {
27 public:
28     enum class TSIndexSignatureKind { NUMBER, STRING };
29 
30     TSIndexSignature() = delete;
31     ~TSIndexSignature() override = default;
32 
33     NO_COPY_SEMANTIC(TSIndexSignature);
34     NO_MOVE_SEMANTIC(TSIndexSignature);
35 
TSIndexSignature(Expression *const param, TypeNode *const typeAnnotation, bool const readonly)36     explicit TSIndexSignature(Expression *const param, TypeNode *const typeAnnotation, bool const readonly)
37         : TypedAstNode(AstNodeType::TS_INDEX_SIGNATURE),
38           param_(param),
39           typeAnnotation_(typeAnnotation),
40           readonly_(readonly)
41     {
42     }
43     // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields
44     friend class checker::TSAnalyzer;
45 
46     [[nodiscard]] const Expression *Param() const noexcept
47     {
48         return param_;
49     }
50 
51     [[nodiscard]] const TypeNode *TypeAnnotation() const noexcept
52     {
53         return typeAnnotation_;
54     }
55 
56     [[nodiscard]] bool Readonly() const noexcept
57     {
58         return readonly_;
59     }
60 
61     [[nodiscard]] TSIndexSignatureKind Kind() const noexcept;
62 
63     [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent) override;
64 
65     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
66     void Iterate(const NodeTraverser &cb) const override;
67 
68     void Dump(ir::AstDumper *dumper) const override;
69     void Dump(ir::SrcDumper *dumper) const override;
70     void Compile(compiler::PandaGen *pg) const override;
71     void Compile(compiler::ETSGen *etsg) const override;
72     checker::Type *Check(checker::TSChecker *checker) override;
73     checker::Type *Check(checker::ETSChecker *checker) override;
74 
75     void Accept(ASTVisitorT *v) override
76     {
77         v->Accept(this);
78     }
79 
80 private:
81     Expression *param_;
82     TypeNode *typeAnnotation_;
83     bool readonly_;
84 };
85 }  // namespace ark::es2panda::ir
86 
87 #endif /* TS_INDEX_SIGNATURE_H */
88