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

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Dec 21 16:15:29 UTC 2023


> 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:

  Fix indentation of padding layout strings nested inside struct layouts

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

Changes:
  - all: https://git.openjdk.org/jextract/pull/170/files
  - new: https://git.openjdk.org/jextract/pull/170/files/c34a3b67..1e6bf58a

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jextract&pr=170&range=01
 - incr: https://webrevs.openjdk.org/?repo=jextract&pr=170&range=00-01

  Stats: 7 lines in 2 files changed: 0 ins; 0 del; 7 mod
  Patch: https://git.openjdk.org/jextract/pull/170.diff
  Fetch: git fetch https://git.openjdk.org/jextract.git pull/170/head:pull/170

PR: https://git.openjdk.org/jextract/pull/170


More information about the jextract-dev mailing list