[clang-tools-extra] 39c9c12 - [clang-tools-extra] reimplement PreprocessorTracker in terms of StringSet.

Chris Lattner via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 16 12:58:01 PDT 2020


Author: Chris Lattner
Date: 2020-04-16T12:57:43-07:00
New Revision: 39c9c12b76da27bd52ca1b82c3d39d9c9b59ad0f

URL: https://github.com/llvm/llvm-project/commit/39c9c12b76da27bd52ca1b82c3d39d9c9b59ad0f
DIFF: https://github.com/llvm/llvm-project/commit/39c9c12b76da27bd52ca1b82c3d39d9c9b59ad0f.diff

LOG: [clang-tools-extra] reimplement PreprocessorTracker in terms of StringSet.

Summary:
PreprocessorTracker is the last user of the old StringPool class, which
isn't super loved and isn't a great improvement over a plan StringSet.
Once this goes in we can remove StringPool entirely.

This is as discussed on cfe-dev.

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78273

Added: 
    

Modified: 
    clang-tools-extra/modularize/PreprocessorTracker.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/modularize/PreprocessorTracker.cpp b/clang-tools-extra/modularize/PreprocessorTracker.cpp
index 26c2923c2983..f8ab2c8067c0 100644
--- a/clang-tools-extra/modularize/PreprocessorTracker.cpp
+++ b/clang-tools-extra/modularize/PreprocessorTracker.cpp
@@ -243,19 +243,19 @@
 //
 //===--------------------------------------------------------------------===//
 
-#include "clang/Lex/LexDiagnostic.h"
 #include "PreprocessorTracker.h"
+#include "ModularizeUtilities.h"
+#include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "llvm/ADT/SmallSet.h"
-#include "llvm/Support/StringPool.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/raw_ostream.h"
-#include "ModularizeUtilities.h"
 
 namespace Modularize {
 
 // Some handle types
-typedef llvm::PooledStringPtr StringHandle;
+typedef llvm::StringRef StringHandle;
 
 typedef int HeaderHandle;
 const HeaderHandle HeaderHandleInvalid = -1;
@@ -463,19 +463,6 @@ ConditionValueKindStrings[] = {
   "(not evaluated)", "false", "true"
 };
 
-bool operator<(const StringHandle &H1, const StringHandle &H2) {
-  const char *S1 = (H1 ? *H1 : "");
-  const char *S2 = (H2 ? *H2 : "");
-  int Diff = strcmp(S1, S2);
-  return Diff < 0;
-}
-bool operator>(const StringHandle &H1, const StringHandle &H2) {
-  const char *S1 = (H1 ? *H1 : "");
-  const char *S2 = (H2 ? *H2 : "");
-  int Diff = strcmp(S1, S2);
-  return Diff > 0;
-}
-
 // Preprocessor item key.
 //
 // This class represents a location in a source file, for use
@@ -922,7 +909,9 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
   }
 
   // Lookup/add string.
