-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Class inheritance requires global namespace swapping #8
Labels
broken
Changes that require refactoring
Comments
GitHub is incredibly dumb with how they format issues. Blame them. |
diamondburned
added a commit
that referenced
this issue
Jul 4, 2021
This commit closes #9 by adding the new girgen/file.go FileGenerator, which is completely refactored from the ground up to be much smaller, cleaner and side effects-free. This commit closes #8 as well by introducing the SourceNamespace and CurrentNamespace API inside typeconv.Converter, which allows the converter to pick the right namespace for resolving and generating.
diamondburned
added a commit
that referenced
this issue
Jul 4, 2021
This commit closes #9 by adding the new girgen/file.go FileGenerator, which is completely refactored from the ground up to be much smaller, cleaner and side effects-free. This commit closes #8 as well by introducing the SourceNamespace and CurrentNamespace API inside typeconv.Converter, which allows the converter to pick the right namespace for resolving and generating.
Merged
diamondburned
added a commit
that referenced
this issue
Jul 4, 2021
This commit closes #9 by adding the new girgen/file.go FileGenerator, which is completely refactored from the ground up to be much smaller, cleaner and side effects-free. This commit closes #8 as well by introducing the SourceNamespace and CurrentNamespace API inside typeconv.Converter, which allows the converter to pick the right namespace for resolving and generating.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Preamble
Right now, the way class generation works, is that the implementation struct
only includes the parent type, which is usually the
GObject
itself. Interfacesthat it implements are generated as regular Go methods and conveniently utilizes
the class wrapper functions to reduce code.
Problem
The problem is, because some classes may implement interfaces from different
packages, and since the
TypeTree
routine naively uses theResolveType
API,the returned methods of the searched interfaces do not contain the namespace.
These methods are then given to
callableGenerator
which then callsTypeConverter
andResolveType
, but since the namespace is not in the typenames, all methods will fail to resolve.
For example, if we're in
package gdkpixbuf
, andgdkpixbuf.Pixbuf
implementsgio.Icon
, then the searched-upIcon
's methods will not containgio
. WhenResolveType
sees this, it tries to restore the namespace by concatenating thecurrent namespace in, creating
gdkpixbuf.Icon
, which is false.Below is the call tree that illustrates this problem:
Solution
The best solution will involve several parts. First off, if the
callableGenerator
were to take in aTypeResolver
interface that would allowthe caller to override the current namespace for just this instance, then the
issue would then become that some code won't have the right namespace prefixes,
because the converter will mistaken the current namespace.
This means that the next solution to implement would be to somehow decouple just
type resolves away from the conversion. It might even make sense to give
ValueConverter
two namespaces, the current one and the one to resolve with (orthe origin one).
Following that solution,
ResolveType
should then be completely decoupled awayfrom
NamespaceGenerator
at all. Instead, it should be its own function. Wecould even make
ValueConverter
take in a callbackResolveType
or aTypeResolver
interface that the caller can then use to wrap around and injectits own namespace. Whatever it may be, the current
ResolveType
is only amethod because:
a mini instance struct) that allow setting a
LineLogger
interface.Generator
. This could be addedinto the
TypeResolver
interface.Generator
and therefore can be inTypeResolver
.ModPath
, which formats the import module path into one that the callerwants, which can also be in
TypeResolver
.From the list above, there are quite a few parts that rely on
Generator
thatit might be worth it to implement just one method that returns the
Generator
instance to grab those common fields. It would also seem that a lot of these
abstractions should be their own packages, which would help decoupling a lot
more. Perhaps
package girgen
should only contain interfaces and the coreGenerator
.A
TypeResolver
should not be file-dependent either. Ideally, it should be verydecoupled to the point of not having any side effects on anything at all
(including imports). This would make it a lot easier to reuse
TypeResolver
fordifferent purposes while easily allowing multiple files with versions and build
tags in the future.
The text was updated successfully, but these errors were encountered: