[cfe-commits] r54851 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseExpr.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Sat Aug 16 13:03:01 PDT 2008
Author: akirtzidis
Date: Sat Aug 16 15:03:01 2008
New Revision: 54851
URL: http://llvm.org/viewvc/llvm-project?rev=54851&view=rev
Log:
Put (argument)-expression-list parsing in a separate function so that it can be re-used.
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseExpr.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=54851&r1=54850&r2=54851&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sat Aug 16 15:03:01 2008
@@ -386,6 +386,12 @@
ExprResult ParsePostfixExpressionSuffix(ExprResult LHS);
ExprResult ParseSizeofAlignofExpression();
ExprResult ParseBuiltinPrimaryExpression();
+
+ typedef llvm::SmallVector<ExprTy*, 8> ExprListTy;
+ typedef llvm::SmallVector<SourceLocation, 8> CommaLocsTy;
+
+ /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
+ bool ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs);
/// ParenParseOption - Control what ParseParenExpression will parse.
enum ParenParseOption {
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=54851&r1=54850&r2=54851&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Sat Aug 16 15:03:01 2008
@@ -607,24 +607,15 @@
}
case tok::l_paren: { // p-e: p-e '(' argument-expression-list[opt] ')'
- llvm::SmallVector<ExprTy*, 8> ArgExprs;
- llvm::SmallVector<SourceLocation, 8> 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 @@
// 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());
+ }
+}
More information about the cfe-commits
mailing list