r178720 - Make the ObjC attributes diagnostics a bit more informative.
Nico Weber
nicolasweber at gmx.de
Wed Apr 3 17:15:10 PDT 2013
Author: nico
Date: Wed Apr 3 19:15:10 2013
New Revision: 178720
URL: http://llvm.org/viewvc/llvm-project?rev=178720&view=rev
Log:
Make the ObjC attributes diagnostics a bit more informative.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/test/Parser/attributes.mm
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=178720&r1=178719&r2=178720&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Wed Apr 3 19:15:10 2013
@@ -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<
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=178720&r1=178719&r2=178720&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Apr 3 19:15:10 2013
@@ -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,
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=178720&r1=178719&r2=178720&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed Apr 3 19:15:10 2013
@@ -23,10 +23,14 @@
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(Sour
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::ParseObjCAtInterfaceDeclar
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(S
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::ParseObjCAtImplementationDeclara
return DeclGroupPtrTy();
}
- MaybeSkipAttributes();
+ MaybeSkipAttributes(tok::objc_implementation);
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident); // missing class or category name.
Modified: cfe/trunk/test/Parser/attributes.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/attributes.mm?rev=178720&r1=178719&r2=178720&view=diff
==============================================================================
--- cfe/trunk/test/Parser/attributes.mm (original)
+++ cfe/trunk/test/Parser/attributes.mm Wed Apr 3 19:15:10 2013
@@ -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}}
- at interface EXP I @end // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+ at 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
- at implementation EXP I @end // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+ at 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}}
- at class EXP OC; // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+ at 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}}
- at protocol EXP P @end // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+ at 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
More information about the cfe-commits
mailing list