Merge changes from topic 'hidl_remove_anon'

* changes:
  hidl-gen: remove support for anonymous enums.
  hidl-gen: disallow anonymous structs and unions.
diff --git a/Scope.cpp b/Scope.cpp
index c4d07c2..8caf9c9 100644
--- a/Scope.cpp
+++ b/Scope.cpp
@@ -115,20 +115,6 @@
     return false;
 }
 
-std::string Scope::pickUniqueAnonymousName() const {
-    static size_t sNextID = 0;
-
-    for (;;) {
-        std::string anonName = "_hidl_Anon_" + std::to_string(sNextID++);
-
-        auto it = mTypeIndexByName.find(anonName);
-
-        if (it == mTypeIndexByName.end()) {
-            return anonName;
-        }
-    }
-}
-
 status_t Scope::emitTypeDeclarations(Formatter &out) const {
     for (size_t i = 0; i < mTypes.size(); ++i) {
         status_t err = mTypes[i]->emitTypeDeclarations(out);
diff --git a/Scope.h b/Scope.h
index fd6074c..8d26cac 100644
--- a/Scope.h
+++ b/Scope.h
@@ -49,8 +49,6 @@
     bool containsSingleInterface(std::string *ifaceName) const;
     bool containsInterfaces() const;
 
-    std::string pickUniqueAnonymousName() const;
-
     status_t emitTypeDeclarations(Formatter &out) const override;
     status_t emitGlobalTypeDeclarations(Formatter &out) const override;
 
diff --git a/hidl-gen_y.yy b/hidl-gen_y.yy
index 9163aa3..1b6ae5c 100644
--- a/hidl-gen_y.yy
+++ b/hidl-gen_y.yy
@@ -98,13 +98,11 @@
 /* Precedence level 3, RTL; but we have to use %left here */
 %left UNARY_MINUS UNARY_PLUS '!' '~'
 
-%type<str> optIdentifier package
+%type<str> package
 %type<fqName> fqname
 %type<type> fqtype
 
 %type<type> type opt_storage_type
-%type<type> enum_declaration
-%type<type> struct_or_union_declaration
 %type<type> opt_extends
 %type<type> type_declaration_body interface_declaration typedef_declaration
 %type<type> named_struct_or_union_declaration named_enum_declaration
@@ -560,40 +558,6 @@
       }
     ;
 
-struct_or_union_declaration
-    : struct_or_union_keyword optIdentifier
-      {
-          const char *localName = $2;
-          std::string anonName;
-          if (localName == nullptr) {
-              anonName = ast->scope()->pickUniqueAnonymousName();
-              localName = anonName.c_str();
-          }
-
-          CompoundType *container = new CompoundType($1, localName);
-          ast->enterScope(container);
-      }
-      struct_or_union_body
-      {
-          CompoundType *container = static_cast<CompoundType *>(ast->scope());
-
-          std::string errorMsg;
-          if (!container->setFields($4, &errorMsg)) {
-              std::cerr << "ERROR: " << errorMsg << " at " << @4 << "\n";
-              YYERROR;
-          }
-
-          ast->leaveScope();
-
-          if (!ast->addScopedType(container, &errorMsg)) {
-              std::cerr << "ERROR: " << errorMsg << " at " << @2 << "\n";
-              YYERROR;
-          }
-
-          $$ = container;
-      }
-    ;
-
 struct_or_union_body
     : '{' field_declarations '}' { $$ = $2; }
     ;
@@ -624,8 +588,8 @@
     ;
 
 compound_declaration
-    : struct_or_union_declaration { $$ = $1; }
-    | enum_declaration { $$ = $1; }
+    : named_struct_or_union_declaration { $$ = $1; }
+    | named_enum_declaration { $$ = $1; }
     ;
 
 opt_storage_type
@@ -668,46 +632,6 @@
       }
     ;
 
-enum_declaration
-    : ENUM
-      {
-          std::string anonName = ast->scope()->pickUniqueAnonymousName();
-          ast->enterScope(new EnumType(anonName.c_str()));
-      }
-      enum_declaration_body
-      {
-
-          EnumType *enumType = static_cast<EnumType *>(ast->scope());
-          ast->leaveScope();
-
-          std::string errorMsg;
-          if (!ast->addScopedType(enumType, &errorMsg)) {
-              // This should never fail.
-              std::cerr << "ERROR: " << errorMsg << "\n";
-              YYERROR;
-          }
-
-          $$ = enumType;
-      }
-    | ENUM IDENTIFIER opt_storage_type
-      {
-          ast->enterScope(new EnumType($2, $3));
-      }
-      enum_declaration_body
-      {
-          EnumType *enumType = static_cast<EnumType *>(ast->scope());
-          ast->leaveScope();
-
-          std::string errorMsg;
-          if (!ast->addScopedType(enumType, &errorMsg)) {
-              std::cerr << "ERROR: " << errorMsg << " at " << @2 << "\n";
-              YYERROR;
-          }
-
-          $$ = enumType;
-      }
-    ;
-
 enum_declaration_body
     : '{' enum_values opt_comma '}' { $$ = $2; }
     ;
@@ -774,11 +698,6 @@
     | INTERFACE { $$ = new GenericBinder; }
     ;
 
-optIdentifier
-    : /* empty */ { $$ = NULL; }
-    | IDENTIFIER { $$ = $1; }
-    ;
-
 %%
 
 #include <android-base/logging.h>