Chris Lattner | 7ad0fbe | 2006-11-05 07:46:30 +0000 | [diff] [blame] | 1 | //===--- ParseInit.cpp - Initializer Parsing ------------------------------===// |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements initializer parsing as specified by C99 6.7.8. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Parse/Parser.h" |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 15 | #include "RAIIObjectsForParser.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "clang/Parse/ParseDiagnostic.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 17 | #include "clang/Sema/Designator.h" |
| 18 | #include "clang/Sema/Scope.h" |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallString.h" |
Daniel Dunbar | ebd5b4a | 2009-10-17 23:52:50 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
| 23 | |
Douglas Gregor | a80cae1 | 2012-02-17 03:49:44 +0000 | [diff] [blame] | 24 | /// MayBeDesignationStart - Return true if the current token might be the start |
| 25 | /// of a designator. If we can tell it is impossible that it is a designator, |
| 26 | /// return false. |
| 27 | bool Parser::MayBeDesignationStart() { |
| 28 | switch (Tok.getKind()) { |
| 29 | default: |
| 30 | return false; |
| 31 | |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 32 | case tok::period: // designator: '.' identifier |
Douglas Gregor | a80cae1 | 2012-02-17 03:49:44 +0000 | [diff] [blame] | 33 | return true; |
| 34 | |
| 35 | case tok::l_square: { // designator: array-designator |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 36 | if (!PP.getLangOpts().CPlusPlus11) |
Chris Lattner | dde6543 | 2008-10-26 22:41:58 +0000 | [diff] [blame] | 37 | return true; |
Douglas Gregor | a80cae1 | 2012-02-17 03:49:44 +0000 | [diff] [blame] | 38 | |
| 39 | // C++11 lambda expressions and C99 designators can be ambiguous all the |
| 40 | // way through the closing ']' and to the next character. Handle the easy |
| 41 | // cases here, and fall back to tentative parsing if those fail. |
| 42 | switch (PP.LookAhead(0).getKind()) { |
| 43 | case tok::equal: |
| 44 | case tok::r_square: |
| 45 | // Definitely starts a lambda expression. |
| 46 | return false; |
| 47 | |
| 48 | case tok::amp: |
| 49 | case tok::kw_this: |
| 50 | case tok::identifier: |
| 51 | // We have to do additional analysis, because these could be the |
| 52 | // start of a constant expression or a lambda capture list. |
| 53 | break; |
| 54 | |
| 55 | default: |
| 56 | // Anything not mentioned above cannot occur following a '[' in a |
| 57 | // lambda expression. |
| 58 | return true; |
| 59 | } |
| 60 | |
Douglas Gregor | 23b0541 | 2012-02-17 16:41:16 +0000 | [diff] [blame] | 61 | // Handle the complicated case below. |
| 62 | break; |
Douglas Gregor | a80cae1 | 2012-02-17 03:49:44 +0000 | [diff] [blame] | 63 | } |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 64 | case tok::identifier: // designation: identifier ':' |
Chris Lattner | dde6543 | 2008-10-26 22:41:58 +0000 | [diff] [blame] | 65 | return PP.LookAhead(0).is(tok::colon); |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 66 | } |
Douglas Gregor | 23b0541 | 2012-02-17 16:41:16 +0000 | [diff] [blame] | 67 | |
| 68 | // Parse up to (at most) the token after the closing ']' to determine |
Richard Smith | 9e2f0a4 | 2014-04-13 04:31:48 +0000 | [diff] [blame] | 69 | // whether this is a C99 designator or a lambda. |
Douglas Gregor | 23b0541 | 2012-02-17 16:41:16 +0000 | [diff] [blame] | 70 | TentativeParsingAction Tentative(*this); |
Richard Smith | 9e2f0a4 | 2014-04-13 04:31:48 +0000 | [diff] [blame] | 71 | |
| 72 | LambdaIntroducer Intro; |
| 73 | bool SkippedInits = false; |
| 74 | Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro, &SkippedInits)); |
| 75 | |
| 76 | if (DiagID) { |
| 77 | // If this can't be a lambda capture list, it's a designator. |
| 78 | Tentative.Revert(); |
| 79 | return true; |
Douglas Gregor | 23b0541 | 2012-02-17 16:41:16 +0000 | [diff] [blame] | 80 | } |
Richard Smith | 9e2f0a4 | 2014-04-13 04:31:48 +0000 | [diff] [blame] | 81 | |
| 82 | // Once we hit the closing square bracket, we look at the next |
| 83 | // token. If it's an '=', this is a designator. Otherwise, it's a |
| 84 | // lambda expression. This decision favors lambdas over the older |
| 85 | // GNU designator syntax, which allows one to omit the '=', but is |
| 86 | // consistent with GCC. |
| 87 | tok::TokenKind Kind = Tok.getKind(); |
| 88 | // FIXME: If we didn't skip any inits, parse the lambda from here |
| 89 | // rather than throwing away then reparsing the LambdaIntroducer. |
| 90 | Tentative.Revert(); |
| 91 | return Kind == tok::equal; |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 94 | static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc, |
| 95 | Designation &Desig) { |
| 96 | // If we have exactly one array designator, this used the GNU |
| 97 | // 'designation: array-designator' extension, otherwise there should be no |
| 98 | // designators at all! |
| 99 | if (Desig.getNumDesignators() == 1 && |
| 100 | (Desig.getDesignator(0).isArrayDesignator() || |
| 101 | Desig.getDesignator(0).isArrayRangeDesignator())) |
| 102 | P.Diag(Loc, diag::ext_gnu_missing_equal_designator); |
| 103 | else if (Desig.getNumDesignators() > 0) |
| 104 | P.Diag(Loc, diag::err_expected_equal_designator); |
| 105 | } |
| 106 | |
Chris Lattner | e7dab44 | 2006-08-13 21:54:51 +0000 | [diff] [blame] | 107 | /// ParseInitializerWithPotentialDesignator - Parse the 'initializer' production |
| 108 | /// checking to see if the token stream starts with a designator. |
| 109 | /// |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 110 | /// designation: |
| 111 | /// designator-list '=' |
| 112 | /// [GNU] array-designator |
| 113 | /// [GNU] identifier ':' |
| 114 | /// |
| 115 | /// designator-list: |
| 116 | /// designator |
| 117 | /// designator-list designator |
| 118 | /// |
| 119 | /// designator: |
| 120 | /// array-designator |
| 121 | /// '.' identifier |
| 122 | /// |
| 123 | /// array-designator: |
| 124 | /// '[' constant-expression ']' |
| 125 | /// [GNU] '[' constant-expression '...' constant-expression ']' |
| 126 | /// |
| 127 | /// NOTE: [OBC] allows '[ objc-receiver objc-message-args ]' as an |
Chris Lattner | 0c02460 | 2008-10-26 21:46:13 +0000 | [diff] [blame] | 128 | /// initializer (because it is an expression). We need to consider this case |
| 129 | /// when parsing array designators. |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 130 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 131 | ExprResult Parser::ParseInitializerWithPotentialDesignator() { |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 132 | |
Chris Lattner | f3e58e2 | 2008-10-26 22:36:07 +0000 | [diff] [blame] | 133 | // If this is the old-style GNU extension: |
| 134 | // designation ::= identifier ':' |
| 135 | // Handle it as a field designator. Otherwise, this must be the start of a |
| 136 | // normal expression. |
| 137 | if (Tok.is(tok::identifier)) { |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 138 | const IdentifierInfo *FieldName = Tok.getIdentifierInfo(); |
Douglas Gregor | 5c7c9cb | 2009-03-28 00:41:23 +0000 | [diff] [blame] | 139 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 140 | SmallString<256> NewSyntax; |
Daniel Dunbar | 07d0785 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 141 | llvm::raw_svector_ostream(NewSyntax) << '.' << FieldName->getName() |
Daniel Dunbar | ebd5b4a | 2009-10-17 23:52:50 +0000 | [diff] [blame] | 142 | << " = "; |
Douglas Gregor | 5c7c9cb | 2009-03-28 00:41:23 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 144 | SourceLocation NameLoc = ConsumeToken(); // Eat the identifier. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 146 | assert(Tok.is(tok::colon) && "MayBeDesignationStart not working properly!"); |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 147 | SourceLocation ColonLoc = ConsumeToken(); |
| 148 | |
Douglas Gregor | afeabec | 2011-08-27 00:13:16 +0000 | [diff] [blame] | 149 | Diag(NameLoc, diag::ext_gnu_old_style_field_designator) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 150 | << FixItHint::CreateReplacement(SourceRange(NameLoc, ColonLoc), |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame^] | 151 | NewSyntax); |
Douglas Gregor | 5c7c9cb | 2009-03-28 00:41:23 +0000 | [diff] [blame] | 152 | |
Douglas Gregor | 85992cf | 2009-03-20 23:11:49 +0000 | [diff] [blame] | 153 | Designation D; |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 154 | D.AddDesignator(Designator::getField(FieldName, SourceLocation(), NameLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 155 | return Actions.ActOnDesignatedInitializer(D, ColonLoc, true, |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 156 | ParseInitializer()); |
Chris Lattner | f3e58e2 | 2008-10-26 22:36:07 +0000 | [diff] [blame] | 157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Chris Lattner | 7243245 | 2008-10-26 22:59:19 +0000 | [diff] [blame] | 159 | // Desig - This is initialized when we see our first designator. We may have |
| 160 | // an objc message send with no designator, so we don't want to create this |
| 161 | // eagerly. |
Douglas Gregor | 85992cf | 2009-03-20 23:11:49 +0000 | [diff] [blame] | 162 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 164 | // Parse each designator in the designator list until we find an initializer. |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 165 | while (Tok.is(tok::period) || Tok.is(tok::l_square)) { |
| 166 | if (Tok.is(tok::period)) { |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 167 | // designator: '.' identifier |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 168 | SourceLocation DotLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 169 | |
Chris Lattner | 7243245 | 2008-10-26 22:59:19 +0000 | [diff] [blame] | 170 | if (Tok.isNot(tok::identifier)) { |
| 171 | Diag(Tok.getLocation(), diag::err_expected_field_designator); |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 172 | return ExprError(); |
Chris Lattner | 7243245 | 2008-10-26 22:59:19 +0000 | [diff] [blame] | 173 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 174 | |
Douglas Gregor | 85992cf | 2009-03-20 23:11:49 +0000 | [diff] [blame] | 175 | Desig.AddDesignator(Designator::getField(Tok.getIdentifierInfo(), DotLoc, |
| 176 | Tok.getLocation())); |
Chris Lattner | 7243245 | 2008-10-26 22:59:19 +0000 | [diff] [blame] | 177 | ConsumeToken(); // Eat the identifier. |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 178 | continue; |
| 179 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 180 | |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 181 | // We must have either an array designator now or an objc message send. |
| 182 | assert(Tok.is(tok::l_square) && "Unexpected token!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | |
Chris Lattner | 8aafd35 | 2008-10-26 23:06:54 +0000 | [diff] [blame] | 184 | // Handle the two forms of array designator: |
| 185 | // array-designator: '[' constant-expression ']' |
| 186 | // array-designator: '[' constant-expression '...' constant-expression ']' |
| 187 | // |
| 188 | // Also, we have to handle the case where the expression after the |
| 189 | // designator an an objc message send: '[' objc-message-expr ']'. |
| 190 | // Interesting cases are: |
| 191 | // [foo bar] -> objc message send |
| 192 | // [foo] -> array designator |
| 193 | // [foo ... bar] -> array designator |
| 194 | // [4][foo bar] -> obsolete GNU designation with objc message send. |
| 195 | // |
Richard Smith | 7bdcc4a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 196 | // We do not need to check for an expression starting with [[ here. If it |
| 197 | // contains an Objective-C message send, then it is not an ill-formed |
| 198 | // attribute. If it is a lambda-expression within an array-designator, then |
| 199 | // it will be rejected because a constant-expression cannot begin with a |
| 200 | // lambda-expression. |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 201 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 202 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 203 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 204 | T.consumeOpen(); |
| 205 | SourceLocation StartLoc = T.getOpenLocation(); |
| 206 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 207 | ExprResult Idx; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 208 | |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 209 | // If Objective-C is enabled and this is a typename (class message |
| 210 | // send) or send to 'super', parse this as a message send |
| 211 | // expression. We handle C++ and C separately, since C++ requires |
| 212 | // much more complicated parsing. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 213 | if (getLangOpts().ObjC1 && getLangOpts().CPlusPlus) { |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 214 | // Send to 'super'. |
| 215 | if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 216 | NextToken().isNot(tok::period) && |
| 217 | getCurScope()->isInObjcMethodScope()) { |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 218 | CheckArrayDesignatorSyntax(*this, StartLoc, Desig); |
| 219 | return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 220 | ConsumeToken(), |
| 221 | ParsedType(), |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 222 | nullptr); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | // Parse the receiver, which is either a type or an expression. |
| 226 | bool IsExpr; |
| 227 | void *TypeOrExpr; |
| 228 | if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 229 | SkipUntil(tok::r_square, StopAtSemi); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 230 | return ExprError(); |
| 231 | } |
| 232 | |
| 233 | // If the receiver was a type, we have a class message; parse |
| 234 | // the rest of it. |
| 235 | if (!IsExpr) { |
| 236 | CheckArrayDesignatorSyntax(*this, StartLoc, Desig); |
| 237 | return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, |
| 238 | SourceLocation(), |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 239 | ParsedType::getFromOpaquePtr(TypeOrExpr), |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 240 | nullptr); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | // If the receiver was an expression, we still don't know |
| 244 | // whether we have a message send or an array designator; just |
| 245 | // adopt the expression for further analysis below. |
| 246 | // FIXME: potentially-potentially evaluated expression above? |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 247 | Idx = ExprResult(static_cast<Expr*>(TypeOrExpr)); |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 248 | } else if (getLangOpts().ObjC1 && Tok.is(tok::identifier)) { |
Chris Lattner | a36ec42 | 2010-04-11 08:28:14 +0000 | [diff] [blame] | 249 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 250 | SourceLocation IILoc = Tok.getLocation(); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 251 | ParsedType ReceiverType; |
Chris Lattner | 3adb17d | 2010-04-12 06:36:00 +0000 | [diff] [blame] | 252 | // Three cases. This is a message send to a type: [type foo] |
| 253 | // This is a message send to super: [super foo] |
| 254 | // This is a message sent to an expr: [super.bar foo] |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 255 | switch (Sema::ObjCMessageKind Kind |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 256 | = Actions.getObjCMessageKind(getCurScope(), II, IILoc, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 257 | II == Ident_super, |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 258 | NextToken().is(tok::period), |
| 259 | ReceiverType)) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 260 | case Sema::ObjCSuperMessage: |
| 261 | case Sema::ObjCClassMessage: |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 262 | CheckArrayDesignatorSyntax(*this, StartLoc, Desig); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 263 | if (Kind == Sema::ObjCSuperMessage) |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 264 | return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, |
| 265 | ConsumeToken(), |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 266 | ParsedType(), |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 267 | nullptr); |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 268 | ConsumeToken(); // the identifier |
| 269 | if (!ReceiverType) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 270 | SkipUntil(tok::r_square, StopAtSemi); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 271 | return ExprError(); |
| 272 | } |
| 273 | |
| 274 | return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, |
| 275 | SourceLocation(), |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 276 | ReceiverType, |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 277 | nullptr); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 278 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 279 | case Sema::ObjCInstanceMessage: |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 280 | // Fall through; we'll just parse the expression and |
| 281 | // (possibly) treat this like an Objective-C message send |
| 282 | // later. |
| 283 | break; |
Chris Lattner | a36ec42 | 2010-04-11 08:28:14 +0000 | [diff] [blame] | 284 | } |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 285 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 286 | |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 287 | // Parse the index expression, if we haven't already gotten one |
| 288 | // above (which can only happen in Objective-C++). |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 289 | // Note that we parse this as an assignment expression, not a constant |
| 290 | // expression (allowing *=, =, etc) to handle the objc case. Sema needs |
| 291 | // to validate that the expression is a constant. |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 292 | // FIXME: We also need to tell Sema that we're in a |
| 293 | // potentially-potentially evaluated context. |
| 294 | if (!Idx.get()) { |
| 295 | Idx = ParseAssignmentExpression(); |
| 296 | if (Idx.isInvalid()) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 297 | SkipUntil(tok::r_square, StopAtSemi); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 298 | return Idx; |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 299 | } |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 300 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 301 | |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 302 | // Given an expression, we could either have a designator (if the next |
| 303 | // tokens are '...' or ']' or an objc message send. If this is an objc |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | // message send, handle it now. An objc-message send is the start of |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 305 | // an assignment-expression production. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 306 | if (getLangOpts().ObjC1 && Tok.isNot(tok::ellipsis) && |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 307 | Tok.isNot(tok::r_square)) { |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 308 | CheckArrayDesignatorSyntax(*this, Tok.getLocation(), Desig); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 309 | return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, |
| 310 | SourceLocation(), |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 311 | ParsedType(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 312 | Idx.get()); |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 313 | } |
Chris Lattner | 8aafd35 | 2008-10-26 23:06:54 +0000 | [diff] [blame] | 314 | |
Chris Lattner | 8aafd35 | 2008-10-26 23:06:54 +0000 | [diff] [blame] | 315 | // If this is a normal array designator, remember it. |
| 316 | if (Tok.isNot(tok::ellipsis)) { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 317 | Desig.AddDesignator(Designator::getArray(Idx.get(), StartLoc)); |
Chris Lattner | 8aafd35 | 2008-10-26 23:06:54 +0000 | [diff] [blame] | 318 | } else { |
| 319 | // Handle the gnu array range extension. |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 320 | Diag(Tok, diag::ext_gnu_array_range); |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 321 | SourceLocation EllipsisLoc = ConsumeToken(); |
Sebastian Redl | 59b5e51 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 322 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 323 | ExprResult RHS(ParseConstantExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 324 | if (RHS.isInvalid()) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 325 | SkipUntil(tok::r_square, StopAtSemi); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 326 | return RHS; |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 327 | } |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 328 | Desig.AddDesignator(Designator::getArrayRange(Idx.get(), |
| 329 | RHS.get(), |
Douglas Gregor | 85992cf | 2009-03-20 23:11:49 +0000 | [diff] [blame] | 330 | StartLoc, EllipsisLoc)); |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 331 | } |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 332 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 333 | T.consumeClose(); |
| 334 | Desig.getDesignator(Desig.getNumDesignators() - 1).setRBracketLoc( |
| 335 | T.getCloseLocation()); |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 336 | } |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 337 | |
Chris Lattner | 7243245 | 2008-10-26 22:59:19 +0000 | [diff] [blame] | 338 | // Okay, we're done with the designator sequence. We know that there must be |
| 339 | // at least one designator, because the only case we can get into this method |
| 340 | // without a designator is when we have an objc message send. That case is |
| 341 | // handled and returned from above. |
Douglas Gregor | 85992cf | 2009-03-20 23:11:49 +0000 | [diff] [blame] | 342 | assert(!Desig.empty() && "Designator is empty?"); |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 343 | |
Chris Lattner | 7243245 | 2008-10-26 22:59:19 +0000 | [diff] [blame] | 344 | // Handle a normal designator sequence end, which is an equal. |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 345 | if (Tok.is(tok::equal)) { |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 346 | SourceLocation EqualLoc = ConsumeToken(); |
Douglas Gregor | 85992cf | 2009-03-20 23:11:49 +0000 | [diff] [blame] | 347 | return Actions.ActOnDesignatedInitializer(Desig, EqualLoc, false, |
Douglas Gregor | e4a0bb7 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 348 | ParseInitializer()); |
Chris Lattner | e2b5e87 | 2008-10-26 22:49:49 +0000 | [diff] [blame] | 349 | } |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 350 | |
Chris Lattner | 7243245 | 2008-10-26 22:59:19 +0000 | [diff] [blame] | 351 | // We read some number of designators and found something that isn't an = or |
Chris Lattner | 46dcba6 | 2008-10-26 23:22:23 +0000 | [diff] [blame] | 352 | // an initializer. If we have exactly one array designator, this |
Chris Lattner | 7243245 | 2008-10-26 22:59:19 +0000 | [diff] [blame] | 353 | // is the GNU 'designation: array-designator' extension. Otherwise, it is a |
| 354 | // parse error. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 355 | if (Desig.getNumDesignators() == 1 && |
Douglas Gregor | 85992cf | 2009-03-20 23:11:49 +0000 | [diff] [blame] | 356 | (Desig.getDesignator(0).isArrayDesignator() || |
| 357 | Desig.getDesignator(0).isArrayRangeDesignator())) { |
Douglas Gregor | 5c7c9cb | 2009-03-28 00:41:23 +0000 | [diff] [blame] | 358 | Diag(Tok, diag::ext_gnu_missing_equal_designator) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 359 | << FixItHint::CreateInsertion(Tok.getLocation(), "= "); |
Douglas Gregor | 5c7c9cb | 2009-03-28 00:41:23 +0000 | [diff] [blame] | 360 | return Actions.ActOnDesignatedInitializer(Desig, Tok.getLocation(), |
Douglas Gregor | 8aa6bf5 | 2009-03-27 23:40:29 +0000 | [diff] [blame] | 361 | true, ParseInitializer()); |
Chris Lattner | 46dcba6 | 2008-10-26 23:22:23 +0000 | [diff] [blame] | 362 | } |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 363 | |
Chris Lattner | 46dcba6 | 2008-10-26 23:22:23 +0000 | [diff] [blame] | 364 | Diag(Tok, diag::err_expected_equal_designator); |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 365 | return ExprError(); |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | |
Chris Lattner | 3fa9239 | 2008-10-26 22:38:55 +0000 | [diff] [blame] | 369 | /// ParseBraceInitializer - Called when parsing an initializer that has a |
| 370 | /// leading open brace. |
| 371 | /// |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 372 | /// initializer: [C99 6.7.8] |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 373 | /// '{' initializer-list '}' |
| 374 | /// '{' initializer-list ',' '}' |
| 375 | /// [GNU] '{' '}' |
| 376 | /// |
| 377 | /// initializer-list: |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 378 | /// designation[opt] initializer ...[opt] |
| 379 | /// initializer-list ',' designation[opt] initializer ...[opt] |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 380 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 381 | ExprResult Parser::ParseBraceInitializer() { |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 382 | InMessageExpressionRAIIObject InMessage(*this, false); |
| 383 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 384 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 385 | T.consumeOpen(); |
| 386 | SourceLocation LBraceLoc = T.getOpenLocation(); |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 387 | |
Chris Lattner | f3e58e2 | 2008-10-26 22:36:07 +0000 | [diff] [blame] | 388 | /// InitExprs - This is the actual list of expressions contained in the |
| 389 | /// initializer. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 390 | ExprVector InitExprs; |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 391 | |
Chris Lattner | 248388e | 2008-10-26 23:35:51 +0000 | [diff] [blame] | 392 | if (Tok.is(tok::r_brace)) { |
Douglas Gregor | d14247a | 2009-01-30 22:09:00 +0000 | [diff] [blame] | 393 | // Empty initializers are a C++ feature and a GNU extension to C. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 394 | if (!getLangOpts().CPlusPlus) |
Douglas Gregor | d14247a | 2009-01-30 22:09:00 +0000 | [diff] [blame] | 395 | Diag(LBraceLoc, diag::ext_gnu_empty_initializer); |
Chris Lattner | 248388e | 2008-10-26 23:35:51 +0000 | [diff] [blame] | 396 | // Match the '}'. |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 397 | return Actions.ActOnInitList(LBraceLoc, None, ConsumeBrace()); |
Chris Lattner | 248388e | 2008-10-26 23:35:51 +0000 | [diff] [blame] | 398 | } |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 399 | |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 400 | bool InitExprsOk = true; |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 401 | |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 402 | while (1) { |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 403 | // Handle Microsoft __if_exists/if_not_exists if necessary. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 404 | if (getLangOpts().MicrosoftExt && (Tok.is(tok::kw___if_exists) || |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 405 | Tok.is(tok::kw___if_not_exists))) { |
| 406 | if (ParseMicrosoftIfExistsBraceInitializer(InitExprs, InitExprsOk)) { |
| 407 | if (Tok.isNot(tok::comma)) break; |
| 408 | ConsumeToken(); |
| 409 | } |
| 410 | if (Tok.is(tok::r_brace)) break; |
| 411 | continue; |
| 412 | } |
| 413 | |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 414 | // Parse: designation[opt] initializer |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 415 | |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 416 | // If we know that this cannot be a designation, just parse the nested |
| 417 | // initializer directly. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 418 | ExprResult SubElt; |
Douglas Gregor | a80cae1 | 2012-02-17 03:49:44 +0000 | [diff] [blame] | 419 | if (MayBeDesignationStart()) |
Douglas Gregor | 85992cf | 2009-03-20 23:11:49 +0000 | [diff] [blame] | 420 | SubElt = ParseInitializerWithPotentialDesignator(); |
| 421 | else |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 422 | SubElt = ParseInitializer(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 423 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 424 | if (Tok.is(tok::ellipsis)) |
| 425 | SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken()); |
Kaelyn Takata | 1586782 | 2014-11-21 18:48:04 +0000 | [diff] [blame] | 426 | |
| 427 | SubElt = Actions.CorrectDelayedTyposInExpr(SubElt.get()); |
| 428 | |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 429 | // If we couldn't parse the subelement, bail out. |
Kaelyn Takata | 1586782 | 2014-11-21 18:48:04 +0000 | [diff] [blame] | 430 | if (SubElt.isUsable()) { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 431 | InitExprs.push_back(SubElt.get()); |
Chris Lattner | 14cd1ee | 2008-04-20 19:07:56 +0000 | [diff] [blame] | 432 | } else { |
| 433 | InitExprsOk = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 434 | |
Chris Lattner | 14cd1ee | 2008-04-20 19:07:56 +0000 | [diff] [blame] | 435 | // We have two ways to try to recover from this error: if the code looks |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 436 | // grammatically ok (i.e. we have a comma coming up) try to continue |
Chris Lattner | 14cd1ee | 2008-04-20 19:07:56 +0000 | [diff] [blame] | 437 | // parsing the rest of the initializer. This allows us to emit |
| 438 | // diagnostics for later elements that we find. If we don't see a comma, |
| 439 | // assume there is a parse error, and just skip to recover. |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 440 | // FIXME: This comment doesn't sound right. If there is a r_brace |
| 441 | // immediately, it can't be an error, since there is no other way of |
| 442 | // leaving this loop except through this if. |
Chris Lattner | 14cd1ee | 2008-04-20 19:07:56 +0000 | [diff] [blame] | 443 | if (Tok.isNot(tok::comma)) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 444 | SkipUntil(tok::r_brace, StopBeforeMatch); |
Chris Lattner | 14cd1ee | 2008-04-20 19:07:56 +0000 | [diff] [blame] | 445 | break; |
| 446 | } |
| 447 | } |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 448 | |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 449 | // If we don't have a comma continued list, we're done. |
Chris Lattner | 76c7228 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 450 | if (Tok.isNot(tok::comma)) break; |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 451 | |
Chris Lattner | f3e58e2 | 2008-10-26 22:36:07 +0000 | [diff] [blame] | 452 | // TODO: save comma locations if some client cares. |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 453 | ConsumeToken(); |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 454 | |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 455 | // Handle trailing comma. |
Chris Lattner | 76c7228 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 456 | if (Tok.is(tok::r_brace)) break; |
Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 457 | } |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 458 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 459 | bool closed = !T.consumeClose(); |
| 460 | |
| 461 | if (InitExprsOk && closed) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 462 | return Actions.ActOnInitList(LBraceLoc, InitExprs, |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 463 | T.getCloseLocation()); |
| 464 | |
Sebastian Redl | d65cea8 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 465 | return ExprError(); // an error occurred. |
Chris Lattner | 8693a51 | 2006-08-13 21:54:02 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 468 | |
| 469 | // Return true if a comma (or closing brace) is necessary after the |
| 470 | // __if_exists/if_not_exists statement. |
| 471 | bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, |
| 472 | bool &InitExprsOk) { |
| 473 | bool trailingComma = false; |
| 474 | IfExistsCondition Result; |
| 475 | if (ParseMicrosoftIfExistsCondition(Result)) |
| 476 | return false; |
| 477 | |
| 478 | BalancedDelimiterTracker Braces(*this, tok::l_brace); |
| 479 | if (Braces.consumeOpen()) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 480 | Diag(Tok, diag::err_expected) << tok::l_brace; |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 481 | return false; |
| 482 | } |
| 483 | |
| 484 | switch (Result.Behavior) { |
| 485 | case IEB_Parse: |
| 486 | // Parse the declarations below. |
| 487 | break; |
| 488 | |
| 489 | case IEB_Dependent: |
| 490 | Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists) |
| 491 | << Result.IsIfExists; |
| 492 | // Fall through to skip. |
| 493 | |
| 494 | case IEB_Skip: |
| 495 | Braces.skipToEnd(); |
| 496 | return false; |
| 497 | } |
| 498 | |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 499 | while (!isEofOrEom()) { |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 500 | trailingComma = false; |
| 501 | // If we know that this cannot be a designation, just parse the nested |
| 502 | // initializer directly. |
| 503 | ExprResult SubElt; |
Douglas Gregor | a80cae1 | 2012-02-17 03:49:44 +0000 | [diff] [blame] | 504 | if (MayBeDesignationStart()) |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 505 | SubElt = ParseInitializerWithPotentialDesignator(); |
| 506 | else |
| 507 | SubElt = ParseInitializer(); |
| 508 | |
| 509 | if (Tok.is(tok::ellipsis)) |
| 510 | SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken()); |
| 511 | |
| 512 | // If we couldn't parse the subelement, bail out. |
| 513 | if (!SubElt.isInvalid()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 514 | InitExprs.push_back(SubElt.get()); |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 515 | else |
| 516 | InitExprsOk = false; |
| 517 | |
| 518 | if (Tok.is(tok::comma)) { |
| 519 | ConsumeToken(); |
| 520 | trailingComma = true; |
| 521 | } |
| 522 | |
| 523 | if (Tok.is(tok::r_brace)) |
| 524 | break; |
| 525 | } |
| 526 | |
| 527 | Braces.consumeClose(); |
| 528 | |
| 529 | return !trailingComma; |
| 530 | } |