[cfe-commits] r61309 - in /cfe/trunk: Driver/PrintParserCallbacks.cpp include/clang/Parse/Action.h include/clang/Parse/Parser.h lib/Parse/AstGuard.h lib/Parse/ParseObjc.cpp lib/Parse/ParseStmt.cpp lib/Sema/Sema.h lib/Sema/SemaStmt.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Sun Dec 21 04:04:11 PST 2008
Author: cornedbee
Date: Sun Dec 21 06:04:03 2008
New Revision: 61309
URL: http://llvm.org/viewvc/llvm-project?rev=61309&view=rev
Log:
Convert a few Stmt actions to smart pointers.
Modified:
cfe/trunk/Driver/PrintParserCallbacks.cpp
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/AstGuard.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaStmt.cpp
Modified: cfe/trunk/Driver/PrintParserCallbacks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/PrintParserCallbacks.cpp?rev=61309&r1=61308&r2=61309&view=diff
==============================================================================
--- cfe/trunk/Driver/PrintParserCallbacks.cpp (original)
+++ cfe/trunk/Driver/PrintParserCallbacks.cpp Sun Dec 21 06:04:03 2008
@@ -241,27 +241,29 @@
//===--------------------------------------------------------------------===//
// Statement Parsing Callbacks.
//===--------------------------------------------------------------------===//
-
- virtual StmtResult ActOnNullStmt(SourceLocation SemiLoc) {
+
+ virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc) {
llvm::cout << __FUNCTION__ << "\n";
- return 0;
+ return StmtEmpty();
}
-
- virtual StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
- StmtTy **Elts, unsigned NumElts,
- bool isStmtExpr) {
+
+ virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L,
+ SourceLocation R,
+ MultiStmtArg Elts,
+ bool isStmtExpr) {
llvm::cout << __FUNCTION__ << "\n";
- return 0;
+ return StmtEmpty();
}
- virtual StmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
- SourceLocation EndLoc) {
+ virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl,
+ SourceLocation StartLoc,
+ SourceLocation EndLoc) {
llvm::cout << __FUNCTION__ << "\n";
- return 0;
+ return StmtEmpty();
}
- virtual StmtResult ActOnExprStmt(ExprTy *Expr) {
+ virtual OwningStmtResult ActOnExprStmt(ExprArg Expr) {
llvm::cout << __FUNCTION__ << "\n";
- return StmtResult(Expr);
+ return OwningStmtResult(*this, Expr.release());
}
/// ActOnCaseStmt - Note that this handles the GNU 'case 1 ... 4' extension,
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=61309&r1=61308&r2=61309&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Sun Dec 21 06:04:03 2008
@@ -342,25 +342,25 @@
//===--------------------------------------------------------------------===//
// Statement Parsing Callbacks.
//===--------------------------------------------------------------------===//
-
- virtual StmtResult ActOnNullStmt(SourceLocation SemiLoc) {
- return 0;
+
+ virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc) {
+ return StmtEmpty();
}
-
- virtual StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
- StmtTy **Elts, unsigned NumElts,
- bool isStmtExpr) {
- return 0;
+
+ virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
+ MultiStmtArg Elts,
+ bool isStmtExpr) {
+ return StmtEmpty();
}
- virtual StmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
+ virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
SourceLocation EndLoc) {
- return 0;
+ return StmtEmpty();
}
-
- virtual StmtResult ActOnExprStmt(ExprTy *Expr) {
- return StmtResult(Expr);
+
+ virtual OwningStmtResult ActOnExprStmt(ExprArg Expr) {
+ return OwningStmtResult(*this, Expr.release());
}
-
+
/// ActOnCaseStmt - Note that this handles the GNU 'case 1 ... 4' extension,
/// which can specify an RHS value.
virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=61309&r1=61308&r2=61309&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sun Dec 21 06:04:03 2008
@@ -90,6 +90,7 @@
typedef Action::OwningTemplateArgResult OwningTemplateArgResult;
typedef Action::ExprArg ExprArg;
+ typedef Action::MultiStmtArg MultiStmtArg;
/// Adorns a ExprResult with Actions to make it an OwningExprResult
OwningExprResult Owned(ExprResult res) {
Modified: cfe/trunk/lib/Parse/AstGuard.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AstGuard.h?rev=61309&r1=61308&r2=61309&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/AstGuard.h (original)
+++ cfe/trunk/lib/Parse/AstGuard.h Sun Dec 21 06:04:03 2008
@@ -23,7 +23,7 @@
/// automatically freeing them on destruction unless it's been disowned.
/// Instantiated for statements and expressions (Action::DeleteStmt and
/// Action::DeleteExpr).
- template <void (ActionBase::*Destroyer)(void*), unsigned N>
+ template <ASTDestroyer Destroyer, unsigned N>
class ASTVector : public llvm::SmallVector<void*, N> {
private:
Action &Actions;
@@ -50,6 +50,8 @@
Owns = false;
return &(*this)[0];
}
+
+ Action &getActions() const { return Actions; }
};
/// A SmallVector of statements, with stack size 32 (as that is the only one
@@ -57,6 +59,11 @@
typedef ASTVector<&Action::DeleteStmt, 32> StmtVector;
/// A SmallVector of expressions, with stack size 12 (the maximum used.)
typedef ASTVector<&Action::DeleteExpr, 12> ExprVector;
+
+ template <ASTDestroyer Destroyer, unsigned N> inline
+ ASTMultiPtr<Destroyer> move_convert(ASTVector<Destroyer, N> &vec) {
+ return ASTMultiPtr<Destroyer>(vec.getActions(), vec.take(), vec.size());
+ }
}
#endif
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=61309&r1=61308&r2=61309&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Sun Dec 21 06:04:03 2008
@@ -1365,7 +1365,8 @@
// If the function body could not be parsed, make a bogus compoundstmt.
if (FnBody.isInvalid())
- FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 0, 0, false);
+ FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc,
+ MultiStmtArg(Actions), false);
// Leave the function body scope.
BodyScope.Exit();
@@ -1392,7 +1393,7 @@
}
// Otherwise, eat the semicolon.
ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
- return Owned(Actions.ActOnExprStmt(Res.release()));
+ return Actions.ActOnExprStmt(move_convert(Res));
}
Parser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=61309&r1=61308&r2=61309&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sun Dec 21 06:04:03 2008
@@ -101,7 +101,7 @@
SourceLocation DeclStart = Tok.getLocation();
DeclTy *Decl = ParseDeclaration(Declarator::BlockContext);
// FIXME: Pass in the right location for the end of the declstmt.
- return Owned(Actions.ActOnDeclStmt(Decl, DeclStart, DeclStart));
+ return Actions.ActOnDeclStmt(Decl, DeclStart, DeclStart);
} else if (Tok.is(tok::r_brace)) {
Diag(Tok, diag::err_expected_statement);
return StmtError();
@@ -117,7 +117,7 @@
}
// Otherwise, eat the semicolon.
ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
- return Owned(Actions.ActOnExprStmt(Expr.release()));
+ return Actions.ActOnExprStmt(move_convert(Expr));
}
case tok::kw_case: // C99 6.8.1: labeled-statement
@@ -128,7 +128,7 @@
case tok::l_brace: // C99 6.8.2: compound-statement
return ParseCompoundStatement();
case tok::semi: // C99 6.8.3p3: expression[opt] ';'
- return Owned(Actions.ActOnNullStmt(ConsumeToken()));
+ return Actions.ActOnNullStmt(ConsumeToken());
case tok::kw_if: // C99 6.8.4.1: if-statement
return ParseIfStatement();
@@ -395,7 +395,7 @@
// Eat the semicolon at the end of stmt and convert the expr into a
// statement.
ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
- R = Actions.ActOnExprStmt(Res.release());
+ R = Actions.ActOnExprStmt(move_convert(Res));
}
}
@@ -410,8 +410,8 @@
}
SourceLocation RBraceLoc = ConsumeBrace();
- return Owned(Actions.ActOnCompoundStmt(LBraceLoc, RBraceLoc, Stmts.take(),
- Stmts.size(), isStmtExpr));
+ return Actions.ActOnCompoundStmt(LBraceLoc, RBraceLoc, move_convert(Stmts),
+ isStmtExpr);
}
/// ParseParenExprOrCondition:
@@ -863,7 +863,7 @@
// Turn the expression into a stmt.
if (!Value.isInvalid())
- FirstPart = Actions.ActOnExprStmt(Value.release());
+ FirstPart = Actions.ActOnExprStmt(move_convert(Value));
if (Tok.is(tok::semi)) {
ConsumeToken();
@@ -900,7 +900,7 @@
Value = ParseExpression();
if (!Value.isInvalid()) {
// Turn the expression into a stmt.
- ThirdPart = Actions.ActOnExprStmt(Value.release());
+ ThirdPart = Actions.ActOnExprStmt(move_convert(Value));
}
}
}
@@ -1039,7 +1039,7 @@
Tok.isNot(tok::r_brace) && Tok.isNot(tok::semi) &&
Tok.isNot(tok::eof));
}
- return Owned(Actions.ActOnNullStmt(Tok.getLocation()));
+ return Actions.ActOnNullStmt(Tok.getLocation());
}
/// ParseAsmStatement - Parse a GNU extended asm statement.
@@ -1239,7 +1239,7 @@
// If the function body could not be parsed, make a bogus compoundstmt.
if (FnBody.isInvalid())
- FnBody = Owned(Actions.ActOnCompoundStmt(L, R, 0, 0, false));
+ FnBody = Actions.ActOnCompoundStmt(L, R, MultiStmtArg(Actions), false);
return Actions.ActOnFinishFunctionBody(Decl, move_convert(FnBody));
}
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=61309&r1=61308&r2=61309&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Dec 21 06:04:03 2008
@@ -552,14 +552,14 @@
//===--------------------------------------------------------------------===//
// Statement Parsing Callbacks: SemaStmt.cpp.
public:
- virtual StmtResult ActOnExprStmt(ExprTy *Expr);
-
- virtual StmtResult ActOnNullStmt(SourceLocation SemiLoc);
- virtual StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
- StmtTy **Elts, unsigned NumElts,
- bool isStmtExpr);
- virtual StmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
- SourceLocation EndLoc);
+ virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
+
+ virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
+ virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
+ MultiStmtArg Elts,
+ bool isStmtExpr);
+ virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
+ SourceLocation EndLoc);
virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
SourceLocation DotDotDotLoc, ExprTy *RHSVal,
SourceLocation ColonLoc, StmtTy *SubStmt);
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=61309&r1=61308&r2=61309&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Dec 21 06:04:03 2008
@@ -20,31 +20,31 @@
#include "clang/Basic/Diagnostic.h"
using namespace clang;
-Sema::StmtResult Sema::ActOnExprStmt(ExprTy *expr) {
- Expr *E = static_cast<Expr*>(expr);
+Sema::OwningStmtResult Sema::ActOnExprStmt(ExprArg expr) {
+ Expr *E = static_cast<Expr*>(expr.release());
assert(E && "ActOnExprStmt(): missing expression");
-
+
// C99 6.8.3p2: The expression in an expression statement is evaluated as a
// void expression for its side effects. Conversion to void allows any
// operand, even incomplete types.
-
+
// Same thing in for stmt first clause (when expr) and third clause.
- return E;
+ return Owned(static_cast<Stmt*>(E));
}
-Sema::StmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc) {
- return new NullStmt(SemiLoc);
+Sema::OwningStmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc) {
+ return Owned(new NullStmt(SemiLoc));
}
-Sema::StmtResult Sema::ActOnDeclStmt(DeclTy *decl, SourceLocation StartLoc,
- SourceLocation EndLoc) {
+Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclTy *decl,
+ SourceLocation StartLoc,
+ SourceLocation EndLoc) {
if (decl == 0)
- return true;
-
+ return StmtError();
+
ScopedDecl *SD = cast<ScopedDecl>(static_cast<Decl *>(decl));
-
-
+
// This is a temporary hack until we are always passing around
// DeclGroupRefs.
llvm::SmallVector<Decl*, 10> decls;
@@ -56,21 +56,22 @@
}
assert (!decls.empty());
-
+
if (decls.size() == 1) {
DeclGroupOwningRef DG(*decls.begin());
- return new DeclStmt(DG, StartLoc, EndLoc);
+ return Owned(new DeclStmt(DG, StartLoc, EndLoc));
}
else {
DeclGroupOwningRef DG(DeclGroup::Create(Context, decls.size(), &decls[0]));
- return new DeclStmt(DG, StartLoc, EndLoc);
+ return Owned(new DeclStmt(DG, StartLoc, EndLoc));
}
}
-Action::StmtResult
+Action::OwningStmtResult
Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R,
- StmtTy **elts, unsigned NumElts, bool isStmtExpr) {
- Stmt **Elts = reinterpret_cast<Stmt**>(elts);
+ MultiStmtArg elts, bool isStmtExpr) {
+ unsigned NumElts = elts.size();
+ Stmt **Elts = reinterpret_cast<Stmt**>(elts.release());
// If we're in C89 mode, check that we don't have any decls after stmts. If
// so, emit an extension diagnostic.
if (!getLangOptions().C99 && !getLangOptions().CPlusPlus) {
@@ -111,11 +112,11 @@
else if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E))
Diag(UO->getOperatorLoc(), diag::warn_unused_expr)
<< UO->getSubExpr()->getSourceRange();
- else
+ else
Diag(E->getExprLoc(), diag::warn_unused_expr) << E->getSourceRange();
}
-
- return new CompoundStmt(Elts, NumElts, L, R);
+
+ return Owned(new CompoundStmt(Elts, NumElts, L, R));
}
Action::StmtResult
More information about the cfe-commits
mailing list