Skip to content

Commit b4a9b59

Browse files
agampemeta-codesync[bot]
authored andcommitted
Make some DexType-related things const
Summary: Incremental work. Reviewed By: xuhdev Differential Revision: D88659573 fbshipit-source-id: 3bed19bae7ec37f1e594d6ef9313f76c9f0a042b
1 parent 4dcfab1 commit b4a9b59

26 files changed

Lines changed: 111 additions & 73 deletions

libredex/ApiLevelChecker.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace api {
1919
// these values until g_redex exists and the classes have been loaded from the
2020
// dex file
2121
int32_t LevelChecker::s_min_level = 0;
22-
DexType* LevelChecker::s_requires_api_old = nullptr;
23-
DexType* LevelChecker::s_requires_api_new = nullptr;
24-
DexType* LevelChecker::s_target_api = nullptr;
22+
const DexType* LevelChecker::s_requires_api_old = nullptr;
23+
const DexType* LevelChecker::s_requires_api_new = nullptr;
24+
const DexType* LevelChecker::s_target_api = nullptr;
2525
bool LevelChecker::s_has_been_init = false;
2626

2727
void LevelChecker::init(int32_t min_level, const Scope& scope) {
@@ -112,7 +112,7 @@ DexClass* LevelChecker::get_outer_class(const DexClass* cls) {
112112
if (slash_idx == std::string::npos || slash_idx < cash_idx) {
113113
// there's a $ in the class name
114114
const std::string& outer_name = cls_name.substr(0, cash_idx) + ';';
115-
DexType* outer = DexType::get_type(outer_name);
115+
const DexType* outer = DexType::get_type(outer_name);
116116
if (outer == nullptr) {
117117
TRACE(MMINL, 4, "Can't find outer class! %.*s -> %s",
118118
static_cast<int>(cls_name.length()), cls_name.data(),
@@ -163,7 +163,7 @@ void propagate_levels(const ClassHierarchy& ch,
163163

164164
auto* intfs = cls->get_interfaces();
165165
if (intfs != nullptr) {
166-
for (auto* intf : *intfs) {
166+
for (const auto* intf : *intfs) {
167167
auto* intf_cls = type_class(intf);
168168
if (intf_cls != nullptr) {
169169
min_level = std::max(

libredex/ApiLevelChecker.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ class LevelChecker {
117117
* initialization, these are read-only and safe to use in parallel
118118
*/
119119
static int32_t s_min_level;
120-
static DexType* s_requires_api_old;
121-
static DexType* s_requires_api_new;
122-
static DexType* s_target_api;
120+
static const DexType* s_requires_api_old;
121+
static const DexType* s_requires_api_new;
122+
static const DexType* s_target_api;
123123
static bool s_has_been_init;
124124
};
125125

libredex/ClassUtil.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ Serdes get_serdes(const DexClass* cls) {
2727
std::replace(flatbuf_name.begin(), flatbuf_name.end(), '$', '_');
2828

2929
std::string desername = name + "$Deserializer;";
30-
DexType* deser = DexType::get_type(desername);
30+
const DexType* deser = DexType::get_type(desername);
3131

3232
std::string flatbuf_desername = flatbuf_name + "Deserializer;";
33-
DexType* flatbuf_deser = DexType::get_type(flatbuf_desername);
33+
const DexType* flatbuf_deser = DexType::get_type(flatbuf_desername);
3434

3535
std::string sername = name + "$Serializer;";
36-
DexType* ser = DexType::get_type(sername);
36+
const DexType* ser = DexType::get_type(sername);
3737

3838
std::string flatbuf_sername = flatbuf_name + "Serializer;";
39-
DexType* flatbuf_ser = DexType::get_type(flatbuf_sername);
39+
const DexType* flatbuf_ser = DexType::get_type(flatbuf_sername);
4040

4141
return Serdes(deser, flatbuf_deser, ser, flatbuf_ser);
4242
}
@@ -72,7 +72,7 @@ DexMethod* get_or_create_clinit(DexClass* cls, bool need_cfg) {
7272
}
7373

7474
bool has_hierarchy_in_scope(DexClass* cls) {
75-
DexType* super = nullptr;
75+
const DexType* super = nullptr;
7676
const DexClass* super_cls = cls;
7777
while (super_cls != nullptr) {
7878
super = super_cls->get_super_class();

libredex/ClassUtil.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
namespace klass {
1313

1414
struct Serdes {
15-
std::vector<DexType*> serdes;
15+
std::vector<const DexType*> serdes;
1616

17-
Serdes(DexType* deser,
18-
DexType* flatbuf_deser,
19-
DexType* ser,
20-
DexType* flatbuf_ser)
17+
Serdes(const DexType* deser,
18+
const DexType* flatbuf_deser,
19+
const DexType* ser,
20+
const DexType* flatbuf_ser)
2121
: serdes{deser, flatbuf_deser, ser, flatbuf_ser} {}
2222

23-
std::vector<DexType*> get_all_serdes() { return serdes; }
23+
std::vector<const DexType*> get_all_serdes() { return serdes; }
2424

25-
DexType* get_deser() { return serdes[0]; }
26-
DexType* get_flatbuf_deser() { return serdes[1]; }
27-
DexType* get_ser() { return serdes[2]; }
28-
DexType* get_flatbuf_ser() { return serdes[3]; }
25+
const DexType* get_deser() { return serdes[0]; }
26+
const DexType* get_flatbuf_deser() { return serdes[1]; }
27+
const DexType* get_ser() { return serdes[2]; }
28+
const DexType* get_flatbuf_ser() { return serdes[3]; }
2929
};
3030

3131
/**

libredex/DexAccess.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ void loosen_access_modifier(const DexClasses& classes) {
8686
});
8787
loosen_access_modifier_for_vmethods(classes);
8888

89-
DexType* dalvikinner = DexType::get_type("Ldalvik/annotation/InnerClass;");
89+
const DexType* dalvikinner =
90+
DexType::get_type("Ldalvik/annotation/InnerClass;");
9091
if (dalvikinner == nullptr) {
9192
return;
9293
}

libredex/DexInstruction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,14 +1111,14 @@ DexInstruction* DexInstruction::make_instruction(DexIdx* idx,
11111111
case DOPCODE_NEW_INSTANCE:
11121112
case DOPCODE_NEW_ARRAY: {
11131113
uint16_t tidx = *insns++;
1114-
DexType* type = idx->get_typeidx(tidx);
1114+
const DexType* type = idx->get_typeidx(tidx);
11151115
return new DexOpcodeType(fopcode, type);
11161116
}
11171117
case DOPCODE_FILLED_NEW_ARRAY:
11181118
case DOPCODE_FILLED_NEW_ARRAY_RANGE: {
11191119
uint16_t tidx = *insns++;
11201120
uint16_t arg = *insns++;
1121-
DexType* type = idx->get_typeidx(tidx);
1121+
const DexType* type = idx->get_typeidx(tidx);
11221122
return new DexOpcodeType(fopcode, type, arg);
11231123
}
11241124
case DOPCODE_CONST_METHOD_HANDLE: {

libredex/DexOutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2706,7 +2706,7 @@ void write_pg_mapping(const std::string& filename, DexClasses* classes) {
27062706
while (type_str[dim] == '[') {
27072707
dim++;
27082708
}
2709-
DexType* inner_type = DexType::get_type(&type_str[dim]);
2709+
const DexType* inner_type = DexType::get_type(&type_str[dim]);
27102710
DexClass* inner_cls =
27112711
inner_type != nullptr ? type_class(inner_type) : nullptr;
27122712
std::string result;

libredex/DexStore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ size_t XDexRefs::get_dex_idx(const DexType* type) const {
306306

307307
bool XDexRefs::cross_dex_ref_override(const DexMethod* overridden,
308308
const DexMethod* overriding) const {
309-
auto* type = overriding->get_class();
309+
const auto* type = overriding->get_class();
310310
auto idx = get_dex_idx(type);
311311
do {
312312
type = type_class(type)->get_super_class();

libredex/IRMetaIO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void deserialize_class_data(std::ifstream& istrm, uint32_t data_size) {
184184
switch (btype) {
185185
case BlockType::ClassBlock: {
186186
// Create a std::string for null termination
187-
DexType* type = DexType::get_type(std::string_view(ptr, strsize));
187+
const DexType* type = DexType::get_type(std::string_view(ptr, strsize));
188188
cls = type_class(type);
189189
always_assert(cls != nullptr);
190190
ptr += strsize + 1;

libredex/InlinerConfig.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct InlinerConfig {
9999
*/
100100
void populate(const Scope& scope);
101101

102-
const UnorderedSet<DexType*>& get_blocklist() const {
102+
const UnorderedSet<const DexType*>& get_blocklist() const {
103103
always_assert_log(m_populated, "Should populate blocklist\n");
104104
return m_blocklist;
105105
}
@@ -109,7 +109,7 @@ struct InlinerConfig {
109109
m_blocklist.clear();
110110
}
111111

112-
const UnorderedSet<DexType*>& get_caller_blocklist() const {
112+
const UnorderedSet<const DexType*>& get_caller_blocklist() const {
113113
always_assert_log(m_populated, "Should populate blocklist\n");
114114
return m_caller_blocklist;
115115
}
@@ -121,7 +121,7 @@ struct InlinerConfig {
121121

122122
void apply_intradex_allowlist() {
123123
always_assert_log(m_populated, "Should populate allowlist\n");
124-
for (DexType* type : UnorderedIterable(m_intradex_allowlist)) {
124+
for (const DexType* type : UnorderedIterable(m_intradex_allowlist)) {
125125
m_blocklist.erase(type);
126126
m_caller_blocklist.erase(type);
127127
}
@@ -130,8 +130,8 @@ struct InlinerConfig {
130130
private:
131131
bool m_populated{false};
132132
// The populated black lists.
133-
UnorderedSet<DexType*> m_blocklist;
134-
UnorderedSet<DexType*> m_caller_blocklist;
135-
UnorderedSet<DexType*> m_intradex_allowlist;
133+
UnorderedSet<const DexType*> m_blocklist;
134+
UnorderedSet<const DexType*> m_caller_blocklist;
135+
UnorderedSet<const DexType*> m_intradex_allowlist;
136136
};
137137
} // namespace inliner

0 commit comments

Comments
 (0)