From 269f0b1b69a8480ccc600aab2a0f5c7e87d75157 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 21 May 2009 16:25:11 +0000 Subject: [PATCH] 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 --- clang/include/clang/Parse/Ownership.h | 25 +++++- clang/lib/Parse/AstGuard.h | 83 ------------------- clang/lib/Parse/ParseDecl.cpp | 1 - clang/lib/Parse/ParseDeclCXX.cpp | 1 - clang/lib/Parse/ParseExpr.cpp | 1 - clang/lib/Parse/ParseExprCXX.cpp | 1 - clang/lib/Parse/ParseInit.cpp | 1 - clang/lib/Parse/ParseObjc.cpp | 1 - clang/lib/Parse/ParseStmt.cpp | 1 - clang/lib/Parse/ParseTemplate.cpp | 1 - .../lib/Sema/SemaTemplateInstantiateExpr.cpp | 15 +--- .../lib/Sema/SemaTemplateInstantiateStmt.cpp | 9 +- 12 files changed, 28 insertions(+), 112 deletions(-) delete mode 100644 clang/lib/Parse/AstGuard.h diff --git a/clang/include/clang/Parse/Ownership.h b/clang/include/clang/Parse/Ownership.h index f593f76e784a..59517930de95 100644 --- a/clang/include/clang/Parse/Ownership.h +++ b/clang/include/clang/Parse/Ownership.h @@ -724,8 +724,8 @@ namespace clang { }; /// \brief A small vector that owns a set of AST nodes. - template - class ASTOwningVector : public llvm::SmallVector { + template + class ASTOwningVector : public llvm::SmallVector { #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 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 inline + ASTMultiPtr move_arg(ASTOwningVector &vec) { +#if !defined(DISABLE_SMART_POINTERS) + return ASTMultiPtr(vec.getActions(), vec.take(), vec.size()); +#else + return ASTMultiPtr(vec.take(), vec.size()); +#endif + } + #if !defined(DISABLE_SMART_POINTERS) // Out-of-line implementations due to definition dependencies diff --git a/clang/lib/Parse/AstGuard.h b/clang/lib/Parse/AstGuard.h deleted file mode 100644 index 1ff6a4e35aee..000000000000 --- a/clang/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 - class ASTVector : public llvm::SmallVector { - 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 inline - ASTMultiPtr move_arg(ASTVector &vec) { -#if !defined(DISABLE_SMART_POINTERS) - return ASTMultiPtr(vec.getActions(), vec.take(), vec.size()); -#else - return ASTMultiPtr(vec.take(), vec.size()); -#endif - } -} - -#endif diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 4c2a77e7d056..0a33d7daa024 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/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/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index b900e25c69ac..c53b0f071c10 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/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/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 527fd4695cc5..869b315d998e 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/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/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index d2d9a87f491c..c065b4760a72 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/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/clang/lib/Parse/ParseInit.cpp b/clang/lib/Parse/ParseInit.cpp index 052586f5ca38..bbc2124e5986 100644 --- a/clang/lib/Parse/ParseInit.cpp +++ b/clang/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/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 571c6108364c..3014f95a8482 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/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/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 842235264e9f..952c4c15f3bb 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/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/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index f23f8c0c831d..2a79b99d29c9 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/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/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp index 43666df7c0f3..340cabd085ca 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -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()); } diff --git a/clang/lib/Sema/SemaTemplateInstantiateStmt.cpp b/clang/lib/Sema/SemaTemplateInstantiateStmt.cpp index d635dff94c66..6d2e28aff801 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateStmt.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateStmt.cpp @@ -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); }