diff options
author | Michael Bien <[email protected]> | 2010-03-31 19:05:36 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-03-31 19:05:36 +0200 |
commit | c5068e42758aeecbd0a3fbf4c2e2b755661e950e (patch) | |
tree | 5aa658bb3998103499d6bcfdecd2a5b13459a3f0 /src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java | |
parent | 5cef76666685a4dc94324c2463a4dba53950071c (diff) |
refactoring and code cleanup in gluegen.opengl and gluegen.procaddress package.
Diffstat (limited to 'src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java')
-rwxr-xr-x | src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java | 185 |
1 files changed, 91 insertions, 94 deletions
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java index 2dda752..5a30ee5 100755 --- a/src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java +++ b/src/java/com/sun/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java @@ -36,118 +36,115 @@ * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ - package com.sun.gluegen.procaddress; import java.io.*; -import java.util.*; import com.sun.gluegen.*; -import com.sun.gluegen.cgram.types.*; /** A specialization of JavaMethodBindingEmitter with knowledge of how - to call through a function pointer. */ - +to call through a function pointer. */ public class ProcAddressJavaMethodBindingEmitter extends JavaMethodBindingEmitter { - private final CommentEmitter commentEmitterForWrappedMethod = - new WrappedMethodCommentEmitter(); - - protected boolean callThroughProcAddress; - protected String getProcAddressTableExpr; - protected boolean changeNameAndArguments; - protected ProcAddressEmitter emitter; - - public ProcAddressJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap, - boolean callThroughProcAddress, - String getProcAddressTableExpr, - boolean changeNameAndArguments, - ProcAddressEmitter emitter) { - super(methodToWrap); - this.callThroughProcAddress = callThroughProcAddress; - this.getProcAddressTableExpr = getProcAddressTableExpr; - this.changeNameAndArguments = changeNameAndArguments; - this.emitter = emitter; - if (callThroughProcAddress) { - setCommentEmitter(new WrappedMethodCommentEmitter()); + + protected boolean callThroughProcAddress; + protected boolean changeNameAndArguments; + + protected String getProcAddressTableExpr; + protected ProcAddressEmitter emitter; + + public ProcAddressJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap, boolean callThroughProcAddress, + String getProcAddressTableExpr, boolean changeNameAndArguments, ProcAddressEmitter emitter) { + + super(methodToWrap); + + this.callThroughProcAddress = callThroughProcAddress; + this.getProcAddressTableExpr = getProcAddressTableExpr; + this.changeNameAndArguments = changeNameAndArguments; + this.emitter = emitter; + + if (callThroughProcAddress) { + setCommentEmitter(new WrappedMethodCommentEmitter()); + } + + if (methodToWrap.getBinding().hasContainingType()) { + throw new IllegalArgumentException( + "Cannot create proc. address wrapper; method has containing type: \"" + + methodToWrap.getBinding() + "\""); + } } - if (methodToWrap.getBinding().hasContainingType()) - { - throw new IllegalArgumentException( - "Cannot create proc. address wrapper; method has containing type: \"" + - methodToWrap.getBinding() + "\""); + public ProcAddressJavaMethodBindingEmitter(ProcAddressJavaMethodBindingEmitter methodToWrap) { + this(methodToWrap, methodToWrap.callThroughProcAddress, methodToWrap.getProcAddressTableExpr, + methodToWrap.changeNameAndArguments, methodToWrap.emitter); } - } - - public ProcAddressJavaMethodBindingEmitter(ProcAddressJavaMethodBindingEmitter methodToWrap) { - this(methodToWrap, - methodToWrap.callThroughProcAddress, - methodToWrap.getProcAddressTableExpr, - methodToWrap.changeNameAndArguments, - methodToWrap.emitter); - } - - public String getName() { - String res = super.getName(); - if (changeNameAndArguments) { - return ProcAddressEmitter.WRAP_PREFIX + res; + + @Override + public String getName() { + String res = super.getName(); + if (changeNameAndArguments) { + return ProcAddressEmitter.WRAP_PREFIX + res; + } + return res; } - return res; - } - - protected int emitArguments(PrintWriter writer) { - int numEmitted = super.emitArguments(writer); - if (callThroughProcAddress) { - if (changeNameAndArguments) { - if (numEmitted > 0) { - writer.print(", "); + + @Override + protected int emitArguments(PrintWriter writer) { + int numEmitted = super.emitArguments(writer); + if (callThroughProcAddress) { + if (changeNameAndArguments) { + if (numEmitted > 0) { + writer.print(", "); + } + + writer.print("long procAddress"); + ++numEmitted; + } } - writer.print("long procAddress"); - ++numEmitted; - } + return numEmitted; } - - return numEmitted; - } - - protected String getImplMethodName() { - String name = super.getImplMethodName(); - if (callThroughProcAddress) { - return ProcAddressEmitter.WRAP_PREFIX + name; + + @Override + protected String getImplMethodName() { + String name = super.getImplMethodName(); + if (callThroughProcAddress) { + return ProcAddressEmitter.WRAP_PREFIX + name; + } + return name; } - return name; - } - - protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) { - super.emitPreCallSetup(binding, writer); - - if (callThroughProcAddress) { - String procAddressVariable = - ProcAddressEmitter.PROCADDRESS_VAR_PREFIX + binding.getName(); - writer.println(" final long __addr_ = " + getProcAddressTableExpr + "." + procAddressVariable + ";"); - writer.println(" if (__addr_ == 0) {"); - writer.println(" throw new " + emitter.unsupportedExceptionType() + "(\"Method \\\"" + binding.getName() + "\\\" not available\");"); - writer.println(" }"); + + @Override + protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) { + super.emitPreCallSetup(binding, writer); + + if (callThroughProcAddress) { + String procAddressVariable = ProcAddressEmitter.PROCADDRESS_VAR_PREFIX + binding.getName(); + writer.println(" final long __addr_ = " + getProcAddressTableExpr + "." + procAddressVariable + ";"); + writer.println(" if (__addr_ == 0) {"); + writer.println(" throw new " + emitter.unsupportedExceptionType() + "(\"Method \\\"" + binding.getName() + "\\\" not available\");"); + writer.println(" }"); + } } - } - - protected int emitCallArguments(MethodBinding binding, PrintWriter writer) { - int numEmitted = super.emitCallArguments(binding, writer); - if (callThroughProcAddress) { - if (numEmitted > 0) { - writer.print(", "); - } - writer.print("__addr_"); - ++numEmitted; + + @Override + protected int emitCallArguments(MethodBinding binding, PrintWriter writer) { + int numEmitted = super.emitCallArguments(binding, writer); + if (callThroughProcAddress) { + if (numEmitted > 0) { + writer.print(", "); + } + writer.print("__addr_"); + ++numEmitted; + } + + return numEmitted; } - return numEmitted; - } + /** This class emits the comment for the wrapper method */ + public class WrappedMethodCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter { - /** This class emits the comment for the wrapper method */ - public class WrappedMethodCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter { - protected void emitBeginning(FunctionEmitter methodEmitter, PrintWriter writer) { - writer.print("Entry point (through function pointer) to C language function: <br> "); + @Override + protected void emitBeginning(FunctionEmitter methodEmitter, PrintWriter writer) { + writer.print("Entry point (through function pointer) to C language function: <br> "); + } } - } } |