Skip to content

Commit

Permalink
Set the correct pointer for setting functions of a parentStruct.
Browse files Browse the repository at this point in the history
Fixes: #326
  • Loading branch information
MikeWey committed Mar 28, 2021
1 parent 4f62b29 commit dd08ce6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 36 deletions.
35 changes: 15 additions & 20 deletions generated/gtkd/gtkd/Implement.d
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ template ImplementClassImpl(Klass, Impl)
"\t"~ Klass.stringof ~"Class parentClass;\n"~
"}\n\n";

result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n"~
"protected static "~ Klass.stringof ~"Class* parentClass = null;\n\n";
result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n\n";

result ~= "protected override void* getStruct()\n"~
"{\n"~
Expand Down Expand Up @@ -145,7 +144,7 @@ template ImplementClassImpl(Klass, Impl)
{
result ~= "static void "~ toCamelCase!Impl() ~"ClassInit (void* klass)\n"~
"{\n"~
"\tparentClass = cast("~ Klass.stringof ~"Class*) g_type_class_peek_parent(klass);\n";
"\t"~ fullyQualifiedName!(getClass!Klass) ~"* "~ toCamelCase!(getClass!Klass)() ~" = cast("~ fullyQualifiedName!(getClass!Klass) ~"*)klass;\n";

result ~= setFunctionPointers!(getClass!Klass)();

Expand Down Expand Up @@ -175,10 +174,7 @@ template ImplementClassImpl(Klass, Impl)
!implements!Impl(toCamelCase!Impl() ~ names[i].capitalizeFirst) )
//TODO: __traits(isOverrideFunction, Foo.foo) ?
{
static if ( is(GtkClass == getClass!Klass) )
result ~= "\tparentClass."~ names[i] ~" = &"~ toCamelCase!Impl() ~ names[i].capitalizeFirst ~";\n";
else
result ~= "\t"~ toCamelCase!GtkClass() ~"."~ names[i] ~" = &"~ toCamelCase!Impl() ~ names[i].capitalizeFirst ~";\n";
result ~= "\t"~ toCamelCase!GtkClass() ~"."~ names[i] ~" = &"~ toCamelCase!Impl() ~ names[i].capitalizeFirst ~";\n";
}
}

Expand Down Expand Up @@ -209,16 +205,6 @@ template ImplementClassImpl(Klass, Impl)

return result;
}

template getClass(Instance)
{
mixin("import "~ getClassImport!Instance() ~"; alias getClass = "~ Instance.stringof ~"Class;");
}

private string getClassImport(Klass)()
{
return fullyQualifiedName!Klass.replace("."~ Klass.stringof, "");
}
}

template ImplementInterfaceImpl(Base, Klass, Impl)
Expand Down Expand Up @@ -248,8 +234,7 @@ template ImplementInterfaceImpl(Base, Klass, Impl)
"\t"~ Base.stringof ~"Class parentClass;\n"~
"}\n\n";

result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n"~
"protected static "~ Base.stringof ~"Class* parentClass = null;\n\n";
result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n\n";

result ~= "protected override void* getStruct()\n"~
"{\n"~
Expand Down Expand Up @@ -306,7 +291,7 @@ template ImplementInterfaceImpl(Base, Klass, Impl)
{
result ~= "static void "~ toCamelCase!Impl() ~"ClassInit (void* klass)\n"~
"{\n"~
"\tparentClass = cast("~ Base.stringof ~"Class*) g_type_class_peek_parent(klass);\n"~
"\t"~ fullyQualifiedName!(getClass!Base) ~"* "~ toCamelCase!(getClass!Base)() ~" = cast("~ fullyQualifiedName!(getClass!Base) ~"*)klass;\n"~
"}\n\n";
}

Expand Down Expand Up @@ -370,6 +355,16 @@ private string getTypeImport(Iface)()
return fullyQualifiedName!Iface.replace("types."~ Iface.stringof, "functions");
}

