Better diagnostics if an attempt is made to redeclare a type under the same name
as an existing type in that scope. Support for anonymous struct/unions.
Change-Id: I0122cfae4da848419956c7b27bacaca66f8021d5
Bug: 30896059
diff --git a/Scope.cpp b/Scope.cpp
index abad31d..0e21c8e 100644
--- a/Scope.cpp
+++ b/Scope.cpp
@@ -12,6 +12,10 @@
bool Scope::addType(const char *localName, NamedType *type) {
if (mTypeIndexByName.indexOfKey(localName) >= 0) {
+ fprintf(stderr,
+ "A type named '%s' is already declared in the current scope.\n",
+ localName);
+
return false;
}
@@ -67,6 +71,18 @@
return false;
}
+std::string Scope::pickUniqueAnonymousName() const {
+ static size_t sNextID = 0;
+
+ for (;;) {
+ std::string anonName = "_hidl_Anon_" + std::to_string(sNextID++);
+
+ if (mTypeIndexByName.indexOfKey(anonName) < 0) {
+ return anonName;
+ }
+ }
+}
+
std::string Scope::getJavaType() const {
CHECK(!"Should not be here");
return std::string();