From: Craig Topper Date: Fri, 12 Sep 2014 05:19:24 +0000 (+0000) Subject: Use unique_ptr for ScratchBuf and PragmaHandlers in the preprocessor. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f51fe881657f5a4a2091ab53225665ed29e49b8;p=clang Use unique_ptr for ScratchBuf and PragmaHandlers in the preprocessor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217656 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 1f8001eaa4..521a8713e7 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -92,7 +92,7 @@ class Preprocessor : public RefCountedBase { const TargetInfo *Target; FileManager &FileMgr; SourceManager &SourceMgr; - ScratchBuffer *ScratchBuf; + std::unique_ptr ScratchBuf; HeaderSearch &HeaderInfo; ModuleLoader &TheModuleLoader; @@ -192,7 +192,7 @@ class Preprocessor : public RefCountedBase { /// \brief Tracks all of the pragmas that the client registered /// with this preprocessor. - PragmaNamespace *PragmaHandlers; + std::unique_ptr PragmaHandlers; /// \brief Pragma handlers of the original source is stored here during the /// parsing of a model file. diff --git a/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp index af65bbfc9b..b784c2938e 100644 --- a/lib/Lex/Pragma.cpp +++ b/lib/Lex/Pragma.cpp @@ -728,7 +728,7 @@ void Preprocessor::HandlePragmaIncludeAlias(Token &Tok) { /// pragma line before the pragma string starts, e.g. "STDC" or "GCC". void Preprocessor::AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler) { - PragmaNamespace *InsertNS = PragmaHandlers; + PragmaNamespace *InsertNS = PragmaHandlers.get(); // If this is specified to be in a namespace, step down into it. if (!Namespace.empty()) { @@ -759,7 +759,7 @@ void Preprocessor::AddPragmaHandler(StringRef Namespace, /// a handler that has not been registered. void Preprocessor::RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler) { - PragmaNamespace *NS = PragmaHandlers; + PragmaNamespace *NS = PragmaHandlers.get(); // If this is specified to be in a namespace, step down into it. if (!Namespace.empty()) { @@ -772,9 +772,8 @@ void Preprocessor::RemovePragmaHandler(StringRef Namespace, NS->RemovePragmaHandler(Handler); - // If this is a non-default namespace and it is now empty, remove - // it. - if (NS != PragmaHandlers && NS->IsEmpty()) { + // If this is a non-default namespace and it is now empty, remove it. + if (NS != PragmaHandlers.get() && NS->IsEmpty()) { PragmaHandlers->RemovePragmaHandler(NS); delete NS; } diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 091a5de8c6..b2f8107ca2 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -62,9 +62,12 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr PPOpts, IdentifierInfoLookup *IILookup, bool OwnsHeaders, TranslationUnitKind TUKind) : PPOpts(PPOpts), Diags(&diags), LangOpts(opts), Target(nullptr), - FileMgr(Headers.getFileMgr()), SourceMgr(SM), HeaderInfo(Headers), + FileMgr(Headers.getFileMgr()), SourceMgr(SM), + ScratchBuf(new ScratchBuffer(SourceMgr)),HeaderInfo(Headers), TheModuleLoader(TheModuleLoader), ExternalSource(nullptr), - Identifiers(opts, IILookup), IncrementalProcessing(false), TUKind(TUKind), + Identifiers(opts, IILookup), + PragmaHandlers(new PragmaNamespace(StringRef())), + IncrementalProcessing(false), TUKind(TUKind), CodeComplete(nullptr), CodeCompletionFile(nullptr), CodeCompletionOffset(0), LastTokenWasAt(false), ModuleImportExpectsIdentifier(false), CodeCompletionReached(0), @@ -74,7 +77,6 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr PPOpts, MIChainHead(nullptr), DeserialMIChainHead(nullptr) { OwnsHeaderSearch = OwnsHeaders; - ScratchBuf = new ScratchBuffer(SourceMgr); CounterValue = 0; // __COUNTER__ starts at 0. // Clear stats. @@ -112,7 +114,6 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr PPOpts, SetPoisonReason(Ident__VA_ARGS__,diag::ext_pp_bad_vaargs_use); // Initialize the pragma handlers. - PragmaHandlers = new PragmaNamespace(StringRef()); RegisterBuiltinPragmas(); // Initialize builtin macros like __LINE__ and friends. @@ -163,12 +164,6 @@ Preprocessor::~Preprocessor() { for (MacroArgs *ArgList = MacroArgCache; ArgList;) ArgList = ArgList->deallocate(); - // Release pragma information. - delete PragmaHandlers; - - // Delete the scratch buffer info. - delete ScratchBuf; - // Delete the header search info, if we own it. if (OwnsHeaderSearch) delete &HeaderInfo; @@ -188,8 +183,8 @@ void Preprocessor::InitializeForModelFile() { NumEnteredSourceFiles = 0; // Reset pragmas - PragmaHandlersBackup = PragmaHandlers; - PragmaHandlers = new PragmaNamespace(StringRef()); + PragmaHandlersBackup = PragmaHandlers.release(); + PragmaHandlers = llvm::make_unique(StringRef()); RegisterBuiltinPragmas(); // Reset PredefinesFileID @@ -199,8 +194,7 @@ void Preprocessor::InitializeForModelFile() { void Preprocessor::FinalizeForModelFile() { NumEnteredSourceFiles = 1; - delete PragmaHandlers; - PragmaHandlers = PragmaHandlersBackup; + PragmaHandlers.reset(PragmaHandlersBackup); } void Preprocessor::setPTHManager(PTHManager* pm) {