Move Decl::NextDeclarator (w/ setters/getters) down to ScopedDecl/FieldDecl.

Decl is now svelte:-)



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41935 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/StmtDumper.cpp b/AST/StmtDumper.cpp
index 332931b..09909d8 100644
--- a/AST/StmtDumper.cpp
+++ b/AST/StmtDumper.cpp
@@ -225,7 +225,7 @@
 void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
   DumpStmt(Node);
   fprintf(F, "\n");
-  for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
+  for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
     ++IndentLevel;
     Indent();
     fprintf(F, "%p ", (void*)D);
diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp
index 9cc2c3a..44a04f6 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -144,7 +144,7 @@
 }
 
 void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
-  for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
+  for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
     Indent();
     PrintRawDecl(D);
     OS << ";\n";
diff --git a/Analysis/LiveVariables.cpp b/Analysis/LiveVariables.cpp
index ab5c552..89cea66 100644
--- a/Analysis/LiveVariables.cpp
+++ b/Analysis/LiveVariables.cpp
@@ -41,8 +41,8 @@
   void VisitStmt(Stmt* S);
   void VisitDeclRefExpr(DeclRefExpr* DR);
   void VisitDeclStmt(DeclStmt* DS);
-  void Register(Decl* D);
-  void RegisterDeclChain(Decl* D);
+  void Register(ScopedDecl* D);
+  void RegisterDeclChain(ScopedDecl* D);
   void RegisterUsedDecls();
 };
 
@@ -59,12 +59,12 @@
   RegisterDeclChain(DS->getDecl());
 }
 
-void RegisterDecls::RegisterDeclChain(Decl* D) {
+void RegisterDecls::RegisterDeclChain(ScopedDecl* D) {
   for (; D != NULL ; D = D->getNextDeclarator())
     Register(D);
 }
 
-void RegisterDecls::Register(Decl* D) {
+void RegisterDecls::Register(ScopedDecl* D) {
   if (VarDecl* V = dyn_cast<VarDecl>(D)) {
     LiveVariables::VPair& VP = L.getVarInfoMap()[V];
 
@@ -240,7 +240,7 @@
   // be live before they are declared.  Declarations, however, are not kills
   // in the sense that the value is obliterated, so we do not register
   // DeclStmts as a "kill site" for a variable.
-  for (Decl* D = DS->getDecl(); D != NULL ; D = D->getNextDeclarator())
+  for (ScopedDecl* D = DS->getDecl(); D != NULL ; D = D->getNextDeclarator())
     KillVar(cast<VarDecl>(D));
 }
 
diff --git a/CodeGen/CGStmt.cpp b/CodeGen/CGStmt.cpp
index fa15c2e..b7f1f29 100644
--- a/CodeGen/CGStmt.cpp
+++ b/CodeGen/CGStmt.cpp
@@ -318,7 +318,8 @@
 }
 
 void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) {
-  for (const Decl *Decl = S.getDecl(); Decl; Decl = Decl->getNextDeclarator())
+  for (const ScopedDecl *Decl = S.getDecl(); Decl; 
+       Decl = Decl->getNextDeclarator())
     EmitDecl(*Decl);
 }
 
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 3095308..1e74321 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -165,7 +165,7 @@
                              DeclTy **Elements, unsigned NumElements);
 private:
   /// Subroutines of ParseDeclarator()...
-  TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *LastDeclarator);
+  TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, ScopedDecl *LastDecl);
   TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *Old);
   FunctionDecl *MergeFunctionDecl(FunctionDecl *New, ScopedDecl *Old);
   VarDecl *MergeVarDecl(VarDecl *New, ScopedDecl *Old);
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 97e8e07..1a808f8 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -430,8 +430,8 @@
 }
 
 Sema::DeclTy *
