1 /** 2 * Copyright (c) 2021-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_VTABLE_BUILDER_H_ 17 #define PANDA_PLUGINS_ETS_RUNTIME_ETS_VTABLE_BUILDER_H_ 18 19 #include <cstddef> 20 #include <utility> 21 22 #include "runtime/class_linker_context.h" 23 #include "runtime/include/vtable_builder_variance-inl.h" 24 #include "plugins/ets/runtime/ets_vm.h" 25 26 namespace ark::ets { 27 28 bool ETSProtoIsOverriddenBy(const ClassLinkerContext *ctx, Method::ProtoId const &base, Method::ProtoId const &derv); 29 30 class EtsVTableCompatibleSignatures { 31 public: EtsVTableCompatibleSignatures(const ClassLinkerContext * ctx)32 explicit EtsVTableCompatibleSignatures(const ClassLinkerContext *ctx) : ctx_(ctx) {} 33 operator()34 bool operator()(const Method::ProtoId &base, const Method::ProtoId &derv) const 35 { 36 return ETSProtoIsOverriddenBy(ctx_, base, derv); 37 } 38 39 private: 40 const ClassLinkerContext *ctx_; 41 }; 42 43 struct EtsVTableOverridePred { operatorEtsVTableOverridePred44 bool operator()(const MethodInfo *base, const MethodInfo *derv) const 45 { 46 if (base->IsPublic() || base->IsProtected()) { 47 return true; 48 } 49 50 if (base->IsPrivate()) { 51 return false; 52 } 53 54 return IsInSamePackage(*base, *derv); 55 } 56 57 bool IsInSamePackage(const MethodInfo &info1, const MethodInfo &info2) const; 58 }; 59 60 using EtsVTableBuilder = VarianceVTableBuilder<EtsVTableCompatibleSignatures, EtsVTableOverridePred>; 61 62 } // namespace ark::ets 63 64 #endif // !PANDA_PLUGINS_ETS_RUNTIME_ETS_ITABLE_BUILDER_H_ 65