nitc :: ast_metrics
Serializable::inspect
to show more useful information
nitc :: modelbuilder
more_collections :: more_collections
Highly specific, but useful, collections-related classes.serialization :: serialization_core
Abstract services to serialize Nit objects to different formatsnitc :: toolcontext
Common command-line tool infrastructure than handle options and error messagescore :: union_find
union–find algorithm using an efficient disjoint-set data structurenitc :: api_metrics
nitc :: nitmetrics
A program that collects various metrics on nit programs and libraries
# Metrics about the nodes and identifiers in the AST
module ast_metrics
import metrics_base
redef class ToolContext
var ast_metrics_phase: Phase = new AstMetricsPhase(self, null)
end
private class AstMetricsPhase
super Phase
var node_counter = new Counter[String]
var id_counter = new Counter[String]
redef fun process_mainmodule(mainmodule, given_mmodules)
do
if not toolcontext.opt_ast.value and not toolcontext.opt_all.value then return
print "--- AST Metrics ---"
# Visit all the source code to collect data
var visitor = new AstMetricsVisitor(self)
for nmodule in toolcontext.modelbuilder.nmodules do
visitor.enter_visit(nmodule)
end
print "## All nodes of the AST"
node_counter.print_summary
node_counter.print_elements(10)
print "## All identifiers of the AST"
id_counter.print_summary
id_counter.print_elements(10)
end
end
private class AstMetricsVisitor
super Visitor
var phase: AstMetricsPhase
redef fun visit(n)
do
n.visit_all(self)
phase.node_counter.inc(n.class_name)
if n isa TId or n isa TAttrid or n isa TClassid then
assert n isa Token
phase.id_counter.inc(n.text)
end
end
end
src/metrics/ast_metrics.nit:17,1--62,3