Moving hidl-gen parser stack outside of AST

Move compiler stack outside of AST members,
adding a parent member to NamedType to make AST
a real tree.

Add a check that interface must be declared in global scope,
that was not checked in hidl-gen.

Also move scanner outside of AST.

Test: compiles, links, boots, hidl_test
Change-Id: Ida0c192b258e40c8cfe033f00a842444df0130ad
diff --git a/hidl-gen_l.ll b/hidl-gen_l.ll
index 5945df9..13b69bf 100644
--- a/hidl-gen_l.ll
+++ b/hidl-gen_l.ll
@@ -53,8 +53,6 @@
 using namespace android;
 using token = yy::parser::token;
 
-int check_type(yyscan_t yyscanner, struct yyguts_t *yyg);
-
 #define SCALAR_TYPE(kind)                                       \
     do {                                                        \
         yylval->type = new ScalarType(ScalarType::kind);        \
@@ -179,22 +177,22 @@
 status_t parseFile(AST *ast) {
     FILE *file = fopen(ast->getFilename().c_str(), "rb");
 
-    if (file == NULL) {
+    if (file == nullptr) {
         return -errno;
     }
 
     yyscan_t scanner;
-    yylex_init_extra(ast, &scanner);
-    ast->setScanner(scanner);
+    yylex_init(&scanner);
 
     yyset_in(file, scanner);
-    int res = yy::parser(ast).parse();
+
+    Scope* scopeStack = ast->getRootScope();
+    int res = yy::parser(scanner, ast, &scopeStack).parse();
 
     yylex_destroy(scanner);
-    ast->setScanner(NULL);
 
     fclose(file);
-    file = NULL;
+    file = nullptr;
 
     if (res != 0 || ast->syntaxErrors() != 0) {
         return UNKNOWN_ERROR;