]> granicus.if.org Git - clang/commitdiff
Preprocessor: Clarify the ownership of the IncludeMacroStack with unique_ptr.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 15 Mar 2014 16:40:40 +0000 (16:40 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 15 Mar 2014 16:40:40 +0000 (16:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204007 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Preprocessor.h
lib/Lex/Preprocessor.cpp

index 56c85d4f912ebd2b476489ec091ef0163f50a037..e103731f64549d16d16f5c7833626738c6a771d4 100644 (file)
@@ -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 {
index 2125d180e80b285fcd9121e7028a5efea2cef78c..d85df38ea711bb01a6fe4e022fea3ed3f59cd43e 100644 (file)
@@ -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)