]> granicus.if.org Git - clang/commitdiff
simplify some code.
authorChris Lattner <sabre@nondot.org>
Sat, 26 Jul 2008 03:47:43 +0000 (03:47 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 26 Jul 2008 03:47:43 +0000 (03:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54091 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticKinds.def
include/clang/Parse/Action.h
lib/Parse/ParseDecl.cpp
lib/Sema/Sema.h
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/category-1.m
test/SemaObjC/class-def-test-1.m
test/SemaObjC/class-proto-1.m
test/SemaObjC/protocol-test-2.m

index 2b0f5aef6ee8d6b4b7fa6d13417cd3eb27a1a460..e5bbdd372aa503ed112b363a3d4da59c167d1175 100644 (file)
@@ -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,
index 12f6d3a73743831c80b788f0220c08060dc4f4bb..47047b911f385f7a58ac1b8e47f393d410baffb9 100644 (file)
@@ -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<DeclTy*> &Protocols) {
+                                 llvm::SmallVectorImpl<DeclTy*> &ResProtos) {
   }
 
   //===----------------------- Obj-C Expressions --------------------------===//
index e7b73cf619751b04141adb795b1b82deec820065..e047d601ef003445f0aadccf69473adb608be7a4 100644 (file)
@@ -435,7 +435,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
       ParseObjCProtocolReferences(ProtocolRefs, EndProtoLoc);
       
       llvm::SmallVector<DeclTy *, 8> 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<IdentifierLocPair, 8> ProtocolRefs;
         ParseObjCProtocolReferences(ProtocolRefs, EndProtoLoc);
         llvm::SmallVector<DeclTy *, 8> ProtocolDecl;
-        Actions.FindProtocolDeclaration(Loc, 
+        Actions.FindProtocolDeclaration(Loc, false,
                                         &ProtocolRefs[0], ProtocolRefs.size(),
                                         ProtocolDecl);
         DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size());
index 25120acc7a9f210f3ba581e82771fc15a4f43f64..3d4552d202203b89ef402efd91b5147a4a0834e8 100644 (file)
@@ -655,6 +655,7 @@ public:
                                                   unsigned NumElts);
   
   virtual void FindProtocolDeclaration(SourceLocation TypeLoc,
+                                       bool WarnOnDeclarations,
                                        const IdentifierLocPair *ProtocolId,
                                        unsigned NumProtocols,
                                    llvm::SmallVectorImpl<DeclTy *> &Protocols);
index 3615ed30c6a30d2db0299011e3717c00af4d44dc..9d2869be8a77ce6cf181b1d10a817aa9b258ab51 100644 (file)
@@ -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<DeclTy*> &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);
       }
     }
index 15f6b166c5b74f0a4c3b8b5bf22b18f420729d9b..1cae2300e0ea7397b5d368fa1e3cfd8f161982f1 100644 (file)
@@ -4,7 +4,7 @@
 
 @protocol p1,p2,p3;
 
-@interface MyClass1 (Category1)  <p1> // expected-warning {{cannot find protocol definition for 'p1', referenced by 'Category1'}}
+@interface MyClass1 (Category1)  <p1> // 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) <p2, p3> @end  // expected-warning {{cannot find protocol definition for 'p2', referenced by 'Category'}}
+@interface MyClass1 (Category) <p2, p3> @end  // expected-warning {{cannot find protocol definition for 'p2'}}
 
 @interface MyClass  (Category) @end // expected-error {{cannot find interface declaration for 'MyClass'}}
 
index 72702d9d18bcd6200baebd3d94dc5f48674fdcfc..3dc687b99a6d8fb47dd724dc9d1b2720ef350e40 100644 (file)
@@ -2,7 +2,7 @@
 
 @protocol SUPER;
 
-@interface SUPER <SUPER> @end // expected-warning {{cannot find protocol definition for 'SUPER', referenced by 'SUPER'}}
+@interface SUPER <SUPER> @end // expected-warning {{cannot find protocol definition for 'SUPER'}}
 
 typedef int INTF; //  expected-error {{previous definition is here}}
 
index f38eaea4c1967c23aef908ef62ebdd34dcd81743..da6811eeb8ddfab27cb2413fe81c1edd2765cfbc 100644 (file)
 
 @interface I1 <p1> @end
 
-@interface E1 <p2> @end        // expected-warning {{cannot find protocol definition for 'p2', referenced by 'E1'}}
+@interface E1 <p2> @end        // expected-warning {{cannot find protocol definition for 'p2'}}
 
 @protocol p2 @end
 
 
 @interface I2 <p1,p2> @end
 
-@interface E2 <p1,p2,p3> @end  // expected-warning {{cannot find protocol definition for 'p3', referenced by 'E2'}}
+@interface E2 <p1,p2,p3> @end  // expected-warning {{cannot find protocol definition for 'p3'}}
 
 @class U1, U2;
 
index f323745c5dfe3e03c9c3db6942660ae8e7ec44fa..1a7fc9ce3ccf0c6bc29339cb40eeacc4a86f5f34 100644 (file)
@@ -10,7 +10,7 @@
 - (INTF1<p1>*) meth;
 @end
 
-@protocol PROTO2<p1> // expected-warning {{cannot find protocol definition for 'p1', referenced by 'PROTO2'}}
+@protocol PROTO2<p1> // expected-warning {{cannot find protocol definition for 'p1'}}
 @end
 
 @protocol p1 @end
@@ -27,5 +27,5 @@
 @protocol p2 <p1>
 @end
 
-@protocol PROTO4 <p1, p2, PROTO, PROTO3, p3> // expected-warning {{cannot find protocol definition for 'p3', referenced by 'PROTO4'}}
+@protocol PROTO4 <p1, p2, PROTO, PROTO3, p3> // expected-warning {{cannot find protocol definition for 'p3'}}
 @end