nitmetrics: refactor static types metrics computation
authorAlexandre Terrasa <alexadre@moz-code.org>
Sun, 4 Nov 2012 20:26:05 +0000 (15:26 -0500)
committerJean Privat <jean@pryen.org>
Mon, 5 Nov 2012 19:17:53 +0000 (14:17 -0500)
Signed-off-by: Alexandre Terrasa <alexadre@moz-code.org>

src/metrics/metrics.nit
src/metrics/metrics_base.nit
src/metrics/static_types_metrics.nit [moved from src/metrics/count_ntypes.nit with 90% similarity]
src/nitmetrics.nit

index 7904ca6..d3a1245 100644 (file)
@@ -18,7 +18,7 @@
 module metrics
 
 import metrics_base
-import count_ntypes
+import static_types_metrics
 import visit_nullable_sends
 import visit_self
 import model_stats
index 4d5b55c..10c9546 100644 (file)
@@ -21,6 +21,8 @@ import modelbuilder
 
 redef class ToolContext
 
+       # --static-types
+       var opt_static_types = new OptionBool("Compute explicit static types metrics", "--static-types")
        # --tables
        var opt_tables = new OptionBool("Compute tables metrics", "--tables")
        # --rta
@@ -34,6 +36,7 @@ redef class ToolContext
        redef init
        do
                super
+               self.option_context.add_option(opt_static_types)
                self.option_context.add_option(opt_tables)
                self.option_context.add_option(opt_rta)
                self.option_context.add_option(opt_generate_hyperdoc)
similarity index 90%
rename from src/metrics/count_ntypes.nit
rename to src/metrics/static_types_metrics.nit
index c74a37b..9986f13 100644 (file)
@@ -14,8 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Statistics on the usage of explicit static types.
-module count_ntypes
+# Metrics on the usage of explicit static types.
+module static_types_metrics
 
 private import metrics_base
 import modelbuilder
@@ -48,8 +48,8 @@ private class ATypeCounterVisitor
        end
 end
 
-# Visit the AST and print statistics on the usage of explicit static types.
-fun count_ntypes(modelbuilder: ModelBuilder)
+# Visit the AST and print metrics on the usage of explicit static types.
+fun compute_static_types_metrics(modelbuilder: ModelBuilder)
 do
        # Count each occurence of a specific static type
        var typecount = new Counter[MType]
@@ -63,7 +63,7 @@ do
        end
 
        # Display data
-       print "--- Statistics of the explitic static types ---"
+       print "--- Metrics of the explitic static types ---"
        print "Total number of explicit static types: {typecount.total}"
        if typecount.total == 0 then return
 
index 14073e1..f0bee27 100644 (file)
@@ -65,8 +65,11 @@ visit_self(modelbuilder)
 print ""
 visit_nullable_sends(modelbuilder)
 
-print ""
-count_ntypes(modelbuilder)
+# Static types metrics
+if toolcontext.opt_static_types.value then
+       print ""
+       compute_static_types_metrics(modelbuilder)
+end
 
 # Tables metrics
 if toolcontext.opt_tables.value then