const-ref: support recursive references
Referenced constant expression can also refer another constant
expressions.
parcelable P {
const int A = B + 1;
const int B = C + 1;
const int C = 1;
}
This works with imported types.
parcelable P { const int A = Q.A + 1; }
parcelable Q { const int A = 1; }
Using this, "auto-fill" of enums got simplified.
enum E { A, B } == enum E { A = 0, B = A + 1 }
Note that circular references are not supported.
parcelable P { const int A = A + 1; } // error
Bug: 142893595
Bug: 174877216
Test: aidl_unittests
Change-Id: Ib187ec47c0184effd64568a9a3d57a2adf5aa4f4
diff --git a/parser.h b/parser.h
index 726922d..f1b6dd8 100644
--- a/parser.h
+++ b/parser.h
@@ -53,6 +53,8 @@
std::string comments_;
};
+using TypeResolver = std::function<bool(const AidlDocument*, AidlTypeSpecifier*)>;
+
class Parser {
public:
// non-copyable, non-assignable
@@ -90,7 +92,7 @@
const vector<AidlTypeSpecifier*>& GetUnresolvedTypespecs() const { return unresolved_typespecs_; }
- bool Resolve();
+ bool Resolve(TypeResolver& type_resolver);
void SetDocument(std::unique_ptr<AidlDocument>&& document) {
// The parsed document is owned by typenames_. This parser object only has
// a reference to it.