Complex or mature work should use the full phase
framework to enable
combination and orcherstration of works.
mainmodule
is the bottom main module (possibly implicit).given_mmodules
is the exact list of module from the command line.modelbuilder
is the context that contains a lot of things.@toimplement
# Easy entry point to prototype a specific work or proof-of-concept.
#
# Complex or mature work should use the full `phase` framework to enable
# combination and orcherstration of works.
#
# * `mainmodule` is the bottom main module (possibly implicit).
# * `given_mmodules` is the exact list of module from the command line.
# * `modelbuilder` is the context that contains a lot of things.
#
# @toimplement
fun do_work(mainmodule: MModule, given_mmodules: SequenceRead[MModule], modelbuilder: ModelBuilder) do end
src/test_phase.nit:37,1--47,106
# The body of the specific work.
# The main entry point is provided by `test_phase`,
# This function is then automatically (unless errors where found).
redef fun do_work(mainmodule, given_mmodules, modelbuilder)
do
print "It works"
var model = modelbuilder.model
print "I have {model.mpackages.length} packages"
print "I have {model.mmodules.length} modules"
var mclasses = mainmodule.flatten_mclass_hierarchy
print "I have {mclasses.length} classes"
var m_cpt = 0
var md_cpt = 0
var cd_cpt = 0
for m in mainmodule.in_importation.greaters do
for cd in m.mclassdefs do
cd_cpt += 1
for pd in cd.mpropdefs do
if pd isa MMethodDef then
md_cpt += 1
if pd.is_intro then m_cpt += 1
end
end
end
end
print "For {cd_cpt} definitions of classes"
print "I have {m_cpt} methods"
print "For {md_cpt} definitions of methods"
end
src/test_test_phase.nit:27,1--56,3
redef fun do_work(mainmodule, given_mmodules, modelbuilder) do
var toolcontext = modelbuilder.toolcontext
var analysis: StaticAnalysis
var analysis_name = toolcontext.opt_analysis.value_name
if analysis_name == "reaching-defs" then
analysis = new ReachingDefsAnalysis(modelbuilder)
else
print "Error: unkown analysis {analysis_name}"
sys.exit 1
return
end
var mainnode = modelbuilder.mmodule2node(mainmodule)
if mainnode == null then return
analysis.start_analysis(mainnode)
analysis.pretty_print
end
src/nitsaf.nit:33,1--50,3
# The body of the specific work.
# The main entry point is provided by `test_phase`,
# This function is then automatically (unless errors where found).
redef fun do_work(mainmodule, given_mmodules, modelbuilder)
do
var model = modelbuilder.model
print "All entities, including fictive ones:"
var filters = new ModelFilter(private_visibility, accept_fictive = true)
var v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
var names = v.names
print "All entities:"
filters = new ModelFilter(private_visibility)
v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
print "\nAll non-private entities:"
filters = new ModelFilter(protected_visibility)
v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
print "\nAll documented non-private entities:"
filters = new ModelFilter(protected_visibility, accept_empty_doc = false)
v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
print "\nAll public entities:"
filters = new ModelFilter(public_visibility)
v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
print "\nAll documented public entities:"
filters = new ModelFilter(public_visibility, accept_empty_doc = false)
v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
print "\nNames:"
print "\n# Classes of entities"
var cpt
cpt = new Counter[String]
for n, e in names do
cpt.inc(e.class_name)
end
cpt.print_summary
cpt.print_elements(10)
print "\n# Name length of entities"
cpt = new Counter[String]
for n, e in names do
cpt[n] = n.length
end
cpt.print_summary
cpt.print_elements(10)
print "\n# All entities"
for n, e in names do
var c = ""
var d = e.mdoc_or_fallback
if d != null and d.content.not_empty then c = d.content.first
print "{n}\t{e.class_name}\t{e.location}\t{c}"
end
end
src/test_model_visitor.nit:50,1--119,3
redef fun do_work(mainmodule, mmodules, mb)
do
var v = new TestHighlightVisitor
print """<head>
<meta charset="utf-8">
<style type="text/css">
{{{v.css_content}}}
</style>
{{{v.head_content}}}
</head><body>
"""
for mm in mmodules do for cd in mm.mclassdefs do for pd in cd.mpropdefs do
var n = mb.mpropdef2node(pd)
if not n isa APropdef then continue
var hl = new TestHighlightVisitor
hl.highlight_node(n)
print "<h1 id=\"{pd.c_name}\">{pd.full_name}</h1>"
printn "<pre><code>"
hl.html.write_to(stdout)
print "</code></pre>"
end
# Some random nodes
var thlv = new THLVisitor
for mm in mmodules do
var n = mb.mmodule2node(mm)
thlv.enter_visit(n)
end
print v.foot_content
print "</body></html>"
end
src/test_highlight.nit:28,1--60,3