[clang-tools-extra] r190158 - clang-modernize: Remove -headers option

Edwin Vane edwin.vane at intel.com
Fri Sep 6 07:23:57 PDT 2013


Author: revane
Date: Fri Sep  6 09:23:56 2013
New Revision: 190158

URL: http://llvm.org/viewvc/llvm-project?rev=190158&view=rev
Log:
clang-modernize: Remove -headers option

clang-modernize can now transform headers properly and the experimental
-headers option is no longer necessary.

Remember, at least -include is necessary for indicating which headers
are allowed to be changed.

Differential Revision: http://llvm-reviews.chandlerc.com/D1610


Modified:
    clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp
    clang-tools-extra/trunk/clang-modernize/Core/Transform.h
    clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp
    clang-tools-extra/trunk/test/clang-modernize/HeaderReplacements/main.cpp
    clang-tools-extra/trunk/test/clang-modernize/HeaderReplacements/no_yaml.cpp
    clang-tools-extra/trunk/test/clang-modernize/ReplaceAutoPtr/basic.cpp
    clang-tools-extra/trunk/test/clang-modernize/UseNullptr/Inputs/basic.h
    clang-tools-extra/trunk/test/clang-modernize/UseNullptr/basic.cpp
    clang-tools-extra/trunk/unittests/clang-modernize/TransformTest.cpp

