minor cleanup to the actions interface to pass around SmallVectorImpl instead

of a specific smallvector size.

Fix protocol lists to pass down proper location info, so we get diagnostics
like this:

t.m:3:35: error: cannot find protocol definition for 'NSCopying', referenced by 'NSWhatever'
@interface NSWhatever : NSObject <NSCopying>
                                  ^

instead of this:

t.m:3:44: error: cannot find protocol definition for 'NSCopying', referenced by 'NSWhatever'
@interface NSWhatever : NSObject <NSCopying>
                                           ^


Add a new IdentifierLocPair typedef which is just a pair<IdentifierInfo*, SourceLocation>

llvm-svn: 53883
This commit is contained in:
Chris Lattner 2008-07-21 22:17:28 +00:00
parent 5224e6a81d
commit d7352d6801
9 changed files with 101 additions and 81 deletions

View File

@ -29,6 +29,12 @@ namespace llvm {
namespace clang { namespace clang {
struct LangOptions; struct LangOptions;
class MultiKeywordSelector; // a private class used by Selector. class MultiKeywordSelector; // a private class used by Selector.
class IdentifierInfo;
class SourceLocation;
/// IdentifierLocPair - A simple pair of identifier info and location.
typedef std::pair<IdentifierInfo*, SourceLocation> IdentifierLocPair;
/// IdentifierInfo - One of these records is kept for each identifier that /// IdentifierInfo - One of these records is kept for each identifier that
/// is lexed. This contains information about whether the token was #define'd, /// is lexed. This contains information about whether the token was #define'd,

View File

@ -207,7 +207,7 @@ public:
/// name of the referenced class. /// name of the referenced class.
virtual void ActOnDefs(Scope *S, SourceLocation DeclStart, virtual void ActOnDefs(Scope *S, SourceLocation DeclStart,
IdentifierInfo *ClassName, IdentifierInfo *ClassName,
llvm::SmallVector<DeclTy*, 16> &Decls) {} llvm::SmallVectorImpl<DeclTy*> &Decls) {}
virtual DeclTy *ActOnField(Scope *S, SourceLocation DeclStart, virtual DeclTy *ActOnField(Scope *S, SourceLocation DeclStart,
Declarator &D, ExprTy *BitfieldWidth) { Declarator &D, ExprTy *BitfieldWidth) {
return 0; return 0;
@ -627,7 +627,7 @@ public:
SourceLocation ClassLoc, SourceLocation ClassLoc,
IdentifierInfo *SuperName, IdentifierInfo *SuperName,
SourceLocation SuperLoc, SourceLocation SuperLoc,
IdentifierInfo **ProtocolNames, const IdentifierLocPair *ProtocolNames,
unsigned NumProtocols, unsigned NumProtocols,
SourceLocation EndProtoLoc, SourceLocation EndProtoLoc,
AttributeList *AttrList) { AttributeList *AttrList) {
@ -649,7 +649,7 @@ public:
SourceLocation AtProtoInterfaceLoc, SourceLocation AtProtoInterfaceLoc,
IdentifierInfo *ProtocolName, IdentifierInfo *ProtocolName,
SourceLocation ProtocolLoc, SourceLocation ProtocolLoc,
IdentifierInfo **ProtoRefNames, const IdentifierLocPair *ProtoRefNames,
unsigned NumProtoRefs, unsigned NumProtoRefs,
SourceLocation EndProtoLoc) { SourceLocation EndProtoLoc) {
return 0; return 0;
@ -662,7 +662,7 @@ public:
SourceLocation ClassLoc, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, IdentifierInfo *CategoryName,
SourceLocation CategoryLoc, SourceLocation CategoryLoc,
IdentifierInfo **ProtoRefNames, const IdentifierLocPair *ProtoRefNames,
unsigned NumProtoRefs, unsigned NumProtoRefs,
SourceLocation EndProtoLoc) { SourceLocation EndProtoLoc) {
return 0; return 0;
@ -768,7 +768,7 @@ public:
} }
virtual DeclTy *ActOnForwardProtocolDeclaration( virtual DeclTy *ActOnForwardProtocolDeclaration(
SourceLocation AtProtocolLoc, SourceLocation AtProtocolLoc,
IdentifierInfo **IdentList, const IdentifierLocPair*IdentList,
unsigned NumElts) { unsigned NumElts) {
return 0; return 0;
} }
@ -777,10 +777,9 @@ public:
/// issues error if they are not declared. It returns list of valid /// issues error if they are not declared. It returns list of valid
/// protocols found. /// protocols found.
virtual void FindProtocolDeclaration(SourceLocation TypeLoc, virtual void FindProtocolDeclaration(SourceLocation TypeLoc,
IdentifierInfo **ProtocolId, const IdentifierLocPair *ProtocolId,
unsigned NumProtocols, unsigned NumProtocols,
llvm::SmallVector<DeclTy *, 8> & llvm::SmallVectorImpl<DeclTy*> &Protocols) {
Protocols) {
} }
//===----------------------- Obj-C Expressions --------------------------===// //===----------------------- Obj-C Expressions --------------------------===//
@ -852,7 +851,8 @@ public:
virtual DeclTy *ActOnStartClassInterface(SourceLocation interLoc, virtual DeclTy *ActOnStartClassInterface(SourceLocation interLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *SuperName, SourceLocation SuperLoc, IdentifierInfo *SuperName, SourceLocation SuperLoc,
IdentifierInfo **ProtocolNames, unsigned NumProtocols, const IdentifierLocPair *ProtocolNames,
unsigned NumProtocols,
SourceLocation EndProtoLoc, AttributeList *AttrList); SourceLocation EndProtoLoc, AttributeList *AttrList);
}; };

View File

@ -325,7 +325,7 @@ private:
AttributeList *prefixAttrs = 0); AttributeList *prefixAttrs = 0);
void ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, void ParseObjCClassInstanceVariables(DeclTy *interfaceDecl,
SourceLocation atLoc); SourceLocation atLoc);
bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<IdentifierInfo*> &, bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<IdentifierLocPair> &,
SourceLocation &endProtoLoc); SourceLocation &endProtoLoc);
void ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, void ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
tok::ObjCKeywordKind contextKey); tok::ObjCKeywordKind contextKey);

