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 ECMASCRIPT_TS_TYPES_TS_TYPE_TABLE_H 17 #define ECMASCRIPT_TS_TYPES_TS_TYPE_TABLE_H 18 19 #include "ecmascript/ts_types/ts_type.h" 20 21 namespace panda::ecmascript { 22 class TSTypeTable : public TaggedArray { 23 public: 24 static constexpr size_t RESERVE_TABLE_LENGTH = 2; // for reserve length and exportTable 25 static constexpr size_t NUMBER_OF_TYPES_INDEX = 0; 26 static constexpr size_t INCREASE_CAPACITY_RATE = 2; 27 static constexpr const char* PRIMITIVE_TABLE_NAME = "primitiveTypes"; 28 static constexpr const char* BUILTINS_TABLE_NAME = "lib_ark_builtins.d"; 29 static constexpr const char* INFER_TABLE_NAME = "inferTypes"; 30 static constexpr const char* RUNTIME_TABLE_NAME = "runtimeTypes"; 31 static constexpr const char* GENERICS_TABLE_NAME = "genericsTypes"; 32 Cast(TaggedObject * object)33 inline static TSTypeTable *Cast(TaggedObject *object) 34 { 35 ASSERT(JSTaggedValue(object).IsTaggedArray()); 36 return static_cast<TSTypeTable *>(object); 37 } 38 39 static JSHandle<JSTaggedValue> GetExportValueTable(JSThread *thread, JSHandle<TSTypeTable> typeTable); 40 41 static void SetExportValueTable(JSThread *thread, JSHandle<TSTypeTable> typeTable, 42 JSHandle<TaggedArray> exportValueTable); 43 GetNumberOfTypes()44 inline int GetNumberOfTypes() const 45 { 46 return TaggedArray::Get(NUMBER_OF_TYPES_INDEX).GetInt(); 47 } 48 49 inline void SetNumberOfTypes(JSThread *thread, uint32_t num = 0) 50 { 51 TaggedArray::Set(thread, NUMBER_OF_TYPES_INDEX, JSTaggedValue(num)); 52 } 53 54 static JSHandle<TSTypeTable> PushBackTypeToTable(JSThread *thread, JSHandle<TSTypeTable> &table, 55 const JSHandle<TSType> &type); 56 }; 57 } // namespace panda::ecmascript 58 59 #endif // ECMASCRIPT_TS_TYPES_TS_TYPE_TABLE_H 60