[cfe-commits] r69939 - in /cfe/trunk/lib: Frontend/PCHWriter.cpp Sema/Sema.h Sema/SemaDeclObjC.cpp Sema/SemaExprObjC.cpp Sema/SemaLookup.cpp

Douglas Gregor dgregor at apple.com
Thu Apr 23 16:18:26 PDT 2009


Author: dgregor
Date: Thu Apr 23 18:18:26 2009
New Revision: 69939

URL: http://llvm.org/viewvc/llvm-project?rev=69939&view=rev
Log:
Eliminate Sema::ObjCProtocols. Instead, we place ObjCProtocolDecls in
their own namespace (IDNS_Protocol) and use the normal name-lookup
routines to find them. Aside from the simplification this provides
(one less DenseMap!), it means that protocols will be lazily
deserialized from PCH files.

Make the code size of the selector table block match the code size of
the type and decl blocks.


Modified:
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69939&r1=69938&r2=69939&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Thu Apr 23 18:18:26 2009
@@ -1888,7 +1888,7 @@
 }
 
 void PCHWriter::WriteSelectorTable() {
-  Stream.EnterSubblock(pch::SELECTOR_BLOCK_ID, 3);
+  Stream.EnterSubblock(pch::SELECTOR_BLOCK_ID, 2);
   RecordData Record;
   Record.push_back(pch::SELECTOR_TABLE);
   Record.push_back(SelectorIDs.size());

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Apr 23 18:18:26 2009
@@ -176,11 +176,6 @@
   /// we can check for duplicates and find local method declarations.
   llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
   
-  /// ObjCProtocols - Keep track of all protocol declarations declared
-  /// with @protocol keyword, so that we can emit errors on duplicates and
-  /// find the declarations when needed.
-  llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
-
   /// ObjCInterfaceDecls - Keep track of all class declarations declared
   /// with @interface, so that we can emit errors on duplicates and
   /// find the declarations when needed. 
@@ -769,11 +764,13 @@
     /// namespace alias definition, ignoring non-namespace names (C++
     /// [basic.lookup.udir]p1).
     LookupNamespaceName,
-    // Look up an ordinary name that is going to be redeclared as a
-    // name with linkage. This lookup ignores any declarations that
-    // are outside of the current scope unless they have linkage. See 
-    // C99 6.2.2p4-5 and C++ [basic.link]p6.
-    LookupRedeclarationWithLinkage
+    /// Look up an ordinary name that is going to be redeclared as a
+    /// name with linkage. This lookup ignores any declarations that
+    /// are outside of the current scope unless they have linkage. See 
+    /// C99 6.2.2p4-5 and C++ [basic.link]p6.
+    LookupRedeclarationWithLinkage,
+    /// Look up the name of an Objective-C protocol.
+    LookupProtocolName
   };
 
   /// @brief Represents the results of name lookup.
@@ -1025,6 +1022,7 @@
     case Sema::LookupTagName:
     case Sema::LookupMemberName:
     case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
+    case Sema::LookupProtocolName:
       return D->isInIdentifierNamespace(IDNS);
       
     case Sema::LookupOperatorName:
@@ -1058,6 +1056,8 @@
                                 bool AllowBuiltinCreation = true,
                                 SourceLocation Loc = SourceLocation());
 
