• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 #include "plugins/ets/runtime/ets_vtable_builder.h"
17 
18 #include "runtime/include/class_linker.h"
19 
20 namespace panda::ets {
21 
IsInSamePackage(const MethodInfo & info1,const MethodInfo & info2) const22 bool EtsVTableOverridePred::IsInSamePackage(const MethodInfo &info1, const MethodInfo &info2) const
23 {
24     if (info1.GetLoadContext() != info2.GetLoadContext()) {
25         return false;
26     }
27 
28     auto *desc1 = info1.GetClassName();
29     auto *desc2 = info2.GetClassName();
30 
31     while (ClassHelper::IsArrayDescriptor(desc1)) {
32         desc1 = ClassHelper::GetComponentDescriptor(desc1);
33     }
34 
35     while (ClassHelper::IsArrayDescriptor(desc2)) {
36         desc2 = ClassHelper::GetComponentDescriptor(desc2);
37     }
38 
39     Span sp1(desc1, 1);
40     Span sp2(desc2, 1);
41     while (sp1[0] == sp2[0] && sp1[0] != 0 && sp2[0] != 0) {
42         sp1 = Span(sp1.cend(), 1);
43         sp2 = Span(sp2.cend(), 1);
44     }
45 
46     bool isSamePackage = true;
47     while (sp1[0] != 0 && isSamePackage) {
48         isSamePackage = sp1[0] != '/';
49         sp1 = Span(sp1.cend(), 1);
50     }
51 
52     while (sp2[0] != 0 && isSamePackage) {
53         isSamePackage = sp2[0] != '/';
54         sp2 = Span(sp2.cend(), 1);
55     }
56 
57     return isSamePackage;
58 }
59 
60 }  // namespace panda::ets
61