Make recursive methods in Type work with cyclic AST
Fixes Type::canCheckEquality, Type::needsResolveReferences,
Type::isJavaCompatible, Type:containsPointer.
Adds set of visited Types to these functions to prevent
infinite recursion.
deep versions of these functions *do not* guarantee the correct
return value, but non-deep versions do:
We need to find al least one path from requested vertex
to "bad" vertex (ie. which is not java compatible).
Fixes a bug with containsPointer (containsPointer returned true
if inner type contained a pointer), so more structures get
__attribute__ aligned and static_assert generated for
struct fields.
This change is required for forward reference, as current
implementations assume that the graph is acyclic.
Potential future work: to reduce theoretical complexity of
described actions (square to linear).
Bug: 31827278
Test: mma
Test: output not changed in
out/soong/.intermediates/hardware/interfaces
Change-Id: I3dbdd1605f9317637241057b12de6031125abf7b
diff --git a/VectorType.cpp b/VectorType.cpp
index 524be55..fa9761e 100644
--- a/VectorType.cpp
+++ b/VectorType.cpp
@@ -76,8 +76,8 @@
return mElementType->isBinder();
}
-bool VectorType::canCheckEquality() const {
- return mElementType->canCheckEquality();
+bool VectorType::deepCanCheckEquality(std::unordered_set<const Type*>* visited) const {
+ return mElementType->canCheckEquality(visited);
}
std::vector<const Reference<Type>*> VectorType::getStrongReferences() const {
@@ -714,16 +714,19 @@
return true;
}
-bool VectorType::needsResolveReferences() const {
- return mElementType->needsResolveReferences();
+bool VectorType::deepNeedsResolveReferences(std::unordered_set<const Type*>* visited) const {
+ if (mElementType->needsResolveReferences(visited)) {
+ return true;
+ }
+ return TemplatedType::deepNeedsResolveReferences(visited);
}
bool VectorType::resultNeedsDeref() const {
return !isVectorOfBinders();
}
-bool VectorType::isJavaCompatible() const {
- if (!mElementType->isJavaCompatible()) {
+bool VectorType::deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const {
+ if (!mElementType->isJavaCompatible(visited)) {
return false;
}
@@ -739,11 +742,14 @@
return false;
}
- return true;
+ return TemplatedType::deepIsJavaCompatible(visited);
}
-bool VectorType::containsPointer() const {
- return mElementType->containsPointer();
+bool VectorType::deepContainsPointer(std::unordered_set<const Type*>* visited) const {
+ if (mElementType->containsPointer(visited)) {
+ return true;
+ }
+ return TemplatedType::deepContainsPointer(visited);
}
// All hidl_vec<T> have the same size.