-Sema::ParseDeclarator(Scope *S, Declarator &D, DeclTy *lastDeclarator) {
-  Decl *LastDeclarator = (Decl*)lastDeclarator;
+Sema::ParseDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
+  ScopedDecl *LastDeclarator = dyn_cast_or_null<ScopedDecl>((Decl *)lastDecl);
   IdentifierInfo *II = D.getIdentifier();
   
   // All of these full declarators require an identifier.  If it doesn't have
@@ -608,16 +608,17 @@
 /// The declarators are chained together backwards, reverse the list.
 Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
   // Often we have single declarators, handle them quickly.
-  Decl *Group = static_cast<Decl*>(group);
-  if (Group == 0)
+  Decl *GroupDecl = static_cast<Decl*>(group);
+  if (GroupDecl == 0)
     return 0;
-    
-  Decl *NewGroup = 0;
+  
+  ScopedDecl *Group = dyn_cast<ScopedDecl>(GroupDecl);
+  ScopedDecl *NewGroup = 0;
   if (Group->getNextDeclarator() == 0) 
     NewGroup = Group;
   else { // reverse the list.
     while (Group) {
-      Decl *Next = Group->getNextDeclarator();
+      ScopedDecl *Next = Group->getNextDeclarator();
       Group->setNextDeclarator(NewGroup);
       NewGroup = Group;
       Group = Next;
@@ -625,7 +626,7 @@
   }
   // Perform semantic analysis that depends on having fully processed both
   // the declarator and initializer.
-  for (Decl *ID = NewGroup; ID; ID = ID->getNextDeclarator()) {
+  for (ScopedDecl *ID = NewGroup; ID; ID = ID->getNextDeclarator()) {
     VarDecl *IDecl = dyn_cast<VarDecl>(ID);
     if (!IDecl)
       continue;
@@ -846,7 +847,7 @@
 
 
 TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D,
-                                    Decl *LastDeclarator) {
+                                    ScopedDecl *LastDeclarator) {
   assert(D.getIdentifier() && "Wrong callback for declspec without declarator");
   
   QualType T = GetTypeForDeclarator(D, S);
diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp
index 2e7e753..7b544a2 100644
--- a/Sema/SemaStmt.cpp
+++ b/Sema/SemaStmt.cpp
@@ -481,7 +481,7 @@
   if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
     // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
     // identifiers for objects having storage class 'auto' or 'register'.
-    for (Decl *D = DS->getDecl(); D; D = D->getNextDeclarator()) {
+    for (ScopedDecl *D = DS->getDecl(); D; D = D->getNextDeclarator()) {
       BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(D);
       if (BVD && !BVD->hasLocalStorage())
         BVD = 0;
diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj
index a7d7e5f..06a6d79 100644
--- a/clang.xcodeproj/project.pbxproj
+++ b/clang.xcodeproj/project.pbxproj
@@ -675,7 +675,6 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 89fc5d5..a3096a4 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -56,13 +56,8 @@
   /// InvalidDecl - This indicates a semantic error occurred.
   int InvalidDecl :  1;
 
-  /// NextDeclarator - If this decl was part of a multi-declarator declaration,
-  /// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
-  Decl *NextDeclarator;
-  
 protected:
-  Decl(Kind DK, Decl *NextDecl)
-    : DeclKind(DK), InvalidDecl(0), NextDeclarator(NextDecl) {
+  Decl(Kind DK) : DeclKind(DK), InvalidDecl(0) {
     if (Decl::CollectingStats()) addDeclKind(DK);
   }
   virtual ~Decl();
@@ -76,13 +71,6 @@
   void setInvalidDecl() { InvalidDecl = 1; }
   int isInvalidDecl() const { return InvalidDecl; }
   
-  /// getNextDeclarator - If this decl was part of a multi-declarator
-  /// declaration, such as "int X, Y, *Z;" this returns the decl for the next
-  /// declarator.  Otherwise it returns null.
-  Decl *getNextDeclarator() { return NextDeclarator; }
-  const Decl *getNextDeclarator() const { return NextDeclarator; }
-  void setNextDeclarator(Decl *N) { NextDeclarator = N; }
-  
   IdentifierNamespace getIdentifierNamespace() const {
     switch (DeclKind) {
     default: assert(0 && "Unknown decl kind!");
@@ -119,14 +107,18 @@
   /// Loc - The location that this decl.
   SourceLocation Loc;
   
+  /// NextDeclarator - If this decl was part of a multi-declarator declaration,
+  /// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
+  ScopedDecl *NextDeclarator;
+  
   /// When this decl is in scope while parsing, the Next field contains a
   /// pointer to the shadowed decl of the same name.  When the scope is popped,
   /// Decls are relinked onto a containing decl object.
   ///
   ScopedDecl *Next;
 protected:
-  ScopedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl) 
-    : Decl(DK, PrevDecl), Identifier(Id), Loc(L), Next(0) {}
+  ScopedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl) 
+    : Decl(DK), Identifier(Id), Loc(L), NextDeclarator(PrevDecl), Next(0) {}
 public:
   IdentifierInfo *getIdentifier() const { return Identifier; }
   SourceLocation getLocation() const { return Loc; }
@@ -136,6 +128,13 @@
   ScopedDecl *getNext() const { return Next; }
   void setNext(ScopedDecl *N) { Next = N; }
   
+  /// getNextDeclarator - If this decl was part of a multi-declarator
+  /// declaration, such as "int X, Y, *Z;" this returns the decl for the next
+  /// declarator.  Otherwise it returns null.
+  ScopedDecl *getNextDeclarator() { return NextDeclarator; }
+  const ScopedDecl *getNextDeclarator() const { return NextDeclarator; }
+  void setNextDeclarator(ScopedDecl *N) { NextDeclarator = N; }
+  
   // Implement isa/cast/dyncast/etc. - true for all ValueDecl's and TypeDecl's.
   static bool classof(const Decl *D) {
     return (D->getKind() >= Function && D->getKind() <= EnumConstant) || 
@@ -151,7 +150,7 @@
   QualType DeclType;
 protected:
   ValueDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
-            Decl *PrevDecl) : ScopedDecl(DK, L, Id, PrevDecl), DeclType(T) {}
+            ScopedDecl *PrevDecl) : ScopedDecl(DK, L, Id, PrevDecl), DeclType(T) {}
 public:
   QualType getType() const { return DeclType; }
   void setType(QualType newType) { DeclType = newType; }
@@ -211,7 +210,7 @@
   static bool classof(const VarDecl *D) { return true; }
 protected:
   VarDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
-          StorageClass SC, Decl *PrevDecl)
+          StorageClass SC, ScopedDecl *PrevDecl)
     : ValueDecl(DK, L, Id, T, PrevDecl), Init(0) { SClass = SC; }
 private:
   StorageClass SClass;
@@ -222,7 +221,7 @@
 class BlockVarDecl : public VarDecl {
 public:
   BlockVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
-               Decl *PrevDecl)
+               ScopedDecl *PrevDecl)
     : VarDecl(BlockVariable, L, Id, T, S, PrevDecl) {}
   
   // Implement isa/cast/dyncast/etc.
@@ -237,7 +236,7 @@
 class FileVarDecl : public VarDecl {
 public:
   FileVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
-              Decl *PrevDecl)
+              ScopedDecl *PrevDecl)
     : VarDecl(FileVariable, L, Id, T, S, PrevDecl) {}
   
   // Implement isa/cast/dyncast/etc.
@@ -249,7 +248,7 @@
 class ParmVarDecl : public VarDecl {
 public:
   ParmVarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, StorageClass S,
-              Decl *PrevDecl)
+              ScopedDecl *PrevDecl)
     : VarDecl(ParmVariable, L, Id, T, S, PrevDecl) {}
   
   // Implement isa/cast/dyncast/etc.
@@ -265,7 +264,8 @@
     None, Extern, Static
   };
   FunctionDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
