• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 - 2023 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_ETS_FUNCTION_TYPE_H
17 #define ES2PANDA_IR_ETS_FUNCTION_TYPE_H
18 
19 #include "ir/typeNode.h"
20 #include "ir/base/scriptFunctionSignature.h"
21 
22 namespace panda::es2panda::checker {
23 class ETSAnalyzer;
24 }  // namespace panda::es2panda::checker
25 
26 namespace panda::es2panda::ir {
27 class TSTypeParameterDeclaration;
28 
29 class ETSFunctionType : public TypeNode {
30 public:
ETSFunctionType(FunctionSignature && signature,ir::ScriptFunctionFlags funcFlags)31     explicit ETSFunctionType(FunctionSignature &&signature, ir::ScriptFunctionFlags funcFlags)
32         : TypeNode(AstNodeType::ETS_FUNCTION_TYPE), signature_(std::move(signature)), funcFlags_(funcFlags)
33     {
34     }
35 
IsScopeBearer()36     bool IsScopeBearer() const override
37     {
38         return true;
39     }
40 
Scope()41     varbinder::Scope *Scope() const override
42     {
43         return scope_;
44     }
45 
SetScope(varbinder::Scope * scope)46     void SetScope(varbinder::Scope *scope)
47     {
48         scope_ = scope;
49     }
50 
TypeParams()51     const TSTypeParameterDeclaration *TypeParams() const
52     {
53         return signature_.TypeParams();
54     }
55 
Params()56     const ArenaVector<Expression *> &Params() const
57     {
58         return signature_.Params();
59     }
60 
ReturnType()61     const TypeNode *ReturnType() const
62     {
63         return signature_.ReturnType();
64     }
65 
ReturnType()66     TypeNode *ReturnType()
67     {
68         return signature_.ReturnType();
69     }
70 
FunctionalInterface()71     ir::TSInterfaceDeclaration *FunctionalInterface()
72     {
73         return functionalInterface_;
74     }
75 
FunctionalInterface()76     const ir::TSInterfaceDeclaration *FunctionalInterface() const
77     {
78         return functionalInterface_;
79     }
80 
SetFunctionalInterface(ir::TSInterfaceDeclaration * functionalInterface)81     void SetFunctionalInterface(ir::TSInterfaceDeclaration *functionalInterface)
82     {
83         functionalInterface_ = functionalInterface;
84     }
85 
Flags()86     ir::ScriptFunctionFlags Flags()
87     {
88         return funcFlags_;
89     }
90 
IsThrowing()91     bool IsThrowing() const
92     {
93         return (funcFlags_ & ir::ScriptFunctionFlags::THROWS) != 0;
94     }
95 
96     void TransformChildren(const NodeTransformer &cb) override;
97     void Iterate(const NodeTraverser &cb) const override;
98     void Dump(ir::AstDumper *dumper) const override;
99     void Dump(ir::SrcDumper *dumper) const override;
100     void Compile(compiler::PandaGen *pg) const override;
101     void Compile(compiler::ETSGen *etsg) const override;
102     checker::Type *Check(checker::TSChecker *checker) override;
103     checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override;
104     checker::Type *Check(checker::ETSChecker *checker) override;
105     checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override;
106 
Accept(ASTVisitorT * v)107     void Accept(ASTVisitorT *v) override
108     {
109         v->Accept(this);
110     }
111 
112     // NOLINTNEXTLINE(google-default-arguments)
113     [[nodiscard]] ETSFunctionType *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override;
114 
115 private:
116     varbinder::Scope *scope_ {};
117     FunctionSignature signature_;
118     ir::TSInterfaceDeclaration *functionalInterface_ {};
119     ir::ScriptFunctionFlags funcFlags_;
120 };
121 }  // namespace panda::es2panda::ir
122 
123 #endif
124