[cfe-commits] r38869 - in /cfe/cfe/trunk: Parse/ParseExpr.cpp include/clang/Parse/Parser.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:25:20 PDT 2007
Author: sabre
Date: Wed Jul 11 11:25:20 2007
New Revision: 38869
URL: http://llvm.org/viewvc/llvm-project?rev=38869&view=rev
Log:
Merge ParseUnaryExpression and ParseCastExpression.
Modified:
cfe/cfe/trunk/Parse/ParseExpr.cpp
cfe/cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=38869&r1=38868&r2=38869&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:25:20 2007
@@ -38,7 +38,7 @@
Parser::ExprTy Parser::ParseExpression() {
- ParseCastExpression();
+ ParseCastExpression(false);
return 0;
}
@@ -47,37 +47,12 @@
ParseExpression();
}
-/// ParseCastExpression
+/// ParseCastExpression - Parse a cast-expression, or, if isUnaryExpression is
+/// true, parse a unary-expression.
+///
/// cast-expression: [C99 6.5.4]
/// unary-expression
/// '(' type-name ')' cast-expression
-///
-void Parser::ParseCastExpression() {
- // If this doesn't start with an '(', then it is a unary-expression.
- if (Tok.getKind() != tok::l_paren)
- return ParseUnaryExpression();
-
- ParenParseOption ParenExprType = CastExpr;
- ParseParenExpression(ParenExprType);
-
- switch (ParenExprType) {
- case SimpleExpr: break; // Nothing to do.
- case CompoundStmt: break; // Nothing to do.
- case CompoundLiteral:
- // We parsed '(' type-name ')' '{' ... '}'. If any suffixes of
- // postfix-expression exist, parse them now.
- //Diag(Tok, diag::err_parse_error);
- //assert(0 && "FIXME");
- break;
- case CastExpr:
- // We parsed '(' type-name ')' and the thing after it wasn't a '{'. Parse
- // the cast-expression that follows it next.
- ParseCastExpression();
- break;
- }
-}
-
-/// ParseUnaryExpression
/// unary-expression: [C99 6.5.3]
/// postfix-expression
/// '++' unary-expression
@@ -92,15 +67,39 @@
/// '&' '*' '+' '-' '~' '!'
/// [GNU] '__extension__' '__real' '__imag'
///
-void Parser::ParseUnaryExpression() {
+///
+void Parser::ParseCastExpression(bool isUnaryExpression) {
+ // If this doesn't start with an '(', then it is a unary-expression.
switch (Tok.getKind()) {
+ case tok::l_paren:
+ // If this expression is limited to being a unary-expression, the parent can
+ // not start a cast expression.
+ ParenParseOption ParenExprType =
+ isUnaryExpression ? CompoundLiteral : CastExpr;
+ ParseParenExpression(ParenExprType);
+
+ switch (ParenExprType) {
+ case SimpleExpr: return; // Nothing else to do.
+ case CompoundStmt: return; // Nothing else to do.
+ case CompoundLiteral:
+ // We parsed '(' type-name ')' '{' ... '}'. If any suffixes of
+ // postfix-expression exist, parse them now.
+ //Diag(Tok, diag::err_parse_error);
+ //assert(0 && "FIXME");
+ return;
+ case CastExpr:
+ // We parsed '(' type-name ')' and the thing after it wasn't a '{'. Parse
+ // the cast-expression that follows it next.
+ ParseCastExpression(false);
+ return;
+ }
default: // unary-expression: postfix-expression
ParsePostfixExpression();
break;
case tok::plusplus: // unary-expression: '++' unary-expression
case tok::minusminus: // unary-expression: '--' unary-expression
ConsumeToken();
- ParseUnaryExpression();
+ ParseCastExpression(true);
break;
case tok::amp: // unary-expression: '&' cast-expression
case tok::star: // unary-expression: '*' cast-expression
@@ -112,7 +111,7 @@
case tok::kw___imag: // unary-expression: '__real' cast-expression [GNU]
//case tok::kw__extension__: [TODO]
ConsumeToken();
- ParseCastExpression();
+ ParseCastExpression(false);
break;
case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression
@@ -149,7 +148,7 @@
// If the operand doesn't start with an '(', it must be an expression.
if (Tok.getKind() != tok::l_paren) {
- ParseUnaryExpression();
+ ParseCastExpression(true);
return;
}
Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=38869&r1=38868&r2=38869&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:25:20 2007
@@ -172,8 +172,7 @@
//ExprTy ParseExpression(); // Above.
void ParseAssignmentExpression(); // Expr that doesn't include commas.
- void ParseCastExpression();
- void ParseUnaryExpression();
+ void ParseCastExpression(bool isUnaryExpression);
void ParseSizeofAlignofExpression();
void ParsePostfixExpression();
More information about the cfe-commits
mailing list