Redefine fqname in hidl-gen_y.yy
There is an inconsistency in hidl-gen_y.yy that fqname does not
mean an FQName object, but a Type object. Redefined fqname to create
an FQName object only, and rename the original fqname rule to fqtype.
This also propagates to AST::lookupType and Scope::lookupType to
take an FQName object instead of a plain string.
Test: `mma`
Test: `make hidl_test && adb sync && adb shell hidl_test`
Change-Id: I5d35192fa5fa9752b10bd9e7d339eadc5cdb78c0
diff --git a/hidl-gen_y.yy b/hidl-gen_y.yy
index 6249886..65dfaee 100644
--- a/hidl-gen_y.yy
+++ b/hidl-gen_y.yy
@@ -94,7 +94,8 @@
%left UNARY_MINUS UNARY_PLUS '!' '~'
%type<str> optIdentifier package
-%type<type> fqname
+%type<fqName> fqname
+%type<type> fqtype
%type<type> type opt_storage_type
%type<type> enum_declaration
@@ -121,6 +122,7 @@
%union {
const char *str;
android::Type *type;
+ android::FQName *fqName;
android::CompoundType *compoundType;
android::CompoundField *field;
std::vector<android::CompoundField *> *fields;
@@ -219,20 +221,33 @@
fqname
: FQNAME
{
- $$ = ast->lookupType($1);
- if ($$ == NULL) {
- std::cerr << "ERROR: Failed to lookup type '" << $1 << "' at "
+ $$ = new FQName($1);
+ if(!$$->isValid()) {
+ std::cerr << "ERROR: FQName '" << $1 << "' is not valid at "
<< @1
- << "\n";
-
+ << ".\n";
YYERROR;
}
}
| IDENTIFIER
{
- $$ = ast->lookupType($1);
+ $$ = new FQName($1);
+ if(!$$->isValid()) {
+ std::cerr << "ERROR: FQName '" << $1 << "' is not valid at "
+ << @1
+ << ".\n";
+ YYERROR;
+ }
+ }
+ ;
+
+fqtype
+ : fqname
+ {
+ $$ = ast->lookupType(*($1));
if ($$ == NULL) {
- std::cerr << "Failed to lookup type '" << $1 << "' at " << @1
+ std::cerr << "ERROR: Failed to lookup type '" << $1->string() << "' at "
+ << @1
<< "\n";
YYERROR;
@@ -279,7 +294,7 @@
opt_extends
: /* empty */ { $$ = NULL; }
- | EXTENDS fqname { $$ = $2; }
+ | EXTENDS fqtype { $$ = $2; }
body
: opt_annotations INTERFACE IDENTIFIER opt_extends
@@ -507,7 +522,7 @@
opt_storage_type
: /* empty */ { $$ = NULL; }
- | ':' fqname
+ | ':' fqtype
{
$$ = $2;
@@ -591,8 +606,8 @@
;
type
- : fqname { $$ = $1; }
- | fqname '[' INTEGER ']'
+ : fqtype { $$ = $1; }
+ | fqtype '[' INTEGER ']'
{
if ($1->isBinder()) {
std::cerr << "ERROR: Arrays of interface types are not supported."
@@ -611,7 +626,7 @@
$$ = new ArrayType($1, size);
}
}
- | VEC '<' fqname '>'
+ | VEC '<' fqtype '>'
{
if ($3->isBinder()) {
std::cerr << "ERROR: Vectors of interface types are not "