Modified: clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp?rev=190158&r1=190157&r2=190158&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp Fri Sep  6 09:23:56 2013
@@ -87,9 +87,6 @@ bool Transform::isFileModifiable(const S
   if (SM.isWrittenInMainFile(Loc))
     return true;
 
-  if (!GlobalOptions.EnableHeaderModifications)
-    return false;
-
   const FileEntry *FE = SM.getFileEntryForID(SM.getFileID(Loc));
   if (!FE)
     return false;

Modified: clang-tools-extra/trunk/clang-modernize/Core/Transform.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/Core/Transform.h?rev=190158&r1=190157&r2=190158&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/Core/Transform.h (original)
+++ clang-tools-extra/trunk/clang-modernize/Core/Transform.h Fri Sep  6 09:23:56 2013
@@ -66,11 +66,6 @@ struct TransformOptions {
   /// \brief Enable the use of performance timers.
   bool EnableTiming;
 
-  /// \brief Allow changes to headers included from the main source file.
-  /// Transform sub-classes should use ModifiableHeaders to determine which
-  /// headers are modifiable and which are not.
-  bool EnableHeaderModifications;
-
   /// \brief Contains information on which headers are safe to transform and
   /// which aren't.
   IncludeExcludeInfo ModifiableHeaders;

Modified: clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp?rev=190158&r1=190157&r2=190158&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp Fri Sep  6 09:23:56 2013
@@ -118,18 +118,9 @@ ExcludeFromFile("exclude-from", cl::Hidd
                 cl::desc("File containing a list of paths that can not be "
                          "transforms"));
 
-// Header modifications will probably be always on eventually. For now, they
-// need to be explicitly enabled.
-static cl::opt<bool, /*ExternalStorage=*/true> EnableHeaderModifications(
-    "headers",
-    cl::Hidden, // Experimental feature for now.
-    cl::desc("Enable modifications to headers"),
-    cl::location(GlobalOptions.EnableHeaderModifications),
-    cl::init(false));
-
 static cl::opt<bool>
 SerializeReplacements("serialize-replacements",
-                      cl::Hidden, // Associated with -headers
+                      cl::Hidden,
                       cl::desc("Serialize translation unit replacements to "
                                "disk instead of changing files."),
                       cl::init(false));
@@ -336,14 +327,11 @@ int main(int argc, const char **argv) {
   if (CmdSwitchError)
     return 1;
 
-  // Populate the ModifiableHeaders structure if header modifications are
-  // enabled.
-  if (GlobalOptions.EnableHeaderModifications) {
-    GlobalOptions.ModifiableHeaders
-        .readListFromString(IncludePaths, ExcludePaths);
-    GlobalOptions.ModifiableHeaders
-        .readListFromFile(IncludeFromFile, ExcludeFromFile);
-  }
+  // Populate the ModifiableHeaders structure.
+  GlobalOptions.ModifiableHeaders
+      .readListFromString(IncludePaths, ExcludePaths);
+  GlobalOptions.ModifiableHeaders
+      .readListFromFile(IncludeFromFile, ExcludeFromFile);
 
   TransformManager.createSelectedTransforms(GlobalOptions, RequiredVersions);
 

Modified: clang-tools-extra/trunk/test/clang-modernize/HeaderReplacements/main.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-modernize/HeaderReplacements/main.cpp?rev=190158&r1=190157&r2=190158&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-modernize/HeaderReplacements/main.cpp (original)
+++ clang-tools-extra/trunk/test/clang-modernize/HeaderReplacements/main.cpp Fri Sep  6 09:23:56 2013
@@ -7,7 +7,7 @@
 // RUN: rm -rf %T/SerializeTest
 // RUN: mkdir -p %T/SerializeTest
 // RUN: cp %S/main.cpp %S/common.cpp %S/common.h %T/SerializeTest
-// RUN: clang-modernize -loop-convert -headers -serialize-replacements -include=%T/SerializeTest %T/SerializeTest/main.cpp %T/SerializeTest/common.cpp --
+// RUN: clang-modernize -loop-convert -serialize-replacements -include=%T/SerializeTest %T/SerializeTest/main.cpp %T/SerializeTest/common.cpp --
 // Check that only 1 file is generated per translation unit
 // RUN: ls -1 %T/SerializeTest | FileCheck %s --check-prefix=MAIN_CPP
 // RUN: ls -1 %T/SerializeTest | FileCheck %s --check-prefix=COMMON_CPP

Modified: clang-tools-extra/trunk/test/clang-modernize/HeaderReplacements/no_yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-modernize/HeaderReplacements/no_yaml.cpp?rev=190158&r1=190157&r2=190158&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-modernize/HeaderReplacements/no_yaml.cpp (original)
+++ clang-tools-extra/trunk/test/clang-modernize/HeaderReplacements/no_yaml.cpp Fri Sep  6 09:23:56 2013
@@ -4,7 +4,7 @@
 // RUN: mkdir -p %T/Inputs
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
 // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/no_yaml.h > %T/Inputs/no_yaml.h
-// RUN: clang-modernize -loop-convert %t.cpp -headers -include=%T/Inputs -- -I %T/Inputs/no_yaml.h
+// RUN: clang-modernize -loop-convert %t.cpp -include=%T/Inputs -- -I %T/Inputs/no_yaml.h
 // RUN: FileCheck --input-file=%t.cpp %s
 // RUN: FileCheck --input-file=%T/Inputs/no_yaml.h %S/Inputs/no_yaml.h
 // RUN: ls -1 %T | FileCheck %s --check-prefix=NO_YAML

Modified: clang-tools-extra/trunk/test/clang-modernize/ReplaceAutoPtr/basic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-modernize/ReplaceAutoPtr/basic.cpp?rev=190158&r1=190157&r2=190158&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-modernize/ReplaceAutoPtr/basic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-modernize/ReplaceAutoPtr/basic.cpp Fri Sep  6 09:23:56 2013
@@ -5,7 +5,7 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
 // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/basic.h > %T/Inputs/basic.h
 // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/memory_stub.h > %T/Inputs/memory_stub.h
-// RUN: clang-modernize -headers -include=%T -replace-auto_ptr %t.cpp -- \
+// RUN: clang-modernize -include=%T -replace-auto_ptr %t.cpp -- \
 // RUN:               -std=c++11 -I %T
 // RUN: FileCheck -input-file=%t.cpp %s
 // RUN: FileCheck -input-file=%T/Inputs/basic.h %S/Inputs/basic.h
@@ -15,7 +15,7 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
 // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/basic.h > %T/Inputs/basic.h
 // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/memory_stub.h > %T/Inputs/memory_stub.h
-// RUN: clang-modernize -headers -include=%T -replace-auto_ptr %t.cpp -- \
+// RUN: clang-modernize -include=%T -replace-auto_ptr %t.cpp -- \
 // RUN:               -DUSE_INLINE_NAMESPACE=1 -std=c++11 -I %T
 // RUN: FileCheck -input-file=%t.cpp %s
 // RUN: FileCheck -input-file=%T/Inputs/basic.h %S/Inputs/basic.h

Modified: clang-tools-extra/trunk/test/clang-modernize/UseNullptr/Inputs/basic.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-modernize/UseNullptr/Inputs/basic.h?rev=190158&r1=190157&r2=190158&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-modernize/UseNullptr/Inputs/basic.h (original)
+++ clang-tools-extra/trunk/test/clang-modernize/UseNullptr/Inputs/basic.h Fri Sep  6 09:23:56 2013
@@ -1,3 +1,2 @@
 int *global_p = 0;
-// CHECK: int *global_p = 0;
-// HEADERS: int *global_p = nullptr;
+// CHECK: int *global_p = nullptr;

Modified: clang-tools-extra/trunk/test/clang-modernize/UseNullptr/basic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-modernize/UseNullptr/basic.cpp?rev=190158&r1=190157&r2=190158&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-modernize/UseNullptr/basic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-modernize/UseNullptr/basic.cpp Fri Sep  6 09:23:56 2013
@@ -1,13 +1,9 @@
 // RUN: mkdir -p %T/Inputs
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
 // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/basic.h > %T/Inputs/basic.h
-// RUN: clang-modernize -use-nullptr %t.cpp -- -std=c++98 -I %T -Wno-non-literal-null-conversion
+// RUN: clang-modernize -use-nullptr -include=%T %t.cpp -- -std=c++98 -I %T -Wno-non-literal-null-conversion
 // RUN: FileCheck -input-file=%t.cpp %s
 // RUN: FileCheck -input-file=%T/Inputs/basic.h %S/Inputs/basic.h
-// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/basic.h > %T/Inputs/basic.h
-// RUN: clang-modernize -headers -include=%T -use-nullptr %t.cpp -- -std=c++98 -I %T -Wno-non-literal-null-conversion
-// RUN: FileCheck -check-prefix=HEADERS -input-file=%T/Inputs/basic.h %S/Inputs/basic.h
 
 #include "Inputs/basic.h"
 

Modified: clang-tools-extra/trunk/unittests/clang-modernize/TransformTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-modernize/TransformTest.cpp?rev=190158&r1=190157&r2=190158&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-modernize/TransformTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-modernize/TransformTest.cpp Fri Sep  6 09:23:56 2013
@@ -191,8 +191,8 @@ TEST(Transform, Timings) {
 class ModifiableCallback
     : public clang::ast_matchers::MatchFinder::MatchCallback {
 public:
-  ModifiableCallback(const Transform &Owner, bool HeadersModifiable)
-      : Owner(Owner), HeadersModifiable(HeadersModifiable) {}
+  ModifiableCallback(const Transform &Owner)
+      : Owner(Owner) {}
 
   virtual void
   run(const clang::ast_matchers::MatchFinder::MatchResult &Result) {
@@ -209,11 +209,9 @@ public:
     else if (Decl->getName().equals("c"))
       EXPECT_FALSE(Owner.isFileModifiable(SM, Decl->getLocStart()));
 
-    // Decl 'b' comes from an included header. It should be modifiable only if
-    // header modifications are allowed.
+    // Decl 'b' comes from an included header.
     else if (Decl->getName().equals("b"))
-      EXPECT_EQ(HeadersModifiable,
-                Owner.isFileModifiable(SM, Decl->getLocStart()));
+      EXPECT_TRUE(Owner.isFileModifiable(SM, Decl->getLocStart()));
 
     // Make sure edge cases are handled gracefully (they should never be
     // allowed).
@@ -223,7 +221,6 @@ public:
 
 private:
   const Transform &Owner;
-  bool HeadersModifiable;
 };
 
 TEST(Transform, isFileModifiable) {
@@ -282,25 +279,10 @@ TEST(Transform, isFileModifiable) {
   Tool.mapVirtualFile(HeaderFile, "int b;");
   Tool.mapVirtualFile(HeaderBFile, "int c;");
 
-  // Run tests with header modifications turned off.
-  {
-    SCOPED_TRACE("Header Modifications are OFF");
-    Options.EnableHeaderModifications = false;
-    DummyTransform T("dummy", Options);
-    MatchFinder Finder;
-    Finder.addMatcher(varDecl().bind("decl"), new ModifiableCallback(T, false));
-    Tool.run(tooling::newFrontendActionFactory(&Finder));
-  }
-
-  // Run again with header modifications turned on.
-  {
-    SCOPED_TRACE("Header Modifications are ON");
-    Options.EnableHeaderModifications = true;
-    DummyTransform T("dummy", Options);
-    MatchFinder Finder;
-    Finder.addMatcher(varDecl().bind("decl"), new ModifiableCallback(T, true));
-    Tool.run(tooling::newFrontendActionFactory(&Finder));
-  }
+  DummyTransform T("dummy", Options);
+  MatchFinder Finder;
+  Finder.addMatcher(varDecl().bind("decl"), new ModifiableCallback(T));
+  Tool.run(tooling::newFrontendActionFactory(&Finder));
 }
 
 TEST(VersionTest, Interface) {





More information about the cfe-commits mailing list