[clang-tools-extra] r176465 - Added summary option to cpp11-migrate tool
Dmitri Gribenko
gribozavr at gmail.com
Mon Mar 4 16:12:33 PST 2013
Author: gribozavr
Date: Mon Mar 4 18:12:33 2013
New Revision: 176465
URL: http://llvm.org/viewvc/llvm-project?rev=176465&view=rev
Log:
Added summary option to cpp11-migrate tool
Added a summary option that enables output to stdout counting the number of
changes each transform has accepted, rejected or deferred.
Patch by Ariel Bernal.
Modified:
clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp
clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.cpp
clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.h
clang-tools-extra/trunk/cpp11-migrate/Transform.h
clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.cpp
clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.h
clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.cpp
clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.h
Modified: clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp?rev=176465&r1=176464&r2=176465&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp Mon Mar 4 18:12:33 2013
@@ -54,6 +54,10 @@ static cl::opt<bool> FinalSyntaxCheck(
cl::desc("Check for correct syntax after applying transformations"),
cl::init(false));
+static cl::opt<bool>
+SummaryMode("summary", cl::desc("Print transform summary"),
+ cl::init(false));
+
class EndSyntaxArgumentsAdjuster : public ArgumentsAdjuster {
CommandLineArguments Adjust(const CommandLineArguments &Args) {
CommandLineArguments AdjustedArgs = Args;
@@ -93,6 +97,18 @@ int main(int argc, const char **argv) {
// FIXME: Improve ClangTool to not abort if just one file fails.
return 1;
}
+ if (SummaryMode) {
+ llvm::outs() << "Transform: " << (*I)->getName()
+ << " - Accepted: "
+ << (*I)->getAcceptedChanges();
+ if ((*I)->getChangesNotMade()) {
+ llvm::outs() << " - Rejected: "
+ << (*I)->getRejectedChanges()
+ << " - Deferred: "
+ << (*I)->getDeferredChanges();
+ }
+ llvm::outs() << "\n";
+ }
std::swap(InputFileStates, OutputFileStates);
OutputFileStates->clear();
}
Modified: clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.cpp?rev=176465&r1=176464&r2=176465&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.cpp Mon Mar 4 18:12:33 2013
@@ -76,13 +76,9 @@ int LoopConvertTransform::apply(const Fi
collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
- if (AcceptedChanges > 0) {
- setChangesMade();
- }
-
- if (RejectedChanges > 0 || DeferredChanges > 0) {
- setChangesNotMade();
- }
+ setAcceptedChanges(AcceptedChanges);
+ setRejectedChanges(RejectedChanges);
+ setDeferredChanges(DeferredChanges);
return 0;
}
Modified: clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.h?rev=176465&r1=176464&r2=176465&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.h Mon Mar 4 18:12:33 2013
@@ -23,6 +23,7 @@
/// for-loops where possible.
class LoopConvertTransform : public Transform {
public:
+ LoopConvertTransform() : Transform("LoopConvert") {}
/// \see Transform::run().
virtual int apply(const FileContentsByPath &InputStates,
Modified: clang-tools-extra/trunk/cpp11-migrate/Transform.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Transform.h?rev=176465&r1=176464&r2=176465&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Transform.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Transform.h Mon Mar 4 18:12:33 2013
@@ -106,7 +106,7 @@ private:
/// \brief Abstract base class for all C++11 migration transforms.
class Transform {
public:
- Transform() {
+ Transform(llvm::StringRef Name) : Name(Name) {
Reset();
}
@@ -126,29 +126,52 @@ public:
FileContentsByPath &ResultStates) = 0;
/// \brief Query if changes were made during the last call to apply().
- bool getChangesMade() const { return ChangesMade; }
+ bool getChangesMade() const { return AcceptedChanges > 0; }
/// \brief Query if changes were not made due to conflicts with other changes
/// made during the last call to apply() or if changes were too risky for the
/// requested risk level.
- bool getChangesNotMade() const { return ChangesNotMade; }
+ bool getChangesNotMade() const {
+ return RejectedChanges > 0 || DeferredChanges > 0;
+ }
+
+ /// \brief Query the number of accepted changes.
+ unsigned getAcceptedChanges() const { return AcceptedChanges; }
+ /// \brief Query the number of changes considered too risky.
+ unsigned getRejectedChanges() const { return RejectedChanges; }
+ /// \brief Query the number of changes not made because they conflicted with
+ /// early changes.
+ unsigned getDeferredChanges() const { return DeferredChanges; }
+
+ /// \brief Query transform name.
+ llvm::StringRef getName() const { return Name; }
/// \brief Reset internal state of the transform.
///
/// Useful if calling apply() several times with one instantiation of a
/// transform.
void Reset() {
- ChangesMade = false;
- ChangesNotMade = false;
+ AcceptedChanges = 0;
+ RejectedChanges = 0;
+ DeferredChanges = 0;
}
protected:
- void setChangesMade() { ChangesMade = true; }
- void setChangesNotMade() { ChangesNotMade = true; }
+ void setAcceptedChanges(unsigned Changes) {
+ AcceptedChanges = Changes;
+ }
+ void setRejectedChanges(unsigned Changes) {
+ RejectedChanges = Changes;
+ }
+ void setDeferredChanges(unsigned Changes) {
+ DeferredChanges = Changes;
+ }
private:
- bool ChangesMade;
- bool ChangesNotMade;
+ const std::string Name;
+ unsigned AcceptedChanges;
+ unsigned RejectedChanges;
+ unsigned DeferredChanges;
};
#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H
Modified: clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.cpp?rev=176465&r1=176464&r2=176465&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.cpp Mon Mar 4 18:12:33 2013
@@ -51,8 +51,7 @@ int UseAutoTransform::apply(const FileCo
collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
- if (AcceptedChanges > 0)
- setChangesMade();
+ setAcceptedChanges(AcceptedChanges);
return 0;
}
Modified: clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.h?rev=176465&r1=176464&r2=176465&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.h Mon Mar 4 18:12:33 2013
@@ -29,6 +29,8 @@
/// p2 are not handled by this transform.
class UseAutoTransform : public Transform {
public:
+ UseAutoTransform() : Transform("UseAuto") {}
+
/// \see Transform::run().
virtual int apply(const FileContentsByPath &InputStates,
RiskLevel MaxRiskLEvel,
Modified: clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.cpp?rev=176465&r1=176464&r2=176465&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.cpp Mon Mar 4 18:12:33 2013
@@ -60,9 +60,7 @@ int UseNullptrTransform::apply(const Fil
collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
- if (AcceptedChanges > 0) {
- setChangesMade();
- }
+ setAcceptedChanges(AcceptedChanges);
return 0;
}
Modified: clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.h?rev=176465&r1=176464&r2=176465&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.h Mon Mar 4 18:12:33 2013
@@ -23,6 +23,8 @@
/// C++11's nullptr keyword where possible.
class UseNullptrTransform : public Transform {
public:
+ UseNullptrTransform() : Transform("UseNullptr") {}
+
/// \see Transform::run().
virtual int apply(const FileContentsByPath &InputStates,
RiskLevel MaxRiskLEvel,
More information about the cfe-commits
mailing list