Enum as an include option

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Oct 18 10:01:42 UTC 2022


Hi,
we did some experiments in this area:

https://git.openjdk.java.net/jextract/pull/36

But when trying it out, some issues were reported:

https://mail.openjdk.org/pipermail/panama-dev/2022-June/017073.html

So we decided to revert to previous behavior.

The main issue is that enums are "lowered" into standalone constants - 
e.g. a C enum like:

```
enum Colors { RED, GREEN, BLUE };
```

Is just translated as three constants in the main header class. There is 
no "Colors" interface generated by jextract. That's because in C enum 
constants are global, so we tried to respect that semantics with jextract.

But Duncan's email above also highlighted the fact that having an 
all-or-nothing flag for generating constants for an entire enum doesn't 
cut it: some enums might be huge, and you only want to import 2-3 constants.

So, the constant-driven filtering gives more flexibility to developers 
that really want to control how much stuff is generated by jextract. The 
alternative would be to have _two_ options, one for enum and one for 
enum constants, and then to define how the two interact which, frankly, 
seems messy.

Cheers
Maurizio



On 18/10/2022 01:12, Nir Lisker wrote:
> Hi,
>
> It looks like there is no --include- option for enum, although 
> Declaration.Scoped.Kind.ENUM exists. Is it part of the WIP or is there 
> another reason it's not an option?
>
> - Nir


More information about the jextract-dev mailing list