# All known modules
readable attr _modules: Array[MMModule] = new Array[MMModule]
- # Register a new module with the modules it depends on
+ # Register a new module with the modules it depends on
meth add_module(module: MMModule, supers: Array[MMModule])
do
- assert supers != null
_module_hierarchy.add(module, _module_hierarchy.select_smallests(supers))
- assert module.name != null
_modules.add(module)
module._mhe = _module_hierarchy[module]
end
# Register a local class
meth add_local_class(c: MMLocalClass, sup: Array[MMLocalClass])
do
- assert sup != null
var csup = new Array[MMLocalClass]
var csups = new Array[String]
for s in sup do
# Parent directory
# null if none
- readable attr _parent: MMDirectory
+ readable attr _parent: nullable MMDirectory
# The module that introduces the directory if any
- readable writable attr _owner: MMModule
+ readable writable attr _owner: nullable MMModule = null
# Known modules in the directory
readable attr _modules: Map[Symbol, MMModule] = new HashMap[Symbol, MMModule]
_modules[module.name] = module
end
- # Directory hierarchy element
- readable attr _dhe: PartialOrderElement[MMDirectory]
-
- init(name: Symbol, path: String, parent: MMDirectory) do
+ init(name: Symbol, path: String, parent: nullable MMDirectory) do
_name = name
_path = path
_parent = parent
readable attr _filename: String
# Module dependence hierarchy element
- readable attr _mhe: PartialOrderElement[MMModule]
+ readable attr _mhe: nullable PartialOrderElement[MMModule]
# All global classes of the module (defined and imported)
readable attr _global_classes: Array[MMGlobalClass] = new Array[MMGlobalClass]
_name = name
_directory = dir
_context = context
-
- if dir == null then
- _full_name = name
- else
- _full_name = dir.full_name_for(name)
- end
+ _full_name = dir.full_name_for(name)
_filename = filename
end
# Get the local class associated with a global class
meth [](c: MMGlobalClass): MMLocalClass
do
- assert _local_class_by_global != null
- assert c != null
return _local_class_by_global[c]
end
# Assign super_classes for a local class
meth set_supers_class(c: MMLocalClass, supers: Array[MMLocalClass])
do
- assert supers != null
var tab = _class_specialization_hierarchy.select_smallests(supers)
c._cshe = _class_specialization_hierarchy.add(c,tab)
var tab_all = c.crhe.direct_greaters.to_a
# Register a local class and its global class in the module
private meth register_global_class(c: MMLocalClass)
do
- assert c.global != null
_local_class_by_global[c.global] = c
end
end
# register a new Local class to local class hierarchy (set the crhe value)
private meth register_local_class(c: MMLocalClass)
do
- assert c.module != null
- assert c.crhe == null
- var sup = new Array[MMLocalClass]
+ var sup = new Array[MMLocalClass]
for s in class_refinement_hierarchy do
if c.module.mhe < s.module and s isa MMConcreteClass then
sup.add(s)
readable attr _module: MMModule
# The global class of the local class
- readable attr _global: MMGlobalClass
+ meth global: MMGlobalClass do return _global.as(not null)
+ attr _global: nullable MMGlobalClass
# The local class refinement hierarchy element
- readable attr _crhe: PartialOrderElement[MMLocalClass]
+ meth crhe: PartialOrderElement[MMLocalClass] do return _crhe.as(not null)
+ attr _crhe: nullable PartialOrderElement[MMLocalClass]
# The local class specialization hierarchy element
- readable attr _cshe: PartialOrderElement[MMLocalClass]
+ meth cshe: PartialOrderElement[MMLocalClass] do return _cshe.as(not null)
+ attr _cshe: nullable PartialOrderElement[MMLocalClass]
# The local class full hierarchy element
- readable attr _che: PartialOrderElement[MMLocalClass]
+ meth che: PartialOrderElement[MMLocalClass] do return _che.as(not null)
+ attr _che: nullable PartialOrderElement[MMLocalClass]
# Association between local properties and global properties
- readable attr _local_property_by_global: Map[MMGlobalProperty, MMLocalProperty]
+ attr _local_property_by_global: Map[MMGlobalProperty, MMLocalProperty] = new HashMap[MMGlobalProperty, MMLocalProperty]
# All known global properties
- readable attr _global_properties: Set[MMGlobalProperty]
+ readable attr _global_properties: Set[MMGlobalProperty] = new HashSet[MMGlobalProperty]
# Dictionnary of global properties
- readable attr _properties_by_name: Map[Symbol, Array[MMGlobalProperty]]
+ attr _properties_by_name: Map[Symbol, Array[MMGlobalProperty]] = new HashMap[Symbol, Array[MMGlobalProperty]]
# Create a new class with a given name and arity
protected init(mod: MMModule, name: Symbol, arity: Int)
# refined classes for this class
meth set_global(g: MMGlobalClass)
do
- assert g != null
_global = g
_global.register_local_class(self)
_module.register_global_class(self)
# TODO: Will disapear when qualified names will be available
meth method(na: Symbol): MMGlobalProperty
do
- assert _properties_by_name != null
return _properties_by_name[na].first
end
# TODO: Will disapear when qualified names will be available
meth select_method(name: Symbol): MMMethod
do
- assert name != null
var gp = method(name)
var res = self[gp]
assert res isa MMMethod
# TODO: Will disapear when qualified names will be available
meth select_attribute(name: Symbol): MMAttribute
do
- assert name != null
var gp = attribute(name)
var res = self[gp]
assert res isa MMAttribute
# Register a local property and associate it with its global property
meth register_local_property(p: MMLocalProperty)
do
- assert p.global != null
- # FIXME: Why a test?
- if not _local_property_by_global.has_key(p.global) then
- _local_property_by_global[p.global] = p
- end
+ _local_property_by_global[p.global] = p
end
# Register a global property and associate it with its name
readable attr _intro: MMLocalProperty
# The local class that introduces the global property
- meth local_class: MMLocalClass
- do
- return intro.local_class
- end
+ meth local_class: MMLocalClass
+ do
+ return intro.local_class
+ end
# The property redefinition hierarchy
readable attr _property_hierarchy: PartialOrder[MMLocalProperty] = new PartialOrder[MMLocalProperty]
# Create a new global property introduced by a local one
protected init(p: MMLocalProperty)
do
- assert p != null
-
- _property_hierarchy = new PartialOrder[MMLocalProperty]
-
_intro = p
add_local_property(p, new Array[MMLocalProperty])
end
# Register a new local property
meth add_local_property(i: MMLocalProperty, sup: Array[MMLocalProperty])
do
- assert i != null
- assert sup != null
i._prhe = _property_hierarchy.add(i,sup)
end
meth is_method: Bool do return intro isa MMMethod
# Is the global property a constructor (thus also a method)?
- readable writable attr _is_init: Bool
+ readable writable attr _is_init: Bool = false
# Is the global property a constructor for a given class?
meth is_init_for(c: MMLocalClass): Bool
readable attr _local_class: MMLocalClass
# The global property where belong the local property
- readable attr _global: MMGlobalProperty
+ attr _global: nullable MMGlobalProperty
+
+ meth global: MMGlobalProperty do return _global.as(not null)
+ meth is_global_set: Bool do return _global != null
# Redefinition hierarchy of the local property
- readable attr _prhe: PartialOrderElement[MMLocalProperty]
+ attr _prhe: nullable PartialOrderElement[MMLocalProperty]
+
+ meth prhe: PartialOrderElement[MMLocalProperty] do return _prhe.as(not null)
# The module of the local property
meth module: MMModule do return _local_class.module
# Full expanded name with all qualifications
meth full_name: String
do
- if global == null then
+ if _global == null then
return "{local_class.module}::{local_class}::(?::{name})"
else if global.intro == self then
return "{local_class.module}::{local_class}::{name}"
# set the global property for this property
meth set_global(g: MMGlobalProperty)
do
- assert g != null
_global = g
_local_class.register_local_property(self)
end
meth new_global
do
assert _global == null
- _global = new MMGlobalProperty(self)
- _local_class.register_global_property(_global)
+ var global = new MMGlobalProperty(self)
+ _global = global
+ _local_class.register_global_property(global)
end
-
+
redef meth to_s do return name.to_s
# Is the concrete property contain a `super' in the body?