[clang-tools-extra] r274848 - [include-fixer] Don't add qualifiers to symbols which have global scope operator.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 8 07:28:43 PDT 2016


Author: hokein
Date: Fri Jul  8 09:28:43 2016
New Revision: 274848

URL: http://llvm.org/viewvc/llvm-project?rev=274848&view=rev
Log:
[include-fixer] Don't add qualifiers to symbols which have global scope operator.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D22127

Modified:
    clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp
    clang-tools-extra/trunk/include-fixer/IncludeFixerContext.h
    clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp

Modified: clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp?rev=274848&r1=274847&r2=274848&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp Fri Jul  8 09:28:43 2016
@@ -34,6 +34,10 @@ tooling::Replacement
 IncludeFixerContext::createSymbolReplacement(llvm::StringRef FilePath,
                                              size_t Idx) {
   assert(Idx < MatchedSymbols.size());
+  // No need to add missing qualifiers if SymbolIndentifer has a global scope
+  // operator "::".
+  if (getSymbolIdentifier().startswith("::"))
+    return tooling::Replacement();
   std::string QualifiedName = MatchedSymbols[Idx].getQualifiedName();
   // For nested classes, the qualified name constructed from database misses
   // some stripped qualifiers, because when we search a symbol in database,

Modified: clang-tools-extra/trunk/include-fixer/IncludeFixerContext.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/IncludeFixerContext.h?rev=274848&r1=274847&r2=274848&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/IncludeFixerContext.h (original)
+++ clang-tools-extra/trunk/include-fixer/IncludeFixerContext.h Fri Jul  8 09:28:43 2016
@@ -30,6 +30,7 @@ public:
   /// symbol.
   tooling::Replacement createSymbolReplacement(llvm::StringRef FilePath,
                                                size_t Idx = 0);
+
   /// \brief Get symbol name.
   llvm::StringRef getSymbolIdentifier() const { return SymbolIdentifier; }
 

Modified: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp?rev=274848&r1=274847&r2=274848&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp Fri Jul  8 09:28:43 2016
@@ -242,18 +242,18 @@ TEST(IncludeFixer, FixNamespaceQualifier
   EXPECT_EQ("#include \"bar.h\"\nnamespace a {\nb::bar::t b;\n}\n",
             runIncludeFixer("namespace a {\nbar::t b;\n}\n"));
 
-  EXPECT_EQ(
-      "#include \"color.h\"\nint test = a::b::Green;\n",
-      runIncludeFixer("int test = Green;\n"));
+  EXPECT_EQ("#include \"color.h\"\nint test = a::b::Green;\n",
+            runIncludeFixer("int test = Green;\n"));
   EXPECT_EQ("#include \"color.h\"\nnamespace d {\nint test = a::b::Green;\n}\n",
             runIncludeFixer("namespace d {\nint test = Green;\n}\n"));
   EXPECT_EQ("#include \"color.h\"\nnamespace a {\nint test = b::Green;\n}\n",
             runIncludeFixer("namespace a {\nint test = Green;\n}\n"));
 
-  // FIXME: Fix-namespace should not fix the global qualified identifier.
-  EXPECT_EQ(
-      "#include \"bar.h\"\na::b::bar b;\n",
-      runIncludeFixer("::a::b::bar b;\n"));
+  // Test global scope operator.
+  EXPECT_EQ("#include \"bar.h\"\n::a::b::bar b;\n",
+            runIncludeFixer("::a::b::bar b;\n"));
+  EXPECT_EQ("#include \"bar.h\"\nnamespace a {\n::a::b::bar b;\n}\n",
+            runIncludeFixer("namespace a {\n::a::b::bar b;\n}\n"));
 }
 
 } // namespace




More information about the cfe-commits mailing list