RFR: 7903616: Bad formatting of layout string for structs with nested anon structs/unions [v3]

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Dec 22 14:48:19 UTC 2023


On Fri, 22 Dec 2023 14:45:16 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This PR fixes an indentation issue when generating a struct layout string.
>> 
>> Example:
>> 
>> 
>> struct Foo {
>>     struct {
>>         int x;
>>         union {
>>             int y;
>>             int z;
>>         };
>>     };
>> }; 
>> 
>> 
>> For this, jextract generates:
>> 
>> 
>>     private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
>>         MemoryLayout.structLayout(
>>         foo_h.C_INT.withName("x"),
>>         MemoryLayout.unionLayout(
>>         foo_h.C_INT.withName("y"),
>>         foo_h.C_INT.withName("z")
>>     ).withName("$anon$7:9")
>>     ).withName("$anon$5:5")
>>     ).withName("Foo");
>> 
>> 
>> With the fix in this PR, the generated string is:
>> 
>> 
>>     private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
>>         MemoryLayout.structLayout(
>>             foo_h.C_INT.withName("x"),
>>             MemoryLayout.unionLayout(
>>                 foo_h.C_INT.withName("y"),
>>                 foo_h.C_INT.withName("z")
>>             ).withName("$anon$7:9")
>>         ).withName("$anon$5:5")
>>     ).withName("Foo");
>> 
>> 
>> The fix is to correctly track required indentation when descending into a scoped declaration.
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Remove redundant trailing semi

src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java line 380:

> 378:     private String constantValue(Class<?> type, Object value) {
> 379:         if (value instanceof String) {
> 380:             return STR."Arena.ofAuto().allocateFrom(\"\{Utils.quote(Objects.toString(value))}\")";

The changes here are unrelated - but I noted a double `;` when eyeballing the generated sources for windows.h, and addressed it here

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

PR Review Comment: https://git.openjdk.org/jextract/pull/170#discussion_r1435128474


More information about the jextract-dev mailing list