[cfe-commits] r71982 - in /cfe/trunk: include/clang/Parse/Action.h include/clang/Parse/Parser.h lib/Parse/ParseStmt.cpp lib/Sema/Sema.h lib/Sema/SemaStmt.cpp lib/Sema/SemaTemplateInstantiateStmt.cpp tools/clang-cc/PrintParserCallbacks.cpp
Anders Carlsson
andersca at mac.com
Sun May 17 11:26:54 PDT 2009
Author: andersca
Date: Sun May 17 13:26:53 2009
New Revision: 71982
URL: http://llvm.org/viewvc/llvm-project?rev=71982&view=rev
Log:
Add the FullExprArg wrapper and use it for if statement conditions.
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateStmt.cpp
cfe/trunk/tools/clang-cc/PrintParserCallbacks.cpp
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=71982&r1=71981&r2=71982&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Sun May 17 13:26:53 2009
@@ -102,6 +102,34 @@
typedef ASTMultiPtr<&ActionBase::DeleteStmt> MultiStmtArg;
typedef ASTMultiPtr<&ActionBase::DeleteTemplateParams> MultiTemplateParamsArg;
+ class FullExprArg {
+ public:
+ FullExprArg(const FullExprArg& Other)
+ : Expr(move(const_cast<FullExprArg&>(Other).Expr)) {}
+
+ OwningExprResult release() {
+ return move(Expr);
+ }
+
+ ExprArg* operator->() {
+ return &Expr;
+ }
+
+ private:
+ // FIXME: No need to make the entire Action class a friend when it's just
+ // Action::FullExpr that needs access to the constructor below.
+ friend class Action;
+
+ explicit FullExprArg(ExprArg expr)
+ : Expr(move(expr)) {}
+
+ ExprArg Expr;
+ };
+
+ FullExprArg FullExpr(ExprArg &Arg) {
+ return FullExprArg(ActOnFinishFullExpr(move(Arg)));
+ }
+
// Utilities for Action implementations to return smart results.
OwningExprResult ExprError() { return OwningExprResult(*this, true); }
@@ -461,8 +489,9 @@
return StmtEmpty();
}
- virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
- StmtArg ThenVal, SourceLocation ElseLoc,
+ virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc,
+ FullExprArg CondVal, StmtArg ThenVal,
+ SourceLocation ElseLoc,
StmtArg ElseVal) {
return StmtEmpty();
}
@@ -1042,6 +1071,13 @@
return ExprEmpty();
}
+
+ /// ActOnFinishFullExpr - Called whenever a full expression has been parsed.
+ /// (C++ [intro.execution]p12).
+ virtual OwningExprResult ActOnFinishFullExpr(ExprArg Expr) {
+ return move(Expr);
+ }
+
//===---------------------------- C++ Classes ---------------------------===//
/// ActOnBaseSpecifier - Parsed a base specifier
virtual BaseResult ActOnBaseSpecifier(DeclPtrTy classdecl,
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=71982&r1=71981&r2=71982&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sun May 17 13:26:53 2009
@@ -141,6 +141,7 @@
typedef Action::ExprArg ExprArg;
typedef Action::MultiStmtArg MultiStmtArg;
+ typedef Action::FullExprArg FullExprArg;
/// Adorns a ExprResult with Actions to make it an OwningExprResult
OwningExprResult Owned(ExprResult res) {
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=71982&r1=71981&r2=71982&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sun May 17 13:26:53 2009
@@ -632,7 +632,7 @@
if (ElseStmt.isInvalid())
ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc);
- return Actions.ActOnIfStmt(IfLoc, move(CondExp), move(ThenStmt),
+ return Actions.ActOnIfStmt(IfLoc, Actions.FullExpr(CondExp), move(ThenStmt),
ElseLoc, move(ElseStmt));
}
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=71982&r1=71981&r2=71982&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun May 17 13:26:53 2009
@@ -1172,9 +1172,9 @@
IdentifierInfo *II,
SourceLocation ColonLoc,
StmtArg SubStmt);
- virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
- StmtArg ThenVal, SourceLocation ElseLoc,
- StmtArg ElseVal);
+ virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc,
+ FullExprArg CondVal, StmtArg ThenVal,
+ SourceLocation ElseLoc, StmtArg ElseVal);
virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
StmtArg Switch, StmtArg Body);
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=71982&r1=71981&r2=71982&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun May 17 13:26:53 2009
@@ -180,17 +180,19 @@
}
Action::OwningStmtResult
-Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
+Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal,
StmtArg ThenVal, SourceLocation ElseLoc,
StmtArg ElseVal) {
- Expr *condExpr = CondVal.takeAs<Expr>();
+ OwningExprResult CondResult(CondVal.release());
+
+ Expr *condExpr = CondResult.takeAs<Expr>();
assert(condExpr && "ActOnIfStmt(): missing expression");
if (!condExpr->isTypeDependent()) {
DefaultFunctionArrayConversion(condExpr);
// Take ownership again until we're past the error checking.
- CondVal = condExpr;
+ CondResult = condExpr;
QualType condType = condExpr->getType();
if (getLangOptions().CPlusPlus) {
@@ -213,7 +215,7 @@
Diag(stmt->getSemiLoc(), diag::warn_empty_if_body);
}
- CondVal.release();
+ CondResult.release();
return Owned(new (Context) IfStmt(IfLoc, condExpr, thenStmt,
ElseLoc, ElseVal.takeAs<Stmt>()));
}
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateStmt.cpp?rev=71982&r1=71981&r2=71982&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateStmt.cpp Sun May 17 13:26:53 2009
@@ -25,6 +25,10 @@
Sema &SemaRef;
const TemplateArgumentList &TemplateArgs;
+ Sema::FullExprArg FullExpr(Sema::ExprArg &expr) {
+ return SemaRef.FullExpr(expr);
+ }
+
public:
typedef Sema::OwningExprResult OwningExprResult;
typedef Sema::OwningStmtResult OwningStmtResult;
@@ -225,7 +229,7 @@
if (Else.isInvalid())
return SemaRef.StmtError();
- return SemaRef.ActOnIfStmt(S->getIfLoc(), move(Cond), move(Then),
+ return SemaRef.ActOnIfStmt(S->getIfLoc(), FullExpr(Cond), move(Then),
S->getElseLoc(), move(Else));
}
Modified: cfe/trunk/tools/clang-cc/PrintParserCallbacks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/PrintParserCallbacks.cpp?rev=71982&r1=71981&r2=71982&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/PrintParserCallbacks.cpp (original)
+++ cfe/trunk/tools/clang-cc/PrintParserCallbacks.cpp Sun May 17 13:26:53 2009
@@ -296,8 +296,9 @@
return StmtEmpty();
}
- virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
- StmtArg ThenVal,SourceLocation ElseLoc,
+ virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc,
+ FullExprArg CondVal, StmtArg ThenVal,
+ SourceLocation ElseLoc,
StmtArg ElseVal) {
llvm::cout << __FUNCTION__ << "\n";
return StmtEmpty();
More information about the cfe-commits
mailing list