]> granicus.if.org Git - clang/commitdiff
Make the ObjC attributes diagnostics a bit more informative.
authorNico Weber <nicolasweber@gmx.de>
Thu, 4 Apr 2013 00:15:10 +0000 (00:15 +0000)
committerNico Weber <nicolasweber@gmx.de>
Thu, 4 Apr 2013 00:15:10 +0000 (00:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178720 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
include/clang/Parse/Parser.h
lib/Parse/ParseObjc.cpp
test/Parser/attributes.mm

index 26820dbddfa2ec8902503f0ae5951b0e8ef12f34..04a433c0a6a2e50df2d8786625845919011b420e 100644 (file)
@@ -401,6 +401,9 @@ def err_objc_unexpected_attr : Error<
   "prefix attribute must be followed by an interface or protocol">;
 def err_objc_postfix_attribute : Error <
   "postfix attributes are not allowed on Objective-C directives">;
+def err_objc_postfix_attribute_hint : Error <
+  "postfix attributes are not allowed on Objective-C directives, place"
+  " them in front of '%select{@interface|@protocol}0'">;
 def err_objc_directive_only_in_protocol : Error<
   "directive may only be specified in protocols only">;
 def err_missing_catch_finally : Error<
index 7ff6f96ff99ed327f76cd33e835370ab29385956..8cc60a29dfa3a594f1312b3d161fd9c9d519346c 100644 (file)
@@ -1113,7 +1113,7 @@ private:
   ExprResult ParseAsmStringLiteral();
 
   // Objective-C External Declarations
-  void MaybeSkipAttributes();
+  void MaybeSkipAttributes(tok::ObjCKeywordKind Kind);
   DeclGroupPtrTy ParseObjCAtDirectives();
   DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
   Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
index 844a3d12e931821eeb0dc7ca084bd301d78102ae..ad95dd5821ceadb2676e0a20e51a0bb6b774d0c7 100644 (file)
 using namespace clang;
 
 /// Skips attributes after an Objective-C @ directive. Emits a diagnostic.
-void Parser::MaybeSkipAttributes() {
+void Parser::MaybeSkipAttributes(tok::ObjCKeywordKind Kind) {
   ParsedAttributes attrs(AttrFactory);
   if (Tok.is(tok::kw___attribute)) {
-    Diag(Tok, diag::err_objc_postfix_attribute);
+    if (Kind == tok::objc_interface || Kind == tok::objc_protocol)
+      Diag(Tok, diag::err_objc_postfix_attribute_hint)
+          << (Kind == tok::objc_protocol);
+    else
+      Diag(Tok, diag::err_objc_postfix_attribute);
     ParseGNUAttributes(attrs);
   }
 }
@@ -101,7 +105,7 @@ Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) {
 
 
   while (1) {
-    MaybeSkipAttributes();
+    MaybeSkipAttributes(tok::objc_class);
     if (Tok.isNot(tok::identifier)) {
       Diag(Tok, diag::err_expected_ident);
       SkipUntil(tok::semi);
@@ -188,7 +192,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
     return 0;
   }
 
-  MaybeSkipAttributes();
+  MaybeSkipAttributes(tok::objc_interface);
 
   if (Tok.isNot(tok::identifier)) {
     Diag(Tok, diag::err_expected_ident); // missing class or category name.
@@ -1408,7 +1412,7 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
     return DeclGroupPtrTy();
   }
 
-  MaybeSkipAttributes();
+  MaybeSkipAttributes(tok::objc_protocol);
 
   if (Tok.isNot(tok::identifier)) {
     Diag(Tok, diag::err_expected_ident); // missing protocol name.
@@ -1501,7 +1505,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) {
     return DeclGroupPtrTy();
   }
 
-  MaybeSkipAttributes();
+  MaybeSkipAttributes(tok::objc_implementation);
 
   if (Tok.isNot(tok::identifier)) {
     Diag(Tok, diag::err_expected_ident); // missing class or category name.
index 812d543e3e2a2cc02a7c1938af08852bb39d1f7c..d92e3d35cfbfc536d6cc61e5929a5d9dfc8a2ec9 100644 (file)
@@ -11,15 +11,15 @@ __attribute__((deprecated)) @protocol P1
 class EXP C {};
 EXP class C2 {}; // expected-warning {{attribute 'visibility' is ignored, place it after "class" to apply attribute to type declaration}}
 
-@interface EXP I @end // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+@interface EXP I @end // expected-error {{postfix attributes are not allowed on Objective-C directives, place them in front of '@interface'}}
 EXP @interface I2 @end
 
-@implementation EXP I @end // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+@implementation EXP I @end // expected-error-re {{postfix attributes are not allowed on Objective-C directives$}}
 // FIXME: Prefix attribute recovery skips until ';'
-EXP @implementation I2 @end; // expected-error{{prefix attribute must be followed by an interface or protocol}}
+EXP @implementation I2 @end; // expected-error {{prefix attribute must be followed by an interface or protocol}}
 
-@class EXP OC; // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+@class EXP OC; // expected-error-re {{postfix attributes are not allowed on Objective-C directives$}}
 EXP @class OC2; // expected-error {{prefix attribute must be followed by an interface or protocol}}
 
-@protocol EXP P @end // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+@protocol EXP P @end // expected-error {{postfix attributes are not allowed on Objective-C directives, place them in front of '@protocol'}}
 EXP @protocol P2 @end