forked from OSchip/llvm-project
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. llvm-svn: 176465
This commit is contained in:
parent
4c8979cd4d
commit
f68a5280cb
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -76,13 +76,9 @@ int LoopConvertTransform::apply(const FileContentsByPath &InputStates,
|
|||
|
||||
collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
|
||||
|
||||
if (AcceptedChanges > 0) {
|
||||
setChangesMade();
|
||||
}
|
||||
|
||||
if (RejectedChanges > 0 || DeferredChanges > 0) {
|
||||
setChangesNotMade();
|
||||
}
|
||||
setAcceptedChanges(AcceptedChanges);
|
||||
setRejectedChanges(RejectedChanges);
|
||||
setDeferredChanges(DeferredChanges);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -51,8 +51,7 @@ int UseAutoTransform::apply(const FileContentsByPath &InputStates,
|
|||
|
||||
collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
|
||||
|
||||
if (AcceptedChanges > 0)
|
||||
setChangesMade();
|
||||
setAcceptedChanges(AcceptedChanges);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -60,9 +60,7 @@ int UseNullptrTransform::apply(const FileContentsByPath &InputStates,
|
|||
|
||||
collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
|
||||
|
||||
if (AcceptedChanges > 0) {
|
||||
setChangesMade();
|
||||
}
|
||||
setAcceptedChanges(AcceptedChanges);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue