using compiler class FooInheritor : DslPlugin { new make(Compiler compiler) : super(compiler) {} override Expr compile(DslExpr expr) { loc := expr.loc type := createInheritor("Foo" + Duration.nowTicks, expr.src) return CallExpr.makeWithMethod(loc, StaticTargetExpr.make(loc, type), type.method("make")) } private static const Str synthMethod := "synth" private CType fooType() { ns.resolveType("dslHack::Foo") } private CMethod fooMethod() { fooType.method("str") } private TypeDef createInheritor(Str name, Str str) { loc := Loc.makeUninit result := TypeDef.make(ns, loc, syntheticsUnit, name) result.flags = FConst.Synthetic + FConst.Public result.base = fooType result.baseSpecified = true //create completely new slot which returns given str method := MethodDef.make(loc, result, synthMethod, FConst.Protected) method.ret = ns.resolveType("sys::Str") method.code = Block.make(loc) method.code.stmts.add(ReturnStmt.make(loc, LiteralExpr.makeStr(loc, ns, str))) //create method overriding over := MethodDef.make(loc, result, fooMethod.name, FConst.Override + FConst.Public) over.ret = fooMethod.returnType over.code = Block.make(loc) over.code.stmts.add(ReturnStmt.make(loc, CallExpr.makeWithMethod(loc, ThisExpr.make(loc), method))) //create constructor make := MethodDef.make(loc, result, "make", FConst.Ctor + FConst.Synthetic) make.ret = ns.resolveType("sys::Void") make.code = Block.make(loc) make.code.add(ReturnStmt.makeSynthetic(loc)) result.addSlot(method) result.addSlot(over) result.addSlot(make) syntheticsUnit.types.add(result) compiler.types.add(result) return result } }