X-Git-Url: http://nitlanguage.org diff --git a/src/model_utils.nit b/src/model_utils.nit index 1c375ba..b2c741b 100644 --- a/src/model_utils.nit +++ b/src/model_utils.nit @@ -63,6 +63,44 @@ redef class MModule end return mclasses end + + fun in_nesting_intro_mclasses(min_visibility: MVisibility): Set[MClass] do + var res = new HashSet[MClass] + for mmodule in in_nesting.greaters do + for mclass in mmodule.intro_mclasses do + if mclass.visibility < min_visibility then continue + res.add mclass + end + end + return res + end + + fun in_nesting_redef_mclasses(min_visibility: MVisibility): Set[MClass] do + var res = new HashSet[MClass] + for mmodule in self.in_nesting.greaters do + for mclass in mmodule.redef_mclasses do + if mclass.visibility < min_visibility then continue + res.add mclass + end + end + return res + end + + fun in_nesting_intro_mclassdefs(min_visibility: MVisibility): Set[MClassDef] do + var res = new HashSet[MClassDef] + for mmodule in in_nesting.greaters do + res.add_all mmodule.intro_mclassdefs(min_visibility) + end + return res + end + + fun in_nesting_redef_mclassdefs(min_visibility: MVisibility): Set[MClassDef] do + var res = new HashSet[MClassDef] + for mmodule in self.in_nesting.greaters do + res.add_all mmodule.redef_mclassdefs(min_visibility) + end + return res + end end redef class MClass @@ -162,6 +200,18 @@ redef class MClass return set end + fun intro_mpropdefs(min_visibility: MVisibility): Set[MPropDef] do + var set = new HashSet[MPropDef] + for mclassdef in mclassdefs do + for mpropdef in mclassdef.mpropdefs do + if not mpropdef.is_intro then continue + if mpropdef.mproperty.visibility < min_visibility then continue + set.add(mpropdef) + end + end + return set + end + # the set of locally refined properties in 'self'. fun redef_mproperties(min_visibility: MVisibility): Set[MProperty] do var set = new HashSet[MProperty] @@ -174,6 +224,18 @@ redef class MClass return set end + fun redef_mpropdefs(min_visibility: MVisibility): Set[MPropDef] do + var set = new HashSet[MPropDef] + for mclassdef in mclassdefs do + for mpropdef in mclassdef.mpropdefs do + if mpropdef.is_intro then continue + if mpropdef.mproperty.visibility < min_visibility then continue + set.add(mpropdef) + end + end + return set + end + # the set of methods inherited by 'self'. fun inherited_mproperties(mainmodule: MModule, min_visibility: MVisibility): Set[MProperty] do var set = new HashSet[MProperty] @@ -290,6 +352,49 @@ redef class MAttribute fun is_nullable: Bool do return intro.static_mtype isa MNullableType end +redef class MClassDef + # modifiers are keywords like redef, private etc. + fun modifiers: Array[String] do + var res = new Array[String] + if not is_intro then + res.add "redef" + else + res.add mclass.visibility.to_s + end + res.add mclass.kind.to_s + return res + end +end + +redef class MPropDef + # modifiers are keywords like redef, private etc. + fun modifiers: Array[String] do + var res = new Array[String] + if not is_intro then + res.add "redef" + else + res.add mproperty.visibility.to_s + end + var mprop = self + if mprop isa MVirtualTypeDef then + res.add "type" + else if mprop isa MMethodDef then + if mprop.is_abstract then + res.add "abstract" + else if mprop.is_intern then + res.add "intern" + end + if mprop.mproperty.is_init then + res.add "init" + else + res.add "fun" + end + end + return res + end +end + + # Sorters # Sort mmodules by their name