Move type-related stuff ouside of parsing

3 new passes: resolving inheritance, evaluating constant expressions and
validation.

`resolveInheritance` completes type fields definition which depends on
type base class (so it needs to be looked up before this pass). That
includes interface method serial autofill and enum value autofill.

`evaluate` evaluates constant expressions. This pass depends on the
previous one as enum autofill creates new expressions (+1s).

`validate` proceedes all type-related checks.

`callForReference` is a special way of calling passes for types:
it is used for types that are defined in reference.
Currently that is only array type (size is defined in reference only)
and template type as it could contain an array.
We need such special way to avoid cyclic evaluate call:
struct S { S[42] arr; };

Test: full build, device boot
Test: hidl_test
Test: full build on mac
Test: generated files differ only in constant expression comments

Change-Id: I499e62ae41c52cc86b13d0014eed790454137af6
diff --git a/Scope.cpp b/Scope.cpp
index f9a844c..acedb28 100644
--- a/Scope.cpp
+++ b/Scope.cpp
@@ -126,6 +126,36 @@
     return OK;
 }
 
+status_t Scope::resolveInheritance() {
+    status_t err = forEachType(&Type::resolveInheritance);
+    if (err != OK) return err;
+    return NamedType::resolveInheritance();
+}
+
+status_t Scope::evaluate() {
+    status_t err = forEachType(&Type::evaluate);
+    if (err != OK) return err;
+
+    for (auto* annotation : mAnnotations) {
+        err = annotation->evaluate();
+        if (err != OK) return err;
+    }
+
+    return NamedType::evaluate();
+}
+
+status_t Scope::validate() const {
+    status_t err = forEachType(&Type::validate);
+    if (err != OK) return err;
+
+    for (const auto* annotation : mAnnotations) {
+        err = annotation->validate();
+        if (err != OK) return err;
+    }
+
+    return NamedType::validate();
+}
+
 status_t Scope::emitTypeDeclarations(Formatter &out) const {
     return forEachType([&](Type *type) {
         return type->emitTypeDeclarations(out);
@@ -195,6 +225,8 @@
     });
 }
 
+////////////////////////////////////////
+
 RootScope::RootScope(const char* localName, const Location& location, Scope* parent)
     : Scope(localName, location, parent) {}
 RootScope::~RootScope() {}
@@ -203,6 +235,13 @@
     return "(root scope)";
 }
 
+status_t RootScope::validate() const {
+    CHECK(annotations().empty());
+    return Scope::validate();
+}
+
+////////////////////////////////////////
+
 LocalIdentifier::LocalIdentifier(){}
 LocalIdentifier::~LocalIdentifier(){}
 
@@ -214,5 +253,14 @@
     return nullptr;
 }
 
+status_t LocalIdentifier::evaluate() {
+    return OK;
+}
+
+status_t LocalIdentifier::validate() const {
+    CHECK(isEnumValue());
+    return OK;
+}
+
 }  // namespace android