From: Chris Lattner Date: Sat, 26 Jul 2008 03:47:43 +0000 (+0000) Subject: simplify some code. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eacc39212e5960b2680067c006384c2e4804873a;p=clang simplify some code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54091 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 2b0f5aef6e..e5bbdd372a 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -425,7 +425,7 @@ DIAG(err_undef_superclass, ERROR, DIAG(err_duplicate_class_def, ERROR, "duplicate interface declaration for class '%0'") DIAG(warn_undef_protocolref, WARNING, - "cannot find protocol definition for '%0', referenced by '%1'") + "cannot find protocol definition for '%0'") DIAG(err_duplicate_protocol_def, ERROR, "duplicate protocol declaration of '%0'") DIAG(err_undef_interface, ERROR, diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 12f6d3a737..47047b911f 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -777,9 +777,10 @@ public: /// issues error if they are not declared. It returns list of valid /// protocols found. virtual void FindProtocolDeclaration(SourceLocation TypeLoc, + bool WarnOnDeclarations, const IdentifierLocPair *ProtocolId, unsigned NumProtocols, - llvm::SmallVectorImpl &Protocols) { + llvm::SmallVectorImpl &ResProtos) { } //===----------------------- Obj-C Expressions --------------------------===// diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index e7b73cf619..e047d601ef 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -435,7 +435,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { ParseObjCProtocolReferences(ProtocolRefs, EndProtoLoc); llvm::SmallVector ProtocolDecl; - Actions.FindProtocolDeclaration(Loc, + Actions.FindProtocolDeclaration(Loc, false, &ProtocolRefs[0], ProtocolRefs.size(), ProtocolDecl); DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size()); @@ -575,7 +575,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { llvm::SmallVector ProtocolRefs; ParseObjCProtocolReferences(ProtocolRefs, EndProtoLoc); llvm::SmallVector ProtocolDecl; - Actions.FindProtocolDeclaration(Loc, + Actions.FindProtocolDeclaration(Loc, false, &ProtocolRefs[0], ProtocolRefs.size(), ProtocolDecl); DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size()); diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 25120acc7a..3d4552d202 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -655,6 +655,7 @@ public: unsigned NumElts); virtual void FindProtocolDeclaration(SourceLocation TypeLoc, + bool WarnOnDeclarations, const IdentifierLocPair *ProtocolId, unsigned NumProtocols, llvm::SmallVectorImpl &Protocols); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 3615ed30c6..9d2869be8a 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -144,7 +144,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, else { if (RefPDecl->isForwardDecl()) Diag(ProtocolNames[i].second, diag::warn_undef_protocolref, - ProtocolNames[i].first->getName(), ClassName->getName()); + ProtocolNames[i].first->getName()); RefProtos.push_back(RefPDecl); } } @@ -230,7 +230,7 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface( else { if (RefPDecl->isForwardDecl()) Diag(ProtoRefNames[i].second, diag::warn_undef_protocolref, - ProtoRefNames[i].first->getName(), ProtocolName->getName()); + ProtoRefNames[i].first->getName()); Protocols.push_back(RefPDecl); } } @@ -245,16 +245,24 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface( /// issuer error if they are not declared. It returns list of protocol /// declarations in its 'Protocols' argument. void -Sema::FindProtocolDeclaration(SourceLocation TypeLoc, +Sema::FindProtocolDeclaration(SourceLocation TypeLoc, bool WarnOnDeclarations, const IdentifierLocPair *ProtocolId, unsigned NumProtocols, llvm::SmallVectorImpl &Protocols) { for (unsigned i = 0; i != NumProtocols; ++i) { - if (ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i].first]) - Protocols.push_back(PDecl); - else + ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i].first]; + if (!PDecl) { Diag(ProtocolId[i].second, diag::err_undeclared_protocol, ProtocolId[i].first->getName()); + continue; + } + + // If this is a forward declaration and we are supposed to warn in this + // case, do it. + if (WarnOnDeclarations && PDecl->isForwardDecl()) + Diag(ProtocolId[i].second, diag::warn_undef_protocolref, + ProtocolId[i].first->getName()); + Protocols.push_back(PDecl); } } @@ -444,7 +452,7 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, else { if (RefPDecl->isForwardDecl()) Diag(ProtoRefNames[i].second, diag::warn_undef_protocolref, - ProtoRefNames[i].first->getName(), CategoryName->getName()); + ProtoRefNames[i].first->getName()); RefProtocols.push_back(RefPDecl); } } diff --git a/test/SemaObjC/category-1.m b/test/SemaObjC/category-1.m index 15f6b166c5..1cae2300e0 100644 --- a/test/SemaObjC/category-1.m +++ b/test/SemaObjC/category-1.m @@ -4,7 +4,7 @@ @protocol p1,p2,p3; -@interface MyClass1 (Category1) // expected-warning {{cannot find protocol definition for 'p1', referenced by 'Category1'}} +@interface MyClass1 (Category1) // expected-warning {{cannot find protocol definition for 'p1'}} @end @interface MyClass1 (Category1) // expected-warning {{duplicate interface declaration for category 'MyClass1(Category1)'}} @@ -27,7 +27,7 @@ @protocol p3 @end -@interface MyClass1 (Category) @end // expected-warning {{cannot find protocol definition for 'p2', referenced by 'Category'}} +@interface MyClass1 (Category) @end // expected-warning {{cannot find protocol definition for 'p2'}} @interface MyClass (Category) @end // expected-error {{cannot find interface declaration for 'MyClass'}} diff --git a/test/SemaObjC/class-def-test-1.m b/test/SemaObjC/class-def-test-1.m index 72702d9d18..3dc687b99a 100644 --- a/test/SemaObjC/class-def-test-1.m +++ b/test/SemaObjC/class-def-test-1.m @@ -2,7 +2,7 @@ @protocol SUPER; -@interface SUPER @end // expected-warning {{cannot find protocol definition for 'SUPER', referenced by 'SUPER'}} +@interface SUPER @end // expected-warning {{cannot find protocol definition for 'SUPER'}} typedef int INTF; // expected-error {{previous definition is here}} diff --git a/test/SemaObjC/class-proto-1.m b/test/SemaObjC/class-proto-1.m index f38eaea4c1..da6811eeb8 100644 --- a/test/SemaObjC/class-proto-1.m +++ b/test/SemaObjC/class-proto-1.m @@ -14,14 +14,14 @@ @interface I1 @end -@interface E1 @end // expected-warning {{cannot find protocol definition for 'p2', referenced by 'E1'}} +@interface E1 @end // expected-warning {{cannot find protocol definition for 'p2'}} @protocol p2 @end @interface I2 @end -@interface E2 @end // expected-warning {{cannot find protocol definition for 'p3', referenced by 'E2'}} +@interface E2 @end // expected-warning {{cannot find protocol definition for 'p3'}} @class U1, U2; diff --git a/test/SemaObjC/protocol-test-2.m b/test/SemaObjC/protocol-test-2.m index f323745c5d..1a7fc9ce3c 100644 --- a/test/SemaObjC/protocol-test-2.m +++ b/test/SemaObjC/protocol-test-2.m @@ -10,7 +10,7 @@ - (INTF1*) meth; @end -@protocol PROTO2 // expected-warning {{cannot find protocol definition for 'p1', referenced by 'PROTO2'}} +@protocol PROTO2 // expected-warning {{cannot find protocol definition for 'p1'}} @end @protocol p1 @end @@ -27,5 +27,5 @@ @protocol p2 @end -@protocol PROTO4 // expected-warning {{cannot find protocol definition for 'p3', referenced by 'PROTO4'}} +@protocol PROTO4 // expected-warning {{cannot find protocol definition for 'p3'}} @end