refactor: parser returns parsed document
Parser::Parse returns AidlDocument. After parsing a document,
AidlDocument is added to AidlTypenames and managed by it. So we don't
need to keep a parser instance.
This enables caching so that when loading a document which is already
parsed then Parse() can simply return the AidlDocument.
Bug: 188878102
Test: aidl_unittests
Change-Id: Ifc50bc20b48e3a2c7a8a614ed8c8a179cd6dd9c9
diff --git a/parser.h b/parser.h
index f34ca78..2061fa0 100644
--- a/parser.h
+++ b/parser.h
@@ -54,7 +54,8 @@
android::aidl::Comments comments_;
};
-using TypeResolver = std::function<bool(const AidlDocument*, AidlTypeSpecifier*)>;
+using TypeResolver = std::function<bool(const AidlDefinedType*, AidlTypeSpecifier*)>;
+bool ResolveReferences(const AidlDocument& document, TypeResolver& resolver);
class Parser {
public:
@@ -65,9 +66,9 @@
~Parser();
// Parse contents of file |filename|. Should only be called once.
- static std::unique_ptr<Parser> Parse(const std::string& filename,
- const android::aidl::IoDelegate& io_delegate,
- AidlTypenames& typenames);
+ static const AidlDocument* Parse(const std::string& filename,
+ const android::aidl::IoDelegate& io_delegate,
+ AidlTypenames& typenames);
void AddError() { error_++; }
bool HasError() const { return error_ != 0; }
@@ -98,9 +99,9 @@
}
}
- const AidlDocument& ParsedDocument() const {
+ const AidlDocument* ParsedDocument() const {
AIDL_FATAL_IF(HasError(), FileName());
- return *document_;
+ return document_;
}
private: