RFR: 7903590: Refactor jextract source code generation
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Nov 27 12:40:40 UTC 2023
On Mon, 27 Nov 2023 12:30:19 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> src/main/java/org/openjdk/jextract/impl/TypedefBuilder.java line 41:
>>
>>> 39: }
>>> 40:
>>> 41: void generate() {
>>
>> This method seems only to be called after we create a new `TypedefBuilder`. Same is true for `FunctionalInterfaceBuilder`. It's also not a special method, just something that clients need to remember to call.
>> I'm wondering if this patch isn't really trying to transition away from the "building" metaphore - e.g. what you want is to create a new "typedef", "functional interface" object, and add it to some list of generated objects (so that their code will be all co-generated at the end). Having the client to call `generate` explicitly so that the string buffer is filled seems redundant. Either the string buffer is filled at construction (eagerly), or it is filled when creating the java file object (lazily).
>
> I don't see much point in doing this lazily, since we will always end up generating the code any way. What we could do is replace the `generate` method with a static one, that then also creates the builder internally.
>
> Note that `FunctionalInterfaceBuilder` is called from both TopLevelBuilder and StructBuilder, so we can't just get rid of `FunctionalInterfaceBuilder` I think. We could potentially remove `TypedefBuilder` since it's only used int he former case, but I thought we should stick to the same pattern.
Not suggesting to remove those builders. But I think the client saying `new FunctionalInterfaceBuilder(...)` should be enough. E.g. my comment is really about reducing the "contract" between builders and their clients.
-------------
PR Review Comment: https://git.openjdk.org/jextract/pull/141#discussion_r1406099372
More information about the jextract-dev
mailing list