< prev index next >
src/jdk.jextract/share/classes/com/sun/tools/jextract/AsmCodeFactory.java
Print this page
*** 39,62 ****
/**
* Scan a header file and generate classes for entities defined in that header
* file.
*/
! public class AsmCodeFactory extends CodeFactory {
! final ClassWriter global_cw;
! final String internal_name;
! final HeaderFile owner;
! final Map<String, byte[]> types;
! final HashSet<String> handledMacros = new HashSet<>();
! final Logger logger = Logger.getLogger(getClass().getPackage().getName());
! public AsmCodeFactory(HeaderFile header) {
logger.info(() -> "Instantiate AsmCodeFactory for " + header.path);
! owner = header;
! internal_name = Utils.toInternalName(owner.pkgName, owner.clsName);
! global_cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
! types = new HashMap<>();
init();
}
private void init() {
global_cw.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE,
--- 39,64 ----
/**
* Scan a header file and generate classes for entities defined in that header
* file.
*/
! final class AsmCodeFactory extends CodeFactory {
! private final Context ctx;
! private final ClassWriter global_cw;
! private final String internal_name;
! private final HeaderFile owner;
! private final Map<String, byte[]> types;
! private final HashSet<String> handledMacros = new HashSet<>();
! private final Logger logger = Logger.getLogger(getClass().getPackage().getName());
! AsmCodeFactory(Context ctx, HeaderFile header) {
! this.ctx = ctx;
logger.info(() -> "Instantiate AsmCodeFactory for " + header.path);
! this.owner = header;
! this.internal_name = Utils.toInternalName(owner.pkgName, owner.clsName);
! this.global_cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
! this.types = new HashMap<>();
init();
}
private void init() {
global_cw.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE,
*** 84,96 ****
deps.visitEnd();
}
}
private void handleException(Exception ex) {
! Context.getInstance().err.println(Main.format("cannot.write.class.file", owner.pkgName + "." + owner.clsName, ex));
if (Main.DEBUG) {
! ex.printStackTrace(Context.getInstance().err);
}
}
private void annotateC(ClassVisitor cw, Cursor dcl) {
AnnotationVisitor av = cw.visitAnnotation(
--- 86,98 ----
deps.visitEnd();
}
}
private void handleException(Exception ex) {
! ctx.err.println(Main.format("cannot.write.class.file", owner.pkgName + "." + owner.clsName, ex));
if (Main.DEBUG) {
! ex.printStackTrace(ctx.err);
}
}
private void annotateC(ClassVisitor cw, Cursor dcl) {
AnnotationVisitor av = cw.visitAnnotation(
*** 495,505 ****
jt2 = (JType2) jt;
jt = jt2.getDelegate();
} else {
logger.warning(() -> "Should have JType2 in addType");
if (Main.DEBUG) {
! new Throwable().printStackTrace(Context.getInstance().err);
}
}
if (cursor == null) {
assert (jt2 != null);
if (jt instanceof JType.FnIf) {
--- 497,507 ----
jt2 = (JType2) jt;
jt = jt2.getDelegate();
} else {
logger.warning(() -> "Should have JType2 in addType");
if (Main.DEBUG) {
! new Throwable().printStackTrace(ctx.err);
}
}
if (cursor == null) {
assert (jt2 != null);
if (jt instanceof JType.FnIf) {
*** 743,756 ****
}
public static void main(String[] args) throws IOException {
final Path file = Paths.get(args[1]);
final String pkg = args[0];
! Context ctx = Context.getInstance();
ctx.usePackageForFolder(file, pkg);
ctx.usePackageForFolder(Paths.get("/usr/include"), "system");
! ctx.sources.add(file);
! ctx.parse(AsmCodeFactory::new);
ctx.collectJarFile(Paths.get(args[2]), pkg);
}
-
}
--- 745,757 ----
}
public static void main(String[] args) throws IOException {
final Path file = Paths.get(args[1]);
final String pkg = args[0];
! Context ctx = new Context();
ctx.usePackageForFolder(file, pkg);
ctx.usePackageForFolder(Paths.get("/usr/include"), "system");
! ctx.addSource(file);
! ctx.parse();
ctx.collectJarFile(Paths.get(args[2]), pkg);
}
}
< prev index next >