1 /** 2 * Copyright (c) 2021 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_TS_INTERFACE_DECLARATION_H 17 #define ES2PANDA_IR_TS_INTERFACE_DECLARATION_H 18 19 #include "varbinder/scope.h" 20 #include "ir/statement.h" 21 #include "util/language.h" 22 23 namespace panda::es2panda::varbinder { 24 class Variable; 25 } // namespace panda::es2panda::varbinder 26 27 namespace panda::es2panda::ir { 28 class Identifier; 29 class TSInterfaceBody; 30 class TSInterfaceHeritage; 31 class TSTypeParameterDeclaration; 32 33 class TSInterfaceDeclaration : public TypedStatement { 34 public: TSInterfaceDeclaration(ArenaAllocator * allocator,Identifier * id,TSTypeParameterDeclaration * typeParams,TSInterfaceBody * body,ArenaVector<TSInterfaceHeritage * > && extends,bool isStatic,bool isExternal,Language lang)35 explicit TSInterfaceDeclaration(ArenaAllocator *allocator, Identifier *id, TSTypeParameterDeclaration *typeParams, 36 TSInterfaceBody *body, ArenaVector<TSInterfaceHeritage *> &&extends, bool isStatic, 37 bool isExternal, Language lang) 38 : TypedStatement(AstNodeType::TS_INTERFACE_DECLARATION), 39 decorators_(allocator->Adapter()), 40 id_(id), 41 typeParams_(typeParams), 42 body_(body), 43 extends_(std::move(extends)), 44 isStatic_(isStatic), 45 isExternal_(isExternal), 46 lang_(lang) 47 { 48 if (isStatic_) { 49 AddModifier(ir::ModifierFlags::STATIC); 50 } 51 } 52 IsScopeBearer()53 bool IsScopeBearer() const override 54 { 55 return true; 56 } 57 Scope()58 varbinder::LocalScope *Scope() const override 59 { 60 return scope_; 61 } 62 SetScope(varbinder::LocalScope * scope)63 void SetScope(varbinder::LocalScope *scope) 64 { 65 scope_ = scope; 66 } 67 Body()68 TSInterfaceBody *Body() 69 { 70 return body_; 71 } 72 Body()73 const TSInterfaceBody *Body() const 74 { 75 return body_; 76 } 77 Id()78 Identifier *Id() 79 { 80 return id_; 81 } 82 Id()83 const Identifier *Id() const 84 { 85 return id_; 86 } 87 InternalName()88 const util::StringView &InternalName() const 89 { 90 return internalName_; 91 } 92 SetInternalName(util::StringView internalName)93 void SetInternalName(util::StringView internalName) 94 { 95 internalName_ = internalName; 96 } 97 IsStatic()98 bool IsStatic() const 99 { 100 return isStatic_; 101 } 102 IsFromExternal()103 bool IsFromExternal() const 104 { 105 return isExternal_; 106 } 107 TypeParams()108 const TSTypeParameterDeclaration *TypeParams() const 109 { 110 return typeParams_; 111 } 112 TypeParams()113 TSTypeParameterDeclaration *TypeParams() 114 { 115 return typeParams_; 116 } 117 Extends()118 ArenaVector<TSInterfaceHeritage *> &Extends() 119 { 120 return extends_; 121 } 122 Extends()123 const ArenaVector<TSInterfaceHeritage *> &Extends() const 124 { 125 return extends_; 126 } 127 Decorators()128 const ArenaVector<Decorator *> &Decorators() const 129 { 130 return decorators_; 131 } 132 DecoratorsPtr()133 const ArenaVector<Decorator *> *DecoratorsPtr() const override 134 { 135 return &Decorators(); 136 } 137 AddDecorators(ArenaVector<ir::Decorator * > && decorators)138 void AddDecorators([[maybe_unused]] ArenaVector<ir::Decorator *> &&decorators) override 139 { 140 decorators_ = std::move(decorators); 141 } 142 CanHaveDecorator(bool inTs)143 bool CanHaveDecorator([[maybe_unused]] bool inTs) const override 144 { 145 return !inTs; 146 } 147 148 void TransformChildren(const NodeTransformer &cb) override; 149 Language()150 es2panda::Language Language() const 151 { 152 return lang_; 153 } 154 155 void Iterate(const NodeTraverser &cb) const override; 156 void Dump(ir::AstDumper *dumper) const override; 157 void Dump(ir::SrcDumper *dumper) const override; 158 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 159 void Compile(compiler::ETSGen *etsg) const override; 160 checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; 161 checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; 162 checker::Type *InferType(checker::TSChecker *checker, varbinder::Variable *bindingVar) const; 163 Accept(ASTVisitorT * v)164 void Accept(ASTVisitorT *v) override 165 { 166 v->Accept(this); 167 } 168 169 private: 170 ArenaVector<Decorator *> decorators_; 171 varbinder::LocalScope *scope_ {nullptr}; 172 Identifier *id_; 173 TSTypeParameterDeclaration *typeParams_; 174 TSInterfaceBody *body_; 175 ArenaVector<TSInterfaceHeritage *> extends_; 176 util::StringView internalName_ {}; 177 bool isStatic_; 178 bool isExternal_; 179 es2panda::Language lang_; 180 }; 181 } // namespace panda::es2panda::ir 182 183 #endif 184