Get rid if Reference<Interface>
This change allows to have
std::vector<Reference<Type>*> getReferences()
^
Thus we can make recursive lookup be like:
for ref : getReferences() { ref->lookup() }
The check that Interface expends only interfaces is moved to
Interface::validate.
Bug: 31827278
Test: mma
Test: new error test
Change-Id: I8e81b1bdf5658749d4b33d02e812a49765dc03bb
diff --git a/Interface.cpp b/Interface.cpp
index 9d785e7..79824ae 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -70,7 +70,7 @@
};
Interface::Interface(const char* localName, const Location& location, Scope* parent,
- const Reference<Interface>& superType)
+ const Reference<Type>& superType)
: Scope(localName, location, parent),
mSuperType(superType),
mIsJavaCompatibleInProgress(false) {}
@@ -508,6 +508,11 @@
status_t Interface::validate() const {
CHECK(isIBase() == mSuperType.isEmptyReference());
+ if (!isIBase() && !mSuperType->isInterface()) {
+ std::cerr << "ERROR: You can only extend interfaces at " << mSuperType.location() << "\n";
+ return UNKNOWN_ERROR;
+ }
+
for (const auto* method : methods()) {
status_t err = method->validate();
if (err != OK) return err;
@@ -589,7 +594,13 @@
}
const Interface* Interface::superType() const {
- return isIBase() ? nullptr : mSuperType;
+ if (isIBase()) return nullptr;
+ if (!mSuperType->isInterface()) {
+ // This is actually an error
+ // that would be caught in validate
+ return nullptr;
+ }
+ return static_cast<Interface*>(mSuperType.get());
}
std::vector<const Interface *> Interface::typeChain() const {