Resolve constant expressions for external constants.

* Allow constant expressions to be used as array sizes
  and as annotation values.

Bug: 31592132 allow constant expressions to be used as array sizes.
Bug: 31628863 Autofill values for enum type

Test: `make android.hardware.tests.expression@1.0` compiles
  and generates enum class Color with autofilled values.
Test: `make hidl_test_java` succeeds.
Test: `make hidl_test && adb sync && adb shell hidl_test` succeeds.
Test: `mma`

Change-Id: I57377ec608503d4741d305e98144264b07973055
diff --git a/AST.cpp b/AST.cpp
index 224387d..901c876 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -17,6 +17,7 @@
 #include "AST.h"
 
 #include "Coordinator.h"
+#include "EnumType.h"
 #include "FQName.h"
 #include "HandleType.h"
 #include "Interface.h"
@@ -175,6 +176,33 @@
     return true;
 }
 
+EnumValue *AST::lookupEnumValue(const FQName &fqName, std::string *errorMsg) {
+
+    FQName enumTypeName = fqName.typeName();
+    std::string enumValueName = fqName.valueName();
+
+    CHECK(enumTypeName.isValid());
+    CHECK(!enumValueName.empty());
+
+    Type *type = lookupType(enumTypeName);
+    if(type == nullptr) {
+        *errorMsg = "Cannot find type " + enumTypeName.string();
+        return nullptr;
+    }
+    if(!type->isEnum()) {
+        *errorMsg = "Type " + enumTypeName.string() + " is not an enum type";
+        return nullptr;
+    }
+
+    EnumType *enumType = static_cast<EnumType *>(type);
+    EnumValue *v = static_cast<EnumValue *>(enumType->lookupIdentifier(enumValueName));
+    if(v == nullptr) {
+        *errorMsg = "Enum type " + enumTypeName.string() + " does not have " + enumValueName;
+        return nullptr;
+    }
+    return v;
+}
+
 Type *AST::lookupType(const FQName &fqName) {
     CHECK(fqName.isValid());