diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-03-15 16:40:40 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-03-15 16:40:40 +0000 |
commit | 329c596e58ae0a044dcb048df2e83848dfd3d5b1 (patch) | |
tree | 3ced91739c3a04f22c29e1a6e83a7ab4c3350e3c | |
parent | a6f3950e3981197a1578723caade31c1ddeafaf6 (diff) | |
download | bcm5719-llvm-329c596e58ae0a044dcb048df2e83848dfd3d5b1.tar.gz bcm5719-llvm-329c596e58ae0a044dcb048df2e83848dfd3d5b1.zip |
Preprocessor: Clarify the ownership of the IncludeMacroStack with unique_ptr.
llvm-svn: 204007
-rw-r--r-- | clang/include/clang/Lex/Preprocessor.h | 36 | ||||
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 6 |
2 files changed, 17 insertions, 25 deletions
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 56c85d4f912..e103731f645 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -298,19 +298,13 @@ class Preprocessor : public RefCountedBase<Preprocessor> { /// \#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<Lexer> TheLexer; + std::unique_ptr<PTHLexer> ThePTHLexer; + PreprocessorLexer *ThePPLexer; + std::unique_ptr<TokenLexer> TheTokenLexer; + const DirectoryLookup *TheDirLookup; }; std::vector<IncludeStackInfo> 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/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 2125d180e80..d85df38ea71 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -143,11 +143,7 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr<PreprocessorOptions> 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) |