]> granicus.if.org Git - clang/commitdiff
Eliminate ObjCClassDecl, which is redundant now that ObjCInterfaceDecl
authorDouglas Gregor <dgregor@apple.com>
Tue, 27 Dec 2011 22:43:10 +0000 (22:43 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 27 Dec 2011 22:43:10 +0000 (22:43 +0000)
covers both declarations (@class) and definitions (@interface) of an
Objective-C class.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147299 91177308-0d34-0410-b5e6-96231b3b80d8

32 files changed:
include/clang/AST/DeclObjC.h
include/clang/AST/RecursiveASTVisitor.h
include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h
include/clang/Basic/DeclNodes.td
include/clang/Serialization/ASTBitCodes.h
lib/AST/ASTImporter.cpp
lib/AST/DeclBase.cpp
lib/AST/DeclObjC.cpp
lib/AST/DeclPrinter.cpp
lib/AST/DumpXML.cpp
lib/CodeGen/CGDecl.cpp
lib/CodeGen/CodeGenModule.cpp
lib/Frontend/ASTUnit.cpp
lib/Rewrite/RewriteObjC.cpp
lib/Sema/CodeCompleteConsumer.cpp
lib/Sema/SemaCodeComplete.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaLookup.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriter.cpp
lib/Serialization/ASTWriterDecl.cpp
test/Index/TestClassDecl.m
test/Index/TestClassForwardDecl.m
test/Index/annotate-tokens.m
test/Index/file-refs.m
test/Index/properties-class-extensions.m
tools/libclang/CIndex.cpp
tools/libclang/CIndexUSRs.cpp
tools/libclang/CursorVisitor.h
tools/libclang/IndexDecl.cpp
tools/libclang/IndexingContext.cpp
tools/libclang/IndexingContext.h

index 34fd4d71e732df5c3283056ffcfd2484428dab39..789b75558de147eaa911fe94e789f722087a2a07 100644 (file)
@@ -1145,39 +1145,6 @@ public:
   friend class ASTDeclWriter;
 };
 
-/// ObjCClassDecl - Specifies a list of forward class declarations. For example:
-///
-/// @class NSCursor, NSImage, NSPasteboard, NSWindow;
-///
-class ObjCClassDecl : public Decl {
-  ObjCInterfaceDecl *Interface;
-  SourceLocation InterfaceLoc;
-  
-  ObjCClassDecl(DeclContext *DC, SourceLocation L,
-                ObjCInterfaceDecl *Interface, SourceLocation InterfaceLoc);
-  
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
-  
-public:
-  static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
-                               ObjCInterfaceDecl *Interface = 0,
-                               SourceLocation InterfaceLoc = SourceLocation());
-
-  ObjCInterfaceDecl *getForwardInterfaceDecl() const {
-    return Interface;
-  }
-
-  /// \brief Retrieve the location of the class name.
-  SourceLocation getNameLoc() const { return InterfaceLoc; }
-
-  virtual SourceRange getSourceRange() const;
-
-  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
-  static bool classof(const ObjCClassDecl *D) { return true; }
-  static bool classofKind(Kind K) { return K == ObjCClass; }
-};
-
 /// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations.
 /// For example:
 ///
index 2bc85a569e6de3fd4f84bb20b11ef5ca1f95deed..0c19351d88b7aeac2f60d35a7c2931e2e31751eb 100644 (file)
@@ -1162,10 +1162,6 @@ DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
 
 DEF_TRAVERSE_DECL(LinkageSpecDecl, { })
 
-DEF_TRAVERSE_DECL(ObjCClassDecl, {
-    // FIXME: implement this
-  })
-
 DEF_TRAVERSE_DECL(ObjCForwardProtocolDecl, {
     // FIXME: implement this
   })
index 5c5ec2d7afd8f8b314549479fd2100005ddb0f90..b9c8b04e28871e5cd09657dc8d8f0aeb9f2f33a2 100644 (file)
@@ -83,7 +83,6 @@ public:
   DEFAULT_DISPATCH(Record)
   DEFAULT_DISPATCH(Enum)
   DEFAULT_DISPATCH(ObjCInterface)
-  DEFAULT_DISPATCH(ObjCClass)
   DEFAULT_DISPATCH(ObjCMethod)
   DEFAULT_DISPATCH(ObjCProtocol)
   DEFAULT_DISPATCH(ObjCCategory)
index 37c6a8b15a5688b5650df0bd783b542c0a156f03..fbe4831f6b0fb5c3cde7bd1ae2426d2ad391b8cf 100644 (file)
@@ -67,7 +67,6 @@ def Named : Decl<1>;
 def LinkageSpec : Decl, DeclContext;
 def ObjCPropertyImpl : Decl;
 def ObjCForwardProtocol : Decl;
-def ObjCClass : Decl;
 def FileScopeAsm : Decl;
 def AccessSpec : Decl;
 def Friend : Decl;
index 073ad80d7491e399c944727df1dc8c233992a472..7fd550f992353f928a578f1a43f0e3ed4006707f 100644 (file)
@@ -814,8 +814,6 @@ namespace clang {
       DECL_OBJC_IVAR,
       /// \brief A ObjCAtDefsFieldDecl record.
       DECL_OBJC_AT_DEFS_FIELD,
-      /// \brief A ObjCClassDecl record.
-      DECL_OBJC_CLASS,
       /// \brief A ObjCForwardProtocolDecl record.
       DECL_OBJC_FORWARD_PROTOCOL,
       /// \brief A ObjCCategoryDecl record.
index a95c941e02eb274d0257cd4ddb44300ab1437698..67045059cfddef16e2ff976e255e7d7d6148090a 100644 (file)
@@ -128,7 +128,6 @@ namespace clang {
     Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D);
     Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
     Decl *VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
-    Decl *VisitObjCClassDecl(ObjCClassDecl *D);
     Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
     Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
     Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
@@ -3605,35 +3604,6 @@ ASTNodeImporter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
   return ToForward;
 }
 
