[cfe-commits] r173097 - in /cfe/trunk: include/clang/Parse/Parser.h include/clang/Sema/Sema.h lib/Parse/ParseObjc.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjC/selector-3.m
Douglas Gregor
dgregor at apple.com
Mon Jan 21 14:48:03 PST 2013
On Jan 21, 2013, at 2:32 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Mon Jan 21 16:32:29 2013
> New Revision: 173097
>
> URL: http://llvm.org/viewvc/llvm-project?rev=173097&view=rev
> Log:
> objectiveC: don't warn when in -Wselector mode and
> an unimplemented selector is consumed by
> "respondsToSelector:". // rdar://12938616
>
> Modified:
> cfe/trunk/include/clang/Parse/Parser.h
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/Parse/ParseObjc.cpp
> cfe/trunk/lib/Sema/SemaExprObjC.cpp
> cfe/trunk/test/SemaObjC/selector-3.m
>
> Modified: cfe/trunk/include/clang/Parse/Parser.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=173097&r1=173096&r2=173097&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Parse/Parser.h (original)
> +++ cfe/trunk/include/clang/Parse/Parser.h Mon Jan 21 16:32:29 2013
> @@ -1410,7 +1410,8 @@
> ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
> ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
> ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
> - ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
> + ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc,
> + bool WarnSelector=true);
> ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
> bool isSimpleObjCMessageExpression();
> ExprResult ParseObjCMessageExpression();
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=173097&r1=173096&r2=173097&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Mon Jan 21 16:32:29 2013
> @@ -4280,7 +4280,8 @@
> SourceLocation AtLoc,
> SourceLocation SelLoc,
> SourceLocation LParenLoc,
> - SourceLocation RParenLoc);
> + SourceLocation RParenLoc,
> + bool WarnSelector);
>
> /// ParseObjCProtocolExpression - Build protocol expression for \@protocol
> ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
>
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=173097&r1=173096&r2=173097&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Jan 21 16:32:29 2013
> @@ -2425,6 +2425,8 @@
> ExprVector KeyExprs;
>
> if (Tok.is(tok::colon)) {
> + bool RespondsToSelector =
> + selIdent && selIdent->isStr("respondsToSelector");
> while (1) {
> // Each iteration parses a single keyword argument.
> KeyIdents.push_back(selIdent);
> @@ -2463,7 +2465,22 @@
> return ExprError();
> }
>
> - ExprResult Res(ParseAssignmentExpression());
> + ExprResult Res;
> + if (RespondsToSelector) {
> + if (Tok.is(tok::at)) {
> + // Special handling for 'respondsToSelector:' which must not warn
> + // on use of @selector expression as its sole argument.
> + Token AfterAt = GetLookAheadToken(1);
> + if (AfterAt.isObjCAtKeyword(tok::objc_selector)) {
> + SourceLocation AtLoc = ConsumeToken();
> + Res = ParseObjCSelectorExpression(AtLoc, false);
> + }
> + }
> + RespondsToSelector = false;
> + }
> + if (!Res.get())
> + Res = ParseAssignmentExpression();
This won't work if the @selector is parenthesized, e.g.,
[foo respondsToSelector:(@selector(blah:wibble:))]
Can't we do this with some simple parser state rather than using lookahead?
- Doug
More information about the cfe-commits
mailing list