]> granicus.if.org Git - clang/commitdiff
Simplify MacroInfo lifetime management. We don't need three different functions
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 24 Jul 2014 03:25:00 +0000 (03:25 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 24 Jul 2014 03:25:00 +0000 (03:25 +0000)
to destroy one of these.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213837 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e9a66e857dbcf665e5f9054716ef30028e32efab..5dc4095943c103d42e3f03538e7aace188750cf3 100644 (file)
@@ -45,7 +45,7 @@ class MacroInfo {
 
   /// \see ArgumentList
   unsigned NumArguments;
-  
+
   /// \brief This is the list of tokens that the macro is defined to.
   SmallVector<Token, 8> ReplacementTokens;
 
@@ -78,8 +78,7 @@ class MacroInfo {
 
   /// \brief Whether this macro contains the sequence ", ## __VA_ARGS__"
   bool HasCommaPasting : 1;
-  
-private:
+
   //===--------------------------------------------------------------------===//
   // State that changes as the macro is used.
 
@@ -107,28 +106,11 @@ private:
   /// \brief Whether this macro was used as header guard.
   bool UsedForHeaderGuard : 1;
 
-  ~MacroInfo() {
-    assert(!ArgumentList && "Didn't call destroy before dtor!");
-  }
-
-public:
+  // Only the Preprocessor gets to create and destroy these.
   MacroInfo(SourceLocation DefLoc);
-  
-  /// \brief Free the argument list of the macro.
-  ///
-  /// This restores this MacroInfo to a state where it can be reused for other
-  /// devious purposes.
-  void FreeArgumentList() {
-    ArgumentList = nullptr;
-    NumArguments = 0;
-  }
-
-  /// \brief Destroy this MacroInfo object.
-  void Destroy() {
-    FreeArgumentList();
-    this->~MacroInfo();
-  }
+  ~MacroInfo() {}
 
+public:
   /// \brief Return the location that the macro was defined at.
   SourceLocation getDefinitionLoc() const { return Location; }
 
index c38080f7159e4b6c8ac3ed9ad9acce5a7c298e10..d7ed0b4859ee7f9d429a5d56d0d06ecf964a56cb 100644 (file)
@@ -85,10 +85,11 @@ Preprocessor::AllocateVisibilityMacroDirective(SourceLocation Loc,
   return MD;
 }
 
-/// \brief Release the specified MacroInfo to be reused for allocating
-/// new MacroInfo objects.
+/// \brief Clean up a MacroInfo that was allocated but not used due to an
+/// error in the macro definition.
 void Preprocessor::ReleaseMacroInfo(MacroInfo *MI) {
-  MI->Destroy();
+  // Don't try to reuse the storage; this only happens on error paths.
+  MI->~MacroInfo();
 }
 
 /// \brief Read and discard all tokens remaining on the current line until
index 963b7157164005d16f16125e7841b9c3ec529f2d..ab11fabbbce5f9e66ee68964f336e9dbe22ea2de 100644 (file)
@@ -141,9 +141,11 @@ Preprocessor::~Preprocessor() {
 
   IncludeMacroStack.clear();
 
-  // Free any macro definitions.
-  for (MacroInfoChain *I = MIChainHead; I; I = I->Next)
-    I->MI.Destroy();
+  // Destroy any macro definitions.
+  while (MacroInfoChain *I = MIChainHead) {
+    MIChainHead = I->Next;
+    I->~MacroInfoChain();
+  }
 
   // Free any cached macro expanders.
   // This populates MacroArgCache, so all TokenLexers need to be destroyed
@@ -152,8 +154,10 @@ Preprocessor::~Preprocessor() {
     delete TokenLexerCache[i];
   CurTokenLexer.reset();
 
-  for (DeserializedMacroInfoChain *I = DeserialMIChainHead ; I ; I = I->Next)
-    I->MI.Destroy();
+  while (DeserializedMacroInfoChain *I = DeserialMIChainHead) {
+    DeserialMIChainHead = I->Next;
+    I->~DeserializedMacroInfoChain();
+  }
 
   // Free any cached MacroArgs.
   for (MacroArgs *ArgList = MacroArgCache; ArgList;)