[foreign-jextract] RFR: 8239809: Need API to access attributes
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Tue Feb 25 18:18:18 UTC 2020
On Tue, 25 Feb 2020 17:30:55 GMT, Henry Jen <henryjen at openjdk.org> wrote:
> Add API to allow associate attributes with Declaration.
>
> An attribute can have multiple values, thus a list of ConstantDesc.
>
> The test case is based on [JDK-8223105](https://bugs.openjdk.java.net/browse/JDK-8223105), Windows test is simply parsing at this point, need to add validation as the header is implemented differently.
>
> We may want to add a more generic test case with some standard attributes.
Overall looks good, but let's try to minimize the API impact. Declaration attributes are, after all, an escape hatch, and we should not publicize them too much in the various declaration factories.
This also reminds me that we never sorted out lack of equals/hashcode in Declaration/Type implementation classes. We should address that (and make these method take into account attributes too). But it's probably preferrable to do this in a separate pull request.
src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/Declaration.java line 70:
> 69: */
> 70: Set<String> availableAttributes();
> 71:
Change this to attributeNames()
src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/Declaration.java line 295:
> 294: */
> 295: static Declaration.Variable globalVariable(Position pos, String name, Type type, Map<String, List<ConstantDesc>> attrs) {
> 296: return new DeclarationImpl.VariableImpl(type, Declaration.Variable.Kind.GLOBAL, name, pos, attrs);
Uhmmm. I think I'd prefer not to have a Map accepting factory, but to have a `Declaration::withAttribute(String, ConstantDesc)` method. This makes the API a lot tidier (and is similar to what we did for layouts).
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/33
More information about the panama-dev
mailing list