[cfe-commits] r54092 - in /cfe/trunk: include/clang/Parse/Action.h include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp
Chris Lattner
sabre at nondot.org
Fri Jul 25 21:03:38 PDT 2008
Author: lattner
Date: Fri Jul 25 23:03:38 2008
New Revision: 54092
URL: http://llvm.org/viewvc/llvm-project?rev=54092&view=rev
Log:
pull protocol resolution out into ActOnStartProtocolInterface.
This temporarily duplicates ParseObjCProtocolReferences, but it
will be removed in the future.
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=54092&r1=54091&r2=54092&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Jul 25 23:03:38 2008
@@ -645,13 +645,12 @@
// ActOnStartProtocolInterface - this action is called immdiately after
// parsing the prologue for a protocol interface.
- virtual DeclTy *ActOnStartProtocolInterface(
- SourceLocation AtProtoInterfaceLoc,
- IdentifierInfo *ProtocolName,
- SourceLocation ProtocolLoc,
- const IdentifierLocPair *ProtoRefNames,
- unsigned NumProtoRefs,
- SourceLocation EndProtoLoc) {
+ virtual DeclTy *ActOnStartProtocolInterface(SourceLocation AtProtoLoc,
+ IdentifierInfo *ProtocolName,
+ SourceLocation ProtocolLoc,
+ DeclTy * const *ProtoRefNames,
+ unsigned NumProtoRefs,
+ SourceLocation EndProtoLoc) {
return 0;
}
// ActOnStartCategoryInterface - this action is called immdiately after
@@ -776,8 +775,7 @@
/// FindProtocolDeclaration - This routine looks up protocols and
/// issues error if they are not declared. It returns list of valid
/// protocols found.
- virtual void FindProtocolDeclaration(SourceLocation TypeLoc,
- bool WarnOnDeclarations,
+ virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
const IdentifierLocPair *ProtocolId,
unsigned NumProtocols,
llvm::SmallVectorImpl<DeclTy*> &ResProtos) {
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=54092&r1=54091&r2=54092&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri Jul 25 23:03:38 2008
@@ -328,6 +328,9 @@
SourceLocation atLoc);
bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<IdentifierLocPair> &,
SourceLocation &endProtoLoc);
+ bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclTy*> &P,
+ bool WarnOnDeclarations,
+ SourceLocation &EndProtoLoc);
void ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
tok::ObjCKeywordKind contextKey);
DeclTy *ParseObjCAtProtocolDeclaration(SourceLocation atLoc);
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=54092&r1=54091&r2=54092&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Jul 25 23:03:38 2008
@@ -431,13 +431,8 @@
continue;
SourceLocation EndProtoLoc;
- llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
- ParseObjCProtocolReferences(ProtocolRefs, EndProtoLoc);
-
llvm::SmallVector<DeclTy *, 8> ProtocolDecl;
- Actions.FindProtocolDeclaration(Loc, false,
- &ProtocolRefs[0], ProtocolRefs.size(),
- ProtocolDecl);
+ ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc);
DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size());
DS.SetRangeEnd(EndProtoLoc);
@@ -572,12 +567,8 @@
{
SourceLocation EndProtoLoc;
- llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
- ParseObjCProtocolReferences(ProtocolRefs, EndProtoLoc);
llvm::SmallVector<DeclTy *, 8> ProtocolDecl;
- Actions.FindProtocolDeclaration(Loc, false,
- &ProtocolRefs[0], ProtocolRefs.size(),
- ProtocolDecl);
+ ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc);
DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size());
DS.SetRangeEnd(EndProtoLoc);
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=54092&r1=54091&r2=54092&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Fri Jul 25 23:03:38 2008
@@ -746,6 +746,48 @@
return true;
}
+/// objc-protocol-refs:
+/// '<' identifier-list '>'
+///
+bool Parser::
+ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclTy*> &Protocols,
+ bool WarnOnDeclarations, SourceLocation &EndLoc) {
+ assert(Tok.is(tok::less) && "expected <");
+
+ ConsumeToken(); // the "<"
+
+ llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents;
+
+ while (1) {
+ if (Tok.isNot(tok::identifier)) {
+ Diag(Tok, diag::err_expected_ident);
+ SkipUntil(tok::greater);
+ return true;
+ }
+ ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(),
+ Tok.getLocation()));
+ ConsumeToken();
+
+ if (Tok.isNot(tok::comma))
+ break;
+ ConsumeToken();
+ }
+
+ // Consume the '>'.
+ if (Tok.isNot(tok::greater)) {
+ Diag(Tok, diag::err_expected_greater);
+ return true;
+ }
+
+ EndLoc = ConsumeAnyToken();
+
+ // Convert the list of protocols identifiers into a list of protocol decls.
+ Actions.FindProtocolDeclaration(WarnOnDeclarations,
+ &ProtocolIdents[0], ProtocolIdents.size(),
+ Protocols);
+ return false;
+}
+
/// objc-class-instance-variables:
/// '{' objc-instance-variable-decl-list[opt] '}'
///
@@ -899,17 +941,17 @@
}
// Last, and definitely not least, parse a protocol declaration.
- SourceLocation endProtoLoc;
- llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
+ SourceLocation EndProtoLoc;
+ llvm::SmallVector<DeclTy *, 8> ProtocolRefs;
if (Tok.is(tok::less) &&
- ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
+ ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc))
return 0;
- DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc,
- protocolName, nameLoc,
- &ProtocolRefs[0],
- ProtocolRefs.size(), endProtoLoc);
+ DeclTy *ProtoType =
+ Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc,
+ &ProtocolRefs[0], ProtocolRefs.size(),
+ EndProtoLoc);
ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol);
// The @ sign was already consumed by ParseObjCInterfaceDeclList().
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=54092&r1=54091&r2=54092&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Jul 25 23:03:38 2008
@@ -621,8 +621,7 @@
virtual DeclTy *ActOnStartProtocolInterface(
SourceLocation AtProtoInterfaceLoc,
IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
- const IdentifierLocPair *ProtoRefNames,
- unsigned NumProtoRefs,
+ DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
SourceLocation EndProtoLoc);
virtual DeclTy *ActOnStartCategoryInterface(
@@ -654,8 +653,7 @@
const IdentifierLocPair *IdentList,
unsigned NumElts);
- virtual void FindProtocolDeclaration(SourceLocation TypeLoc,
- bool WarnOnDeclarations,
+ virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
const IdentifierLocPair *ProtocolId,
unsigned NumProtocols,
llvm::SmallVectorImpl<DeclTy *> &Protocols);
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=54092&r1=54091&r2=54092&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Jul 25 23:03:38 2008
@@ -195,11 +195,13 @@
return AliasDecl;
}
-Sema::DeclTy *Sema::ActOnStartProtocolInterface(
- SourceLocation AtProtoInterfaceLoc,
- IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
- const IdentifierLocPair *ProtoRefNames, unsigned NumProtoRefs,
- SourceLocation EndProtoLoc) {
+Sema::DeclTy *
+Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
+ IdentifierInfo *ProtocolName,
+ SourceLocation ProtocolLoc,
+ DeclTy * const *ProtoRefs,
+ unsigned NumProtoRefs,
+ SourceLocation EndProtoLoc) {
assert(ProtocolName && "Missing protocol identifier");
ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName];
if (PDecl) {
@@ -221,21 +223,7 @@
if (NumProtoRefs) {
/// Check then save referenced protocols.
- llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
- for (unsigned int i = 0; i != NumProtoRefs; i++) {
- ObjCProtocolDecl *RefPDecl = ObjCProtocols[ProtoRefNames[i].first];
- if (!RefPDecl)
- Diag(ProtoRefNames[i].second, diag::err_undeclared_protocol,
- ProtoRefNames[i].first->getName());
- else {
- if (RefPDecl->isForwardDecl())
- Diag(ProtoRefNames[i].second, diag::warn_undef_protocolref,
- ProtoRefNames[i].first->getName());
- Protocols.push_back(RefPDecl);
- }
- }
- if (!Protocols.empty())
- PDecl->addReferencedProtocols(&Protocols[0], Protocols.size());
+ PDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs);
PDecl->setLocEnd(EndProtoLoc);
}
return PDecl;
@@ -245,7 +233,7 @@
/// issuer error if they are not declared. It returns list of protocol
/// declarations in its 'Protocols' argument.
void
-Sema::FindProtocolDeclaration(SourceLocation TypeLoc, bool WarnOnDeclarations,
+Sema::FindProtocolDeclaration(bool WarnOnDeclarations,
const IdentifierLocPair *ProtocolId,
unsigned NumProtocols,
llvm::SmallVectorImpl<DeclTy*> &Protocols) {
More information about the cfe-commits
mailing list