- var layout_builder: ClassLayoutBuilder
- if modelbuilder.toolcontext.opt_phmod_typing.value then
- layout_builder = new PHClassLayoutBuilder(mainmodule, new PHModOperator)
- self.header.add_decl("#define HASH(mask, id) ((mask)%(id))")
- else if modelbuilder.toolcontext.opt_phand_typing.value then
- layout_builder = new PHClassLayoutBuilder(mainmodule, new PHAndOperator)
- self.header.add_decl("#define HASH(mask, id) ((mask)&(id))")
- else if modelbuilder.toolcontext.opt_bm_typing.value then
- layout_builder = new BMClassLayoutBuilder(mainmodule)
- else
- layout_builder = new CLClassLayoutBuilder(mainmodule)
+ # vt coloration
+ var vt_colorer = new POSetBucketsColorer[MClass, MVirtualTypeProp](poset, colorer.conflicts)
+ vt_colors = vt_colorer.colorize(vts)
+ vt_tables = build_vt_tables(mclasses)
+ end
+
+ fun build_vt_tables(mclasses: Set[MClass]): 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 = 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 MVirtualTypeProp then continue
+ var color = vt_colors[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 = vt_colors[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