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_COMPILER_CHECKER_TYPES_ETS_DYNAMIC_TYPE_H 17 #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_DYNAMIC_TYPE_H 18 19 #include "checker/types/ets/etsObjectType.h" 20 21 namespace panda::es2panda::checker { 22 class ETSDynamicType : public ETSObjectType { 23 public: ETSDynamicType(ArenaAllocator * allocator,util::StringView name,util::StringView assemblerName,ir::AstNode * declNode,ETSObjectFlags flags,Language lang,bool hasDecl)24 explicit ETSDynamicType(ArenaAllocator *allocator, util::StringView name, util::StringView assemblerName, 25 ir::AstNode *declNode, ETSObjectFlags flags, Language lang, bool hasDecl) 26 : ETSObjectType(allocator, name, assemblerName, declNode, flags | ETSObjectFlags::DYNAMIC), 27 propertiesCache_ {allocator->Adapter()}, 28 lang_(lang), 29 hasDecl_(hasDecl) 30 { 31 AddTypeFlag(TypeFlag::ETS_DYNAMIC_TYPE); 32 } 33 34 varbinder::LocalVariable *GetPropertyDynamic(const util::StringView &name, const ETSChecker *checker) const; 35 void AssignmentTarget(TypeRelation *relation, Type *source) override; 36 bool AssignmentSource(TypeRelation *relation, Type *target) override; 37 void Cast(TypeRelation *relation, Type *target) override; 38 void CastTarget(TypeRelation *relation, Type *source) override; 39 Language()40 es2panda::Language Language() const 41 { 42 return lang_; 43 } 44 HasDecl()45 bool HasDecl() const 46 { 47 return hasDecl_; 48 } 49 50 ETSFunctionType *CreateETSFunctionType(const util::StringView &name) const override; 51 52 void ToAssemblerType(std::stringstream &ss) const override; 53 54 static bool IsConvertible(Type const *target); 55 56 private: 57 mutable PropertyMap propertiesCache_; 58 es2panda::Language lang_; 59 bool hasDecl_; 60 }; 61 } // namespace panda::es2panda::checker 62 63 #endif 64