blob: f5cdfffba50673e13d3cf6a5ed66606de4b0c3f9 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- ParseStmt.cpp - Statement and Block Parser -----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Statement and Block portions of the Parser
11// interface.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Parse/Parser.h"
Chris Lattner39146d62008-10-20 06:51:33 +000016#include "ExtensionRAIIObject.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000017#include "clang/Basic/Diagnostic.h"
Steve Naroffb746ce82008-02-07 23:24:32 +000018#include "clang/Basic/SourceManager.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000019#include "clang/Parse/DeclSpec.h"
20#include "clang/Parse/Scope.h"
21using namespace clang;
22
23//===----------------------------------------------------------------------===//
24// C99 6.8: Statements and Blocks.
25//===----------------------------------------------------------------------===//
26
27/// ParseStatementOrDeclaration - Read 'statement' or 'declaration'.
28/// StatementOrDeclaration:
29/// statement
30/// declaration
31///
32/// statement:
33/// labeled-statement
34/// compound-statement
35/// expression-statement
36/// selection-statement
37/// iteration-statement
38/// jump-statement
Argyrios Kyrtzidisdcdd55f2008-09-07 18:58:01 +000039/// [C++] declaration-statement
Fariborz Jahanianb384d322007-10-04 20:19:06 +000040/// [OBC] objc-throw-statement
41/// [OBC] objc-try-catch-statement
Fariborz Jahanianc385c902008-01-29 18:21:32 +000042/// [OBC] objc-synchronized-statement
Reid Spencer5f016e22007-07-11 17:01:13 +000043/// [GNU] asm-statement
44/// [OMP] openmp-construct [TODO]
45///
46/// labeled-statement:
47/// identifier ':' statement
48/// 'case' constant-expression ':' statement
49/// 'default' ':' statement
50///
51/// selection-statement:
52/// if-statement
53/// switch-statement
54///
55/// iteration-statement:
56/// while-statement
57/// do-statement
58/// for-statement
59///
60/// expression-statement:
61/// expression[opt] ';'
62///
63/// jump-statement:
64/// 'goto' identifier ';'
65/// 'continue' ';'
66/// 'break' ';'
67/// 'return' expression[opt] ';'
68/// [GNU] 'goto' '*' expression ';'
69///
Fariborz Jahanianb384d322007-10-04 20:19:06 +000070/// [OBC] objc-throw-statement:
71/// [OBC] '@' 'throw' expression ';'
72/// [OBC] '@' 'throw' ';'
Reid Spencer5f016e22007-07-11 17:01:13 +000073///
74Parser::StmtResult Parser::ParseStatementOrDeclaration(bool OnlyStatement) {
75 const char *SemiError = 0;
76 Parser::StmtResult Res;
77
78 // Cases in this switch statement should fall through if the parser expects
79 // the token to end in a semicolon (in which case SemiError should be set),
80 // or they directly 'return;' if not.
Fariborz Jahanian397fcc12007-09-19 19:14:32 +000081 tok::TokenKind Kind = Tok.getKind();
82 SourceLocation AtLoc;
83 switch (Kind) {
Fariborz Jahanian397fcc12007-09-19 19:14:32 +000084 case tok::at: // May be a @try or @throw statement
85 {
86 AtLoc = ConsumeToken(); // consume @
Steve Naroff64515f32008-02-05 21:27:35 +000087 return ParseObjCAtStatement(AtLoc);
Fariborz Jahanian397fcc12007-09-19 19:14:32 +000088 }
Fariborz Jahanian397fcc12007-09-19 19:14:32 +000089
Argyrios Kyrtzidisb9f930d2008-07-12 21:04:42 +000090 case tok::identifier:
91 if (NextToken().is(tok::colon)) { // C99 6.8.1: labeled-statement
92 // identifier ':' statement
93 return ParseLabeledStatement();
94 }
95 // PASS THROUGH.
96
Reid Spencer5f016e22007-07-11 17:01:13 +000097 default:
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000098 if ((getLang().CPlusPlus || !OnlyStatement) && isDeclarationStatement()) {
Chris Lattner81c018d2008-03-13 06:29:04 +000099 SourceLocation DeclStart = Tok.getLocation();
100 DeclTy *Res = ParseDeclaration(Declarator::BlockContext);
101 // FIXME: Pass in the right location for the end of the declstmt.
Chris Lattner691a38b2008-03-13 06:29:54 +0000102 return Actions.ActOnDeclStmt(Res, DeclStart, DeclStart);
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000103 } else if (Tok.is(tok::r_brace)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000104 Diag(Tok, diag::err_expected_statement);
105 return true;
106 } else {
107 // expression[opt] ';'
Fariborz Jahanianb384d322007-10-04 20:19:06 +0000108 ExprResult Res = ParseExpression();
Reid Spencer5f016e22007-07-11 17:01:13 +0000109 if (Res.isInvalid) {
110 // If the expression is invalid, skip ahead to the next semicolon. Not
111 // doing this opens us up to the possibility of infinite loops if
112 // ParseExpression does not consume any tokens.
113 SkipUntil(tok::semi);
114 return true;
115 }
116 // Otherwise, eat the semicolon.
117 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
Steve Naroff1b273c42007-09-16 14:56:35 +0000118 return Actions.ActOnExprStmt(Res.Val);
Reid Spencer5f016e22007-07-11 17:01:13 +0000119 }
120
121 case tok::kw_case: // C99 6.8.1: labeled-statement
122 return ParseCaseStatement();
123 case tok::kw_default: // C99 6.8.1: labeled-statement
124 return ParseDefaultStatement();
125
126 case tok::l_brace: // C99 6.8.2: compound-statement
127 return ParseCompoundStatement();
128 case tok::semi: // C99 6.8.3p3: expression[opt] ';'
Steve Naroff1b273c42007-09-16 14:56:35 +0000129 return Actions.ActOnNullStmt(ConsumeToken());
Reid Spencer5f016e22007-07-11 17:01:13 +0000130
131 case tok::kw_if: // C99 6.8.4.1: if-statement
132 return ParseIfStatement();
133 case tok::kw_switch: // C99 6.8.4.2: switch-statement
134 return ParseSwitchStatement();
135
136 case tok::kw_while: // C99 6.8.5.1: while-statement
137 return ParseWhileStatement();
138 case tok::kw_do: // C99 6.8.5.2: do-statement
139 Res = ParseDoStatement();
140 SemiError = "do/while loop";
141 break;
142 case tok::kw_for: // C99 6.8.5.3: for-statement
143 return ParseForStatement();
144
145 case tok::kw_goto: // C99 6.8.6.1: goto-statement
146 Res = ParseGotoStatement();
147 SemiError = "goto statement";
148 break;
149 case tok::kw_continue: // C99 6.8.6.2: continue-statement
150 Res = ParseContinueStatement();
151 SemiError = "continue statement";
152 break;
153 case tok::kw_break: // C99 6.8.6.3: break-statement
154 Res = ParseBreakStatement();
155 SemiError = "break statement";
156 break;
157 case tok::kw_return: // C99 6.8.6.4: return-statement
158 Res = ParseReturnStatement();
159 SemiError = "return statement";
160 break;
161
162 case tok::kw_asm:
Steve Naroffd62701b2008-02-07 03:50:06 +0000163 bool msAsm = false;
164 Res = ParseAsmStatement(msAsm);
165 if (msAsm) return Res;
Reid Spencer5f016e22007-07-11 17:01:13 +0000166 SemiError = "asm statement";
167 break;
168 }
169
170 // If we reached this code, the statement must end in a semicolon.
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000171 if (Tok.is(tok::semi)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000172 ConsumeToken();
173 } else {
174 Diag(Tok, diag::err_expected_semi_after, SemiError);
175 SkipUntil(tok::semi);
176 }
177 return Res;
178}
179
Argyrios Kyrtzidisf7da7262008-07-09 22:53:07 +0000180/// ParseLabeledStatement - We have an identifier and a ':' after it.
Reid Spencer5f016e22007-07-11 17:01:13 +0000181///
182/// labeled-statement:
183/// identifier ':' statement
184/// [GNU] identifier ':' attributes[opt] statement
Argyrios Kyrtzidisf7da7262008-07-09 22:53:07 +0000185///
186Parser::StmtResult Parser::ParseLabeledStatement() {
187 assert(Tok.is(tok::identifier) && Tok.getIdentifierInfo() &&
188 "Not an identifier!");
189
190 Token IdentTok = Tok; // Save the whole token.
191 ConsumeToken(); // eat the identifier.
192
193 assert(Tok.is(tok::colon) && "Not a label!");
194
195 // identifier ':' statement
196 SourceLocation ColonLoc = ConsumeToken();
197
198 // Read label attributes, if present.
199 DeclTy *AttrList = 0;
200 if (Tok.is(tok::kw___attribute))
201 // TODO: save these somewhere.
202 AttrList = ParseAttributes();
203
204 StmtResult SubStmt = ParseStatement();
205
206 // Broken substmt shouldn't prevent the label from being added to the AST.
207 if (SubStmt.isInvalid)
208 SubStmt = Actions.ActOnNullStmt(ColonLoc);
209
210 return Actions.ActOnLabelStmt(IdentTok.getLocation(),
211 IdentTok.getIdentifierInfo(),
212 ColonLoc, SubStmt.Val);
213}
Reid Spencer5f016e22007-07-11 17:01:13 +0000214
215/// ParseCaseStatement
216/// labeled-statement:
217/// 'case' constant-expression ':' statement
218/// [GNU] 'case' constant-expression '...' constant-expression ':' statement
219///
220/// Note that this does not parse the 'statement' at the end.
221///
222Parser::StmtResult Parser::ParseCaseStatement() {
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000223 assert(Tok.is(tok::kw_case) && "Not a case stmt!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000224 SourceLocation CaseLoc = ConsumeToken(); // eat the 'case'.
225
226 ExprResult LHS = ParseConstantExpression();
227 if (LHS.isInvalid) {
228 SkipUntil(tok::colon);
229 return true;
230 }
231
232 // GNU case range extension.
233 SourceLocation DotDotDotLoc;
234 ExprTy *RHSVal = 0;
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000235 if (Tok.is(tok::ellipsis)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000236 Diag(Tok, diag::ext_gnu_case_range);
237 DotDotDotLoc = ConsumeToken();
238
239 ExprResult RHS = ParseConstantExpression();
240 if (RHS.isInvalid) {
241 SkipUntil(tok::colon);
242 return true;
243 }
244 RHSVal = RHS.Val;
245 }
246
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000247 if (Tok.isNot(tok::colon)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000248 Diag(Tok, diag::err_expected_colon_after, "'case'");
249 SkipUntil(tok::colon);
250 return true;
251 }
252
253 SourceLocation ColonLoc = ConsumeToken();
254
255 // Diagnose the common error "switch (X) { case 4: }", which is not valid.
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000256 if (Tok.is(tok::r_brace)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000257 Diag(Tok, diag::err_label_end_of_compound_statement);
258 return true;
259 }
260
261 StmtResult SubStmt = ParseStatement();
262
263 // Broken substmt shouldn't prevent the case from being added to the AST.
264 if (SubStmt.isInvalid)
Steve Naroff1b273c42007-09-16 14:56:35 +0000265 SubStmt = Actions.ActOnNullStmt(ColonLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +0000266
Steve Naroff1b273c42007-09-16 14:56:35 +0000267 return Actions.ActOnCaseStmt(CaseLoc, LHS.Val, DotDotDotLoc, RHSVal, ColonLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000268 SubStmt.Val);
269}
270
271/// ParseDefaultStatement
272/// labeled-statement:
273/// 'default' ':' statement
274/// Note that this does not parse the 'statement' at the end.
275///
276Parser::StmtResult Parser::ParseDefaultStatement() {
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000277 assert(Tok.is(tok::kw_default) && "Not a default stmt!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000278 SourceLocation DefaultLoc = ConsumeToken(); // eat the 'default'.
279
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000280 if (Tok.isNot(tok::colon)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000281 Diag(Tok, diag::err_expected_colon_after, "'default'");
282 SkipUntil(tok::colon);
283 return true;
284 }
285
286 SourceLocation ColonLoc = ConsumeToken();
287
288 // Diagnose the common error "switch (X) {... default: }", which is not valid.
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000289 if (Tok.is(tok::r_brace)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000290 Diag(Tok, diag::err_label_end_of_compound_statement);
291 return true;
292 }
293
294 StmtResult SubStmt = ParseStatement();
295 if (SubStmt.isInvalid)
296 return true;
297
Steve Naroff1b273c42007-09-16 14:56:35 +0000298 return Actions.ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt.Val, CurScope);
Reid Spencer5f016e22007-07-11 17:01:13 +0000299}
300
301
302/// ParseCompoundStatement - Parse a "{}" block.
303///
304/// compound-statement: [C99 6.8.2]
305/// { block-item-list[opt] }
306/// [GNU] { label-declarations block-item-list } [TODO]
307///
308/// block-item-list:
309/// block-item
310/// block-item-list block-item
311///
312/// block-item:
313/// declaration
Chris Lattner45a566c2007-08-27 01:01:57 +0000314/// [GNU] '__extension__' declaration
Reid Spencer5f016e22007-07-11 17:01:13 +0000315/// statement
316/// [OMP] openmp-directive [TODO]
317///
318/// [GNU] label-declarations:
319/// [GNU] label-declaration
320/// [GNU] label-declarations label-declaration
321///
322/// [GNU] label-declaration:
323/// [GNU] '__label__' identifier-list ';'
324///
325/// [OMP] openmp-directive: [TODO]
326/// [OMP] barrier-directive
327/// [OMP] flush-directive
328///
Chris Lattner98414c12007-08-31 21:49:55 +0000329Parser::StmtResult Parser::ParseCompoundStatement(bool isStmtExpr) {
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000330 assert(Tok.is(tok::l_brace) && "Not a compount stmt!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000331
Chris Lattner31e05722007-08-26 06:24:45 +0000332 // Enter a scope to hold everything within the compound stmt. Compound
333 // statements can always hold declarations.
334 EnterScope(Scope::DeclScope);
Reid Spencer5f016e22007-07-11 17:01:13 +0000335
336 // Parse the statements in the body.
Chris Lattner98414c12007-08-31 21:49:55 +0000337 StmtResult Body = ParseCompoundStatementBody(isStmtExpr);
Reid Spencer5f016e22007-07-11 17:01:13 +0000338
339 ExitScope();
340 return Body;
341}
342
343
344/// ParseCompoundStatementBody - Parse a sequence of statements and invoke the
Steve Naroff1b273c42007-09-16 14:56:35 +0000345/// ActOnCompoundStmt action. This expects the '{' to be the current token, and
Reid Spencer5f016e22007-07-11 17:01:13 +0000346/// consume the '}' at the end of the block. It does not manipulate the scope
347/// stack.
Chris Lattner98414c12007-08-31 21:49:55 +0000348Parser::StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000349 SourceLocation LBraceLoc = ConsumeBrace(); // eat the '{'.
350
351 // TODO: "__label__ X, Y, Z;" is the GNU "Local Label" extension. These are
Chris Lattner45a566c2007-08-27 01:01:57 +0000352 // only allowed at the start of a compound stmt regardless of the language.
Reid Spencer5f016e22007-07-11 17:01:13 +0000353
354 llvm::SmallVector<StmtTy*, 32> Stmts;
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000355 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
Chris Lattner45a566c2007-08-27 01:01:57 +0000356 StmtResult R;
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000357 if (Tok.isNot(tok::kw___extension__)) {
Chris Lattner45a566c2007-08-27 01:01:57 +0000358 R = ParseStatementOrDeclaration(false);
359 } else {
360 // __extension__ can start declarations and it can also be a unary
361 // operator for expressions. Consume multiple __extension__ markers here
362 // until we can determine which is which.
363 SourceLocation ExtLoc = ConsumeToken();
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000364 while (Tok.is(tok::kw___extension__))
Chris Lattner45a566c2007-08-27 01:01:57 +0000365 ConsumeToken();
366
Chris Lattner043a0b52008-03-13 06:32:11 +0000367 // __extension__ silences extension warnings in the subexpression.
Chris Lattner39146d62008-10-20 06:51:33 +0000368 ExtensionRAIIObject O(Diags); // Use RAII to do this.
369
Chris Lattner45a566c2007-08-27 01:01:57 +0000370 // If this is the start of a declaration, parse it as such.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000371 if (isDeclarationStatement()) {
Chris Lattner45a566c2007-08-27 01:01:57 +0000372 // FIXME: Save the __extension__ on the decl as a node somehow.
Chris Lattner81c018d2008-03-13 06:29:04 +0000373 SourceLocation DeclStart = Tok.getLocation();
374 DeclTy *Res = ParseDeclaration(Declarator::BlockContext);
375 // FIXME: Pass in the right location for the end of the declstmt.
Chris Lattner691a38b2008-03-13 06:29:54 +0000376 R = Actions.ActOnDeclStmt(Res, DeclStart, DeclStart);
Chris Lattner45a566c2007-08-27 01:01:57 +0000377 } else {
378 // Otherwise this was a unary __extension__ marker. Parse the
379 // subexpression and add the __extension__ unary op.
Chris Lattner45a566c2007-08-27 01:01:57 +0000380 ExprResult Res = ParseCastExpression(false);
Chris Lattner043a0b52008-03-13 06:32:11 +0000381
Chris Lattner45a566c2007-08-27 01:01:57 +0000382 if (Res.isInvalid) {
383 SkipUntil(tok::semi);
384 continue;
385 }
386
387 // Add the __extension__ node to the AST.
Steve Narofff69936d2007-09-16 03:34:24 +0000388 Res = Actions.ActOnUnaryOp(ExtLoc, tok::kw___extension__, Res.Val);
Chris Lattner45a566c2007-08-27 01:01:57 +0000389 if (Res.isInvalid)
390 continue;
391
Chris Lattner39146d62008-10-20 06:51:33 +0000392 // Eat the semicolon at the end of stmt and convert the expr into a
393 // statement.
Chris Lattner45a566c2007-08-27 01:01:57 +0000394 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
Steve Naroff1b273c42007-09-16 14:56:35 +0000395 R = Actions.ActOnExprStmt(Res.Val);
Chris Lattner45a566c2007-08-27 01:01:57 +0000396 }
397 }
398
Reid Spencer5f016e22007-07-11 17:01:13 +0000399 if (!R.isInvalid && R.Val)
400 Stmts.push_back(R.Val);
401 }
402
403 // We broke out of the while loop because we found a '}' or EOF.
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000404 if (Tok.isNot(tok::r_brace)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000405 Diag(Tok, diag::err_expected_rbrace);
Steve Naroffd1a7cf82008-01-31 18:29:10 +0000406 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000407 }
408
409 SourceLocation RBraceLoc = ConsumeBrace();
Steve Naroff1b273c42007-09-16 14:56:35 +0000410 return Actions.ActOnCompoundStmt(LBraceLoc, RBraceLoc,
Chris Lattner98414c12007-08-31 21:49:55 +0000411 &Stmts[0], Stmts.size(), isStmtExpr);
Reid Spencer5f016e22007-07-11 17:01:13 +0000412}
413
414/// ParseIfStatement
415/// if-statement: [C99 6.8.4.1]
416/// 'if' '(' expression ')' statement
417/// 'if' '(' expression ')' statement 'else' statement
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000418/// [C++] 'if' '(' condition ')' statement
419/// [C++] 'if' '(' condition ')' statement 'else' statement
Reid Spencer5f016e22007-07-11 17:01:13 +0000420///
421Parser::StmtResult Parser::ParseIfStatement() {
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000422 assert(Tok.is(tok::kw_if) && "Not an if stmt!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000423 SourceLocation IfLoc = ConsumeToken(); // eat the 'if'.
424
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000425 if (Tok.isNot(tok::l_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000426 Diag(Tok, diag::err_expected_lparen_after, "if");
427 SkipUntil(tok::semi);
428 return true;
429 }
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000430
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000431 bool C99orCXX = getLang().C99 || getLang().CPlusPlus;
432
Chris Lattner22153252007-08-26 23:08:06 +0000433 // C99 6.8.4p3 - In C99, the if statement is a block. This is not
434 // the case for C90.
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000435 //
436 // C++ 6.4p3:
437 // A name introduced by a declaration in a condition is in scope from its
438 // point of declaration until the end of the substatements controlled by the
439 // condition.
Argyrios Kyrtzidis14d08c02008-09-11 23:08:39 +0000440 // C++ 3.3.2p4:
441 // Names declared in the for-init-statement, and in the condition of if,
442 // while, for, and switch statements are local to the if, while, for, or
443 // switch statement (including the controlled statement).
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000444 //
445 if (C99orCXX)
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000446 EnterScope(Scope::DeclScope | Scope::ControlScope);
Chris Lattner22153252007-08-26 23:08:06 +0000447
Reid Spencer5f016e22007-07-11 17:01:13 +0000448 // Parse the condition.
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000449 ExprResult CondExp;
450 if (getLang().CPlusPlus) {
451 SourceLocation LParenLoc = ConsumeParen();
452 CondExp = ParseCXXCondition();
453 MatchRHSPunctuation(tok::r_paren, LParenLoc);
454 } else {
455 CondExp = ParseSimpleParenExpression();
456 }
457
Reid Spencer5f016e22007-07-11 17:01:13 +0000458 if (CondExp.isInvalid) {
459 SkipUntil(tok::semi);
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000460 if (C99orCXX)
Chris Lattner22153252007-08-26 23:08:06 +0000461 ExitScope();
Reid Spencer5f016e22007-07-11 17:01:13 +0000462 return true;
463 }
464
Chris Lattner0ecea032007-08-22 05:28:50 +0000465 // C99 6.8.4p3 - In C99, the body of the if statement is a scope, even if
Chris Lattner38484402007-08-22 05:33:11 +0000466 // there is no compound stmt. C90 does not have this clause. We only do this
467 // if the body isn't a compound statement to avoid push/pop in common cases.
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000468 //
469 // C++ 6.4p1:
470 // The substatement in a selection-statement (each substatement, in the else
471 // form of the if statement) implicitly defines a local scope.
472 //
473 // For C++ we create a scope for the condition and a new scope for
474 // substatements because:
475 // -When the 'then' scope exits, we want the condition declaration to still be
476 // active for the 'else' scope too.
477 // -Sema will detect name clashes by considering declarations of a
478 // 'ControlScope' as part of its direct subscope.
479 // -If we wanted the condition and substatement to be in the same scope, we
480 // would have to notify ParseStatement not to create a new scope. It's
481 // simpler to let it create a new scope.
482 //
483 bool NeedsInnerScope = C99orCXX && Tok.isNot(tok::l_brace);
Chris Lattner31e05722007-08-26 06:24:45 +0000484 if (NeedsInnerScope) EnterScope(Scope::DeclScope);
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000485
Chris Lattnerb96728d2007-10-29 05:08:52 +0000486 // Read the 'then' stmt.
487 SourceLocation ThenStmtLoc = Tok.getLocation();
488 StmtResult ThenStmt = ParseStatement();
Reid Spencer5f016e22007-07-11 17:01:13 +0000489
Chris Lattnera36ce712007-08-22 05:16:28 +0000490 // Pop the 'if' scope if needed.
Chris Lattner38484402007-08-22 05:33:11 +0000491 if (NeedsInnerScope) ExitScope();
Reid Spencer5f016e22007-07-11 17:01:13 +0000492
493 // If it has an else, parse it.
494 SourceLocation ElseLoc;
Chris Lattnerb96728d2007-10-29 05:08:52 +0000495 SourceLocation ElseStmtLoc;
Reid Spencer5f016e22007-07-11 17:01:13 +0000496 StmtResult ElseStmt(false);
Chris Lattnerb96728d2007-10-29 05:08:52 +0000497
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000498 if (Tok.is(tok::kw_else)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000499 ElseLoc = ConsumeToken();
Chris Lattnera36ce712007-08-22 05:16:28 +0000500
Chris Lattner0ecea032007-08-22 05:28:50 +0000501 // C99 6.8.4p3 - In C99, the body of the if statement is a scope, even if
Chris Lattner38484402007-08-22 05:33:11 +0000502 // there is no compound stmt. C90 does not have this clause. We only do
503 // this if the body isn't a compound statement to avoid push/pop in common
504 // cases.
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000505 //
506 // C++ 6.4p1:
507 // The substatement in a selection-statement (each substatement, in the else
508 // form of the if statement) implicitly defines a local scope.
509 //
510 NeedsInnerScope = C99orCXX && Tok.isNot(tok::l_brace);
Chris Lattner31e05722007-08-26 06:24:45 +0000511 if (NeedsInnerScope) EnterScope(Scope::DeclScope);
Chris Lattnera36ce712007-08-22 05:16:28 +0000512
Chris Lattnerb96728d2007-10-29 05:08:52 +0000513 ElseStmtLoc = Tok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000514 ElseStmt = ParseStatement();
Chris Lattnera36ce712007-08-22 05:16:28 +0000515
516 // Pop the 'else' scope if needed.
Chris Lattner38484402007-08-22 05:33:11 +0000517 if (NeedsInnerScope) ExitScope();
Reid Spencer5f016e22007-07-11 17:01:13 +0000518 }
519
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000520 if (C99orCXX)
Chris Lattner22153252007-08-26 23:08:06 +0000521 ExitScope();
522
Chris Lattnerb96728d2007-10-29 05:08:52 +0000523 // If the then or else stmt is invalid and the other is valid (and present),
524 // make turn the invalid one into a null stmt to avoid dropping the other
525 // part. If both are invalid, return error.
526 if ((ThenStmt.isInvalid && ElseStmt.isInvalid) ||
527 (ThenStmt.isInvalid && ElseStmt.Val == 0) ||
528 (ThenStmt.Val == 0 && ElseStmt.isInvalid)) {
529 // Both invalid, or one is invalid and other is non-present: delete cond and
530 // return error.
531 Actions.DeleteExpr(CondExp.Val);
532 return true;
533 }
534
535 // Now if either are invalid, replace with a ';'.
536 if (ThenStmt.isInvalid)
537 ThenStmt = Actions.ActOnNullStmt(ThenStmtLoc);
538 if (ElseStmt.isInvalid)
539 ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc);
540
Chris Lattnerb96728d2007-10-29 05:08:52 +0000541 return Actions.ActOnIfStmt(IfLoc, CondExp.Val, ThenStmt.Val,
Reid Spencer5f016e22007-07-11 17:01:13 +0000542 ElseLoc, ElseStmt.Val);
543}
544
545/// ParseSwitchStatement
546/// switch-statement:
547/// 'switch' '(' expression ')' statement
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000548/// [C++] 'switch' '(' condition ')' statement
Reid Spencer5f016e22007-07-11 17:01:13 +0000549Parser::StmtResult Parser::ParseSwitchStatement() {
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000550 assert(Tok.is(tok::kw_switch) && "Not a switch stmt!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000551 SourceLocation SwitchLoc = ConsumeToken(); // eat the 'switch'.
552
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000553 if (Tok.isNot(tok::l_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000554 Diag(Tok, diag::err_expected_lparen_after, "switch");
555 SkipUntil(tok::semi);
556 return true;
557 }
Chris Lattner22153252007-08-26 23:08:06 +0000558
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000559 bool C99orCXX = getLang().C99 || getLang().CPlusPlus;
560
Chris Lattner22153252007-08-26 23:08:06 +0000561 // C99 6.8.4p3 - In C99, the switch statement is a block. This is
562 // not the case for C90. Start the switch scope.
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000563 //
564 // C++ 6.4p3:
565 // A name introduced by a declaration in a condition is in scope from its
566 // point of declaration until the end of the substatements controlled by the
567 // condition.
Argyrios Kyrtzidis14d08c02008-09-11 23:08:39 +0000568 // C++ 3.3.2p4:
569 // Names declared in the for-init-statement, and in the condition of if,
570 // while, for, and switch statements are local to the if, while, for, or
571 // switch statement (including the controlled statement).
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000572 //
573 if (C99orCXX)
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000574 EnterScope(Scope::BreakScope | Scope::DeclScope | Scope::ControlScope);
Chris Lattner22153252007-08-26 23:08:06 +0000575 else
576 EnterScope(Scope::BreakScope);
Reid Spencer5f016e22007-07-11 17:01:13 +0000577
578 // Parse the condition.
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000579 ExprResult Cond;
580 if (getLang().CPlusPlus) {
581 SourceLocation LParenLoc = ConsumeParen();
582 Cond = ParseCXXCondition();
583 MatchRHSPunctuation(tok::r_paren, LParenLoc);
584 } else {
585 Cond = ParseSimpleParenExpression();
586 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000587
Anders Carlssonc1fcb772007-07-22 07:07:56 +0000588 if (Cond.isInvalid) {
589 ExitScope();
590 return true;
591 }
592
Steve Naroff1b273c42007-09-16 14:56:35 +0000593 StmtResult Switch = Actions.ActOnStartOfSwitchStmt(Cond.Val);
Anders Carlssonc1fcb772007-07-22 07:07:56 +0000594
Chris Lattner0ecea032007-08-22 05:28:50 +0000595 // C99 6.8.4p3 - In C99, the body of the switch statement is a scope, even if
Chris Lattner38484402007-08-22 05:33:11 +0000596 // there is no compound stmt. C90 does not have this clause. We only do this
597 // if the body isn't a compound statement to avoid push/pop in common cases.
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000598 //
599 // C++ 6.4p1:
600 // The substatement in a selection-statement (each substatement, in the else
601 // form of the if statement) implicitly defines a local scope.
602 //
603 // See comments in ParseIfStatement for why we create a scope for the
604 // condition and a new scope for substatement in C++.
605 //
606 bool NeedsInnerScope = C99orCXX && Tok.isNot(tok::l_brace);
Chris Lattner31e05722007-08-26 06:24:45 +0000607 if (NeedsInnerScope) EnterScope(Scope::DeclScope);
Chris Lattner0ecea032007-08-22 05:28:50 +0000608
Reid Spencer5f016e22007-07-11 17:01:13 +0000609 // Read the body statement.
610 StmtResult Body = ParseStatement();
611
Chris Lattner0ecea032007-08-22 05:28:50 +0000612 // Pop the body scope if needed.
Chris Lattner38484402007-08-22 05:33:11 +0000613 if (NeedsInnerScope) ExitScope();
Chris Lattner0ecea032007-08-22 05:28:50 +0000614
Anders Carlssonc1fcb772007-07-22 07:07:56 +0000615 if (Body.isInvalid) {
Steve Naroff1b273c42007-09-16 14:56:35 +0000616 Body = Actions.ActOnNullStmt(Tok.getLocation());
Anders Carlssonc1fcb772007-07-22 07:07:56 +0000617 // FIXME: Remove the case statement list from the Switch statement.
618 }
619
Reid Spencer5f016e22007-07-11 17:01:13 +0000620 ExitScope();
621
Steve Naroff1b273c42007-09-16 14:56:35 +0000622 return Actions.ActOnFinishSwitchStmt(SwitchLoc, Switch.Val, Body.Val);
Reid Spencer5f016e22007-07-11 17:01:13 +0000623}
624
625/// ParseWhileStatement
626/// while-statement: [C99 6.8.5.1]
627/// 'while' '(' expression ')' statement
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000628/// [C++] 'while' '(' condition ')' statement
Reid Spencer5f016e22007-07-11 17:01:13 +0000629Parser::StmtResult Parser::ParseWhileStatement() {
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000630 assert(Tok.is(tok::kw_while) && "Not a while stmt!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000631 SourceLocation WhileLoc = Tok.getLocation();
632 ConsumeToken(); // eat the 'while'.
633
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000634 if (Tok.isNot(tok::l_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000635 Diag(Tok, diag::err_expected_lparen_after, "while");
636 SkipUntil(tok::semi);
637 return true;
638 }
639
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000640 bool C99orCXX = getLang().C99 || getLang().CPlusPlus;
641
Chris Lattner22153252007-08-26 23:08:06 +0000642 // C99 6.8.5p5 - In C99, the while statement is a block. This is not
643 // the case for C90. Start the loop scope.
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000644 //
645 // C++ 6.4p3:
646 // A name introduced by a declaration in a condition is in scope from its
647 // point of declaration until the end of the substatements controlled by the
648 // condition.
Argyrios Kyrtzidis14d08c02008-09-11 23:08:39 +0000649 // C++ 3.3.2p4:
650 // Names declared in the for-init-statement, and in the condition of if,
651 // while, for, and switch statements are local to the if, while, for, or
652 // switch statement (including the controlled statement).
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000653 //
654 if (C99orCXX)
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000655 EnterScope(Scope::BreakScope | Scope::ContinueScope |
656 Scope::DeclScope | Scope::ControlScope);
Chris Lattner22153252007-08-26 23:08:06 +0000657 else
658 EnterScope(Scope::BreakScope | Scope::ContinueScope);
Reid Spencer5f016e22007-07-11 17:01:13 +0000659
660 // Parse the condition.
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000661 ExprResult Cond;
662 if (getLang().CPlusPlus) {
663 SourceLocation LParenLoc = ConsumeParen();
664 Cond = ParseCXXCondition();
665 MatchRHSPunctuation(tok::r_paren, LParenLoc);
666 } else {
667 Cond = ParseSimpleParenExpression();
668 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000669
Chris Lattner0ecea032007-08-22 05:28:50 +0000670 // C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
Chris Lattner38484402007-08-22 05:33:11 +0000671 // there is no compound stmt. C90 does not have this clause. We only do this
672 // if the body isn't a compound statement to avoid push/pop in common cases.
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000673 //
674 // C++ 6.5p2:
675 // The substatement in an iteration-statement implicitly defines a local scope
676 // which is entered and exited each time through the loop.
677 //
678 // See comments in ParseIfStatement for why we create a scope for the
679 // condition and a new scope for substatement in C++.
680 //
681 bool NeedsInnerScope = C99orCXX && Tok.isNot(tok::l_brace);
Chris Lattner31e05722007-08-26 06:24:45 +0000682 if (NeedsInnerScope) EnterScope(Scope::DeclScope);
Chris Lattner0ecea032007-08-22 05:28:50 +0000683
Reid Spencer5f016e22007-07-11 17:01:13 +0000684 // Read the body statement.
685 StmtResult Body = ParseStatement();
686
Chris Lattner0ecea032007-08-22 05:28:50 +0000687 // Pop the body scope if needed.
Chris Lattner38484402007-08-22 05:33:11 +0000688 if (NeedsInnerScope) ExitScope();
Chris Lattner0ecea032007-08-22 05:28:50 +0000689
Reid Spencer5f016e22007-07-11 17:01:13 +0000690 ExitScope();
691
692 if (Cond.isInvalid || Body.isInvalid) return true;
693
Steve Naroff1b273c42007-09-16 14:56:35 +0000694 return Actions.ActOnWhileStmt(WhileLoc, Cond.Val, Body.Val);
Reid Spencer5f016e22007-07-11 17:01:13 +0000695}
696
697/// ParseDoStatement
698/// do-statement: [C99 6.8.5.2]
699/// 'do' statement 'while' '(' expression ')' ';'
700/// Note: this lets the caller parse the end ';'.
701Parser::StmtResult Parser::ParseDoStatement() {
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000702 assert(Tok.is(tok::kw_do) && "Not a do stmt!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000703 SourceLocation DoLoc = ConsumeToken(); // eat the 'do'.
704
Chris Lattner22153252007-08-26 23:08:06 +0000705 // C99 6.8.5p5 - In C99, the do statement is a block. This is not
706 // the case for C90. Start the loop scope.
707 if (getLang().C99)
708 EnterScope(Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope);
709 else
710 EnterScope(Scope::BreakScope | Scope::ContinueScope);
Reid Spencer5f016e22007-07-11 17:01:13 +0000711
Chris Lattner0ecea032007-08-22 05:28:50 +0000712 // C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
Chris Lattner38484402007-08-22 05:33:11 +0000713 // there is no compound stmt. C90 does not have this clause. We only do this
714 // if the body isn't a compound statement to avoid push/pop in common cases.
Argyrios Kyrtzidis143db712008-09-11 04:46:46 +0000715 //
716 // C++ 6.5p2:
717 // The substatement in an iteration-statement implicitly defines a local scope
718 // which is entered and exited each time through the loop.
719 //
720 bool NeedsInnerScope = (getLang().C99 || getLang().CPlusPlus) &&
721 Tok.isNot(tok::l_brace);
Chris Lattner31e05722007-08-26 06:24:45 +0000722 if (NeedsInnerScope) EnterScope(Scope::DeclScope);
Chris Lattner0ecea032007-08-22 05:28:50 +0000723
Reid Spencer5f016e22007-07-11 17:01:13 +0000724 // Read the body statement.
725 StmtResult Body = ParseStatement();
726
Chris Lattner0ecea032007-08-22 05:28:50 +0000727 // Pop the body scope if needed.
Chris Lattner38484402007-08-22 05:33:11 +0000728 if (NeedsInnerScope) ExitScope();
Chris Lattner0ecea032007-08-22 05:28:50 +0000729
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000730 if (Tok.isNot(tok::kw_while)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000731 ExitScope();
732 Diag(Tok, diag::err_expected_while);
733 Diag(DoLoc, diag::err_matching, "do");
734 SkipUntil(tok::semi);
735 return true;
736 }
737 SourceLocation WhileLoc = ConsumeToken();
738
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000739 if (Tok.isNot(tok::l_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000740 ExitScope();
741 Diag(Tok, diag::err_expected_lparen_after, "do/while");
742 SkipUntil(tok::semi);
743 return true;
744 }
745
746 // Parse the condition.
747 ExprResult Cond = ParseSimpleParenExpression();
748
749 ExitScope();
750
751 if (Cond.isInvalid || Body.isInvalid) return true;
752
Steve Naroff1b273c42007-09-16 14:56:35 +0000753 return Actions.ActOnDoStmt(DoLoc, Body.Val, WhileLoc, Cond.Val);
Reid Spencer5f016e22007-07-11 17:01:13 +0000754}
755
756/// ParseForStatement
757/// for-statement: [C99 6.8.5.3]
758/// 'for' '(' expr[opt] ';' expr[opt] ';' expr[opt] ')' statement
759/// 'for' '(' declaration expr[opt] ';' expr[opt] ')' statement
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000760/// [C++] 'for' '(' for-init-statement condition[opt] ';' expression[opt] ')'
761/// [C++] statement
Fariborz Jahanian3ba5a0f2008-01-03 17:55:25 +0000762/// [OBJC2] 'for' '(' declaration 'in' expr ')' statement
763/// [OBJC2] 'for' '(' expr 'in' expr ')' statement
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000764///
765/// [C++] for-init-statement:
766/// [C++] expression-statement
767/// [C++] simple-declaration
768///
Reid Spencer5f016e22007-07-11 17:01:13 +0000769Parser::StmtResult Parser::ParseForStatement() {
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000770 assert(Tok.is(tok::kw_for) && "Not a for stmt!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000771 SourceLocation ForLoc = ConsumeToken(); // eat the 'for'.
772
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000773 if (Tok.isNot(tok::l_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000774 Diag(Tok, diag::err_expected_lparen_after, "for");
775 SkipUntil(tok::semi);
776 return true;
777 }
778
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000779 bool C99orCXX = getLang().C99 || getLang().CPlusPlus;
780
Chris Lattner22153252007-08-26 23:08:06 +0000781 // C99 6.8.5p5 - In C99, the for statement is a block. This is not
782 // the case for C90. Start the loop scope.
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000783 //
784 // C++ 6.4p3:
785 // A name introduced by a declaration in a condition is in scope from its
786 // point of declaration until the end of the substatements controlled by the
787 // condition.
Argyrios Kyrtzidis14d08c02008-09-11 23:08:39 +0000788 // C++ 3.3.2p4:
789 // Names declared in the for-init-statement, and in the condition of if,
790 // while, for, and switch statements are local to the if, while, for, or
791 // switch statement (including the controlled statement).
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000792 // C++ 6.5.3p1:
793 // Names declared in the for-init-statement are in the same declarative-region
794 // as those declared in the condition.
795 //
796 if (C99orCXX)
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000797 EnterScope(Scope::BreakScope | Scope::ContinueScope |
798 Scope::DeclScope | Scope::ControlScope);
Chris Lattner22153252007-08-26 23:08:06 +0000799 else
800 EnterScope(Scope::BreakScope | Scope::ContinueScope);
Reid Spencer5f016e22007-07-11 17:01:13 +0000801
802 SourceLocation LParenLoc = ConsumeParen();
803 ExprResult Value;
804
805 StmtTy *FirstPart = 0;
806 ExprTy *SecondPart = 0;
807 StmtTy *ThirdPart = 0;
Fariborz Jahanianbdd15f72008-01-04 23:23:46 +0000808 bool ForEach = false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000809
810 // Parse the first part of the for specifier.
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000811 if (Tok.is(tok::semi)) { // for (;
Reid Spencer5f016e22007-07-11 17:01:13 +0000812 // no first part, eat the ';'.
813 ConsumeToken();
Argyrios Kyrtzidisbbc70c02008-10-05 15:50:46 +0000814 } else if (isSimpleDeclaration()) { // for (int X = 4;
Reid Spencer5f016e22007-07-11 17:01:13 +0000815 // Parse declaration, which eats the ';'.
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000816 if (!C99orCXX) // Use of C99-style for loops in C90 mode?
Reid Spencer5f016e22007-07-11 17:01:13 +0000817 Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
Chris Lattner81c018d2008-03-13 06:29:04 +0000818
819 SourceLocation DeclStart = Tok.getLocation();
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000820 DeclTy *aBlockVarDecl = ParseSimpleDeclaration(Declarator::ForContext);
Chris Lattner81c018d2008-03-13 06:29:04 +0000821 // FIXME: Pass in the right location for the end of the declstmt.
822 StmtResult stmtResult = Actions.ActOnDeclStmt(aBlockVarDecl, DeclStart,
Chris Lattner691a38b2008-03-13 06:29:54 +0000823 DeclStart);
Reid Spencer5f016e22007-07-11 17:01:13 +0000824 FirstPart = stmtResult.isInvalid ? 0 : stmtResult.Val;
Fariborz Jahanianbdd15f72008-01-04 23:23:46 +0000825 if ((ForEach = isTokIdentifier_in())) {
Fariborz Jahanian3ba5a0f2008-01-03 17:55:25 +0000826 ConsumeToken(); // consume 'in'
827 Value = ParseExpression();
828 if (!Value.isInvalid)
829 SecondPart = Value.Val;
830 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000831 } else {
832 Value = ParseExpression();
833
834 // Turn the expression into a stmt.
835 if (!Value.isInvalid) {
Steve Naroff1b273c42007-09-16 14:56:35 +0000836 StmtResult R = Actions.ActOnExprStmt(Value.Val);
Reid Spencer5f016e22007-07-11 17:01:13 +0000837 if (!R.isInvalid)
838 FirstPart = R.Val;
839 }
840
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000841 if (Tok.is(tok::semi)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000842 ConsumeToken();
Fariborz Jahanian3ba5a0f2008-01-03 17:55:25 +0000843 }
Fariborz Jahanianbdd15f72008-01-04 23:23:46 +0000844 else if ((ForEach = isTokIdentifier_in())) {
Fariborz Jahanian3ba5a0f2008-01-03 17:55:25 +0000845 ConsumeToken(); // consume 'in'
846 Value = ParseExpression();
847 if (!Value.isInvalid)
848 SecondPart = Value.Val;
849 }
850 else {
Reid Spencer5f016e22007-07-11 17:01:13 +0000851 if (!Value.isInvalid) Diag(Tok, diag::err_expected_semi_for);
852 SkipUntil(tok::semi);
853 }
854 }
Fariborz Jahanianbdd15f72008-01-04 23:23:46 +0000855 if (!ForEach) {
Fariborz Jahanian3ba5a0f2008-01-03 17:55:25 +0000856 // Parse the second part of the for specifier.
857 if (Tok.is(tok::semi)) { // for (...;;
858 // no second part.
859 Value = ExprResult();
860 } else {
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +0000861 Value = getLang().CPlusPlus ? ParseCXXCondition()
862 : ParseExpression();
Fariborz Jahanian3ba5a0f2008-01-03 17:55:25 +0000863 if (!Value.isInvalid)
864 SecondPart = Value.Val;
865 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000866
Fariborz Jahanian3ba5a0f2008-01-03 17:55:25 +0000867 if (Tok.is(tok::semi)) {
868 ConsumeToken();
869 } else {
870 if (!Value.isInvalid) Diag(Tok, diag::err_expected_semi_for);
871 SkipUntil(tok::semi);
872 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000873
Fariborz Jahanian3ba5a0f2008-01-03 17:55:25 +0000874 // Parse the third part of the for specifier.
875 if (Tok.is(tok::r_paren)) { // for (...;...;)
876 // no third part.
877 Value = ExprResult();
878 } else {
879 Value = ParseExpression();
880 if (!Value.isInvalid) {
881 // Turn the expression into a stmt.
882 StmtResult R = Actions.ActOnExprStmt(Value.Val);
883 if (!R.isInvalid)
884 ThirdPart = R.Val;
885 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000886 }
887 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000888 // Match the ')'.
889 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
890
Chris Lattner0ecea032007-08-22 05:28:50 +0000891 // C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
Chris Lattner38484402007-08-22 05:33:11 +0000892 // there is no compound stmt. C90 does not have this clause. We only do this
893 // if the body isn't a compound statement to avoid push/pop in common cases.
Argyrios Kyrtzidis488d37e2008-09-11 03:06:46 +0000894 //
895 // C++ 6.5p2:
896 // The substatement in an iteration-statement implicitly defines a local scope
897 // which is entered and exited each time through the loop.
898 //
899 // See comments in ParseIfStatement for why we create a scope for
900 // for-init-statement/condition and a new scope for substatement in C++.
901 //
902 bool NeedsInnerScope = C99orCXX && Tok.isNot(tok::l_brace);
Chris Lattner31e05722007-08-26 06:24:45 +0000903 if (NeedsInnerScope) EnterScope(Scope::DeclScope);
Chris Lattner0ecea032007-08-22 05:28:50 +0000904
Reid Spencer5f016e22007-07-11 17:01:13 +0000905 // Read the body statement.
906 StmtResult Body = ParseStatement();
907
Chris Lattner0ecea032007-08-22 05:28:50 +0000908 // Pop the body scope if needed.
Chris Lattner38484402007-08-22 05:33:11 +0000909 if (NeedsInnerScope) ExitScope();
Chris Lattner0ecea032007-08-22 05:28:50 +0000910
Reid Spencer5f016e22007-07-11 17:01:13 +0000911 // Leave the for-scope.
912 ExitScope();
913
914 if (Body.isInvalid)
915 return Body;
916
Fariborz Jahanianbdd15f72008-01-04 23:23:46 +0000917 if (!ForEach)
918 return Actions.ActOnForStmt(ForLoc, LParenLoc, FirstPart,
919 SecondPart, ThirdPart, RParenLoc, Body.Val);
920 else
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000921 return Actions.ActOnObjCForCollectionStmt(ForLoc, LParenLoc, FirstPart,
Fariborz Jahanianbdd15f72008-01-04 23:23:46 +0000922 SecondPart, RParenLoc, Body.Val);
Reid Spencer5f016e22007-07-11 17:01:13 +0000923}
924
925/// ParseGotoStatement
926/// jump-statement:
927/// 'goto' identifier ';'
928/// [GNU] 'goto' '*' expression ';'
929///
930/// Note: this lets the caller parse the end ';'.
931///
932Parser::StmtResult Parser::ParseGotoStatement() {
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000933 assert(Tok.is(tok::kw_goto) && "Not a goto stmt!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000934 SourceLocation GotoLoc = ConsumeToken(); // eat the 'goto'.
935
936 StmtResult Res;
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000937 if (Tok.is(tok::identifier)) {
Steve Naroff1b273c42007-09-16 14:56:35 +0000938 Res = Actions.ActOnGotoStmt(GotoLoc, Tok.getLocation(),
Reid Spencer5f016e22007-07-11 17:01:13 +0000939 Tok.getIdentifierInfo());
940 ConsumeToken();
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000941 } else if (Tok.is(tok::star) && !getLang().NoExtensions) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000942 // GNU indirect goto extension.
943 Diag(Tok, diag::ext_gnu_indirect_goto);
944 SourceLocation StarLoc = ConsumeToken();
945 ExprResult R = ParseExpression();
946 if (R.isInvalid) { // Skip to the semicolon, but don't consume it.
947 SkipUntil(tok::semi, false, true);
948 return true;
949 }
Steve Naroff1b273c42007-09-16 14:56:35 +0000950 Res = Actions.ActOnIndirectGotoStmt(GotoLoc, StarLoc, R.Val);
Chris Lattner95cfb852007-07-22 04:13:33 +0000951 } else {
952 Diag(Tok, diag::err_expected_ident);
953 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000954 }
Chris Lattner95cfb852007-07-22 04:13:33 +0000955
Reid Spencer5f016e22007-07-11 17:01:13 +0000956 return Res;
957}
958
959/// ParseContinueStatement
960/// jump-statement:
961/// 'continue' ';'
962///
963/// Note: this lets the caller parse the end ';'.
964///
965Parser::StmtResult Parser::ParseContinueStatement() {
966 SourceLocation ContinueLoc = ConsumeToken(); // eat the 'continue'.
Steve Naroff1b273c42007-09-16 14:56:35 +0000967 return Actions.ActOnContinueStmt(ContinueLoc, CurScope);
Reid Spencer5f016e22007-07-11 17:01:13 +0000968}
969
970/// ParseBreakStatement
971/// jump-statement:
972/// 'break' ';'
973///
974/// Note: this lets the caller parse the end ';'.
975///
976Parser::StmtResult Parser::ParseBreakStatement() {
977 SourceLocation BreakLoc = ConsumeToken(); // eat the 'break'.
Steve Naroff1b273c42007-09-16 14:56:35 +0000978 return Actions.ActOnBreakStmt(BreakLoc, CurScope);
Reid Spencer5f016e22007-07-11 17:01:13 +0000979}
980
981/// ParseReturnStatement
982/// jump-statement:
983/// 'return' expression[opt] ';'
984Parser::StmtResult Parser::ParseReturnStatement() {
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000985 assert(Tok.is(tok::kw_return) && "Not a return stmt!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000986 SourceLocation ReturnLoc = ConsumeToken(); // eat the 'return'.
987
988 ExprResult R(0);
Chris Lattner4e1d99a2007-10-09 17:41:39 +0000989 if (Tok.isNot(tok::semi)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000990 R = ParseExpression();
991 if (R.isInvalid) { // Skip to the semicolon, but don't consume it.
992 SkipUntil(tok::semi, false, true);
993 return true;
994 }
995 }
Steve Naroff1b273c42007-09-16 14:56:35 +0000996 return Actions.ActOnReturnStmt(ReturnLoc, R.Val);
Reid Spencer5f016e22007-07-11 17:01:13 +0000997}
998
Steve Naroff5f8aa692008-02-11 23:15:56 +0000999/// FuzzyParseMicrosoftAsmStatement. When -fms-extensions is enabled, this
1000/// routine is called to skip/ignore tokens that comprise the MS asm statement.
Steve Naroffd62701b2008-02-07 03:50:06 +00001001Parser::StmtResult Parser::FuzzyParseMicrosoftAsmStatement() {
Steve Naroffb746ce82008-02-07 23:24:32 +00001002 if (Tok.is(tok::l_brace)) {
1003 unsigned short savedBraceCount = BraceCount;
1004 do {
1005 ConsumeAnyToken();
1006 } while (BraceCount > savedBraceCount && Tok.isNot(tok::eof));
1007 } else {
1008 // From the MS website: If used without braces, the __asm keyword means
1009 // that the rest of the line is an assembly-language statement.
1010 SourceManager &SrcMgr = PP.getSourceManager();
Steve Naroff03d6bc62008-02-08 03:36:19 +00001011 SourceLocation TokLoc = Tok.getLocation();
Steve Naroff36280972008-02-08 18:01:27 +00001012 unsigned lineNo = SrcMgr.getLogicalLineNumber(TokLoc);
1013 do {
1014 ConsumeAnyToken();
1015 TokLoc = Tok.getLocation();
1016 } while ((SrcMgr.getLogicalLineNumber(TokLoc) == lineNo) &&
1017 Tok.isNot(tok::r_brace) && Tok.isNot(tok::semi) &&
1018 Tok.isNot(tok::eof));
Steve Naroffb746ce82008-02-07 23:24:32 +00001019 }
Steve Naroffd77bc282008-04-07 21:06:54 +00001020 return Actions.ActOnNullStmt(Tok.getLocation());
Steve Naroffd62701b2008-02-07 03:50:06 +00001021}
1022
Reid Spencer5f016e22007-07-11 17:01:13 +00001023/// ParseAsmStatement - Parse a GNU extended asm statement.
Steve Naroff5f8aa692008-02-11 23:15:56 +00001024/// asm-statement:
1025/// gnu-asm-statement
1026/// ms-asm-statement
1027///
1028/// [GNU] gnu-asm-statement:
Reid Spencer5f016e22007-07-11 17:01:13 +00001029/// 'asm' type-qualifier[opt] '(' asm-argument ')' ';'
1030///
1031/// [GNU] asm-argument:
1032/// asm-string-literal
1033/// asm-string-literal ':' asm-operands[opt]
1034/// asm-string-literal ':' asm-operands[opt] ':' asm-operands[opt]
1035/// asm-string-literal ':' asm-operands[opt] ':' asm-operands[opt]
1036/// ':' asm-clobbers
1037///
1038/// [GNU] asm-clobbers:
1039/// asm-string-literal
1040/// asm-clobbers ',' asm-string-literal
1041///
Steve Naroff5f8aa692008-02-11 23:15:56 +00001042/// [MS] ms-asm-statement:
1043/// '__asm' assembly-instruction ';'[opt]
1044/// '__asm' '{' assembly-instruction-list '}' ';'[opt]
1045///
1046/// [MS] assembly-instruction-list:
1047/// assembly-instruction ';'[opt]
1048/// assembly-instruction-list ';' assembly-instruction ';'[opt]
1049///
Steve Naroffd62701b2008-02-07 03:50:06 +00001050Parser::StmtResult Parser::ParseAsmStatement(bool &msAsm) {
Chris Lattner4e1d99a2007-10-09 17:41:39 +00001051 assert(Tok.is(tok::kw_asm) && "Not an asm stmt");
Chris Lattnerfe795952007-10-29 04:04:16 +00001052 SourceLocation AsmLoc = ConsumeToken();
Reid Spencer5f016e22007-07-11 17:01:13 +00001053
Steve Naroff5f8aa692008-02-11 23:15:56 +00001054 if (getLang().Microsoft && Tok.isNot(tok::l_paren) && !isTypeQualifier()) {
Steve Naroffd62701b2008-02-07 03:50:06 +00001055 msAsm = true;
1056 return FuzzyParseMicrosoftAsmStatement();
1057 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001058 DeclSpec DS;
1059 SourceLocation Loc = Tok.getLocation();
1060 ParseTypeQualifierListOpt(DS);
1061
1062 // GNU asms accept, but warn, about type-qualifiers other than volatile.
1063 if (DS.getTypeQualifiers() & DeclSpec::TQ_const)
1064 Diag(Loc, diag::w_asm_qualifier_ignored, "const");
1065 if (DS.getTypeQualifiers() & DeclSpec::TQ_restrict)
1066 Diag(Loc, diag::w_asm_qualifier_ignored, "restrict");
1067
1068 // Remember if this was a volatile asm.
Anders Carlsson39c47b52007-11-23 23:12:25 +00001069 bool isVolatile = DS.getTypeQualifiers() & DeclSpec::TQ_volatile;
Anders Carlssondfab34a2008-02-05 23:03:50 +00001070 bool isSimple = false;
Chris Lattner4e1d99a2007-10-09 17:41:39 +00001071 if (Tok.isNot(tok::l_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001072 Diag(Tok, diag::err_expected_lparen_after, "asm");
1073 SkipUntil(tok::r_paren);
1074 return true;
1075 }
1076 Loc = ConsumeParen();
1077
Anders Carlsson6a0ef4b2007-11-20 19:21:03 +00001078 ExprResult AsmString = ParseAsmStringLiteral();
1079 if (AsmString.isInvalid)
1080 return true;
Anders Carlssonb235fc22007-11-22 01:36:19 +00001081
1082 llvm::SmallVector<std::string, 4> Names;
1083 llvm::SmallVector<ExprTy*, 4> Constraints;
1084 llvm::SmallVector<ExprTy*, 4> Exprs;
Anders Carlssonb235fc22007-11-22 01:36:19 +00001085 llvm::SmallVector<ExprTy*, 4> Clobbers;
Reid Spencer5f016e22007-07-11 17:01:13 +00001086
Anders Carlssondfab34a2008-02-05 23:03:50 +00001087 unsigned NumInputs = 0, NumOutputs = 0;
1088
1089 SourceLocation RParenLoc;
1090 if (Tok.is(tok::r_paren)) {
1091 // We have a simple asm expression
1092 isSimple = true;
1093
1094 RParenLoc = ConsumeParen();
1095 } else {
1096 // Parse Outputs, if present.
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001097 if (ParseAsmOperandsOpt(Names, Constraints, Exprs))
1098 return true;
Anders Carlssondfab34a2008-02-05 23:03:50 +00001099
1100 NumOutputs = Names.size();
1101
1102 // Parse Inputs, if present.
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001103 if (ParseAsmOperandsOpt(Names, Constraints, Exprs))
1104 return true;
1105
Anders Carlssondfab34a2008-02-05 23:03:50 +00001106 assert(Names.size() == Constraints.size() &&
1107 Constraints.size() == Exprs.size()
1108 && "Input operand size mismatch!");
1109
1110 NumInputs = Names.size() - NumOutputs;
1111
1112 // Parse the clobbers, if present.
1113 if (Tok.is(tok::colon)) {
Anders Carlssoneecf8472007-11-21 23:27:34 +00001114 ConsumeToken();
Anders Carlssondfab34a2008-02-05 23:03:50 +00001115
1116 // Parse the asm-string list for clobbers.
1117 while (1) {
1118 ExprResult Clobber = ParseAsmStringLiteral();
1119
1120 if (Clobber.isInvalid)
1121 break;
1122
1123 Clobbers.push_back(Clobber.Val);
1124
1125 if (Tok.isNot(tok::comma)) break;
1126 ConsumeToken();
1127 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001128 }
Anders Carlssondfab34a2008-02-05 23:03:50 +00001129
1130 RParenLoc = MatchRHSPunctuation(tok::r_paren, Loc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001131 }
1132
Anders Carlssondfab34a2008-02-05 23:03:50 +00001133 return Actions.ActOnAsmStmt(AsmLoc, isSimple, isVolatile,
1134 NumOutputs, NumInputs,
Anders Carlssonb235fc22007-11-22 01:36:19 +00001135 &Names[0], &Constraints[0], &Exprs[0],
1136 AsmString.Val,
1137 Clobbers.size(), &Clobbers[0],
1138 RParenLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001139}
1140
1141/// ParseAsmOperands - Parse the asm-operands production as used by
1142/// asm-statement. We also parse a leading ':' token. If the leading colon is
1143/// not present, we do not parse anything.
1144///
1145/// [GNU] asm-operands:
1146/// asm-operand
1147/// asm-operands ',' asm-operand
1148///
1149/// [GNU] asm-operand:
1150/// asm-string-literal '(' expression ')'
1151/// '[' identifier ']' asm-string-literal '(' expression ')'
1152///
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001153bool Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
Anders Carlssonb235fc22007-11-22 01:36:19 +00001154 llvm::SmallVectorImpl<ExprTy*> &Constraints,
1155 llvm::SmallVectorImpl<ExprTy*> &Exprs) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001156 // Only do anything if this operand is present.
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001157 if (Tok.isNot(tok::colon)) return false;
Reid Spencer5f016e22007-07-11 17:01:13 +00001158 ConsumeToken();
1159
1160 // 'asm-operands' isn't present?
Chris Lattner4e1d99a2007-10-09 17:41:39 +00001161 if (!isTokenStringLiteral() && Tok.isNot(tok::l_square))
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001162 return false;
Reid Spencer5f016e22007-07-11 17:01:13 +00001163
Anders Carlssonb235fc22007-11-22 01:36:19 +00001164 while (1) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001165 // Read the [id] if present.
Chris Lattner4e1d99a2007-10-09 17:41:39 +00001166 if (Tok.is(tok::l_square)) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001167 SourceLocation Loc = ConsumeBracket();
1168
Chris Lattner4e1d99a2007-10-09 17:41:39 +00001169 if (Tok.isNot(tok::identifier)) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001170 Diag(Tok, diag::err_expected_ident);
1171 SkipUntil(tok::r_paren);
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001172 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +00001173 }
Chris Lattner69efba72007-10-29 04:06:22 +00001174
Anders Carlssonb235fc22007-11-22 01:36:19 +00001175 IdentifierInfo *II = Tok.getIdentifierInfo();
Chris Lattner69efba72007-10-29 04:06:22 +00001176 ConsumeToken();
Anders Carlssonb235fc22007-11-22 01:36:19 +00001177
1178 Names.push_back(std::string(II->getName(), II->getLength()));
Reid Spencer5f016e22007-07-11 17:01:13 +00001179 MatchRHSPunctuation(tok::r_square, Loc);
Anders Carlssonb235fc22007-11-22 01:36:19 +00001180 } else
1181 Names.push_back(std::string());
Reid Spencer5f016e22007-07-11 17:01:13 +00001182
Anders Carlssonb235fc22007-11-22 01:36:19 +00001183 ExprResult Constraint = ParseAsmStringLiteral();
1184 if (Constraint.isInvalid) {
1185 SkipUntil(tok::r_paren);
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001186 return true;
Anders Carlssonb235fc22007-11-22 01:36:19 +00001187 }
1188 Constraints.push_back(Constraint.Val);
Reid Spencer5f016e22007-07-11 17:01:13 +00001189
Chris Lattner4e1d99a2007-10-09 17:41:39 +00001190 if (Tok.isNot(tok::l_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001191 Diag(Tok, diag::err_expected_lparen_after, "asm operand");
1192 SkipUntil(tok::r_paren);
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001193 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +00001194 }
1195
1196 // Read the parenthesized expression.
1197 ExprResult Res = ParseSimpleParenExpression();
1198 if (Res.isInvalid) {
1199 SkipUntil(tok::r_paren);
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001200 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +00001201 }
Anders Carlssonb235fc22007-11-22 01:36:19 +00001202 Exprs.push_back(Res.Val);
Reid Spencer5f016e22007-07-11 17:01:13 +00001203 // Eat the comma and continue parsing if it exists.
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001204 if (Tok.isNot(tok::comma)) return false;
Reid Spencer5f016e22007-07-11 17:01:13 +00001205 ConsumeToken();
1206 }
Anders Carlsson8bd36fc2008-02-09 19:57:29 +00001207
1208 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +00001209}
Fariborz Jahanianf9ed3152007-11-08 19:01:26 +00001210
1211Parser::DeclTy *Parser::ParseFunctionStatementBody(DeclTy *Decl,
1212 SourceLocation L, SourceLocation R) {
1213 // Do not enter a scope for the brace, as the arguments are in the same scope
1214 // (the function body) as the body itself. Instead, just read the statement
1215 // list and put it into a CompoundStmt for safe keeping.
1216 StmtResult FnBody = ParseCompoundStatementBody();
1217
1218 // If the function body could not be parsed, make a bogus compoundstmt.
1219 if (FnBody.isInvalid)
1220 FnBody = Actions.ActOnCompoundStmt(L, R, 0, 0, false);
1221
1222 // Leave the function body scope.
1223 ExitScope();
1224
Steve Naroffd6d054d2007-11-11 23:20:51 +00001225 return Actions.ActOnFinishFunctionBody(Decl, FnBody.Val);
Seo Sanghyeoncd5af4b2007-12-01 08:06:07 +00001226}