• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024-2025 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, ClassLinkerContext *classLinkerContext,
53                       ClassLinkerErrorHandler *errorHandler = nullptr);
54     Method *GetAsyncImplMethod(Method *method, EtsCoroutine *coroutine);
55 
GetEtsClassLinkerExtension()56     EtsClassLinkerExtension *GetEtsClassLinkerExtension()
57     {
58         return ext_;
59     }
60 
61     NO_COPY_SEMANTIC(EtsClassLinker);
62     NO_MOVE_SEMANTIC(EtsClassLinker);
63 
64 private:
65     explicit EtsClassLinker(ClassLinker *classLinker);
66 
67     ClassLinker *classLinker_ {};
68     EtsClassLinkerExtension *ext_ {};
69 
70     friend class mem::Allocator;
71 };
72 
73 }  // namespace ark::ets
74 
75 #endif  // !PANDA_PLUGINS_ETS_RUNTIME_ETS_CLASS_LINKER_H_
76