From 03bf321dc0aac6a2bc635093d634e1c8e67f8d43 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Thu, 8 Oct 2009 18:44:55 +0200 Subject: defines with constant but more complex expressions are now no longer ignored (e.g #define CL_FP_FMA (1 << 5)). --- src/java/com/sun/gluegen/JavaEmitter.java | 91 +++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 28 deletions(-) (limited to 'src/java/com/sun/gluegen/JavaEmitter.java') diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java index 1667ed6..c9a54e3 100644 --- a/src/java/com/sun/gluegen/JavaEmitter.java +++ b/src/java/com/sun/gluegen/JavaEmitter.java @@ -133,14 +133,10 @@ public class JavaEmitter implements GlueEmitter { } } - public void beginEmission(GlueEmitterControls controls) throws IOException - { - try - { + public void beginEmission(GlueEmitterControls controls) throws IOException { + try { openWriters(); - } - catch (Exception e) - { + } catch (Exception e) { throw new RuntimeException( "Unable to open files for writing", e); } @@ -156,30 +152,24 @@ public class JavaEmitter implements GlueEmitter { controls.runSymbolFilter(new ConstantRenamer()); } - public void endEmission() - { + public void endEmission() { emitAllFileFooters(); - try - { + try { closeWriters(); - } - catch (Exception e) - { + } catch (Exception e) { throw new RuntimeException( "Unable to close open files", e); } } - public void beginDefines() throws Exception - { + public void beginDefines() throws Exception { if (cfg.allStatic() || cfg.emitInterface()) { javaWriter().println(); } } - protected static int getJavaRadix(String name, String value) - { + protected static int getJavaRadix(String name, String value) { // FIXME: need to handle when type specifier is in last char (e.g., // "1.0d or 2759L", because parseXXX() methods don't allow the type // specifier character in the string. @@ -222,14 +212,59 @@ public class JavaEmitter implements GlueEmitter { } } - protected static Object getJavaValue(String name, String value) - { + protected static Object getJavaValue(String name, String value) { + + // "calculates" the result type of a simple expression + // example: (2+3)-(2.0f-3.0) -> Double + // example: (1 << 2) -> Integer + + Scanner scanner = new Scanner(value).useDelimiter("[+-/*/> 1) { // TODO: is "0" the prefix in C to indicate octal??? - radix = 8; + radix = 8; parseValue = value.substring(1); } else { @@ -257,7 +292,7 @@ public class JavaEmitter implements GlueEmitter { return new Integer((int)longVal); } return new Long(longVal); - + } catch (NumberFormatException e) { try { // see if it's a double or float @@ -268,7 +303,7 @@ public class JavaEmitter implements GlueEmitter { return new Double(dVal); } return new Float((float) dVal); - } catch (NumberFormatException e2) { + } catch (NumberFormatException e2) { throw new RuntimeException( "Cannot emit define \""+name+"\": value \""+value+ "\" cannot be assigned to a int, long, float, or double", e2); @@ -276,6 +311,7 @@ public class JavaEmitter implements GlueEmitter { } } + protected static String getJavaType(String name, String value) { Object oval = getJavaValue(name, value); return getJavaType(name, oval); @@ -297,8 +333,8 @@ public class JavaEmitter implements GlueEmitter { "\" cannot be assigned to a int, long, float, or double"); } - public void emitDefine(ConstantDefinition def, String optionalComment) throws Exception - { + public void emitDefine(ConstantDefinition def, String optionalComment) throws Exception { + if (cfg.allStatic() || cfg.emitInterface()) { // TODO: Some defines (e.g., GL_DOUBLE_EXT in gl.h) are defined in terms // of other defines -- should we emit them as references to the original @@ -325,8 +361,7 @@ public class JavaEmitter implements GlueEmitter { } } - public void endDefines() throws Exception - { + public void endDefines() throws Exception { } public void beginFunctions(TypeDictionary typedefDictionary, -- cgit v1.2.3