#ifndef LLVM_CLANG_PARSE_ASTGUARD_H
#define LLVM_CLANG_PARSE_ASTGUARD_H
#include "clang/Parse/Action.h"
#include "llvm/ADT/SmallVector.h"
namespace clang
{
template <ASTDestroyer Destroyer, unsigned N>
class ASTVector : public llvm::SmallVector<void*, N> {
private:
#if !defined(DISABLE_SMART_POINTERS)
Action &Actions;
bool Owns;
void destroy() {
if (Owns) {
while (!this->empty()) {
(Actions.*Destroyer)(this->back());
this->pop_back();
}
}
}
ASTVector(const ASTVector&); #endif
public:
#if !defined(DISABLE_SMART_POINTERS)
ASTVector(Action &actions) : Actions(actions), Owns(true) {}
~ASTVector() { destroy(); }
#else
ASTVector(Action &) {}
#endif
void **take() {
#if !defined(DISABLE_SMART_POINTERS)
Owns = false;
#endif
return &(*this)[0];
}
#if !defined(DISABLE_SMART_POINTERS)
Action &getActions() const { return Actions; }
#endif
};
typedef ASTVector<&Action::DeleteStmt, 32> StmtVector;
typedef ASTVector<&Action::DeleteExpr, 12> ExprVector;
template <ASTDestroyer Destroyer, unsigned N> inline
ASTMultiPtr<Destroyer> move_arg(ASTVector<Destroyer, N> &vec) {
#if !defined(DISABLE_SMART_POINTERS)
return ASTMultiPtr<Destroyer>(vec.getActions(), vec.take(), vec.size());
#else
return ASTMultiPtr<Destroyer>(vec.take(), vec.size());
#endif
}
}
#endif