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/ScalarType.cpp b/ScalarType.cpp
index d612d9b..f308a72 100644
--- a/ScalarType.cpp
+++ b/ScalarType.cpp
@@ -12,6 +12,11 @@
     return this;
 }
 
+bool ScalarType::isValidEnumStorageType() const {
+    // Only integer types.
+    return mKind >= KIND_INT8 && mKind <= KIND_UINT64;
+}
+
 std::string ScalarType::getCppType(StorageMode, std::string *extra) const {
     static const char *const kName[] = {
         "char",