-Decl *ASTNodeImporter::VisitObjCClassDecl(ObjCClassDecl *D) {
-  // Import the context of this declaration.
-  DeclContext *DC = Importer.ImportContext(D->getDeclContext());
-  if (!DC)
-    return 0;
-  
-  DeclContext *LexicalDC = DC;
-  if (D->getDeclContext() != D->getLexicalDeclContext()) {
-    LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
-    if (!LexicalDC)
-      return 0;
-  }
-  
-  // Import the location of this declaration.
-  SourceLocation Loc = Importer.Import(D->getLocation());
-  ObjCInterfaceDecl *ToIface
-    = cast_or_null<ObjCInterfaceDecl>(
-        Importer.Import(D->getForwardInterfaceDecl()));
-  ObjCClassDecl *ToClass = ObjCClassDecl::Create(Importer.getToContext(), DC,
-                             Loc,
-                             ToIface,
-                             Importer.Import(D->getNameLoc()));
-    
-  ToClass->setLexicalDeclContext(LexicalDC);
-  LexicalDC->addDeclInternal(ToClass);
-  Importer.Imported(D, ToClass);
-  return ToClass;
-}
-
 Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   // For template arguments, we adopt the translation unit as our declaration
   // context. This context will be fixed when the actual template declaration
index 024f370c56d3288f7509f69ac277733236083c38..983673fec8fe93ad3f07e1741736381b16e5a8d2 100644 (file)
@@ -495,7 +495,6 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
     case LinkageSpec:
     case FileScopeAsm:
     case StaticAssert:
-    case ObjCClass:
     case ObjCPropertyImpl:
     case ObjCForwardProtocol:
     case Block:
@@ -1062,11 +1061,6 @@ void DeclContext::buildLookup(DeclContext *DCtx) {
         if (D->getDeclContext() == DCtx)
           makeDeclVisibleInContextImpl(ND, false);
 
-      // Insert any forward-declared Objective-C interface into the lookup
-      // data structure.
-      if (ObjCClassDecl *Class = dyn_cast<ObjCClassDecl>(*D))
-        makeDeclVisibleInContextImpl(Class->getForwardInterfaceDecl(), false);
-      
       // If this declaration is itself a transparent declaration context or
       // inline namespace, add its members (recursively).
       if (DeclContext *InnerCtx = dyn_cast<DeclContext>(*D))
index a204e45bac9fd658726a7a492838b65bdd1019c6..75100ecb3cbf0ffc17e3e873491af46ee2316451 100644 (file)
@@ -1010,28 +1010,6 @@ void ObjCProtocolDecl::completedForwardDecl() {
     L->CompletedObjCForwardRef(this);
 }
 
-//===----------------------------------------------------------------------===//
-// ObjCClassDecl
-//===----------------------------------------------------------------------===//
-
-ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L,
-                             ObjCInterfaceDecl *Interface, 
-                             SourceLocation InterfaceLoc)
-  : Decl(ObjCClass, DC, L), Interface(Interface), InterfaceLoc(InterfaceLoc)
-{
-}
-
-ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
-                                     SourceLocation L,
-                                     ObjCInterfaceDecl *Interface,
-                                     SourceLocation InterfaceLoc) {
-  return new (C) ObjCClassDecl(DC, L, Interface, InterfaceLoc);
-}
-
-SourceRange ObjCClassDecl::getSourceRange() const {
-  return SourceRange(getLocation(), InterfaceLoc);
-}
-
 //===----------------------------------------------------------------------===//
 // ObjCForwardProtocolDecl
 //===----------------------------------------------------------------------===//
index 03a69a04185a9743e525b82f7d56e83ee036702f..9b72bb416af6a080bee1689d6ec23ea058e40fa9 100644 (file)
@@ -70,7 +70,6 @@ namespace {
     void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
     void VisitClassTemplateDecl(ClassTemplateDecl *D);
     void VisitObjCMethodDecl(ObjCMethodDecl *D);
-    void VisitObjCClassDecl(ObjCClassDecl *D);
     void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
     void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
     void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
@@ -847,10 +846,6 @@ void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
 // Objective-C declarations
 //----------------------------------------------------------------------------
 
-void DeclPrinter::VisitObjCClassDecl(ObjCClassDecl *D) {
-  Out << "@class " << *D->getForwardInterfaceDecl();
-}
-
 void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
   if (OMD->isInstanceMethod())
     Out << "- ";
index e0ea612dc29190aaa6e59f056a770aad04b606f0..959bbcbb1748baf05315546f3ca3ca88d60617f6 100644 (file)
@@ -740,11 +740,6 @@ struct XMLDumper : public XMLDeclVisitor<XMLDumper>,
     visitDeclContext(D);
   }
 
