+
+ # vt coloration
+ var vt_coloring = new CLPropertyLayoutBuilder[MVirtualTypeProp](mainmodule)
+ var vt_layout = vt_coloring.build_layout(mclasses)
+ self.vt_tables = build_vt_tables(mclasses, vt_layout)
+ self.compile_color_consts(vt_layout.pos)
+ self.vt_layout = vt_layout
+ end
+
+ fun build_vt_tables(mclasses: Set[MClass], layout: PropertyLayout[MProperty]): Map[MClass, Array[nullable MPropDef]] do
+ var tables = new HashMap[MClass, Array[nullable MPropDef]]
+ for mclass in mclasses do
+ var table = new Array[nullable MPropDef]
+ # first, fill table from parents by reverse linearization order
+ var parents = self.mainmodule.super_mclasses(mclass)
+ var lin = self.mainmodule.reverse_linearize_mclasses(parents)
+ for parent in lin do
+ for mproperty in self.mainmodule.properties(parent) do
+ if not mproperty isa MVirtualTypeProp 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
+ end
+
+ # then override with local properties
+ for mproperty in self.mainmodule.properties(mclass) do
+ if not mproperty isa MVirtualTypeProp 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
+ tables[mclass] = table
+ end
+ return tables