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 *GetArrayBufferClass(); 58 EtsClass *GetStringBuilderClass(); 59 EtsClass *GetSharedMemoryClass(); 60 EtsClass *GetObjectClass(); 61 EtsClass *GetVoidClass(); 62 EtsClass *GetTypeAPIFieldClass(); 63 EtsClass *GetTypeAPIMethodClass(); 64 EtsClass *GetTypeAPIParameterClass(); 65 EtsClass *GetIFunctionClass(); 66 EtsClass *GetFinalizableWeakRefClass(); 67 // NOTE(molotkovmikhail): Need to implement a method cache that should be accessible by some class and method ids. 68 Method *GetSubscribeOnAnotherPromiseMethod(); 69 GetEtsClassLinkerExtension()70 EtsClassLinkerExtension *GetEtsClassLinkerExtension() 71 { 72 return ext_; 73 } 74 75 NO_COPY_SEMANTIC(EtsClassLinker); 76 NO_MOVE_SEMANTIC(EtsClassLinker); 77 78 private: 79 explicit EtsClassLinker(ClassLinker *classLinker); 80 81 ClassLinker *classLinker_ {}; 82 EtsClassLinkerExtension *ext_ {}; 83 84 friend class mem::Allocator; 85 }; 86 87 } // namespace ark::ets 88 89 #endif // !PANDA_PLUGINS_ETS_RUNTIME_ETS_CLASS_LINKER_H_ 90