• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TS_TYPE_ALIAS_DECLARATION_H
17 #define ES2PANDA_IR_TS_TYPE_ALIAS_DECLARATION_H
18 
19 #include "ir/statement.h"
20 #include "ir/typed.h"
21 
22 namespace ark::es2panda::varbinder {
23 class Variable;
24 }  // namespace ark::es2panda::varbinder
25 
26 namespace ark::es2panda::ir {
27 class Identifier;
28 class TSTypeParameterDeclaration;
29 
30 class TSTypeAliasDeclaration : public AnnotatedStatement {
31 public:
TSTypeAliasDeclaration(ArenaAllocator * allocator,Identifier * id,TSTypeParameterDeclaration * typeParams,TypeNode * typeAnnotation,bool declare)32     explicit TSTypeAliasDeclaration(ArenaAllocator *allocator, Identifier *id, TSTypeParameterDeclaration *typeParams,
33                                     TypeNode *typeAnnotation, bool declare)
34         : AnnotatedStatement(AstNodeType::TS_TYPE_ALIAS_DECLARATION, typeAnnotation),
35           decorators_(allocator->Adapter()),
36           id_(id),
37           typeParams_(typeParams),
38           typeParamTypes_(allocator->Adapter()),
39           declare_(declare)
40     {
41     }
42 
TSTypeAliasDeclaration(ArenaAllocator * allocator,Identifier * id)43     explicit TSTypeAliasDeclaration(ArenaAllocator *allocator, Identifier *id)
44         : AnnotatedStatement(AstNodeType::TS_TYPE_ALIAS_DECLARATION),
45           decorators_(allocator->Adapter()),
46           id_(id),
47           typeParams_(nullptr),
48           typeParamTypes_(allocator->Adapter()),
49           declare_(false)
50     {
51     }
52 
Id()53     Identifier *Id()
54     {
55         return id_;
56     }
57 
Id()58     const Identifier *Id() const
59     {
60         return id_;
61     }
62 
TypeParams()63     TSTypeParameterDeclaration *TypeParams() const
64     {
65         return typeParams_;
66     }
67 
Declare()68     bool Declare() const
69     {
70         return declare_;
71     }
72 
Decorators()73     const ArenaVector<Decorator *> &Decorators() const
74     {
75         return decorators_;
76     }
77 
DecoratorsPtr()78     const ArenaVector<Decorator *> *DecoratorsPtr() const override
79     {
80         return &Decorators();
81     }
82 
SetTypeParameters(ir::TSTypeParameterDeclaration * typeParams)83     void SetTypeParameters(ir::TSTypeParameterDeclaration *typeParams)
84     {
85         typeParams_ = typeParams;
86     }
87 
AddDecorators(ArenaVector<ir::Decorator * > && decorators)88     void AddDecorators([[maybe_unused]] ArenaVector<ir::Decorator *> &&decorators) override
89     {
90         decorators_ = std::move(decorators);
91     }
92 
CanHaveDecorator(bool inTs)93     bool CanHaveDecorator([[maybe_unused]] bool inTs) const override
94     {
95         return !inTs;
96     }
97 
SetTypeParameterTypes(ArenaVector<checker::Type * > && typeParamTypes)98     void SetTypeParameterTypes(ArenaVector<checker::Type *> &&typeParamTypes)
99     {
100         typeParamTypes_ = std::move(typeParamTypes);
101     }
102 
TypeParameterTypes()103     ArenaVector<checker::Type *> const &TypeParameterTypes() const
104     {
105         return typeParamTypes_;
106     }
107 
108     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
109     void Iterate(const NodeTraverser &cb) const override;
110     void Dump(ir::AstDumper *dumper) const override;
111     void Dump(ir::SrcDumper *dumper) const override;
112     void Compile([[maybe_unused]] compiler::PandaGen *pg) const override;
113     void Compile(compiler::ETSGen *etsg) const override;
114     checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override;
115     checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override;
116 
Accept(ASTVisitorT * v)117     void Accept(ASTVisitorT *v) override
118     {
119         v->Accept(this);
120     }
121 
122 private:
123     ArenaVector<Decorator *> decorators_;
124     Identifier *id_;
125     TSTypeParameterDeclaration *typeParams_;
126     ArenaVector<checker::Type *> typeParamTypes_;
127     bool declare_;
128 };
129 }  // namespace ark::es2panda::ir
130 
131 #endif
132