< prev index next >
src/jdk.jextract/share/classes/com/sun/tools/jextract/AsmCodeFactory.java
Print this page
*** 88,97 ****
--- 88,99 ----
private final String internal_name;
private final HeaderFile owner;
private final Map<String, byte[]> types;
private final Logger logger = Logger.getLogger(getClass().getPackage().getName());
private final List<String> headerDeclarations = new ArrayList<>();
+ private final StaticForwarderGenerator staticForwardGen;
+
private transient boolean built = false;
AsmCodeFactory(Context ctx, HeaderFile header) {
this.ctx = ctx;
logger.info(() -> "Instantiate AsmCodeFactory for " + header.path);
*** 100,109 ****
--- 102,116 ----
this.global_cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
this.types = new HashMap<>();
global_cw.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE,
internal_name,
null, "java/lang/Object", null);
+ if (ctx.getGenStaticForwarder()) {
+ this.staticForwardGen = new StaticForwarderGenerator(header);
+ } else {
+ this.staticForwardGen = null;
+ }
}
private void generateNativeHeader() {
AnnotationVisitor av = global_cw.visitAnnotation(NATIVE_HEADER, true);
av.visit("path", owner.path.toAbsolutePath().toString());
*** 187,212 ****
av.visit("column", loc.column());
av.visit("USR", tree.USR());
av.visitEnd();
mv.visitEnd();
! cw.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, fieldName + "$set",
"(" + jt.getDescriptor() + ")V",
"(" + JType.getPointerVoidAsWildcard(jt) + ")V", null);
if (tree instanceof VarTree || !isBitField(tree)) {
JType ptrType = new PointerType(jt);
! cw.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, fieldName + "$ptr",
"()" + ptrType.getDescriptor(), "()" + ptrType.getSignature(), null);
}
}
@Override
public Void visitVar(VarTree varTree, JType jt) {
addField(global_cw, varTree, null);
Layout layout = varTree.layout();
String descStr = decorateAsAccessor(varTree, layout).toString();
addHeaderDecl(varTree.name(), descStr);
return null;
}
private void addHeaderDecl(String symbol, String desc) {
headerDeclarations.add(String.format("%s=%s", symbol, desc));
--- 194,224 ----
av.visit("column", loc.column());
av.visit("USR", tree.USR());
av.visitEnd();
mv.visitEnd();
! mv = cw.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, fieldName + "$set",
"(" + jt.getDescriptor() + ")V",
"(" + JType.getPointerVoidAsWildcard(jt) + ")V", null);
+ mv.visitEnd();
if (tree instanceof VarTree || !isBitField(tree)) {
JType ptrType = new PointerType(jt);
! mv = cw.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, fieldName + "$ptr",
"()" + ptrType.getDescriptor(), "()" + ptrType.getSignature(), null);
+ mv.visitEnd();
}
}
@Override
public Void visitVar(VarTree varTree, JType jt) {
addField(global_cw, varTree, null);
Layout layout = varTree.layout();
String descStr = decorateAsAccessor(varTree, layout).toString();
addHeaderDecl(varTree.name(), descStr);
+ if (staticForwardGen != null) {
+ staticForwardGen.visitVar(varTree, jt);
+ }
return null;
}
private void addHeaderDecl(String symbol, String desc) {
headerDeclarations.add(String.format("%s=%s", symbol, desc));
*** 306,315 ****
--- 318,330 ----
return null;
}
// generate annotation class for named enum
createAnnotationCls(enumTree);
+ if (staticForwardGen != null) {
+ staticForwardGen.visitEnum(enumTree, jt);
+ }
return null;
}
private void createAnnotationCls(Tree tree) {
String nativeName = tree.name();
*** 478,487 ****
--- 493,505 ----
null, alias.getAnnotationDescriptor(), true)
.visitEnd();
}
}
mv.visitEnd();
+ if (staticForwardGen != null) {
+ staticForwardGen.visitFunction(funcTree, jt);
+ }
return null;
}
protected AsmCodeFactory addType(JType jt, Tree tree) {
JType2 jt2 = null;
*** 564,573 ****
--- 582,594 ----
} else if (macroType.equals(String.class)) {
mv.visitInsn(ARETURN);
}
mv.visitMaxs(0, 0);
mv.visitEnd();
+ if (staticForwardGen != null) {
+ staticForwardGen.visitMacro(macroTree, jt);
+ }
return null;
}
protected synchronized void produce() {
if (built) {
*** 578,587 ****
--- 599,611 ----
try {
writeClassFile(global_cw, owner.clsName);
} catch (IOException ex) {
handleException(ex);
}
+ if (staticForwardGen != null) {
+ types.put(staticForwardGen.getSimpleClassName(), staticForwardGen.getClassBytes());
+ }
}
protected Map<String, byte[]> collect() {
// Ensure classes are produced
if (!built) produce();
< prev index next >