+ fun build_method_tables(mclasses: Set[MClass], super_calls: Set[MMethodDef]): Map[MClass, Array[nullable MPropDef]] do
+ var layout = self.method_layout
+ var tables = new HashMap[MClass, Array[nullable MPropDef]]
+ for mclass in mclasses do
+ var table = new Array[nullable MPropDef]
+ var supercalls = new List[MMethodDef]
+
+ # first, fill table from parents by reverse linearization order
+ var parents = new Array[MClass]
+ if mainmodule.flatten_mclass_hierarchy.has(mclass) then
+ parents = mclass.in_hierarchy(mainmodule).greaters.to_a
+ self.mainmodule.linearize_mclasses(parents)
+ end
+
+ for parent in parents do
+ if parent == mclass then continue
+ for mproperty in self.mainmodule.properties(parent) do
+ if not mproperty isa MMethod then continue
+ var color = layout.pos[mproperty]
+ if table.length <= color then
+ for i in [table.length .. color[ do
+ table[i] = null
+ end
+ end
+ for mpropdef in mproperty.mpropdefs do
+ if mpropdef.mclassdef.mclass == parent then
+ table[color] = mpropdef
+ end
+ end
+ end
+
+ # lookup for super calls in super classes
+ for mmethoddef in super_calls do
+ for mclassdef in parent.mclassdefs do
+ if mclassdef.mpropdefs.has(mmethoddef) then
+ supercalls.add(mmethoddef)
+ end
+ end
+ end
+ end
+
+ # then override with local properties
+ for mproperty in self.mainmodule.properties(mclass) do
+ if not mproperty isa MMethod then continue
+ var color = layout.pos[mproperty]
+ if table.length <= color then
+ for i in [table.length .. color[ do
+ table[i] = null
+ end
+ end
+ for mpropdef in mproperty.mpropdefs do
+ if mpropdef.mclassdef.mclass == mclass then
+ table[color] = mpropdef
+ end
+ end
+ end
+
+ # lookup for super calls in local class
+ for mmethoddef in super_calls do
+ for mclassdef in mclass.mclassdefs do
+ if mclassdef.mpropdefs.has(mmethoddef) then
+ supercalls.add(mmethoddef)
+ end
+ end
+ end
+ # insert super calls in table according to receiver
+ for supercall in supercalls do
+ var color = layout.pos[supercall]
+ if table.length <= color then
+ for i in [table.length .. color[ do
+ table[i] = null
+ end
+ end
+ var mmethoddef = supercall.lookup_next_definition(self.mainmodule, mclass.intro.bound_mtype)
+ table[color] = mmethoddef
+ end
+ tables[mclass] = table