refactor: type resolution using visitor
Type references and constant references are done in a same visitor.
Visitor provides "scope" which can be used to (not implemented in this
change)
- resolve "type parameter"(AidlTypeSpecifier) bound to the scope
- resolve nested types
- ...
Bug: n/a
Test: aidl_unittests
Change-Id: I44aef519545ca377b208dbe98ef5a57b9cec1878
diff --git a/aidl_language.h b/aidl_language.h
index e0c28a0..fcc592a 100644
--- a/aidl_language.h
+++ b/aidl_language.h
@@ -700,8 +700,10 @@
const std::string& GetFieldName() const { return field_name_; }
bool CheckValid() const override;
- void TraverseChildren(std::function<void(const AidlNode&)>) const override {
- // resolved_ is not my child.
+ void TraverseChildren(std::function<void(const AidlNode&)> traverse) const override {
+ if (ref_type_) {
+ traverse(*ref_type_);
+ }
}
void DispatchVisit(AidlVisitor& v) const override { v.Visit(*this); }
const AidlConstantValue* Resolve(const AidlDefinedType* scope) const;
@@ -1249,4 +1251,17 @@
n.TraverseChildren(top_down);
};
top_down(node);
+}
+
+// Utility to make a visitor to visit AST tree in bottom-up order
+// Given: foo
+// / \
+// bar baz
+// VisitBottomUp(v, foo) makes v visit bar -> baz -> foo.
+inline void VisitBottomUp(AidlVisitor& v, const AidlNode& node) {
+ std::function<void(const AidlNode&)> bottom_up = [&](const AidlNode& n) {
+ n.TraverseChildren(bottom_up);
+ n.DispatchVisit(v);
+ };
+ bottom_up(node);
}
\ No newline at end of file