View File

@ -91,7 +91,8 @@ Action::DeclTy *
MinimalAction::ActOnStartClassInterface(SourceLocation AtInterfaceLoc, MinimalAction::ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *SuperName, SourceLocation SuperLoc, IdentifierInfo *SuperName, SourceLocation SuperLoc,
IdentifierInfo **ProtocolNames, unsigned NumProtocols, const IdentifierLocPair *ProtocolNames,
unsigned NumProtocols,
SourceLocation EndProtoLoc, AttributeList *AttrList) { SourceLocation EndProtoLoc, AttributeList *AttrList) {
TypeNameInfo *TI = TypeNameInfo *TI =
new TypeNameInfo(1, ClassName->getFETokenInfo<TypeNameInfo>()); new TypeNameInfo(1, ClassName->getFETokenInfo<TypeNameInfo>());

View File

@ -413,8 +413,11 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
ConsumeToken(); // The identifier ConsumeToken(); // The identifier
if (Tok.is(tok::less)) { if (Tok.is(tok::less)) {
SourceLocation endProtoLoc; SourceLocation endProtoLoc;
llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc); ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc);
// FIXME: New'ing this here seems wrong, why not have the action do
// it?
llvm::SmallVector<DeclTy *, 8> *ProtocolDecl = llvm::SmallVector<DeclTy *, 8> *ProtocolDecl =
new llvm::SmallVector<DeclTy *, 8>; new llvm::SmallVector<DeclTy *, 8>;
DS.setProtocolQualifiers(ProtocolDecl); DS.setProtocolQualifiers(ProtocolDecl);
@ -553,7 +556,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
case tok::less: case tok::less:
if (!DS.hasTypeSpecifier()) { if (!DS.hasTypeSpecifier()) {
SourceLocation endProtoLoc; SourceLocation endProtoLoc;
llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc); ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc);
llvm::SmallVector<DeclTy *, 8> *ProtocolDecl = llvm::SmallVector<DeclTy *, 8> *ProtocolDecl =
new llvm::SmallVector<DeclTy *, 8>; new llvm::SmallVector<DeclTy *, 8>;

View File

@ -131,7 +131,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
SourceLocation lparenLoc = ConsumeParen(); SourceLocation lparenLoc = ConsumeParen();
SourceLocation categoryLoc, rparenLoc; SourceLocation categoryLoc, rparenLoc;
IdentifierInfo *categoryId = 0; IdentifierInfo *categoryId = 0;
llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
// For ObjC2, the category name is optional (not an error). // For ObjC2, the category name is optional (not an error).
if (Tok.is(tok::identifier)) { if (Tok.is(tok::identifier)) {
@ -185,7 +185,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
superClassLoc = ConsumeToken(); superClassLoc = ConsumeToken();
} }
// Next, we need to check for any protocol references. // Next, we need to check for any protocol references.
llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
SourceLocation endProtoLoc; SourceLocation endProtoLoc;
if (Tok.is(tok::less)) { if (Tok.is(tok::less)) {
if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc)) if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
@ -337,7 +337,7 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
/// copy /// copy
/// nonatomic /// nonatomic
/// ///
void Parser::ParseObjCPropertyAttribute (ObjCDeclSpec &DS) { void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) {
SourceLocation loc = ConsumeParen(); // consume '(' SourceLocation loc = ConsumeParen(); // consume '('
while (isObjCPropertyAttribute()) { while (isObjCPropertyAttribute()) {
const IdentifierInfo *II = Tok.getIdentifierInfo(); const IdentifierInfo *II = Tok.getIdentifierInfo();
@ -715,8 +715,9 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
/// objc-protocol-refs: /// objc-protocol-refs:
/// '<' identifier-list '>' /// '<' identifier-list '>'
/// ///
bool Parser::ParseObjCProtocolReferences( bool Parser::
llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs, SourceLocation &endLoc){ ParseObjCProtocolReferences(llvm::SmallVectorImpl<IdentifierLocPair> &Protocols,
SourceLocation &endLoc) {
assert(Tok.is(tok::less) && "expected <"); assert(Tok.is(tok::less) && "expected <");
ConsumeToken(); // the "<" ConsumeToken(); // the "<"
@ -727,7 +728,8 @@ bool Parser::ParseObjCProtocolReferences(
SkipUntil(tok::greater); SkipUntil(tok::greater);
return true; return true;
} }
ProtocolRefs.push_back(Tok.getIdentifierInfo()); Protocols.push_back(std::make_pair(Tok.getIdentifierInfo(),
Tok.getLocation()));
ConsumeToken(); ConsumeToken();
if (Tok.isNot(tok::comma)) if (Tok.isNot(tok::comma))
@ -865,15 +867,17 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {
IdentifierInfo *protocolName = Tok.getIdentifierInfo(); IdentifierInfo *protocolName = Tok.getIdentifierInfo();
SourceLocation nameLoc = ConsumeToken(); SourceLocation nameLoc = ConsumeToken();
llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
if (Tok.is(tok::semi)) { // forward declaration of one protocol. if (Tok.is(tok::semi)) { // forward declaration of one protocol.
IdentifierLocPair ProtoInfo(protocolName, nameLoc);
ConsumeToken(); ConsumeToken();
ProtocolRefs.push_back(protocolName); return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1);
} }
if (Tok.is(tok::comma)) { // list of forward declarations. if (Tok.is(tok::comma)) { // list of forward declarations.
llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc));
// Parse the list of forward declarations. // Parse the list of forward declarations.
ProtocolRefs.push_back(protocolName);
while (1) { while (1) {
ConsumeToken(); // the ',' ConsumeToken(); // the ','
if (Tok.isNot(tok::identifier)) { if (Tok.isNot(tok::identifier)) {
@ -881,7 +885,8 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {
SkipUntil(tok::semi); SkipUntil(tok::semi);
return 0; return 0;
} }
ProtocolRefs.push_back(Tok.getIdentifierInfo()); ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(),
Tok.getLocation()));
ConsumeToken(); // the identifier ConsumeToken(); // the identifier
if (Tok.isNot(tok::comma)) if (Tok.isNot(tok::comma))
@ -890,17 +895,19 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {
// Consume the ';'. // Consume the ';'.
if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
return 0; return 0;
}
if (!ProtocolRefs.empty())
return Actions.ActOnForwardProtocolDeclaration(AtLoc, return Actions.ActOnForwardProtocolDeclaration(AtLoc,
&ProtocolRefs[0], &ProtocolRefs[0],
ProtocolRefs.size()); ProtocolRefs.size());
}
// Last, and definitely not least, parse a protocol declaration. // Last, and definitely not least, parse a protocol declaration.
SourceLocation endProtoLoc; SourceLocation endProtoLoc;
if (Tok.is(tok::less)) { llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
return 0; if (Tok.is(tok::less) &&
} ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
return 0;
DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc, DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc,
protocolName, nameLoc, protocolName, nameLoc,

View File

@ -241,7 +241,7 @@ private:
SourceLocation KWLoc, IdentifierInfo *Name, SourceLocation KWLoc, IdentifierInfo *Name,
SourceLocation NameLoc, AttributeList *Attr); SourceLocation NameLoc, AttributeList *Attr);
virtual void ActOnDefs(Scope *S, SourceLocation DeclStart, IdentifierInfo virtual void ActOnDefs(Scope *S, SourceLocation DeclStart, IdentifierInfo
*ClassName, llvm::SmallVector<DeclTy*, 16> &Decls); *ClassName, llvm::SmallVectorImpl<DeclTy*> &Decls);
virtual DeclTy *ActOnField(Scope *S, SourceLocation DeclStart, virtual DeclTy *ActOnField(Scope *S, SourceLocation DeclStart,
Declarator &D, ExprTy *BitfieldWidth); Declarator &D, ExprTy *BitfieldWidth);
@ -615,7 +615,8 @@ public:
SourceLocation AtInterafceLoc, SourceLocation AtInterafceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *SuperName, SourceLocation SuperLoc, IdentifierInfo *SuperName, SourceLocation SuperLoc,
IdentifierInfo **ProtocolNames, unsigned NumProtocols, const IdentifierLocPair *ProtocolNames,
unsigned NumProtocols,
SourceLocation EndProtoLoc, AttributeList *AttrList); SourceLocation EndProtoLoc, AttributeList *AttrList);
virtual DeclTy *ActOnCompatiblityAlias( virtual DeclTy *ActOnCompatiblityAlias(
@ -626,14 +627,16 @@ public:
virtual DeclTy *ActOnStartProtocolInterface( virtual DeclTy *ActOnStartProtocolInterface(
SourceLocation AtProtoInterfaceLoc, SourceLocation AtProtoInterfaceLoc,
IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs, const IdentifierLocPair *ProtoRefNames,
unsigned NumProtoRefs,
SourceLocation EndProtoLoc); SourceLocation EndProtoLoc);
virtual DeclTy *ActOnStartCategoryInterface( virtual DeclTy *ActOnStartCategoryInterface(
SourceLocation AtInterfaceLoc, SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc, IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs, const IdentifierLocPair *ProtoRefNames,
unsigned NumProtoRefs,
SourceLocation EndProtoLoc); SourceLocation EndProtoLoc);
virtual DeclTy *ActOnStartClassImplementation( virtual DeclTy *ActOnStartClassImplementation(
@ -654,14 +657,13 @@ public:
unsigned NumElts); unsigned NumElts);
virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
IdentifierInfo **IdentList, const IdentifierLocPair *IdentList,
unsigned NumElts); unsigned NumElts);
virtual void FindProtocolDeclaration(SourceLocation TypeLoc, virtual void FindProtocolDeclaration(SourceLocation TypeLoc,
IdentifierInfo **ProtocolId, const IdentifierLocPair *ProtocolId,
unsigned NumProtocols, unsigned NumProtocols,
llvm::SmallVector<DeclTy *, 8> & llvm::SmallVectorImpl<DeclTy *> &Protocols);
Protocols);
void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
ObjCPropertyDecl *SuperProperty, ObjCPropertyDecl *SuperProperty,

