|
From: <eli...@us...> - 2006-12-20 19:19:57
|
Revision: 2697
http://svn.sourceforge.net/java-game-lib/?rev=2697&view=rev
Author: elias_naur
Date: 2006-12-20 11:19:56 -0800 (Wed, 20 Dec 2006)
Log Message:
-----------
Generator: Support arbitrary @AutoResultSize expressions. Make Buffer result sizes long instead of int
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/util/generator/AutoResultSize.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java
Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/AutoResultSize.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/generator/AutoResultSize.java 2006-12-20 17:55:10 UTC (rev 2696)
+++ trunk/LWJGL/src/java/org/lwjgl/util/generator/AutoResultSize.java 2006-12-20 19:19:56 UTC (rev 2697)
@@ -33,8 +33,8 @@
/**
*
- * AutoResultSize specifies that a parameter should determine
- * the size of a Buffer result.
+ * AutoResultSize specifies the size of a returned Buffer
+ * as an expression.
*
* @author elias_naur <eli...@us...>
* @version $Revision$
@@ -44,6 +44,7 @@
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
-@Target(ElementType.PARAMETER)
+@Target(ElementType.METHOD)
public @interface AutoResultSize {
+ String value(); // The size as a java expression
}
Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2006-12-20 17:55:10 UTC (rev 2696)
+++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2006-12-20 19:19:56 UTC (rev 2697)
@@ -123,12 +123,14 @@
if (!first_parameter)
writer.print(", ");
first_parameter = false;
- writer.print("int " + Utils.RESULT_SIZE_NAME);
- if (method.getAnnotation(CachedResult.class) != null) {
+ writer.print("long " + Utils.RESULT_SIZE_NAME);
+ }
+ if (method.getAnnotation(CachedResult.class) != null) {
+ if (!first_parameter)
writer.print(", ");
- printResultType(writer, method);
- writer.print(" " + Utils.CACHED_BUFFER_NAME);
- }
+ first_parameter = false;
+ printResultType(writer, method);
+ writer.print(" " + Utils.CACHED_BUFFER_NAME);
}
return first_parameter;
}
@@ -382,13 +384,13 @@
if (!first_parameter)
writer.print(", ");
first_parameter = false;
- ParameterDeclaration auto_result_size_parameter = Utils.getAutoResultSizeParameter(method);
- String result_size_parameter_name;
- if (auto_result_size_parameter == null)
- result_size_parameter_name = Utils.RESULT_SIZE_NAME;
+ AutoResultSize auto_result_size_annotation = method.getAnnotation(AutoResultSize.class);
+ String result_size_expression;
+ if (auto_result_size_annotation == null)
+ result_size_expression = Utils.RESULT_SIZE_NAME;
else
- result_size_parameter_name = auto_result_size_parameter.getSimpleName();
- Utils.printExtraCallArguments(writer, method, result_size_parameter_name);
+ result_size_expression = auto_result_size_annotation.value();
+ Utils.printExtraCallArguments(writer, method, result_size_expression);
}
return first_parameter;
}
Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java 2006-12-20 17:55:10 UTC (rev 2696)
+++ trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java 2006-12-20 19:19:56 UTC (rev 2697)
@@ -95,7 +95,7 @@
writer.print("(JNIEnv *env, jclass clazz");
generateParameters(writer, method.getParameters(), mode);
if (Utils.getNIOBufferType(result_type) != null) {
- writer.print(", jint " + Utils.RESULT_SIZE_NAME);
+ writer.print(", jlong " + Utils.RESULT_SIZE_NAME);
if (method.getAnnotation(CachedResult.class) != null)
writer.print(", jobject " + Utils.CACHED_BUFFER_NAME);
}
Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java 2006-12-20 17:55:10 UTC (rev 2696)
+++ trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java 2006-12-20 19:19:56 UTC (rev 2697)
@@ -144,17 +144,6 @@
}
}
- public static ParameterDeclaration getAutoResultSizeParameter(MethodDeclaration method) {
- ParameterDeclaration result = null;
- for (ParameterDeclaration param : method.getParameters())
- if (param.getAnnotation(AutoResultSize.class) != null) {
- if (result != null)
- throw new RuntimeException(method + " contains multiple AutoResultSize annotations");
- result = param;
- }
- return result;
- }
-
public static AnnotationMirror getParameterAutoAnnotation(ParameterDeclaration param) {
for (AnnotationMirror annotation : param.getAnnotationMirrors())
if (NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null)
@@ -210,7 +199,7 @@
}
public static boolean needResultSize(MethodDeclaration method) {
- return getNIOBufferType(getMethodReturnType(method)) != null && getAutoResultSizeParameter(method) == null;
+ return getNIOBufferType(getMethodReturnType(method)) != null && method.getAnnotation(AutoResultSize.class) == null;
}
public static void printExtraCallArguments(PrintWriter writer, MethodDeclaration method, String size_parameter_name) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|