1 /** 2 * Copyright (c) 2021-2025 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_SIGNATURE_DECLARATION_H 17 #define ES2PANDA_PARSER_INCLUDE_AST_TS_SIGNATURE_DECLARATION_H 18 19 #include "ir/base/scriptFunctionSignature.h" 20 #include "ir/typed.h" 21 22 namespace ark::es2panda::checker { 23 class TSAnalyzer; 24 } // namespace ark::es2panda::checker 25 26 namespace ark::es2panda::ir { 27 class TSTypeParameterDeclaration; 28 29 class TSSignatureDeclaration : public TypedAstNode { 30 public: 31 enum class TSSignatureDeclarationKind { CALL_SIGNATURE, CONSTRUCT_SIGNATURE }; 32 33 TSSignatureDeclaration() = delete; 34 ~TSSignatureDeclaration() override = default; 35 36 NO_COPY_SEMANTIC(TSSignatureDeclaration); 37 NO_MOVE_SEMANTIC(TSSignatureDeclaration); 38 TSSignatureDeclaration(TSSignatureDeclarationKind const kind,FunctionSignature && signature)39 explicit TSSignatureDeclaration(TSSignatureDeclarationKind const kind, FunctionSignature &&signature) 40 : TypedAstNode(AstNodeType::TS_SIGNATURE_DECLARATION), kind_(kind), signature_(std::move(signature)) 41 { 42 } 43 // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields 44 friend class checker::TSAnalyzer; 45 IsScopeBearer()46 [[nodiscard]] bool IsScopeBearer() const noexcept override 47 { 48 return true; 49 } 50 Scope()51 [[nodiscard]] varbinder::Scope *Scope() const noexcept override 52 { 53 return scope_; 54 } 55 SetScope(varbinder::Scope * scope)56 void SetScope(varbinder::Scope *scope) 57 { 58 ES2PANDA_ASSERT(scope_ == nullptr); 59 scope_ = scope; 60 } 61 ClearScope()62 void ClearScope() noexcept override 63 { 64 scope_ = nullptr; 65 } 66 TypeParams()67 [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept 68 { 69 return signature_.TypeParams(); 70 } 71 TypeParams()72 [[nodiscard]] TSTypeParameterDeclaration *TypeParams() 73 { 74 return signature_.TypeParams(); 75 } 76 Params()77 [[nodiscard]] const ArenaVector<ir::Expression *> &Params() const noexcept 78 { 79 return signature_.Params(); 80 } 81 ReturnTypeAnnotation()82 [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept 83 { 84 return signature_.ReturnType(); 85 } 86 ReturnTypeAnnotation()87 TypeNode *ReturnTypeAnnotation() noexcept 88 { 89 return signature_.ReturnType(); 90 } 91 Kind()92 [[nodiscard]] TSSignatureDeclarationKind Kind() const noexcept 93 { 94 return kind_; 95 } 96 97 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 98 void Iterate(const NodeTraverser &cb) const override; 99 100 void Dump(ir::AstDumper *dumper) const override; 101 void Dump(ir::SrcDumper *dumper) const override; 102 void Compile(compiler::PandaGen *pg) const override; 103 void Compile(compiler::ETSGen *etsg) const override; 104 checker::Type *Check(checker::TSChecker *checker) override; 105 checker::VerifiedType Check(checker::ETSChecker *checker) override; 106 Accept(ASTVisitorT * v)107 void Accept(ASTVisitorT *v) override 108 { 109 v->Accept(this); 110 } 111 112 private: 113 varbinder::Scope *scope_ {nullptr}; 114 TSSignatureDeclarationKind kind_; 115 ir::FunctionSignature signature_; 116 }; 117 } // namespace ark::es2panda::ir 118 119 #endif 120