Simplify handling of struct/union/class tags.
Instead of using two sets of Decl kinds (Struct/Union/Class and CXXStruct/CXXUnion/CXXClass), use one 'Record' and one 'CXXRecord' Decl kind and make tag kind a property of TagDecl.
Cleans up the code a bit and better reflects that Decl class structure.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57541 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 382b9eb..3713776 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -221,9 +221,9 @@
 // RecordDecl Implementation
 //===----------------------------------------------------------------------===//
 
-RecordDecl::RecordDecl(Kind DK, DeclContext *DC, SourceLocation L,
+RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
                        IdentifierInfo *Id)
-: TagDecl(DK, DC, L, Id, 0) {
+: TagDecl(DK, TK, DC, L, Id, 0) {
   
   HasFlexibleArrayMember = false;
   assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
@@ -236,16 +236,7 @@
                                RecordDecl* PrevDecl) {
   
   void *Mem = C.getAllocator().Allocate<RecordDecl>();
-  Kind DK;
-  switch (TK) {
-    default: assert(0 && "Invalid TagKind!");
-    case TK_enum: assert(0 && "Enum TagKind passed for Record!");
-    case TK_struct: DK = Struct; break;
-    case TK_union:  DK = Union;  break;
-    case TK_class:  DK = Class;  break;
-  }
-  
-  RecordDecl* R = new (Mem) RecordDecl(DK, DC, L, Id);
+  RecordDecl* R = new (Mem) RecordDecl(Record, TK, DC, L, Id);
   C.getTypeDeclType(R, PrevDecl);
   return R;
 }
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 265913c..75d6bc6 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -74,9 +74,8 @@
   case ObjCMethod:          return "ObjCMethod";
   case ObjCProtocol:        return "ObjCProtocol";
   case ObjCForwardProtocol: return "ObjCForwardProtocol"; 
-  case Struct:              return "Struct";
-  case Union:               return "Union";
-  case Class:               return "Class";
+  case Record:              return "Record";
+  case CXXRecord:           return "CXXRecord";
   case Enum:                return "Enum";
   case Block:               return "Block";
   }
@@ -206,7 +205,7 @@
   case ParmVar:             nParmVars++; break;
   case EnumConstant:        nEnumConst++; break;
   case Field:               nFieldDecls++; break;
-  case Struct: case Union: case Class: nSUC++; break;
+  case Record:              nSUC++; break;
   case Enum:                nEnumDecls++; break;
   case ObjCInterface:       nInterfaceDecls++; break;
   case ObjCClass:           nClassDecls++; break;
@@ -228,7 +227,7 @@
   case TranslationUnit:     break;
 
   case CXXField:            nCXXFieldDecls++; break;
-  case CXXStruct: case CXXUnion: case CXXClass: nCXXSUC++; break;
+  case CXXRecord:           nCXXSUC++; break;
   // FIXME: Statistics for C++ decls.
   case CXXMethod:
   case CXXClassVar:
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index 3f93791..af89da4 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -29,16 +29,8 @@
 CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
                                      SourceLocation L, IdentifierInfo *Id,
                                      CXXRecordDecl* PrevDecl) {
-  Kind DK;
-  switch (TK) {
-    default: assert(0 && "Invalid TagKind!");
-    case TK_enum:   assert(0 && "Enum TagKind passed for Record!");
-    case TK_struct: DK = CXXStruct; break;
-    case TK_union:  DK = CXXUnion;  break;
-    case TK_class:  DK = CXXClass;  break;
-  }
   void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
-  CXXRecordDecl* R = new (Mem) CXXRecordDecl(DK, DC, L, Id);
+  CXXRecordDecl* R = new (Mem) CXXRecordDecl(TK, DC, L, Id);
   C.getTypeDeclType(R, PrevDecl);  
   return R;
 }
diff --git a/lib/AST/DeclSerialization.cpp b/lib/AST/DeclSerialization.cpp
index 718885b..a0befbd 100644
--- a/lib/AST/DeclSerialization.cpp
+++ b/lib/AST/DeclSerialization.cpp
@@ -75,10 +75,8 @@
       Dcl = FunctionDecl::CreateImpl(D, C);
       break;
     
-    case Class:
-    case Union:
-    case Struct:
-      Dcl = RecordDecl::CreateImpl(k, D, C);
+    case Record:
+      Dcl = RecordDecl::CreateImpl(D, C);
       break;
       
     case Typedef:
@@ -461,6 +459,8 @@
 //===----------------------------------------------------------------------===//
 
 void RecordDecl::EmitImpl(Serializer& S) const {
+  S.EmitInt(getTagKind());
+
   ScopedDecl::EmitInRec(S);
   S.EmitBool(isDefinition());
   S.EmitBool(hasFlexibleArrayMember());
@@ -473,11 +473,11 @@
     ScopedDecl::EmitOutRec(S);
 }
 
-RecordDecl* RecordDecl::CreateImpl(Decl::Kind DK, Deserializer& D,
-                                   ASTContext& C) {
+RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) {
+  TagKind TK = TagKind(D.ReadInt());
 
   void *Mem = C.getAllocator().Allocate<RecordDecl>();
-  RecordDecl* decl = new (Mem) RecordDecl(DK, 0, SourceLocation(), NULL);
+  RecordDecl* decl = new (Mem) RecordDecl(Record, TK, 0, SourceLocation(), NULL);
     
   decl->ScopedDecl::ReadInRec(D, C);
   decl->setDefinition(D.ReadBool());
diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp
index dd92e84..666cad6 100644
--- a/lib/AST/StmtDumper.cpp
+++ b/lib/AST/StmtDumper.cpp
@@ -284,13 +284,9 @@
     case Decl::ParmVar: fprintf(F,"ParmVar"); break;
     case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
     case Decl::Typedef: fprintf(F,"Typedef"); break;
-    case Decl::Struct: fprintf(F,"Struct"); break;
-    case Decl::Union: fprintf(F,"Union"); break;
-    case Decl::Class: fprintf(F,"Class"); break;
+    case Decl::Record: fprintf(F,"Record"); break;
     case Decl::Enum: fprintf(F,"Enum"); break;
-    case Decl::CXXStruct: fprintf(F,"CXXStruct"); break;
-    case Decl::CXXUnion: fprintf(F,"CXXUnion"); break;
-    case Decl::CXXClass: fprintf(F,"CXXClass"); break;
+    case Decl::CXXRecord: fprintf(F,"CXXRecord"); break;
     case Decl::ObjCInterface: fprintf(F,"ObjCInterface"); break;
     case Decl::ObjCClass: fprintf(F,"ObjCClass"); break;
     default: fprintf(F,"Decl"); break;
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 6ab227d..57e9c39 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -33,14 +33,10 @@
     assert(0 && "Parmdecls should not be in declstmts!");
   case Decl::Typedef:   // typedef int X;
   case Decl::Function:  // void X();
-  case Decl::Struct:    // struct X;
-  case Decl::Union:     // union X;
-  case Decl::Class:     // class X;
+  case Decl::Record:    // struct/union/class X;
   case Decl::Enum:      // enum X;
   case Decl::EnumConstant: // enum ? { X = ? } 
-  case Decl::CXXStruct: // struct X; [C++]
-  case Decl::CXXUnion:  // union X; [C++]
-  case Decl::CXXClass:  // class X; [C++]
+  case Decl::CXXRecord: // struct/union/class X; [C++]
     // None of these decls require codegen support.
     return;