From 0cd5b429fad6833dda23f0aced14a10907ac5539 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 16 Aug 2008 20:03:01 +0000 Subject: [PATCH] Put (argument)-expression-list parsing in a separate function so that it can be re-used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54851 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Parse/Parser.h | 6 +++++ lib/Parse/ParseExpr.cpp | 44 ++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 83ec0a7a8c..2a6e505d64 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -386,6 +386,12 @@ private: ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); ExprResult ParseSizeofAlignofExpression(); ExprResult ParseBuiltinPrimaryExpression(); + + typedef llvm::SmallVector ExprListTy; + typedef llvm::SmallVector CommaLocsTy; + + /// ParseExpressionList - Used for C/C++ (argument-)expression-list. + bool ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs); /// ParenParseOption - Control what ParseParenExpression will parse. enum ParenParseOption { diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 4b45cb73f6..16bd1cba04 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -607,24 +607,15 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { } case tok::l_paren: { // p-e: p-e '(' argument-expression-list[opt] ')' - llvm::SmallVector ArgExprs; - llvm::SmallVector CommaLocs; + ExprListTy ArgExprs; + CommaLocsTy CommaLocs; Loc = ConsumeParen(); if (Tok.isNot(tok::r_paren)) { - while (1) { - ExprResult ArgExpr = ParseAssignmentExpression(); - if (ArgExpr.isInvalid) { - SkipUntil(tok::r_paren); - return ExprResult(true); - } else - ArgExprs.push_back(ArgExpr.Val); - - if (Tok.isNot(tok::comma)) - break; - // Move to the next argument, remember where the comma was. - CommaLocs.push_back(ConsumeToken()); + if (ParseExpressionList(ArgExprs, CommaLocs)) { + SkipUntil(tok::r_paren); + return ExprResult(true); } } @@ -1010,3 +1001,28 @@ Parser::ExprResult Parser::ParseStringLiteralExpression() { // Pass the set of string tokens, ready for concatenation, to the actions. return Actions.ActOnStringLiteral(&StringToks[0], StringToks.size()); } + +/// ParseExpressionList - Used for C/C++ (argument-)expression-list. +/// +/// argument-expression-list: +/// assignment-expression +/// argument-expression-list , assignment-expression +/// +/// [C++] expression-list: +/// [C++] assignment-expression +/// [C++] expression-list , assignment-expression +/// +bool Parser::ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs) { + while (1) { + ExprResult Expr = ParseAssignmentExpression(); + if (Expr.isInvalid) + return true; + else + Exprs.push_back(Expr.Val); + + if (Tok.isNot(tok::comma)) + return false; + // Move to the next argument, remember where the comma was. + CommaLocs.push_back(ConsumeToken()); + } +} -- 2.40.0