[cfe-commits] r89827 - in /cfe/trunk: include/clang/Parse/Action.h include/clang/Parse/Parser.h lib/Parse/ParseExpr.cpp lib/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/TreeTransform.h
Fariborz Jahanian
fjahanian at apple.com
Tue Nov 24 17:26:41 PST 2009
Author: fjahanian
Date: Tue Nov 24 19:26:41 2009
New Revision: 89827
URL: http://llvm.org/viewvc/llvm-project?rev=89827&view=rev
Log:
Some fancy footwork to move the decision on how
to build casted expression-list AST to Sema.
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/TreeTransform.h
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=89827&r1=89826&r2=89827&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Nov 24 19:26:41 2009
@@ -992,9 +992,10 @@
return move(Val); // Default impl returns operand.
}
- virtual OwningExprResult ActOnParenListExpr(SourceLocation L,
+ virtual OwningExprResult ActOnParenOrParenListExpr(SourceLocation L,
SourceLocation R,
- MultiExprArg Val) {
+ MultiExprArg Val,
+ TypeTy *TypeOfCast=0) {
return ExprEmpty();
}
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=89827&r1=89826&r2=89827&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Nov 24 19:26:41 2009
@@ -833,10 +833,10 @@
OwningExprResult ParseCastExpression(bool isUnaryExpression,
bool isAddressOfOperand,
bool &NotCastExpr,
- bool parseParenAsExprList);
+ TypeTy *TypeOfCast);
OwningExprResult ParseCastExpression(bool isUnaryExpression,
bool isAddressOfOperand = false,
- bool parseParenAsExprList = false);
+ TypeTy *TypeOfCast = 0);
OwningExprResult ParsePostfixExpressionSuffix(OwningExprResult LHS);
OwningExprResult ParseSizeofAlignofExpression();
OwningExprResult ParseBuiltinPrimaryExpression();
@@ -866,7 +866,7 @@
};
OwningExprResult ParseParenExpression(ParenParseOption &ExprType,
bool stopIfCastExpr,
- bool parseAsExprList,
+ TypeTy *TypeOfCast,
TypeTy *&CastTy,
SourceLocation &RParenLoc);
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=89827&r1=89826&r2=89827&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Tue Nov 24 19:26:41 2009
@@ -413,12 +413,12 @@
///
Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression,
bool isAddressOfOperand,
- bool parseParenAsExprList){
+ TypeTy *TypeOfCast) {
bool NotCastExpr;
OwningExprResult Res = ParseCastExpression(isUnaryExpression,
isAddressOfOperand,
NotCastExpr,
- parseParenAsExprList);
+ TypeOfCast);
if (NotCastExpr)
Diag(Tok, diag::err_expected_expression);
return move(Res);
@@ -538,7 +538,7 @@
Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression,
bool isAddressOfOperand,
bool &NotCastExpr,
- bool parseParenAsExprList){
+ TypeTy *TypeOfCast) {
OwningExprResult Res(Actions);
tok::TokenKind SavedKind = Tok.getKind();
NotCastExpr = false;
@@ -563,7 +563,7 @@
SourceLocation LParenLoc = Tok.getLocation();
SourceLocation RParenLoc;
Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
- parseParenAsExprList, CastTy, RParenLoc);
+ TypeOfCast, CastTy, RParenLoc);
if (Res.isInvalid()) return move(Res);
switch (ParenExprType) {
@@ -1047,7 +1047,8 @@
// operands.
EnterExpressionEvaluationContext Unevaluated(Actions,
Action::Unevaluated);
- Operand = ParseParenExpression(ExprType, true/*stopIfCastExpr*/, false,
+ Operand = ParseParenExpression(ExprType, true/*stopIfCastExpr*/,
+ 0/*TypeOfCast*/,
CastTy, RParenLoc);
CastRange = SourceRange(LParenLoc, RParenLoc);
@@ -1304,7 +1305,7 @@
///
Parser::OwningExprResult
Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
- bool parseAsExprList, TypeTy *&CastTy,
+ TypeTy *TypeOfCast, TypeTy *&CastTy,
SourceLocation &RParenLoc) {
assert(Tok.is(tok::l_paren) && "Not a paren expr!");
GreaterThanIsOperatorScope G(GreaterThanIsOperator, true);
@@ -1365,8 +1366,7 @@
// Parse the cast-expression that follows it next.
// TODO: For cast expression with CastTy.
- Result = ParseCastExpression(false, false,
- Actions.TypeIsVectorType(CastTy));
+ Result = ParseCastExpression(false, false, CastTy);
if (!Result.isInvalid())
Result = Actions.ActOnCastExpr(CurScope, OpenLoc, CastTy, RParenLoc,
move(Result));
@@ -1375,15 +1375,15 @@
Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
return ExprError();
- } else if (parseAsExprList) {
+ } else if (TypeOfCast) {
// Parse the expression-list.
ExprVector ArgExprs(Actions);
CommaLocsTy CommaLocs;
if (!ParseExpressionList(ArgExprs, CommaLocs)) {
ExprType = SimpleExpr;
- Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
- move_arg(ArgExprs));
+ Result = Actions.ActOnParenOrParenListExpr(OpenLoc, Tok.getLocation(),
+ move_arg(ArgExprs), TypeOfCast);
}
} else {
Result = ParseExpression();
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=89827&r1=89826&r2=89827&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Nov 24 19:26:41 2009
@@ -1443,9 +1443,10 @@
virtual OwningExprResult ActOnCharacterConstant(const Token &);
virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
ExprArg Val);
- virtual OwningExprResult ActOnParenListExpr(SourceLocation L,
+ virtual OwningExprResult ActOnParenOrParenListExpr(SourceLocation L,
SourceLocation R,
- MultiExprArg Val);
+ MultiExprArg Val,
+ TypeTy *TypeOfCast=0);
/// ActOnStringLiteral - The specified tokens were lexed as pasted string
/// fragments (e.g. "foo" "bar" L"baz").
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=89827&r1=89826&r2=89827&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Nov 24 19:26:41 2009
@@ -3328,13 +3328,18 @@
}
}
-Action::OwningExprResult Sema::ActOnParenListExpr(SourceLocation L,
+Action::OwningExprResult Sema::ActOnParenOrParenListExpr(SourceLocation L,
SourceLocation R,
- MultiExprArg Val) {
+ MultiExprArg Val,
+ TypeTy *TypeOfCast) {
unsigned nexprs = Val.size();
Expr **exprs = reinterpret_cast<Expr**>(Val.release());
- assert((exprs != 0) && "ActOnParenListExpr() missing expr list");
- Expr *expr = new (Context) ParenListExpr(Context, L, exprs, nexprs, R);
+ assert((exprs != 0) && "ActOnParenOrParenListExpr() missing expr list");
+ Expr *expr;
+ if (nexprs == 1 && TypeOfCast && !TypeIsVectorType(TypeOfCast))
+ expr = new (Context) ParenExpr(L, R, exprs[0]);
+ else
+ expr = new (Context) ParenListExpr(Context, L, exprs, nexprs, R);
return Owned(expr);
}
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=89827&r1=89826&r2=89827&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Tue Nov 24 19:26:41 2009
@@ -1120,7 +1120,8 @@
OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
MultiExprArg SubExprs,
SourceLocation RParenLoc) {
- return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
+ return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
+ move(SubExprs));
}
/// \brief Build a new address-of-label expression.
More information about the cfe-commits
mailing list