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 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 panda { 25 class Method; 26 class ClassLinker; 27 class ClassLinkerContext; 28 class ClassLinkerErrorHandler; 29 } // namespace panda 30 31 namespace panda::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 *GetArrayBufferClass(); 56 EtsClass *GetSharedMemoryClass(); 57 EtsClass *GetObjectClass(); 58 EtsClass *GetVoidClass(); 59 EtsClass *GetTypeAPIFieldClass(); 60 EtsClass *GetTypeAPIMethodClass(); 61 EtsClass *GetTypeAPIParameterClass(); 62 GetEtsClassLinkerExtension()63 EtsClassLinkerExtension *GetEtsClassLinkerExtension() 64 { 65 return ext_; 66 } 67 68 NO_COPY_SEMANTIC(EtsClassLinker); 69 NO_MOVE_SEMANTIC(EtsClassLinker); 70 71 private: 72 explicit EtsClassLinker(ClassLinker *classLinker); 73 74 ClassLinker *classLinker_ {}; 75 EtsClassLinkerExtension *ext_ {}; 76 77 friend class mem::Allocator; 78 }; 79 80 } // namespace panda::ets 81 82 #endif // !PANDA_PLUGINS_ETS_RUNTIME_ETS_CLASS_LINKER_H 83