Introduce AidlDocument

AidlDocument models an AIDL file. Previously, it was implicily modeled
inside the parser object. This change removes the responsibility from
the parser.

This is in preparation for the upcoming change to make the entire AST to
be a complete tree rooted at the AidlTypenames object.

Bug: 156309715
Test: m
Test: run aidl_unittests
Change-Id: Ie57e1a1f7fd373efdc5582f479f31090d07275d4
diff --git a/aidl.cpp b/aidl.cpp
index 513327e..c8b75c9 100644
--- a/aidl.cpp
+++ b/aidl.cpp
@@ -427,7 +427,7 @@
     return AidlError::PARSE_ERROR;
   }
   int num_interfaces_or_structured_parcelables = 0;
-  for (AidlDefinedType* type : main_parser->GetDefinedTypes()) {
+  for (AidlDefinedType* type : main_parser->Document().DefinedTypes()) {
     if (type->AsInterface() != nullptr || type->AsStructuredParcelable() != nullptr) {
       num_interfaces_or_structured_parcelables++;
       if (num_interfaces_or_structured_parcelables > 1) {
@@ -453,7 +453,7 @@
                                  options.InputFiles()};
 
   vector<string> type_from_import_statements;
-  for (const auto& import : main_parser->GetImports()) {
+  for (const auto& import : main_parser->Document().Imports()) {
     if (!AidlTypenames::IsBuiltinTypename(import->GetNeededClass())) {
       type_from_import_statements.emplace_back(import->GetNeededClass());
     }
@@ -570,8 +570,9 @@
   // serious failures.
   bool contains_unstructured_parcelable = false;
 
-  const int num_defined_types = main_parser->GetDefinedTypes().size();
-  for (const auto defined_type : main_parser->GetDefinedTypes()) {
+  const auto& types = main_parser->Document().DefinedTypes();
+  const int num_defined_types = types.size();
+  for (const auto defined_type : types) {
     CHECK(defined_type != nullptr);
 
     // Language specific validation
@@ -740,7 +741,7 @@
   }
 
   if (defined_types != nullptr) {
-    *defined_types = main_parser->GetDefinedTypes();
+    *defined_types = main_parser->Document().DefinedTypes();
   }
 
   if (imported_files != nullptr) {
@@ -850,7 +851,7 @@
     std::unique_ptr<Parser> p = Parser::Parse(file, io_delegate, typenames);
     if (p == nullptr) return false;
 
-    for (const auto& defined_type : p->GetDefinedTypes()) {
+    for (const auto& defined_type : p->Document().DefinedTypes()) {
       if (!writer->Write("%s %s;\n", defined_type->GetPreprocessDeclarationName().c_str(),
                          defined_type->GetCanonicalName().c_str())) {
         return false;