Skip to content

Commit

Permalink
7903449: Jextract generates structs that cannot be compiled
Browse files Browse the repository at this point in the history
Reviewed-by: jvernee
  • Loading branch information
mcimadamore committed Mar 30, 2023
1 parent 750c415 commit f3c7c85
Show file tree
Hide file tree
Showing 10 changed files with 702 additions and 773 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/openjdk/jextract/Type.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -107,21 +107,21 @@ enum Kind {
/**
* {@code short} type.
*/
Short("short", ValueLayout.JAVA_SHORT.withBitAlignment(16)),
Short("short", ValueLayout.JAVA_SHORT),
/**
* {@code int} type.
*/
Int("int", ValueLayout.JAVA_INT.withBitAlignment(32)),
Int("int", ValueLayout.JAVA_INT),
/**
* {@code long} type.
*/
Long("long", TypeImpl.IS_WINDOWS ?
ValueLayout.JAVA_INT.withBitAlignment(32) :
ValueLayout.JAVA_LONG.withBitAlignment(64)),
ValueLayout.JAVA_INT :
ValueLayout.JAVA_LONG),
/**
* {@code long long} type.
*/
LongLong("long long", ValueLayout.JAVA_LONG.withBitAlignment(64)),
LongLong("long long", ValueLayout.JAVA_LONG),
/**
* {@code int128} type.
*/
Expand Down
31 changes: 12 additions & 19 deletions src/main/java/org/openjdk/jextract/impl/ClassSourceBuilder.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,9 +27,10 @@
import javax.tools.JavaFileObject;
import java.lang.constant.ClassDesc;
import java.util.List;
import java.util.function.Consumer;

import org.openjdk.jextract.Declaration;
import org.openjdk.jextract.Type;
import org.openjdk.jextract.impl.Constants.Constant;

/**
* Superclass for .java source generator classes.
Expand Down Expand Up @@ -159,6 +160,10 @@ public List<JavaFileObject> toFiles() {

// Internal generation helpers (used by other builders)

void append(Object o) {
sb.append(o);
}

void append(String s) {
sb.append(s);
}
Expand Down Expand Up @@ -264,17 +269,17 @@ protected void emitImportSection() {
}
}

protected void emitGetter(String mods, Class<?> type, String name, String access, boolean nullCheck, String symbolName) {
void emitConstantGetter(String mods, String getterName, boolean nullCheck, String symbolName, Constant constant) {
incrAlign();
indent();
append(mods + " " + type.getSimpleName() + " " +name + "() {\n");
append(mods + " " + constant.type().getSimpleName() + " " + getterName + "() {\n");
incrAlign();
indent();
append("return ");
if (nullCheck) {
append("RuntimeHelper.requireNonNull(");
}
append(access);
append(constant.accessExpression());
if (nullCheck) {
append(",\"");
append(symbolName);
Expand All @@ -287,20 +292,8 @@ protected void emitGetter(String mods, Class<?> type, String name, String access
decrAlign();
}

protected void emitGetter(String mods, Class<?> type, String name, String access) {
emitGetter(mods, type, name, access, false, null);
}

ToplevelBuilder toplevel() {
JavaSourceBuilder encl = enclosing;
while (encl instanceof ClassSourceBuilder classSourceBuilder) {
encl = classSourceBuilder.enclosing;
}
return (ToplevelBuilder)encl;
}

@Override
protected void emitWithConstantClass(Consumer<ConstantBuilder> constantConsumer) {
enclosing.emitWithConstantClass(constantConsumer);
protected Constants constants() {
return enclosing.constants();
}
}

0 comments on commit f3c7c85

Please sign in to comment.