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