summaryrefslogtreecommitdiff
path: root/tools/stats_log_api_gen/Collation.cpp
diff options
context:
space:
mode:
authorStefan Lafon <stlafon@google.com>2017-10-30 21:20:20 -0700
committerStefan Lafon <stlafon@google.com>2017-10-31 11:23:09 -0700
commit9478f3515b2e0ccc8320b1911e6f911e3a3ffde0 (patch)
treed6f3b618e3854b1037852e8a6d56970b495a6822 /tools/stats_log_api_gen/Collation.cpp
parent941dcba6e310e0bafcc1459422e7db01c5b70bb0 (diff)
Generate constants for enum values.
Test: Builds successfully, tests pass and statsd works (it seems). This will allow us to use those constants instead of literals. The generated code only augmentes the java constant file. If needed, the same can be done for the C++ file. Some of the constant names are very long, but this is due to enum value names that are unnecessarily redundant with the enum names, i.e. enum ENUM_NAME { ENUM_NAME_UNKNOWN = 0; ENUM_NAME_VALUE1 = 1; ENUM_NAME_VALUE2 = 2; ... } which can be fixed by avoiding the 'ENUM_NAME_' part in the value names above. So, when possible, we should use shorter value names in stats_events.proto. Change-Id: I1ad19b86e28d0df0f8c15d4c995d101423cff4c2
Diffstat (limited to 'tools/stats_log_api_gen/Collation.cpp')
-rw-r--r--tools/stats_log_api_gen/Collation.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/tools/stats_log_api_gen/Collation.cpp b/tools/stats_log_api_gen/Collation.cpp
index 5d2926821164..f76196dd2a19 100644
--- a/tools/stats_log_api_gen/Collation.cpp
+++ b/tools/stats_log_api_gen/Collation.cpp
@@ -22,6 +22,7 @@
namespace android {
namespace stats_log_api_gen {
+using google::protobuf::EnumDescriptor;
using google::protobuf::FieldDescriptor;
using google::protobuf::FileDescriptor;
using google::protobuf::SourceLocation;
@@ -120,7 +121,7 @@ java_type(const FieldDescriptor* field)
case FieldDescriptor::TYPE_UINT32:
return JAVA_TYPE_INT;
case FieldDescriptor::TYPE_ENUM:
- return JAVA_TYPE_INT;
+ return JAVA_TYPE_ENUM;
case FieldDescriptor::TYPE_SFIXED32:
return JAVA_TYPE_INT;
case FieldDescriptor::TYPE_SFIXED64:
@@ -208,7 +209,6 @@ collate_atoms(const Descriptor* descriptor, Atoms* atoms)
errorCount++;
continue;
}
-
}
// Check that if there's a WorkSource, it's at position 1.
@@ -228,15 +228,26 @@ collate_atoms(const Descriptor* descriptor, Atoms* atoms)
AtomDecl atomDecl(atomField->number(), atomField->name(), atom->name());
- // Build the type signature
+ // Build the type signature and the atom data.
vector<java_type_t> signature;
for (map<int,const FieldDescriptor*>::const_iterator it = fields.begin();
it != fields.end(); it++) {
const FieldDescriptor* field = it->second;
java_type_t javaType = java_type(field);
- atomDecl.fields.push_back(AtomField(field->name(), javaType));
- signature.push_back(javaType);
+ AtomField atField(field->name(), javaType);
+ if (javaType == JAVA_TYPE_ENUM) {
+ // All enums are treated as ints when it comes to function signatures.
+ signature.push_back(JAVA_TYPE_INT);
+ const EnumDescriptor* enumDescriptor = field->enum_type();
+ for (int i = 0; i < enumDescriptor->value_count(); i++) {
+ atField.enumValues[enumDescriptor->value(i)->number()] =
+ enumDescriptor->value(i)->name().c_str();
+ }
+ } else {
+ signature.push_back(javaType);
+ }
+ atomDecl.fields.push_back(atField);
}
atoms->signatures.insert(signature);
@@ -261,5 +272,3 @@ collate_atoms(const Descriptor* descriptor, Atoms* atoms)
} // namespace stats_log_api_gen
} // namespace android
-
-