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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72214 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Parse/Ownership.h b/include/clang/Parse/Ownership.h
index f593f76..5951793 100644
--- a/include/clang/Parse/Ownership.h
+++ b/include/clang/Parse/Ownership.h
@@ -724,8 +724,8 @@
};
/// \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 @@
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 @@
}
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
diff --git a/lib/Parse/AstGuard.h b/lib/Parse/AstGuard.h
deleted file mode 100644
index 1ff6a4e..0000000
--- a/lib/Parse/AstGuard.h
+++ /dev/null
@@ -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
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 4c2a77e..0a33d7d 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -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;
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index b900e25..c53b0f0 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -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;
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 527fd46..869b315 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -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;
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index d2d9a87..c065b47 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -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
diff --git a/lib/Parse/ParseInit.cpp b/lib/Parse/ParseInit.cpp
index 052586f..bbc2124 100644
--- a/lib/Parse/ParseInit.cpp
+++ b/lib/Parse/ParseInit.cpp
@@ -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;
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index 571c610..3014f95 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -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;
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 8422352..952c4c1 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -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"
diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp
index f23f8c0..2a79b99 100644
--- a/lib/Parse/ParseTemplate.cpp
+++ b/lib/Parse/ParseTemplate.cpp
@@ -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
diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp
index 43666df..340cabd 100644
--- a/lib/Sema/SemaTemplateInstantiateExpr.cpp
+++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp
@@ -282,8 +282,7 @@
= ((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 @@
/*, 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 @@
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 @@
E->getLParenLoc()),
T.getAsOpaquePtr(),
E->getLParenLoc(),
- Sema::MultiExprArg(SemaRef,
- Args.take(),
- Args.size()),
+ move_arg(Args),
&FakeCommaLocs.front(),
E->getRParenLoc());
}
diff --git a/lib/Sema/SemaTemplateInstantiateStmt.cpp b/lib/Sema/SemaTemplateInstantiateStmt.cpp
index d635dff..6d2e28a 100644
--- a/lib/Sema/SemaTemplateInstantiateStmt.cpp
+++ b/lib/Sema/SemaTemplateInstantiateStmt.cpp
@@ -314,9 +314,7 @@
}
return SemaRef.ActOnCXXTryBlock(S->getTryLoc(), move(TryBlock),
- Sema::MultiStmtArg(SemaRef,
- Handlers.take(),
- Handlers.size()));
+ move_arg(Handlers));
}
Sema::OwningStmtResult
@@ -442,8 +440,5 @@
}
return ActOnCompoundStmt(S->getLBracLoc(), S->getRBracLoc(),
- Sema::MultiStmtArg(*this,
- Statements.take(),
- Statements.size()),
- isStmtExpr);
+ move_arg(Statements), isStmtExpr);
}