[cfe-commits] r51882 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseExpr.cpp lib/Parse/ParseInit.cpp test/Parser/objc-init.m
Chris Lattner
sabre at nondot.org
Mon Jun 2 14:31:07 PDT 2008
Author: lattner
Date: Mon Jun 2 16:31:07 2008
New Revision: 51882
URL: http://llvm.org/viewvc/llvm-project?rev=51882&view=rev
Log:
handle the full assignment-expression grammar when using an
objc message send in an initializer expression.
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseInit.cpp
cfe/trunk/test/Parser/objc-init.m
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=51882&r1=51881&r2=51882&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Jun 2 16:31:07 2008
@@ -403,6 +403,9 @@
ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
IdentifierInfo *ReceiverName,
ExprTy *ReceiverExpr);
+ ExprResult ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracloc,
+ IdentifierInfo *ReceiverName,
+ ExprTy *ReceiverExpr);
//===--------------------------------------------------------------------===//
// C99 6.8: Statements and Blocks.
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=51882&r1=51881&r2=51882&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Mon Jun 2 16:31:07 2008
@@ -200,6 +200,27 @@
return ParseRHSOfBinaryExpression(LHS, prec::Assignment);
}
+/// ParseAssignmentExprWithObjCMessageExprStart - Parse an assignment expression
+/// where part of an objc message send has already been parsed. In this case
+/// LBracLoc indicates the location of the '[' of the message send, and either
+/// ReceiverName or ReceiverExpr is non-null indicating the receiver of the
+/// message.
+///
+/// Since this handles full assignment-expression's, it handles postfix
+/// expressions and other binary operators for these expressions as well.
+Parser::ExprResult
+Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc,
+ IdentifierInfo *ReceiverName,
+ ExprTy *ReceiverExpr) {
+ ExprResult R = ParseObjCMessageExpressionBody(LBracLoc, ReceiverName,
+ ReceiverExpr);
+ if (R.isInvalid) return R;
+ R = ParsePostfixExpressionSuffix(R);
+ if (R.isInvalid) return R;
+ return ParseRHSOfBinaryExpression(R, 2);
+}
+
+
Parser::ExprResult Parser::ParseConstantExpression() {
ExprResult LHS = ParseCastExpression(false);
if (LHS.isInvalid) return LHS;
Modified: cfe/trunk/lib/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseInit.cpp?rev=51882&r1=51881&r2=51882&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseInit.cpp (original)
+++ cfe/trunk/lib/Parse/ParseInit.cpp Mon Jun 2 16:31:07 2008
@@ -98,8 +98,7 @@
// [4][foo bar].
IdentifierInfo *Name = Tok.getIdentifierInfo();
ConsumeToken();
- ExprResult R = ParseObjCMessageExpressionBody(StartLoc, Name, 0);
- return ParsePostfixExpressionSuffix(R);
+ return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, Name, 0);
}
// Note that we parse this as an assignment expression, not a constant
@@ -113,13 +112,13 @@
// Given an expression, we could either have a designator (if the next
// tokens are '...' or ']' or an objc message send. If this is an objc
- // message send, handle it now.
+ // message send, handle it now. An objc-message send is the start of
+ // an assignment-expression production.
if (getLang().ObjC1 && Tok.isNot(tok::ellipsis) &&
Tok.isNot(tok::r_square)) {
// FIXME: Emit ext_gnu_missing_equal_designator for inits like
// [4][foo bar].
- ExprResult R = ParseObjCMessageExpressionBody(StartLoc, 0, Idx.Val);
- return ParsePostfixExpressionSuffix(R);
+ return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, 0,Idx.Val);
}
// Handle the gnu array range extension.
Modified: cfe/trunk/test/Parser/objc-init.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-init.m?rev=51882&r1=51881&r2=51882&view=diff
==============================================================================
--- cfe/trunk/test/Parser/objc-init.m (original)
+++ cfe/trunk/test/Parser/objc-init.m Mon Jun 2 16:31:07 2008
@@ -3,6 +3,7 @@
@interface NSNumber;
- () METH;
+- (unsigned) METH2;
@end
void test1() {
@@ -15,3 +16,8 @@
}
+// rdar://5977581
+void test3() {
+ unsigned x[] = {[NSNumber METH2]+2};
+}
+
More information about the cfe-commits
mailing list