• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMPILER_TS_HCLASS_GENERATOR_H
17 #define ECMASCRIPT_COMPILER_TS_HCLASS_GENERATOR_H
18 
19 #include "ecmascript/ts_types/ts_manager.h"
20 
21 namespace panda::ecmascript::kungfu {
22 class TSHClassGenerator {
23 public:
TSHClassGenerator(TSManager * tsManager)24     explicit TSHClassGenerator(TSManager *tsManager): tsManager_(tsManager) {};
25     ~TSHClassGenerator() = default;
26 
27     void GenerateTSHClasses() const;
28 
29 private:
30     void RecursiveGenerate(const JSHandle<TSClassType> &classType) const;
31 
32     JSHandle<JSHClass> Generate(const JSHandle<TSClassType> &classType) const;
33 
34     enum class Kind : uint8_t {
35         INSTANCE = 0,
36         PROTOTYPE,
37         CONSTRUCTOR,
38     };
39 
40     JSHandle<JSHClass> CreateHClass(const JSThread *thread, const JSHandle<TSClassType> &classType, Kind kind) const;
41 
42     JSHandle<JSHClass> CreateIHClass(const JSThread *thread, const JSHandle<TSClassType> &classType) const;
43 
44     JSHandle<JSHClass> CreatePHClass(const JSThread *thread, const JSHandle<TSClassType> &classType) const;
45 
46     JSHandle<JSHClass> CreateCHClass(const JSThread *thread, const JSHandle<TSClassType> &classType) const;
47 
GetCollectedGT()48     inline const std::set<GlobalTSTypeRef>& GetCollectedGT() const
49     {
50         return tsManager_->GetCollectedGT();
51     }
52 
53     TSManager *tsManager_ {nullptr};
54 };
55 }  // namespace panda::ecmascript::kungfu
56 #endif  // ECMASCRIPT_COMPILER_TS_HCLASS_GENERATOR_H
57