protected override void Generate(Writer Write, IDLXML idl) { Write(@" #pragma once #include <mono/jit/jit.h> #include ""dom/Dom.h"" #include ""css/CSS.h"" #include ""engine/ContentWindow.h"" #include ""CanvasRenderingContext2D.h"" using namespace Dom; using namespace CSS; using namespace JS; using namespace WebCore; void addMonoInternalsForBindings(); "); foreach (var iface in idl.Interfaces) { Write(@" /*** class ${name} ***/ ".FormatWith(new { name = iface.Name })); foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { var argList = string.Join("", op.Args.Select(a => ", " + a.Type.AsCPPArg() + " arg" + a.Index)); Write(@" ${returnType} ${iName}_${oName}(void* domObject${args}); ".FormatWith(new { returnType = op.RetType.AsCPPRet(), iName = iface.Name, oName = op.Name, args = argList })); } foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { Write(@" ${returnType} ${iName}_${aName}Getter(void* domObject); ".FormatWith(new { returnType = attr.GetterType.AsCPPRet(), iName = iface.Name, aName = attr.Name })); if (!attr.IsReadOnly) { Write(@" void ${iName}_${aName}Setter(void* domObject, ${argType} value); ".FormatWith(new { iName = iface.Name, aName = attr.Name, argType = attr.SetterType.AsCPPArg() })); } } } }
protected override void Generate(Writer Write, IDLXML idl) { Write(@" #pragma once #include <mono/jit/jit.h> #include ""dom/Dom.h"" #include ""css/CSS.h"" #include ""engine/ContentWindow.h"" #include ""CanvasRenderingContext2D.h"" using namespace Dom; using namespace CSS; using namespace JS; using namespace WebCore; void addMonoInternalsForBindings(); "); foreach (var iface in idl.Interfaces) { Write(@" /*** class ${name} ***/ ".FormatWith(new { name = iface.Name })); foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { var argList = string.Join("", op.Args.Select(a => ", " + a.Type.AsCPPArg() + " arg" + a.Index)); Write(@" ${returnType} ${iName}_${oName}(void* domObject${args}); ".FormatWith(new { returnType = op.RetType.AsCPPRet(), iName = iface.Name, oName = op.Name, args = argList })); } foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { Write(@" ${returnType} ${iName}_${aName}Getter(void* domObject); ".FormatWith(new { returnType = attr.GetterType.AsCPPRet(), iName = iface.Name, aName = attr.Name })); if (!attr.IsReadOnly) Write(@" void ${iName}_${aName}Setter(void* domObject, ${argType} value); ".FormatWith(new { iName = iface.Name, aName = attr.Name, argType = attr.SetterType.AsCPPArg() })); } } }
protected override void Generate(Writer Write, IDLXML idl) { #if ENABLE_ZOOMM_MONO_EXTENSIONS // Only use .NET 4.5 MethodImplOptions on Mono platforms (UNIX / Mac OS X) for now. var os = (int)Environment.OSVersion.Platform; var methodImplOptions = "[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]" .If(os == 4 || os == 6 || os == 128); #else var methodImplOptions = ""; #endif Write(@" using System; using System.Runtime.CompilerServices; using mwr.Extensions; namespace mwr.DOM { "); foreach (var iface in (from i in idl.Interfaces where (i.IsPrivate && !i.IsRuntime) select i)) { Write(@" public partial class ${name} : IWrappedPrivateObject { private IntPtr _${name}Ptr; public ${name}(IntPtr p) { _${name}Ptr = p; } ${implOpts} public IntPtr AsDOMPtr() { return _${name}Ptr; } } ".FormatWith(new { name = iface.Name, implOpts = methodImplOptions, })); } Write(@" } "); }
protected override void Generate(Writer Write, IDLXML idl) { #if ENABLE_ZOOMM_MONO_EXTENSIONS // Only use .NET 4.5 MethodImplOptions on Mono platforms (UNIX / Mac OS X) for now. var os = (int) Environment.OSVersion.Platform; var methodImplOptions = "[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]" .If(os == 4 || os == 6 || os == 128); #else var methodImplOptions = ""; #endif Write(@" using System; using System.Runtime.CompilerServices; using mwr.Extensions; namespace mwr.DOM { "); foreach (var iface in (from i in idl.Interfaces where (i.IsPrivate && ! i.IsRuntime) select i)) Write(@" public partial class ${name} : IWrappedPrivateObject { private IntPtr _${name}Ptr; public ${name}(IntPtr p) { _${name}Ptr = p; } ${implOpts} public IntPtr AsDOMPtr() { return _${name}Ptr; } } ".FormatWith(new { name = iface.Name, implOpts = methodImplOptions, })); Write(@" } "); }
protected override void Generate(Writer Write, IDLXML idl) { #if ENABLE_ZOOMM_MONO_EXTENSIONS // Only use .NET 4.5 MethodImplOptions on Mono platforms (UNIX / Mac OS X) for now. var os = (int)Environment.OSVersion.Platform; var methodImplOptions = "[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]" .If(os == 4 || os == 6 || os == 128); #else var methodImplOptions = ""; #endif Write(@" using System; using System.Runtime.CompilerServices; using mwr.Extensions; // Disable warnings related to new and override. #pragma warning disable 108, 109, 114 namespace mwr.DOM { "); foreach (var iface in idl.Interfaces) { Write(@" public partial class ${Name} { public new partial class Bindings { ".FormatWith(iface)); foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { var argList = string.Join("", op.Args.Select(a => ", " + a.Type.AsCSInternalArg() + " arg" + a.Index)); var callArgList = string.Join("", op.Args.Select(a => ", " + "ref ".If(a.Type.ByRef) + "arg" + a.Index)); Write(@" ${implOpts} public static ${returnType} ${oName}(IntPtr domObject${args}) { ${retValDef} m.Util.Timers.Timer timer = null; try { if (HTMLRuntime.Instance != null) timer = HTMLRuntime.StartTimer(HTMLRuntime.Instance.Configuration.ProfileBindingTime, ""JS/Binding/${iName}.Internal.${oName}""); #if (ENABLE_HOOKS${forceDisableHooks}) #if ENABLE_RR if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.RecordEnabled) { ${retAssign}${iName}.Internal.${oName}(domObject${callArgs}); RecordReplayManager.Instance.Record(""${iName}"", ${retVal}, ""${oName}"", true, domObject${callArgs}); } else if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.ReplayEnabled) { ${retAssign}${retCast}RecordReplayManager.Instance.OutputBindingReplay(""${iName}"", ""${oName}"", domObject${callArgs}); } else { ${retAssign}${iName}.Internal.${oName}(domObject${callArgs}); } #endif #else ${retAssign}${iName}.Internal.${oName}(domObject${callArgs}); #endif } finally { if (HTMLRuntime.Instance != null) HTMLRuntime.StopTimer(timer); } ${retValReturn} } ".FormatWith(new { implOpts = methodImplOptions, returnType = op.RetType.AsCSRet(), oName = op.Name, args = argList, forceDisableHooks = " && HOOKS_DISABLED_FOR_THIS_OPERATION".If(op.DisableHooks), iName = iface.Name, callArgs = callArgList, retAssign = "retVal = ".If(!op.RetType.IsVoid), ret = "return ".If(!op.RetType.IsVoid), retValDef = (op.RetType.AsCSArg() + " retVal;").If(!op.RetType.IsVoid), retVal = (op.RetType.IsVoid) ? "null" : "retVal", retValReturn = "return retVal;".If(!op.RetType.IsVoid), retCast = ("(" + op.RetType.AsCSArg() + ")").If(!op.RetType.IsVoid), })); } foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { if (!attr.IsReadOnly) { Write(@" ${implOpts} public static void ${aName}Setter(IntPtr domObject, ${argType} arg) { m.Util.Timers.Timer timer = null; try { if (HTMLRuntime.Instance != null) timer = HTMLRuntime.StartTimer(HTMLRuntime.Instance.Configuration.ProfileBindingTime, ""JS/Binding/${iName}.Internal.${aName}Setter""); #if ENABLE_HOOKS #if ENABLE_RR if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.RecordEnabled) { ${iName}.Internal.${aName}Setter(domObject, arg); RecordReplayManager.Instance.Record(""${iName}"", null, ""${aName}Setter"", true, domObject, arg); } else if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.ReplayEnabled) { RecordReplayManager.Instance.OutputBindingReplay(""${iName}"", ""${aName}Setter"", domObject, arg); } else { ${iName}.Internal.${aName}Setter(domObject, arg); } #endif #else ${iName}.Internal.${aName}Setter(domObject, arg); #endif } finally { if (HTMLRuntime.Instance != null) HTMLRuntime.StopTimer(timer); } } ".FormatWith(new { implOpts = methodImplOptions, aName = attr.Name, argType = attr.SetterType.AsCSInternalArg(), iName = iface.Name })); } Write(@" ${implOpts} public static ${returnType} ${aName}Getter(IntPtr domObject) { ${retValDef} m.Util.Timers.Timer timer = null; try { if (HTMLRuntime.Instance != null) timer = HTMLRuntime.StartTimer(HTMLRuntime.Instance.Configuration.ProfileBindingTime, ""JS/Binding/${iName}.Internal.${aName}Getter""); #if ENABLE_HOOKS #if ENABLE_RR if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.RecordEnabled) { ${retAssign}${iName}.Internal.${aName}Getter(domObject); RecordReplayManager.Instance.Record(""${iName}"", ${retVal}, ""${aName}Getter"", true, domObject); } else if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.ReplayEnabled) { ${retAssign}${retCast}RecordReplayManager.Instance.OutputBindingReplay(""${iName}"", ""${aName}Getter"", domObject); } else { ${retAssign}${iName}.Internal.${aName}Getter(domObject); } #endif #else ${retAssign}${iName}.Internal.${aName}Getter(domObject); #endif } finally { if (HTMLRuntime.Instance != null) HTMLRuntime.StopTimer(timer); } ${retValReturn} } ".FormatWith(new { implOpts = methodImplOptions, returnType = attr.GetterType.AsCSRet(), aName = attr.Name, iName = iface.Name, retValDef = (attr.GetterType.AsCSArg() + " retVal;").If(!attr.GetterType.IsVoid), retAssign = "retVal = ".If(!attr.GetterType.IsVoid), retVal = (attr.GetterType.IsVoid) ? "null" : "retVal", retValReturn = "return retVal;".If(!attr.GetterType.IsVoid), retCast = ("(" + attr.GetterType.AsCSArg() + ")").If(!attr.GetterType.IsVoid), })); } Write(@" } } "); } Write(@" } "); }
protected override void Generate(Writer Write, IDLXML idl) { Write(@" using System; using System.Runtime.CompilerServices; using mwr.Extensions; namespace mwr.DOM { "); foreach (var iface in (from i in idl.Interfaces where !i.IsPrivate select i)) { Write(@" public partial class ${Name} : ${Superclass} { public ${Name}(IntPtr objPtr) : base(objPtr) { Initialize(); ".FormatWith(iface)); if (iface.IsList) {//Forcing ItemAccessor to be initialized if it is null to fix the ThreadStatic issue (TODO: A more elegant solution must be implement!) Write(@" if (ItemAccessor == null) { ItemAccessor = new mdr.PropertyDescriptor(null) { Getter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) => { value.Set(DOMBinder.CheckUndefined(Bindings.item(obj.AsDOMPtr(), (UInt32)pd.Index))); }, Setter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) => { m.Util.Diagnose.Trace.Fail(""Cannot assign to the WrappedObject.item's elements""); }, }; } "); } Write(@" } partial void Initialize(); public new partial class Internal : ${Superclass}.Internal {} public new partial class Bindings : ${Superclass}.Bindings {} ".FormatWith(iface)); if (iface.IsList) { Write(@" // A PropertyDescriptor for this list's items; for now shared as an optimization. [ThreadStatic] static mdr.PropertyDescriptor ItemAccessor = null; // Override the GetPropertyDescriptor methods since this is a list type; // this will allow expressions of the form obj[10] to work as expected. public override mdr.PropertyDescriptor GetPropertyDescriptor(int field) { ItemAccessor.Index = field; return ItemAccessor; } public override mdr.PropertyDescriptor GetPropertyDescriptor(double field) { var intField = (int)field; if (field == intField) return GetPropertyDescriptor(intField); else return base.GetPropertyDescriptor(field); } public override mdr.PropertyDescriptor GetPropertyDescriptor(string field) { int i; if (int.TryParse(field, out i)) return GetPropertyDescriptor(i); else { # if DEBUG var pd = Map.GetPropertyDescriptor(field); if (pd == null) m.Util.Diagnose.Debug.Warning("" #### The field {0} does not exist #### "", field); # endif return base.GetPropertyDescriptor(field); } } "); } Write(@" public static new void PreparePrototype(mdr.DObject prototype) { FillPrototype(prototype); CustomFillPrototype(prototype); } static partial void CustomFillPrototype(mdr.DObject prototype); private static void FillPrototype(mdr.DObject prototype) { mdr.Runtime.Instance.GetMapMetadataOfPrototype(prototype).Name = ""${Name}""; ".FormatWith(iface)); foreach (var overloads in (from o in iface.Operations where !o.IsPrivate group o by o.Name into overloads select overloads)) { Write(@" prototype.SetField(""${Name}"", new mdr.DFunction((ref mdr.CallFrame callFrame) => { switch (callFrame.PassedArgsCount) { default: ".FormatWith(overloads.First())); foreach (var op in (from o in overloads orderby o.Args.Count() descending select o)) { var retSetPre = op.RetType.IsVoid ? "" : op.RetType.IsNullable ? "callFrame.Return.SetNullable(" : "callFrame.Return.Set("; var retSetPost = ")".If(retSetPre != ""); var argumentList = string.Join("", op.Args.Select(a => ", arg" + a.Index)); Write(@" case ${argsCount}: { /* ${idl} */ m.Util.Diagnose.Debug.WriteLine(""++$> calling ${iName}:${oName}(this${argList})""); callFrame.SetExpectedArgsCount(${argsCount}); ".FormatWith(new { argsCount = op.Args.Count(), idl = op.WebIDL, iName = iface.Name, oName = op.Name, argList = argumentList })); if (op.IsRuntime) { Write(@" ${Name}(ref callFrame); ".FormatWith(op)); } else { foreach (var arg in op.Args) { if (arg.Type.AsJSArg().ToString() != "DOMPtr") { Write(@" var arg${idx} = mjr.Operations.Convert.To${argType}.Run(ref ${callFrameArg}); ".FormatWith(new { idx = arg.Index, callFrameArg = CallFrameArg(arg.Index), argType = arg.Type.AsJSArg() })); } else { Write(@" var arg${idx} = ${callFrameArg}.As${argType}(); ".FormatWith(new { idx = arg.Index, callFrameArg = CallFrameArg(arg.Index), argType = arg.Type.AsJSArg() })); } } Write(@" ${retSetPre}Bindings.${oName}(callFrame.This.AsDOMPtr()${argList})${retSetPost}; ".FormatWith(new { retSetPre = retSetPre, oName = op.Name, argList = argumentList, retSetPost = retSetPost })); } Write(@" break; } "); } Write(@" } })); "); } foreach (var attr in iface.Attributes) { if (attr.IsEventHandler) { Write(@" /* ${WebIDL} */ prototype.DefineOwnProperty(""${Name}"", EventHandlerProperty.CreateProperty(""${Name}"")); ".FormatWith(attr)); } else { Write(@" /* ${idl} */ prototype.DefineOwnProperty(""${aName}"", new mdr.DProperty() { TargetValueType = mdr.ValueTypes.${aType}, ".FormatWith(new { idl = attr.WebIDL, aName = attr.Name, aType = attr.GetterType.AsJSDynamic() })); if (!attr.IsReadOnly) { if (attr.SetterType.AsJSArg().ToString() != "DOMPtr") { Write(@" OnSetDValue = (mdr.DObject This, ref mdr.DValue v) => { var arg = mjr.Operations.Convert.To${aType}.Run(ref v); Bindings.${aName}Setter(This.AsDOMPtr(), arg); }, ".FormatWith(new { aType = attr.SetterType.AsJSArg(), aName = attr.Name })); } else { Write(@" OnSetDValue = (mdr.DObject This, ref mdr.DValue v) => { var arg = v.As${aType}(); Bindings.${aName}Setter(This.AsDOMPtr(), arg); }, ".FormatWith(new { aType = attr.SetterType.AsJSArg(), aName = attr.Name })); } } Write(@" OnGetDValue = (mdr.DObject This, ref mdr.DValue v) => { v.Set${nullable}(Bindings.${aName}Getter(This.AsDOMPtr())); }, }${jsProperties}); ".FormatWith(new { aName = attr.Name, nullable = "Nullable".If(attr.GetterType.IsNullable), jsProperties = ", mdr.PropertyDescriptor.Attributes.NotWritable".If(attr.IsReadOnly), })); } } foreach (var constant in iface.Constants) { Write(@" /* ${WebIDL} */ prototype.SetField(""${Name}"", ${Value}); ".FormatWith(constant)); } Write(@" } }; // end of ${Name} ".FormatWith(iface)); } Write(@" } "); }
protected override void Generate(Writer Write, IDLXML idl) { #if ENABLE_ZOOMM_MONO_EXTENSIONS // Only use .NET 4.5 MethodImplOptions on Mono platforms (UNIX / Mac OS X) for now. var os = (int) Environment.OSVersion.Platform; var methodImplOptions = "[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]" .If(os == 4 || os == 6 || os == 128); #else var methodImplOptions = ""; #endif Write(@" using System; using System.Runtime.CompilerServices; using mwr.Extensions; // Disable warnings related to new and override. #pragma warning disable 108, 109, 114 namespace mwr.DOM { "); foreach (var iface in idl.Interfaces) { Write(@" public partial class ${Name} { public new partial class Bindings { ".FormatWith(iface)); foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { var argList = string.Join("", op.Args.Select(a => ", " + a.Type.AsCSInternalArg() + " arg" + a.Index)); var callArgList = string.Join("", op.Args.Select(a => ", " + "ref ".If(a.Type.ByRef) + "arg" + a.Index)); Write(@" ${implOpts} public static ${returnType} ${oName}(IntPtr domObject${args}) { ${retValDef} m.Util.Timers.Timer timer = null; try { if (HTMLRuntime.Instance != null) timer = HTMLRuntime.StartTimer(HTMLRuntime.Instance.Configuration.ProfileBindingTime, ""JS/Binding/${iName}.Internal.${oName}""); #if (ENABLE_HOOKS${forceDisableHooks}) #if ENABLE_RR if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.RecordEnabled) { ${retAssign}${iName}.Internal.${oName}(domObject${callArgs}); RecordReplayManager.Instance.Record(""${iName}"", ${retVal}, ""${oName}"", true, domObject${callArgs}); } else if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.ReplayEnabled) { ${retAssign}${retCast}RecordReplayManager.Instance.OutputBindingReplay(""${iName}"", ""${oName}"", domObject${callArgs}); } else { ${retAssign}${iName}.Internal.${oName}(domObject${callArgs}); } #endif #else ${retAssign}${iName}.Internal.${oName}(domObject${callArgs}); #endif } finally { if (HTMLRuntime.Instance != null) HTMLRuntime.StopTimer(timer); } ${retValReturn} } ".FormatWith(new { implOpts = methodImplOptions, returnType = op.RetType.AsCSRet(), oName = op.Name, args = argList, forceDisableHooks = " && HOOKS_DISABLED_FOR_THIS_OPERATION".If(op.DisableHooks), iName = iface.Name, callArgs = callArgList, retAssign = "retVal = ".If(!op.RetType.IsVoid), ret = "return ".If(!op.RetType.IsVoid), retValDef = (op.RetType.AsCSArg() + " retVal;").If(!op.RetType.IsVoid), retVal = (op.RetType.IsVoid) ? "null" : "retVal", retValReturn = "return retVal;".If(!op.RetType.IsVoid), retCast = ("(" + op.RetType.AsCSArg() + ")").If(!op.RetType.IsVoid), })); } foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { if (!attr.IsReadOnly) Write(@" ${implOpts} public static void ${aName}Setter(IntPtr domObject, ${argType} arg) { m.Util.Timers.Timer timer = null; try { if (HTMLRuntime.Instance != null) timer = HTMLRuntime.StartTimer(HTMLRuntime.Instance.Configuration.ProfileBindingTime, ""JS/Binding/${iName}.Internal.${aName}Setter""); #if ENABLE_HOOKS #if ENABLE_RR if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.RecordEnabled) { ${iName}.Internal.${aName}Setter(domObject, arg); RecordReplayManager.Instance.Record(""${iName}"", null, ""${aName}Setter"", true, domObject, arg); } else if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.ReplayEnabled) { RecordReplayManager.Instance.OutputBindingReplay(""${iName}"", ""${aName}Setter"", domObject, arg); } else { ${iName}.Internal.${aName}Setter(domObject, arg); } #endif #else ${iName}.Internal.${aName}Setter(domObject, arg); #endif } finally { if (HTMLRuntime.Instance != null) HTMLRuntime.StopTimer(timer); } } ".FormatWith(new { implOpts = methodImplOptions, aName = attr.Name, argType = attr.SetterType.AsCSInternalArg(), iName = iface.Name })); Write(@" ${implOpts} public static ${returnType} ${aName}Getter(IntPtr domObject) { ${retValDef} m.Util.Timers.Timer timer = null; try { if (HTMLRuntime.Instance != null) timer = HTMLRuntime.StartTimer(HTMLRuntime.Instance.Configuration.ProfileBindingTime, ""JS/Binding/${iName}.Internal.${aName}Getter""); #if ENABLE_HOOKS #if ENABLE_RR if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.RecordEnabled) { ${retAssign}${iName}.Internal.${aName}Getter(domObject); RecordReplayManager.Instance.Record(""${iName}"", ${retVal}, ""${aName}Getter"", true, domObject); } else if (mwr.RecordReplayManager.Instance != null && mwr.RecordReplayManager.Instance.ReplayEnabled) { ${retAssign}${retCast}RecordReplayManager.Instance.OutputBindingReplay(""${iName}"", ""${aName}Getter"", domObject); } else { ${retAssign}${iName}.Internal.${aName}Getter(domObject); } #endif #else ${retAssign}${iName}.Internal.${aName}Getter(domObject); #endif } finally { if (HTMLRuntime.Instance != null) HTMLRuntime.StopTimer(timer); } ${retValReturn} } ".FormatWith(new { implOpts = methodImplOptions, returnType = attr.GetterType.AsCSRet(), aName = attr.Name, iName = iface.Name, retValDef = (attr.GetterType.AsCSArg() + " retVal;").If(!attr.GetterType.IsVoid), retAssign = "retVal = ".If(!attr.GetterType.IsVoid), retVal = (attr.GetterType.IsVoid) ? "null" : "retVal", retValReturn = "return retVal;".If(!attr.GetterType.IsVoid), retCast = ("(" + attr.GetterType.AsCSArg() + ")").If(!attr.GetterType.IsVoid), })); } Write(@" } } "); } Write(@" } "); }
protected override void Generate(Writer Write, IDLXML idl) { #if ENABLE_ZOOMM_MONO_EXTENSIONS // Only use .NET 4.5 MethodImplOptions on Mono platforms (UNIX / Mac OS X) for now. var os = (int)Environment.OSVersion.Platform; var methodImplOptions = "[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]" .If(os == 4 || os == 6 || os == 128); #else var methodImplOptions = ""; #endif Write(@" using System; using System.Runtime.CompilerServices; using mwr.Extensions; // Disable warnings related to new and override. #pragma warning disable 108, 109, 114 namespace mwr.DOM { "); foreach (var iface in idl.Interfaces) { Write(@" public partial class ${Name} { ".FormatWith(iface)); // Turn operations into methods. foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { var argList = string.Join(", ", op.Args.Select(a => a.Type.AsCSArg() + " arg" + a.Index)); var callArgList = string.Join("", op.Args.Select(a => ", " + "ref ".If(a.Type.ByRef) + "arg" + a.Index + ".AsDOMPtr()".If(a.Type.IsObject && !a.Type.ByRef))); Write(@" ${implOpts} public ${returnType} ${name}(${args}) { ${ret}${iName}.Bindings.${oName}(this.AsDOMPtr()${callArgs}); } ".FormatWith(new { implOpts = methodImplOptions, returnType = op.RetType.AsCSRet(), name = op.CapitalizedName, args = argList, ret = "return ".If(!op.RetType.IsVoid), iName = iface.Name, oName = op.Name, callArgs = callArgList, })); } // Turn attributes into properties. In the case where getterType != setterType, // we generate a method for the setter. foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { Write(@" public ${type} ${name} { ${implOpts} get { return ${iName}.Bindings.${aName}Getter(this.AsDOMPtr()); } ".FormatWith(new { implOpts = methodImplOptions, name = attr.CapitalizedName, type = attr.GetterType.AsCSRet(), iName = iface.Name, aName = attr.Name, })); if (!attr.IsReadOnly && attr.GetterType == attr.SetterType) { Write(@" ${implOpts} set { ${iName}.Bindings.${aName}Setter(this.AsDOMPtr(), value${toCPP}); } ".FormatWith(new { implOpts = methodImplOptions, iName = iface.Name, aName = attr.Name, toCPP = ".AsDOMPtr()".If(attr.SetterType.IsObject), })); } Write(@" } "); // Generate a setter method if the set type and get type are different. if (!attr.IsReadOnly && attr.GetterType != attr.SetterType) { Write(@" ${implOpts} void Set${aName}(${type} value) { ${iName}.Bindings.${aName}Setter(this.AsDOMPtr(), value${toCPP}); } ".FormatWith(new { implOpts = methodImplOptions, aName = attr.Name, type = attr.SetterType.AsCSRet(), iName = iface.Name, toCPP = ".AsDOMPtr()".If(attr.SetterType.IsObject), })); } } // Turn constants into read-only properties. foreach (var constant in iface.Constants) { Write(@" public ${type} ${name} { ${implOpts} get { return ${value}; } } ".FormatWith(new { implOpts = methodImplOptions, type = constant.Type.AsCSRet(), name = constant.CapitalizedName, value = constant.Value, })); } Write(@" } "); } Write(@" } "); }
protected abstract void Generate(Writer Write, IDLXML idl);
protected override void Generate(Writer Write, IDLXML idl) { Write(@" using System; using System.Runtime.CompilerServices; using mwr.Extensions; namespace mwr.DOM { "); foreach (var iface in (from i in idl.Interfaces where !i.IsPrivate select i)) { Write(@" public partial class ${Name} : ${Superclass} { public ${Name}(IntPtr objPtr) : base(objPtr) { Initialize(); ".FormatWith(iface)); if (iface.IsList) {//Forcing ItemAccessor to be initialized if it is null to fix the ThreadStatic issue (TODO: A more elegant solution must be implement!) Write(@" if (ItemAccessor == null) { ItemAccessor = new mdr.PropertyDescriptor(null) { Getter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) => { value.Set(DOMBinder.CheckUndefined(Bindings.item(obj.AsDOMPtr(), (UInt32)pd.Index))); }, Setter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) => { m.Util.Diagnose.Trace.Fail(""Cannot assign to the WrappedObject.item's elements""); }, }; } "); } Write(@" } partial void Initialize(); public new partial class Internal : ${Superclass}.Internal {} public new partial class Bindings : ${Superclass}.Bindings {} ".FormatWith(iface)); if (iface.IsList) { Write(@" // A PropertyDescriptor for this list's items; for now shared as an optimization. [ThreadStatic] static mdr.PropertyDescriptor ItemAccessor = null; // Override the GetPropertyDescriptor methods since this is a list type; // this will allow expressions of the form obj[10] to work as expected. public override mdr.PropertyDescriptor GetPropertyDescriptor(int field) { ItemAccessor.Index = field; return ItemAccessor; } public override mdr.PropertyDescriptor GetPropertyDescriptor(double field) { var intField = (int)field; if (field == intField) return GetPropertyDescriptor(intField); else return base.GetPropertyDescriptor(field); } public override mdr.PropertyDescriptor GetPropertyDescriptor(string field) { int i; if (int.TryParse(field, out i)) return GetPropertyDescriptor(i); else { # if DEBUG var pd = Map.GetPropertyDescriptor(field); if (pd == null) m.Util.Diagnose.Debug.Warning("" #### The field {0} does not exist #### "", field); # endif return base.GetPropertyDescriptor(field); } } "); } Write(@" public static new void PreparePrototype(mdr.DObject prototype) { FillPrototype(prototype); CustomFillPrototype(prototype); } static partial void CustomFillPrototype(mdr.DObject prototype); private static void FillPrototype(mdr.DObject prototype) { mdr.Runtime.Instance.GetMapMetadataOfPrototype(prototype).Name = ""${Name}""; ".FormatWith(iface)); foreach (var overloads in (from o in iface.Operations where !o.IsPrivate group o by o.Name into overloads select overloads)) { Write(@" prototype.SetField(""${Name}"", new mdr.DFunction((ref mdr.CallFrame callFrame) => { switch (callFrame.PassedArgsCount) { default: ".FormatWith(overloads.First())); foreach (var op in (from o in overloads orderby o.Args.Count() descending select o)) { var retSetPre = op.RetType.IsVoid ? "" : op.RetType.IsNullable ? "callFrame.Return.SetNullable(" : "callFrame.Return.Set("; var retSetPost = ")".If(retSetPre != ""); var argumentList = string.Join("", op.Args.Select(a => ", arg" + a.Index)); Write(@" case ${argsCount}: { /* ${idl} */ m.Util.Diagnose.Debug.WriteLine(""++$> calling ${iName}:${oName}(this${argList})""); callFrame.SetExpectedArgsCount(${argsCount}); ".FormatWith(new { argsCount = op.Args.Count(), idl = op.WebIDL, iName = iface.Name, oName = op.Name, argList = argumentList })); if (op.IsRuntime) Write(@" ${Name}(ref callFrame); ".FormatWith(op)); else { foreach (var arg in op.Args) if (arg.Type.AsJSArg().ToString() != "DOMPtr") { Write(@" var arg${idx} = mjr.Operations.Convert.To${argType}.Run(ref ${callFrameArg}); ".FormatWith(new { idx = arg.Index, callFrameArg = CallFrameArg(arg.Index), argType = arg.Type.AsJSArg() })); } else { Write(@" var arg${idx} = ${callFrameArg}.As${argType}(); ".FormatWith(new { idx = arg.Index, callFrameArg = CallFrameArg(arg.Index), argType = arg.Type.AsJSArg() })); } Write(@" ${retSetPre}Bindings.${oName}(callFrame.This.AsDOMPtr()${argList})${retSetPost}; ".FormatWith(new { retSetPre = retSetPre, oName = op.Name, argList = argumentList, retSetPost = retSetPost })); } Write(@" break; } "); } Write(@" } })); "); } foreach (var attr in iface.Attributes) { if (attr.IsEventHandler) Write(@" /* ${WebIDL} */ prototype.DefineOwnProperty(""${Name}"", EventHandlerProperty.CreateProperty(""${Name}"")); ".FormatWith(attr)); else { Write(@" /* ${idl} */ prototype.DefineOwnProperty(""${aName}"", new mdr.DProperty() { TargetValueType = mdr.ValueTypes.${aType}, ".FormatWith(new { idl = attr.WebIDL, aName = attr.Name, aType = attr.GetterType.AsJSDynamic() })); if (!attr.IsReadOnly) { if (attr.SetterType.AsJSArg().ToString() != "DOMPtr") { Write(@" OnSetDValue = (mdr.DObject This, ref mdr.DValue v) => { var arg = mjr.Operations.Convert.To${aType}.Run(ref v); Bindings.${aName}Setter(This.AsDOMPtr(), arg); }, ".FormatWith(new { aType = attr.SetterType.AsJSArg(), aName = attr.Name })); } else { Write(@" OnSetDValue = (mdr.DObject This, ref mdr.DValue v) => { var arg = v.As${aType}(); Bindings.${aName}Setter(This.AsDOMPtr(), arg); }, ".FormatWith(new { aType = attr.SetterType.AsJSArg(), aName = attr.Name })); } } Write(@" OnGetDValue = (mdr.DObject This, ref mdr.DValue v) => { v.Set${nullable}(Bindings.${aName}Getter(This.AsDOMPtr())); }, }${jsProperties}); ".FormatWith(new { aName = attr.Name, nullable = "Nullable".If(attr.GetterType.IsNullable), jsProperties = ", mdr.PropertyDescriptor.Attributes.NotWritable".If(attr.IsReadOnly) , })); } } foreach (var constant in iface.Constants) Write(@" /* ${WebIDL} */ prototype.SetField(""${Name}"", ${Value}); ".FormatWith(constant)); Write(@" } }; // end of ${Name} ".FormatWith(iface)); } Write(@" } "); }
protected override void Generate(Writer Write, IDLXML idl) { Write(@" using System; using System.Runtime.CompilerServices; using mwr.Extensions; // Disable warnings related to new and override. #pragma warning disable 108, 109, 114 namespace mwr.DOM { "); foreach (var iface in idl.Interfaces) { Write(@" public partial class ${Name} { public new partial class Internal { ".FormatWith(iface)); foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { var argList = string.Join("", op.Args.Select(a => ", " + a.Type.AsCSInternalArg() + " arg" + a.Index)); Write(@" [MethodImplAttribute(MethodImplOptions.InternalCall)] extern public static ${returnType} ${name}(IntPtr domObject${args}); ".FormatWith(new { returnType = op.RetType.AsCSRet(), name = op.Name, args = argList })); } foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { if (!attr.IsReadOnly) Write(@" [MethodImplAttribute(MethodImplOptions.InternalCall)] extern public static void ${name}Setter(IntPtr domObject, ${argType} arg); ".FormatWith(new { name = attr.Name, argType = attr.SetterType.AsCSInternalArg() })); Write(@" [MethodImplAttribute(MethodImplOptions.InternalCall)] extern public static ${returnType} ${name}Getter(IntPtr domObject); ".FormatWith(new { returnType = attr.GetterType.AsCSRet(), name = attr.Name })); } Write(@" } } "); } Write(@" } "); }
protected override void Generate(Writer Write, IDLXML idl) { Write(@" using System; using System.Runtime.CompilerServices; using mwr.Extensions; // Disable warnings related to new and override. #pragma warning disable 108, 109, 114 namespace mwr.DOM { "); foreach (var iface in idl.Interfaces) { Write(@" public partial class ${Name} { public new partial class Internal { ".FormatWith(iface)); foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { var argList = string.Join("", op.Args.Select(a => ", " + a.Type.AsCSInternalArg() + " arg" + a.Index)); Write(@" [MethodImplAttribute(MethodImplOptions.InternalCall)] extern public static ${returnType} ${name}(IntPtr domObject${args}); ".FormatWith(new { returnType = op.RetType.AsCSRet(), name = op.Name, args = argList })); } foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { if (!attr.IsReadOnly) { Write(@" [MethodImplAttribute(MethodImplOptions.InternalCall)] extern public static void ${name}Setter(IntPtr domObject, ${argType} arg); ".FormatWith(new { name = attr.Name, argType = attr.SetterType.AsCSInternalArg() })); } Write(@" [MethodImplAttribute(MethodImplOptions.InternalCall)] extern public static ${returnType} ${name}Getter(IntPtr domObject); ".FormatWith(new { returnType = attr.GetterType.AsCSRet(), name = attr.Name })); } Write(@" } } "); } Write(@" } "); }
protected override void Generate(Writer Write, IDLXML idl) { Write(@" #include <mono/metadata/exception.h> #include ""javascript/WrappedException.h"" #include ""AutoDOMBind.h"" void addMonoInternalsForBindings() { "); foreach (var iface in idl.Interfaces) { foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { // Create argument list for C# internal call. var argList = op.Args.Select(a => a.Type.AsMonoArg().ToString()); var csArgList = string.Join(",", (new[] { "intptr" }).Concat(argList)); // Create argument list for C trampoline function. argList = op.Args.Select(a => a.Type.AsCPPArg().ToString()); var cArgList = string.Join(", ", (new[] { "void*" }).Concat(argList)); Write(@" { ${returnType} (*fn)(${cArgs}) = &${iName}_${oName}; mono_add_internal_call(""mwr.DOM.${iName}/Internal::${oName}(${csArgs})"", (const void*)fn); } ".FormatWith(new { returnType = op.RetType.AsCPPRet(), cArgs = cArgList, csArgs = csArgList, iName = iface.Name, oName = op.Name })); } foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { Write(@" mono_add_internal_call(""mwr.DOM.${iName}/Internal::${aName}Getter"", (const void*)${iName}_${aName}Getter); ".FormatWith(new { iName = iface.Name, aName = attr.Name })); if (!attr.IsReadOnly) Write(@" mono_add_internal_call(""mwr.DOM.${iName}/Internal::${aName}Setter"", (const void*)${iName}_${aName}Setter); ".FormatWith(new { iName = iface.Name, aName = attr.Name })); } } Write(@" } "); foreach (var iface in idl.Interfaces) { foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { var retConverter = op.RetType.IsObject ? "convertToCSObject" : op.RetType.IsString ? "convertToCSString" : ""; // Create argument list for C trampoline function. var argList = op.Args.Select(a => a.Type.AsCPPArg() + " arg" + a.Index); var cArgList = string.Join(", ", (new[] { "void* domObject" }).Concat(argList)); // Create argument list for C++ method invocation. argList = op.Args.Select(a => "(DOMString*)".If(a.Type.IsString) + "arg" + a.Index); var cppArgList = string.Join(", ", argList); Write(@" ${retType} ${iName}_${oName}(${cArgs}) { ScopedTimer timer(""Binding.${iName}.${oName}""); ".FormatWith(new { retType = op.RetType.AsCPPRet(), iName = iface.Name, oName = op.Name, cArgs = cArgList })); if (op.IsUnsafe) Write(@" auto targetObject = static_cast<${Name}*>(domObject); ".FormatWith(iface)); else Write(@" auto wrappedObject = static_cast<WrappedObject*>(domObject); auto targetObject = static_cast<${Name}*>(wrappedObject); AssertPointer(targetObject); ZDASSERT(targetObject == dynamic_cast<${Name}*>(wrappedObject), ""Dynamic and static cast do not return the same value - this is probably caused by multiple inheritance, which we do not allow""); ".FormatWith(iface)); Write(@" try { return ${retConverter}(targetObject->${oName}(${cppArgs})); } catch (const WrappedException* err) { ZDLOG(""Caught C++-level exception; rethrowing at the C# layer...""); mono_raise_exception(convertToCSException(err)); return ${defaultReturn}; // Avoid compiler warning about missing return; this line will never be executed. } } ".FormatWith(new { retConverter = retConverter, oName = op.Name, cppArgs = cppArgList, defaultReturn = "0".If(!op.RetType.IsVoid) })); } foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { var getConverter = attr.GetterType.IsObject ? "convertToCSObject" : attr.GetterType.IsString ? "convertToCSString" : ""; var setConverter = "(DOMString*)".If(attr.SetterType.IsString); Write(@" ${retType} ${iName}_${aName}Getter(void* domObject) { ScopedTimer timer(""Binding.${iName}.${aName}Getter""); auto wrappedObject = static_cast<WrappedObject*>(domObject); auto targetObject = static_cast<${iName}*>(wrappedObject); AssertPointer(targetObject); ZDASSERT(targetObject == dynamic_cast<${iName}*>(wrappedObject), ""Dynamic and static cast do not return the same value - this is probably caused by multiple inheritance, which we do not allow""); try { return ${getConverter}(targetObject->${aName}()); } catch (const WrappedException* err) { ZDLOG(""Caught C++-level exception; rethrowing at the C# layer...""); mono_raise_exception(convertToCSException(err)); return 0; // Avoid compiler warning about missing return; this line will never be executed. } } ".FormatWith(new { retType = attr.GetterType.AsCPPRet(), iName = iface.Name, aName = attr.Name, getConverter = getConverter })); if (!attr.IsReadOnly) Write(@" void ${iName}_${aName}Setter(void* domObject, ${argType} value) { ScopedTimer timer(""Binding.${iName}.${aName}Setter""); auto wrappedObject = static_cast<WrappedObject*>(domObject); auto targetObject = static_cast<${iName}*>(wrappedObject); AssertPointer(targetObject); ZDASSERT(targetObject == dynamic_cast<${iName}*>(wrappedObject), ""Dynamic and static cast do not return the same value - this is probably caused by multiple inheritance, which we do not allow""); try { targetObject->${setter}(${setConverter}value); } catch (const WrappedException* err) { ZDLOG(""Caught C++-level exception; rethrowing at the C# layer...""); mono_raise_exception(convertToCSException(err)); } } ".FormatWith(new { iName = iface.Name, aName = attr.Name, argType = attr.SetterType.AsCPPArg(), setter = "set" + attr.CapitalizedName, setConverter = setConverter })); } } }
protected override void Generate(Writer Write, IDLXML idl) { Write(@" #include <mono/metadata/exception.h> #include ""javascript/WrappedException.h"" #include ""AutoDOMBind.h"" void addMonoInternalsForBindings() { "); foreach (var iface in idl.Interfaces) { foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { // Create argument list for C# internal call. var argList = op.Args.Select(a => a.Type.AsMonoArg().ToString()); var csArgList = string.Join(",", (new[] { "intptr" }).Concat(argList)); // Create argument list for C trampoline function. argList = op.Args.Select(a => a.Type.AsCPPArg().ToString()); var cArgList = string.Join(", ", (new[] { "void*" }).Concat(argList)); Write(@" { ${returnType} (*fn)(${cArgs}) = &${iName}_${oName}; mono_add_internal_call(""mwr.DOM.${iName}/Internal::${oName}(${csArgs})"", (const void*)fn); } ".FormatWith(new { returnType = op.RetType.AsCPPRet(), cArgs = cArgList, csArgs = csArgList, iName = iface.Name, oName = op.Name })); } foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { Write(@" mono_add_internal_call(""mwr.DOM.${iName}/Internal::${aName}Getter"", (const void*)${iName}_${aName}Getter); ".FormatWith(new { iName = iface.Name, aName = attr.Name })); if (!attr.IsReadOnly) { Write(@" mono_add_internal_call(""mwr.DOM.${iName}/Internal::${aName}Setter"", (const void*)${iName}_${aName}Setter); ".FormatWith(new { iName = iface.Name, aName = attr.Name })); } } } Write(@" } "); foreach (var iface in idl.Interfaces) { foreach (var op in (from o in iface.Operations where !o.IsRuntime select o)) { var retConverter = op.RetType.IsObject ? "convertToCSObject" : op.RetType.IsString ? "convertToCSString" : ""; // Create argument list for C trampoline function. var argList = op.Args.Select(a => a.Type.AsCPPArg() + " arg" + a.Index); var cArgList = string.Join(", ", (new[] { "void* domObject" }).Concat(argList)); // Create argument list for C++ method invocation. argList = op.Args.Select(a => "(DOMString*)".If(a.Type.IsString) + "arg" + a.Index); var cppArgList = string.Join(", ", argList); Write(@" ${retType} ${iName}_${oName}(${cArgs}) { ScopedTimer timer(""Binding.${iName}.${oName}""); ".FormatWith(new { retType = op.RetType.AsCPPRet(), iName = iface.Name, oName = op.Name, cArgs = cArgList })); if (op.IsUnsafe) { Write(@" auto targetObject = static_cast<${Name}*>(domObject); ".FormatWith(iface)); } else { Write(@" auto wrappedObject = static_cast<WrappedObject*>(domObject); auto targetObject = static_cast<${Name}*>(wrappedObject); AssertPointer(targetObject); ZDASSERT(targetObject == dynamic_cast<${Name}*>(wrappedObject), ""Dynamic and static cast do not return the same value - this is probably caused by multiple inheritance, which we do not allow""); ".FormatWith(iface)); } Write(@" try { return ${retConverter}(targetObject->${oName}(${cppArgs})); } catch (const WrappedException* err) { ZDLOG(""Caught C++-level exception; rethrowing at the C# layer...""); mono_raise_exception(convertToCSException(err)); return ${defaultReturn}; // Avoid compiler warning about missing return; this line will never be executed. } } ".FormatWith(new { retConverter = retConverter, oName = op.Name, cppArgs = cppArgList, defaultReturn = "0".If(!op.RetType.IsVoid) })); } foreach (var attr in (from a in iface.Attributes where !a.IsEventHandler select a)) { var getConverter = attr.GetterType.IsObject ? "convertToCSObject" : attr.GetterType.IsString ? "convertToCSString" : ""; var setConverter = "(DOMString*)".If(attr.SetterType.IsString); Write(@" ${retType} ${iName}_${aName}Getter(void* domObject) { ScopedTimer timer(""Binding.${iName}.${aName}Getter""); auto wrappedObject = static_cast<WrappedObject*>(domObject); auto targetObject = static_cast<${iName}*>(wrappedObject); AssertPointer(targetObject); ZDASSERT(targetObject == dynamic_cast<${iName}*>(wrappedObject), ""Dynamic and static cast do not return the same value - this is probably caused by multiple inheritance, which we do not allow""); try { return ${getConverter}(targetObject->${aName}()); } catch (const WrappedException* err) { ZDLOG(""Caught C++-level exception; rethrowing at the C# layer...""); mono_raise_exception(convertToCSException(err)); return 0; // Avoid compiler warning about missing return; this line will never be executed. } } ".FormatWith(new { retType = attr.GetterType.AsCPPRet(), iName = iface.Name, aName = attr.Name, getConverter = getConverter })); if (!attr.IsReadOnly) { Write(@" void ${iName}_${aName}Setter(void* domObject, ${argType} value) { ScopedTimer timer(""Binding.${iName}.${aName}Setter""); auto wrappedObject = static_cast<WrappedObject*>(domObject); auto targetObject = static_cast<${iName}*>(wrappedObject); AssertPointer(targetObject); ZDASSERT(targetObject == dynamic_cast<${iName}*>(wrappedObject), ""Dynamic and static cast do not return the same value - this is probably caused by multiple inheritance, which we do not allow""); try { targetObject->${setter}(${setConverter}value); } catch (const WrappedException* err) { ZDLOG(""Caught C++-level exception; rethrowing at the C# layer...""); mono_raise_exception(convertToCSException(err)); } } ".FormatWith(new { iName = iface.Name, aName = attr.Name, argType = attr.SetterType.AsCPPArg(), setter = "set" + attr.CapitalizedName, setConverter = setConverter })); } } } }