-  // ObjCClassDecl
-  void visitObjCClassDeclChildren(ObjCClassDecl *D) {
-    visitDeclRef(D->getForwardInterfaceDecl());
-  }
-
   // ObjCInterfaceDecl
   void visitCategoryList(ObjCCategoryDecl *D) {
     if (!D) return;
index ff85fc56886eb43b014713c3c93b2c8a05f4d37f..e8f00e7dde57231c922066ad9c79d4874d0c314f 100644 (file)
@@ -65,7 +65,6 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
   case Decl::AccessSpec:
   case Decl::LinkageSpec:
   case Decl::ObjCPropertyImpl:
-  case Decl::ObjCClass:
   case Decl::ObjCForwardProtocol:
   case Decl::FileScopeAsm:
   case Decl::Friend:
index 16d01efb934b6d6ec5dbf42f129fcc863892807b..12c4dff39c0551f5b7fcaabc9bb3035f2d60c37e 100644 (file)
@@ -2375,7 +2375,6 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
   // Objective-C Decls
 
   // Forward declarations, no (immediate) code generation.
-  case Decl::ObjCClass:
   case Decl::ObjCForwardProtocol:
   case Decl::ObjCInterface:
     break;
index 10ec6be37be8743608faa6aa64faa39d75c1a248..241a2c3296632203f19fad1d0f92de91be12d557 100644 (file)
@@ -837,11 +837,6 @@ void AddTopLevelDeclarationToHash(Decl *D, unsigned &Hash) {
       AddTopLevelDeclarationToHash(*P, Hash);
     return;
   }
-  
-  if (ObjCClassDecl *Class = dyn_cast<ObjCClassDecl>(D)) {
-    AddTopLevelDeclarationToHash(Class->getForwardInterfaceDecl(), Hash);
-    return;
-  }
 }
 
 class TopLevelDeclTrackerConsumer : public ASTConsumer {
index 57acba3de0bb0f62c52ef1ba2e69003f5bed3b20..4b41e5a445034416f76a9665d6ce2a92ed2cb732 100644 (file)
@@ -165,10 +165,13 @@ namespace {
     // Top Level Driver code.
     virtual bool HandleTopLevelDecl(DeclGroupRef D) {
       for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
-        if (isa<ObjCClassDecl>((*I))) {
-          RewriteForwardClassDecl(D);
-          break;
+        if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(*I)) {
+          if (!Class->isThisDeclarationADefinition()) {
+            RewriteForwardClassDecl(D);
+            break;
+          }
         }
+
         HandleTopLevelSingleDecl(*I);
       }
       return true;
@@ -256,7 +259,7 @@ namespace {
     void RewriteInclude();
     void RewriteForwardClassDecl(DeclGroupRef D);
     void RewriteForwardClassDecl(const llvm::SmallVector<Decl*, 8> &DG);
-    void RewriteForwardClassEpilogue(ObjCClassDecl *ClassDecl, 
+    void RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl, 
                                      const std::string &typedefString);
     void RewriteImplementations();
     void RewritePropertyImplDecl(ObjCPropertyImplDecl *PID,
@@ -668,27 +671,23 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) {
     for (DeclContext::decl_iterator DI = LSD->decls_begin(),
                                  DIEnd = LSD->decls_end();
          DI != DIEnd; ) {
-      if (isa<ObjCClassDecl>((*DI))) {
-        SmallVector<Decl *, 8> DG;
-        Decl *D = (*DI);
-        SourceLocation Loc = D->getLocation();
-        while (DI != DIEnd &&
-               isa<ObjCClassDecl>(D) && D->getLocation() == Loc) {
-          ObjCClassDecl *Class = cast<ObjCClassDecl>(D);
-          DG.push_back(D);
-          ++DI;
-          D = (*DI);
-
-          // Following the ObjCClassDecl, we should have the corresponding
-          // ObjCInterfaceDecl. Skip over it.
-          if (DI != DIEnd && isa<ObjCInterfaceDecl>(D) && 
-              Class->getForwardInterfaceDecl() == D) {
+      if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>((*DI))) {
+        if (!IFace->isThisDeclarationADefinition()) {
+          SmallVector<Decl *, 8> DG;
+          SourceLocation StartLoc = IFace->getLocStart();
+          do {
+            if (isa<ObjCInterfaceDecl>(*DI) &&
+                !cast<ObjCInterfaceDecl>(*DI)->isThisDeclarationADefinition() &&
+                StartLoc == (*DI)->getLocStart())
+              DG.push_back(*DI);
+            else
+              break;
+            
             ++DI;
-            D = (*DI);
-          }
+          } while (DI != DIEnd);
+          RewriteForwardClassDecl(DG);
+          continue;
         }
-        RewriteForwardClassDecl(DG);
-        continue;
       }
       HandleTopLevelSingleDecl(*DI);
       ++DI;
@@ -873,9 +872,9 @@ static void RewriteOneForwardClassDecl(ObjCInterfaceDecl *ForwardDecl,
   typedefString += ";\n#endif\n";
 }
 
-void RewriteObjC::RewriteForwardClassEpilogue(ObjCClassDecl *ClassDecl,
+void RewriteObjC::RewriteForwardClassEpilogue(ObjCInterfaceDecl *ClassDecl,
                                               const std::string &typedefString) {
-    SourceLocation startLoc = ClassDecl->getLocation();
+    SourceLocation startLoc = ClassDecl->getLocStart();
     const char *startBuf = SM->getCharacterData(startLoc);
     const char *semiPtr = strchr(startBuf, ';'); 
     // Replace the @class with typedefs corresponding to the classes.
@@ -885,8 +884,7 @@ void RewriteObjC::RewriteForwardClassEpilogue(ObjCClassDecl *ClassDecl,
 void RewriteObjC::RewriteForwardClassDecl(DeclGroupRef D) {
   std::string typedefString;
   for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
-    ObjCClassDecl *ClassDecl = cast<ObjCClassDecl>(*I);
-    ObjCInterfaceDecl *ForwardDecl = ClassDecl->getForwardInterfaceDecl();
+    ObjCInterfaceDecl *ForwardDecl = cast<ObjCInterfaceDecl>(*I);
     if (I == D.begin()) {
       // Translate to typedef's that forward reference structs with the same name
       // as the class. As a convenience, we include the original declaration
@@ -898,15 +896,14 @@ void RewriteObjC::RewriteForwardClassDecl(DeclGroupRef D) {
     RewriteOneForwardClassDecl(ForwardDecl, typedefString);
   }
   DeclGroupRef::iterator I = D.begin();
-  RewriteForwardClassEpilogue(cast<ObjCClassDecl>(*I), typedefString);
+  RewriteForwardClassEpilogue(cast<ObjCInterfaceDecl>(*I), typedefString);
 }
 
 void RewriteObjC::RewriteForwardClassDecl(
                                 const llvm::SmallVector<Decl*, 8> &D) {
   std::string typedefString;
   for (unsigned i = 0; i < D.size(); i++) {
-    ObjCClassDecl *ClassDecl = cast<ObjCClassDecl>(D[i]);
-    ObjCInterfaceDecl *ForwardDecl = ClassDecl->getForwardInterfaceDecl();
+    ObjCInterfaceDecl *ForwardDecl = cast<ObjCInterfaceDecl>(D[i]);
     if (i == 0) {
       typedefString += "// @class ";
       typedefString += ForwardDecl->getNameAsString();
@@ -914,7 +911,7 @@ void RewriteObjC::RewriteForwardClassDecl(
     }
     RewriteOneForwardClassDecl(ForwardDecl, typedefString);
   }
-  RewriteForwardClassEpilogue(cast<ObjCClassDecl>(D[0]), typedefString);
+  RewriteForwardClassEpilogue(cast<ObjCInterfaceDecl>(D[0]), typedefString);
 }
 
 void RewriteObjC::RewriteMethodDeclaration(ObjCMethodDecl *Method) {
@@ -4990,10 +4987,6 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
         RewriteRecordBody(RD);
       break;
     }
-    case Decl::ObjCClass: {
-      llvm_unreachable("RewriteObjC::HandleDeclInMainFile - ObjCClassDecl");
-      break;
-    }
     default:
       break;
   }
index da9860361bc3db0387b2a9d5ef88ed0c4c435b7a..17e02c7473da8f34d76b27386cf335c37b4632e2 100644 (file)
@@ -424,8 +424,14 @@ void CodeCompletionResult::computeCursorKindAndAvailability(bool Accessible) {
         Availability = CXAvailability_NotAvailable;
       
     CursorKind = getCursorKindForDecl(Declaration);
-    if (CursorKind == CXCursor_UnexposedDecl)
-      CursorKind = CXCursor_NotImplemented;
+    if (CursorKind == CXCursor_UnexposedDecl) {
+      // FIXME: Forward declarations of Objective-C classes are not directly
+      // exposed, but we want code completion to treat them like an @interface.
+      if (isa<ObjCInterfaceDecl>(Declaration))
+        CursorKind = CXCursor_ObjCInterfaceDecl;
+      else
+        CursorKind = CXCursor_NotImplemented;
+    }
     break;
 
   case RK_Macro:
index 79985e8b322ab6657498c78eae6c79404e295a7c..72cc37ccdd336e9f096504c70e6517da06d3ab11 100644 (file)
@@ -2781,14 +2781,20 @@ CXCursorKind clang::getCursorKindForDecl(Decl *D) {
       return CXCursor_FunctionDecl;
     case Decl::ObjCCategory:       return CXCursor_ObjCCategoryDecl;
     case Decl::ObjCCategoryImpl:   return CXCursor_ObjCCategoryImplDecl;
-    case Decl::ObjCClass:
       // FIXME
       return CXCursor_UnexposedDecl;
     case Decl::ObjCForwardProtocol:
       // FIXME
       return CXCursor_UnexposedDecl;      
     case Decl::ObjCImplementation: return CXCursor_ObjCImplementationDecl;
-    case Decl::ObjCInterface:      return CXCursor_ObjCInterfaceDecl;
+
+    case Decl::ObjCInterface:
+      if (cast<ObjCInterfaceDecl>(D)->isThisDeclarationADefinition())
+        return CXCursor_ObjCInterfaceDecl;
+      
+      // Forward declarations are not directly exposed.
+      return CXCursor_UnexposedDecl;
+
     case Decl::ObjCIvar:           return CXCursor_ObjCIvarDecl; 
     case Decl::ObjCMethod:
       return cast<ObjCMethodDecl>(D)->isInstanceMethod()
@@ -5490,15 +5496,6 @@ static void AddInterfaceResults(DeclContext *Ctx, DeclContext *CurContext,
       if ((!OnlyForwardDeclarations || !Class->hasDefinition()) &&
           (!OnlyUnimplemented || !Class->getImplementation()))
         Results.AddResult(Result(Class, 0), CurContext, 0, false);
-
-    // Record any forward-declared interfaces we find.
-    if (ObjCClassDecl *Forward = dyn_cast<ObjCClassDecl>(*D)) {
-      ObjCInterfaceDecl *IDecl = Forward->getForwardInterfaceDecl();
-      if ((!OnlyForwardDeclarations || !IDecl->hasDefinition()) &&
-          (!OnlyUnimplemented || !IDecl->getImplementation()))
-        Results.AddResult(Result(IDecl, 0), CurContext,
-                          0, false);
-    }
   }
 }
 
index c86f735d57d8823d81fbd80899bf57faa0f68ef0..168ccfc3f578cb03cede886852964457042358e8 100644 (file)
@@ -1775,21 +1775,12 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
       = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
     ObjCInterfaceDecl *IDecl
       = ObjCInterfaceDecl::Create(Context, CurContext, AtClassLoc,
-                                  IdentList[i], PrevIDecl, IdentLocs[i], true);
+                                  IdentList[i], PrevIDecl, IdentLocs[i]);
     IDecl->setAtEndRange(IdentLocs[i]);
     
-    // Create the forward declaration. Note that we intentionally do this 
-    // before we add the ObjCInterfaceDecl we just created, so that the
-    // rewriter sees the ObjCClassDecl first.
-    // FIXME: ObjCClassDecl should probably just go away.
-    ObjCClassDecl *CDecl = ObjCClassDecl::Create(Context, CurContext, AtClassLoc,
-                                                 IDecl, IdentLocs[i]);
-    CurContext->addDecl(CDecl);
-    
     PushOnScopeChains(IDecl, TUScope);
-    
-    CheckObjCDeclScope(CDecl);
-    DeclsInGroup.push_back(CDecl);
+    CheckObjCDeclScope(IDecl);
+    DeclsInGroup.push_back(IDecl);
   }
   
   return BuildDeclaratorGroup(DeclsInGroup.data(), DeclsInGroup.size(), false);
index a5fc682d18c96052a30758704f03bff572b6939e..389abd5ec740eb3a85a8d9edf574ffc8093127db 100644 (file)
@@ -2776,12 +2776,6 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result,
             Visited.add(ND);
           }
         }
-      } else if (ObjCClassDecl *Class = dyn_cast<ObjCClassDecl>(*D)) {
-          ObjCInterfaceDecl *IFace = Class->getForwardInterfaceDecl();
-          if (NamedDecl *ND = Result.getAcceptableDecl(IFace)) {
-            Consumer.FoundDecl(ND, Visited.checkHidden(ND), Ctx, InBaseClass);
-            Visited.add(ND);
-          }
       }
       
       // Visit transparent contexts and inline namespaces inside this context.
index 3819191e0c291bd967a7dbb28f721120fe5ece10..476f8b5c026de9480d22d5df3ac10818c89b53f4 100644 (file)
@@ -279,7 +279,6 @@ namespace clang {
     void VisitObjCIvarDecl(ObjCIvarDecl *D);
     void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
     void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
-    void VisitObjCClassDecl(ObjCClassDecl *D);
     void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
     void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
     void VisitObjCImplDecl(ObjCImplDecl *D);
@@ -782,12 +781,6 @@ void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
   VisitFieldDecl(FD);
 }
 
-void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
-  VisitDecl(CD);
-  CD->Interface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
-  CD->InterfaceLoc = ReadSourceLocation(Record, Idx);
-}
-
 void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
   VisitDecl(FPD);
   unsigned NumProtoRefs = Record[Idx++];
@@ -1944,9 +1937,6 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
     D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
                                     SourceLocation(), 0, QualType(), 0);
     break;
-  case DECL_OBJC_CLASS:
-    D = ObjCClassDecl::Create(Context, 0, SourceLocation());
-    break;
   case DECL_OBJC_FORWARD_PROTOCOL:
     D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
     break;
index feeb27f338929e01d7eb4f1ff7a9e5ae97cb2bea..1302d538f5a07160e060486e6b4b5674a16ecafe 100644 (file)
@@ -865,7 +865,6 @@ void ASTWriter::WriteBlockInfoBlock() {
   RECORD(DECL_OBJC_PROTOCOL);
   RECORD(DECL_OBJC_IVAR);
   RECORD(DECL_OBJC_AT_DEFS_FIELD);
-  RECORD(DECL_OBJC_CLASS);
   RECORD(DECL_OBJC_FORWARD_PROTOCOL);
   RECORD(DECL_OBJC_CATEGORY);
   RECORD(DECL_OBJC_CATEGORY_IMPL);
index 7ae601810b92c729b43d3d51cd5c5e1ae1f2a1ce..0692c023e497186745f7d48f7c7cb3771939d48a 100644 (file)
@@ -114,7 +114,6 @@ namespace clang {
     void VisitObjCIvarDecl(ObjCIvarDecl *D);
     void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
     void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
-    void VisitObjCClassDecl(ObjCClassDecl *D);
     void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
     void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
     void VisitObjCImplDecl(ObjCImplDecl *D);
@@ -538,13 +537,6 @@ void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
   Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
 }
 
-void ASTDeclWriter::VisitObjCClassDecl(ObjCClassDecl *D) {
-  VisitDecl(D);
-  Writer.AddDeclRef(D->Interface, Record);
-  Writer.AddSourceLocation(D->InterfaceLoc, Record);
-  Code = serialization::DECL_OBJC_CLASS;
-}
-
 void ASTDeclWriter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
   VisitDecl(D);
   Record.push_back(D->protocol_size());
index bc4f2afb73e08a460b9030c084d7e442429dc6a8..2abc39d78c295e8a9d4952229ab6c006d28bcbf2 100644 (file)
@@ -16,7 +16,7 @@ void function(Foo * arg)
 }
 
 // CHECK-scan: [1:1 - 8:1] Invalid Cursor => NoDeclFound
-// CHECK-scan: [8:1 - 8:8] UnexposedDecl=[8:8]
+// CHECK-scan: [8:1 - 8:8] UnexposedDecl=Foo:8:8
 // CHECK-scan: [8:8 - 8:11] ObjCClassRef=Foo:10:12
 // CHECK-scan: [8:11 - 10:1] Invalid Cursor => NoDeclFound
 // CHECK-scan: [10:1 - 11:5] ObjCInterfaceDecl=Foo:10:12
index d3d720c2bafa4728f5edc3adda148cc87d950497..b37f5ff937c333b0ead1f20f98d122a04be1084c 100644 (file)
@@ -13,7 +13,7 @@ void function(Foo * arg)
 }
 
 // CHECK-scan: [1:1 - 8:1] Invalid Cursor => NoDeclFound
-// CHECK-scan: [8:1 - 8:8] UnexposedDecl=[8:8]
+// CHECK-scan: [8:1 - 8:8] UnexposedDecl=Foo:8:8
 // CHECK-scan: [8:8 - 8:11] ObjCClassRef=Foo:8:8
 // CHECK-scan: [8:11 - 10:1] Invalid Cursor => NoDeclFound
 // CHECK-scan: [10:1 - 10:15] FunctionDecl=function:10:6 (Definition)
index 34115d6d54b3afe0210c24d073ae1ca24bc34d46..9eb87be1330d3074fa312f110d652b6b5a1ec977 100644 (file)
@@ -452,8 +452,8 @@ static Rdar8595462_A * Rdar8595462_staticVar;
 // CHECK: Punctuation: ")" [88:24 - 88:25] ObjCProtocolExpr=Proto:85:1
 // CHECK: Punctuation: ";" [88:25 - 88:26] CompoundStmt=
 // CHECK: Punctuation: "}" [89:1 - 89:2] CompoundStmt=
-// CHECK: Punctuation: "@" [93:1 - 93:2] UnexposedDecl=[93:8]
-// CHECK: Keyword: "class" [93:2 - 93:7] UnexposedDecl=[93:8]
+// CHECK: Punctuation: "@" [93:1 - 93:2] UnexposedDecl=Rdar8595462_A:93:8
+// CHECK: Keyword: "class" [93:2 - 93:7] UnexposedDecl=Rdar8595462_A:93:8
 // CHECK: Identifier: "Rdar8595462_A" [93:8 - 93:21] ObjCClassRef=Rdar8595462_A:93:8
 // CHECK: Punctuation: ";" [93:21 - 93:22]
 // CHECK: Punctuation: "@" [94:1 - 94:2] ObjCInterfaceDecl=Rdar8595462_B:94:12
index 2267259d58a290c4095285040dc6059d43102558..3f9d33687a54f84cf9bb861005d2843ced14735d 100644 (file)
@@ -43,6 +43,7 @@ void test2(Sub *s, id<Prot1> p) {
 
 // RUN:  -file-refs-at=%s:7:18 \
 // CHECK:      ObjCImplementationDecl=Foo:7:17 (Definition)
+// CHECK-NEXT: UnexposedDecl=Foo:1:8 =[1:8 - 1:11]
 // CHECK-NEXT: ObjCClassRef=Foo:3:12 =[1:8 - 1:11]
 // CHECK-NEXT: ObjCInterfaceDecl=Foo:3:12 =[3:12 - 3:15]
 // CHECK-NEXT: ObjCImplementationDecl=Foo:7:17 (Definition) =[7:17 - 7:20]
index 7b1e90fcd6fe28cf40c21564056a566831252750..96706d2aeb9fd7fe24bb6dc8fd770ee547664c8f 100644 (file)
@@ -70,7 +70,7 @@
 // CHECK-NOT: properties-class-extensions.m:16:25: ObjCInstanceMethodDecl=bar:16:25 Extent=[16:25 - 16:28]
 // CHECK: properties-class-extensions.m:19:26: ObjCInstanceMethodDecl=setBar::19:26 Extent=[19:26 - 19:29]
 // CHECK: properties-class-extensions.m:19:26: ParmDecl=bar:19:26 (Definition) Extent=[19:26 - 19:29]
-// CHECK: properties-class-extensions.m:24:1: UnexposedDecl=[24:8] Extent=[24:1 - 24:23]
+// CHECK: properties-class-extensions.m:24:8: UnexposedDecl=Rdar8467189_Bar:24:8
 // CHECK: properties-class-extensions.m:24:8: ObjCClassRef=Rdar8467189_Bar:24:8 Extent=[24:8 - 24:23]
 // CHECK: properties-class-extensions.m:25:11: ObjCProtocolDecl=Rdar8467189_FooProtocol:25:11 (Definition) Extent=[25:1 - 27:5]
 // CHECK: properties-class-extensions.m:26:39: ObjCPropertyDecl=Rdar8467189_Bar:26:39 Extent=[26:1 - 26:54]
index 525c5fc0f56ab96e6bfac403c15e1a3d84a4787a..33feadfdf1baa6e64e352312c089ae5609d4f06f 100644 (file)
@@ -297,12 +297,6 @@ void CursorVisitor::visitDeclsFromFileRegion(FileID File,
 
     CurDC = dyn_cast<DeclContext>(D);
 
-    // We handle forward decls via ObjCClassDecl.
-    if (ObjCInterfaceDecl *InterD = dyn_cast<ObjCInterfaceDecl>(D)) {
-      if (!InterD->isThisDeclarationADefinition())
-        continue;
-    }
-
     if (TagDecl *TD = dyn_cast<TagDecl>(D))
       if (!TD->isFreeStanding())
         continue;
@@ -1004,6 +998,11 @@ bool CursorVisitor::VisitObjCPropertyDecl(ObjCPropertyDecl *PD) {
 }
 
 bool CursorVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
+  if (!D->isThisDeclarationADefinition()) {
+    // Forward declaration is treated like a reference.
+    return Visit(MakeCursorObjCClassRef(D, D->getLocation(), TU));
+  }
+
   // Issue callbacks for super class.
   if (D->getSuperClass() &&
       Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(),
@@ -1058,13 +1057,6 @@ bool CursorVisitor::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
   return false;
 }
 
-bool CursorVisitor::VisitObjCClassDecl(ObjCClassDecl *D) {
-  if (Visit(MakeCursorObjCClassRef(D->getForwardInterfaceDecl(), 
-                                   D->getNameLoc(), TU)))
-      return true;
-  return false;
-}
-
 bool CursorVisitor::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PD) {
   if (ObjCIvarDecl *Ivar = PD->getPropertyIvarDecl())
     return Visit(MakeCursorMemberRef(Ivar, PD->getPropertyIvarDeclLoc(), TU));
@@ -3890,8 +3882,6 @@ CXCursor clang_getCursorReferenced(CXCursor C) {
       return clang_getNullCursor();
     if (UsingDecl *Using = dyn_cast<UsingDecl>(D))
       return MakeCursorOverloadedDeclRef(Using, D->getLocation(), tu);
-    if (ObjCClassDecl *Classes = dyn_cast<ObjCClassDecl>(D))
-      return MakeCursorOverloadedDeclRef(Classes, D->getLocation(), tu);
     if (ObjCForwardProtocolDecl *Protocols
                                         = dyn_cast<ObjCForwardProtocolDecl>(D))
       return MakeCursorOverloadedDeclRef(Protocols, D->getLocation(), tu);
@@ -4140,19 +4130,20 @@ CXCursor clang_getCursorDefinition(CXCursor C) {
       return C;
     return clang_getNullCursor();
 
-  case Decl::ObjCInterface:
+  case Decl::ObjCInterface: {
     // There are two notions of a "definition" for an Objective-C
     // class: the interface and its implementation. When we resolved a
     // reference to an Objective-C class, produce the @interface as
     // the definition; when we were provided with the interface,
     // produce the @implementation as the definition.
+    ObjCInterfaceDecl *IFace = cast<ObjCInterfaceDecl>(D);
     if (WasReference) {
-      if (ObjCInterfaceDecl *Def = cast<ObjCInterfaceDecl>(D)->getDefinition())
+      if (ObjCInterfaceDecl *Def = IFace->getDefinition())
         return MakeCXCursor(Def, TU);
-    } else if (ObjCImplementationDecl *Impl
-                              = cast<ObjCInterfaceDecl>(D)->getImplementation())
+    } else if (ObjCImplementationDecl *Impl = IFace->getImplementation())
       return MakeCXCursor(Impl, TU);
     return clang_getNullCursor();
+  }
 
   case Decl::ObjCProperty:
     // FIXME: We don't really know where to find the
@@ -4171,10 +4162,6 @@ CXCursor clang_getCursorDefinition(CXCursor C) {
     return MakeCursorOverloadedDeclRef(cast<ObjCForwardProtocolDecl>(D), 
                                        D->getLocation(), TU);
 
-  case Decl::ObjCClass:
-    return MakeCursorOverloadedDeclRef(cast<ObjCClassDecl>(D), D->getLocation(),
-                                       TU);
-
   case Decl::Friend:
     if (NamedDecl *Friend = cast<FriendDecl>(D)->getFriendDecl())
       return clang_getCursorDefinition(MakeCXCursor(Friend, TU));
@@ -4230,8 +4217,6 @@ unsigned clang_getNumOverloadedDecls(CXCursor C) {
   Decl *D = Storage.get<Decl*>();
   if (UsingDecl *Using = dyn_cast<UsingDecl>(D))
     return Using->shadow_size();
-  if (isa<ObjCClassDecl>(D))
-    return 1;
   if (ObjCForwardProtocolDecl *Protocols =dyn_cast<ObjCForwardProtocolDecl>(D))
     return Protocols->protocol_size();
   
@@ -4261,8 +4246,6 @@ CXCursor clang_getOverloadedDecl(CXCursor cursor, unsigned index) {
     std::advance(Pos, index);
     return MakeCXCursor(cast<UsingShadowDecl>(*Pos)->getTargetDecl(), TU);
   }
-  if (ObjCClassDecl *Classes = dyn_cast<ObjCClassDecl>(D))
-    return MakeCXCursor(Classes->getForwardInterfaceDecl(), TU);
   if (ObjCForwardProtocolDecl *Protocols = dyn_cast<ObjCForwardProtocolDecl>(D))
     return MakeCXCursor(Protocols->protocol_begin()[index], TU);
   
@@ -5191,7 +5174,6 @@ static CXLanguageKind getDeclLanguage(const Decl *D) {
     case Decl::ObjCAtDefsField:
     case Decl::ObjCCategory:
     case Decl::ObjCCategoryImpl:
-    case Decl::ObjCClass:
     case Decl::ObjCCompatibleAlias:
     case Decl::ObjCForwardProtocol:
     case Decl::ObjCImplementation:
index 40d4fb1c694642b2fa9d3283d07d58ffc91874fc..1b57ef23ad4bf9cfdaa65e210fcc6cba1e8ecc19 100644 (file)
@@ -75,7 +75,6 @@ public:
   void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
   void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
   void VisitClassTemplateDecl(ClassTemplateDecl *D);
-  void VisitObjCClassDecl(ObjCClassDecl *CD);
   void VisitObjCContainerDecl(ObjCContainerDecl *CD);
   void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *P);
   void VisitObjCMethodDecl(ObjCMethodDecl *MD);
@@ -310,12 +309,6 @@ void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) {
   N.printName(Out);
 }
 
-void USRGenerator::VisitObjCClassDecl(ObjCClassDecl *D) {
-  // FIXME: @class declarations can refer to multiple classes.  We need
-  //  to be able to traverse these.
-  IgnoreResults = true;
-}
-
 void USRGenerator::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
   // FIXME: @protocol declarations can refer to multiple protocols.  We need
   //  to be able to traverse these.
index ec0865515471c620b6686f7ca291f47e386e38d3..184d36f180a3252076bd85c3bc9becdc105508b3 100644 (file)
@@ -216,7 +216,6 @@ public:
   bool VisitObjCImplementationDecl(ObjCImplementationDecl *D);
   // FIXME: ObjCCompatibleAliasDecl requires aliased-class locations.
   bool VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
-  bool VisitObjCClassDecl(ObjCClassDecl *D);
   bool VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PD);
   bool VisitLinkageSpecDecl(LinkageSpecDecl *D);
   bool VisitNamespaceDecl(NamespaceDecl *D);
index 96a21d8486480968eab93df825496a14c83d2f46..38868138cf2302a9484bf4cc4e052e328c6ccc4f 100644 (file)
@@ -77,11 +77,6 @@ public:
     return true;
   }
 
-  bool VisitObjCClassDecl(ObjCClassDecl *D) {
-    IndexCtx.handleObjCClass(D);
-    return true;
-  }
-
   bool VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
     ObjCForwardProtocolDecl::protocol_loc_iterator LI = D->protocol_loc_begin();
     for (ObjCForwardProtocolDecl::protocol_iterator
@@ -96,14 +91,12 @@ public:
   }
 
   bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
-    // Forward decls are handled at VisitObjCClassDecl.
-    if (!D->isThisDeclarationADefinition())
-      return true;
-
     IndexCtx.handleObjCInterface(D);
 
-    IndexCtx.indexTUDeclsInObjCContainer();
-    IndexCtx.indexDeclContext(D);
+    if (D->isThisDeclarationADefinition()) {
+      IndexCtx.indexTUDeclsInObjCContainer();
+      IndexCtx.indexDeclContext(D);
+    }
     return true;
   }
 
index 11b2ed3c352aeba653ae646ff6784610240bb118..49dfa05cf1cc575adf607aa72a7ba876ecb9f84d 100644 (file)
@@ -335,24 +335,22 @@ bool IndexingContext::handleTypedefName(const TypedefNameDecl *D) {
   return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
 }
 
-bool IndexingContext::handleObjCClass(const ObjCClassDecl *D) {
-  ObjCInterfaceDecl *IFaceD = D->getForwardInterfaceDecl();
-  SourceLocation Loc = D->getNameLoc();
-  bool isRedeclaration = IFaceD->getLocation() != Loc;
+bool IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) {
   // For @class forward declarations, suppress them the same way as references.
-  if (suppressRefs()) {
-    if (markEntityOccurrenceInFile(IFaceD, Loc))
+  if (!D->isThisDeclarationADefinition()) {
+    if (suppressRefs() && markEntityOccurrenceInFile(D, D->getLocation()))
       return false; // already occurred.
-  }
 
-  ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration,
-                                  /*isImplementation=*/false);
-  return handleObjCContainer(IFaceD, Loc,
-                          MakeCursorObjCClassRef(IFaceD, Loc, CXTU), ContDInfo);
-}
+    // FIXME: This seems like the wrong definition for redeclaration.
+    bool isRedeclaration = D->hasDefinition() || D->getPreviousDeclaration();
+    ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration,
+                                    /*isImplementation=*/false);
+    return handleObjCContainer(D, D->getLocation(),
+                               MakeCursorObjCClassRef(D, D->getLocation(),
+                                                      CXTU), 
+                               ContDInfo);
+  }
 
-bool IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) {
   ScratchAlloc SA(*this);
 
   CXIdxBaseClassInfo BaseClass;
@@ -370,8 +368,8 @@ bool IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) {
   }
   
   ObjCProtocolList EmptyProtoList;
-  ObjCProtocolListInfo ProtInfo(D->hasDefinition()? D->getReferencedProtocols()
-                                                  : EmptyProtoList, 
+  ObjCProtocolListInfo ProtInfo(D->hasDefinition() ? D->getReferencedProtocols()
+                                                   : EmptyProtoList, 
                                 *this, SA);
   
   ObjCInterfaceDeclInfo InterInfo(D);
index 206e322337a2034095024631976f593935906ac0..90801d9694f5797c6d09774e96b55ad493d706c2 100644 (file)
@@ -17,7 +17,6 @@
 namespace clang {
   class FileEntry;
   class ObjCPropertyDecl;
-  class ObjCClassDecl;
   class ClassTemplateDecl;
   class FunctionTemplateDecl;
   class TypeAliasTemplateDecl;
@@ -370,7 +369,6 @@ public:
   
   bool handleTypedefName(const TypedefNameDecl *D);
 
-  bool handleObjCClass(const ObjCClassDecl *D);
   bool handleObjCInterface(const ObjCInterfaceDecl *D);
   bool handleObjCImplementation(const ObjCImplementationDecl *D);