Skip to content

Commit

Permalink
[registrar] Refactor code to make it easier to reuse code later on
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Apr 20, 2023
1 parent 41a36aa commit 24b50f7
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions tools/common/StaticRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4340,27 +4340,7 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>
sb.Write (", 0x{0:X}", token_ref);
sb.WriteLine (");");
if (isCtor) {
sb.WriteLine ("if (call_super && rv) {");
sb.Write ("struct objc_super super = { rv, [").Write (method.DeclaringType.SuperType.ExportedName).WriteLine (" class] };");
sb.Write ("rv = ((id (*)(objc_super*, SEL");

if (method.Parameters != null) {
for (int i = 0; i < method.Parameters.Length; i++)
sb.Append (", ").Append (ToObjCParameterType (method.Parameters [i], method.DescriptiveMethodName, exceptions, method.Method));
}
if (method.IsVariadic)
sb.Append (", ...");

sb.Write (")) objc_msgSendSuper) (&super, @selector (");
sb.Write (method.Selector);
sb.Write (")");
var split = method.Selector.Split (':');
for (int i = 0; i < split.Length - 1; i++) {
sb.Append (", ");
sb.AppendFormat ("p{0}", i);
}
sb.WriteLine (");");
sb.WriteLine ("}");
GenerateCallToSuperForConstructor (sb, method, exceptions);
sb.WriteLine ("return rv;");
}
sb.WriteLine ("}");
Expand All @@ -4369,6 +4349,31 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>
}
}

void GenerateCallToSuperForConstructor (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception> exceptions)
{
sb.WriteLine ("if (call_super && rv) {");
sb.Write ("struct objc_super super = { rv, [").Write (method.DeclaringType.SuperType.ExportedName).WriteLine (" class] };");
sb.Write ("rv = ((id (*)(objc_super*, SEL");

if (method.Parameters != null) {
for (int i = 0; i < method.Parameters.Length; i++)
sb.Append (", ").Append (ToObjCParameterType (method.Parameters [i], method.DescriptiveMethodName, exceptions, method.Method));
}
if (method.IsVariadic)
sb.Append (", ...");

sb.Write (")) objc_msgSendSuper) (&super, @selector (");
sb.Write (method.Selector);
sb.Write (")");
var split = method.Selector.Split (':');
for (int i = 0; i < split.Length - 1; i++) {
sb.Append (", ");
sb.AppendFormat ("p{0}", i);
}
sb.WriteLine (");");
sb.WriteLine ("}");
}

public TypeDefinition GetInstantiableType (TypeDefinition td, List<Exception> exceptions, string descriptiveMethodName)
{
TypeDefinition nativeObjType = td;
Expand Down

0 comments on commit 24b50f7

Please sign in to comment.