[cfe-commits] r42801 - in /cfe/trunk: Sema/Sema.h Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Decl.h include/clang/AST/DeclObjC.h include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h

Fariborz Jahanian fjahanian at apple.com
Tue Oct 9 11:03:53 PDT 2007


Author: fjahanian
Date: Tue Oct  9 13:03:53 2007
New Revision: 42801

URL: http://llvm.org/viewvc/llvm-project?rev=42801&view=rev
Log:
Remove addition of protocol names to declaration scopes, use a separate
DenseMap to keep track of such declarations and derive ObjcProtocolDecl
directyly from NamedScope.

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

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Oct  9 13:03:53 2007
@@ -87,6 +87,11 @@
   /// @implementation's, so that we can emit errors on duplicates.
   llvm::SmallPtrSet<IdentifierInfo*, 8> ObjcImplementations;
   
+  /// ObjcProtocols - Keep track of all protocol declarations declared
+  /// with @protocol keyword, so that we can emit errors on duplicates and
+  /// find the declarations when needded.
+  llvm::DenseMap<IdentifierInfo*, ObjcProtocolDecl*> ObjcProtocols;
+  
   // Enum values used by KnownFunctionIDs (see below).
   enum {
     id_printf,
@@ -195,8 +200,6 @@
   ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, 
                                SourceLocation IdLoc, Scope *S);  
   ObjcInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
-  ObjcProtocolDecl *getObjCProtocolDecl(Scope *S, 
-		       IdentifierInfo *Id, SourceLocation IdLoc);
   ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
   ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
                                  Scope *S);

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Oct  9 13:03:53 2007
@@ -97,25 +97,6 @@
   return cast_or_null<ObjcInterfaceDecl>(static_cast<Decl*>(IdDecl));
 }
 
-/// getObjcProtocolDecl - Look up a for a protocol declaration in the scope.
-/// return 0 if one not found.
-ObjcProtocolDecl *Sema::getObjCProtocolDecl(Scope *S,
-                                            IdentifierInfo *Id, 
-                                            SourceLocation IdLoc) {
-  // Note that Protocols have their own namespace.
-  ScopedDecl *PrDecl = NULL;
-  for (ScopedDecl *D = Id->getFETokenInfo<ScopedDecl>(); D; D = D->getNext()) {
-    if (D->getIdentifierNamespace() == Decl::IDNS_Protocol) {
-      PrDecl = D;
-      break;
-    }
-  }
-  
-  if (PrDecl && !isa<ObjcProtocolDecl>(PrDecl))
-    PrDecl = 0;
-  return cast_or_null<ObjcProtocolDecl>(static_cast<Decl*>(PrDecl));
-}
-
 /// LookupScopedDecl - Look up the inner-most declaration in the specified
 /// namespace.
 ScopedDecl *Sema::LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
@@ -911,8 +892,7 @@
   // Check for another declaration kind with the same name.
   ScopedDecl *PrevDecl = LookupScopedDecl(ClassName, Decl::IDNS_Ordinary,
                                           ClassLoc, S);
