forked from OSchip/llvm-project
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 llvm-svn: 190158
This commit is contained in:
parent
5c1035e7fa
commit
5f002639e4
|
@ -87,9 +87,6 @@ bool Transform::isFileModifiable(const SourceManager &SM,
|
|||
if (SM.isWrittenInMainFile(Loc))
|
||||
return true;
|
||||
|
||||
if (!GlobalOptions.EnableHeaderModifications)
|
||||
return false;
|
||||
|
||||
const FileEntry *FE = SM.getFileEntryForID(SM.getFileID(Loc));
|
||||
if (!FE)
|
||||
return false;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -118,18 +118,9 @@ ExcludeFromFile("exclude-from", cl::Hidden, cl::value_desc("filename"),
|
|||
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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
int *global_p = 0;
|
||||
// CHECK: int *global_p = 0;
|
||||
// HEADERS: int *global_p = nullptr;
|
||||
// CHECK: int *global_p = nullptr;
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue