[cfe-commits] r38885 - 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:29 PDT 2007
Author: sabre
Date: Wed Jul 11 11:25:28 2007
New Revision: 38885
URL: http://llvm.org/viewvc/llvm-project?rev=38885&view=rev
Log:
Split postfix-expression suffix handling out into ParsePostfixExpressionSuffix
for future use.
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=38885&r1=38884&r2=38885&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:25:28 2007
@@ -302,21 +302,6 @@
/// '&' '*' '+' '-' '~' '!'
/// [GNU] '__extension__' '__real' '__imag'
///
-/// postfix-expression: [C99 6.5.2]
-/// primary-expression
-/// postfix-expression '[' expression ']'
-/// postfix-expression '(' argument-expression-list[opt] ')'
-/// postfix-expression '.' identifier
-/// postfix-expression '->' identifier
-/// postfix-expression '++'
-/// postfix-expression '--'
-/// '(' type-name ')' '{' initializer-list '}'
-/// '(' type-name ')' '{' initializer-list ',' '}'
-///
-/// argument-expression-list: [C99 6.5.2]
-/// argument-expression
-/// argument-expression-list ',' assignment-expression
-///
/// primary-expression: [C99 6.5.1]
/// identifier
/// constant
@@ -348,7 +333,6 @@
/// [GNU] offsetof-member-designator '.' identifier
/// [GNU] offsetof-member-designator '[' expression ']'
///
-///
Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) {
ExprResult Res;
@@ -359,9 +343,9 @@
// expression, or statement expression.
//
// If the parsed tokens consist of a primary-expression, the cases below
- // 'break' out of the switch. This allows the postfix expression pieces to
- // be applied to them. Cases that cannot be followed by postfix exprs should
- // return instead.
+ // call ParsePostfixExpressionSuffix to handle the postfix expression
+ // suffixes. Cases that cannot be followed by postfix exprs should
+ // return without invoking ParsePostfixExpressionSuffix.
switch (Tok.getKind()) {
case tok::l_paren:
// If this expression is limited to being a unary-expression, the parent can
@@ -383,7 +367,9 @@
// the cast-expression that follows it next.
return ParseCastExpression(false);
}
- break; // These can be followed by postfix-expr pieces.
+
+ // These can be followed by postfix-expr pieces.
+ return ParsePostfixExpressionSuffix(Res);
// primary-expression
case tok::identifier: // primary-expression: identifier
@@ -394,17 +380,22 @@
case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2]
case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU]
case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU]
+ Res = ExprResult(false);
ConsumeToken();
- break;
+ // These can be followed by postfix-expr pieces.
+ return ParsePostfixExpressionSuffix(Res);
case tok::string_literal: // primary-expression: string-literal
Res = ParseStringLiteralExpression();
if (Res.isInvalid) return Res;
- break;
+ // This can be followed by postfix-expr pieces (e.g. "foo"[1]).
+ return ParsePostfixExpressionSuffix(Res);
case tok::kw___builtin_va_arg:
case tok::kw___builtin_offsetof:
case tok::kw___builtin_choose_expr:
case tok::kw___builtin_types_compatible_p:
assert(0 && "FIXME: UNIMP!");
+ // This can be followed by postfix-expr pieces.
+ return ParsePostfixExpressionSuffix(Res);
case tok::plusplus: // unary-expression: '++' unary-expression
case tok::minusminus: // unary-expression: '--' unary-expression
ConsumeToken();
@@ -441,13 +432,38 @@
return ExprResult(true);
}
+ // unreachable.
+ abort();
+}
+
+/// ParsePostfixExpressionSuffix - Once the leading part of a postfix-expression
+/// is parsed, this method parses any suffixes that apply.
+///
+/// postfix-expression: [C99 6.5.2]
+/// primary-expression
+/// postfix-expression '[' expression ']'
+/// postfix-expression '(' argument-expression-list[opt] ')'
+/// postfix-expression '.' identifier
+/// postfix-expression '->' identifier
+/// postfix-expression '++'
+/// postfix-expression '--'
+/// '(' type-name ')' '{' initializer-list '}'
+/// '(' type-name ')' '{' initializer-list ',' '}'
+///
+/// argument-expression-list: [C99 6.5.2]
+/// argument-expression
+/// argument-expression-list ',' assignment-expression
+///
+Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
+ assert(!LHS.isInvalid && "LHS is invalid already!");
+
// Now that the primary-expression piece of the postfix-expression has been
// parsed, see if there are any postfix-expression pieces here.
SourceLocation Loc;
while (1) {
switch (Tok.getKind()) {
- default:
- return ExprResult(false);
+ default: // Not a postfix-expression suffix.
+ return LHS;
case tok::l_square: // postfix-expression: p-e '[' expression ']'
Loc = Tok.getLocation();
ConsumeBracket();
@@ -489,6 +505,7 @@
}
}
+
/// ParseSizeofAlignofExpression - Parse a sizeof or alignof expression.
/// unary-expression: [C99 6.5.3]
/// 'sizeof' unary-expression
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=38885&r1=38884&r2=38885&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:25:28 2007
@@ -182,6 +182,7 @@
ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec);
ExprResult ParseCastExpression(bool isUnaryExpression);
+ ExprResult ParsePostfixExpressionSuffix(ExprResult LHS);
ExprResult ParseSizeofAlignofExpression();
/// ParenParseOption - Control what ParseParenExpression will parse.
More information about the cfe-commits
mailing list