• 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_PARSER_INCLUDE_AST_TS_METHOD_SIGNATURE_H
17 #define ES2PANDA_PARSER_INCLUDE_AST_TS_METHOD_SIGNATURE_H
18 
19 #include "ir/typeNode.h"
20 #include "ir/base/scriptFunctionSignature.h"
21 
22 namespace panda::es2panda::checker {
23 class TSAnalyzer;
24 class ETSAnalyzer;
25 }  // namespace panda::es2panda::checker
26 
27 namespace panda::es2panda::ir {
28 class TSTypeParameterDeclaration;
29 
30 class TSMethodSignature : public AstNode {
31 public:
32     TSMethodSignature() = delete;
33     ~TSMethodSignature() override = default;
34 
35     NO_COPY_SEMANTIC(TSMethodSignature);
36     NO_MOVE_SEMANTIC(TSMethodSignature);
37 
TSMethodSignature(Expression * key,ir::FunctionSignature && signature,bool computed,bool optional)38     explicit TSMethodSignature(Expression *key, ir::FunctionSignature &&signature, bool computed, bool optional)
39         : AstNode(AstNodeType::TS_METHOD_SIGNATURE),
40           key_(key),
41           signature_(std::move(signature)),
42           computed_(computed),
43           optional_(optional)
44     {
45     }
46 
47     // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields
48     friend class checker::TSAnalyzer;
49 
IsScopeBearer()50     bool IsScopeBearer() const override
51     {
52         return true;
53     }
54 
Scope()55     varbinder::Scope *Scope() const override
56     {
57         return scope_;
58     }
59 
SetScope(varbinder::Scope * scope)60     void SetScope(varbinder::Scope *scope)
61     {
62         scope_ = scope;
63     }
64 
Key()65     [[nodiscard]] const Expression *Key() const noexcept
66     {
67         return key_;
68     }
69 
Key()70     [[nodiscard]] Expression *Key() noexcept
71     {
72         return key_;
73     }
74 
TypeParams()75     [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept
76     {
77         return signature_.TypeParams();
78     }
79 
TypeParams()80     [[nodiscard]] TSTypeParameterDeclaration *TypeParams()
81     {
82         return signature_.TypeParams();
83     }
84 
Params()85     [[nodiscard]] const ArenaVector<Expression *> &Params() const noexcept
86     {
87         return signature_.Params();
88     }
89 
ReturnTypeAnnotation()90     [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept
91     {
92         return signature_.ReturnType();
93     }
94 
ReturnTypeAnnotation()95     TypeNode *ReturnTypeAnnotation()
96     {
97         return signature_.ReturnType();
98     }
99 
Computed()100     [[nodiscard]] bool Computed() const noexcept
101     {
102         return computed_;
103     }
104 
Optional()105     [[nodiscard]] bool Optional() const noexcept
106     {
107         return optional_;
108     }
109 
110     void TransformChildren(const NodeTransformer &cb) override;
111     void Iterate(const NodeTraverser &cb) const override;
112 
113     void Dump(ir::AstDumper *dumper) const override;
114     void Dump(ir::SrcDumper *dumper) const override;
115     void Compile(compiler::PandaGen *pg) const override;
116     void Compile(compiler::ETSGen *etsg) const override;
117     checker::Type *Check(checker::TSChecker *checker) override;
118     checker::Type *Check(checker::ETSChecker *checker) override;
119 
Accept(ASTVisitorT * v)120     void Accept(ASTVisitorT *v) override
121     {
122         v->Accept(this);
123     }
124 
125 private:
126     varbinder::Scope *scope_ {nullptr};
127     Expression *key_;
128     ir::FunctionSignature signature_;
129     bool computed_;
130     bool optional_;
131 };
132 }  // namespace panda::es2panda::ir
133 
134 #endif
135