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