void VisitObjCInterfaceType(const ObjCInterfaceType *OIT) {
Outer.add(OIT->getDecl(), Flags);
}
- void VisitObjCObjectType(const ObjCObjectType *OOT) {
- // Make all of the protocols targets since there's no child nodes for
- // protocols. This isn't needed for the base type, which *does* have a
- // child `ObjCInterfaceTypeLoc`. This structure is a hack, but it works
- // well for go-to-definition.
- unsigned NumProtocols = OOT->getNumProtocols();
- for (unsigned I = 0; I < NumProtocols; I++)
- Outer.add(OOT->getProtocol(I), Flags);
- }
};
Visitor(*this, Flags).Visit(T.getTypePtr());
}
Finder.add(TAL->getArgument(), Flags);
else if (const CXXBaseSpecifier *CBS = N.get<CXXBaseSpecifier>())
Finder.add(CBS->getTypeSourceInfo()->getType(), Flags);
+ else if (const ObjCProtocolLoc *PL = N.get<ObjCProtocolLoc>())
+ Finder.add(PL->getProtocol(), Flags);
return Finder.takeDecls();
}
{OMD}});
}
- void visitProtocolList(
- llvm::iterator_range<ObjCProtocolList::iterator> Protocols,
- llvm::iterator_range<const SourceLocation *> Locations) {
- for (const auto &P : llvm::zip(Protocols, Locations)) {
- Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
- std::get<1>(P),
- /*IsDecl=*/false,
- {std::get<0>(P)}});
- }
- }
-
- void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *OID) {
- if (OID->isThisDeclarationADefinition())
- visitProtocolList(OID->protocols(), OID->protocol_locs());
- Base::VisitObjCInterfaceDecl(OID); // Visit the interface's name.
- }
-
void VisitObjCCategoryDecl(const ObjCCategoryDecl *OCD) {
- visitProtocolList(OCD->protocols(), OCD->protocol_locs());
// getLocation is the extended class's location, not the category's.
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
OCD->getLocation(),
/*IsDecl=*/true,
{OCID->getCategoryDecl()}});
}
-
- void VisitObjCProtocolDecl(const ObjCProtocolDecl *OPD) {
- if (OPD->isThisDeclarationADefinition())
- visitProtocolList(OPD->protocols(), OPD->protocol_locs());
- Base::VisitObjCProtocolDecl(OPD); // Visit the protocol's name.
- }
};
Visitor V{Resolver};
/*IsDecl=*/false,
{L.getIFaceDecl()}});
}
-
- void VisitObjCObjectTypeLoc(ObjCObjectTypeLoc L) {
- unsigned NumProtocols = L.getNumProtocols();
- for (unsigned I = 0; I < NumProtocols; I++) {
- Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
- L.getProtocolLoc(I),
- /*IsDecl=*/false,
- {L.getProtocol(I)}});
- }
- }
};
Visitor V{Resolver};
return RecursiveASTVisitor::TraverseNestedNameSpecifierLoc(L);
}
+ bool TraverseObjCProtocolLoc(ObjCProtocolLoc ProtocolLoc) {
+ visitNode(DynTypedNode::create(ProtocolLoc));
+ return true;
+ }
+
bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
visitNode(DynTypedNode::create(*Init));
return RecursiveASTVisitor::TraverseConstructorInitializer(Init);
{CCI->getAnyMember()}}};
}
}
+ if (const ObjCProtocolLoc *PL = N.get<ObjCProtocolLoc>())
+ return {ReferenceLoc{NestedNameSpecifierLoc(),
+ PL->getLocation(),
+ /*IsDecl=*/false,
+ {PL->getProtocol()}}};
+
// We do not have location information for other nodes (QualType, etc)
return {};
}
EXPECT_DECLS("ObjCCategoryImplDecl", "@interface Foo(Ext)");
Code = R"cpp(
- @protocol Foo
- @end
- void test([[id<Foo>]] p);
+ void test(id</*error-ok*/[[InvalidProtocol]]> p);
)cpp";
- EXPECT_DECLS("ObjCObjectTypeLoc", "@protocol Foo");
+ EXPECT_DECLS("ParmVarDecl", "id p");
Code = R"cpp(
@class C;
@end
void test(C<[[Foo]]> *p);
)cpp";
- EXPECT_DECLS("ObjCObjectTypeLoc", "@protocol Foo");
+ EXPECT_DECLS("ObjCProtocolLoc", "@protocol Foo");
Code = R"cpp(
@class C;
@end
void test(C<[[Foo]], Bar> *p);
)cpp";
- // FIXME: We currently can't disambiguate between multiple protocols.
- EXPECT_DECLS("ObjCObjectTypeLoc", "@protocol Foo", "@protocol Bar");
+ EXPECT_DECLS("ObjCProtocolLoc", "@protocol Foo");
+
+ Code = R"cpp(
+ @class C;
+ @protocol Foo
+ @end
+ @protocol Bar
+ @end
+ void test(C<Foo, [[Bar]]> *p);
+ )cpp";
+ EXPECT_DECLS("ObjCProtocolLoc", "@protocol Bar");
Code = R"cpp(
@interface Foo