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_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 ark::es2panda::checker { 22 class ETSDynamicType : public ETSObjectType { 23 static constexpr auto NAME = 0; 24 static constexpr auto ASSEMBLER_NAME = 1; 25 static constexpr auto LANGUAGE = 2; 26 static constexpr auto DECL_NODE = 0; 27 static constexpr auto FLAGS = 1; 28 static constexpr auto RELATION = 2; 29 30 public: ETSDynamicType(ArenaAllocator * allocator,std::tuple<util::StringView,util::StringView,Language> label,std::tuple<ir::AstNode *,ETSObjectFlags,TypeRelation * > info,bool hasDecl)31 explicit ETSDynamicType(ArenaAllocator *allocator, std::tuple<util::StringView, util::StringView, Language> label, 32 std::tuple<ir::AstNode *, ETSObjectFlags, TypeRelation *> info, bool hasDecl) 33 : ETSObjectType(allocator, std::get<NAME>(label), std::get<ASSEMBLER_NAME>(label), 34 std::make_tuple(std::get<DECL_NODE>(info), std::get<FLAGS>(info) | ETSObjectFlags::DYNAMIC, 35 std::get<RELATION>(info))), 36 propertiesCache_ {allocator->Adapter()}, 37 lang_(std::get<LANGUAGE>(label)), 38 hasDecl_(hasDecl) 39 { 40 AddTypeFlag(TypeFlag::ETS_DYNAMIC_TYPE); 41 } 42 43 varbinder::LocalVariable *GetPropertyDynamic(const util::StringView &name, const ETSChecker *checker) const; 44 void AssignmentTarget(TypeRelation *relation, Type *source) override; 45 bool AssignmentSource(TypeRelation *relation, Type *target) override; 46 void Cast(TypeRelation *relation, Type *target) override; 47 void CastTarget(TypeRelation *relation, Type *source) override; 48 Language()49 es2panda::Language Language() const 50 { 51 return lang_; 52 } 53 HasDecl()54 bool HasDecl() const 55 { 56 return hasDecl_; 57 } 58 59 ETSFunctionType *CreateETSFunctionType(const util::StringView &name) const override; 60 61 void ToAssemblerType(std::stringstream &ss) const override; 62 63 static bool IsConvertible(Type const *target); 64 65 private: 66 mutable PropertyMap propertiesCache_; 67 es2panda::Language lang_; 68 bool hasDecl_; 69 }; 70 } // namespace ark::es2panda::checker 71 72 #endif 73