• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024 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 PANDA_PLUGINS_ETS_RUNTIME_ETS_CLASS_LINKER_H_
17 #define PANDA_PLUGINS_ETS_RUNTIME_ETS_CLASS_LINKER_H_
18 
19 #include "plugins/ets/runtime/ets_class_root.h"
20 #include "runtime/include/mem/panda_smart_pointers.h"
21 #include "runtime/include/mem/panda_string.h"
22 #include "runtime/include/mem/panda_containers.h"
23 
24 namespace ark {
25 class Method;
26 class ClassLinker;
27 class ClassLinkerContext;
28 class ClassLinkerErrorHandler;
29 }  // namespace ark
30 
31 namespace ark::ets {
32 
33 class EtsClass;
34 class EtsClassLinkerExtension;
35 class EtsCoroutine;
36 
37 class PANDA_PUBLIC_API EtsClassLinker {
38 public:
39     static Expected<PandaUniquePtr<EtsClassLinker>, PandaString> Create(ClassLinker *classLinker);
40     ~EtsClassLinker() = default;
41 
42     bool Initialize();
43 
44     bool InitializeClass(EtsCoroutine *coroutine, EtsClass *klass);
45     EtsClass *GetClassRoot(EtsClassRoot root) const;
46     EtsClass *GetClass(const char *name, bool needCopyDescriptor = false,
47                        ClassLinkerContext *classLinkerContext = nullptr,
48                        ClassLinkerErrorHandler *errorHandler = nullptr);
49     EtsClass *GetClass(const panda_file::File &pf, panda_file::File::EntityId id,
50                        ClassLinkerContext *classLinkerContext = nullptr,
51                        ClassLinkerErrorHandler *errorHandler = nullptr);
52     Method *GetMethod(const panda_file::File &pf, panda_file::File::EntityId id);
53     Method *GetAsyncImplMethod(Method *method, EtsCoroutine *coroutine);
54     EtsClass *GetPromiseClass();
55     EtsClass *GetPromiseRefClass();
56     EtsClass *GetArrayClass();
57     EtsClass *GetWaitersListClass();
58     EtsClass *GetMutexClass();
59     EtsClass *GetEventClass();
60     EtsClass *GetCondVarClass();
61     EtsClass *GetArrayBufferClass();
62     EtsClass *GetStringBuilderClass();
63     EtsClass *GetSharedMemoryClass();
64     EtsClass *GetObjectClass();
65     EtsClass *GetVoidClass();
66     EtsClass *GetTypeAPIFieldClass();
67     EtsClass *GetTypeAPIMethodClass();
68     EtsClass *GetTypeAPIParameterClass();
69     EtsClass *GetFunctionClass();
70     EtsClass *GetFinalizableWeakRefClass();
71     // NOTE(molotkovmikhail): Need to implement a method cache that should be accessible by some class and method ids.
72     Method *GetSubscribeOnAnotherPromiseMethod();
73 
GetEtsClassLinkerExtension()74     EtsClassLinkerExtension *GetEtsClassLinkerExtension()
75     {
76         return ext_;
77     }
78 
79     NO_COPY_SEMANTIC(EtsClassLinker);
80     NO_MOVE_SEMANTIC(EtsClassLinker);
81 
82 private:
83     explicit EtsClassLinker(ClassLinker *classLinker);
84 
85     ClassLinker *classLinker_ {};
86     EtsClassLinkerExtension *ext_ {};
87 
88     friend class mem::Allocator;
89 };
90 
91 }  // namespace ark::ets
92 
93 #endif  // !PANDA_PLUGINS_ETS_RUNTIME_ETS_CLASS_LINKER_H_
94