[cfe-commits] r140404 - in /cfe/trunk: lib/Parse/ParseObjc.cpp test/SemaObjC/attr-deprecated.m
Douglas Gregor
dgregor at apple.com
Fri Sep 23 12:19:41 PDT 2011
Author: dgregor
Date: Fri Sep 23 14:19:41 2011
New Revision: 140404
URL: http://llvm.org/viewvc/llvm-project?rev=140404&view=rev
Log:
Clean up parsing the category names in interfaces slightly, using
MatchRHSPunctuation appropriately and giving a useful source location
for the complaint about attributes being added to a category.
Modified:
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/test/SemaObjC/attr-deprecated.m
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=140404&r1=140403&r2=140404&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Fri Sep 23 14:19:41 2011
@@ -164,9 +164,7 @@
SourceLocation nameLoc = ConsumeToken();
if (Tok.is(tok::l_paren) &&
!isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category.
- // TODO(dgregor): Use the return value from the next line to provide better
- // recovery.
- ConsumeParen();
+ SourceLocation LParenLoc = ConsumeParen();
SourceLocation categoryLoc, rparenLoc;
IdentifierInfo *categoryId = 0;
if (Tok.is(tok::code_completion)) {
@@ -184,12 +182,16 @@
Diag(Tok, diag::err_expected_ident); // missing category name.
return 0;
}
- if (Tok.isNot(tok::r_paren)) {
- Diag(Tok, diag::err_expected_rparen);
- SkipUntil(tok::r_paren, false); // don't stop at ';'
+
+ rparenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
+ if (rparenLoc.isInvalid())
return 0;
+
+ if (!attrs.empty()) { // categories don't support attributes.
+ Diag(nameLoc, diag::err_objc_no_attributes_on_category);
+ attrs.clear();
}
- rparenLoc = ConsumeParen();
+
// Next, we need to check for any protocol references.
SourceLocation LAngleLoc, EndProtoLoc;
SmallVector<Decl *, 8> ProtocolRefs;
@@ -199,9 +201,6 @@
LAngleLoc, EndProtoLoc))
return 0;
- if (!attrs.empty()) // categories don't support attributes.
- Diag(Tok, diag::err_objc_no_attributes_on_category);
-
Decl *CategoryType =
Actions.ActOnStartCategoryInterface(atLoc,
nameId, nameLoc,
Modified: cfe/trunk/test/SemaObjC/attr-deprecated.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-deprecated.m?rev=140404&r1=140403&r2=140404&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-deprecated.m (original)
+++ cfe/trunk/test/SemaObjC/attr-deprecated.m Fri Sep 23 14:19:41 2011
@@ -108,3 +108,7 @@
foo.test2 = x; // expected-warning {{'test2' is deprecated}}
[foo setTest2: x]; // expected-warning {{'setTest2:' is deprecated}}
}
+
+__attribute__((deprecated))
+ at interface A(Blah) // expected-error{{attributes may not be specified on a category}}
+ at end
More information about the cfe-commits
mailing list