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