Create a new TypeNodes.def file that enumerates all of the types,
giving them rough classifications (normal types, never-canonical
types, always-dependent types, abstract type representations) and
making it far easier to make sure that we've hit all of the cases when
decoding types. 

Switched some switch() statements on the type class over to using this
mechanism, and filtering out those things we don't care about. For
example, CodeGen should never see always-dependent or non-canonical
types, while debug info generation should never see always-dependent
types. More switch() statements on the type class need to be moved 
over to using this approach, so that we'll get warnings when we add a
new type then fail to account for it somewhere in the compiler.

As part of this, some types have been renamed:

  TypeOfExpr -> TypeOfExprType
  FunctionTypeProto -> FunctionProtoType
  FunctionTypeNoProto -> FunctionNoProtoType

There shouldn't be any functionality change...


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65591 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
index 65f6cb1..276c46f 100644
--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -321,12 +321,12 @@
 /// function type for the block, including the first block literal argument.
 static QualType getBlockFunctionType(ASTContext &Ctx,
                                      const BlockPointerType *BPT) {
-  const FunctionTypeProto *FTy = cast<FunctionTypeProto>(BPT->getPointeeType());
+  const FunctionProtoType *FTy = cast<FunctionProtoType>(BPT->getPointeeType());
 
   llvm::SmallVector<QualType, 8> Types;
   Types.push_back(Ctx.getPointerType(Ctx.VoidTy));
 
-  for (FunctionTypeProto::arg_type_iterator i = FTy->arg_type_begin(),
+  for (FunctionProtoType::arg_type_iterator i = FTy->arg_type_begin(),
        e = FTy->arg_type_end(); i != e; ++i)
     Types.push_back(*i);
 
@@ -455,9 +455,9 @@
                                                        const BlockInfo& Info,
                                                        uint64_t &Size,
                                                        uint64_t &Align,
-                                                       llvm::SmallVector<ValueDecl *, 8> &subBlockDeclRefDecls) {
-  const FunctionTypeProto *FTy =
-    cast<FunctionTypeProto>(Expr->getFunctionType());
+                    llvm::SmallVector<ValueDecl *, 8> &subBlockDeclRefDecls) {
+  const FunctionProtoType *FTy =
+    cast<FunctionProtoType>(Expr->getFunctionType());
 
   FunctionArgList Args;
 
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 7a98b0c..38f6e96 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -37,13 +37,13 @@
 // FIXME: Use iterator and sidestep silly type array creation.
 
 const 
-CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionTypeNoProto *FTNP) {
+CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionNoProtoType *FTNP) {
   return getFunctionInfo(FTNP->getResultType(), 
                          llvm::SmallVector<QualType, 16>());
 }
 
 const 
-CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionTypeProto *FTP) {
+CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionProtoType *FTP) {
   llvm::SmallVector<QualType, 16> ArgTys;
   // FIXME: Kill copy.
   for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
@@ -53,9 +53,9 @@
 
 const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionDecl *FD) {
   const FunctionType *FTy = FD->getType()->getAsFunctionType();
-  if (const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(FTy))
+  if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(FTy))
     return getFunctionInfo(FTP);
