RFR: 7903257: jextract should generate javadoc comments [v3]

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Oct 12 12:21:35 UTC 2022


On Wed, 12 Oct 2022 12:12:11 GMT, Athijegannathan Sundararajan <sundar at openjdk.org> wrote:

>> Generating C signature as doc comments.
>
> Athijegannathan Sundararajan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   defensive code to avoid possible crashes in doc generation

src/main/java/org/openjdk/jextract/impl/CDeclarationPrinter.java line 105:

> 103:         var ftype = d.type();
> 104:         var rtype = ftype.returnType();
> 105:         builder.append(nameAndType(rtype, ""));

I would rather add another helper function to just print a type, rather than reusing `nameAndType` here. Also, we should check that the type doesn't have a name attached.

src/main/java/org/openjdk/jextract/impl/CDeclarationPrinter.java line 149:

> 147:         indent();
> 148:         builder.append("typedef ");
> 149:         builder.append(nameAndType(d.type(), d.name()));

This use of `nameAndType` also leaves me a bit doubtful. There's var declarations, and there's just types + name. What's acceptable in both cases is different - e.g. `int a[3]` is not a valid type for a typedef. So, in cases where we just want a type, and the type should not have a name, we should have a way to say so in the code.

src/main/java/org/openjdk/jextract/impl/CDeclarationPrinter.java line 162:

> 160:     // in the result.
> 161: 
> 162:     private static String nameAndType(Type type, String name) {

Maybe we should call this "varDecl" since this is morally to be used for variable declarations.

src/main/java/org/openjdk/jextract/impl/CDeclarationPrinter.java line 231:

> 229:             }
> 230:             String res = t.returnType().accept(this, "").typeStr();
> 231:             return new TypeVisitorResult(true, res + " (" + context + ")" + argsStr);

Is there always a name attached to a function pointer? I'd say no (e.g. typedef).

src/main/java/org/openjdk/jextract/impl/CDeclarationPrinter.java line 244:

> 242:             String brackets = String.format(" %s[%s]", context,
> 243:                 t.elementCount().isPresent() ? t.elementCount().getAsLong() : "");
> 244:             return new TypeVisitorResult(true, t.elementType().accept(this, "").typeStr() + brackets);

Is there always a name attached to an array type? I would say no? (e.g. in a typedef)

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

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


More information about the jextract-dev mailing list