X-Git-Url: http://nitlanguage.org diff --git a/src/model/mmodule.nit b/src/model/mmodule.nit index a3ee105..648eb49 100644 --- a/src/model/mmodule.nit +++ b/src/model/mmodule.nit @@ -28,8 +28,10 @@ redef class Model # All known modules var mmodules: Array[MModule] = new Array[MModule] - # Module nesting hierarchy. + # placebo for old module nesting hierarchy. # where mainmodule < mainmodule::nestedmodule + # + # TODO REMOVE, rely on mgroup instead var mmodule_nesting_hierarchy: POSet[MModule] = new POSet[MModule] # Full module importation hierarchy including private or nested links. @@ -55,21 +57,34 @@ end redef class MGroup # The loaded modules of this group var mmodules = new Array[MModule] + + # Placebo stuff to find the owner (module with same name) + # null is returned if there is no owner, or if it is not loaded yet + fun fuzzy_owner: nullable MModule + do + for m in mmodules do if m.name == name then return m + return null + end end # A Nit module is usually associated with a Nit source file. class MModule + super MConcern + # The model considered - var model: Model + redef var model: Model - # The direct nesting module, return null if self is not nested (ie. is a top-level module) + # placebo for old module nesting hierarchy + # return null if self is not nested (ie. is a top-level module) + # + # TODO REMOVE, rely on mgroup instead var direct_owner: nullable MModule # The group of module in the project if any var mgroup: nullable MGroup # The short name of the module - var name: String + redef var name: String # The origin of the definition var location: Location @@ -77,7 +92,10 @@ class MModule # Alias for `name` redef fun to_s do return self.name + # placebo for old module nesting hierarchy # The view of the module in the `model.mmodule_nesting_hierarchy` + # + # TODO REMOVE, rely on mgroup instead var in_nesting: POSetElement[MModule] # The view of the module in the `model.mmodule_importation_hierarchy` @@ -96,8 +114,7 @@ class MModule end # Create a new empty module and register it to a model - # `direct_owner` is the direct owner (null if top-level module) - init(model: Model, direct_owner: nullable MModule, name: String, location: Location) + init(model: Model, mgroup: nullable MGroup, name: String, location: Location) do self.model = model self.name = name @@ -105,9 +122,25 @@ class MModule model.mmodules_by_name.add_one(name, self) model.mmodules.add(self) self.in_nesting = model.mmodule_nesting_hierarchy.add_node(self) - self.direct_owner = direct_owner - if direct_owner != null then - model.mmodule_nesting_hierarchy.add_edge(direct_owner, self) + self.mgroup = mgroup + if mgroup != null then + mgroup.mmodules.add(self) + # placebo for old module nesting hierarchy + var direct_owner = mgroup.fuzzy_owner + if direct_owner == self then + # The module is the new owner of its own group, thus adopt the other modules + for m in mgroup.mmodules do + if m == self then continue + m.direct_owner = self + model.mmodule_nesting_hierarchy.add_edge(self, m) + end + # The potential owner is the the fuzzy_owner of the parent group + if mgroup.parent != null then direct_owner = mgroup.parent.fuzzy_owner + end + if direct_owner != self and direct_owner != null then + self.direct_owner = direct_owner + model.mmodule_nesting_hierarchy.add_edge(direct_owner, self) + end end self.in_importation = model.mmodule_importation_hierarchy.add_node(self) end @@ -160,17 +193,15 @@ class MModule end end - # The first module in the nesting hierarchy to export self as public - # This function is used to determine the canonical name of modules, classes and properties. - # REQUIRE: the visibility of all nesting modules is already set. + # placebo for old module nesting hierarchy fun public_owner: nullable MModule do - var res = self.direct_owner - var last = res - while last != null do - if last.visibility_for(self) >= public_visibility then res = last - last = last.direct_owner - end + var mgroup = self.mgroup + if mgroup == null then return null + mgroup = mgroup.mproject.root + if mgroup.mmodules.is_empty then return null + var res = mgroup.fuzzy_owner + if res == self then return null return res end @@ -190,4 +221,11 @@ class MModule abort end end + + # Is the mmodule created for internal purpose? + # Fictive module are instantied internally but they should not be + # exposed to the final user + var is_fictive: Bool writable = false + + redef fun parent_concern do return mgroup end