View File

@ -1789,7 +1789,7 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK,
/// Collect the instance variables declared in an Objective-C object. Used in /// Collect the instance variables declared in an Objective-C object. Used in
/// the creation of structures from objects using the @defs directive. /// the creation of structures from objects using the @defs directive.
static void CollectIvars(ObjCInterfaceDecl *Class, static void CollectIvars(ObjCInterfaceDecl *Class,
llvm::SmallVector<Sema::DeclTy*, 16> &ivars) { llvm::SmallVectorImpl<Sema::DeclTy*> &ivars) {
if (Class->getSuperClass()) if (Class->getSuperClass())
CollectIvars(Class->getSuperClass(), ivars); CollectIvars(Class->getSuperClass(), ivars);
ivars.append(Class->ivar_begin(), Class->ivar_end()); ivars.append(Class->ivar_begin(), Class->ivar_end());
@ -1799,7 +1799,7 @@ static void CollectIvars(ObjCInterfaceDecl *Class,
/// instance variables of ClassName into Decls. /// instance variables of ClassName into Decls.
void Sema::ActOnDefs(Scope *S, SourceLocation DeclStart, void Sema::ActOnDefs(Scope *S, SourceLocation DeclStart,
IdentifierInfo *ClassName, IdentifierInfo *ClassName,
llvm::SmallVector<DeclTy*, 16> &Decls) { llvm::SmallVectorImpl<DeclTy*> &Decls) {
// Check that ClassName is a valid class // Check that ClassName is a valid class
ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName); ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName);
if (!Class) { if (!Class) {

View File

@ -68,12 +68,13 @@ void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
} }
} }
Sema::DeclTy *Sema::ActOnStartClassInterface( Sema::DeclTy *Sema::
SourceLocation AtInterfaceLoc, ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *SuperName, SourceLocation SuperLoc, IdentifierInfo *SuperName, SourceLocation SuperLoc,
IdentifierInfo **ProtocolNames, unsigned NumProtocols, const IdentifierLocPair *ProtocolNames,
SourceLocation EndProtoLoc, AttributeList *AttrList) { unsigned NumProtocols,
SourceLocation EndProtoLoc, AttributeList *AttrList) {
assert(ClassName && "Missing class identifier"); assert(ClassName && "Missing class identifier");
// Check for another declaration kind with the same name. // Check for another declaration kind with the same name.
@ -133,14 +134,14 @@ Sema::DeclTy *Sema::ActOnStartClassInterface(
if (NumProtocols) { if (NumProtocols) {
llvm::SmallVector<ObjCProtocolDecl*, 8> RefProtos; llvm::SmallVector<ObjCProtocolDecl*, 8> RefProtos;
for (unsigned int i = 0; i != NumProtocols; i++) { for (unsigned int i = 0; i != NumProtocols; i++) {
ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtocolNames[i]]; ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtocolNames[i].first];
if (!RefPDecl) if (!RefPDecl)
Diag(EndProtoLoc, diag::err_undef_protocolref, Diag(ProtocolNames[i].second, diag::err_undef_protocolref,
ProtocolNames[i]->getName(), ClassName->getName()); ProtocolNames[i].first->getName(), ClassName->getName());
else { else {
if (RefPDecl->isForwardDecl()) if (RefPDecl->isForwardDecl())
Diag(EndProtoLoc, diag::warn_undef_protocolref, Diag(ProtocolNames[i].second, diag::warn_undef_protocolref,
ProtocolNames[i]->getName(), ClassName->getName()); ProtocolNames[i].first->getName(), ClassName->getName());
RefProtos.push_back(RefPDecl); RefProtos.push_back(RefPDecl);
} }
} }
@ -194,7 +195,7 @@ Sema::DeclTy *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc,
Sema::DeclTy *Sema::ActOnStartProtocolInterface( Sema::DeclTy *Sema::ActOnStartProtocolInterface(
SourceLocation AtProtoInterfaceLoc, SourceLocation AtProtoInterfaceLoc,
IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs, const IdentifierLocPair *ProtoRefNames, unsigned NumProtoRefs,
SourceLocation EndProtoLoc) { SourceLocation EndProtoLoc) {
assert(ProtocolName && "Missing protocol identifier"); assert(ProtocolName && "Missing protocol identifier");
ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName]; ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName];
@ -219,14 +220,14 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface(
/// Check then save referenced protocols. /// Check then save referenced protocols.
llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
for (unsigned int i = 0; i != NumProtoRefs; i++) { for (unsigned int i = 0; i != NumProtoRefs; i++) {
ObjCProtocolDecl *RefPDecl = ObjCProtocols[ProtoRefNames[i]]; ObjCProtocolDecl *RefPDecl = ObjCProtocols[ProtoRefNames[i].first];
if (!RefPDecl) if (!RefPDecl)
Diag(ProtocolLoc, diag::err_undef_protocolref, Diag(ProtoRefNames[i].second, diag::err_undef_protocolref,
ProtoRefNames[i]->getName(), ProtocolName->getName()); ProtoRefNames[i].first->getName(), ProtocolName->getName());
else { else {
if (RefPDecl->isForwardDecl()) if (RefPDecl->isForwardDecl())
Diag(ProtocolLoc, diag::warn_undef_protocolref, Diag(ProtoRefNames[i].second, diag::warn_undef_protocolref,
ProtoRefNames[i]->getName(), ProtocolName->getName()); ProtoRefNames[i].first->getName(), ProtocolName->getName());
Protocols.push_back(RefPDecl); Protocols.push_back(RefPDecl);
} }
} }
@ -242,16 +243,15 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface(
/// declarations in its 'Protocols' argument. /// declarations in its 'Protocols' argument.
void void
Sema::FindProtocolDeclaration(SourceLocation TypeLoc, Sema::FindProtocolDeclaration(SourceLocation TypeLoc,
IdentifierInfo **ProtocolId, const IdentifierLocPair *ProtocolId,
unsigned NumProtocols, unsigned NumProtocols,
llvm::SmallVector<DeclTy *,8> &Protocols) { llvm::SmallVectorImpl<DeclTy*> &Protocols) {
for (unsigned i = 0; i != NumProtocols; ++i) { for (unsigned i = 0; i != NumProtocols; ++i) {
ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i]]; if (ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i].first])
if (!PDecl)
Diag(TypeLoc, diag::err_undeclared_protocol,
ProtocolId[i]->getName());
else
Protocols.push_back(PDecl); Protocols.push_back(PDecl);
else
Diag(ProtocolId[i].second, diag::err_undeclared_protocol,
ProtocolId[i].first->getName());
} }
} }
@ -382,16 +382,15 @@ Sema::MergeProtocolPropertiesIntoClass(ObjCInterfaceDecl *IDecl,
/// ActOnForwardProtocolDeclaration - /// ActOnForwardProtocolDeclaration -
Action::DeclTy * Action::DeclTy *
Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
IdentifierInfo **IdentList, unsigned NumElts) { const IdentifierLocPair *IdentList,
unsigned NumElts) {
llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols; llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols;
for (unsigned i = 0; i != NumElts; ++i) { for (unsigned i = 0; i != NumElts; ++i) {
IdentifierInfo *Ident = IdentList[i]; IdentifierInfo *Ident = IdentList[i].first;
ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident]; ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident];
if (PDecl == 0) { // Not already seen? if (PDecl == 0) // Not already seen?
// FIXME: Pass in the location of the identifier! PDecl = ObjCProtocolDecl::Create(Context, IdentList[i].second, Ident);
PDecl = ObjCProtocolDecl::Create(Context, AtProtocolLoc, Ident);
}
Protocols.push_back(PDecl); Protocols.push_back(PDecl);
} }
@ -399,12 +398,14 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
&Protocols[0], Protocols.size()); &Protocols[0], Protocols.size());
} }
Sema::DeclTy *Sema::ActOnStartCategoryInterface( Sema::DeclTy *Sema::
SourceLocation AtInterfaceLoc, ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc, IdentifierInfo *CategoryName,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs, SourceLocation CategoryLoc,
SourceLocation EndProtoLoc) { const IdentifierLocPair *ProtoRefNames,
unsigned NumProtoRefs,
SourceLocation EndProtoLoc) {
ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName); ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName);
ObjCCategoryDecl *CDecl = ObjCCategoryDecl *CDecl =
@ -433,14 +434,14 @@ Sema::DeclTy *Sema::ActOnStartCategoryInterface(
llvm::SmallVector<ObjCProtocolDecl*, 32> RefProtocols; llvm::SmallVector<ObjCProtocolDecl*, 32> RefProtocols;
/// Check and then save the referenced protocols. /// Check and then save the referenced protocols.
for (unsigned int i = 0; i != NumProtoRefs; i++) { for (unsigned int i = 0; i != NumProtoRefs; i++) {
ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtoRefNames[i]]; ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtoRefNames[i].first];
if (!RefPDecl) if (!RefPDecl)
Diag(CategoryLoc, diag::err_undef_protocolref, Diag(ProtoRefNames[i].second, diag::err_undef_protocolref,
ProtoRefNames[i]->getName(), CategoryName->getName()); ProtoRefNames[i].first->getName(), CategoryName->getName());
else { else {
if (RefPDecl->isForwardDecl()) if (RefPDecl->isForwardDecl())
Diag(CategoryLoc, diag::warn_undef_protocolref, Diag(ProtoRefNames[i].second, diag::warn_undef_protocolref,
ProtoRefNames[i]->getName(), CategoryName->getName()); ProtoRefNames[i].first->getName(), CategoryName->getName());
RefProtocols.push_back(RefPDecl); RefProtocols.push_back(RefPDecl);
} }
} }