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:
///
DEF_TRAVERSE_DECL(LinkageSpecDecl, { })
-DEF_TRAVERSE_DECL(ObjCClassDecl, {
- // FIXME: implement this
- })
-
DEF_TRAVERSE_DECL(ObjCForwardProtocolDecl, {
// FIXME: implement this
})
DEFAULT_DISPATCH(Record)
DEFAULT_DISPATCH(Enum)
DEFAULT_DISPATCH(ObjCInterface)
- DEFAULT_DISPATCH(ObjCClass)
DEFAULT_DISPATCH(ObjCMethod)
DEFAULT_DISPATCH(ObjCProtocol)
DEFAULT_DISPATCH(ObjCCategory)
def LinkageSpec : Decl, DeclContext;
def ObjCPropertyImpl : Decl;
def ObjCForwardProtocol : Decl;
-def ObjCClass : Decl;
def FileScopeAsm : Decl;
def AccessSpec : Decl;
def Friend : Decl;
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.
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);
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
case LinkageSpec:
case FileScopeAsm:
case StaticAssert:
- case ObjCClass:
case ObjCPropertyImpl:
case ObjCForwardProtocol:
case Block:
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))
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
//===----------------------------------------------------------------------===//
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);
// Objective-C declarations
//----------------------------------------------------------------------------
-void DeclPrinter::VisitObjCClassDecl(ObjCClassDecl *D) {
- Out << "@class " << *D->getForwardInterfaceDecl();
-}
-
void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
if (OMD->isInstanceMethod())
Out << "- ";
visitDeclContext(D);
}
- // ObjCClassDecl
- void visitObjCClassDeclChildren(ObjCClassDecl *D) {
- visitDeclRef(D->getForwardInterfaceDecl());
- }
-
// ObjCInterfaceDecl
void visitCategoryList(ObjCCategoryDecl *D) {
if (!D) return;
case Decl::AccessSpec:
case Decl::LinkageSpec:
case Decl::ObjCPropertyImpl:
- case Decl::ObjCClass:
case Decl::ObjCForwardProtocol:
case Decl::FileScopeAsm:
case Decl::Friend:
// Objective-C Decls
// Forward declarations, no (immediate) code generation.
- case Decl::ObjCClass:
case Decl::ObjCForwardProtocol:
case Decl::ObjCInterface:
break;
AddTopLevelDeclarationToHash(*P, Hash);
return;
}
-
- if (ObjCClassDecl *Class = dyn_cast<ObjCClassDecl>(D)) {
- AddTopLevelDeclarationToHash(Class->getForwardInterfaceDecl(), Hash);
- return;
- }
}
class TopLevelDeclTrackerConsumer : public ASTConsumer {
// 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;
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,
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;
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.
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
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();
}
RewriteOneForwardClassDecl(ForwardDecl, typedefString);
}
- RewriteForwardClassEpilogue(cast<ObjCClassDecl>(D[0]), typedefString);
+ RewriteForwardClassEpilogue(cast<ObjCInterfaceDecl>(D[0]), typedefString);
}
void RewriteObjC::RewriteMethodDeclaration(ObjCMethodDecl *Method) {
RewriteRecordBody(RD);
break;
}
- case Decl::ObjCClass: {
- llvm_unreachable("RewriteObjC::HandleDeclInMainFile - ObjCClassDecl");
- break;
- }
default:
break;
}
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:
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()
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);
- }
}
}
= 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);
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.
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);
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++];
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;
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);
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);
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());
}
// 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
}
// 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)
// 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
// 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]
// 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]
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;
}
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(),
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));
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);
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
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));
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();
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);
case Decl::ObjCAtDefsField:
case Decl::ObjCCategory:
case Decl::ObjCCategoryImpl:
- case Decl::ObjCClass:
case Decl::ObjCCompatibleAlias:
case Decl::ObjCForwardProtocol:
case Decl::ObjCImplementation:
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);
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.
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);
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
}
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;
}
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;
}
ObjCProtocolList EmptyProtoList;
- ObjCProtocolListInfo ProtInfo(D->hasDefinition()? D->getReferencedProtocols()
- : EmptyProtoList,
+ ObjCProtocolListInfo ProtInfo(D->hasDefinition() ? D->getReferencedProtocols()
+ : EmptyProtoList,
*this, SA);
ObjCInterfaceDeclInfo InterInfo(D);
namespace clang {
class FileEntry;
class ObjCPropertyDecl;
- class ObjCClassDecl;
class ClassTemplateDecl;
class FunctionTemplateDecl;
class TypeAliasTemplateDecl;
bool handleTypedefName(const TypedefNameDecl *D);
- bool handleObjCClass(const ObjCClassDecl *D);
bool handleObjCInterface(const ObjCInterfaceDecl *D);
bool handleObjCImplementation(const ObjCImplementationDecl *D);