summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ioana-Teodora Isar <ioanaisar@google.com> 2024-07-05 14:30:26 +0000
committer Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-07-23 11:36:26 +0000
commita8ac825ec7733025d6ef32eba62f1edb0dd2078d (patch)
tree464b98dd04d72a3b52b8ef3fb5f3cbc394466b00
parent05d977cfcffa75339a631cd78ff30a43bf6145cf (diff)
Make Dexdump::AccessFor an enum class
Bug: 329034512 Test: m test-art-host-gtest Change-Id: I7b6e2d64c58cbedceebf3319f8cffff1ec3631d4
-rw-r--r--dexdump/dexdump.cc21
1 files changed, 12 insertions, 9 deletions
diff --git a/dexdump/dexdump.cc b/dexdump/dexdump.cc
index fd42454007..e8af600165 100644
--- a/dexdump/dexdump.cc
+++ b/dexdump/dexdump.cc
@@ -94,10 +94,13 @@ struct FieldMethodInfo {
/*
* Flags for use with createAccessFlagStr().
*/
-enum AccessFor {
- kAccessForClass = 0, kAccessForMethod = 1, kAccessForField = 2, kAccessForMAX
+enum class AccessFor {
+ kClass = 0,
+ kMethod = 1,
+ kField = 2,
+ kCount
};
-const int kNumFlags = 18;
+static constexpr int kNumFlags = 18;
/*
* Gets 2 little-endian bytes.
@@ -240,7 +243,7 @@ static int countOnes(u4 val) {
* they're u4.
*/
static char* createAccessFlagStr(u4 flags, AccessFor forWhat) {
- static const char* kAccessStrings[kAccessForMAX][kNumFlags] = {
+ static constexpr const char* kAccessStrings[static_cast<int>(AccessFor::kCount)][kNumFlags] = {
{
"PUBLIC", /* 0x00001 */
"PRIVATE", /* 0x00002 */
@@ -304,7 +307,7 @@ static char* createAccessFlagStr(u4 flags, AccessFor forWhat) {
// Allocate enough storage to hold the expected number of strings,
// plus a space between each. We over-allocate, using the longest
// string above as the base metric.
- const int kLongest = 21; // The strlen of longest string above.
+ static constexpr int kLongest = 21; // The strlen of longest string above.
const int count = countOnes(flags);
char* str;
char* cp;
@@ -312,7 +315,7 @@ static char* createAccessFlagStr(u4 flags, AccessFor forWhat) {
for (int i = 0; i < kNumFlags; i++) {
if (flags & 0x01) {
- const char* accessStr = kAccessStrings[forWhat][i];
+ const char* accessStr = kAccessStrings[static_cast<int>(forWhat)][i];
const int len = strlen(accessStr);
if (cp != str) {
*cp++ = ' ';
@@ -1357,7 +1360,7 @@ static void dumpMethod(const ClassAccessor::Method& method, int i) {
const Signature signature = dex_file.GetMethodSignature(pMethodId);
char* typeDescriptor = strdup(signature.ToString().c_str());
const char* backDescriptor = dex_file.GetTypeDescriptor(pMethodId.class_idx_);
- char* accessStr = createAccessFlagStr(flags, kAccessForMethod);
+ char* accessStr = createAccessFlagStr(flags, AccessFor::kMethod);
const uint32_t hiddenapiFlags = method.GetHiddenapiFlags();
if (gOptions.outputFormat == OUTPUT_PLAIN) {
@@ -1477,7 +1480,7 @@ static void dumpField(const ClassAccessor::Field& field, int i, const u1** data
const char* name = dex_file.GetStringData(field_id.name_idx_);
const char* typeDescriptor = dex_file.GetTypeDescriptor(field_id.type_idx_);
const char* backDescriptor = dex_file.GetTypeDescriptor(field_id.class_idx_);
- char* accessStr = createAccessFlagStr(flags, kAccessForField);
+ char* accessStr = createAccessFlagStr(flags, AccessFor::kField);
const uint32_t hiddenapiFlags = field.GetHiddenapiFlags();
if (gOptions.outputFormat == OUTPUT_PLAIN) {
@@ -1602,7 +1605,7 @@ static void dumpClass(const DexFile* pDexFile, int idx, char** pLastPackage) {
}
// General class information.
- char* accessStr = createAccessFlagStr(pClassDef.access_flags_, kAccessForClass);
+ char* accessStr = createAccessFlagStr(pClassDef.access_flags_, AccessFor::kClass);
const char* superclassDescriptor;
if (!pClassDef.superclass_idx_.IsValid()) {
superclassDescriptor = nullptr;