diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-09-09 20:38:47 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-09-09 20:38:47 +0000 |
| commit | 2b4072fe5544c8c07a69b216424845d83efc2938 (patch) | |
| tree | 91d84956f6d4488b961f861d448b9f1ef65889ea /clang/lib/Parse/ParseExprCXX.cpp | |
| parent | 53b728c27c76f3b97139ebfd8dc8d219c275b4fc (diff) | |
| download | bcm5719-llvm-2b4072fe5544c8c07a69b216424845d83efc2938.tar.gz bcm5719-llvm-2b4072fe5544c8c07a69b216424845d83efc2938.zip | |
Implement parser support for the 'condition' part of C++ selection-statements and iteration-statements (if/switch/while/for).
Add new 'ActOnCXXConditionDeclarationExpr' action, called when the 'condition' is a declaration instead of an expression.
llvm-svn: 56007
Diffstat (limited to 'clang/lib/Parse/ParseExprCXX.cpp')
| -rw-r--r-- | clang/lib/Parse/ParseExprCXX.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index bd8e7d510ea..28071b6e29d 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -153,6 +153,55 @@ Parser::ExprResult Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) { &CommaLocs[0], RParenLoc); } +/// ParseCXXCondition - if/switch/while/for condition expression. +/// +/// condition: +/// expression +/// type-specifier-seq declarator '=' assignment-expression +/// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt] +/// '=' assignment-expression +/// +Parser::ExprResult Parser::ParseCXXCondition() { + if (!isDeclarationSpecifier()) + return ParseExpression(); // expression + + SourceLocation StartLoc = Tok.getLocation(); + + // type-specifier-seq + DeclSpec DS; + ParseSpecifierQualifierList(DS); + + // declarator + Declarator DeclaratorInfo(DS, Declarator::ConditionContext); + ParseDeclarator(DeclaratorInfo); + + // simple-asm-expr[opt] + if (Tok.is(tok::kw_asm)) { + ExprResult AsmLabel = ParseSimpleAsm(); + if (AsmLabel.isInvalid) { + SkipUntil(tok::semi); + return true; + } + DeclaratorInfo.setAsmLabel(AsmLabel.Val); + } + + // If attributes are present, parse them. + if (Tok.is(tok::kw___attribute)) + DeclaratorInfo.AddAttributes(ParseAttributes()); + + // '=' assignment-expression + if (Tok.isNot(tok::equal)) + return Diag(Tok, diag::err_expected_equal_after_declarator); + SourceLocation EqualLoc = ConsumeToken(); + ExprResult AssignExpr = ParseAssignmentExpression(); + if (AssignExpr.isInvalid) + return true; + + return Actions.ActOnCXXConditionDeclarationExpr(CurScope, StartLoc, + DeclaratorInfo, + EqualLoc, AssignExpr.Val); +} + /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. /// This should only be called when the current token is known to be part of /// simple-type-specifier. |

