AIDL: fix string literal parsing.
Even though AIDL doesn't support escaped literals, we should parse
these so that we can have correct error messages (and correct
parsing of the rest of the file). This also makes it pretty easy
to add support if needed.
Bug: 215037384
Test: aidl_unittests
Change-Id: If1f2bdf4d3f5c0c7ab485d924072570af1790dee
diff --git a/aidl_const_expressions.cpp b/aidl_const_expressions.cpp
index 244ec4b..aefd8a0 100644
--- a/aidl_const_expressions.cpp
+++ b/aidl_const_expressions.cpp
@@ -477,10 +477,13 @@
}
AidlConstantValue* AidlConstantValue::String(const AidlLocation& location, const string& value) {
+ AIDL_FATAL_IF(value.size() == 0, "If this is unquoted, we need to update the index log");
+ AIDL_FATAL_IF(value[0] != '\"', "If this is unquoted, we need to update the index log");
+
for (size_t i = 0; i < value.length(); ++i) {
if (!isValidLiteralChar(value[i])) {
- AIDL_ERROR(location) << "Found invalid character at index " << i << " in string constant '"
- << value << "'";
+ AIDL_ERROR(location) << "Found invalid character '" << value[i] << "' at index " << i - 1
+ << " in string constant '" << value << "'";
return new AidlConstantValue(location, Type::ERROR, value);
}
}