using references in constant expressions
References to enumerators or other constants can be used in constant
expressions. This enables setting defaults to enum type variables.
References are resolved at compilation time.
Note that recursive references are not supported yet.
Bug: 142893595
Test: aidl_unittests
Test: aidl_integration_test
Change-Id: Ic7d7e74c1306462fa9148d474c764ebb9a5fae45
diff --git a/aidl_to_ndk.cpp b/aidl_to_ndk.cpp
index 6884e89..9d1b794 100644
--- a/aidl_to_ndk.cpp
+++ b/aidl_to_ndk.cpp
@@ -70,10 +70,21 @@
};
std::string ConstantValueDecorator(const AidlTypeSpecifier& type, const std::string& raw_value) {
+ if (type.IsArray()) {
+ return raw_value;
+ }
+
if (type.GetName() == "long" && !type.IsArray()) {
return raw_value + "L";
}
+ if (auto defined_type = type.GetDefinedType(); defined_type) {
+ auto enum_type = defined_type->AsEnumDeclaration();
+ AIDL_FATAL_IF(!enum_type, type) << "Invalid type for \"" << raw_value << "\"";
+ return NdkFullClassName(*enum_type, cpp::ClassNames::RAW) +
+ "::" + raw_value.substr(raw_value.find_last_of('.') + 1);
+ }
+
return raw_value;
};