X-Git-Url: http://nitlanguage.org diff --git a/src/metrics/metrics_base.nit b/src/metrics/metrics_base.nit index 627af78..c68947b 100644 --- a/src/metrics/metrics_base.nit +++ b/src/metrics/metrics_base.nit @@ -19,6 +19,7 @@ module metrics_base import model_utils import csv +import counter redef class ToolContext @@ -31,6 +32,8 @@ redef class ToolContext var opt_refinement = new OptionBool("Compute metrics about refinement usage", "--refinement") # --self var opt_self = new OptionBool("Compute metrics about the usage of explicit and implicit self", "--self") + # --ast + var opt_ast = new OptionBool("Compute metrics about the usage of nodes and identifiers in the AST", "--ast") # --nullables var opt_nullables = new OptionBool("Compute metrics on nullables send", "--nullables") # --static-types @@ -43,6 +46,8 @@ redef class ToolContext var opt_generate_csv = new OptionBool("Generate CVS format metrics", "--generate-csv") # --generate_hyperdoc var opt_generate_hyperdoc = new OptionBool("Generate Hyperdoc", "--generate_hyperdoc") + # --poset + var opt_poset = new OptionBool("Complete metrics on posets", "--poset") var opt_dir = new OptionString("Directory where some statistics files are generated", "-d", "--dir") var output_dir: String = "." @@ -54,12 +59,14 @@ redef class ToolContext self.option_context.add_option(opt_inheritance) self.option_context.add_option(opt_refinement) self.option_context.add_option(opt_self) + self.option_context.add_option(opt_ast) self.option_context.add_option(opt_nullables) 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_csv) self.option_context.add_option(opt_generate_hyperdoc) + self.option_context.add_option(opt_poset) self.option_context.add_option(opt_dir) end @@ -118,50 +125,3 @@ redef class MModule return not self.model.std_modules.has(self.name) end end - -# A counter counts occurence of things -# Use this instead of a HashMap[E, Int] -class Counter[E: Object] - # Total number of counted occurences - var total: Int = 0 - - private var map = new HashMap[E, Int] - - # The number of counted occurences of `e' - fun [](e: E): Int - do - var map = self.map - if map.has_key(e) then return map[e] - return 0 - end - - # Count one more occurence of `e' - fun inc(e: E) - do - self.map[e] = self[e] + 1 - total += 1 - end - - # Return an array of elements sorted by occurences - fun sort: Array[E] - do - var res = map.keys.to_a - var sorter = new CounterSorter[E](self) - sorter.sort(res) - #res.sort !cmp a, b = map[a] <=> map[b] - return res - end -end - -private class CounterSorter[E: Object] - super AbstractSorter[E] - var counter: Counter[E] - redef fun compare(a,b) do return self.counter.map[a] <=> self.counter.map[b] -end - -# Helper function to display n/d and handle division by 0 -fun div(n: Int, d: Int): String -do - if d == 0 then return "na" - return ((100*n/d).to_f/100.0).to_precision(2) -end