Keep track of all declarations of an Objective-C class (both forward
declarations and definitions) as ObjCInterfaceDecls within the same
redeclaration chain. This new representation matches what we do for
C/C++ variables/functions/classes/templates/etc., and makes it
possible to answer the query "where are all of the declarations of
this class?"
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146679 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index f74953f..a5b390a 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -299,12 +299,7 @@
// We handle forward decls via ObjCClassDecl.
if (ObjCInterfaceDecl *InterD = dyn_cast<ObjCInterfaceDecl>(D)) {
- if (InterD->isForwardDecl())
- continue;
- // An interface that started as a forward decl may have changed location
- // because its @interface was parsed.
- if (InterD->isInitiallyForwardDecl() &&
- !SM.isInFileID(SM.getFileLoc(InterD->getLocation()), File))
+ if (!InterD->isThisDeclarationADefinition())
continue;
}
@@ -3948,8 +3943,13 @@
case CXCursor_ObjCProtocolRef: {
return MakeCXCursor(getCursorObjCProtocolRef(C).first, tu);
- case CXCursor_ObjCClassRef:
- return MakeCXCursor(getCursorObjCClassRef(C).first, tu );
+ case CXCursor_ObjCClassRef: {
+ ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
+ if (ObjCInterfaceDecl *Def = Class->getDefinition())
+ return MakeCXCursor(Def, tu);
+
+ return MakeCXCursor(Class, tu);
+ }
case CXCursor_TypeRef:
return MakeCXCursor(getCursorTypeRef(C).first, tu );
@@ -4147,8 +4147,8 @@
// the definition; when we were provided with the interface,
// produce the @implementation as the definition.
if (WasReference) {
- if (!cast<ObjCInterfaceDecl>(D)->isForwardDecl())
- return C;
+ if (ObjCInterfaceDecl *Def = cast<ObjCInterfaceDecl>(D)->getDefinition())
+ return MakeCXCursor(Def, TU);
} else if (ObjCImplementationDecl *Impl
= cast<ObjCInterfaceDecl>(D)->getImplementation())
return MakeCXCursor(Impl, TU);
@@ -4162,8 +4162,8 @@
case Decl::ObjCCompatibleAlias:
if (ObjCInterfaceDecl *Class
= cast<ObjCCompatibleAliasDecl>(D)->getClassInterface())
- if (!Class->isForwardDecl())
- return MakeCXCursor(Class, TU);
+ if (ObjCInterfaceDecl *Def = Class->getDefinition())
+ return MakeCXCursor(Def, TU);
return clang_getNullCursor();