[cfe-commits] r41935 - in /cfe/trunk: AST/StmtDumper.cpp AST/StmtPrinter.cpp Analysis/LiveVariables.cpp CodeGen/CGStmt.cpp Sema/Sema.h Sema/SemaDecl.cpp Sema/SemaStmt.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Decl.h

Steve Naroff snaroff at apple.com
Thu Sep 13 16:52:59 PDT 2007


Author: snaroff
Date: Thu Sep 13 18:52:58 2007
New Revision: 41935

URL: http://llvm.org/viewvc/llvm-project?rev=41935&view=rev
Log:

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

Decl is now svelte:-)


Modified:
    cfe/trunk/AST/StmtDumper.cpp
    cfe/trunk/AST/StmtPrinter.cpp
    cfe/trunk/Analysis/LiveVariables.cpp
    cfe/trunk/CodeGen/CGStmt.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/Sema/SemaStmt.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/AST/Decl.h

Modified: cfe/trunk/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtDumper.cpp?rev=41935&r1=41934&r2=41935&view=diff

==============================================================================
--- cfe/trunk/AST/StmtDumper.cpp (original)
+++ cfe/trunk/AST/StmtDumper.cpp Thu Sep 13 18:52:58 2007
@@ -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);

Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=41935&r1=41934&r2=41935&view=diff

==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Thu Sep 13 18:52:58 2007
@@ -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";

Modified: cfe/trunk/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/LiveVariables.cpp?rev=41935&r1=41934&r2=41935&view=diff

==============================================================================
--- cfe/trunk/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/Analysis/LiveVariables.cpp Thu Sep 13 18:52:58 2007
@@ -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));
 }
 

Modified: cfe/trunk/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGStmt.cpp?rev=41935&r1=41934&r2=41935&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/CodeGen/CGStmt.cpp Thu Sep 13 18:52:58 2007
@@ -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);
 }
 

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=41935&r1=41934&r2=41935&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Thu Sep 13 18:52:58 2007
@@ -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);

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=41935&r1=41934&r2=41935&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Thu Sep 13 18:52:58 2007
@@ -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);

Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=41935&r1=41934&r2=41935&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Thu Sep 13 18:52:58 2007
@@ -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;

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=41935&r1=41934&r2=41935&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Thu Sep 13 18:52:58 2007
@@ -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 = "";

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=41935&r1=41934&r2=41935&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Sep 13 18:52:58 2007
@@ -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) {}
 





More information about the cfe-commits mailing list