Hi tareqsiraj, arielbernal, Sarcasm,

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.

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

Files:
  clang-modernize/Core/Transform.cpp
  clang-modernize/Core/Transform.h
  clang-modernize/tool/ClangModernize.cpp
  test/clang-modernize/HeaderReplacements/main.cpp
  test/clang-modernize/HeaderReplacements/no_yaml.cpp
  test/clang-modernize/ReplaceAutoPtr/basic.cpp
  test/clang-modernize/UseNullptr/Inputs/basic.h
  test/clang-modernize/UseNullptr/basic.cpp
  unittests/clang-modernize/TransformTest.cpp
Index: clang-modernize/Core/Transform.cpp
===================================================================
--- clang-modernize/Core/Transform.cpp
+++ clang-modernize/Core/Transform.cpp
@@ -87,9 +87,6 @@
   if (SM.isWrittenInMainFile(Loc))
     return true;
 
-  if (!GlobalOptions.EnableHeaderModifications)
-    return false;
-
   const FileEntry *FE = SM.getFileEntryForID(SM.getFileID(Loc));
   if (!FE)
     return false;
Index: clang-modernize/Core/Transform.h
===================================================================
--- clang-modernize/Core/Transform.h
+++ clang-modernize/Core/Transform.h
@@ -66,11 +66,6 @@
   /// \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;
Index: clang-modernize/tool/ClangModernize.cpp
===================================================================
--- clang-modernize/tool/ClangModernize.cpp
+++ clang-modernize/tool/ClangModernize.cpp
@@ -118,18 +118,9 @@
                 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 @@
   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);
 
Index: test/clang-modernize/HeaderReplacements/main.cpp
===================================================================
--- test/clang-modernize/HeaderReplacements/main.cpp
+++ test/clang-modernize/HeaderReplacements/main.cpp
@@ -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
Index: test/clang-modernize/HeaderReplacements/no_yaml.cpp
===================================================================
--- test/clang-modernize/HeaderReplacements/no_yaml.cpp
+++ test/clang-modernize/HeaderReplacements/no_yaml.cpp
@@ -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
Index: test/clang-modernize/ReplaceAutoPtr/basic.cpp
===================================================================
--- test/clang-modernize/ReplaceAutoPtr/basic.cpp
+++ test/clang-modernize/ReplaceAutoPtr/basic.cpp
@@ -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
Index: test/clang-modernize/UseNullptr/Inputs/basic.h
===================================================================
--- test/clang-modernize/UseNullptr/Inputs/basic.h
+++ test/clang-modernize/UseNullptr/Inputs/basic.h
@@ -1,3 +1,2 @@
 int *global_p = 0;
-// CHECK: int *global_p = 0;
-// HEADERS: int *global_p = nullptr;
+// CHECK: int *global_p = nullptr;
Index: test/clang-modernize/UseNullptr/basic.cpp
===================================================================
--- test/clang-modernize/UseNullptr/basic.cpp
+++ test/clang-modernize/UseNullptr/basic.cpp
@@ -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"
 
Index: unittests/clang-modernize/TransformTest.cpp
===================================================================
--- unittests/clang-modernize/TransformTest.cpp
+++ unittests/clang-modernize/TransformTest.cpp
@@ -191,8 +191,8 @@
 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 @@
     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 @@
 
 private:
   const Transform &Owner;
-  bool HeadersModifiable;
 };
 
 TEST(Transform, isFileModifiable) {
@@ -282,25 +279,10 @@
   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) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to