forked from facebook/redex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDexMemberRefs.h
100 lines (82 loc) · 2.36 KB
/
DexMemberRefs.h
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* 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.
*/
#pragma once
#include <boost/functional/hash.hpp>
#include <vector>
#include <string>
class DexType;
class DexString;
class DexProto;
/**
* A specification for a method in order to look it up in the global cache
* or to create it. Also used to modify an existing method reference.
*/
struct DexMethodSpec {
/* Method related members */
DexType* cls = nullptr;
DexString* name = nullptr;
DexProto* proto = nullptr;
DexMethodSpec() = default;
DexMethodSpec(DexType* c, DexString* n, DexProto* p)
: cls(c), name(n), proto(p) {}
bool operator==(const DexMethodSpec& r) const {
return cls == r.cls && name == r.name && proto == r.proto;
}
};
/**
* A specification for a field in order to look it up in the global cache
* or to create it. Also used to modify an existing field reference.
*/
struct DexFieldSpec {
/* Field related members */
DexType* cls = nullptr;
DexString* name = nullptr;
DexType* type = nullptr;
DexFieldSpec() = default;
DexFieldSpec(DexType* c, DexString* n, DexType* t)
: cls(c), name(n), type(t) {}
bool operator==(const DexFieldSpec& r) const {
return cls == r.cls && name == r.name && type == r.type;
};
};
namespace dex_member_refs {
struct FieldDescriptorTokens {
std::string cls;
std::string name;
std::string type;
};
struct MethodDescriptorTokens {
std::string cls;
std::string name;
std::vector<std::string> args;
std::string rtype;
};
FieldDescriptorTokens parse_field(const std::string&);
MethodDescriptorTokens parse_method(const std::string&);
} // namespace dex_member_refs
namespace std {
template <>
struct hash<DexMethodSpec> {
size_t operator()(const DexMethodSpec& r) const {
size_t seed = boost::hash<DexType*>()(r.cls);
boost::hash_combine(seed, r.name);
boost::hash_combine(seed, r.proto);
return seed;
}
};
template <>
struct hash<DexFieldSpec> {
size_t operator()(const DexFieldSpec& r) const {
size_t seed = boost::hash<DexType*>()(r.cls);
boost::hash_combine(seed, r.name);
boost::hash_combine(seed, r.type);
return seed;
}
};
}