public void WrapperConstructorImplementation(AST.Constructor c, AST.Object owner) { Line($"{TypeRef(owner)} {owner.Namespace.FullName("::")}::Create{owner.Name}({DeclParameters(c.Parameters)})"); Block(() => { Line($"{TypeRef(owner, true)}* instance;"); CallToABIMethodBody(c.Rename(c.GetABIConstructorName(owner))); Line($"return ::ABI::Wrap<{TypeRef(owner)}>(instance);"); }); }
public void ConstructorImplementation(AST.Constructor c, AST.Object owner, Action implementation = null, IEnumerable <string> initializers = null) { if (Strata == ApiStrata.Normal) { Code("{0}::{1}({2})", TypeRef(owner), owner.Name, DeclParameters(c.Parameters)); if (owner.BaseType != null && owner.BaseType.Constructors.Count != 0 && owner.BaseType.Constructors[0].Parameters.Count != 0) { Code(" : "); List(() => { if (Settings.Mode == CppMode.PimplWrapper) { Line($"{owner.BaseType.Name}(nullptr)"); } else { Code("Base("); List(() => { var bc = owner.BaseType.Constructors[0]; foreach (var bcarg in bc.Parameters) { ListItem("DEFAULT_({0})", TypeRef(bcarg)); } }); Line(")"); NextListItem(); if (initializers != null) { foreach (var str in initializers) { ListItem(str); } } } }); } else { Line(); } if (implementation == null) { Block(() => Line("Not_Implemented_Warning")); } else { Block(() => implementation()); } } else { Line($"ABI_CONSTRUCTOR {c.GetABIConstructorName(owner)}({DeclParameters(c.GetABIParametersCpp(), $"{TypeRef(owner, true)}** outInstance")})"); Block(() => { if (implementation != null) { implementation(); return; } Code("try "); Block(() => { ABIWrapperParameterValidation(c); Line("if(!outInstance) return E_POINTER;"); Line($"*outInstance = new {TypeRef(owner, false)}("); List(CodeListStyle.MultiLine, () => { Indent++; foreach (var arg in c.Parameters) { string extra = ""; if (arg.IsArray) { extra = ", " + arg.Name + "_count"; } else if (arg.Type.IsDelegate) { extra = ", " + arg.Name + "_context"; } ListItem($"ABIUtil<{TypeRef(arg, false)}>::{(arg.IsWriteable() ? "Ref" : "FromABI")}({arg.Name}{extra})"); } Indent--; }); Line(");"); Line("return S_OK;"); }, " TRANSLATE_EXCEPTIONS"); }); } }