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 Cast(TaggedObject * object)32 inline static TSTypeTable *Cast(TaggedObject *object) 33 { 34 ASSERT(JSTaggedValue(object).IsTaggedArray()); 35 return static_cast<TSTypeTable *>(object); 36 } 37 38 static JSHandle<JSTaggedValue> GetExportValueTable(JSThread *thread, JSHandle<TSTypeTable> typeTable); 39 40 static void SetExportValueTable(JSThread *thread, JSHandle<TSTypeTable> typeTable, 41 JSHandle<TaggedArray> exportValueTable); 42 GetNumberOfTypes()43 inline int GetNumberOfTypes() const 44 { 45 return TaggedArray::Get(NUMBER_OF_TYPES_INDEX).GetInt(); 46 } 47 48 inline void SetNumberOfTypes(JSThread *thread, uint32_t num = 0) 49 { 50 TaggedArray::Set(thread, NUMBER_OF_TYPES_INDEX, JSTaggedValue(num)); 51 } 52 53 static JSHandle<TSTypeTable> PushBackTypeToTable(JSThread *thread, JSHandle<TSTypeTable> &table, 54 const JSHandle<TSType> &type); 55 }; 56 } // namespace panda::ecmascript 57 58 #endif // ECMASCRIPT_TS_TYPES_TS_TYPE_TABLE_H 59