1 /* 2 * Copyright (c) 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 ECMASCRIPT_TS_TYPES_TS_TYPE_TABLE_GENERATOR_H 17 #define ECMASCRIPT_TS_TYPES_TS_TYPE_TABLE_GENERATOR_H 18 19 #include "ecmascript/ts_types/ts_manager.h" 20 #include "ecmascript/ts_types/ts_type_table.h" 21 22 namespace panda::ecmascript { 23 class TSTypeTableGenerator { 24 public: TSTypeTableGenerator(TSManager * tsManager)25 explicit TSTypeTableGenerator(TSManager *tsManager) 26 : tsManager_(tsManager), vm_(tsManager->GetEcmaVM()), 27 thread_(vm_->GetJSThread()), factory_(vm_->GetFactory()) {} 28 ~TSTypeTableGenerator() = default; 29 30 void GenerateDefaultTSTypeTables(); 31 32 JSHandle<TSTypeTable> GetOrGenerateTSTypeTable(const JSPandaFile *jsPandaFile, 33 const CString &recordName, 34 uint32_t moduleId); 35 36 uint32_t TryGetModuleId(const CString &recordName) const; 37 38 uint32_t TryGetLocalId(const JSHandle<TSTypeTable> &table) const; 39 40 private: GetTSModuleTable()41 inline JSHandle<TSModuleTable> GetTSModuleTable() const 42 { 43 return tsManager_->GetTSModuleTable(); 44 } 45 GetNextModuleId()46 int GetNextModuleId() const 47 { 48 JSHandle<TSModuleTable> table = GetTSModuleTable(); 49 return table->GetNumberOfTSTypeTables(); 50 } 51 52 JSHandle<TSTypeTable> AddTypeTable(const JSHandle<EcmaString> &recordNameStr, uint32_t numTypes = 0); 53 54 void GenerateBuiltinsTypeTable(); 55 56 void InitRuntimeTypeTable(); 57 58 void FillLayoutTypes(const JSHandle<TSObjLayoutInfo> &layout, 59 const std::vector<JSHandle<JSTaggedValue>> &prop, 60 const std::vector<GlobalTSTypeRef> &propType); 61 62 TSManager *tsManager_ {nullptr}; 63 EcmaVM *vm_ {nullptr}; 64 JSThread *thread_ {nullptr}; 65 ObjectFactory *factory_ {nullptr}; 66 }; 67 } // panda::ecmascript 68 #endif // ECMASCRIPT_TS_TYPES_TS_TYPE_TABLE_GENERATOR_H 69