nitc :: mmodule_data
This module help analysis and tool to store piece of data in MModule
then
retrieve them through the importation relation.
MModuleData
where multiples values could be set on a single module
MModuleData
where multiples values could be set on a single module
Serializable::inspect
to show more useful information
more_collections :: more_collections
Highly specific, but useful, collections-related classes.serialization :: serialization_core
Abstract services to serialize Nit objects to different formatscore :: union_find
union–find algorithm using an efficient disjoint-set data structurenitc :: actors_generation_phase
Generate a support module for each module that contain a class annotated withis actor
nitc :: actors_injection_phase
Injects model for the classes annotated with "is actor" sonitc :: api_metrics
nitc :: astbuilder
Instantiation and transformation of semantic nodes in the AST of expressions and statementscflags
and ldflags
to specify
nitc :: commands_ini
extra_java_files
to compile extra java files
nitc :: i18n_phase
Basic support of internationalization through the generation of id-to-string tablesnitc :: light_only
Compiler support for the light FFI only, detects unsupported usage of callbacksnitc
.
nitc :: nitmetrics
A program that collects various metrics on nit programs and librariesnitc :: nitrestful
Tool generating boilerplate code linking RESTful actions to Nit methodsthreaded
annotation
nitc :: separate_erasure_compiler
Separate compilation of a Nit program with generic type erasurenitc :: serialization_code_gen_phase
Phase generating methods (code) to serialize Nit objectsnitc :: serialization_model_phase
Phase generating methods (model-only) to serialize Nit objectsclone
method of the astbuilder tool
nitc :: uml_module
Services for generation of a UML package diagram based on aModel
# Define and retrieve data in modules
# This module help analysis and tool to store piece of data in `MModule` then
# retrieve them through the importation relation.
module mmodule_data
import mmodule
# A map-like structure to associate `E` to` MModule`
# The advantage of this class is the various `lookup_*` method that
# allow to retrieve values trough the importation relation.
class MModuleData[E: Object]
# The model associated with the data
# Used to execute correclty mmodule-related operation
var model: Model
# is a value locally defined in `mmodule`
fun has_mmodule(mmodule: MModule): Bool
do
return defs.has_key(mmodule)
end
# The value locally defined in `mmodule`.
# Return null if no value locally defined.
fun [](mmodule: MModule): nullable E
do
return defs.get_or_null(mmodule)
end
# Set the value locally defined in `mmodule`.
# Gining `null` just undefine the value
fun []=(mmodule: MModule, value: nullable E)
do
if value == null then
defs.keys.remove(mmodule)
else
defs[mmodule] = value
end
end
private var defs = new HashMap[MModule, E]
# Return all the super modules that defines a value
# `min_visibility` is used to filter modules by their visibility in `mmodule`.
fun lookup_all_modules(mmodule: MModule, min_visibility: MVisibility): Sequence[MModule]
do
var res = new Array[MModule]
for m in mmodule.in_importation.greaters do
if mmodule.visibility_for(m) < min_visibility then continue
if self.defs.has_key(m) then res.add(m)
end
return res
end
# Return all the values defined in `mmodule` and its imported modules.
# `min_visibility` is used to filter modules by their visibility in `mmodule`.
# This method could be usefull to check possible static conflicts.
fun lookup_all_values(mmodule: MModule, min_visibility: MVisibility): Sequence[E]
do
var mmodules = lookup_all_modules(mmodule, min_visibility)
mmodules = model.mmodule_importation_hierarchy.linearize(mmodules)
var res = new Array[E]
for m in mmodules do res.add defs[m]
return res
end
# Return the most specific values defined in `mmodule` and its imported modules.
# `min_visibility_` is used to filter modules by their visibility in `mmodule`.
# Unlike `lookup_all_values`, redefined values are hidden,
# However, in case of conflit, all conflicting definitions are returned
fun lookup_values(mmodule: MModule, min_visibility: MVisibility): Sequence[E]
do
var mmodules = lookup_all_modules(mmodule, min_visibility)
mmodules = model.mmodule_importation_hierarchy.select_smallest(mmodules)
var res = new Array[E]
for m in mmodules do res.add defs[m]
return res
end
# Return the most specific values defined in `mmodule` and its imported modules.
# Unlike `lookup_values`, only the most specific value, according to importation, is returned.
fun lookup_first_value(mmodule: MModule, min_visibility: MVisibility): nullable E
do
var mmodules = lookup_all_modules(mmodule, min_visibility)
if mmodules.is_empty then return null
mmodules = model.mmodule_importation_hierarchy.linearize(mmodules)
return defs[mmodules.last]
end
end
# A `MModuleData` where multiples values could be set on a single module
# a-la `MultiHashMap`
class MModuleMultiData[E]
super MModuleData[Array[E]]
# Instead of `null` return an empty array usable
redef fun [](mmodule)
do
var res = super
if res == null then
res = new Array[E]
defs[mmodule] = res
end
return res
end
# like `lookup_all_values` but return a big concatenated sequence (instead of a sequence of array)
fun lookup_joined_values(mmodule: MModule, min_visibility: MVisibility): Sequence[E]
do
var mmodules = lookup_all_modules(mmodule, min_visibility)
mmodules = model.mmodule_importation_hierarchy.linearize(mmodules)
var res = new Array[E]
for m in mmodules do res.add_all defs[m]
return res
end
end
src/model/mmodule_data.nit:15,1--129,3