Add location info to named types.

Bug: 31827278

Test: hidl_test
Change-Id: I1922d5c309c9706cef37ab34d28e1193d1e247cd
diff --git a/hidl-gen_y.yy b/hidl-gen_y.yy
index 266a5f2..8937da4 100644
--- a/hidl-gen_y.yy
+++ b/hidl-gen_y.yy
@@ -25,6 +25,7 @@
 #include "FQName.h"
 #include "GenericBinder.h"
 #include "Interface.h"
+#include "Location.h"
 #include "Method.h"
 #include "VectorType.h"
 #include "RefType.h"
@@ -40,6 +41,14 @@
 
 #define scanner ast->scanner()
 
+::android::Location convertYYLoc(const yy::parser::location_type &loc) {
+    return ::android::Location(
+            ::android::Position(*(loc.begin.filename), loc.begin.line, loc.begin.column),
+            ::android::Position(*(loc.end.filename), loc.end.line, loc.end.column)
+    );
+}
+
+
 %}
 
 %initial-action {
@@ -396,7 +405,7 @@
               YYERROR;
           }
 
-          Interface *iface = new Interface($2, static_cast<Interface *>($3));
+          Interface *iface = new Interface($2, convertYYLoc(@2), static_cast<Interface *>($3));
 
           // Register interface immediately so it can be referenced inside
           // definition.
@@ -422,7 +431,7 @@
     : TYPEDEF type IDENTIFIER
       {
           std::string errorMsg;
-          if (!ast->addTypeDef($3, $2, &errorMsg)) {
+          if (!ast->addTypeDef($3, $2, convertYYLoc(@3), &errorMsg)) {
               std::cerr << "ERROR: " << errorMsg << " at " << @3 << "\n";
               YYERROR;
           }
@@ -539,7 +548,7 @@
 named_struct_or_union_declaration
     : struct_or_union_keyword IDENTIFIER
       {
-          CompoundType *container = new CompoundType($1, $2);
+          CompoundType *container = new CompoundType($1, $2, convertYYLoc(@2));
           ast->enterScope(container);
       }
       struct_or_union_body
@@ -620,7 +629,7 @@
 named_enum_declaration
     : ENUM IDENTIFIER opt_storage_type
       {
-          ast->enterScope(new EnumType($2, $3));
+          ast->enterScope(new EnumType($2, convertYYLoc(@2), $3));
       }
       enum_declaration_body
       {