-               StorageClass S = None, bool isInline = false, Decl *PrevDecl = 0)
+               StorageClass S = None, bool isInline = false, 
+               ScopedDecl *PrevDecl = 0)
     : ValueDecl(Function, L, Id, T, PrevDecl), 
       ParamInfo(0), Body(0), DeclChain(0), SClass(S), IsInline(isInline) {}
   virtual ~FunctionDecl();
@@ -324,19 +324,31 @@
   /// Loc - The location that this decl.
   SourceLocation Loc;
   
+  /// NextDeclarator - If this decl was part of a multi-declarator declaration,
+  /// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
+  FieldDecl *NextDeclarator;
+  
   QualType DeclType;  
 public:
-  FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Decl *PrevDecl)
-    : Decl(Field, PrevDecl), Identifier(Id), Loc(L), DeclType(T) {}
+  FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T, FieldDecl *PrevD)
+    : Decl(Field), Identifier(Id), Loc(L), NextDeclarator(PrevD), 
+      DeclType(T) {}
   FieldDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T, 
-            Decl *PrevDecl) : Decl(DK, PrevDecl), Identifier(Id), Loc(L), 
-            DeclType(T) {}
+            FieldDecl *PrevD) : Decl(DK), Identifier(Id), Loc(L), 
+            NextDeclarator(PrevD), DeclType(T) {}
 
   IdentifierInfo *getIdentifier() const { return Identifier; }
   SourceLocation getLocation() const { return Loc; }
   void setLocation(SourceLocation L) { Loc = L; }
   const char *getName() const;
 