-  return getFunctionInfo(cast<FunctionTypeNoProto>(FTy));
+  return getFunctionInfo(cast<FunctionNoProtoType>(FTy));
 }
 
 const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const ObjCMethodDecl *MD) {
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index 5e78c58..6c67ba5 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -179,7 +179,7 @@
   
   // Set up remainder of arguments if there is a prototype.
   // FIXME: IF NOT, HOW IS THIS REPRESENTED?  llvm-gcc doesn't represent '...'!
-  if (const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(Ty)) {
+  if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(Ty)) {
     for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
       EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit));
   } else {
@@ -481,6 +481,13 @@
 
   // Work out details of type.
   switch (Ty->getTypeClass()) {
+#define TYPE(Class, Base)
+#define ABSTRACT_TYPE(Class, Base)
+#define NON_CANONICAL_TYPE(Class, Base)
+#define DEPENDENT_TYPE(Class, Base) case Type::Class:
+#include "clang/AST/TypeNodes.def"
+    assert(false && "Dependent types cannot show up in debug information");
+    
   case Type::Complex:
   case Type::Reference:
   case Type::Vector:
@@ -489,13 +496,16 @@
   case Type::ObjCInterface:
   case Type::ObjCQualifiedInterface:
   case Type::ObjCQualifiedId:
-  default:
     return llvm::DIType();
 
   case Type::Builtin: Slot = CreateType(cast<BuiltinType>(Ty), Unit); break;
   case Type::Pointer: Slot = CreateType(cast<PointerType>(Ty), Unit); break;
-  case Type::TypeName: Slot = CreateType(cast<TypedefType>(Ty), Unit); break;
-  case Type::Tagged: Slot = CreateType(cast<TagType>(Ty), Unit); break;
+  case Type::Typedef: Slot = CreateType(cast<TypedefType>(Ty), Unit); break;
+  case Type::Record:
+  case Type::CXXRecord:
+  case Type::Enum:
+    Slot = CreateType(cast<TagType>(Ty), Unit); 
+    break;
   case Type::FunctionProto:
   case Type::FunctionNoProto:
     return Slot = CreateType(cast<FunctionType>(Ty), Unit);
@@ -504,10 +514,10 @@
   case Type::VariableArray:
   case Type::IncompleteArray:
     return Slot = CreateType(cast<ArrayType>(Ty), Unit);
-  case Type::TypeOfExp:
-    return Slot = getOrCreateType(cast<TypeOfExpr>(Ty)->getUnderlyingExpr()
+  case Type::TypeOfExpr:
+    return Slot = getOrCreateType(cast<TypeOfExprType>(Ty)->getUnderlyingExpr()
                                   ->getType(), Unit);
-  case Type::TypeOfTyp:
+  case Type::TypeOf:
     return Slot = getOrCreateType(cast<TypeOfType>(Ty)->getUnderlyingType(),
                                   Unit);
   }
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index 81fd387..d6e3394 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -209,7 +209,7 @@
   
   FunctionArgList Args;
   if (FD->getNumParams()) {
-    const FunctionTypeProto* FProto = FD->getType()->getAsFunctionTypeProto();
+    const FunctionProtoType* FProto = FD->getType()->getAsFunctionProtoType();
     assert(FProto && "Function def must have prototype!");
 
     for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i)
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 918646f..057f554 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -41,7 +41,7 @@
   class Decl;
   class EnumConstantDecl;
   class FunctionDecl;
-  class FunctionTypeProto;
+  class FunctionProtoType;
   class LabelStmt;
   class ObjCContainerDecl;
   class ObjCInterfaceDecl;
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp
index 1458ccd..0912183 100644
--- a/lib/CodeGen/CodeGenTypes.cpp
+++ b/lib/CodeGen/CodeGenTypes.cpp
@@ -174,13 +174,14 @@
   const clang::Type &Ty = *Context.getCanonicalType(T);
   
   switch (Ty.getTypeClass()) {
-  case Type::TypeName:        // typedef isn't canonical.
-  case Type::TemplateTypeParm:// template type parameters never generated
-  case Type::ClassTemplateSpecialization: // these types are always sugar
-  case Type::DependentSizedArray: // dependent types are never generated
-  case Type::TypeOfExp:       // typeof isn't canonical.
-  case Type::TypeOfTyp:       // typeof isn't canonical.
-    assert(0 && "Non-canonical type, shouldn't happen");
+#define TYPE(Class, Base)
+#define ABSTRACT_TYPE(Class, Base)
+#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
+#define DEPENDENT_TYPE(Class, Base) case Type::Class:
+#include "clang/AST/TypeNodes.def"
+    assert(false && "Non-canonical or dependent types aren't possible.");
+    break;
+
   case Type::Builtin: {
     switch (cast<BuiltinType>(Ty).getKind()) {
     default: assert(0 && "Unknown builtin type!");
@@ -265,10 +266,10 @@
                                  VT.getNumElements());
   }
   case Type::FunctionNoProto:
-    return GetFunctionType(getFunctionInfo(cast<FunctionTypeNoProto>(&Ty)), 
+    return GetFunctionType(getFunctionInfo(cast<FunctionNoProtoType>(&Ty)), 
                            true);
   case Type::FunctionProto: {
-    const FunctionTypeProto *FTP = cast<FunctionTypeProto>(&Ty);
+    const FunctionProtoType *FTP = cast<FunctionProtoType>(&Ty);
     return GetFunctionType(getFunctionInfo(FTP), FTP->isVariadic());
   }
   
@@ -300,7 +301,9 @@
     // Protocols don't influence the LLVM type.
     return ConvertTypeRecursive(Context.getObjCIdType());
 
-  case Type::Tagged: {
+  case Type::Record:
+  case Type::CXXRecord:
+  case Type::Enum: {
     const TagDecl *TD = cast<TagType>(Ty).getDecl();
     const llvm::Type *Res = ConvertTagDeclType(TD);
     
diff --git a/lib/CodeGen/CodeGenTypes.h b/lib/CodeGen/CodeGenTypes.h
index 228502d..e5dbd84 100644
--- a/lib/CodeGen/CodeGenTypes.h
+++ b/lib/CodeGen/CodeGenTypes.h
@@ -33,7 +33,7 @@
   class ABIInfo;
   class ASTContext;
   class FieldDecl;
-  class FunctionTypeProto;
+  class FunctionProtoType;
   class ObjCInterfaceDecl;
   class ObjCIvarDecl;
   class PointerType;
@@ -166,8 +166,8 @@
                                         const llvm::SmallVector<QualType,16> 
                                         &ArgTys);
 
-  const CGFunctionInfo &getFunctionInfo(const FunctionTypeNoProto *FTNP);
-  const CGFunctionInfo &getFunctionInfo(const FunctionTypeProto *FTP);
+  const CGFunctionInfo &getFunctionInfo(const FunctionNoProtoType *FTNP);
+  const CGFunctionInfo &getFunctionInfo(const FunctionProtoType *FTP);
   const CGFunctionInfo &getFunctionInfo(const FunctionDecl *FD);
   const CGFunctionInfo &getFunctionInfo(const ObjCMethodDecl *MD);
   const CGFunctionInfo &getFunctionInfo(QualType ResTy, 
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp
index c802966..525f0fe 100644
--- a/lib/CodeGen/Mangle.cpp
+++ b/lib/CodeGen/Mangle.cpp
@@ -454,10 +454,10 @@
   if (MangleReturnType)
     mangleType(T->getResultType());
 
-  const FunctionTypeProto *Proto = dyn_cast<FunctionTypeProto>(T);
+  const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(T);
   assert(Proto && "Can't mangle K&R function prototypes");
 
-  for (FunctionTypeProto::arg_type_iterator Arg = Proto->arg_type_begin(),
+  for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
                                          ArgEnd = Proto->arg_type_end(); 
        Arg != ArgEnd; ++Arg)
     mangleType(*Arg);