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_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 ark::es2panda::checker { 23 class TSAnalyzer; 24 class ETSAnalyzer; 25 } // namespace ark::es2panda::checker 26 27 namespace ark::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 50 [[nodiscard]] bool IsScopeBearer() const noexcept override 51 { 52 return true; 53 } 54 55 [[nodiscard]] varbinder::Scope *Scope() const noexcept override 56 { 57 return scope_; 58 } 59 SetScope(varbinder::Scope *scope)60 void SetScope(varbinder::Scope *scope) 61 { 62 ASSERT(scope_ == nullptr); 63 scope_ = scope; 64 } 65 66 void ClearScope() noexcept override 67 { 68 scope_ = nullptr; 69 } 70 71 [[nodiscard]] const Expression *Key() const noexcept 72 { 73 return key_; 74 } 75 76 [[nodiscard]] Expression *Key() noexcept 77 { 78 return key_; 79 } 80 81 [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept 82 { 83 return signature_.TypeParams(); 84 } 85 TypeParams()86 [[nodiscard]] TSTypeParameterDeclaration *TypeParams() 87 { 88 return signature_.TypeParams(); 89 } 90 91 [[nodiscard]] const ArenaVector<Expression *> &Params() const noexcept 92 { 93 return signature_.Params(); 94 } 95 96 [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept 97 { 98 return signature_.ReturnType(); 99 } 100 ReturnTypeAnnotation()101 TypeNode *ReturnTypeAnnotation() 102 { 103 return signature_.ReturnType(); 104 } 105 106 [[nodiscard]] bool Computed() const noexcept 107 { 108 return computed_; 109 } 110 111 [[nodiscard]] bool Optional() const noexcept 112 { 113 return optional_; 114 } 115 116 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 117 void Iterate(const NodeTraverser &cb) const override; 118 119 void Dump(ir::AstDumper *dumper) const override; 120 void Dump(ir::SrcDumper *dumper) const override; 121 void Compile(compiler::PandaGen *pg) const override; 122 void Compile(compiler::ETSGen *etsg) const override; 123 checker::Type *Check(checker::TSChecker *checker) override; 124 checker::Type *Check(checker::ETSChecker *checker) override; 125 126 void Accept(ASTVisitorT *v) override 127 { 128 v->Accept(this); 129 } 130 131 private: 132 varbinder::Scope *scope_ {nullptr}; 133 Expression *key_; 134 ir::FunctionSignature signature_; 135 bool computed_; 136 bool optional_; 137 }; 138 } // namespace ark::es2panda::ir 139 140 #endif 141