+  /// getNextDeclarator - If this decl was part of a multi-declarator
+  /// declaration, such as "int X, Y, *Z;" this returns the decl for the next
+  /// declarator.  Otherwise it returns null.
+  FieldDecl *getNextDeclarator() { return NextDeclarator; }
+  const FieldDecl *getNextDeclarator() const { return NextDeclarator; }
+  void setNextDeclarator(FieldDecl *N) { NextDeclarator = N; }
+
   QualType getType() const { return DeclType; }
   QualType getCanonicalType() const { return DeclType.getCanonicalType(); }
   
@@ -356,7 +368,7 @@
   llvm::APSInt Val; // The value.
 public:
   EnumConstantDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E,
-                   const llvm::APSInt &V, Decl *PrevDecl)
+                   const llvm::APSInt &V, ScopedDecl *PrevDecl)
     : ValueDecl(EnumConstant, L, Id, T, PrevDecl), Init(E), Val(V) {}
 
   const Expr *getInitExpr() const { return Init; }
@@ -383,7 +395,7 @@
   Type *TypeForDecl;
   friend class ASTContext;
 protected:
-  TypeDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl)
+  TypeDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
     : ScopedDecl(DK, L, Id, PrevDecl), TypeForDecl(0) {}
 public:
   // Implement isa/cast/dyncast/etc.
@@ -398,8 +410,8 @@
   /// UnderlyingType - This is the type the typedef is set to.
   QualType UnderlyingType;
 public:
-  TypedefDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Decl *PrevDecl)
-    : TypeDecl(Typedef, L, Id, PrevDecl), UnderlyingType(T) {}
+  TypedefDecl(SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PD) 
+    : TypeDecl(Typedef, L, Id, PD), UnderlyingType(T) {}
   
   QualType getUnderlyingType() const { return UnderlyingType; }
   void setUnderlyingType(QualType newType) { UnderlyingType = newType; }
@@ -416,7 +428,7 @@
   /// it is a declaration ("struct foo;").
   bool IsDefinition : 1;
 protected:
-  TagDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl)
+  TagDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
     : TypeDecl(DK, L, Id, PrevDecl) {
     IsDefinition = false;
   }
@@ -459,7 +471,7 @@
   /// have a different type than this does.
   QualType IntegerType;
 public:
-  EnumDecl(SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl)
+  EnumDecl(SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
     : TagDecl(Enum, L, Id, PrevDecl) {
     ElementList = 0;
   }
@@ -502,7 +514,7 @@
   FieldDecl **Members;   // Null if not defined.
   int NumMembers;   // -1 if not defined.
 public:
-  RecordDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, Decl *PrevDecl)
+  RecordDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl*PrevDecl)
     : TagDecl(DK, L, Id, PrevDecl) {
     HasFlexibleArrayMember = false;
     assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
@@ -568,8 +580,8 @@
 
 class ObjcIvarDecl : public FieldDecl {
 public:
-  ObjcIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Decl *PrevDecl)
-    : FieldDecl(ObjcIvar, L, Id, T, PrevDecl) {}
+  ObjcIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
+               FieldDecl *PrevDecl) : FieldDecl(ObjcIvar, L, Id, T, PrevDecl) {}
     
   enum AccessControl {
     None, Private, Protected, Public, Package
@@ -614,7 +626,7 @@
 		 ParmVarDecl **paramInfo = 0, int numParams=-1,
 		 AttributeList *M = 0, bool isInstance = true, 
 		 Decl *PrevDecl = 0)
-    : Decl(ObjcMethod, PrevDecl), MethodDeclType(T), 
+    : Decl(ObjcMethod), MethodDeclType(T), 
       ParamInfo(paramInfo), NumMethodParams(numParams),
       MethodAttrs(M), IsInstance(isInstance) {}