+
+ # The primitive type Object, the root of the class hierarchy
+ fun object_type: MClassType
+ do
+ var res = self.object_type_cache
+ if res != null then return res
+ res = self.get_primitive_class("Object").mclass_type
+ self.object_type_cache = res
+ return res
+ end
+
+ private var object_type_cache: nullable MClassType
+
+ # The primitive type Bool
+ fun bool_type: MClassType
+ do
+ var res = self.bool_type_cache
+ if res != null then return res
+ res = self.get_primitive_class("Bool").mclass_type
+ self.bool_type_cache = res
+ return res
+ end
+
+ private var bool_type_cache: nullable MClassType
+
+ # The primitive type Sys, the main type of the program, if any
+ fun sys_type: nullable MClassType
+ do
+ var clas = self.model.get_mclasses_by_name("Sys")
+ if clas == null then return null
+ return get_primitive_class("Sys").mclass_type
+ end
+
+ # Force to get the primitive class named `name' or abort
+ fun get_primitive_class(name: String): MClass
+ do
+ var cla = self.model.get_mclasses_by_name(name)
+ if cla == null then
+ if name == "Bool" then
+ var c = new MClass(self, name, 0, enum_kind, public_visibility)
+ var cladef = new MClassDef(self, c.mclass_type, new Location(null, 0,0,0,0), new Array[String])
+ return c
+ end
+ print("Fatal Error: no primitive class {name}")
+ exit(1)
+ end
+ assert cla.length == 1 else print cla.join(", ")
+ return cla.first
+ end
+
+ # Try to get the primitive method named `name' on the type `recv'
+ fun try_get_primitive_method(name: String, recv: MClass): nullable MMethod
+ do
+ var props = self.model.get_mproperties_by_name(name)
+ if props == null then return null
+ var res: nullable MMethod = null
+ for mprop in props do
+ assert mprop isa MMethod
+ var intro = mprop.intro_mclassdef
+ for mclassdef in recv.mclassdefs do
+ if not self.in_importation.greaters.has(mclassdef.mmodule) then continue
+ if not mclassdef.in_hierarchy.greaters.has(intro) then continue
+ if res == null then
+ res = mprop
+ else if res != mprop then
+ print("Fatal Error: ambigous property name '{name}'; conflict between {mprop.full_name} and {res.full_name}")
+ abort
+ end
+ end
+ end
+ return res
+ end
+end
+
+private class MClassDefSorter
+ super AbstractSorter[MClassDef]
+ var mmodule: MModule
+ redef fun compare(a, b)
+ do
+ var ca = a.mclass
+ var cb = b.mclass
+ if ca != cb then return mmodule.flatten_mclass_hierarchy.compare(ca, cb)
+ return mmodule.model.mclassdef_hierarchy.compare(a, b)
+ end
+end
+
+private class MPropDefSorter
+ super AbstractSorter[MPropDef]
+ var mmodule: MModule
+ redef fun compare(pa, pb)
+ do
+ var a = pa.mclassdef
+ var b = pb.mclassdef
+ var ca = a.mclass
+ var cb = b.mclass
+ if ca != cb then return mmodule.flatten_mclass_hierarchy.compare(ca, cb)
+ return mmodule.model.mclassdef_hierarchy.compare(a, b)
+ end