forked from OSchip/llvm-project
Merge the ASTVector and ASTOwningVector templates, since they offered
redundant functionality. The result (ASTOwningVector) lives in clang/Parse/Ownership.h and is used by both the parser and semantic analysis. No intended functionality change. llvm-svn: 72214
This commit is contained in:
parent
d334aca93f
commit
269f0b1b69
|
@ -724,8 +724,8 @@ namespace clang {
|
|||
};
|
||||
|
||||
/// \brief A small vector that owns a set of AST nodes.
|
||||
template <ASTDestroyer Destroyer>
|
||||
class ASTOwningVector : public llvm::SmallVector<void *, 8> {
|
||||
template <ASTDestroyer Destroyer, unsigned N = 8>
|
||||
class ASTOwningVector : public llvm::SmallVector<void *, N> {
|
||||
#if !defined(DISABLE_SMART_POINTERS)
|
||||
ActionBase &Actions;
|
||||
bool Owned;
|
||||
|
@ -746,7 +746,7 @@ namespace clang {
|
|||
if (!Owned)
|
||||
return;
|
||||
|
||||
for (unsigned I = 0, N = this->size(); I != N; ++I)
|
||||
for (unsigned I = 0, Last = this->size(); I != Last; ++I)
|
||||
(Actions.*Destroyer)((*this)[I]);
|
||||
}
|
||||
#endif
|
||||
|
@ -759,8 +759,27 @@ namespace clang {
|
|||
}
|
||||
|
||||
template<typename T> T **takeAs() { return (T**)take(); }
|
||||
|
||||
#if !defined(DISABLE_SMART_POINTERS)
|
||||
ActionBase &getActions() const { return Actions; }
|
||||
#endif
|
||||
};
|
||||
|
||||
/// A SmallVector of statements, with stack size 32 (as that is the only one
|
||||
/// used.)
|
||||
typedef ASTOwningVector<&ActionBase::DeleteStmt, 32> StmtVector;
|
||||
/// A SmallVector of expressions, with stack size 12 (the maximum used.)
|
||||
typedef ASTOwningVector<&ActionBase::DeleteExpr, 12> ExprVector;
|
||||
|
||||
template <ASTDestroyer Destroyer, unsigned N> inline
|
||||
ASTMultiPtr<Destroyer> move_arg(ASTOwningVector<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
|
||||
}
|
||||
|
||||
#if !defined(DISABLE_SMART_POINTERS)
|
||||
|
||||
// Out-of-line implementations due to definition dependencies
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
//===--- AstGuard.h - Parser Ownership Tracking Utilities -------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines RAII objects for managing ExprTy* and StmtTy*.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_PARSE_ASTGUARD_H
|
||||
#define LLVM_CLANG_PARSE_ASTGUARD_H
|
||||
|
||||
#include "clang/Parse/Action.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
|
||||
namespace clang
|
||||
{
|
||||
/// 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
|
||||
/// Action::DeleteExpr).
|
||||
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&); // DO NOT IMPLEMENT
|
||||
// Reference member prevents copy assignment.
|
||||
#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->data();
|
||||
}
|
||||
|
||||
#if !defined(DISABLE_SMART_POINTERS)
|
||||
Action &getActions() const { return Actions; }
|
||||
#endif
|
||||
};
|
||||
|
||||
/// A SmallVector of statements, with stack size 32 (as that is the only one
|
||||
/// used.)
|
||||
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_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
|
|
@ -15,7 +15,6 @@
|
|||
#include "clang/Parse/ParseDiagnostic.h"
|
||||
#include "clang/Parse/Scope.h"
|
||||
#include "ExtensionRAIIObject.h"
|
||||
#include "AstGuard.h"
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
using namespace clang;
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "clang/Parse/ParseDiagnostic.h"
|
||||
#include "clang/Parse/DeclSpec.h"
|
||||
#include "clang/Parse/Scope.h"
|
||||
#include "AstGuard.h"
|
||||
#include "ExtensionRAIIObject.h"
|
||||
using namespace clang;
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "clang/Parse/Scope.h"
|
||||
#include "clang/Basic/PrettyStackTrace.h"
|
||||
#include "ExtensionRAIIObject.h"
|
||||
#include "AstGuard.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
using namespace clang;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "clang/Parse/ParseDiagnostic.h"
|
||||
#include "clang/Parse/Parser.h"
|
||||
#include "clang/Parse/DeclSpec.h"
|
||||
#include "AstGuard.h"
|
||||
using namespace clang;
|
||||
|
||||
/// ParseOptionalCXXScopeSpecifier - Parse global scope or
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
#include "clang/Parse/Designator.h"
|
||||
#include "clang/Parse/Parser.h"
|
||||
#include "AstGuard.h"
|
||||
#include "clang/Parse/ParseDiagnostic.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
using namespace clang;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "clang/Parse/Parser.h"
|
||||
#include "clang/Parse/DeclSpec.h"
|
||||
#include "clang/Parse/Scope.h"
|
||||
#include "AstGuard.h"
|
||||
#include "clang/Parse/ParseDiagnostic.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
using namespace clang;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
#include "clang/Parse/Parser.h"
|
||||
#include "ExtensionRAIIObject.h"
|
||||
#include "AstGuard.h"
|
||||
#include "clang/Parse/DeclSpec.h"
|
||||
#include "clang/Parse/Scope.h"
|
||||
#include "clang/Basic/Diagnostic.h"
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "clang/Parse/ParseDiagnostic.h"
|
||||
#include "clang/Parse/DeclSpec.h"
|
||||
#include "clang/Parse/Scope.h"
|
||||
#include "AstGuard.h"
|
||||
using namespace clang;
|
||||
|
||||
/// \brief Parse a template declaration, explicit instantiation, or
|
||||
|
|
|
@ -282,8 +282,7 @@ Sema::OwningExprResult TemplateExprInstantiator::VisitCallExpr(CallExpr *E) {
|
|||
= ((Expr *)Callee.get())->getSourceRange().getBegin();
|
||||
return SemaRef.ActOnCallExpr(/*Scope=*/0, move(Callee),
|
||||
/*FIXME:*/FakeLParenLoc,
|
||||
Sema::MultiExprArg(SemaRef,
|
||||
Args.take(), Args.size()),
|
||||
move_arg(Args),
|
||||
/*FIXME:*/&FakeCommaLocs.front(),
|
||||
E->getRParenLoc());
|
||||
}
|
||||
|
@ -671,9 +670,7 @@ TemplateExprInstantiator::VisitCXXTemporaryObjectExpr(
|
|||
/*, FIXME*/),
|
||||
T.getAsOpaquePtr(),
|
||||
/*FIXME*/E->getTypeBeginLoc(),
|
||||
Sema::MultiExprArg(SemaRef,
|
||||
Args.take(),
|
||||
Args.size()),
|
||||
move_arg(Args),
|
||||
/*HACK*/&CommaLoc,
|
||||
E->getSourceRange().getEnd());
|
||||
}
|
||||
|
@ -924,9 +921,7 @@ TemplateExprInstantiator::VisitCXXNewExpr(CXXNewExpr *E) {
|
|||
return SemaRef.BuildCXXNew(E->getSourceRange().getBegin(),
|
||||
E->isGlobalNew(),
|
||||
/*FIXME*/SourceLocation(),
|
||||
Sema::MultiExprArg(SemaRef,
|
||||
PlacementArgs.take(),
|
||||
PlacementArgs.size()),
|
||||
move_arg(PlacementArgs),
|
||||
/*FIXME*/SourceLocation(),
|
||||
E->isParenTypeId(),
|
||||
AllocType,
|
||||
|
@ -979,9 +974,7 @@ TemplateExprInstantiator::VisitCXXUnresolvedConstructExpr(
|
|||
E->getLParenLoc()),
|
||||
T.getAsOpaquePtr(),
|
||||
E->getLParenLoc(),
|
||||
Sema::MultiExprArg(SemaRef,
|
||||
Args.take(),
|
||||
Args.size()),
|
||||
move_arg(Args),
|
||||
&FakeCommaLocs.front(),
|
||||
E->getRParenLoc());
|
||||
}
|
||||
|
|
|
@ -314,9 +314,7 @@ TemplateStmtInstantiator::VisitCXXTryStmt(CXXTryStmt *S) {
|
|||
}
|
||||
|
||||
return SemaRef.ActOnCXXTryBlock(S->getTryLoc(), move(TryBlock),
|
||||
Sema::MultiStmtArg(SemaRef,
|
||||
Handlers.take(),
|
||||
Handlers.size()));
|
||||
move_arg(Handlers));
|
||||
}
|
||||
|
||||
Sema::OwningStmtResult
|
||||
|
@ -442,8 +440,5 @@ Sema::InstantiateCompoundStmt(CompoundStmt *S,
|
|||
}
|
||||
|
||||
return ActOnCompoundStmt(S->getLBracLoc(), S->getRBracLoc(),
|
||||
Sema::MultiStmtArg(*this,
|
||||
Statements.take(),
|
||||
Statements.size()),
|
||||
isStmtExpr);
|
||||
move_arg(Statements), isStmtExpr);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue