[PATCH] Added summary option to cpp11-migrate tool

Ariel Bernal ariel.j.bernal at intel.com
Fri Mar 1 12:56:05 PST 2013


  Fixed capitals variable names

Hi klimek,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D338?vs=1167&id=1170#toc

Files:
  cpp11-migrate/Cpp11Migrate.cpp
  cpp11-migrate/LoopConvert/LoopConvert.cpp
  cpp11-migrate/LoopConvert/LoopConvert.h
  cpp11-migrate/Transform.h
  cpp11-migrate/UseAuto/UseAuto.cpp
  cpp11-migrate/UseAuto/UseAuto.h
  cpp11-migrate/UseNullptr/UseNullptr.cpp
  cpp11-migrate/UseNullptr/UseNullptr.h

Index: cpp11-migrate/Cpp11Migrate.cpp
===================================================================
--- cpp11-migrate/Cpp11Migrate.cpp
+++ cpp11-migrate/Cpp11Migrate.cpp
@@ -49,6 +49,10 @@
                clEnumValEnd),
     cl::init(RL_Reasonable));
 
+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;
@@ -98,6 +102,18 @@
       // 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();
   }
Index: cpp11-migrate/LoopConvert/LoopConvert.cpp
===================================================================
--- cpp11-migrate/LoopConvert/LoopConvert.cpp
+++ cpp11-migrate/LoopConvert/LoopConvert.cpp
@@ -76,13 +76,9 @@
 
   collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
 
-  if (AcceptedChanges > 0) {
-    setChangesMade();
-  }
-
-  if (RejectedChanges > 0 || DeferredChanges > 0) {
-    setChangesNotMade();
-  }
+  setAcceptedChanges(AcceptedChanges);
+  setRejectedChanges(RejectedChanges);
+  setDeferredChanges(DeferredChanges);
 
   return 0;
 }
Index: cpp11-migrate/LoopConvert/LoopConvert.h
===================================================================
--- cpp11-migrate/LoopConvert/LoopConvert.h
+++ cpp11-migrate/LoopConvert/LoopConvert.h
@@ -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,
Index: cpp11-migrate/Transform.h
===================================================================
--- cpp11-migrate/Transform.h
+++ cpp11-migrate/Transform.h
@@ -106,7 +106,7 @@
 /// \brief Abstract base class for all C++11 migration transforms.
 class Transform {
 public:
-  Transform() {
+  Transform(const llvm::StringRef &Name) : Name(Name) {
     Reset();
   }
 
@@ -126,29 +126,52 @@
                     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;
+  std::string Name;
+  unsigned AcceptedChanges;
+  unsigned RejectedChanges;
+  unsigned DeferredChanges;
 };
 
 #endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H
Index: cpp11-migrate/UseAuto/UseAuto.cpp
===================================================================
--- cpp11-migrate/UseAuto/UseAuto.cpp
+++ cpp11-migrate/UseAuto/UseAuto.cpp
@@ -51,8 +51,7 @@
 
   collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
 
-  if (AcceptedChanges > 0)
-    setChangesMade();
+  setAcceptedChanges(AcceptedChanges);
 
   return 0;
 }
Index: cpp11-migrate/UseAuto/UseAuto.h
===================================================================
--- cpp11-migrate/UseAuto/UseAuto.h
+++ cpp11-migrate/UseAuto/UseAuto.h
@@ -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,
Index: cpp11-migrate/UseNullptr/UseNullptr.cpp
===================================================================
--- cpp11-migrate/UseNullptr/UseNullptr.cpp
+++ cpp11-migrate/UseNullptr/UseNullptr.cpp
@@ -60,9 +60,7 @@
 
   collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
 
-  if (AcceptedChanges > 0) {
-    setChangesMade();
-  }
+  setAcceptedChanges(AcceptedChanges);
 
   return 0;
 }
Index: cpp11-migrate/UseNullptr/UseNullptr.h
===================================================================
--- cpp11-migrate/UseNullptr/UseNullptr.h
+++ cpp11-migrate/UseNullptr/UseNullptr.h
@@ -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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D338.4.patch
Type: text/x-patch
Size: 6453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130301/dc76ff37/attachment.bin>


More information about the llvm-commits mailing list