+  ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II);
+
   void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
                                     QualType T1, QualType T2, 
                                     FunctionSet &Functions);

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=69939&r1=69938&r2=69939&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Apr 23 18:18:26 2009
@@ -222,7 +222,7 @@
   for (ObjCList<ObjCProtocolDecl>::iterator I = PList.begin(),
        E = PList.end(); I != E; ++I) {
        
-    if (ObjCProtocolDecl *PDecl = ObjCProtocols[(*I)->getIdentifier()]) {
+    if (ObjCProtocolDecl *PDecl = LookupProtocol((*I)->getIdentifier())) {
       if (PDecl->getIdentifier() == PName) {
         Diag(Ploc, diag::err_protocol_has_circular_dependency);
         Diag(PrevLoc, diag::note_previous_definition);
@@ -243,7 +243,7 @@
                                   AttributeList *AttrList) {
   // FIXME: Deal with AttrList.
   assert(ProtocolName && "Missing protocol identifier");
-  ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName];
+  ObjCProtocolDecl *PDecl = LookupProtocol(ProtocolName);
   if (PDecl) {
     // Protocol already seen. Better be a forward protocol declaration
     if (!PDecl->isForwardDecl()) {
@@ -265,10 +265,8 @@
   } else {
     PDecl = ObjCProtocolDecl::Create(Context, CurContext, 
                                      AtProtoInterfaceLoc,ProtocolName);
-    // FIXME: PushOnScopeChains?
-    CurContext->addDecl(Context, PDecl);
+    PushOnScopeChains(PDecl, TUScope);
     PDecl->setForwardDecl(false);
-    ObjCProtocols[ProtocolName] = PDecl;
   }
   if (AttrList)
     ProcessDeclAttributeList(PDecl, AttrList);
@@ -291,7 +289,7 @@
                               unsigned NumProtocols,
                               llvm::SmallVectorImpl<DeclPtrTy> &Protocols) {
   for (unsigned i = 0; i != NumProtocols; ++i) {
-    ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i].first];
+    ObjCProtocolDecl *PDecl = LookupProtocol(ProtocolId[i].first);
     if (!PDecl) {
       Diag(ProtocolId[i].second, diag::err_undeclared_protocol)
         << ProtocolId[i].first;
@@ -514,12 +512,11 @@
   
   for (unsigned i = 0; i != NumElts; ++i) {
     IdentifierInfo *Ident = IdentList[i].first;
-    ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident];
+    ObjCProtocolDecl *PDecl = LookupProtocol(Ident);
     if (PDecl == 0) { // Not already seen?
       PDecl = ObjCProtocolDecl::Create(Context, CurContext, 
                                        IdentList[i].second, Ident);
-      // FIXME: PushOnScopeChains?
-      CurContext->addDecl(Context, PDecl);
+      PushOnScopeChains(PDecl, TUScope);
     }
     if (attrList)
       ProcessDeclAttributeList(PDecl, attrList);

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=69939&r1=69938&r2=69939&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Apr 23 18:18:26 2009
@@ -128,7 +128,7 @@
                                                    SourceLocation ProtoLoc,
                                                    SourceLocation LParenLoc,
                                                    SourceLocation RParenLoc) {
-  ObjCProtocolDecl* PDecl = ObjCProtocols[ProtocolId];
+  ObjCProtocolDecl* PDecl = LookupProtocol(ProtocolId);
   if (!PDecl) {
     Diag(ProtoLoc, diag::err_undeclared_protocol) << ProtocolId;
     return true;

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=69939&r1=69938&r2=69939&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Thu Apr 23 18:18:26 2009
@@ -293,6 +293,10 @@
   case Sema::LookupNamespaceName:
     IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Member;
     break;
+
+  case Sema::LookupProtocolName:
+    IDNS = Decl::IDNS_Protocol;
+    break;
   }
   return IDNS;
 }
@@ -831,6 +835,10 @@
         S = S->getParent();
       IDNS = Decl::IDNS_Ordinary;
       break;
+
+    case Sema::LookupProtocolName:
+      IDNS = Decl::IDNS_Protocol;
+      break;
     }
 
     // Scan up the scope chain looking for a decl that matches this
@@ -1480,6 +1488,12 @@
   return false;
 }
 
+/// \brief Find the protocol with the given name, if any.
+ObjCProtocolDecl *Sema::LookupProtocol(IdentifierInfo *II) {
+  Decl *D = LookupName(TUScope, II, LookupProtocolName).getAsDecl();
+  return cast_or_null<ObjCProtocolDecl>(D);
+}
+
 void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
                                         QualType T1, QualType T2, 
                                         FunctionSet &Functions) {





More information about the cfe-commits mailing list