template getClass(Instance)
{
mixin("import "~ getClassImport!Instance() ~"; alias getClass = "~ Instance.stringof ~"Class;");
}

private string getClassImport(Klass)()
{
return fullyQualifiedName!Klass.replace("."~ Klass.stringof, "");
}

private string getWrapFunction(Impl, Member, string name)()
{
string result;
Expand Down
31 changes: 15 additions & 16 deletions src/gtkd/Implement.d
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ template ImplementClassImpl(Klass, Impl)
string result;

result ~= "import glib.Str;\n"~
"import gobject.ObjectG;\n"~
"import gobject.Type : Type;\n"~
"import gobject.c.functions : g_type_class_peek_parent, g_object_get_data;\n";

Expand All @@ -105,8 +106,7 @@ template ImplementClassImpl(Klass, Impl)
"\t"~ Klass.stringof ~"Class parentClass;\n"~
"}\n\n";

result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n"~
"protected static "~ Klass.stringof ~"Class* parentClass = null;\n\n";
result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n\n";

result ~= "protected override void* getStruct()\n"~
"{\n"~
Expand Down Expand Up @@ -144,7 +144,7 @@ template ImplementClassImpl(Klass, Impl)
{
result ~= "static void "~ toCamelCase!Impl() ~"ClassInit (void* klass)\n"~
"{\n"~
"\tparentClass = cast("~ Klass.stringof ~"Class*) g_type_class_peek_parent(klass);\n";
"\t"~ fullyQualifiedName!(getClass!Klass) ~"* "~ toCamelCase!(getClass!Klass)() ~" = cast("~ fullyQualifiedName!(getClass!Klass) ~"*)klass;\n";

result ~= setFunctionPointers!(getClass!Klass)();

Expand Down Expand Up @@ -205,16 +205,6 @@ template ImplementClassImpl(Klass, Impl)

return result;
}

template getClass(Instance)
{
mixin("import "~ getClassImport!Instance() ~"; alias getClass = "~ Instance.stringof ~"Class;");
}

private string getClassImport(Klass)()
{
return fullyQualifiedName!Klass.replace("."~ Klass.stringof, "");
}
}

template ImplementInterfaceImpl(Base, Klass, Impl)
Expand Down Expand Up @@ -244,8 +234,7 @@ template ImplementInterfaceImpl(Base, Klass, Impl)
"\t"~ Base.stringof ~"Class parentClass;\n"~
"}\n\n";

result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n"~
"protected static "~ Base.stringof ~"Class* parentClass = null;\n\n";
result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n\n";

result ~= "protected override void* getStruct()\n"~
"{\n"~
Expand Down Expand Up @@ -302,7 +291,7 @@ template ImplementInterfaceImpl(Base, Klass, Impl)
{
result ~= "static void "~ toCamelCase!Impl() ~"ClassInit (void* klass)\n"~
"{\n"~
"\tparentClass = cast("~ Base.stringof ~"Class*) g_type_class_peek_parent(klass);\n"~
"\t"~ fullyQualifiedName!(getClass!Base) ~"* "~ toCamelCase!(getClass!Base)() ~" = cast("~ fullyQualifiedName!(getClass!Base) ~"*)klass;\n"~
"}\n\n";
}

Expand Down Expand Up @@ -366,6 +355,16 @@ private string getTypeImport(Iface)()
return fullyQualifiedName!Iface.replace("types."~ Iface.stringof, "functions");
}

template getClass(Instance)
{
mixin("import "~ getClassImport!Instance() ~"; alias getClass = "~ Instance.stringof ~"Class;");
}

private string getClassImport(Klass)()
{
return fullyQualifiedName!Klass.replace("."~ Klass.stringof, "");
}

private string getWrapFunction(Impl, Member, string name)()
{
string result;
Expand Down

0 comments on commit dd08ce6

Please sign in to comment.