Be a little smarter about dealing with TypeDefs, resolve to the typedef'd

target at lookup time, so all code ever sees is anything _but_ TypeDefs.
Also verify that the optional Enum storage type is valid (i.e. an enum
or an integer type) and re-emit enum values for derived enum types.
diff --git a/AST.cpp b/AST.cpp
index d10a3ef..c26c99c 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -5,6 +5,7 @@
 #include "FQName.h"
 #include "HandleType.h"
 #include "Scope.h"
+#include "TypeDef.h"
 
 #include <android-base/logging.h>
 #include <stdlib.h>
@@ -183,6 +184,11 @@
             Type *type = mScopePath[i]->lookupType(name);
 
             if (type != NULL) {
+                // Resolve typeDefs to the target type.
+                while (type->isTypeDef()) {
+                    type = static_cast<TypeDef *>(type)->referencedType();
+                }
+
                 return type->ref();
             }
         }
@@ -228,6 +234,11 @@
         }
 
         if (dotPos == std::string::npos) {
+            // Resolve typeDefs to the target type.
+            while (type->isTypeDef()) {
+                type = static_cast<TypeDef *>(type)->referencedType();
+            }
+
             return type;
         }