From: Benjamin Kramer Date: Sat, 15 Mar 2014 16:40:40 +0000 (+0000) Subject: Preprocessor: Clarify the ownership of the IncludeMacroStack with unique_ptr. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec4d626ce2f86e0a2a87f996b23c501f14ba86a8;p=clang Preprocessor: Clarify the ownership of the IncludeMacroStack with unique_ptr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204007 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 56c85d4f91..e103731f64 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -298,19 +298,13 @@ class Preprocessor : public RefCountedBase { /// \#included, and macros currently being expanded from, not counting /// CurLexer/CurTokenLexer. struct IncludeStackInfo { - enum CurLexerKind CurLexerKind; - Module *TheSubmodule; - Lexer *TheLexer; - PTHLexer *ThePTHLexer; - PreprocessorLexer *ThePPLexer; - TokenLexer *TheTokenLexer; - const DirectoryLookup *TheDirLookup; - - IncludeStackInfo(enum CurLexerKind K, Module *M, Lexer *L, PTHLexer *P, - PreprocessorLexer *PPL, TokenLexer *TL, - const DirectoryLookup *D) - : CurLexerKind(K), TheSubmodule(M), TheLexer(L), ThePTHLexer(P), - ThePPLexer(PPL), TheTokenLexer(TL), TheDirLookup(D) {} + enum CurLexerKind CurLexerKind; + Module *TheSubmodule; + std::unique_ptr TheLexer; + std::unique_ptr ThePTHLexer; + PreprocessorLexer *ThePPLexer; + std::unique_ptr TheTokenLexer; + const DirectoryLookup *TheDirLookup; }; std::vector IncludeMacroStack; @@ -1327,17 +1321,19 @@ public: private: void PushIncludeMacroStack() { - IncludeMacroStack.push_back(IncludeStackInfo( - CurLexerKind, CurSubmodule, CurLexer.release(), CurPTHLexer.release(), - CurPPLexer, CurTokenLexer.release(), CurDirLookup)); + IncludeStackInfo Info = {CurLexerKind, CurSubmodule, + std::move(CurLexer), std::move(CurPTHLexer), + CurPPLexer, std::move(CurTokenLexer), + CurDirLookup}; + IncludeMacroStack.push_back(std::move(Info)); CurPPLexer = 0; } void PopIncludeMacroStack() { - CurLexer.reset(IncludeMacroStack.back().TheLexer); - CurPTHLexer.reset(IncludeMacroStack.back().ThePTHLexer); + CurLexer = std::move(IncludeMacroStack.back().TheLexer); + CurPTHLexer = std::move(IncludeMacroStack.back().ThePTHLexer); CurPPLexer = IncludeMacroStack.back().ThePPLexer; - CurTokenLexer.reset(IncludeMacroStack.back().TheTokenLexer); + CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer); CurDirLookup = IncludeMacroStack.back().TheDirLookup; CurSubmodule = IncludeMacroStack.back().TheSubmodule; CurLexerKind = IncludeMacroStack.back().CurLexerKind; @@ -1461,7 +1457,7 @@ private: } static bool IsFileLexer(const IncludeStackInfo& I) { - return IsFileLexer(I.TheLexer, I.ThePPLexer); + return IsFileLexer(I.TheLexer.get(), I.ThePPLexer); } bool IsFileLexer() const { diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 2125d180e8..d85df38ea7 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -143,11 +143,7 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr PPOpts, Preprocessor::~Preprocessor() { assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!"); - while (!IncludeMacroStack.empty()) { - delete IncludeMacroStack.back().TheLexer; - delete IncludeMacroStack.back().TheTokenLexer; - IncludeMacroStack.pop_back(); - } + IncludeMacroStack.clear(); // Free any macro definitions. for (MacroInfoChain *I = MIChainHead ; I ; I = I->Next)