Use unique_ptr for ScratchBuf and PragmaHandlers in the preprocessor.
llvm-svn: 217656
This commit is contained in:
parent
fec61ef391
commit
be25030137
|
@ -92,7 +92,7 @@ class Preprocessor : public RefCountedBase<Preprocessor> {
|
|||
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 RefCountedBase<Preprocessor> {
|
|||
|
||||
/// \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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -62,9 +62,12 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr<PreprocessorOptions> 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<PreprocessorOptions> 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<PreprocessorOptions> 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<PragmaNamespace>(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) {
|
||||
|
|
Loading…
Reference in New Issue