On Thu, 25 Jan 2024 17:25:59 GMT, Maurizio Cimadamore <mcimadamore@openjdk.org> wrote:
This PR tweaks jextract so that typedefs of anonymous structs only generate one class (that of the struct).
This required some changes in both `NameMangler` (to make sure that the special naming rule was applied), and then in `OutputFactory`, to make sure that in such case the typedef class is not emitted.
I've tweaked a number of tests which now reflect the "less verbose" jextract output - as such I don't think we need to add further tests.
src/main/java/org/openjdk/jextract/impl/NameMangler.java line 211:
209: // We may potentially generate a class for a typedef. Make sure 210: // class name is unique in the current nesting context. 211: javaName = curScope.uniqueNestedClassName(typedef.name());
This logic is a bit subtle: we have to avoid calling `uniqueNestedClassName` in case there's a struct that will inherit the typedef name - otherwise the mangler will see _two_ attempts to add the typedef name to the current scope, which will result in extra mangling.
This seems a bit ad-hoc... Suggestion: the `Scope` constructor tries to generate a unique nested class name if `parent` is not `null`. That's only the case when calling `newStruct`, which is only called from `visitScoped`. So, I think we can move the logic that computes the nested class name from the `Scope` constructor to `visitScoped` (to the `else` branch this patch adds). Then we can just pass the unmangled name from the `if` branch to `newStruct`, and there should be no need to have this logic here. ------------- PR Review Comment: https://git.openjdk.org/jextract/pull/195#discussion_r1466931107