[foreign-jextract] RFR: 8274155 Foreign API refresh - jextract update

Maurizio Cimadamore mcimadamore at openjdk.java.net
Thu Sep 23 10:16:21 UTC 2021


On Thu, 23 Sep 2021 09:52:32 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/OutputFactory.java line 371:
>> 
>>> 369: 
>>> 370:         if (type instanceof Type.Declared) {
>>> 371:             // anon type - let's generate something
>> 
>> name empty check removed. Does this comment make sense still?
>
> I will need to double check this one.

This is caused by a difference in the AST when nested structs are found. Consider this example:

struct Foo {
    struct Bar {
        int x, y;
    } bar;
};


The AST used to be:

Scoped: TOPLEVEL <toplevel>
    Scoped: STRUCT Foo layout = [[b32(x)[abi/kind=INT,layout/name=x]b32(y)[abi/kind=INT,layout/name=y]](bar)[layout/name=bar]](Foo)[layout/name=Foo]
        Scoped: STRUCT Bar layout = [b32(x)[abi/kind=INT,layout/name=x]b32(y)[abi/kind=INT,layout/name=y]](Bar)[layout/name=Bar]
            Variable: FIELD x type = Int(layout = b32[abi/kind=INT]), layout = Optional[b32[abi/kind=INT]]
            Variable: FIELD y type = Int(layout = b32[abi/kind=INT]), layout = Optional[b32[abi/kind=INT]]
        Variable: FIELD bar type = Declared([b32(x)[abi/kind=INT,layout/name=x]b32(y)[abi/kind=INT,layout/name=y]](Bar)[layout/name=Bar]), layout = Optional[[b32(x)[abi/kind=INT,layout/name=x]b32(y)[abi/kind=INT,layout/name=y]](Bar)[layout/name=Bar]]

Here you can see that both `Foo` and `Bar` declaration are present in the AST. After these changes the AST is like this:


Scoped: TOPLEVEL <toplevel>
    Scoped: STRUCT Foo layout = [[8%b32(x)8%b32(y)](bar)](Foo)
        Variable: FIELD bar type = Declared([8%b32(x)8%b32(y)](Bar)), layout = Optional[[8%b32(x)8%b32(y)](Bar)]


That is, the declaration for `Bar` is still there, but it's "hidden" behind the declared type of the struct field `bar`.

Is there some API method I can call to find a struct declared "on the fly" in this way?

-------------

PR: https://git.openjdk.java.net/panama-foreign/pull/577


More information about the panama-dev mailing list