From 0fbda68b50ce17d7ad36ef7a5ed77518a5cd272e Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 15 Sep 2010 14:51:05 +0000 Subject: Implement bracket insertion for Objective-C instance message sends as part of parser recovery. For example, given: a method1:arg]; we detect after parsing the expression "a" that we have the start of a message send expression. We pretend we've seen a '[' prior to the a, then parse the remainder as a message send. We'll then give a diagnostic+fix-it such as: fixit-objc-message.m:17:3: error: missing '[' at start of message send expression a method1:arg]; ^ [ The algorithm here is very simple, and always assumes that the open bracket goes at the beginning of the message send. It also only works for non-super instance message sends at this time. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113968 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseInit.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/Parse/ParseInit.cpp') diff --git a/lib/Parse/ParseInit.cpp b/lib/Parse/ParseInit.cpp index 4347294141..c2675f33e7 100644 --- a/lib/Parse/ParseInit.cpp +++ b/lib/Parse/ParseInit.cpp @@ -13,6 +13,7 @@ #include "clang/Parse/Parser.h" #include "clang/Parse/ParseDiagnostic.h" +#include "RAIIObjectsForParser.h" #include "clang/Sema/Designator.h" #include "clang/Sema/Scope.h" #include "llvm/ADT/SmallString.h" @@ -136,6 +137,8 @@ ExprResult Parser::ParseInitializerWithPotentialDesignator() { // [foo ... bar] -> array designator // [4][foo bar] -> obsolete GNU designation with objc message send. // + InMessageExpressionRAIIObject InMessage(*this, true); + SourceLocation StartLoc = ConsumeBracket(); ExprResult Idx; @@ -146,7 +149,8 @@ ExprResult Parser::ParseInitializerWithPotentialDesignator() { if (getLang().ObjC1 && getLang().CPlusPlus) { // Send to 'super'. if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && - NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) { + NextToken().isNot(tok::period) && + getCurScope()->isInObjcMethodScope()) { CheckArrayDesignatorSyntax(*this, StartLoc, Desig); return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, ConsumeToken(), @@ -310,6 +314,8 @@ ExprResult Parser::ParseInitializerWithPotentialDesignator() { /// initializer-list ',' designation[opt] initializer /// ExprResult Parser::ParseBraceInitializer() { + InMessageExpressionRAIIObject InMessage(*this, false); + SourceLocation LBraceLoc = ConsumeBrace(); /// InitExprs - This is the actual list of expressions contained in the -- cgit v1.2.3-70-g09d2