[cfe-commits] r39373 - in /cfe/cfe/trunk: AST/SemaDecl.cpp Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Decl.h

Steve Naroff snaroff at apple.com
Wed Jul 11 09:43:43 PDT 2007


Author: snaroff
Date: Wed Jul 11 11:43:43 2007
New Revision: 39373

URL: http://llvm.org/viewvc/llvm-project?rev=39373&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Add three new classes to Decl.h: BlockVarDecl, FileVarDecl, and ParmVarDecl.

Made the constructor to VarDecl protected, to indicate it is "abstract".

Reorganized the Decl::Kind enum to allow us to add ObjectDecls/TypeDecls with
minimal breakage.  In the process, realized the isa support for ObjectDecl was already broken (so
the reorg paid for itself already:-) The range check should also be more efficient...

Modified:
    cfe/cfe/trunk/AST/SemaDecl.cpp
    cfe/cfe/trunk/Sema/SemaDecl.cpp
    cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/cfe/trunk/include/clang/AST/Decl.h

Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39373&r1=39372&r2=39373&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:43:43 2007
@@ -273,6 +273,8 @@
       case DeclSpec::SCS_auto:        SC = ObjectDecl::Auto; break;
       case DeclSpec::SCS_register:    SC = ObjectDecl::Register; break;
     }
+    VarDecl *NewVD;
+    
     if (S->getParent() == 0) {
       // File scope. C99 6.9.2p2: A declaration of an identifier for and 
       // object that has file scope without an initializer, and without a
@@ -288,6 +290,7 @@
           return 0;
         }
       }
+      NewVD = new FileVarDecl(D.getIdentifierLoc(), II, R, SC);
     } else { 
       // Block scope. C99 6.7p7: If an identifier for an object is declared with
       // no linkage (C99 6.2.2p6), the type for the object shall be complete...
@@ -297,9 +300,8 @@
           return 0;
         }
       }
-	}
-    VarDecl *NewVD = new VarDecl(D.getIdentifierLoc(), II, R, SC);
-    
+      NewVD = new BlockVarDecl(D.getIdentifierLoc(), II, R, SC);
+    }    
     // Merge the decl with the existing one if appropriate.
     if (PrevDecl) {
       NewVD = MergeVarDecl(NewVD, PrevDecl);
@@ -337,9 +339,9 @@
   }
   
   // FIXME: Handle storage class (auto, register). No declarator?
-  VarDecl *New = new VarDecl(PI.IdentLoc, II, 
-                             TypeRef::getFromOpaquePtr(PI.TypeInfo), 
-                             ObjectDecl::None);
+  VarDecl *New = new ParmVarDecl(PI.IdentLoc, II, 
+                                 TypeRef::getFromOpaquePtr(PI.TypeInfo), 
+                                 ObjectDecl::None);
 
   // If this has an identifier, add it to the scope stack.
   if (II) {

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:43:43 2007
@@ -273,6 +273,8 @@
       case DeclSpec::SCS_auto:        SC = ObjectDecl::Auto; break;
       case DeclSpec::SCS_register:    SC = ObjectDecl::Register; break;
     }
+    VarDecl *NewVD;
+    
     if (S->getParent() == 0) {
       // File scope. C99 6.9.2p2: A declaration of an identifier for and 
       // object that has file scope without an initializer, and without a
@@ -288,6 +290,7 @@
           return 0;
         }
       }
+      NewVD = new FileVarDecl(D.getIdentifierLoc(), II, R, SC);
     } else { 
       // Block scope. C99 6.7p7: If an identifier for an object is declared with
       // no linkage (C99 6.2.2p6), the type for the object shall be complete...
@@ -297,9 +300,8 @@
           return 0;
         }
       }
-	}
-    VarDecl *NewVD = new VarDecl(D.getIdentifierLoc(), II, R, SC);
-    
+      NewVD = new BlockVarDecl(D.getIdentifierLoc(), II, R, SC);
+    }    
     // Merge the decl with the existing one if appropriate.
     if (PrevDecl) {
       NewVD = MergeVarDecl(NewVD, PrevDecl);
@@ -337,9 +339,9 @@
   }
   
   // FIXME: Handle storage class (auto, register). No declarator?
-  VarDecl *New = new VarDecl(PI.IdentLoc, II, 
-                             TypeRef::getFromOpaquePtr(PI.TypeInfo), 
-                             ObjectDecl::None);
+  VarDecl *New = new ParmVarDecl(PI.IdentLoc, II, 
+                                 TypeRef::getFromOpaquePtr(PI.TypeInfo), 
+                                 ObjectDecl::None);
 
   // If this has an identifier, add it to the scope stack.
   if (II) {

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

==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:43:43 2007
@@ -96,23 +96,6 @@
 		DED7D9E50A5257F6003AD0FB /* ScratchBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED7D9E40A5257F6003AD0FB /* ScratchBuffer.cpp */; };
 /* End PBXBuildFile section */
 
