diff options
Diffstat (limited to 'lib/Parse/AstGuard.h')
-rw-r--r-- | lib/Parse/AstGuard.h | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/lib/Parse/AstGuard.h b/lib/Parse/AstGuard.h index 71d2565052..5d17aa66b6 100644 --- a/lib/Parse/AstGuard.h +++ b/lib/Parse/AstGuard.h @@ -19,119 +19,6 @@ namespace clang { - template <void (ActionBase::*Destroyer)(void*)> - class ASTOwner; - - typedef ASTOwner<&ActionBase::DeleteStmt> StmtOwner; - typedef ASTOwner<&ActionBase::DeleteExpr> ExprOwner; - - /// Some trickery to switch between an ActionResult and an ASTOwner - template <typename Owner> struct ResultOfOwner; - template <> struct ResultOfOwner<StmtOwner> { - typedef Action::StmtResult type; - }; - template <> struct ResultOfOwner<ExprOwner> { - typedef Action::ExprResult type; - }; - - /// Move emulation helper for ASTOwner. Implicitly convertible to ActionResult - /// and void*, which means ASTOwner::move() can be used universally. - template <void (ActionBase::*Destroyer)(void*)> - class ASTMove { - ASTOwner<Destroyer> &Moved; - - public: - explicit ASTMove(ASTOwner<Destroyer> &moved) : Moved(moved) {} - ASTOwner<Destroyer> * operator ->() { - return &Moved; - } - - /// Allow moving from ASTOwner to ActionResult - operator typename ResultOfOwner< ASTOwner<Destroyer> >::type() { - if (Moved.isInvalid()) - return true; - return Moved.take(); - } - - /// Allow moving from ASTOwner to void* - operator void*() { - if (Moved.isInvalid()) - return 0; - return Moved.take(); - } - }; - - /// RAII owning pointer for StmtTys and ExprTys. Simple move emulation. - template <void (ActionBase::*Destroyer)(void*)> - class ASTOwner { - typedef typename ResultOfOwner<ASTOwner>::type Result; - - Action &Actions; - void *Node; - bool Invalid; - - void destroy() { - if (Node) - (Actions.*Destroyer)(Node); - } - - ASTOwner(const ASTOwner&); // DO NOT IMPLEMENT - // Reference member prevents copy assignment. - - public: - explicit ASTOwner(Action &actions, bool invalid = false) - : Actions(actions), Node(0), Invalid(invalid) {} - ASTOwner(Action &actions, void *node) - : Actions(actions), Node(node), Invalid(false) {} - ASTOwner(Action &actions, const Result &res) - : Actions(actions), Node(res.Val), Invalid(res.isInvalid) {} - /// Move constructor - ASTOwner(ASTMove<Destroyer> mover) - : Actions(mover->Actions), Node(mover->take()), Invalid(mover->Invalid) {} - /// Move assignment - ASTOwner & operator =(ASTMove<Destroyer> mover) { - assert(&Actions == &mover->Actions && - "AST Owners from different actions."); - destroy(); - Node = mover->take(); - Invalid = mover->Invalid; - return *this; - } - /// Convenience, for better syntax. reset() is so ugly. Just remember that - /// this takes ownership. - ASTOwner & operator =(const Result &res) { - reset(res); - return *this; - } - - void reset(void *node = 0) { - destroy(); - Node = node; - Invalid = false; - } - void reset(const Result &res) { - destroy(); - Node = res.Val; - Invalid = res.isInvalid; - } - /// Take ownership from this pointer and return the node. Calling move() is - /// better. - void *take() { - void *Temp = Node; - Node = 0; - return Temp; - } - void *get() const { return Node; } - bool isInvalid() const { return Invalid; } - /// Does this point to a usable AST node? To be usable, the node must be - /// valid and non-null. - bool isUsable() const { return !Invalid && Node; } - - ASTMove<Destroyer> move() { - return ASTMove<Destroyer>(*this); - } - }; - /// RAII SmallVector wrapper that holds Action::ExprTy* and similar, /// automatically freeing them on destruction unless it's been disowned. /// Instantiated for statements and expressions (Action::DeleteStmt and |