2006-11-05 15:46:30 +08:00
|
|
|
//===--- ParseStmt.cpp - Statement and Block Parser -----------------------===//
|
2006-08-09 13:47:47 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Statement and Block portions of the Parser
|
|
|
|
// interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Parse/Parser.h"
|
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2006-11-05 15:46:30 +08:00
|
|
|
#include "clang/Parse/SemaDecl.h"
|
2006-08-09 13:47:47 +08:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// C99 6.8: Statements and Blocks.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ParseStatementOrDeclaration - Read 'statement' or 'declaration'.
|
|
|
|
/// StatementOrDeclaration:
|
|
|
|
/// statement
|
|
|
|
/// declaration
|
|
|
|
///
|
|
|
|
/// statement:
|
|
|
|
/// labeled-statement
|
|
|
|
/// compound-statement
|
|
|
|
/// expression-statement
|
|
|
|
/// selection-statement
|
|
|
|
/// iteration-statement
|
|
|
|
/// jump-statement
|
|
|
|
/// [OBC] objc-throw-statement [TODO]
|
|
|
|
/// [OBC] objc-try-catch-statement [TODO]
|
|
|
|
/// [OBC] objc-synchronized-statement [TODO]
|
2006-08-15 14:03:28 +08:00
|
|
|
/// [GNU] asm-statement
|
2006-08-09 13:47:47 +08:00
|
|
|
/// [OMP] openmp-construct [TODO]
|
|
|
|
///
|
|
|
|
/// labeled-statement:
|
|
|
|
/// identifier ':' statement
|
|
|
|
/// 'case' constant-expression ':' statement
|
|
|
|
/// 'default' ':' statement
|
|
|
|
///
|
|
|
|
/// selection-statement:
|
|
|
|
/// if-statement
|
|
|
|
/// switch-statement
|
|
|
|
///
|
|
|
|
/// iteration-statement:
|
|
|
|
/// while-statement
|
|
|
|
/// do-statement
|
|
|
|
/// for-statement
|
|
|
|
///
|
2006-08-10 12:59:57 +08:00
|
|
|
/// expression-statement:
|
|
|
|
/// expression[opt] ';'
|
|
|
|
///
|
2006-08-09 13:47:47 +08:00
|
|
|
/// jump-statement:
|
|
|
|
/// 'goto' identifier ';'
|
|
|
|
/// 'continue' ';'
|
|
|
|
/// 'break' ';'
|
|
|
|
/// 'return' expression[opt] ';'
|
2006-08-10 13:45:44 +08:00
|
|
|
/// [GNU] 'goto' '*' expression ';'
|
2006-08-09 13:47:47 +08:00
|
|
|
///
|
|
|
|
/// [OBC] objc-throw-statement: [TODO]
|
|
|
|
/// [OBC] '@' 'throw' expression ';' [TODO]
|
|
|
|
/// [OBC] '@' 'throw' ';' [TODO]
|
|
|
|
///
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseStatementOrDeclaration(bool OnlyStatement) {
|
2006-08-10 13:45:44 +08:00
|
|
|
const char *SemiError = 0;
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Res;
|
2006-08-10 13:45:44 +08:00
|
|
|
|
|
|
|
// Cases in this switch statement should fall through if the parser expects
|
|
|
|
// the token to end in a semicolon (in which case SemiError should be set),
|
|
|
|
// or they directly 'return;' if not.
|
2006-08-09 13:47:47 +08:00
|
|
|
switch (Tok.getKind()) {
|
2006-08-11 02:26:31 +08:00
|
|
|
case tok::identifier: // C99 6.8.1: labeled-statement
|
|
|
|
// identifier ':' statement
|
|
|
|
// declaration (if !OnlyStatement)
|
|
|
|
// expression[opt] ';'
|
|
|
|
return ParseIdentifierStatement(OnlyStatement);
|
|
|
|
|
2006-08-09 13:47:47 +08:00
|
|
|
default:
|
2006-08-11 02:26:31 +08:00
|
|
|
if (!OnlyStatement && isDeclarationSpecifier()) {
|
|
|
|
// TODO: warn/disable if declaration is in the middle of a block and !C99.
|
|
|
|
ParseDeclaration(Declarator::BlockContext);
|
2006-10-16 13:52:41 +08:00
|
|
|
// FIXME: Make a DeclStmt node!
|
|
|
|
return 0;
|
2006-08-11 02:26:31 +08:00
|
|
|
} else if (Tok.getKind() == tok::r_brace) {
|
|
|
|
Diag(Tok, diag::err_expected_statement);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-11 02:26:31 +08:00
|
|
|
} else {
|
|
|
|
// expression[opt] ';'
|
2006-08-11 14:41:18 +08:00
|
|
|
ExprResult Res = ParseExpression();
|
|
|
|
if (Res.isInvalid) {
|
|
|
|
// If the expression is invalid, skip ahead to the next semicolon. Not
|
|
|
|
// doing this opens us up to the possibility of infinite loops if
|
|
|
|
// ParseExpression does not consume any tokens.
|
|
|
|
SkipUntil(tok::semi);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return Actions.ParseExprStmt(Res.Val);
|
2006-08-11 14:41:18 +08:00
|
|
|
}
|
2006-08-11 02:26:31 +08:00
|
|
|
}
|
2006-08-09 13:47:47 +08:00
|
|
|
|
2006-08-10 13:59:48 +08:00
|
|
|
case tok::kw_case: // C99 6.8.1: labeled-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
return ParseCaseStatement();
|
2006-08-10 13:59:48 +08:00
|
|
|
case tok::kw_default: // C99 6.8.1: labeled-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
return ParseDefaultStatement();
|
2006-08-10 12:59:57 +08:00
|
|
|
|
|
|
|
case tok::l_brace: // C99 6.8.2: compound-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
return ParseCompoundStatement();
|
2006-08-10 12:59:57 +08:00
|
|
|
case tok::semi: // C99 6.8.3: expression[opt] ';'
|
2006-10-16 13:52:41 +08:00
|
|
|
// TODO: Could return a NullStmt action result if we cared to.
|
2006-08-09 13:47:47 +08:00
|
|
|
ConsumeToken();
|
2006-10-16 13:52:41 +08:00
|
|
|
return 0;
|
2006-08-10 13:45:44 +08:00
|
|
|
|
2006-08-10 12:59:57 +08:00
|
|
|
case tok::kw_if: // C99 6.8.4.1: if-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
return ParseIfStatement();
|
2006-08-10 12:59:57 +08:00
|
|
|
case tok::kw_switch: // C99 6.8.4.2: switch-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
return ParseSwitchStatement();
|
2006-08-10 13:45:44 +08:00
|
|
|
|
2006-08-10 12:59:57 +08:00
|
|
|
case tok::kw_while: // C99 6.8.5.1: while-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
return ParseWhileStatement();
|
2006-08-10 12:59:57 +08:00
|
|
|
case tok::kw_do: // C99 6.8.5.2: do-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
Res = ParseDoStatement();
|
2006-08-10 13:45:44 +08:00
|
|
|
SemiError = "do/while loop";
|
2006-08-10 12:59:57 +08:00
|
|
|
break;
|
|
|
|
case tok::kw_for: // C99 6.8.5.3: for-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
return ParseForStatement();
|
2006-08-10 13:45:44 +08:00
|
|
|
|
|
|
|
case tok::kw_goto: // C99 6.8.6.1: goto-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
Res = ParseGotoStatement();
|
2006-08-10 13:45:44 +08:00
|
|
|
SemiError = "goto statement";
|
|
|
|
break;
|
|
|
|
case tok::kw_continue: // C99 6.8.6.2: continue-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
Res = Actions.ParseContinueStmt(Tok.getLocation());
|
2006-08-10 13:45:44 +08:00
|
|
|
ConsumeToken(); // eat the 'continue'.
|
|
|
|
SemiError = "continue statement";
|
2006-08-10 12:59:57 +08:00
|
|
|
break;
|
2006-08-10 13:45:44 +08:00
|
|
|
case tok::kw_break: // C99 6.8.6.3: break-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
Res = Actions.ParseBreakStmt(Tok.getLocation());
|
2006-08-10 13:45:44 +08:00
|
|
|
ConsumeToken(); // eat the 'break'.
|
|
|
|
SemiError = "break statement";
|
|
|
|
break;
|
|
|
|
case tok::kw_return: // C99 6.8.6.4: return-statement
|
2006-10-16 13:52:41 +08:00
|
|
|
Res = ParseReturnStatement();
|
2006-08-10 13:45:44 +08:00
|
|
|
SemiError = "return statement";
|
|
|
|
break;
|
2006-08-15 14:03:28 +08:00
|
|
|
|
|
|
|
case tok::kw_asm:
|
2006-10-16 13:52:41 +08:00
|
|
|
Res = ParseAsmStatement();
|
2006-08-15 14:03:28 +08:00
|
|
|
SemiError = "asm statement";
|
|
|
|
break;
|
2006-08-09 13:47:47 +08:00
|
|
|
}
|
2006-08-10 13:45:44 +08:00
|
|
|
|
|
|
|
// If we reached this code, the statement must end in a semicolon.
|
|
|
|
if (Tok.getKind() == tok::semi) {
|
|
|
|
ConsumeToken();
|
|
|
|
} else {
|
|
|
|
Diag(Tok, diag::err_expected_semi_after, SemiError);
|
|
|
|
SkipUntil(tok::semi);
|
|
|
|
}
|
2006-10-16 13:52:41 +08:00
|
|
|
return Res;
|
2006-08-09 13:47:47 +08:00
|
|
|
}
|
|
|
|
|
2006-08-11 02:26:31 +08:00
|
|
|
/// ParseIdentifierStatement - Because we don't have two-token lookahead, we
|
|
|
|
/// have a bit of a quandry here. Reading the identifier is necessary to see if
|
|
|
|
/// there is a ':' after it. If there is, this is a label, regardless of what
|
|
|
|
/// else the identifier can mean. If not, this is either part of a declaration
|
|
|
|
/// (if the identifier is a type-name) or part of an expression.
|
2006-08-11 02:31:37 +08:00
|
|
|
///
|
|
|
|
/// labeled-statement:
|
|
|
|
/// identifier ':' statement
|
2006-08-15 12:50:22 +08:00
|
|
|
/// [GNU] identifier ':' attributes[opt] statement
|
2006-08-11 02:31:37 +08:00
|
|
|
/// declaration (if !OnlyStatement)
|
|
|
|
/// expression[opt] ';'
|
|
|
|
///
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseIdentifierStatement(bool OnlyStatement) {
|
2006-08-11 02:31:37 +08:00
|
|
|
IdentifierInfo *II = Tok.getIdentifierInfo();
|
|
|
|
assert(Tok.getKind() == tok::identifier && II && "Not an identifier!");
|
2006-11-05 04:32:01 +08:00
|
|
|
II=II; // FIXME: SILENCE WARNING UNTIL THIS IS USED.
|
2006-08-11 02:31:37 +08:00
|
|
|
|
2006-10-16 13:52:41 +08:00
|
|
|
LexerToken IdentTok = Tok; // Save the whole token.
|
2006-08-11 02:31:37 +08:00
|
|
|
ConsumeToken(); // eat the identifier.
|
2006-08-11 02:26:31 +08:00
|
|
|
|
2006-08-11 02:31:37 +08:00
|
|
|
// identifier ':' statement
|
|
|
|
if (Tok.getKind() == tok::colon) {
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation ColonLoc = ConsumeToken();
|
2006-08-15 12:50:22 +08:00
|
|
|
|
|
|
|
// Read label attributes, if present.
|
|
|
|
if (Tok.getKind() == tok::kw___attribute)
|
2006-10-16 13:52:41 +08:00
|
|
|
// TODO: save these somewhere.
|
2006-08-15 12:50:22 +08:00
|
|
|
ParseAttributes();
|
|
|
|
|
2006-10-16 13:52:41 +08:00
|
|
|
StmtResult SubStmt = ParseStatement();
|
|
|
|
if (SubStmt.isInvalid) return true;
|
|
|
|
|
|
|
|
// FIXME: Enter this label into the symbol table for the function.
|
2006-10-25 11:38:23 +08:00
|
|
|
return Actions.ParseLabelStmt(IdentTok.getLocation(),
|
|
|
|
IdentTok.getIdentifierInfo(),
|
|
|
|
ColonLoc, SubStmt.Val);
|
2006-08-11 02:31:37 +08:00
|
|
|
}
|
2006-08-11 02:26:31 +08:00
|
|
|
|
2006-10-16 13:52:41 +08:00
|
|
|
// Check to see if this is a declaration.
|
2006-08-14 08:45:39 +08:00
|
|
|
if (!OnlyStatement &&
|
2006-10-28 07:18:49 +08:00
|
|
|
Actions.isTypeName(*IdentTok.getIdentifierInfo(), CurScope)) {
|
2006-08-11 02:31:37 +08:00
|
|
|
// Handle this. Warn/disable if in middle of block and !C99.
|
2006-08-11 02:39:24 +08:00
|
|
|
DeclSpec DS;
|
|
|
|
|
|
|
|
// FIXME: Add the typedef name to the start of the decl-specs.
|
|
|
|
// ParseDeclarationSpecifiers will continue from there.
|
|
|
|
ParseDeclarationSpecifiers(DS);
|
|
|
|
|
2006-08-14 03:58:17 +08:00
|
|
|
// C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"
|
|
|
|
// declaration-specifiers init-declarator-list[opt] ';'
|
|
|
|
if (Tok.getKind() == tok::semi) {
|
|
|
|
// TODO: emit error on 'int;' or 'const enum foo;'.
|
|
|
|
// if (!DS.isMissingDeclaratorOk()) Diag(...);
|
|
|
|
|
|
|
|
ConsumeToken();
|
2006-10-16 13:52:41 +08:00
|
|
|
// FIXME: Return this as a type decl.
|
|
|
|
return 0;
|
2006-08-14 03:58:17 +08:00
|
|
|
}
|
|
|
|
|
2006-08-11 02:39:24 +08:00
|
|
|
// Parse all the declarators.
|
|
|
|
Declarator DeclaratorInfo(DS, Declarator::BlockContext);
|
|
|
|
ParseDeclarator(DeclaratorInfo);
|
|
|
|
|
|
|
|
ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
|
2006-10-16 13:52:41 +08:00
|
|
|
// FIXME: Return this as a declstmt.
|
|
|
|
return 0;
|
2006-08-11 02:31:37 +08:00
|
|
|
}
|
|
|
|
|
2006-08-13 02:12:45 +08:00
|
|
|
// Otherwise, this is an expression. Seed it with II and parse it.
|
|
|
|
ExprResult Res = ParseExpressionWithLeadingIdentifier(IdentTok);
|
2006-10-16 13:52:41 +08:00
|
|
|
if (Res.isInvalid) {
|
2006-08-13 02:12:45 +08:00
|
|
|
SkipUntil(tok::semi);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
|
|
|
} else if (Tok.getKind() != tok::semi) {
|
2006-08-13 02:12:45 +08:00
|
|
|
Diag(Tok, diag::err_expected_semi_after, "expression");
|
|
|
|
SkipUntil(tok::semi);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
ConsumeToken();
|
|
|
|
return Actions.ParseExprStmt(Res.Val);
|
2006-08-13 02:12:45 +08:00
|
|
|
}
|
2006-08-11 02:26:31 +08:00
|
|
|
}
|
|
|
|
|
2006-08-10 13:59:48 +08:00
|
|
|
/// ParseCaseStatement
|
|
|
|
/// labeled-statement:
|
|
|
|
/// 'case' constant-expression ':' statement
|
2006-08-14 06:09:58 +08:00
|
|
|
/// [GNU] 'case' constant-expression '...' constant-expression ':' statement
|
2006-08-14 05:54:02 +08:00
|
|
|
///
|
2006-08-10 13:59:48 +08:00
|
|
|
/// Note that this does not parse the 'statement' at the end.
|
|
|
|
///
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseCaseStatement() {
|
2006-08-10 13:59:48 +08:00
|
|
|
assert(Tok.getKind() == tok::kw_case && "Not a case stmt!");
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation CaseLoc = ConsumeToken(); // eat the 'case'.
|
2006-08-10 13:59:48 +08:00
|
|
|
|
2006-10-16 13:52:41 +08:00
|
|
|
ExprResult LHS = ParseConstantExpression();
|
|
|
|
if (LHS.isInvalid) {
|
2006-08-14 06:09:58 +08:00
|
|
|
SkipUntil(tok::colon);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-14 06:09:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GNU case range extension.
|
2006-10-16 13:52:41 +08:00
|
|
|
SourceLocation DotDotDotLoc;
|
|
|
|
ExprTy *RHSVal = 0;
|
2006-08-14 06:09:58 +08:00
|
|
|
if (Tok.getKind() == tok::ellipsis) {
|
|
|
|
Diag(Tok, diag::ext_gnu_case_range);
|
2006-10-16 14:06:51 +08:00
|
|
|
DotDotDotLoc = ConsumeToken();
|
2006-08-14 06:09:58 +08:00
|
|
|
|
|
|
|
ExprResult RHS = ParseConstantExpression();
|
|
|
|
if (RHS.isInvalid) {
|
|
|
|
SkipUntil(tok::colon);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-14 06:09:58 +08:00
|
|
|
}
|
2006-10-16 13:52:41 +08:00
|
|
|
RHSVal = RHS.Val;
|
2006-08-14 06:09:58 +08:00
|
|
|
}
|
2006-08-10 13:59:48 +08:00
|
|
|
|
2006-10-16 13:52:41 +08:00
|
|
|
if (Tok.getKind() != tok::colon) {
|
2006-08-10 13:59:48 +08:00
|
|
|
Diag(Tok, diag::err_expected_colon_after, "'case'");
|
|
|
|
SkipUntil(tok::colon);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-10 13:59:48 +08:00
|
|
|
}
|
2006-10-16 13:52:41 +08:00
|
|
|
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation ColonLoc = ConsumeToken();
|
2006-10-16 13:52:41 +08:00
|
|
|
|
|
|
|
// Diagnose the common error "switch (X) { case 4: }", which is not valid.
|
|
|
|
if (Tok.getKind() == tok::r_brace) {
|
|
|
|
Diag(Tok, diag::err_label_end_of_compound_statement);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
StmtResult SubStmt = ParseStatement();
|
|
|
|
if (SubStmt.isInvalid)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// TODO: look up enclosing switch stmt.
|
|
|
|
return Actions.ParseCaseStmt(CaseLoc, LHS.Val, DotDotDotLoc, RHSVal, ColonLoc,
|
|
|
|
SubStmt.Val);
|
2006-08-10 13:59:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseDefaultStatement
|
|
|
|
/// labeled-statement:
|
|
|
|
/// 'default' ':' statement
|
|
|
|
/// Note that this does not parse the 'statement' at the end.
|
|
|
|
///
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseDefaultStatement() {
|
2006-08-10 13:59:48 +08:00
|
|
|
assert(Tok.getKind() == tok::kw_default && "Not a default stmt!");
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation DefaultLoc = ConsumeToken(); // eat the 'default'.
|
2006-08-10 13:59:48 +08:00
|
|
|
|
2006-10-16 13:52:41 +08:00
|
|
|
if (Tok.getKind() != tok::colon) {
|
2006-08-10 13:59:48 +08:00
|
|
|
Diag(Tok, diag::err_expected_colon_after, "'default'");
|
|
|
|
SkipUntil(tok::colon);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation ColonLoc = ConsumeToken();
|
2006-10-16 13:52:41 +08:00
|
|
|
|
|
|
|
// Diagnose the common error "switch (X) {... default: }", which is not valid.
|
|
|
|
if (Tok.getKind() == tok::r_brace) {
|
|
|
|
Diag(Tok, diag::err_label_end_of_compound_statement);
|
|
|
|
return true;
|
2006-08-10 13:59:48 +08:00
|
|
|
}
|
2006-10-16 13:52:41 +08:00
|
|
|
|
|
|
|
StmtResult SubStmt = ParseStatement();
|
|
|
|
if (SubStmt.isInvalid)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// TODO: look up enclosing switch stmt.
|
|
|
|
return Actions.ParseDefaultStmt(DefaultLoc, ColonLoc, SubStmt.Val);
|
2006-08-10 13:59:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-09 13:47:47 +08:00
|
|
|
/// ParseCompoundStatement - Parse a "{}" block.
|
|
|
|
///
|
|
|
|
/// compound-statement: [C99 6.8.2]
|
|
|
|
/// { block-item-list[opt] }
|
|
|
|
/// [GNU] { label-declarations block-item-list } [TODO]
|
|
|
|
///
|
|
|
|
/// block-item-list:
|
|
|
|
/// block-item
|
|
|
|
/// block-item-list block-item
|
|
|
|
///
|
|
|
|
/// block-item:
|
|
|
|
/// declaration
|
|
|
|
/// [GNU] '__extension__' declaration [TODO]
|
|
|
|
/// statement
|
|
|
|
/// [OMP] openmp-directive [TODO]
|
|
|
|
///
|
|
|
|
/// [GNU] label-declarations:
|
|
|
|
/// [GNU] label-declaration
|
|
|
|
/// [GNU] label-declarations label-declaration
|
|
|
|
///
|
|
|
|
/// [GNU] label-declaration:
|
|
|
|
/// [GNU] '__label__' identifier-list ';'
|
|
|
|
///
|
|
|
|
/// [OMP] openmp-directive: [TODO]
|
|
|
|
/// [OMP] barrier-directive
|
|
|
|
/// [OMP] flush-directive
|
2006-10-16 13:52:41 +08:00
|
|
|
///
|
|
|
|
Parser::StmtResult Parser::ParseCompoundStatement() {
|
2006-08-09 13:47:47 +08:00
|
|
|
assert(Tok.getKind() == tok::l_brace && "Not a compount stmt!");
|
2006-10-16 14:12:55 +08:00
|
|
|
SourceLocation LBraceLoc = ConsumeBrace(); // eat the '{'.
|
2006-08-09 13:47:47 +08:00
|
|
|
|
2006-10-25 11:38:23 +08:00
|
|
|
// Enter a scope to hold everything within the compound stmt.
|
2006-10-25 11:15:33 +08:00
|
|
|
EnterScope();
|
|
|
|
|
2006-10-16 13:52:41 +08:00
|
|
|
SmallVector<StmtTy*, 32> Stmts;
|
|
|
|
while (Tok.getKind() != tok::r_brace && Tok.getKind() != tok::eof) {
|
|
|
|
StmtResult R = ParseStatementOrDeclaration(false);
|
|
|
|
if (!R.isInvalid && R.Val)
|
|
|
|
Stmts.push_back(R.Val);
|
|
|
|
}
|
2006-08-09 13:47:47 +08:00
|
|
|
|
|
|
|
// We broke out of the while loop because we found a '}' or EOF.
|
2006-10-16 13:52:41 +08:00
|
|
|
if (Tok.getKind() != tok::r_brace) {
|
2006-08-09 13:47:47 +08:00
|
|
|
Diag(Tok, diag::err_expected_rbrace);
|
2006-10-16 13:52:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-25 11:15:33 +08:00
|
|
|
ExitScope();
|
|
|
|
|
2006-10-16 14:12:55 +08:00
|
|
|
SourceLocation RBraceLoc = ConsumeBrace();
|
2006-10-16 13:52:41 +08:00
|
|
|
return Actions.ParseCompoundStmt(LBraceLoc, RBraceLoc,
|
|
|
|
&Stmts[0], Stmts.size());
|
2006-08-09 13:47:47 +08:00
|
|
|
}
|
2006-08-10 12:23:57 +08:00
|
|
|
|
|
|
|
/// ParseIfStatement
|
|
|
|
/// if-statement: [C99 6.8.4.1]
|
|
|
|
/// 'if' '(' expression ')' statement
|
|
|
|
/// 'if' '(' expression ')' statement 'else' statement
|
2006-10-16 13:52:41 +08:00
|
|
|
///
|
|
|
|
Parser::StmtResult Parser::ParseIfStatement() {
|
2006-08-10 12:23:57 +08:00
|
|
|
assert(Tok.getKind() == tok::kw_if && "Not an if stmt!");
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation IfLoc = ConsumeToken(); // eat the 'if'.
|
2006-08-10 12:23:57 +08:00
|
|
|
|
|
|
|
if (Tok.getKind() != tok::l_paren) {
|
2006-08-10 12:59:57 +08:00
|
|
|
Diag(Tok, diag::err_expected_lparen_after, "if");
|
2006-08-10 12:23:57 +08:00
|
|
|
SkipUntil(tok::semi);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-10 12:23:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the condition.
|
2006-10-16 13:52:41 +08:00
|
|
|
ExprResult CondExp = ParseSimpleParenExpression();
|
|
|
|
if (CondExp.isInvalid) {
|
|
|
|
SkipUntil(tok::semi);
|
|
|
|
return true;
|
|
|
|
}
|
2006-08-10 12:23:57 +08:00
|
|
|
|
|
|
|
// Read the if condition.
|
2006-10-16 13:52:41 +08:00
|
|
|
StmtResult CondStmt = ParseStatement();
|
2006-08-10 12:23:57 +08:00
|
|
|
|
|
|
|
// If it has an else, parse it.
|
2006-10-16 13:52:41 +08:00
|
|
|
SourceLocation ElseLoc;
|
|
|
|
StmtResult ElseStmt(false);
|
2006-08-10 12:23:57 +08:00
|
|
|
if (Tok.getKind() == tok::kw_else) {
|
2006-10-16 14:06:51 +08:00
|
|
|
ElseLoc = ConsumeToken();
|
2006-10-16 13:52:41 +08:00
|
|
|
ElseStmt = ParseStatement();
|
2006-08-10 12:23:57 +08:00
|
|
|
}
|
2006-10-16 13:52:41 +08:00
|
|
|
|
|
|
|
if (CondStmt.isInvalid || ElseStmt.isInvalid)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return Actions.ParseIfStmt(IfLoc, CondExp.Val, CondStmt.Val,
|
|
|
|
ElseLoc, ElseStmt.Val);
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseSwitchStatement
|
|
|
|
/// switch-statement:
|
|
|
|
/// 'switch' '(' expression ')' statement
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseSwitchStatement() {
|
2006-08-10 12:59:57 +08:00
|
|
|
assert(Tok.getKind() == tok::kw_switch && "Not a switch stmt!");
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation SwitchLoc = ConsumeToken(); // eat the 'switch'.
|
2006-08-10 12:59:57 +08:00
|
|
|
|
|
|
|
if (Tok.getKind() != tok::l_paren) {
|
|
|
|
Diag(Tok, diag::err_expected_lparen_after, "switch");
|
|
|
|
SkipUntil(tok::semi);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
2006-08-10 12:23:57 +08:00
|
|
|
|
2006-08-10 12:59:57 +08:00
|
|
|
// Parse the condition.
|
2006-10-16 13:52:41 +08:00
|
|
|
ExprResult Cond = ParseSimpleParenExpression();
|
2006-08-10 12:59:57 +08:00
|
|
|
|
|
|
|
// Read the body statement.
|
2006-10-16 13:52:41 +08:00
|
|
|
StmtResult Body = ParseStatement();
|
|
|
|
|
|
|
|
if (Cond.isInvalid || Body.isInvalid) return true;
|
|
|
|
|
|
|
|
return Actions.ParseSwitchStmt(SwitchLoc, Cond.Val, Body.Val);
|
2006-08-10 12:23:57 +08:00
|
|
|
}
|
|
|
|
|
2006-08-10 12:59:57 +08:00
|
|
|
/// ParseWhileStatement
|
|
|
|
/// while-statement: [C99 6.8.5.1]
|
|
|
|
/// 'while' '(' expression ')' statement
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseWhileStatement() {
|
2006-08-10 12:59:57 +08:00
|
|
|
assert(Tok.getKind() == tok::kw_while && "Not a while stmt!");
|
2006-10-16 13:52:41 +08:00
|
|
|
SourceLocation WhileLoc = Tok.getLocation();
|
2006-08-10 12:59:57 +08:00
|
|
|
ConsumeToken(); // eat the 'while'.
|
|
|
|
|
|
|
|
if (Tok.getKind() != tok::l_paren) {
|
|
|
|
Diag(Tok, diag::err_expected_lparen_after, "while");
|
|
|
|
SkipUntil(tok::semi);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the condition.
|
2006-10-16 13:52:41 +08:00
|
|
|
ExprResult Cond = ParseSimpleParenExpression();
|
2006-08-10 12:59:57 +08:00
|
|
|
|
|
|
|
// Read the body statement.
|
2006-10-16 13:52:41 +08:00
|
|
|
StmtResult Body = ParseStatement();
|
|
|
|
|
|
|
|
if (Cond.isInvalid || Body.isInvalid) return true;
|
|
|
|
|
|
|
|
return Actions.ParseWhileStmt(WhileLoc, Cond.Val, Body.Val);
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseDoStatement
|
|
|
|
/// do-statement: [C99 6.8.5.2]
|
|
|
|
/// 'do' statement 'while' '(' expression ')' ';'
|
2006-08-10 13:45:44 +08:00
|
|
|
/// Note: this lets the caller parse the end ';'.
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseDoStatement() {
|
2006-08-10 12:59:57 +08:00
|
|
|
assert(Tok.getKind() == tok::kw_do && "Not a do stmt!");
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation DoLoc = ConsumeToken(); // eat the 'do'.
|
2006-08-10 12:59:57 +08:00
|
|
|
|
|
|
|
// Read the body statement.
|
2006-10-16 13:52:41 +08:00
|
|
|
StmtResult Body = ParseStatement();
|
2006-08-10 12:59:57 +08:00
|
|
|
|
|
|
|
if (Tok.getKind() != tok::kw_while) {
|
|
|
|
Diag(Tok, diag::err_expected_while);
|
2006-08-11 06:57:16 +08:00
|
|
|
Diag(DoLoc, diag::err_matching, "do");
|
2006-08-10 12:59:57 +08:00
|
|
|
SkipUntil(tok::semi);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation WhileLoc = ConsumeToken();
|
2006-08-10 12:59:57 +08:00
|
|
|
|
|
|
|
if (Tok.getKind() != tok::l_paren) {
|
|
|
|
Diag(Tok, diag::err_expected_lparen_after, "do/while");
|
|
|
|
SkipUntil(tok::semi);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the condition.
|
2006-10-16 13:52:41 +08:00
|
|
|
ExprResult Cond = ParseSimpleParenExpression();
|
|
|
|
if (Cond.isInvalid || Body.isInvalid) return true;
|
|
|
|
|
|
|
|
return Actions.ParseDoStmt(DoLoc, Body.Val, WhileLoc, Cond.Val);
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseForStatement
|
|
|
|
/// for-statement: [C99 6.8.5.3]
|
|
|
|
/// 'for' '(' expr[opt] ';' expr[opt] ';' expr[opt] ')' statement
|
|
|
|
/// 'for' '(' declaration expr[opt] ';' expr[opt] ')' statement
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseForStatement() {
|
2006-08-10 12:59:57 +08:00
|
|
|
assert(Tok.getKind() == tok::kw_for && "Not a for stmt!");
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation ForLoc = ConsumeToken(); // eat the 'for'.
|
2006-08-10 12:59:57 +08:00
|
|
|
|
|
|
|
if (Tok.getKind() != tok::l_paren) {
|
|
|
|
Diag(Tok, diag::err_expected_lparen_after, "for");
|
|
|
|
SkipUntil(tok::semi);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
|
|
|
|
2006-10-16 14:12:55 +08:00
|
|
|
SourceLocation LParenLoc = ConsumeParen();
|
2006-08-11 14:41:18 +08:00
|
|
|
ExprResult Value;
|
|
|
|
|
2006-11-05 04:18:38 +08:00
|
|
|
StmtTy *FirstPart = 0;
|
|
|
|
ExprTy *SecondPart = 0, *ThirdPart = 0;
|
|
|
|
|
2006-08-10 12:59:57 +08:00
|
|
|
// Parse the first part of the for specifier.
|
|
|
|
if (Tok.getKind() == tok::semi) { // for (;
|
2006-08-10 13:19:57 +08:00
|
|
|
// no first part, eat the ';'.
|
|
|
|
ConsumeToken();
|
2006-08-10 12:59:57 +08:00
|
|
|
} else if (isDeclarationSpecifier()) { // for (int X = 4;
|
2006-08-10 13:19:57 +08:00
|
|
|
// Parse declaration, which eats the ';'.
|
2006-08-10 13:22:36 +08:00
|
|
|
if (!getLang().C99) // Use of C99-style for loops in C90 mode?
|
|
|
|
Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
|
2006-08-10 13:19:57 +08:00
|
|
|
ParseDeclaration(Declarator::ForContext);
|
2006-11-05 04:18:38 +08:00
|
|
|
// FIXME: Turn declaration into stmt.
|
|
|
|
FirstPart = 0;
|
2006-08-10 12:59:57 +08:00
|
|
|
} else {
|
2006-08-11 14:41:18 +08:00
|
|
|
Value = ParseExpression();
|
2006-11-05 04:18:38 +08:00
|
|
|
|
|
|
|
// Turn the expression into a stmt.
|
|
|
|
if (!Value.isInvalid) {
|
|
|
|
StmtResult R = Actions.ParseExprStmt(Value.Val);
|
|
|
|
if (!R.isInvalid)
|
|
|
|
FirstPart = R.Val;
|
|
|
|
}
|
|
|
|
|
2006-08-10 13:19:57 +08:00
|
|
|
if (Tok.getKind() == tok::semi) {
|
|
|
|
ConsumeToken();
|
|
|
|
} else {
|
2006-08-11 14:41:18 +08:00
|
|
|
if (!Value.isInvalid) Diag(Tok, diag::err_expected_semi_for);
|
2006-08-10 13:19:57 +08:00
|
|
|
SkipUntil(tok::semi);
|
|
|
|
}
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the second part of the for specifier.
|
|
|
|
if (Tok.getKind() == tok::semi) { // for (...;;
|
|
|
|
// no second part.
|
2006-08-11 14:41:18 +08:00
|
|
|
Value = ExprResult();
|
2006-08-10 12:59:57 +08:00
|
|
|
} else {
|
2006-08-11 14:41:18 +08:00
|
|
|
Value = ParseExpression();
|
2006-11-05 04:18:38 +08:00
|
|
|
if (!Value.isInvalid)
|
|
|
|
SecondPart = Value.Val;
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.getKind() == tok::semi) {
|
|
|
|
ConsumeToken();
|
|
|
|
} else {
|
2006-08-11 14:41:18 +08:00
|
|
|
if (!Value.isInvalid) Diag(Tok, diag::err_expected_semi_for);
|
2006-08-10 12:59:57 +08:00
|
|
|
SkipUntil(tok::semi);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the third part of the for specifier.
|
|
|
|
if (Tok.getKind() == tok::r_paren) { // for (...;...;)
|
|
|
|
// no third part.
|
2006-08-11 14:41:18 +08:00
|
|
|
Value = ExprResult();
|
2006-08-10 12:59:57 +08:00
|
|
|
} else {
|
2006-08-11 14:41:18 +08:00
|
|
|
Value = ParseExpression();
|
2006-11-05 04:18:38 +08:00
|
|
|
if (!Value.isInvalid)
|
|
|
|
ThirdPart = Value.Val;
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
|
|
|
|
2006-08-11 07:14:52 +08:00
|
|
|
// Match the ')'.
|
2006-11-05 04:18:38 +08:00
|
|
|
SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
|
2006-08-10 12:59:57 +08:00
|
|
|
|
|
|
|
// Read the body statement.
|
2006-11-05 04:18:38 +08:00
|
|
|
StmtResult Body = ParseStatement();
|
|
|
|
if (Body.isInvalid)
|
|
|
|
return Body;
|
2006-10-16 13:52:41 +08:00
|
|
|
|
2006-11-05 04:18:38 +08:00
|
|
|
return Actions.ParseForStmt(ForLoc, LParenLoc, FirstPart, SecondPart,
|
|
|
|
ThirdPart, RParenLoc, Body.Val);
|
2006-08-10 12:59:57 +08:00
|
|
|
}
|
2006-08-10 12:23:57 +08:00
|
|
|
|
2006-08-10 13:45:44 +08:00
|
|
|
/// ParseGotoStatement
|
|
|
|
/// jump-statement:
|
|
|
|
/// 'goto' identifier ';'
|
|
|
|
/// [GNU] 'goto' '*' expression ';'
|
|
|
|
///
|
|
|
|
/// Note: this lets the caller parse the end ';'.
|
|
|
|
///
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseGotoStatement() {
|
2006-08-10 13:45:44 +08:00
|
|
|
assert(Tok.getKind() == tok::kw_goto && "Not a goto stmt!");
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation GotoLoc = ConsumeToken(); // eat the 'goto'.
|
2006-08-10 13:45:44 +08:00
|
|
|
|
2006-10-16 13:52:41 +08:00
|
|
|
StmtResult Res;
|
2006-08-10 13:45:44 +08:00
|
|
|
if (Tok.getKind() == tok::identifier) {
|
2006-10-25 11:38:23 +08:00
|
|
|
Res = Actions.ParseGotoStmt(GotoLoc, Tok.getLocation(),
|
|
|
|
Tok.getIdentifierInfo());
|
2006-08-10 13:45:44 +08:00
|
|
|
ConsumeToken();
|
|
|
|
} else if (Tok.getKind() == tok::star && !getLang().NoExtensions) {
|
|
|
|
// GNU indirect goto extension.
|
|
|
|
Diag(Tok, diag::ext_gnu_indirect_goto);
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation StarLoc = ConsumeToken();
|
2006-08-13 00:59:03 +08:00
|
|
|
ExprResult R = ParseExpression();
|
2006-10-16 13:52:41 +08:00
|
|
|
if (R.isInvalid) { // Skip to the semicolon, but don't consume it.
|
2006-08-13 00:59:03 +08:00
|
|
|
SkipUntil(tok::semi, false, true);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Res = Actions.ParseIndirectGotoStmt(GotoLoc, StarLoc, R.Val);
|
2006-08-10 13:45:44 +08:00
|
|
|
}
|
2006-10-16 13:52:41 +08:00
|
|
|
return Res;
|
2006-08-10 13:45:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseReturnStatement
|
|
|
|
/// jump-statement:
|
|
|
|
/// 'return' expression[opt] ';'
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseReturnStatement() {
|
2006-08-10 13:45:44 +08:00
|
|
|
assert(Tok.getKind() == tok::kw_return && "Not a return stmt!");
|
2006-10-16 14:06:51 +08:00
|
|
|
SourceLocation ReturnLoc = ConsumeToken(); // eat the 'return'.
|
2006-08-10 13:45:44 +08:00
|
|
|
|
2006-10-16 13:52:41 +08:00
|
|
|
ExprResult R(0);
|
2006-08-13 00:59:03 +08:00
|
|
|
if (Tok.getKind() != tok::semi) {
|
2006-10-16 13:52:41 +08:00
|
|
|
R = ParseExpression();
|
|
|
|
if (R.isInvalid) { // Skip to the semicolon, but don't consume it.
|
2006-08-13 00:59:03 +08:00
|
|
|
SkipUntil(tok::semi, false, true);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
2006-08-13 00:59:03 +08:00
|
|
|
}
|
2006-10-16 13:52:41 +08:00
|
|
|
return Actions.ParseReturnStmt(ReturnLoc, R.Val);
|
2006-08-10 13:45:44 +08:00
|
|
|
}
|
2006-08-15 14:03:28 +08:00
|
|
|
|
|
|
|
/// ParseAsmStatement - Parse a GNU extended asm statement.
|
|
|
|
/// [GNU] asm-statement:
|
|
|
|
/// 'asm' type-qualifier[opt] '(' asm-argument ')' ';'
|
|
|
|
///
|
|
|
|
/// [GNU] asm-argument:
|
|
|
|
/// asm-string-literal
|
|
|
|
/// asm-string-literal ':' asm-operands[opt]
|
|
|
|
/// asm-string-literal ':' asm-operands[opt] ':' asm-operands[opt]
|
|
|
|
/// asm-string-literal ':' asm-operands[opt] ':' asm-operands[opt]
|
|
|
|
/// ':' asm-clobbers
|
|
|
|
///
|
|
|
|
/// [GNU] asm-clobbers:
|
|
|
|
/// asm-string-literal
|
|
|
|
/// asm-clobbers ',' asm-string-literal
|
|
|
|
///
|
2006-10-16 13:52:41 +08:00
|
|
|
Parser::StmtResult Parser::ParseAsmStatement() {
|
2006-08-15 14:03:28 +08:00
|
|
|
assert(Tok.getKind() == tok::kw_asm && "Not an asm stmt");
|
|
|
|
ConsumeToken();
|
|
|
|
|
|
|
|
DeclSpec DS;
|
|
|
|
SourceLocation Loc = Tok.getLocation();
|
|
|
|
ParseTypeQualifierListOpt(DS);
|
|
|
|
|
|
|
|
// GNU asms accept, but warn, about type-qualifiers other than volatile.
|
|
|
|
if (DS.TypeQualifiers & DeclSpec::TQ_const)
|
|
|
|
Diag(Loc, diag::w_asm_qualifier_ignored, "const");
|
|
|
|
if (DS.TypeQualifiers & DeclSpec::TQ_restrict)
|
|
|
|
Diag(Loc, diag::w_asm_qualifier_ignored, "restrict");
|
|
|
|
|
|
|
|
// Remember if this was a volatile asm.
|
2006-10-18 12:02:28 +08:00
|
|
|
//bool isVolatile = DS.TypeQualifiers & DeclSpec::TQ_volatile;
|
2006-08-15 14:03:28 +08:00
|
|
|
|
|
|
|
if (Tok.getKind() != tok::l_paren) {
|
|
|
|
Diag(Tok, diag::err_expected_lparen_after, "asm");
|
|
|
|
SkipUntil(tok::r_paren);
|
2006-10-16 13:52:41 +08:00
|
|
|
return true;
|
2006-08-15 14:03:28 +08:00
|
|
|
}
|
2006-10-16 14:12:55 +08:00
|
|
|
Loc = ConsumeParen();
|
2006-08-15 14:03:28 +08:00
|
|
|
|
|
|
|
ParseAsmStringLiteral();
|
|
|
|
|
|
|
|
// Parse Outputs, if present.
|
|
|
|
ParseAsmOperandsOpt();
|
|
|
|
|
|
|
|
// Parse Inputs, if present.
|
|
|
|
ParseAsmOperandsOpt();
|
|
|
|
|
|
|
|
// Parse the clobbers, if present.
|
|
|
|
if (Tok.getKind() == tok::colon) {
|
|
|
|
ConsumeToken();
|
|
|
|
|
2006-10-06 13:22:26 +08:00
|
|
|
if (isTokenStringLiteral()) {
|
2006-08-15 14:03:28 +08:00
|
|
|
// Parse the asm-string list for clobbers.
|
|
|
|
while (1) {
|
|
|
|
ParseAsmStringLiteral();
|
|
|
|
|
|
|
|
if (Tok.getKind() != tok::comma) break;
|
|
|
|
ConsumeToken();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MatchRHSPunctuation(tok::r_paren, Loc);
|
2006-10-16 13:52:41 +08:00
|
|
|
|
|
|
|
// FIXME: Implement action for asm parsing.
|
|
|
|
return false;
|
2006-08-15 14:03:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseAsmOperands - Parse the asm-operands production as used by
|
|
|
|
/// asm-statement. We also parse a leading ':' token. If the leading colon is
|
|
|
|
/// not present, we do not parse anything.
|
|
|
|
///
|
|
|
|
/// [GNU] asm-operands:
|
|
|
|
/// asm-operand
|
|
|
|
/// asm-operands ',' asm-operand
|
|
|
|
///
|
|
|
|
/// [GNU] asm-operand:
|
|
|
|
/// asm-string-literal '(' expression ')'
|
|
|
|
/// '[' identifier ']' asm-string-literal '(' expression ')'
|
|
|
|
///
|
|
|
|
void Parser::ParseAsmOperandsOpt() {
|
|
|
|
// Only do anything if this operand is present.
|
|
|
|
if (Tok.getKind() != tok::colon) return;
|
|
|
|
ConsumeToken();
|
|
|
|
|
|
|
|
// 'asm-operands' isn't present?
|
2006-10-06 13:22:26 +08:00
|
|
|
if (!isTokenStringLiteral() && Tok.getKind() != tok::l_square)
|
2006-08-15 14:03:28 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// Read the [id] if present.
|
|
|
|
if (Tok.getKind() == tok::l_square) {
|
2006-10-16 14:12:55 +08:00
|
|
|
SourceLocation Loc = ConsumeBracket();
|
2006-08-15 14:03:28 +08:00
|
|
|
|
|
|
|
if (Tok.getKind() != tok::identifier) {
|
|
|
|
Diag(Tok, diag::err_expected_ident);
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MatchRHSPunctuation(tok::r_square, Loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
ParseAsmStringLiteral();
|
|
|
|
|
|
|
|
if (Tok.getKind() != tok::l_paren) {
|
|
|
|
Diag(Tok, diag::err_expected_lparen_after, "asm operand");
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the parenthesized expression.
|
2006-08-24 14:37:51 +08:00
|
|
|
ExprResult Res = ParseSimpleParenExpression();
|
2006-08-15 14:03:28 +08:00
|
|
|
if (Res.isInvalid) {
|
|
|
|
SkipUntil(tok::r_paren);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eat the comma and continue parsing if it exists.
|
|
|
|
if (Tok.getKind() != tok::comma) return;
|
|
|
|
ConsumeToken();
|
|
|
|
}
|
|
|
|
}
|