-  if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)
-      && !isa<ObjcProtocolDecl>(PrevDecl)) {
+  if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
     Diag(ClassLoc, diag::err_redefinition_different_kind,
          ClassName->getName());
     Diag(PrevDecl->getLocation(), diag::err_previous_definition);
@@ -941,8 +921,7 @@
     // Check if a different kind of symbol declared in this scope.
     PrevDecl = LookupScopedDecl(SuperName, Decl::IDNS_Ordinary,
                                 SuperLoc, S);
-    if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)
-        && !isa<ObjcProtocolDecl>(PrevDecl)) {
+    if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
       Diag(SuperLoc, diag::err_redefinition_different_kind,
            SuperName->getName());
       Diag(PrevDecl->getLocation(), diag::err_previous_definition);
@@ -961,8 +940,7 @@
   
   /// Check then save referenced protocols
   for (unsigned int i = 0; i != NumProtocols; i++) {
-    ObjcProtocolDecl* RefPDecl = getObjCProtocolDecl(S, ProtocolNames[i], 
-                                                     ClassLoc);
+    ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtocolNames[i]];
     if (!RefPDecl || RefPDecl->isForwardDecl())
       Diag(ClassLoc, diag::err_undef_protocolref,
            ProtocolNames[i]->getName(),
@@ -978,7 +956,7 @@
                 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
                 IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
   assert(ProtocolName && "Missing protocol identifier");
-  ObjcProtocolDecl *PDecl = getObjCProtocolDecl(S, ProtocolName, ProtocolLoc);
+  ObjcProtocolDecl *PDecl = ObjcProtocols[ProtocolName];
   if (PDecl) {
     // Protocol already seen. Better be a forward protocol declaration
     if (!PDecl->isForwardDecl())
@@ -992,16 +970,12 @@
   else {
     PDecl = new ObjcProtocolDecl(AtProtoInterfaceLoc, NumProtoRefs, 
                                  ProtocolName);
-    PDecl->setForwardDecl(false);
-    // Chain & install the protocol decl into the identifier.
-    PDecl->setNext(ProtocolName->getFETokenInfo<ScopedDecl>());
-    ProtocolName->setFETokenInfo(PDecl);
+    ObjcProtocols[ProtocolName] = PDecl;
   }    
   
   /// Check then save referenced protocols
   for (unsigned int i = 0; i != NumProtoRefs; i++) {
-    ObjcProtocolDecl* RefPDecl = getObjCProtocolDecl(S, ProtoRefNames[i], 
-                                                     ProtocolLoc);
+    ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
     if (!RefPDecl || RefPDecl->isForwardDecl())
       Diag(ProtocolLoc, diag::err_undef_protocolref,
            ProtoRefNames[i]->getName(),
@@ -1021,8 +995,7 @@
                                    IdentifierInfo **ProtocolId,
                                    unsigned NumProtocols) {
   for (unsigned i = 0; i != NumProtocols; ++i) {
-    ObjcProtocolDecl *PDecl = getObjCProtocolDecl(S, ProtocolId[i], 
-                                                  TypeLoc);
+    ObjcProtocolDecl *PDecl = ObjcProtocols[ProtocolId[i]];
     if (!PDecl)
       Diag(TypeLoc, diag::err_undeclared_protocol, 
            ProtocolId[i]->getName());
@@ -1039,16 +1012,11 @@
   
   for (unsigned i = 0; i != NumElts; ++i) {
     IdentifierInfo *P = IdentList[i];
-    ObjcProtocolDecl *PDecl = getObjCProtocolDecl(S, P, AtProtocolLoc);
+    ObjcProtocolDecl *PDecl = ObjcProtocols[P];
     if (!PDecl)  { // Not already seen?
       // FIXME: Pass in the location of the identifier!
       PDecl = new ObjcProtocolDecl(AtProtocolLoc, 0, P, true);
-      // Chain & install the protocol decl into the identifier.
-      PDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
-      IdentList[i]->setFETokenInfo(PDecl);
-
-      // Remember that this needs to be removed when the scope is popped.
-      S->AddDecl(PDecl);
+      ObjcProtocols[P] = PDecl;
     }
     
     Protocols.push_back(PDecl);
@@ -1090,8 +1058,7 @@
   
   /// Check then save referenced protocols
   for (unsigned int i = 0; i != NumProtoRefs; i++) {
-    ObjcProtocolDecl* RefPDecl = getObjCProtocolDecl(S, ProtoRefNames[i], 
-                                                     CategoryLoc);
+    ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
     if (!RefPDecl || RefPDecl->isForwardDecl()) {
       Diag(CategoryLoc, diag::err_undef_protocolref,
            ProtoRefNames[i]->getName(),
@@ -1148,8 +1115,7 @@
     // Check if a different kind of symbol declared in this scope.
     PrevDecl = LookupScopedDecl(SuperClassname, Decl::IDNS_Ordinary,
                                 SuperClassLoc, S);
-    if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)
-        && !isa<ObjcProtocolDecl>(PrevDecl)) {
+    if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
       Diag(SuperClassLoc, diag::err_redefinition_different_kind,
            SuperClassname->getName());
       Diag(PrevDecl->getLocation(), diag::err_previous_definition);

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

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Oct  9 13:03:53 2007
@@ -739,6 +739,7 @@
 		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=42801&r1=42800&r2=42801&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Oct  9 13:03:53 2007
@@ -84,7 +84,6 @@
     IDNS_Label,
     IDNS_Tag,
     IDNS_Member,
-    IDNS_Protocol,
     IDNS_Ordinary
   };
   
@@ -133,8 +132,6 @@
     case Class:
     case Enum:
       return IDNS_Tag;
-    case ObjcProtocol:
-      return IDNS_Protocol;
     }
   }
   // global temp stats (until we have a per-module visitor)

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Tue Oct  9 13:03:53 2007
@@ -279,7 +279,7 @@
 ///
 /// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
 ///
-class ObjcProtocolDecl : public ScopedDecl {
+class ObjcProtocolDecl : public NamedDecl {
   /// referenced protocols
   ObjcProtocolDecl **ReferencedProtocols;  // Null if none
   int NumReferencedProtocols;  // -1 if none
@@ -296,7 +296,7 @@
 public:
   ObjcProtocolDecl(SourceLocation L, unsigned numRefProtos,
                    IdentifierInfo *Id, bool FD = false)
-    : ScopedDecl(ObjcProtocol, L, Id, 0), 
+    : NamedDecl(ObjcProtocol, L, Id), 
       ReferencedProtocols(0), NumReferencedProtocols(-1),
       InstanceMethods(0), NumInstanceMethods(-1), 
       ClassMethods(0), NumClassMethods(-1),

Modified: cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h?rev=42801&r1=42800&r2=42801&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h (original)
+++ cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h Tue Oct  9 13:03:53 2007
@@ -64,7 +64,6 @@
         DISPATCH_CASE(Class,RecordDecl)     // FIXME: Refine. 
         DISPATCH_CASE(Enum,EnumDecl)
         DISPATCH_CASE(ObjcInterface,ObjcInterfaceDecl)
-        DISPATCH_CASE(ObjcProtocol,ObjcProtocolDecl)
       default:
         assert(false && "Subtype of ScopedDecl not handled.");
     }





More information about the cfe-commits mailing list