Merge SQ1A.220205.002
Bug: 213904741
Merged-In: I7924d7b19ec30e42fd1d17ec913c4a75d51ea6bc
Change-Id: I73618ff8ee69680cdbe3b493d2c06d12f9128502
diff --git a/aidl_const_expressions.cpp b/aidl_const_expressions.cpp
index b3a1667..eeeb14b 100644
--- a/aidl_const_expressions.cpp
+++ b/aidl_const_expressions.cpp
@@ -343,6 +343,9 @@
if (name == "boolean") {
return Boolean(location, false);
}
+ if (name == "char") {
+ return Character(location, "'\\0'"); // literal to be used in backends
+ }
if (name == "byte" || name == "int" || name == "long") {
return Integral(location, "0");
}
@@ -359,13 +362,22 @@
return new AidlConstantValue(location, Type::BOOLEAN, value ? "true" : "false");
}
-AidlConstantValue* AidlConstantValue::Character(const AidlLocation& location, char value) {
- const std::string explicit_value = string("'") + value + "'";
- if (!isValidLiteralChar(value)) {
- AIDL_ERROR(location) << "Invalid character literal " << value;
- return new AidlConstantValue(location, Type::ERROR, explicit_value);
+AidlConstantValue* AidlConstantValue::Character(const AidlLocation& location,
+ const std::string& value) {
+ static const char* kZeroString = "'\\0'";
+
+ // We should have better supports for escapes in the future, but for now
+ // allow only what is needed for defaults.
+ if (value != kZeroString) {
+ AIDL_FATAL_IF(value.size() != 3 || value[0] != '\'' || value[2] != '\'', location) << value;
+
+ if (!isValidLiteralChar(value[1])) {
+ AIDL_ERROR(location) << "Invalid character literal " << value[1];
+ return new AidlConstantValue(location, Type::ERROR, value);
+ }
}
- return new AidlConstantValue(location, Type::CHARACTER, explicit_value);
+
+ return new AidlConstantValue(location, Type::CHARACTER, value);
}
AidlConstantValue* AidlConstantValue::Floating(const AidlLocation& location,
@@ -1055,6 +1067,8 @@
return false;
}
+// Constructor for integer(byte, int, long)
+// Keep parsed integer & literal
AidlConstantValue::AidlConstantValue(const AidlLocation& location, Type parsed_type,
int64_t parsed_value, const string& checked_value)
: AidlNode(location),
@@ -1066,6 +1080,8 @@
AIDL_FATAL_IF(type_ != Type::INT8 && type_ != Type::INT32 && type_ != Type::INT64, location);
}
+// Constructor for non-integer(String, char, boolean, float, double)
+// Keep literal as it is. (e.g. String literal has double quotes at both ends)
AidlConstantValue::AidlConstantValue(const AidlLocation& location, Type type,
const string& checked_value)
: AidlNode(location),
@@ -1085,6 +1101,7 @@
}
}
+// Constructor for array
AidlConstantValue::AidlConstantValue(const AidlLocation& location, Type type,
std::unique_ptr<vector<unique_ptr<AidlConstantValue>>> values,
const std::string& value)