-/* Begin PBXBuildStyle section */
-		8435EC6D0BAA4095007CD940 /* Development */ = {
-			isa = PBXBuildStyle;
-			buildSettings = {
-				COPY_PHASE_STRIP = NO;
-			};
-			name = Development;
-		};
-		8435EC6E0BAA4095007CD940 /* Deployment */ = {
-			isa = PBXBuildStyle;
-			buildSettings = {
-				COPY_PHASE_STRIP = YES;
-			};
-			name = Deployment;
-		};
-/* End PBXBuildStyle section */
-
 /* Begin PBXCopyFilesBuildPhase section */
 		8DD76F690486A84900D96B5E /* CopyFiles */ = {
 			isa = PBXCopyFilesBuildPhase;
@@ -500,15 +483,12 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-			buildSettings = {
-			};
-			buildStyles = (
-				8435EC6D0BAA4095007CD940 /* Development */,
-				8435EC6E0BAA4095007CD940 /* Deployment */,
-			);
+			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";
+			projectRoot = "";
+			shouldCheckCompatibility = 1;
 			targets = (
 				8DD76F620486A84900D96B5E /* clang */,
 			);

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Decl.h Wed Jul 11 11:43:43 2007
@@ -30,8 +30,16 @@
 class Decl {
 public:
   enum Kind {
-    Typedef, Function, Variable, Field, EnumConstant,
-    Struct, Union, Class, Enum
+    FIRST_ObjectDecl,
+    Function, 
+    BlockVariable, FileVariable, ParmVariable, // subclasses of VarDecl
+    Field, 
+    EnumConstant,
+    LAST_ObjectDecl,
+    FIRST_TypeDecl,
+    Typedef, 
+    Struct, Union, Class, Enum, // subclasses of TagDecl
+    LAST_TypeDecl
   };
 
   /// IdentifierNamespace - According to C99 6.2.3, there are four namespaces,
@@ -79,7 +87,9 @@
     default: assert(0 && "Unknown decl kind!");
     case Typedef:
     case Function:
-    case Variable:
+    case BlockVariable:
+    case FileVariable:
+    case ParmVariable:
     case EnumConstant:
       return IDNS_Ordinary;
     case Struct:
@@ -115,7 +125,7 @@
   
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) {
-    return D->getKind() == Variable || D->getKind() == Function;
+    return D->getKind() > FIRST_ObjectDecl && D->getKind() < LAST_ObjectDecl;
   }
   static bool classof(const ObjectDecl *D) { return true; }
 };
@@ -124,13 +134,54 @@
 /// declaration or definition.
 class VarDecl : public ObjectDecl {
   // TODO: Initializer.
+protected:
+  VarDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, TypeRef T, StorageClass S)
+    : ObjectDecl(DK, L, Id, T, S) {}
+public:  
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Decl *D) { 
+    return D->getKind() >= BlockVariable && D->getKind() <= ParmVariable; 
+  }
+  static bool classof(const VarDecl *D) { return true; }
+};
+
+/// BlockVarDecl - Represent a local variable declaration.
+class BlockVarDecl : public VarDecl {
 public:
-  VarDecl(SourceLocation L, IdentifierInfo *Id, TypeRef T, StorageClass S)
-    : ObjectDecl(Variable, L, Id, T, S) {}
+  BlockVarDecl(SourceLocation L, IdentifierInfo *Id, 
+                     TypeRef T, StorageClass S)
+    : VarDecl(BlockVariable, L, Id, T, S) {}
   
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == Variable; }
-  static bool classof(const VarDecl *D) { return true; }
+  static bool classof(const VarDecl *D) { return D->getKind() == BlockVariable; }
+  static bool classof(const BlockVarDecl *D) { return true; }
+};
+
+/// FileVarDecl - Represent a file scoped variable declaration. This
+/// will allow us to reason about external variable declarations and tentative 
+/// definitions (C99 6.9.2p2) using our type system (without storing a
+/// pointer to the decl's scope, which is transient).
+class FileVarDecl : public VarDecl {
+public:
+  FileVarDecl(SourceLocation L, IdentifierInfo *Id, 
+                    TypeRef T, StorageClass S)
+    : VarDecl(FileVariable, L, Id, T, S) {}
+  
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const VarDecl *D) { return D->getKind() == FileVariable; }
+  static bool classof(const FileVarDecl *D) { return true; }
+};
+
+/// ParmVarDecl - Represent a parameter to a function.
+class ParmVarDecl : public VarDecl {
+public:
+  ParmVarDecl(SourceLocation L, IdentifierInfo *Id, 
+                     TypeRef T, StorageClass S)
+    : VarDecl(ParmVariable, L, Id, T, S) {}
+  
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const VarDecl *D) { return D->getKind() == ParmVariable; }
+  static bool classof(const ParmVarDecl *D) { return true; }
 };
 
 /// FunctionDecl - An instance of this class is created to represent a function
@@ -219,9 +270,7 @@
   
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) {
-    return D->getKind() == Typedef ||
-           D->getKind() == Struct || D->getKind() == Union ||
-           D->getKind() == Class || D->getKind() == Enum;
+    return D->getKind() > FIRST_TypeDecl && D->getKind() < LAST_TypeDecl;
   }
   static bool classof(const TypeDecl *D) { return true; }
 };





More information about the cfe-commits mailing list