forked from facebook/redex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVinfo.cpp
80 lines (67 loc) · 2.28 KB
/
Vinfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "Vinfo.h"
#include "DexClass.h"
#include "DexInstruction.h"
#include "DexUtil.h"
#include "Resolver.h"
namespace {
using methods_t = Vinfo::methods_t;
using vinfo_t = Vinfo::vinfo_t;
using vinfos_t = Vinfo::vinfos_t;
void build_vinfos_for_meth(vinfos_t& vinfos, const DexMethod* meth) {
// Get super method
auto cls = type_class(meth->get_class());
const DexMethod* super_meth = cls == nullptr ? nullptr :
resolve_virtual(type_class(cls->get_super_class()),
meth->get_name(), meth->get_proto());
// If we have a super method, we're an override, and it's overriden
if (super_meth) {
vinfos[meth].override_of = super_meth;
vinfos[super_meth].overriden_by.insert(meth);
vinfos[super_meth].is_overriden = true;
}
const DexMethod* decl = find_top_impl(
cls, meth->get_name(), meth->get_proto());
vinfos[meth].decl = decl;
}
vinfos_t build_vinfos(const std::vector<DexClass*>& scope) {
vinfos_t vinfos;
for (const DexClass* cls : scope) {
if (cls->get_access() & ACC_INTERFACE) continue;
for (const DexMethod* meth : cls->get_vmethods()) {
build_vinfos_for_meth(vinfos, meth);
}
}
return vinfos;
}
} // end namespace
Vinfo::Vinfo(const std::vector<DexClass*>& scope) {
m_vinfos = build_vinfos(scope);
}
const DexMethod* Vinfo::get_decl(const DexMethod* meth) {
assert(m_vinfos.find(meth) != m_vinfos.end());
return m_vinfos[meth].decl;
}
bool Vinfo::is_override(const DexMethod* meth) {
assert(m_vinfos.find(meth) != m_vinfos.end());
return m_vinfos[meth].override_of;
}
const DexMethod* Vinfo::get_overriden_method(const DexMethod* meth) {
assert(m_vinfos.find(meth) != m_vinfos.end());
return m_vinfos[meth].override_of;
}
bool Vinfo::is_overriden(const DexMethod* meth) {
assert(m_vinfos.find(meth) != m_vinfos.end());
return m_vinfos[meth].is_overriden;
}
const methods_t& Vinfo::get_override_methods(const DexMethod* meth) {
assert(m_vinfos.find(meth) != m_vinfos.end());
return m_vinfos[meth].overriden_by;
}