diff options
author | Sven Gothel <[email protected]> | 2023-06-16 01:10:46 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-06-16 01:10:46 +0200 |
commit | 0a9105dd3ebbcf4b98664e50333334bff677031c (patch) | |
tree | f88ee400fa386e6f98b1336c2428f8ebcd6a3c72 /src/java/com/jogamp/gluegen/procaddress | |
parent | f1678c4ac8b85c85d11b737d08dcfe31b388e021 (diff) |
GlueGen Struct [3]: Adopt to CodeUnit Abstraction (replacing plain PrintWriter...)
Diffstat (limited to 'src/java/com/jogamp/gluegen/procaddress')
3 files changed, 90 insertions, 89 deletions
diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java index 37a39e1..c3c374f 100644 --- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,12 +41,11 @@ package com.jogamp.gluegen.procaddress; import com.jogamp.gluegen.CMethodBindingEmitter; -import com.jogamp.gluegen.MethodBinding; import com.jogamp.gluegen.JavaType; - -import java.io.*; - -import com.jogamp.gluegen.cgram.types.*; +import com.jogamp.gluegen.MethodBinding; +import com.jogamp.gluegen.cgram.types.FunctionSymbol; +import com.jogamp.gluegen.cgram.types.PointerType; +import com.jogamp.gluegen.cgram.types.Type; public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { @@ -74,7 +74,7 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { } } }, - methodToWrap.getDefaultOutput(), + methodToWrap.getUnit(), methodToWrap.getJavaPackageName(), methodToWrap.getJavaClassName(), methodToWrap.getIsOverloadedBinding(), @@ -102,14 +102,14 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { } @Override - protected int emitArguments(final PrintWriter writer) { - int numEmitted = super.emitArguments(writer); + protected int emitArguments() { + int numEmitted = super.emitArguments(); if (callThroughProcAddress) { if (numEmitted > 0) { - writer.print(", "); + unit.emit(", "); } - writer.print(procAddressJavaTypeName); - writer.print(" procAddress"); + unit.emit(procAddressJavaTypeName); + unit.emit(" procAddress"); ++numEmitted; } @@ -117,7 +117,7 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { } @Override - protected void emitBodyVariableDeclarations(final PrintWriter writer) { + protected void emitBodyVariableDeclarations() { if (callThroughProcAddress) { // create variable for the function pointer with the right type, and set // it to the value of the passed-in proc address @@ -138,23 +138,23 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { } final PointerType funcPtrType = new PointerType(null, cSym.getType(), 0); - writer.print(" typedef "); - writer.print(funcPtrType.toString(funcPointerTypedefLocalName, localTypedefCallingConvention)); - writer.println(";"); + unit.emit(" typedef "); + unit.emit(funcPtrType.toString(funcPointerTypedefLocalName, localTypedefCallingConvention)); + unit.emitln(";"); - writer.print(" "); - writer.print(funcPointerTypedefName); // Uses public typedef if available! - writer.print(" ptr_"); - writer.print(getNativeName()); - writer.println(";"); + unit.emit(" "); + unit.emit(funcPointerTypedefName); // Uses public typedef if available! + unit.emit(" ptr_"); + unit.emit(getNativeName()); + unit.emitln(";"); } - super.emitBodyVariableDeclarations(writer); + super.emitBodyVariableDeclarations(); } @Override - protected void emitBodyVariablePreCallSetup(final PrintWriter writer) { - super.emitBodyVariablePreCallSetup(writer); + protected void emitBodyVariablePreCallSetup() { + super.emitBodyVariablePreCallSetup(); if (callThroughProcAddress) { // set the function pointer to the value of the passed-in procAddress @@ -171,25 +171,25 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { final String ptrVarName = "ptr_" + getNativeName(); if (hasProcAddrTypedef) { - writer.println(" // implicit type validation of "+funcPointerTypedefLocalName+" -> "+funcPointerTypedefName); + unit.emitln(" // implicit type validation of "+funcPointerTypedefLocalName+" -> "+funcPointerTypedefName); } - writer.print(" "); - writer.print(ptrVarName); - writer.print(" = ("); - writer.print(funcPointerTypedefLocalName); - writer.println(") (intptr_t) procAddress;"); + unit.emit(" "); + unit.emit(ptrVarName); + unit.emit(" = ("); + unit.emit(funcPointerTypedefLocalName); + unit.emitln(") (intptr_t) procAddress;"); - writer.println(" assert(" + ptrVarName + " != NULL);"); + unit.emitln(" assert(" + ptrVarName + " != NULL);"); } } @Override - protected void emitBodyCallCFunction(final PrintWriter writer) { + protected void emitBodyCallCFunction() { if (!callThroughProcAddress) { - super.emitBodyCallCFunction(writer); + super.emitBodyCallCFunction(); } else { // Make the call to the actual C function - writer.print(" "); + unit.emit(" "); // WARNING: this code assumes that the return type has already been // typedef-resolved. @@ -199,9 +199,9 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { // Note we respect const/volatile in the function return type. // However, we cannot have it 'const' for our local variable. // See return type in CMethodBindingEmitter.emitBodyVariableDeclarations(..)! - writer.print("_res = ("); - writer.print(cReturnType.getCName(false)); - writer.print(") "); + unit.emit("_res = ("); + unit.emit(cReturnType.getCName(false)); + unit.emit(") "); } final MethodBinding mBinding = getBinding(); if (mBinding.hasContainingType()) { @@ -211,12 +211,12 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter { } // call throught the run-time function pointer - writer.print("(* ptr_"); - writer.print(getNativeName()); - writer.print(") "); - writer.print("("); - emitBodyPassCArguments(writer); - writer.println(");"); + unit.emit("(* ptr_"); + unit.emit(getNativeName()); + unit.emit(") "); + unit.emit("("); + emitBodyPassCArguments(); + unit.emitln(");"); } } diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java index ec29b08..b812416 100644 --- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java +++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2013 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -40,7 +40,6 @@ package com.jogamp.gluegen.procaddress; import java.io.File; -import java.io.PrintWriter; import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashSet; @@ -52,6 +51,7 @@ import java.util.logging.Level; import com.jogamp.gluegen.CMethodBindingEmitter; import com.jogamp.gluegen.CodeGenUtils; import com.jogamp.gluegen.FunctionEmitter; +import com.jogamp.gluegen.JavaCodeUnit; import com.jogamp.gluegen.JavaConfiguration; import com.jogamp.gluegen.JavaEmitter; import com.jogamp.gluegen.JavaMethodBindingEmitter; @@ -72,7 +72,7 @@ public class ProcAddressEmitter extends JavaEmitter { public static final String PROCADDRESS_VAR_PREFIX = "_addressof_"; protected static final String WRAP_PREFIX = "dispatch_"; private TypeDictionary typedefDictionary; - protected PrintWriter tableWriter; + protected JavaCodeUnit tableJavaUnit; protected Set<String> emittedTableEntries; protected String tableClassPackage; protected String tableClassName; @@ -307,47 +307,47 @@ public class ProcAddressEmitter extends JavaEmitter { final String jImplRoot = getJavaOutputDir() + File.separator + CodeGenUtils.packageAsPath(implPackageName); - tableWriter = openFile(jImplRoot + File.separator + tableClassName + ".java", tableClassName); - emittedTableEntries = new HashSet<String>(); + final String javaFileName = jImplRoot + File.separator + tableClassName + ".java"; + tableJavaUnit = openJavaUnit(javaFileName, implPackageName, tableClassName); - CodeGenUtils.emitAutogeneratedWarning(tableWriter, this); + emittedTableEntries = new HashSet<String>(); - tableWriter.println("package " + implPackageName + ";"); - tableWriter.println(); + tableJavaUnit.emitln("package " + implPackageName + ";"); + tableJavaUnit.emitln(); for (final String imporT : getConfig().imports()) { - tableWriter.println("import " + imporT + ";"); + tableJavaUnit.emitln("import " + imporT + ";"); } - tableWriter.println("import " + ProcAddressTable.class.getName() + ";"); - tableWriter.println("import com.jogamp.common.util.SecurityUtil;"); - tableWriter.println(); - - tableWriter.println("/**"); - tableWriter.println(" * This table is a cache of pointers to the dynamically-linkable C library."); - tableWriter.println(" * @see " + ProcAddressTable.class.getSimpleName()); - tableWriter.println(" */"); + tableJavaUnit.emitln("import " + ProcAddressTable.class.getName() + ";"); + tableJavaUnit.emitln("import com.jogamp.common.util.SecurityUtil;"); + tableJavaUnit.emitln(); + + tableJavaUnit.emitln("/**"); + tableJavaUnit.emitln(" * This table is a cache of pointers to the dynamically-linkable C library."); + tableJavaUnit.emitln(" * @see " + ProcAddressTable.class.getSimpleName()); + tableJavaUnit.emitln(" */"); for (int i = 0; accessModifiers != null && i < accessModifiers.length; ++i) { - tableWriter.print(accessModifiers[i]); - tableWriter.print(' '); + tableJavaUnit.emit(accessModifiers[i]); + tableJavaUnit.emit(" "); } - tableWriter.println("final class " + tableClassName + " extends "+ ProcAddressTable.class.getSimpleName() + " {"); - tableWriter.println(); + tableJavaUnit.emitln("final class " + tableClassName + " extends "+ ProcAddressTable.class.getSimpleName() + " {"); + tableJavaUnit.emitln(); for (final String string : getProcAddressConfig().getForceProcAddressGen()) { emitProcAddressTableEntryForString(string); } - tableWriter.println(); - tableWriter.println(" public "+tableClassName+"(){ super(); }"); - tableWriter.println(); - tableWriter.println(" public "+tableClassName+"("+FunctionAddressResolver.class.getName()+" resolver){ super(resolver); }"); - tableWriter.println(); + tableJavaUnit.emitln(); + tableJavaUnit.emitln(" public "+tableClassName+"(){ super(); }"); + tableJavaUnit.emitln(); + tableJavaUnit.emitln(" public "+tableClassName+"("+FunctionAddressResolver.class.getName()+" resolver){ super(resolver); }"); + tableJavaUnit.emitln(); } protected void endProcAddressTable() throws Exception { - tableWriter.println("} // end of class " + tableClassName); - tableWriter.flush(); - tableWriter.close(); + tableJavaUnit.emitln("} // end of class " + tableClassName); + tableJavaUnit.close(); + tableJavaUnit = null; } protected void emitProcAddressTableEntryForString(final String str) { @@ -357,10 +357,10 @@ public class ProcAddressEmitter extends JavaEmitter { return; } emittedTableEntries.add(str); - tableWriter.print(" /* pp */ long "); - tableWriter.print(PROCADDRESS_VAR_PREFIX); - tableWriter.print(str); - tableWriter.println(";"); + tableJavaUnit.emit(" /* pp */ long "); + tableJavaUnit.emit(PROCADDRESS_VAR_PREFIX); + tableJavaUnit.emit(str); + tableJavaUnit.emitln(";"); } protected ProcAddressConfiguration getProcAddressConfig() { diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java index 5298a8d..0d5de1c 100644 --- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without @@ -90,15 +91,15 @@ public class ProcAddressJavaMethodBindingEmitter extends JavaMethodBindingEmitte } @Override - protected int emitArguments(final PrintWriter writer) { - int numEmitted = super.emitArguments(writer); + protected int emitArguments() { + int numEmitted = super.emitArguments(); if (callThroughProcAddress) { if (changeNameAndArguments) { if (numEmitted > 0) { - writer.print(", "); + unit.emit(", "); } - writer.print("long procAddress"); + unit.emit("long procAddress"); ++numEmitted; } } @@ -116,27 +117,27 @@ public class ProcAddressJavaMethodBindingEmitter extends JavaMethodBindingEmitte } @Override - protected void emitPreCallSetup(final MethodBinding binding, final PrintWriter writer) { - super.emitPreCallSetup(binding, writer); + protected void emitPreCallSetup(final MethodBinding binding) { + super.emitPreCallSetup(binding); if (callThroughProcAddress) { final String procAddressVariable = ProcAddressEmitter.PROCADDRESS_VAR_PREFIX + binding.getNativeName(); - writer.println(" final long __addr_ = " + getProcAddressTableExpr + "." + procAddressVariable + ";"); - writer.println(" if (__addr_ == 0) {"); - writer.format(" throw new %s(String.format(\"Method \\\"%%s\\\" not available\", \"%s\"));%n", + unit.emitln(" final long __addr_ = " + getProcAddressTableExpr + "." + procAddressVariable + ";"); + unit.emitln(" if (__addr_ == 0) {"); + unit.emitf(" throw new %s(String.format(\"Method \\\"%%s\\\" not available\", \"%s\"));%n", emitter.unsupportedExceptionType(), binding.getName()); - writer.println(" }"); + unit.emitln(" }"); } } @Override - protected int emitCallArguments(final MethodBinding binding, final PrintWriter writer) { - int numEmitted = super.emitCallArguments(binding, writer); + protected int emitCallArguments(final MethodBinding binding) { + int numEmitted = super.emitCallArguments(binding); if (callThroughProcAddress) { if (numEmitted > 0) { - writer.print(", "); + unit.emit(", "); } - writer.print("__addr_"); + unit.emit("__addr_"); ++numEmitted; } |