-  StringHandle addString(llvm::StringRef Str) { return Strings.intern(Str); }
+  StringHandle addString(llvm::StringRef Str) {
+    return Strings.insert(Str).first->first();
+  }
 
   // Convert to a canonical path.
   std::string getCanonicalPath(llvm::StringRef path) const {
@@ -950,7 +939,7 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
     HeaderHandle H = 0;
     for (auto I = HeaderPaths.begin(), E = HeaderPaths.end(); I != E;
          ++I, ++H) {
-      if (**I == CanonicalPath)
+      if (*I == CanonicalPath)
         return H;
     }
     return HeaderHandleInvalid;
@@ -1143,10 +1132,10 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
       // Tell caller we found one or more errors.
       ReturnValue = true;
       // Start the error message.
-      OS << *MacroExpTracker.InstanceSourceLine;
+      OS << MacroExpTracker.InstanceSourceLine;
       if (ItemKey.Column > 0)
         OS << std::string(ItemKey.Column - 1, ' ') << "^\n";
-      OS << "error: Macro instance '" << *MacroExpTracker.MacroUnexpanded
+      OS << "error: Macro instance '" << MacroExpTracker.MacroUnexpanded
          << "' has 
diff erent values in this header, depending on how it was "
             "included.\n";
       // Walk all the instances.
@@ -1154,8 +1143,8 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
                 EMT = MacroExpTracker.MacroExpansionInstances.end();
            IMT != EMT; ++IMT) {
         MacroExpansionInstance &MacroInfo = *IMT;
-        OS << "  '" << *MacroExpTracker.MacroUnexpanded << "' expanded to: '"
-           << *MacroInfo.MacroExpanded
+        OS << "  '" << MacroExpTracker.MacroUnexpanded << "' expanded to: '"
+           << MacroInfo.MacroExpanded
            << "' with respect to these inclusion paths:\n";
         // Walk all the inclusion path hierarchies.
         for (auto IIP = MacroInfo.InclusionPathHandles.begin(),
@@ -1165,7 +1154,7 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
           auto Count = (int)ip.size();
           for (int Index = 0; Index < Count; ++Index) {
             HeaderHandle H = ip[Index];
-            OS << std::string((Index * 2) + 4, ' ') << *getHeaderFilePath(H)
+            OS << std::string((Index * 2) + 4, ' ') << getHeaderFilePath(H)
                << "\n";
           }
         }
@@ -1173,7 +1162,7 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
         // instance location.
         // If there is a definition...
         if (MacroInfo.DefinitionLocation.Line != ItemKey.Line) {
-          OS << *MacroInfo.DefinitionSourceLine;
+          OS << MacroInfo.DefinitionSourceLine;
           if (MacroInfo.DefinitionLocation.Column > 0)
             OS << std::string(MacroInfo.DefinitionLocation.Column - 1, ' ')
                << "^\n";
@@ -1201,13 +1190,13 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
       // Tell caller we found one or more errors.
       ReturnValue = true;
       // Start the error message.
-      OS << *HeaderPaths[ItemKey.File] << ":" << ItemKey.Line << ":"
+      OS << HeaderPaths[ItemKey.File] << ":" << ItemKey.Line << ":"
          << ItemKey.Column << "\n";
       OS << "#" << getDirectiveSpelling(CondTracker.DirectiveKind) << " "
-         << *CondTracker.ConditionUnexpanded << "\n";
+         << CondTracker.ConditionUnexpanded << "\n";
       OS << "^\n";
       OS << "error: Conditional expression instance '"
-         << *CondTracker.ConditionUnexpanded
+         << CondTracker.ConditionUnexpanded
          << "' has 
diff erent values in this header, depending on how it was "
             "included.\n";
       // Walk all the instances.
@@ -1215,7 +1204,7 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
                 EMT = CondTracker.ConditionalExpansionInstances.end();
            IMT != EMT; ++IMT) {
         ConditionalExpansionInstance &MacroInfo = *IMT;
-        OS << "  '" << *CondTracker.ConditionUnexpanded << "' expanded to: '"
+        OS << "  '" << CondTracker.ConditionUnexpanded << "' expanded to: '"
            << ConditionValueKindStrings[MacroInfo.ConditionValue]
            << "' with respect to these inclusion paths:\n";
         // Walk all the inclusion path hierarchies.
@@ -1226,7 +1215,7 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
           auto Count = (int)ip.size();
           for (int Index = 0; Index < Count; ++Index) {
             HeaderHandle H = ip[Index];
-            OS << std::string((Index * 2) + 4, ' ') << *getHeaderFilePath(H)
+            OS << std::string((Index * 2) + 4, ' ') << getHeaderFilePath(H)
                << "\n";
           }
         }
@@ -1255,7 +1244,7 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
   llvm::SmallVector<std::string, 32> HeaderList;
   // Only do extern, namespace check for headers in HeaderList.
   bool BlockCheckHeaderListOnly;
-  llvm::StringPool Strings;
+  llvm::StringSet<> Strings;
   std::vector<StringHandle> HeaderPaths;
   std::vector<HeaderHandle> HeaderStack;
   std::vector<HeaderInclusionPath> InclusionPaths;


        


More information about the cfe-commits mailing list