[foreign] RFC: Additional jextract filtering
Jorn Vernee
jbvernee at xs4all.nl
Mon Mar 11 13:04:19 UTC 2019
Hi,
I've been looking into adding more filtering capabilities to jextract
over the past few days.
I have come up with the following proposal; Replace --include-symbols
and --exclude-symbols with 2 new options, --include and --exclude. These
options take as an argument a filter expression, which looks like
SELECTOR:PATTERN or, for includes only, SELECTOR-PRESET, where SELECTOR
is one of [symbol, macro, struct, typedef, enum], and PRESET is one of
[ALL, REQUIRED]. PATTERN is a regex pattern. The selector lets us select
the type of element a pattern applies to, and the preset is a default
for what to do when there are no explicit includes specified for that
specific selector.
The earlier mentioned problem with allowing filtering of things besides
symbols and macros (which is what the current implementation supports),
is that we might end up excluding something that is actually required.
So, to make sure that doesn't happen, we first filter a set of 'root'
declarations, which are library symbols (global vars and functions) and
macros, then from those compute a minimal set of dependencies, and then
use that in a subsequent round of filtering for structs, typedefs and
enums to make sure nothing that is required gets filtered out. This
minimal dependency set can also be used to only include what's
absolutely needed, by using the REQUIRED filter preset.
To give an example; If we have a header like so:
```
struct Foo {
int x;
};
struct Bar {
int x;
};
void func(struct Foo foo);
```
We can use the option `--include struct-REQUIRED`, and `Bar` will be
omitted from the output, since it is not used directly by `func`.
However, if we also use the option `--exclude struct:Foo` the output
won't change, since the struct Foo is required by the function func.
But, if we instead use `--exclude symbol:func` in the options, we get no
output at all, because `func` is filtered, and then none of the structs
are required, so they get filtered as well.
I have implemented a prototype of this proposal here:
http://cr.openjdk.java.net/~jvernee/panama/webrevs/filters/webrev.00/
If the proposal sounds good I can add more tests and make an RFR.
Thanks,
Jorn
More information about the panama-dev
mailing list