r217656 - Use unique_ptr for ScratchBuf and PragmaHandlers in the preprocessor.
Craig Topper
craig.topper at gmail.com
Thu Sep 11 22:19:24 PDT 2014
Author: ctopper
Date: Fri Sep 12 00:19:24 2014
New Revision: 217656
URL: http://llvm.org/viewvc/llvm-project?rev=217656&view=rev
Log:
Use unique_ptr for ScratchBuf and PragmaHandlers in the preprocessor.
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=217656&r1=217655&r2=217656&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Sep 12 00:19:24 2014
@@ -92,7 +92,7 @@ class Preprocessor : public RefCountedBa
const TargetInfo *Target;
FileManager &FileMgr;
SourceManager &SourceMgr;
- ScratchBuffer *ScratchBuf;
+ std::unique_ptr<ScratchBuffer> ScratchBuf;
HeaderSearch &HeaderInfo;
ModuleLoader &TheModuleLoader;
@@ -192,7 +192,7 @@ class Preprocessor : public RefCountedBa
/// \brief Tracks all of the pragmas that the client registered
/// with this preprocessor.
- PragmaNamespace *PragmaHandlers;
+ std::unique_ptr<PragmaNamespace> PragmaHandlers;
/// \brief Pragma handlers of the original source is stored here during the
/// parsing of a model file.
Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=217656&r1=217655&r2=217656&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Fri Sep 12 00:19:24 2014
@@ -728,7 +728,7 @@ void Preprocessor::HandlePragmaIncludeAl
/// 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(Stri
/// 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(S
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;
}
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=217656&r1=217655&r2=217656&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Sep 12 00:19:24 2014
@@ -62,9 +62,12 @@ Preprocessor::Preprocessor(IntrusiveRefC
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(IntrusiveRefC
MIChainHead(nullptr), DeserialMIChainHead(nullptr) {
OwnsHeaderSearch = OwnsHeaders;
- ScratchBuf = new ScratchBuffer(SourceMgr);
CounterValue = 0; // __COUNTER__ starts at 0.
// Clear stats.
@@ -112,7 +114,6 @@ Preprocessor::Preprocessor(IntrusiveRefC
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::InitializeForModelFil
NumEnteredSourceFiles = 0;
// Reset pragmas
- PragmaHandlersBackup = PragmaHandlers;
- PragmaHandlers = new PragmaNamespace(StringRef());
+ PragmaHandlersBackup = PragmaHandlers.release();
+ PragmaHandlers = llvm::make_unique<PragmaNamespace>(StringRef());
RegisterBuiltinPragmas();
// Reset PredefinesFileID
@@ -199,8 +194,7 @@ void Preprocessor::InitializeForModelFil
void Preprocessor::FinalizeForModelFile() {
NumEnteredSourceFiles = 1;
- delete PragmaHandlers;
- PragmaHandlers = PragmaHandlersBackup;
+ PragmaHandlers.reset(PragmaHandlersBackup);
}
void Preprocessor::setPTHManager(PTHManager* pm) {
More information about the cfe-commits
mailing list