Automatic code reformatting.

Nothing to see here, just a cleanup so that subsequent commits are cleaner.
This commit is contained in:
Ioannis Tsakpinis 2014-09-14 17:16:51 +03:00
parent 774bd17ece
commit 59323ff03f
28 changed files with 3122 additions and 3176 deletions

View File

@ -43,85 +43,85 @@ import javax.lang.model.type.TypeMirror;
public class FieldsGenerator { public class FieldsGenerator {
private static void validateField(VariableElement field) { private static void validateField(VariableElement field) {
// Check if field is "public static final" // Check if field is "public static final"
Set<Modifier> modifiers = field.getModifiers(); Set<Modifier> modifiers = field.getModifiers();
if (modifiers.size() != 3 if ( modifiers.size() != 3
|| !modifiers.contains(Modifier.PUBLIC) || !modifiers.contains(Modifier.PUBLIC)
|| !modifiers.contains(Modifier.STATIC) || !modifiers.contains(Modifier.STATIC)
|| !modifiers.contains(Modifier.FINAL)) { || !modifiers.contains(Modifier.FINAL) ) {
throw new RuntimeException("Field " + field.getSimpleName() + " is not declared public static final"); throw new RuntimeException("Field " + field.getSimpleName() + " is not declared public static final");
} }
// Check suported types (int, long, float, String) // Check suported types (int, long, float, String)
TypeMirror field_type = field.asType(); TypeMirror field_type = field.asType();
if ("java.lang.String".equals(field_type.toString())) { if ( "java.lang.String".equals(field_type.toString()) ) {
} else if (field_type instanceof PrimitiveType) { } else if ( field_type instanceof PrimitiveType ) {
PrimitiveType field_type_prim = (PrimitiveType) field_type; PrimitiveType field_type_prim = (PrimitiveType)field_type;
TypeKind field_kind = field_type_prim.getKind(); TypeKind field_kind = field_type_prim.getKind();
if (field_kind != TypeKind.INT if ( field_kind != TypeKind.INT
&& field_kind != TypeKind.LONG && field_kind != TypeKind.LONG
&& field_kind != TypeKind.FLOAT && field_kind != TypeKind.FLOAT
&& field_kind != TypeKind.BYTE) { && field_kind != TypeKind.BYTE ) {
throw new RuntimeException("Field " + field.getSimpleName() + " is not of type 'int', 'long', 'float' or 'byte' " + field_kind.toString()); throw new RuntimeException("Field " + field.getSimpleName() + " is not of type 'int', 'long', 'float' or 'byte' " + field_kind.toString());
} }
} else { } else {
throw new RuntimeException("Field " + field.getSimpleName() + " is not a primitive type or String"); throw new RuntimeException("Field " + field.getSimpleName() + " is not a primitive type or String");
} }
Object field_value = field.getConstantValue(); Object field_value = field.getConstantValue();
if (field_value == null) { if ( field_value == null ) {
throw new RuntimeException("Field " + field.getSimpleName() + " has no initial value"); throw new RuntimeException("Field " + field.getSimpleName() + " has no initial value");
} }
} }
private static void generateField(PrintWriter writer, VariableElement field, VariableElement prev_field, ProcessingEnvironment env) { private static void generateField(PrintWriter writer, VariableElement field, VariableElement prev_field, ProcessingEnvironment env) {
validateField(field); validateField(field);
Object value = field.getConstantValue(); Object value = field.getConstantValue();
String field_value_string; String field_value_string;
Class field_value_class = value.getClass(); Class field_value_class = value.getClass();
if (field_value_class.equals(Integer.class)) { if ( field_value_class.equals(Integer.class) ) {
field_value_string = "0x" + Integer.toHexString((Integer) field.getConstantValue()).toUpperCase(); field_value_string = "0x" + Integer.toHexString((Integer)field.getConstantValue()).toUpperCase();
} else if (field_value_class.equals(Long.class)) { } else if ( field_value_class.equals(Long.class) ) {
field_value_string = "0x" + Long.toHexString((Long) field.getConstantValue()).toUpperCase() + 'L'; field_value_string = "0x" + Long.toHexString((Long)field.getConstantValue()).toUpperCase() + 'L';
} else if (field_value_class.equals(Float.class)) { } else if ( field_value_class.equals(Float.class) ) {
field_value_string = field.getConstantValue() + "f"; field_value_string = field.getConstantValue() + "f";
} else if (value.getClass().equals(Byte.class)) { } else if ( value.getClass().equals(Byte.class) ) {
field_value_string = "0x" + Integer.toHexString((Byte) field.getConstantValue()).toUpperCase(); field_value_string = "0x" + Integer.toHexString((Byte)field.getConstantValue()).toUpperCase();
} else if (field_value_class.equals(String.class)) { } else if ( field_value_class.equals(String.class) ) {
field_value_string = "\"" + field.getConstantValue() + "\""; field_value_string = "\"" + field.getConstantValue() + "\"";
} else { } else {
throw new RuntimeException("Field is of unexpected type. This means there is a bug in validateField()."); throw new RuntimeException("Field is of unexpected type. This means there is a bug in validateField().");
} }
boolean hadDoc = prev_field != null && env.getElementUtils().getDocComment(prev_field) != null; boolean hadDoc = prev_field != null && env.getElementUtils().getDocComment(prev_field) != null;
boolean hasDoc = env.getElementUtils().getDocComment(field) != null; boolean hasDoc = env.getElementUtils().getDocComment(field) != null;
boolean newBatch = prev_field == null || !prev_field.asType().equals(field.asType()) || (!hadDoc && env.getElementUtils().getDocComment(field) != null) || (hadDoc && hasDoc && !env.getElementUtils().getDocComment(prev_field).equals(env.getElementUtils().getDocComment(field))); boolean newBatch = prev_field == null || !prev_field.asType().equals(field.asType()) || (!hadDoc && env.getElementUtils().getDocComment(field) != null) || (hadDoc && hasDoc && !env.getElementUtils().getDocComment(prev_field).equals(env.getElementUtils().getDocComment(field)));
// Print field declaration // Print field declaration
if (newBatch) { if ( newBatch ) {
if (prev_field != null) { if ( prev_field != null ) {
writer.println(";\n"); writer.println(";\n");
} }
Utils.printDocComment(writer, field, env); Utils.printDocComment(writer, field, env);
writer.print("\tpublic static final " + field.asType().toString() + " " + field.getSimpleName() + " = " + field_value_string); writer.print("\tpublic static final " + field.asType().toString() + " " + field.getSimpleName() + " = " + field_value_string);
} else { } else {
writer.print(",\n\t\t" + field.getSimpleName() + " = " + field_value_string); writer.print(",\n\t\t" + field.getSimpleName() + " = " + field_value_string);
} }
} }
public static void generateFields(ProcessingEnvironment env, PrintWriter writer, Collection<? extends VariableElement> fields) { public static void generateFields(ProcessingEnvironment env, PrintWriter writer, Collection<? extends VariableElement> fields) {
if (0 < fields.size()) { if ( 0 < fields.size() ) {
writer.println(); writer.println();
VariableElement prev_field = null; VariableElement prev_field = null;
for (VariableElement field : fields) { for ( VariableElement field : fields ) {
generateField(writer, field, prev_field, env); generateField(writer, field, prev_field, env);
prev_field = field; prev_field = field;
} }
writer.println(";"); writer.println(";");
} }
} }
} }

View File

@ -36,11 +36,7 @@ import java.io.FileFilter;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.*;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
@ -54,92 +50,92 @@ import javax.tools.Diagnostic;
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$ * @version $Revision$ $Id$
*/ */
@SupportedAnnotationTypes({"*"}) @SupportedAnnotationTypes({ "*" })
@SupportedSourceVersion(SourceVersion.RELEASE_7) @SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedOptions({"binpath", "typemap", "generatechecks", "contextspecific"}) @SupportedOptions({ "binpath", "typemap", "generatechecks", "contextspecific" })
public class GeneratorProcessor extends AbstractProcessor { public class GeneratorProcessor extends AbstractProcessor {
private static boolean first_round = true; private static boolean first_round = true;
@Override @Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || !first_round) { if ( roundEnv.processingOver() || !first_round ) {
System.exit(0); System.exit(0);
return true; return true;
} }
Map<String, String> options = processingEnv.getOptions(); Map<String, String> options = processingEnv.getOptions();
String typemap_classname = options.get("typemap"); String typemap_classname = options.get("typemap");
String bin_path = options.get("binpath"); String bin_path = options.get("binpath");
boolean generate_error_checks = options.containsKey("generatechecks"); boolean generate_error_checks = options.containsKey("generatechecks");
boolean context_specific = options.containsKey("contextspecific"); boolean context_specific = options.containsKey("contextspecific");
if (bin_path == null) { if ( bin_path == null ) {
throw new RuntimeException("No path specified for the bin directory with -Abinpath=<path>"); throw new RuntimeException("No path specified for the bin directory with -Abinpath=<path>");
} }
if (typemap_classname == null) { if ( typemap_classname == null ) {
throw new RuntimeException("No TypeMap class name specified with -Atypemap=<class-name>"); throw new RuntimeException("No TypeMap class name specified with -Atypemap=<class-name>");
} }
Element lastFile = null; Element lastFile = null;
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "annotations " + annotations.toString()); processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "annotations " + annotations.toString());
try { try {
long generatorLM = getGeneratorLastModified(bin_path); long generatorLM = getGeneratorLastModified(bin_path);
TypeMap type_map = (TypeMap) (Class.forName(typemap_classname).newInstance()); TypeMap type_map = (TypeMap)(Class.forName(typemap_classname).newInstance());
for (Iterator<TypeElement> it = ElementFilter.typesIn(roundEnv.getRootElements()).iterator(); it.hasNext();) { for ( Iterator<TypeElement> it = ElementFilter.typesIn(roundEnv.getRootElements()).iterator(); it.hasNext(); ) {
lastFile = it.next(); lastFile = it.next();
lastFile.accept(new GeneratorVisitor(processingEnv, type_map, generate_error_checks, context_specific, generatorLM), null); lastFile.accept(new GeneratorVisitor(processingEnv, type_map, generate_error_checks, context_specific, generatorLM), null);
} }
first_round = false; first_round = false;
return true; return true;
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
if (lastFile == null) { if ( lastFile == null ) {
throw new RuntimeException(e); throw new RuntimeException(e);
} else { } else {
throw new RuntimeException("\n-- Failed to process template: " + lastFile.asType().toString() + " --", e); throw new RuntimeException("\n-- Failed to process template: " + lastFile.asType().toString() + " --", e);
} }
} }
} }
/** /**
* Gets the time of the latest change on the Generator classes. * Gets the time of the latest change on the Generator classes.
* *
* @return time of the latest change * @return time of the latest change
*/ */
private static long getGeneratorLastModified(final String bin_path) { private static long getGeneratorLastModified(final String bin_path) {
long lastModified = getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator"); long lastModified = getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator");
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/openal")); lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/openal"));
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/opengl")); lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/opengl"));
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/opencl")); lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/opencl"));
return lastModified; return lastModified;
} }
private static long getDirectoryLastModified(final String bin_path, final String path) { private static long getDirectoryLastModified(final String bin_path, final String path) {
final File pck = new File(bin_path + path); final File pck = new File(bin_path + path);
if (!pck.exists() || !pck.isDirectory()) { if ( !pck.exists() || !pck.isDirectory() ) {
return Long.MAX_VALUE; return Long.MAX_VALUE;
} }
final File[] classes = pck.listFiles(new FileFilter() { final File[] classes = pck.listFiles(new FileFilter() {
public boolean accept(final File pathname) { public boolean accept(final File pathname) {
return pathname.isFile() && pathname.getName().endsWith(".class"); return pathname.isFile() && pathname.getName().endsWith(".class");
} }
}); });
if (classes == null || classes.length == 0) { if ( classes == null || classes.length == 0 ) {
return Long.MAX_VALUE; return Long.MAX_VALUE;
} }
long lastModified = 0; long lastModified = 0;
for (File clazz : classes) { for ( File clazz : classes ) {
long lm = clazz.lastModified(); long lm = clazz.lastModified();
if (lastModified < lm) { if ( lastModified < lm ) {
lastModified = lm; lastModified = lm;
} }
} }
return lastModified; return lastModified;
} }
} }

View File

@ -31,19 +31,18 @@
*/ */
package org.lwjgl.util.generator; package org.lwjgl.util.generator;
import java.io.*; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.nio.Buffer;
import java.nio.*; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.*; import java.util.Collection;
import java.util.List;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.*;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementKindVisitor7; import javax.lang.model.util.ElementKindVisitor7;
@ -53,7 +52,6 @@ import javax.tools.FileObject;
import javax.tools.StandardLocation; import javax.tools.StandardLocation;
/** /**
*
* Generator visitor for the generator tool * Generator visitor for the generator tool
* *
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
@ -61,335 +59,335 @@ import javax.tools.StandardLocation;
*/ */
public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> { public class GeneratorVisitor extends ElementKindVisitor7<Void, Void> {
private final ProcessingEnvironment env; private final ProcessingEnvironment env;
private final TypeMap type_map; private final TypeMap type_map;
private final boolean generate_error_checks; private final boolean generate_error_checks;
private final boolean context_specific; private final boolean context_specific;
private final long generatorLM; private final long generatorLM;
public GeneratorVisitor(ProcessingEnvironment env, TypeMap type_map, boolean generate_error_checks, boolean context_specific, long generatorLM) { public GeneratorVisitor(ProcessingEnvironment env, TypeMap type_map, boolean generate_error_checks, boolean context_specific, long generatorLM) {
this.env = env; this.env = env;
this.type_map = type_map; this.type_map = type_map;
this.generate_error_checks = generate_error_checks; this.generate_error_checks = generate_error_checks;
this.context_specific = context_specific; this.context_specific = context_specific;
this.generatorLM = generatorLM; this.generatorLM = generatorLM;
} }
private void validateMethod(ExecutableElement method) { private void validateMethod(ExecutableElement method) {
if (method.isVarArgs()) { if ( method.isVarArgs() ) {
throw new RuntimeException("Method " + method.getSimpleName() + " is variadic"); throw new RuntimeException("Method " + method.getSimpleName() + " is variadic");
} }
Collection<Modifier> modifiers = method.getModifiers(); Collection<Modifier> modifiers = method.getModifiers();
if (!modifiers.contains(Modifier.PUBLIC)) { if ( !modifiers.contains(Modifier.PUBLIC) ) {
throw new RuntimeException("Method " + method.getSimpleName() + " is not public"); throw new RuntimeException("Method " + method.getSimpleName() + " is not public");
} }
if (method.getThrownTypes().size() > 0) { if ( method.getThrownTypes().size() > 0 ) {
throw new RuntimeException("Method " + method.getSimpleName() + " throws checked exceptions"); throw new RuntimeException("Method " + method.getSimpleName() + " throws checked exceptions");
} }
validateParameters(method); validateParameters(method);
StripPostfix strip_annotation = method.getAnnotation(StripPostfix.class); StripPostfix strip_annotation = method.getAnnotation(StripPostfix.class);
if (strip_annotation != null && method.getAnnotation(Alternate.class) == null) { if ( strip_annotation != null && method.getAnnotation(Alternate.class) == null ) {
String postfix_param_name = strip_annotation.value(); String postfix_param_name = strip_annotation.value();
VariableElement postfix_param = Utils.findParameter(method, postfix_param_name); VariableElement postfix_param = Utils.findParameter(method, postfix_param_name);
if (Utils.isParameterMultiTyped(postfix_param)) { if ( Utils.isParameterMultiTyped(postfix_param) ) {
throw new RuntimeException("Postfix parameter can't be the same as a multityped parameter in method " + method); throw new RuntimeException("Postfix parameter can't be the same as a multityped parameter in method " + method);
} }
if (Utils.getNIOBufferType(postfix_param.asType()) == null) { if ( Utils.getNIOBufferType(postfix_param.asType()) == null ) {
throw new RuntimeException("Postfix parameter type must be a nio Buffer"); throw new RuntimeException("Postfix parameter type must be a nio Buffer");
} }
} }
if (Utils.getResultParameter(method) != null && !method.getReturnType().equals(env.getTypeUtils().getNoType(TypeKind.VOID))) { if ( Utils.getResultParameter(method) != null && !method.getReturnType().equals(env.getTypeUtils().getNoType(TypeKind.VOID)) ) {
throw new RuntimeException(method + " return type is not void but a parameter is annotated with Result"); throw new RuntimeException(method + " return type is not void but a parameter is annotated with Result");
} }
if (method.getAnnotation(CachedResult.class) != null) { if ( method.getAnnotation(CachedResult.class) != null ) {
if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) == null) { if ( Utils.getNIOBufferType(Utils.getMethodReturnType(method)) == null ) {
throw new RuntimeException(method + " return type is not a Buffer, but is annotated with CachedResult"); throw new RuntimeException(method + " return type is not a Buffer, but is annotated with CachedResult");
} }
if (method.getAnnotation(AutoSize.class) == null) { if ( method.getAnnotation(AutoSize.class) == null ) {
throw new RuntimeException(method + " is annotated with CachedResult but misses an AutoSize annotation"); throw new RuntimeException(method + " is annotated with CachedResult but misses an AutoSize annotation");
} }
} }
validateTypes(method, method.getAnnotationMirrors(), method.getReturnType()); validateTypes(method, method.getAnnotationMirrors(), method.getReturnType());
} }
private void validateType(ExecutableElement method, Class<? extends Annotation> annotation_type, Class type) { private void validateType(ExecutableElement method, Class<? extends Annotation> annotation_type, Class type) {
Class[] valid_types = type_map.getValidAnnotationTypes(type); Class[] valid_types = type_map.getValidAnnotationTypes(type);
for (Class valid_type : valid_types) { for ( Class valid_type : valid_types ) {
if (valid_type.equals(annotation_type)) { if ( valid_type.equals(annotation_type) ) {
return; return;
} }
} }
throw new RuntimeException(type + " is annotated with invalid native type " + annotation_type throw new RuntimeException(type + " is annotated with invalid native type " + annotation_type
+ " in method " + method); + " in method " + method);
} }
private void validateTypes(ExecutableElement method, List<? extends AnnotationMirror> annotations, TypeMirror type_mirror) { private void validateTypes(ExecutableElement method, List<? extends AnnotationMirror> annotations, TypeMirror type_mirror) {
for (AnnotationMirror annotation : annotations) { for ( AnnotationMirror annotation : annotations ) {
NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class); NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
if (native_type_annotation != null) { if ( native_type_annotation != null ) {
Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType()); Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
Class type = Utils.getJavaType(type_mirror); Class type = Utils.getJavaType(type_mirror);
if (Buffer.class.equals(type)) { if ( Buffer.class.equals(type) ) {
continue; continue;
} }
validateType(method, annotation_type, type); validateType(method, annotation_type, type);
} }
} }
} }
private void validateParameters(ExecutableElement method) { private void validateParameters(ExecutableElement method) {
for (VariableElement param : method.getParameters()) { for ( VariableElement param : method.getParameters() ) {
validateTypes(method, param.getAnnotationMirrors(), param.asType()); validateTypes(method, param.getAnnotationMirrors(), param.asType());
Class<?> param_type = Utils.getJavaType(param.asType()); Class<?> param_type = Utils.getJavaType(param.asType());
if (Utils.getNIOBufferType(param.asType()) != null && param_type != CharSequence.class && param_type != CharSequence[].class) { if ( Utils.getNIOBufferType(param.asType()) != null && param_type != CharSequence.class && param_type != CharSequence[].class ) {
Check parameter_check_annotation = param.getAnnotation(Check.class); Check parameter_check_annotation = param.getAnnotation(Check.class);
NullTerminated null_terminated_annotation = param.getAnnotation(NullTerminated.class); NullTerminated null_terminated_annotation = param.getAnnotation(NullTerminated.class);
if (parameter_check_annotation == null && null_terminated_annotation == null) { if ( parameter_check_annotation == null && null_terminated_annotation == null ) {
boolean found_auto_size_param = false; boolean found_auto_size_param = false;
for (VariableElement inner_param : method.getParameters()) { for ( VariableElement inner_param : method.getParameters() ) {
AutoSize auto_size_annotation = inner_param.getAnnotation(AutoSize.class); AutoSize auto_size_annotation = inner_param.getAnnotation(AutoSize.class);
if (auto_size_annotation != null if ( auto_size_annotation != null
&& auto_size_annotation.value().equals(param.getSimpleName().toString())) { && auto_size_annotation.value().equals(param.getSimpleName().toString()) ) {
found_auto_size_param = true; found_auto_size_param = true;
break; break;
} }
} }
if (!found_auto_size_param if ( !found_auto_size_param
&& param.getAnnotation(Result.class) == null && param.getAnnotation(Result.class) == null
&& param.getAnnotation(Constant.class) == null && param.getAnnotation(Constant.class) == null
&& !Utils.isReturnParameter(method, param)) { && !Utils.isReturnParameter(method, param) ) {
throw new RuntimeException(param + " has no Check, Result nor Constant annotation, is not the return parameter and no other parameter has" throw new RuntimeException(param + " has no Check, Result nor Constant annotation, is not the return parameter and no other parameter has"
+ " an @AutoSize annotation on it in method " + method); + " an @AutoSize annotation on it in method " + method);
} }
} }
if (param.getAnnotation(CachedReference.class) != null && param.getAnnotation(Result.class) != null) { if ( param.getAnnotation(CachedReference.class) != null && param.getAnnotation(Result.class) != null ) {
throw new RuntimeException(param + " can't be annotated with both CachedReference and Result"); throw new RuntimeException(param + " can't be annotated with both CachedReference and Result");
} }
if (param.getAnnotation(BufferObject.class) != null && param.getAnnotation(Result.class) != null) { if ( param.getAnnotation(BufferObject.class) != null && param.getAnnotation(Result.class) != null ) {
throw new RuntimeException(param + " can't be annotated with both BufferObject and Result"); throw new RuntimeException(param + " can't be annotated with both BufferObject and Result");
} }
//if (param.getAnnotation(Constant.class) != null) //if (param.getAnnotation(Constant.class) != null)
//throw new RuntimeException("Buffer parameter " + param + " cannot be Constant"); //throw new RuntimeException("Buffer parameter " + param + " cannot be Constant");
} else { } else {
if (param.getAnnotation(BufferObject.class) != null) { if ( param.getAnnotation(BufferObject.class) != null ) {
throw new RuntimeException(param + " type is not a buffer, but annotated as a BufferObject"); throw new RuntimeException(param + " type is not a buffer, but annotated as a BufferObject");
} }
if (param.getAnnotation(CachedReference.class) != null) { if ( param.getAnnotation(CachedReference.class) != null ) {
throw new RuntimeException(param + " type is not a buffer, but annotated as a CachedReference"); throw new RuntimeException(param + " type is not a buffer, but annotated as a CachedReference");
} }
} }
} }
} }
private static void generateMethodsNativePointers(PrintWriter writer, Collection<? extends ExecutableElement> methods) { private static void generateMethodsNativePointers(PrintWriter writer, Collection<? extends ExecutableElement> methods) {
for (ExecutableElement method : methods) { for ( ExecutableElement method : methods ) {
if (method.getAnnotation(Alternate.class) == null) { if ( method.getAnnotation(Alternate.class) == null ) {
generateMethodNativePointers(writer, method); generateMethodNativePointers(writer, method);
} }
} }
} }
private static void generateMethodNativePointers(PrintWriter writer, ExecutableElement method) { private static void generateMethodNativePointers(PrintWriter writer, ExecutableElement method) {
if (method.getAnnotation(Extern.class) == null) { if ( method.getAnnotation(Extern.class) == null ) {
writer.print("static "); writer.print("static ");
} }
writer.println(Utils.getTypedefName(method) + " " + method.getSimpleName() + ";"); writer.println(Utils.getTypedefName(method) + " " + method.getSimpleName() + ";");
} }
private void generateJavaSource(TypeElement d, PrintWriter java_writer) throws IOException { private void generateJavaSource(TypeElement d, PrintWriter java_writer) throws IOException {
java_writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */"); java_writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
java_writer.println(); java_writer.println();
java_writer.println("package " + env.getElementUtils().getPackageOf(d).getQualifiedName().toString() + ";"); java_writer.println("package " + env.getElementUtils().getPackageOf(d).getQualifiedName().toString() + ";");
java_writer.println(); java_writer.println();
java_writer.println("import org.lwjgl.*;"); java_writer.println("import org.lwjgl.*;");
java_writer.println("import java.nio.*;"); java_writer.println("import java.nio.*;");
Imports imports = d.getAnnotation(Imports.class); Imports imports = d.getAnnotation(Imports.class);
if (imports != null) { if ( imports != null ) {
for (String i : imports.value()) { for ( String i : imports.value() ) {
java_writer.println("import " + i + ";"); java_writer.println("import " + i + ";");
} }
} }
java_writer.println(); java_writer.println();
Utils.printDocComment(java_writer, d, env); Utils.printDocComment(java_writer, d, env);
if (d.getAnnotation(Private.class) == null) { if ( d.getAnnotation(Private.class) == null ) {
java_writer.print("public "); java_writer.print("public ");
} }
boolean is_final = Utils.isFinal(d); boolean is_final = Utils.isFinal(d);
if (is_final) { if ( is_final ) {
java_writer.write("final "); java_writer.write("final ");
} }
java_writer.print("class " + Utils.getSimpleClassName(d)); java_writer.print("class " + Utils.getSimpleClassName(d));
List<? extends TypeMirror> super_interfaces = d.getInterfaces(); List<? extends TypeMirror> super_interfaces = d.getInterfaces();
if (super_interfaces.size() > 1) { if ( super_interfaces.size() > 1 ) {
throw new RuntimeException(d + " extends more than one interface"); throw new RuntimeException(d + " extends more than one interface");
} }
if (super_interfaces.size() == 1) { if ( super_interfaces.size() == 1 ) {
TypeMirror super_interface = super_interfaces.iterator().next(); TypeMirror super_interface = super_interfaces.iterator().next();
java_writer.print(" extends " + Utils.getSimpleClassName(env.getElementUtils().getTypeElement(super_interface.toString()))); java_writer.print(" extends " + Utils.getSimpleClassName(env.getElementUtils().getTypeElement(super_interface.toString())));
} }
java_writer.println(" {"); java_writer.println(" {");
FieldsGenerator.generateFields(env, java_writer, Utils.getFields(d)); FieldsGenerator.generateFields(env, java_writer, Utils.getFields(d));
java_writer.println(); java_writer.println();
if (is_final) { if ( is_final ) {
// Write private constructor to avoid instantiation // Write private constructor to avoid instantiation
java_writer.println("\tprivate " + Utils.getSimpleClassName(d) + "() {}"); java_writer.println("\tprivate " + Utils.getSimpleClassName(d) + "() {}");
} }
if (Utils.getMethods(d).size() > 0 && !context_specific) { if ( Utils.getMethods(d).size() > 0 && !context_specific ) {
java_writer.println(); java_writer.println();
java_writer.println("\tstatic native void " + Utils.STUB_INITIALIZER_NAME + "() throws LWJGLException;"); java_writer.println("\tstatic native void " + Utils.STUB_INITIALIZER_NAME + "() throws LWJGLException;");
} }
JavaMethodsGenerator.generateMethodsJava(env, type_map, java_writer, d, generate_error_checks, context_specific); JavaMethodsGenerator.generateMethodsJava(env, type_map, java_writer, d, generate_error_checks, context_specific);
java_writer.println("}"); java_writer.println("}");
java_writer.close(); java_writer.close();
String qualified_interface_name = Utils.getQualifiedClassName(d); String qualified_interface_name = Utils.getQualifiedClassName(d);
env.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generated class " + qualified_interface_name); env.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generated class " + qualified_interface_name);
} }
private void generateNativeSource(TypeElement d) throws IOException { private void generateNativeSource(TypeElement d) throws IOException {
if (d.getKind().equals(ElementKind.ANNOTATION_TYPE)) { if ( d.getKind().equals(ElementKind.ANNOTATION_TYPE) ) {
return; return;
} }
String qualified_interface_name = Utils.getQualifiedClassName(d); String qualified_interface_name = Utils.getQualifiedClassName(d);
String qualified_native_name = Utils.getNativeQualifiedName(qualified_interface_name) + ".c"; String qualified_native_name = Utils.getNativeQualifiedName(qualified_interface_name) + ".c";
PrintWriter native_writer = new PrintWriter(env.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", qualified_native_name).openWriter()); PrintWriter native_writer = new PrintWriter(env.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", qualified_native_name).openWriter());
native_writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */"); native_writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
native_writer.println(); native_writer.println();
native_writer.println("#include <jni.h>"); native_writer.println("#include <jni.h>");
type_map.printNativeIncludes(native_writer); type_map.printNativeIncludes(native_writer);
native_writer.println(); native_writer.println();
TypedefsGenerator.generateNativeTypedefs(type_map, native_writer, Utils.getMethods(d)); TypedefsGenerator.generateNativeTypedefs(type_map, native_writer, Utils.getMethods(d));
native_writer.println(); native_writer.println();
if (!context_specific) { if ( !context_specific ) {
generateMethodsNativePointers(native_writer, Utils.getMethods(d)); generateMethodsNativePointers(native_writer, Utils.getMethods(d));
native_writer.println(); native_writer.println();
} }
NativeMethodStubsGenerator.generateNativeMethodStubs(env, type_map, native_writer, d, generate_error_checks, context_specific); NativeMethodStubsGenerator.generateNativeMethodStubs(env, type_map, native_writer, d, generate_error_checks, context_specific);
if (!context_specific) { if ( !context_specific ) {
native_writer.print("JNIEXPORT void JNICALL " + Utils.getQualifiedNativeMethodName(qualified_interface_name, Utils.STUB_INITIALIZER_NAME)); native_writer.print("JNIEXPORT void JNICALL " + Utils.getQualifiedNativeMethodName(qualified_interface_name, Utils.STUB_INITIALIZER_NAME));
native_writer.println("(JNIEnv *env, jclass clazz) {"); native_writer.println("(JNIEnv *env, jclass clazz) {");
native_writer.println("\tJavaMethodAndExtFunction functions[] = {"); native_writer.println("\tJavaMethodAndExtFunction functions[] = {");
RegisterStubsGenerator.generateMethodsNativeStubBind(env, native_writer, d, generate_error_checks, context_specific); RegisterStubsGenerator.generateMethodsNativeStubBind(env, native_writer, d, generate_error_checks, context_specific);
native_writer.println("\t};"); native_writer.println("\t};");
native_writer.println("\tint num_functions = NUMFUNCTIONS(functions);"); native_writer.println("\tint num_functions = NUMFUNCTIONS(functions);");
native_writer.print("\t"); native_writer.print("\t");
native_writer.print(type_map.getRegisterNativesFunctionName()); native_writer.print(type_map.getRegisterNativesFunctionName());
native_writer.println("(env, clazz, num_functions, functions);"); native_writer.println("(env, clazz, num_functions, functions);");
native_writer.println("}"); native_writer.println("}");
} }
native_writer.close(); native_writer.close();
env.getMessager().printMessage(Kind.NOTE, "Generated C source " + qualified_interface_name); env.getMessager().printMessage(Kind.NOTE, "Generated C source " + qualified_interface_name);
} }
@Override @Override
public Void visitTypeAsInterface(TypeElement e, Void p) { public Void visitTypeAsInterface(TypeElement e, Void p) {
PrintWriter java_writer = null; PrintWriter java_writer = null;
try { try {
final Collection<? extends ExecutableElement> methods = Utils.getMethods(e); final Collection<? extends ExecutableElement> methods = Utils.getMethods(e);
if (methods.isEmpty() && Utils.getFields(e).isEmpty()) { if ( methods.isEmpty() && Utils.getFields(e).isEmpty() ) {
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
env.getMessager().printMessage(Kind.NOTE, "methods count : " + Utils.getMethods(e).size() + " fields count : " + Utils.getFields(e).size(), e); env.getMessager().printMessage(Kind.NOTE, "methods count : " + Utils.getMethods(e).size() + " fields count : " + Utils.getFields(e).size(), e);
for (final ExecutableElement method : methods) { for ( final ExecutableElement method : methods ) {
validateMethod(method); validateMethod(method);
} }
java_writer = new PrintWriter(env.getFiler().createSourceFile(Utils.getQualifiedClassName(e), env.getElementUtils().getPackageOf(e)).openWriter()); java_writer = new PrintWriter(env.getFiler().createSourceFile(Utils.getQualifiedClassName(e), env.getElementUtils().getPackageOf(e)).openWriter());
generateJavaSource(e, java_writer); generateJavaSource(e, java_writer);
if (methods.size() > 0) { if ( methods.size() > 0 ) {
boolean noNative = true; boolean noNative = true;
for (final ExecutableElement method : methods) { for ( final ExecutableElement method : methods ) {
Alternate alt_annotation = method.getAnnotation(Alternate.class); Alternate alt_annotation = method.getAnnotation(Alternate.class);
if ((alt_annotation == null || alt_annotation.nativeAlt()) && method.getAnnotation(Reuse.class) == null) { if ( (alt_annotation == null || alt_annotation.nativeAlt()) && method.getAnnotation(Reuse.class) == null ) {
noNative = false; noNative = false;
break; break;
} }
} }
if (noNative) { if ( noNative ) {
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
boolean outputNativeExists = true, outputBackupExists = true; boolean outputNativeExists = true, outputBackupExists = true;
File outputNative = null, outputBackup = null; File outputNative = null, outputBackup = null;
try { try {
final FileObject fo_outputNative = env.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", Utils.getNativeQualifiedName(Utils.getQualifiedClassName(e)).replace(".", "/") + ".c"); final FileObject fo_outputNative = env.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", Utils.getNativeQualifiedName(Utils.getQualifiedClassName(e)).replace(".", "/") + ".c");
outputNative = new File(fo_outputNative.toUri()); outputNative = new File(fo_outputNative.toUri());
outputNativeExists = outputNative.exists(); outputNativeExists = outputNative.exists();
final FileObject fo_outputBackup = env.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", Utils.getNativeQualifiedName(Utils.getQualifiedClassName(e)).replace(".", "/") + "_backup.c"); final FileObject fo_outputBackup = env.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", Utils.getNativeQualifiedName(Utils.getQualifiedClassName(e)).replace(".", "/") + "_backup.c");
outputBackup = new File(fo_outputBackup.toUri()); outputBackup = new File(fo_outputBackup.toUri());
outputBackupExists = outputBackup.exists(); outputBackupExists = outputBackup.exists();
} catch (IOException ex) { } catch (IOException ex) {
if (outputNative == null) { if ( outputNative == null ) {
outputNativeExists = false; outputNativeExists = false;
} }
if (outputBackup == null) { if ( outputBackup == null ) {
outputBackupExists = false; outputBackupExists = false;
} }
} finally { } finally {
// If the native file exists, rename. // If the native file exists, rename.
final ByteBuffer nativeBefore; final ByteBuffer nativeBefore;
if (outputNativeExists) { if ( outputNativeExists ) {
nativeBefore = readFile(outputNative); nativeBefore = readFile(outputNative);
if (outputBackupExists) { if ( outputBackupExists ) {
outputBackup.delete(); outputBackup.delete();
} }
outputNative.renameTo(outputBackup); outputNative.renameTo(outputBackup);
} else { } else {
nativeBefore = null; nativeBefore = null;
} }
try { try {
generateNativeSource(e); generateNativeSource(e);
// If the native file did exist, compare with the new file. If they're the same, // If the native file did exist, compare with the new file. If they're the same,
// reset the last modified time to avoid ridiculous C compilation times. // reset the last modified time to avoid ridiculous C compilation times.
if (nativeBefore != null && outputNative.length() == nativeBefore.capacity()) { if ( nativeBefore != null && outputNative.length() == nativeBefore.capacity() ) {
final ByteBuffer nativeAfter = readFile(outputNative); final ByteBuffer nativeAfter = readFile(outputNative);
boolean same = true; boolean same = true;
for (int i = nativeBefore.position(); i < nativeBefore.limit(); i++) { for ( int i = nativeBefore.position(); i < nativeBefore.limit(); i++ ) {
if (nativeBefore.get(i) != nativeAfter.get(i)) { if ( nativeBefore.get(i) != nativeAfter.get(i) ) {
same = false; same = false;
break; break;
} }
} }
if (same) { if ( same ) {
outputNative.delete(); outputNative.delete();
outputBackup.renameTo(outputNative); outputBackup.renameTo(outputNative);
} }
} }
} catch (IOException ex) { } catch (IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} finally { } finally {
if (outputBackup.exists()) { if ( outputBackup.exists() ) {
outputBackup.delete(); outputBackup.delete();
} }
} }
} }
} }
return DEFAULT_VALUE; return DEFAULT_VALUE;
} catch (Exception ex) { } catch (Exception ex) {
// If anything goes wrong mid-gen, delete output to allow regen next time we run. // If anything goes wrong mid-gen, delete output to allow regen next time we run.
if (java_writer != null) { if ( java_writer != null ) {
java_writer.close(); java_writer.close();
} }
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }
private static ByteBuffer readFile(final File file) throws IOException { private static ByteBuffer readFile(final File file) throws IOException {
final FileChannel channel = new FileInputStream(file).getChannel(); final FileChannel channel = new FileInputStream(file).getChannel();
final long bytesTotal = channel.size(); final long bytesTotal = channel.size();
final ByteBuffer buffer = ByteBuffer.allocateDirect((int) bytesTotal); final ByteBuffer buffer = ByteBuffer.allocateDirect((int)bytesTotal);
long bytesRead = 0; long bytesRead = 0;
do { do {
bytesRead += channel.read(buffer); bytesRead += channel.read(buffer);
} while (bytesRead < bytesTotal); } while ( bytesRead < bytesTotal );
buffer.flip(); buffer.flip();
channel.close(); channel.close();
return buffer; return buffer;
} }
} }

View File

@ -32,22 +32,22 @@
package org.lwjgl.util.generator; package org.lwjgl.util.generator;
import org.lwjgl.PointerBuffer;
import java.nio.Buffer; import java.nio.Buffer;
import javax.lang.model.type.ArrayType; import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType; import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType; import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.PrimitiveType;
import javax.lang.model.util.SimpleTypeVisitor6; import javax.lang.model.util.SimpleTypeVisitor6;
import org.lwjgl.PointerBuffer;
/** /**
*
* A TypeVisitor that translates TypeMirrors to JNI * A TypeVisitor that translates TypeMirrors to JNI
* type strings. * type strings.
* *
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ * @version $Revision$
* $Id$ * $Id$
*/ */
public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> { public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
@ -63,7 +63,7 @@ public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
return objectReturn ? "jobject" : signature.toString(); return objectReturn ? "jobject" : signature.toString();
} }
@Override @Override
public Void visitArray(ArrayType t, Void o) { public Void visitArray(ArrayType t, Void o) {
final String className = t.getComponentType().toString(); final String className = t.getComponentType().toString();
if ( "java.lang.CharSequence".equals(className) ) if ( "java.lang.CharSequence".equals(className) )
@ -74,7 +74,7 @@ public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
signature.append("jobjectArray"); signature.append("jobjectArray");
else else
throw new RuntimeException(t + " is not allowed"); throw new RuntimeException(t + " is not allowed");
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
private void visitClassType(DeclaredType t) { private void visitClassType(DeclaredType t) {
@ -86,17 +86,17 @@ public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
signature.append("jobject"); signature.append("jobject");
} }
@Override @Override
public Void visitDeclared(DeclaredType t, Void o) { public Void visitDeclared(DeclaredType t, Void o) {
if(t.asElement().getKind().isClass()) if ( t.asElement().getKind().isClass() )
visitClassType(t); visitClassType(t);
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
@Override @Override
public Void visitPrimitive(PrimitiveType t, Void o) { public Void visitPrimitive(PrimitiveType t, Void o) {
String type; String type;
switch (t.getKind()) { switch ( t.getKind() ) {
case LONG: case LONG:
type = "jlong"; type = "jlong";
break; break;
@ -122,13 +122,13 @@ public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
throw new RuntimeException(t + " is not allowed"); throw new RuntimeException(t + " is not allowed");
} }
signature.append(type); signature.append(type);
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
@Override @Override
public Void visitNoType(NoType t, Void o) { public Void visitNoType(NoType t, Void o) {
signature.append(t.toString()); signature.append(t.toString());
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -32,19 +32,7 @@
package org.lwjgl.util.generator; package org.lwjgl.util.generator;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.logging.Level; import javax.lang.model.type.*;
import java.util.logging.Logger;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import static javax.lang.model.type.TypeKind.BOOLEAN;
import static javax.lang.model.type.TypeKind.BYTE;
import static javax.lang.model.type.TypeKind.DOUBLE;
import static javax.lang.model.type.TypeKind.FLOAT;
import static javax.lang.model.type.TypeKind.INT;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.SimpleTypeVisitor6; import javax.lang.model.util.SimpleTypeVisitor6;
/** /**
@ -56,106 +44,106 @@ import javax.lang.model.util.SimpleTypeVisitor6;
*/ */
public class JavaTypeTranslator extends SimpleTypeVisitor6<Void, Void> { public class JavaTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
private Class type; private Class type;
public Class getType() { public Class getType() {
return type; return type;
} }
@Override @Override
public Void visitArray(ArrayType t, Void o) { public Void visitArray(ArrayType t, Void o) {
final TypeMirror componentType = t.getComponentType(); final TypeMirror componentType = t.getComponentType();
try { try {
final Class c = Class.forName(t.getComponentType().toString()); final Class c = Class.forName(t.getComponentType().toString());
if (CharSequence.class.isAssignableFrom(c) || ByteBuffer.class.isAssignableFrom(c) || org.lwjgl.PointerWrapper.class.isAssignableFrom(c)) { if ( CharSequence.class.isAssignableFrom(c) || ByteBuffer.class.isAssignableFrom(c) || org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
type = Class.forName("[L" + t.getComponentType() + ";"); type = Class.forName("[L" + t.getComponentType() + ";");
} }
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
type = null; type = null;
} finally { } finally {
if (type == null) { if ( type == null ) {
if (componentType instanceof PrimitiveType) { if ( componentType instanceof PrimitiveType ) {
type = getPrimitiveArrayClassFromKind(((PrimitiveType) componentType).getKind()); type = getPrimitiveArrayClassFromKind(((PrimitiveType)componentType).getKind());
} else { } else {
throw new RuntimeException(t + " is not allowed"); throw new RuntimeException(t + " is not allowed");
} }
} }
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
} }
public static Class getPrimitiveClassFromKind(TypeKind kind) { public static Class getPrimitiveClassFromKind(TypeKind kind) {
switch (kind) { switch ( kind ) {
case LONG: case LONG:
return long.class; return long.class;
case INT: case INT:
return int.class; return int.class;
case DOUBLE: case DOUBLE:
return double.class; return double.class;
case FLOAT: case FLOAT:
return float.class; return float.class;
case SHORT: case SHORT:
return short.class; return short.class;
case BYTE: case BYTE:
return byte.class; return byte.class;
case BOOLEAN: case BOOLEAN:
return boolean.class; return boolean.class;
default: default:
throw new RuntimeException(kind + " is not allowed"); throw new RuntimeException(kind + " is not allowed");
} }
} }
private static Class getPrimitiveArrayClassFromKind(TypeKind kind) { private static Class getPrimitiveArrayClassFromKind(TypeKind kind) {
switch (kind) { switch ( kind ) {
case LONG: case LONG:
return long[].class; return long[].class;
case INT: case INT:
return int[].class; return int[].class;
case DOUBLE: case DOUBLE:
return double[].class; return double[].class;
case FLOAT: case FLOAT:
return float[].class; return float[].class;
case SHORT: case SHORT:
return short[].class; return short[].class;
case BYTE: case BYTE:
return byte[].class; return byte[].class;
case BOOLEAN: case BOOLEAN:
return boolean[].class; return boolean[].class;
default: default:
throw new RuntimeException(kind + " is not allowed"); throw new RuntimeException(kind + " is not allowed");
} }
} }
@Override @Override
public Void visitPrimitive(PrimitiveType t, Void p) { public Void visitPrimitive(PrimitiveType t, Void p) {
type = getPrimitiveClassFromKind(t.getKind()); type = getPrimitiveClassFromKind(t.getKind());
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
@Override @Override
public Void visitDeclared(DeclaredType t, Void o) { public Void visitDeclared(DeclaredType t, Void o) {
if (t.asElement().getKind().isClass()) { if ( t.asElement().getKind().isClass() ) {
visitClassType(t); visitClassType(t);
} else if (t.asElement().getKind().isInterface()) { } else if ( t.asElement().getKind().isInterface() ) {
visitInterfaceType(t); visitInterfaceType(t);
} else { } else {
throw new RuntimeException(t.asElement().getKind() + " is not allowed"); throw new RuntimeException(t.asElement().getKind() + " is not allowed");
} }
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
private void visitClassType(DeclaredType t) { private void visitClassType(DeclaredType t) {
type = NativeTypeTranslator.getClassFromType(t); type = NativeTypeTranslator.getClassFromType(t);
} }
private void visitInterfaceType(DeclaredType t) { private void visitInterfaceType(DeclaredType t) {
type = NativeTypeTranslator.getClassFromType(t); type = NativeTypeTranslator.getClassFromType(t);
} }
@Override @Override
public Void visitNoType(NoType t, Void p) { public Void visitNoType(NoType t, Void p) {
type = void.class; type = void.class;
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
} }

View File

@ -41,9 +41,11 @@ package org.lwjgl.util.generator;
* $Id$ * $Id$
*/ */
import java.io.*; import org.lwjgl.PointerBuffer;
import java.nio.*;
import java.util.*; import java.io.PrintWriter;
import java.nio.Buffer;
import java.util.List;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
@ -51,27 +53,26 @@ import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement; import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import org.lwjgl.PointerBuffer;
public class NativeMethodStubsGenerator { public class NativeMethodStubsGenerator {
private static final String BUFFER_ADDRESS_POSTFIX = "_address"; private static final String BUFFER_ADDRESS_POSTFIX = "_address";
public static final String BUFFER_POSITION_POSTFIX = "_position"; public static final String BUFFER_POSITION_POSTFIX = "_position";
private static final String STRING_LIST_NAME = "_str"; private static final String STRING_LIST_NAME = "_str";
private static final String POINTER_LIST_NAME = "_ptr"; private static final String POINTER_LIST_NAME = "_ptr";
public static void generateNativeMethodStubs(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement d, boolean generate_error_checks, boolean context_specific) { public static void generateNativeMethodStubs(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement d, boolean generate_error_checks, boolean context_specific) {
for (ExecutableElement method : Utils.getMethods( d)) { for ( ExecutableElement method : Utils.getMethods(d) ) {
Alternate alt_annotation = method.getAnnotation(Alternate.class); Alternate alt_annotation = method.getAnnotation(Alternate.class);
if ( (alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null ) if ( (alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null )
continue; continue;
generateMethodStub(env, type_map, writer, Utils.getQualifiedClassName(d), method, Mode.NORMAL, generate_error_checks, context_specific); generateMethodStub(env, type_map, writer, Utils.getQualifiedClassName(d), method, Mode.NORMAL, generate_error_checks, context_specific);
if (Utils.hasMethodBufferObjectParameter(method)) if ( Utils.hasMethodBufferObjectParameter(method) )
generateMethodStub(env, type_map, writer, Utils.getQualifiedClassName(d), method, Mode.BUFFEROBJECT, generate_error_checks, context_specific); generateMethodStub(env, type_map, writer, Utils.getQualifiedClassName(d), method, Mode.BUFFEROBJECT, generate_error_checks, context_specific);
} }
} }
private static void generateParameters(PrintWriter writer, List<? extends VariableElement> params, Mode mode) { private static void generateParameters(PrintWriter writer, List<? extends VariableElement> params, Mode mode) {
for (VariableElement param : params) { for ( VariableElement param : params ) {
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) ) if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
continue; continue;
final Constant constant_annotation = param.getAnnotation(Constant.class); final Constant constant_annotation = param.getAnnotation(Constant.class);
@ -82,7 +83,7 @@ public class NativeMethodStubsGenerator {
private static void generateParameter(PrintWriter writer, VariableElement param, Mode mode) { private static void generateParameter(PrintWriter writer, VariableElement param, Mode mode) {
writer.print(", "); writer.print(", ");
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) { if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
writer.print("jlong " + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX); writer.print("jlong " + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
} else if ( param.getAnnotation(PointerWrapper.class) != null ) { } else if ( param.getAnnotation(PointerWrapper.class) != null ) {
writer.print("jlong " + param.getSimpleName()); writer.print("jlong " + param.getSimpleName());
@ -113,24 +114,24 @@ public class NativeMethodStubsGenerator {
writer.print(" JNICALL "); writer.print(" JNICALL ");
writer.print(Utils.getQualifiedNativeMethodName(interface_name, method, generate_error_checks, context_specific)); writer.print(Utils.getQualifiedNativeMethodName(interface_name, method, generate_error_checks, context_specific));
if (mode == Mode.BUFFEROBJECT) if ( mode == Mode.BUFFEROBJECT )
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX); writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
writer.print("(JNIEnv *env, jclass clazz"); writer.print("(JNIEnv *env, jclass clazz");
generateParameters(writer, method.getParameters(), mode); generateParameters(writer, method.getParameters(), mode);
if (Utils.getNIOBufferType(result_type) != null) { if ( Utils.getNIOBufferType(result_type) != null ) {
if ( (cached_result_annotation == null || !cached_result_annotation.isRange()) && (auto_size_annotation == null || !auto_size_annotation.isNative()) ) if ( (cached_result_annotation == null || !cached_result_annotation.isRange()) && (auto_size_annotation == null || !auto_size_annotation.isNative()) )
writer.print(", jlong " + Utils.RESULT_SIZE_NAME); writer.print(", jlong " + Utils.RESULT_SIZE_NAME);
if (cached_result_annotation != null) if ( cached_result_annotation != null )
writer.print(", jobject " + Utils.CACHED_BUFFER_NAME); writer.print(", jobject " + Utils.CACHED_BUFFER_NAME);
} }
if (context_specific) { if ( context_specific ) {
writer.print(", jlong " + Utils.FUNCTION_POINTER_VAR_NAME); writer.print(", jlong " + Utils.FUNCTION_POINTER_VAR_NAME);
} }
writer.println(") {"); writer.println(") {");
generateBufferParameterAddresses(type_map, writer, method, mode); generateBufferParameterAddresses(type_map, writer, method, mode);
Alternate alt_annotation = method.getAnnotation(Alternate.class); Alternate alt_annotation = method.getAnnotation(Alternate.class);
if (context_specific) { if ( context_specific ) {
String typedef_name = Utils.getTypedefName(method); String typedef_name = Utils.getTypedefName(method);
writer.print("\t" + typedef_name + " " + (alt_annotation == null ? method.getSimpleName() : alt_annotation.value())); writer.print("\t" + typedef_name + " " + (alt_annotation == null ? method.getSimpleName() : alt_annotation.value()));
writer.print(" = (" + typedef_name + ")((intptr_t)"); writer.print(" = (" + typedef_name + ")((intptr_t)");
@ -166,21 +167,21 @@ public class NativeMethodStubsGenerator {
writer.println(code_annotation.nativeAfterCall()); writer.println(code_annotation.nativeAfterCall());
generateStringDeallocations(writer, method.getParameters()); generateStringDeallocations(writer, method.getParameters());
if (!result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID))) { if ( !result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID)) ) {
writer.print("\treturn "); writer.print("\treturn ");
Class java_result_type = Utils.getJavaType(result_type); Class java_result_type = Utils.getJavaType(result_type);
if (Buffer.class.isAssignableFrom(java_result_type)) { if ( Buffer.class.isAssignableFrom(java_result_type) ) {
if (cached_result_annotation != null) if ( cached_result_annotation != null )
writer.print("safeNewBufferCached(env, "); writer.print("safeNewBufferCached(env, ");
else else
writer.print("safeNewBuffer(env, "); writer.print("safeNewBuffer(env, ");
} else if (String.class.equals(java_result_type)) { } else if ( String.class.equals(java_result_type) ) {
writer.print("NewStringNativeUnsigned(env, "); writer.print("NewStringNativeUnsigned(env, ");
} else if ( method.getAnnotation(PointerWrapper.class) != null ) { } else if ( method.getAnnotation(PointerWrapper.class) != null ) {
writer.print("(intptr_t)"); writer.print("(intptr_t)");
} }
writer.print(Utils.RESULT_VAR_NAME); writer.print(Utils.RESULT_VAR_NAME);
if (Buffer.class.isAssignableFrom(java_result_type)) { if ( Buffer.class.isAssignableFrom(java_result_type) ) {
final String size_parameter_name; final String size_parameter_name;
if ( auto_size_annotation != null && (auto_size_annotation.isNative() || (cached_result_annotation != null && cached_result_annotation.isRange())) ) if ( auto_size_annotation != null && (auto_size_annotation.isNative() || (cached_result_annotation != null && cached_result_annotation.isRange())) )
size_parameter_name = auto_size_annotation.value(); size_parameter_name = auto_size_annotation.value();
@ -190,8 +191,8 @@ public class NativeMethodStubsGenerator {
writer.print(", "); writer.print(", ");
Utils.printExtraCallArguments(writer, method, size_parameter_name); Utils.printExtraCallArguments(writer, method, size_parameter_name);
} }
if (Buffer.class.isAssignableFrom(java_result_type) || if ( Buffer.class.isAssignableFrom(java_result_type) ||
String.class.equals(java_result_type)) String.class.equals(java_result_type) )
writer.print(")"); writer.print(")");
writer.println(";"); writer.println(";");
} }
@ -207,14 +208,14 @@ public class NativeMethodStubsGenerator {
if ( preDeclare ) if ( preDeclare )
writer.print("\t"); writer.print("\t");
writer.print(result_translator.getSignature() + " " + Utils.RESULT_VAR_NAME); writer.print(result_translator.getSignature() + " " + Utils.RESULT_VAR_NAME);
if ( preDeclare) if ( preDeclare )
writer.println(";"); writer.println(";");
else else
writer.print(result_param == null ? " = " : ";\n\t"); writer.print(result_param == null ? " = " : ";\n\t");
} }
private static void generateCallParameters(PrintWriter writer, TypeMap type_map, List<? extends VariableElement> params) { private static void generateCallParameters(PrintWriter writer, TypeMap type_map, List<? extends VariableElement> params) {
if (params.size() > 0) { if ( params.size() > 0 ) {
boolean first = true; boolean first = true;
for ( VariableElement param : params ) { for ( VariableElement param : params ) {
if ( param.getAnnotation(Helper.class) != null ) if ( param.getAnnotation(Helper.class) != null )
@ -241,7 +242,7 @@ public class NativeMethodStubsGenerator {
} }
boolean is_indirect = param.getAnnotation(Indirect.class) != null; boolean is_indirect = param.getAnnotation(Indirect.class) != null;
if (is_indirect || param.getAnnotation(PointerArray.class) != null) { if ( is_indirect || param.getAnnotation(PointerArray.class) != null ) {
writer.print("("); writer.print("(");
final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param); final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
param.asType().accept(translator, null); param.asType().accept(translator, null);
@ -250,7 +251,7 @@ public class NativeMethodStubsGenerator {
} }
if ( param.getAnnotation(PointerWrapper.class) != null ) if ( param.getAnnotation(PointerWrapper.class) != null )
writer.print("(" + param.getAnnotation(PointerWrapper.class).value() + ")(intptr_t)"); writer.print("(" + param.getAnnotation(PointerWrapper.class).value() + ")(intptr_t)");
if (param.getAnnotation(Result.class) != null || is_indirect) if ( param.getAnnotation(Result.class) != null || is_indirect )
writer.print("&"); writer.print("&");
if ( param.getAnnotation(Result.class) != null ) { if ( param.getAnnotation(Result.class) != null ) {
@ -265,11 +266,11 @@ public class NativeMethodStubsGenerator {
} }
private static void generateStringDeallocations(PrintWriter writer, List<? extends VariableElement> params) { private static void generateStringDeallocations(PrintWriter writer, List<? extends VariableElement> params) {
for (VariableElement param : params) { for ( VariableElement param : params ) {
final Class java_type = Utils.getJavaType(param.asType()); final Class java_type = Utils.getJavaType(param.asType());
if ( java_type.equals(String.class) && param.getAnnotation(Result.class) == null ) if ( java_type.equals(String.class) && param.getAnnotation(Result.class) == null )
writer.println("\tfree(" + param.getSimpleName() + BUFFER_ADDRESS_POSTFIX + ");"); writer.println("\tfree(" + param.getSimpleName() + BUFFER_ADDRESS_POSTFIX + ");");
else if (param.getAnnotation(PointerArray.class) != null ) // Free the string array mem else if ( param.getAnnotation(PointerArray.class) != null ) // Free the string array mem
writer.println("\tfree(" + param.getSimpleName() + getPointerArrayName(java_type) + ");"); writer.println("\tfree(" + param.getSimpleName() + getPointerArrayName(java_type) + ");");
} }
} }
@ -279,8 +280,8 @@ public class NativeMethodStubsGenerator {
ptrLoopDeclared = false; ptrLoopDeclared = false;
for ( VariableElement param : method.getParameters() ) { for ( VariableElement param : method.getParameters() ) {
final Constant constant_annotation = param.getAnnotation(Constant.class); final Constant constant_annotation = param.getAnnotation(Constant.class);
if ( param.getAnnotation(Result.class) == null && (constant_annotation == null || !constant_annotation.isNative()) && Utils.isAddressableType(param.asType())) if ( param.getAnnotation(Result.class) == null && (constant_annotation == null || !constant_annotation.isNative()) && Utils.isAddressableType(param.asType()) )
generateBufferParameterAddress(type_map, writer, method, param, mode); generateBufferParameterAddress(type_map, writer, method, param, mode);
} }
} }
@ -302,12 +303,12 @@ public class NativeMethodStubsGenerator {
writer.print(native_type); writer.print(native_type);
writer.print(")(intptr_t)"); writer.print(")(intptr_t)");
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) { if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
writer.print("offsetToPointer(" + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX + ")"); writer.print("offsetToPointer(" + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX + ")");
} else { } else {
if (Buffer.class.isAssignableFrom(java_type) || java_type.equals(CharSequence.class) || java_type.equals(CharSequence[].class) || PointerBuffer.class.isAssignableFrom(java_type) ) { if ( Buffer.class.isAssignableFrom(java_type) || java_type.equals(CharSequence.class) || java_type.equals(CharSequence[].class) || PointerBuffer.class.isAssignableFrom(java_type) ) {
writer.print(param.getSimpleName()); writer.print(param.getSimpleName());
} else if (java_type.equals(String.class)) { } else if ( java_type.equals(String.class) ) {
writer.print("GetStringNativeChars(env, " + param.getSimpleName() + ")"); writer.print("GetStringNativeChars(env, " + param.getSimpleName() + ")");
} else if ( array_annotation == null ) } else if ( array_annotation == null )
throw new RuntimeException("Illegal type " + java_type); throw new RuntimeException("Illegal type " + java_type);

View File

@ -39,21 +39,17 @@ package org.lwjgl.util.generator;
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$ * @version $Revision$ $Id$
*/ */
import org.lwjgl.PointerBuffer;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.nio.*; import java.nio.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.type.ArrayType; import javax.lang.model.type.*;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.util.SimpleTypeVisitor6; import javax.lang.model.util.SimpleTypeVisitor6;
import org.lwjgl.PointerBuffer;
/** /**
* $Id$ * $Id$
@ -65,189 +61,189 @@ import org.lwjgl.PointerBuffer;
*/ */
public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> { public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
private Collection<Class> native_types; private Collection<Class> native_types;
private boolean is_indirect; private boolean is_indirect;
private final Element declaration; private final Element declaration;
private final TypeMap type_map; private final TypeMap type_map;
public NativeTypeTranslator(TypeMap type_map, Element declaration) { public NativeTypeTranslator(TypeMap type_map, Element declaration) {
this.declaration = declaration; this.declaration = declaration;
this.type_map = type_map; this.type_map = type_map;
} }
public String getSignature() { public String getSignature() {
return getSignature(false); return getSignature(false);
} }
public String getSignature(final boolean skipConst) { public String getSignature(final boolean skipConst) {
StringBuilder signature = new StringBuilder(); StringBuilder signature = new StringBuilder();
if (!skipConst && declaration.getAnnotation(Const.class) != null) { if ( !skipConst && declaration.getAnnotation(Const.class) != null ) {
signature.append("const "); signature.append("const ");
} }
if (declaration.getAnnotation(PointerWrapper.class) != null) { if ( declaration.getAnnotation(PointerWrapper.class) != null ) {
signature.append(declaration.getAnnotation(PointerWrapper.class).value()); signature.append(declaration.getAnnotation(PointerWrapper.class).value());
} else if (declaration.getAnnotation(NativeType.class) != null) { } else if ( declaration.getAnnotation(NativeType.class) != null ) {
signature.append(declaration.getAnnotation(NativeType.class).value()); signature.append(declaration.getAnnotation(NativeType.class).value());
} else { } else {
// Use the name of the native type annotation as the C type name // Use the name of the native type annotation as the C type name
signature.append(getAnnotationType().getSimpleName()); signature.append(getAnnotationType().getSimpleName());
} }
if (is_indirect) { if ( is_indirect ) {
signature.append(" *"); signature.append(" *");
} }
return signature.toString(); return signature.toString();
} }
public Class getAnnotationType() { public Class getAnnotationType() {
if (native_types.size() != 1) { if ( native_types.size() != 1 ) {
throw new RuntimeException("Expected only one native type for declaration " + declaration throw new RuntimeException("Expected only one native type for declaration " + declaration
+ ", but got " + native_types.size()); + ", but got " + native_types.size());
} }
return native_types.iterator().next(); return native_types.iterator().next();
} }
@Override @Override
public Void visitArray(ArrayType t, Void o) { public Void visitArray(ArrayType t, Void o) {
final Class<?> type = Utils.getJavaType(t).getComponentType(); final Class<?> type = Utils.getJavaType(t).getComponentType();
if (CharSequence.class.isAssignableFrom(type)) { if ( CharSequence.class.isAssignableFrom(type) ) {
is_indirect = true; is_indirect = true;
native_types = new ArrayList<>(); native_types = new ArrayList<>();
native_types.add(type_map.getStringArrayType()); native_types.add(type_map.getStringArrayType());
} else if (Buffer.class.isAssignableFrom(type)) { } else if ( Buffer.class.isAssignableFrom(type) ) {
is_indirect = true; is_indirect = true;
native_types = new ArrayList<>(); native_types = new ArrayList<>();
native_types.add(type_map.getByteBufferArrayType()); native_types.add(type_map.getByteBufferArrayType());
} else if (org.lwjgl.PointerWrapper.class.isAssignableFrom(type)) { } else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) ) {
is_indirect = false; is_indirect = false;
} else { } else {
throw new RuntimeException(t + " is not allowed"); throw new RuntimeException(t + " is not allowed");
} }
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
public static TypeKind getPrimitiveKindFromBufferClass(Class c) { public static TypeKind getPrimitiveKindFromBufferClass(Class c) {
if (IntBuffer.class.equals(c)) { if ( IntBuffer.class.equals(c) ) {
return TypeKind.INT; return TypeKind.INT;
} else if (DoubleBuffer.class.equals(c)) { } else if ( DoubleBuffer.class.equals(c) ) {
return TypeKind.DOUBLE; return TypeKind.DOUBLE;
} else if (ShortBuffer.class.equals(c)) { } else if ( ShortBuffer.class.equals(c) ) {
return TypeKind.SHORT; return TypeKind.SHORT;
} else if (ByteBuffer.class.equals(c) || PointerBuffer.class.equals(c)) { } else if ( ByteBuffer.class.equals(c) || PointerBuffer.class.equals(c) ) {
return TypeKind.BYTE; return TypeKind.BYTE;
} else if (FloatBuffer.class.equals(c)) { } else if ( FloatBuffer.class.equals(c) ) {
return TypeKind.FLOAT; return TypeKind.FLOAT;
} else if (LongBuffer.class.equals(c)) { } else if ( LongBuffer.class.equals(c) ) {
return TypeKind.LONG; return TypeKind.LONG;
} else { } else {
throw new RuntimeException(c + " is not allowed"); throw new RuntimeException(c + " is not allowed");
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Class<? extends Annotation> getClassFromType(DeclaredType t) { public static Class<? extends Annotation> getClassFromType(DeclaredType t) {
try { try {
return (Class<? extends Annotation>) Class.forName(t.toString()); return (Class<? extends Annotation>)Class.forName(t.toString());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private void getNativeTypeFromAnnotatedPrimitiveType(TypeKind kind) { private void getNativeTypeFromAnnotatedPrimitiveType(TypeKind kind) {
native_types = translateAnnotations(); native_types = translateAnnotations();
if (native_types.isEmpty()) { if ( native_types.isEmpty() ) {
native_types.add(type_map.getNativeTypeFromPrimitiveType(kind)); native_types.add(type_map.getNativeTypeFromPrimitiveType(kind));
} }
} }
private void visitClassType(DeclaredType t) { private void visitClassType(DeclaredType t) {
is_indirect = true; is_indirect = true;
Class<?> c = getClassFromType(t); Class<?> c = getClassFromType(t);
if (String.class.equals(c)) { if ( String.class.equals(c) ) {
native_types = new ArrayList<>(); native_types = new ArrayList<>();
native_types.add(type_map.getStringElementType()); native_types.add(type_map.getStringElementType());
} else if (Buffer.class.equals(c)) { } else if ( Buffer.class.equals(c) ) {
native_types = new ArrayList<>(); native_types = new ArrayList<>();
native_types.add(type_map.getVoidType()); native_types.add(type_map.getVoidType());
} else if (Buffer.class.isAssignableFrom(c) || PointerBuffer.class.isAssignableFrom(c)) { } else if ( Buffer.class.isAssignableFrom(c) || PointerBuffer.class.isAssignableFrom(c) ) {
TypeKind kind = getPrimitiveKindFromBufferClass(c); TypeKind kind = getPrimitiveKindFromBufferClass(c);
getNativeTypeFromAnnotatedPrimitiveType(kind); getNativeTypeFromAnnotatedPrimitiveType(kind);
} else if (org.lwjgl.PointerWrapper.class.isAssignableFrom(c)) { } else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
native_types = new ArrayList<>(); native_types = new ArrayList<>();
native_types.add(PointerWrapper.class); native_types.add(PointerWrapper.class);
is_indirect = false; is_indirect = false;
} else { } else {
throw new RuntimeException(t + " is not allowed"); throw new RuntimeException(t + " is not allowed");
} }
} }
@Override @Override
public Void visitPrimitive(PrimitiveType t, Void p) { public Void visitPrimitive(PrimitiveType t, Void p) {
getNativeTypeFromAnnotatedPrimitiveType(t.getKind()); getNativeTypeFromAnnotatedPrimitiveType(t.getKind());
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
private void visitInterfaceType(DeclaredType t) { private void visitInterfaceType(DeclaredType t) {
// See ARB_debug_label.glObjectPtrLabel // See ARB_debug_label.glObjectPtrLabel
Class<?> c = getClassFromType(t); Class<?> c = getClassFromType(t);
if (org.lwjgl.PointerWrapper.class.isAssignableFrom(c)) { if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
native_types = new ArrayList<>(); native_types = new ArrayList<>();
native_types.add(PointerWrapper.class); native_types.add(PointerWrapper.class);
is_indirect = false; is_indirect = false;
} else { } else {
throw new RuntimeException(t + " is not allowed"); throw new RuntimeException(t + " is not allowed");
} }
} }
@Override @Override
public Void visitDeclared(DeclaredType t, Void p) { public Void visitDeclared(DeclaredType t, Void p) {
if (t.asElement().getKind().isInterface()) { if ( t.asElement().getKind().isInterface() ) {
visitInterfaceType(t); visitInterfaceType(t);
} else if (t.asElement().getKind().isClass()) { } else if ( t.asElement().getKind().isClass() ) {
visitClassType(t); visitClassType(t);
} }
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
/* Check if the annotation is itself annotated with a certain annotation type /* Check if the annotation is itself annotated with a certain annotation type
* @discuss compare (DeclaredType).getAnnotation(Class) and (Element).getAnnotation(Class), they mean different Annotation's. * @discuss compare (DeclaredType).getAnnotation(Class) and (Element).getAnnotation(Class), they mean different Annotation's.
*/ */
public static <T extends Annotation> T getAnnotation(AnnotationMirror annotation, Class<T> type) { public static <T extends Annotation> T getAnnotation(AnnotationMirror annotation, Class<T> type) {
return annotation.getAnnotationType().asElement().getAnnotation(type); return annotation.getAnnotationType().asElement().getAnnotation(type);
} }
private static Class translateAnnotation(AnnotationMirror annotation) { private static Class translateAnnotation(AnnotationMirror annotation) {
NativeType native_type = getAnnotation(annotation, NativeType.class); NativeType native_type = getAnnotation(annotation, NativeType.class);
if (native_type != null) { if ( native_type != null ) {
return getClassFromType(annotation.getAnnotationType()); return getClassFromType(annotation.getAnnotationType());
} else { } else {
return null; return null;
} }
} }
private List<Class> translateAnnotations() { private List<Class> translateAnnotations() {
List<Class> result = new ArrayList<>(); List<Class> result = new ArrayList<>();
for (AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors())) { for ( AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors()) ) {
Class translated_result = translateAnnotation(annotation); Class translated_result = translateAnnotation(annotation);
if (translated_result != null) { if ( translated_result != null ) {
result.add(translated_result); result.add(translated_result);
} }
} }
return result; return result;
} }
@Override @Override
public Void visitNoType(NoType t, Void p) { public Void visitNoType(NoType t, Void p) {
native_types = translateAnnotations(); native_types = translateAnnotations();
if (native_types.isEmpty()) { if ( native_types.isEmpty() ) {
native_types.add(void.class); native_types.add(void.class);
} }
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
} }

View File

@ -51,7 +51,7 @@ import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.util.SimpleTypeVisitor6; import javax.lang.model.util.SimpleTypeVisitor6;
public class PostfixTranslator extends SimpleTypeVisitor6<Void,Void> { public class PostfixTranslator extends SimpleTypeVisitor6<Void, Void> {
private final StringBuilder signature = new StringBuilder(); private final StringBuilder signature = new StringBuilder();
private final Element declaration; private final Element declaration;
private final TypeMap type_map; private final TypeMap type_map;
@ -66,17 +66,17 @@ public class PostfixTranslator extends SimpleTypeVisitor6<Void,Void> {
} }
private static TypeKind getPrimitiveKindFromBufferClass(Class c) { private static TypeKind getPrimitiveKindFromBufferClass(Class c) {
if (IntBuffer.class.equals(c) || int.class.equals(c) ) if ( IntBuffer.class.equals(c) || int.class.equals(c) )
return TypeKind.INT; return TypeKind.INT;
else if (DoubleBuffer.class.equals(c) || double.class.equals(c) ) else if ( DoubleBuffer.class.equals(c) || double.class.equals(c) )
return TypeKind.DOUBLE; return TypeKind.DOUBLE;
else if (ShortBuffer.class.equals(c) || short.class.equals(c) ) else if ( ShortBuffer.class.equals(c) || short.class.equals(c) )
return TypeKind.SHORT; return TypeKind.SHORT;
else if (ByteBuffer.class.equals(c) || byte.class.equals(c) ) else if ( ByteBuffer.class.equals(c) || byte.class.equals(c) )
return TypeKind.BYTE; return TypeKind.BYTE;
else if (FloatBuffer.class.equals(c) || float.class.equals(c)) else if ( FloatBuffer.class.equals(c) || float.class.equals(c) )
return TypeKind.FLOAT; return TypeKind.FLOAT;
else if (LongBuffer.class.equals(c) || long.class.equals(c) ) else if ( LongBuffer.class.equals(c) || long.class.equals(c) )
return TypeKind.LONG; return TypeKind.LONG;
else else
throw new RuntimeException(c + " is not allowed"); throw new RuntimeException(c + " is not allowed");
@ -88,16 +88,16 @@ public class PostfixTranslator extends SimpleTypeVisitor6<Void,Void> {
visitPrimitiveTypeKind(kind); visitPrimitiveTypeKind(kind);
} }
@Override @Override
public Void visitDeclared(DeclaredType t, Void o) { public Void visitDeclared(DeclaredType t, Void o) {
if(t.asElement().getKind().isClass()) if ( t.asElement().getKind().isClass() )
visitClassType(t); visitClassType(t);
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
private boolean translateAnnotation(AnnotationMirror annotation) { private boolean translateAnnotation(AnnotationMirror annotation) {
NativeType native_type = NativeTypeTranslator.getAnnotation(annotation, NativeType.class); NativeType native_type = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
if (native_type != null) { if ( native_type != null ) {
Class<? extends Annotation> annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType()); Class<? extends Annotation> annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
signature.append(type_map.translateAnnotation(annotation_class)); signature.append(type_map.translateAnnotation(annotation_class));
return true; return true;
@ -107,28 +107,28 @@ public class PostfixTranslator extends SimpleTypeVisitor6<Void,Void> {
private boolean translateAnnotations() { private boolean translateAnnotations() {
boolean result = false; boolean result = false;
for (AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors())) for ( AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors()) )
if (translateAnnotation(annotation)) { if ( translateAnnotation(annotation) ) {
if (result) if ( result )
throw new RuntimeException("Multiple native types"); throw new RuntimeException("Multiple native types");
result = true; result = true;
} }
return result; return result;
} }
@Override @Override
public Void visitPrimitive(PrimitiveType t, Void o) { public Void visitPrimitive(PrimitiveType t, Void o) {
visitPrimitiveTypeKind(t.getKind()); visitPrimitiveTypeKind(t.getKind());
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
private void visitPrimitiveTypeKind(TypeKind kind) { private void visitPrimitiveTypeKind(TypeKind kind) {
boolean annotated_translation = translateAnnotations(); boolean annotated_translation = translateAnnotations();
if (annotated_translation) if ( annotated_translation )
return; return;
// No annotation type was specified, fall back to default // No annotation type was specified, fall back to default
String type; String type;
switch (kind) { switch ( kind ) {
case INT: case INT:
type = "i"; type = "i";
break; break;

View File

@ -38,8 +38,11 @@ package org.lwjgl.util.generator;
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$ * @version $Revision$ $Id$
*/ */
import java.io.*; import java.io.PrintWriter;
import java.util.*; import java.util.Arrays;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
@ -48,97 +51,97 @@ import javax.lang.model.type.TypeMirror;
public class RegisterStubsGenerator { public class RegisterStubsGenerator {
public static void generateMethodsNativeStubBind(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean generate_error_checks, boolean context_specific) { public static void generateMethodsNativeStubBind(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean generate_error_checks, boolean context_specific) {
Iterator<? extends ExecutableElement> it = Utils.getMethods( d).iterator(); Iterator<? extends ExecutableElement> it = Utils.getMethods(d).iterator();
while (it.hasNext()) { while ( it.hasNext() ) {
ExecutableElement method = it.next(); ExecutableElement method = it.next();
Alternate alt_annotation = method.getAnnotation(Alternate.class); Alternate alt_annotation = method.getAnnotation(Alternate.class);
if ((alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null) { if ( (alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null ) {
continue; continue;
} }
EnumSet<Platform> platforms; EnumSet<Platform> platforms;
PlatformDependent platform_annotation = method.getAnnotation(PlatformDependent.class); PlatformDependent platform_annotation = method.getAnnotation(PlatformDependent.class);
if (platform_annotation != null) { if ( platform_annotation != null ) {
platforms = EnumSet.copyOf(Arrays.asList(platform_annotation.value())); platforms = EnumSet.copyOf(Arrays.asList(platform_annotation.value()));
} else { } else {
platforms = EnumSet.of(Platform.ALL); platforms = EnumSet.of(Platform.ALL);
} }
for (Platform platform : platforms) { for ( Platform platform : platforms ) {
platform.printPrologue(writer); platform.printPrologue(writer);
boolean has_buffer_parameter = Utils.hasMethodBufferObjectParameter(method); boolean has_buffer_parameter = Utils.hasMethodBufferObjectParameter(method);
printMethodNativeStubBind(writer, d, method, platform, Mode.NORMAL, it.hasNext() || has_buffer_parameter, generate_error_checks, context_specific); printMethodNativeStubBind(writer, d, method, platform, Mode.NORMAL, it.hasNext() || has_buffer_parameter, generate_error_checks, context_specific);
if (has_buffer_parameter) { if ( has_buffer_parameter ) {
printMethodNativeStubBind(writer, d, method, platform, Mode.BUFFEROBJECT, it.hasNext(), generate_error_checks, context_specific); printMethodNativeStubBind(writer, d, method, platform, Mode.BUFFEROBJECT, it.hasNext(), generate_error_checks, context_specific);
} }
platform.printEpilogue(writer); platform.printEpilogue(writer);
} }
} }
writer.println(); writer.println();
} }
private static String getTypeSignature(TypeMirror type, boolean add_position_signature) { private static String getTypeSignature(TypeMirror type, boolean add_position_signature) {
SignatureTranslator v = new SignatureTranslator(add_position_signature); SignatureTranslator v = new SignatureTranslator(add_position_signature);
type.accept(v, null); type.accept(v, null);
return v.getSignature(); return v.getSignature();
} }
private static String getMethodSignature(ExecutableElement method, Mode mode) { private static String getMethodSignature(ExecutableElement method, Mode mode) {
List<? extends VariableElement> params = method.getParameters(); List<? extends VariableElement> params = method.getParameters();
String signature = "("; String signature = "(";
for (VariableElement param : params) { for ( VariableElement param : params ) {
if (param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative())) { if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) ) {
continue; continue;
} }
final Constant constant_annotation = param.getAnnotation(Constant.class); final Constant constant_annotation = param.getAnnotation(Constant.class);
if (constant_annotation != null && constant_annotation.isNative()) { if ( constant_annotation != null && constant_annotation.isNative() ) {
continue; continue;
} }
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) { if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
signature += "J"; signature += "J";
} else { } else {
signature += getTypeSignature(param.asType(), true); signature += getTypeSignature(param.asType(), true);
} }
} }
final TypeMirror result_type = Utils.getMethodReturnType(method); final TypeMirror result_type = Utils.getMethodReturnType(method);
final CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class); final CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class);
final AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class); final AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class);
final boolean isNIOBuffer = Utils.getNIOBufferType(result_type) != null; final boolean isNIOBuffer = Utils.getNIOBufferType(result_type) != null;
if (isNIOBuffer && (auto_size_annotation == null || !auto_size_annotation.isNative())) { if ( isNIOBuffer && (auto_size_annotation == null || !auto_size_annotation.isNative()) ) {
signature += "J"; signature += "J";
} }
final String result_type_signature = isNIOBuffer ? "Ljava/nio/ByteBuffer;" : getTypeSignature(result_type, false); final String result_type_signature = isNIOBuffer ? "Ljava/nio/ByteBuffer;" : getTypeSignature(result_type, false);
if (cached_result_annotation != null) { if ( cached_result_annotation != null ) {
signature += result_type_signature; signature += result_type_signature;
} }
signature += ")"; signature += ")";
signature += result_type_signature; signature += result_type_signature;
return signature; return signature;
} }
private static void printMethodNativeStubBind(PrintWriter writer, TypeElement d, ExecutableElement method, Platform platform, Mode mode, boolean has_more, boolean generate_error_checks, boolean context_specific) { private static void printMethodNativeStubBind(PrintWriter writer, TypeElement d, ExecutableElement method, Platform platform, Mode mode, boolean has_more, boolean generate_error_checks, boolean context_specific) {
writer.print("\t\t{\"" + Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific)); writer.print("\t\t{\"" + Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific));
if (mode == Mode.BUFFEROBJECT) { if ( mode == Mode.BUFFEROBJECT ) {
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX); writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
} }
writer.print("\", \"" + getMethodSignature(method, mode) + "\", (void *)&"); writer.print("\", \"" + getMethodSignature(method, mode) + "\", (void *)&");
writer.print(Utils.getQualifiedNativeMethodName(Utils.getQualifiedClassName(d), method, generate_error_checks, context_specific)); writer.print(Utils.getQualifiedNativeMethodName(Utils.getQualifiedClassName(d), method, generate_error_checks, context_specific));
if (mode == Mode.BUFFEROBJECT) { if ( mode == Mode.BUFFEROBJECT ) {
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX); writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
} }
final Alternate alt_annotation = method.getAnnotation(Alternate.class); final Alternate alt_annotation = method.getAnnotation(Alternate.class);
final String methodName = alt_annotation == null ? method.getSimpleName().toString() : alt_annotation.value(); final String methodName = alt_annotation == null ? method.getSimpleName().toString() : alt_annotation.value();
String opengl_handle_name = methodName.replaceFirst("gl", platform.getPrefix()); String opengl_handle_name = methodName.replaceFirst("gl", platform.getPrefix());
writer.print(", \"" + opengl_handle_name + "\", (void *)&" + methodName + ", " + (method.getAnnotation(Optional.class) == null ? "false" : "true") + "}"); writer.print(", \"" + opengl_handle_name + "\", (void *)&" + methodName + ", " + (method.getAnnotation(Optional.class) == null ? "false" : "true") + "}");
if (has_more) { if ( has_more ) {
writer.println(","); writer.println(",");
} }
} }
} }

View File

@ -41,22 +41,15 @@ package org.lwjgl.util.generator;
* $Id$ * $Id$
*/ */
import org.lwjgl.PointerBuffer;
import java.nio.*; import java.nio.Buffer;
import javax.annotation.processing.ProcessingEnvironment; import java.nio.ByteBuffer;
import javax.lang.model.type.ArrayType; import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType; import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType; import javax.lang.model.type.NoType;
import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.PrimitiveType;
import static javax.lang.model.type.TypeKind.BOOLEAN;
import static javax.lang.model.type.TypeKind.BYTE;
import static javax.lang.model.type.TypeKind.DOUBLE;
import static javax.lang.model.type.TypeKind.FLOAT;
import static javax.lang.model.type.TypeKind.INT;
import static javax.lang.model.type.TypeKind.LONG;
import static javax.lang.model.type.TypeKind.SHORT;
import javax.lang.model.util.SimpleTypeVisitor6; import javax.lang.model.util.SimpleTypeVisitor6;
import org.lwjgl.PointerBuffer;
class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> { class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
private final boolean add_position_signature; private final boolean add_position_signature;
@ -74,7 +67,7 @@ class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
return signature.toString(); return signature.toString();
} }
@Override @Override
public Void visitArray(ArrayType t, Void o) { public Void visitArray(ArrayType t, Void o) {
final Class type = Utils.getJavaType(t.getComponentType()); final Class type = Utils.getJavaType(t.getComponentType());
if ( CharSequence.class.isAssignableFrom(type) ) if ( CharSequence.class.isAssignableFrom(type) )
@ -85,7 +78,7 @@ class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
signature.append("[L" + getNativeNameFromClassName(type.getName()) + ";"); signature.append("[L" + getNativeNameFromClassName(type.getName()) + ";");
else else
throw new RuntimeException(t + " is not allowed"); throw new RuntimeException(t + " is not allowed");
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
private void visitClassType(DeclaredType t) { private void visitClassType(DeclaredType t) {
@ -106,13 +99,13 @@ class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
} }
} }
@Override @Override
public Void visitDeclared(DeclaredType t, Void o) { public Void visitDeclared(DeclaredType t, Void o) {
if(t.asElement().getKind().isClass()) if ( t.asElement().getKind().isClass() )
visitClassType(t); visitClassType(t);
else if(t.asElement().getKind().isInterface()) else if ( t.asElement().getKind().isInterface() )
visitInterfaceType(t); visitInterfaceType(t);
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
private void visitInterfaceType(DeclaredType t) { private void visitInterfaceType(DeclaredType t) {
@ -123,9 +116,9 @@ class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
throw new RuntimeException(t + " is not allowed"); throw new RuntimeException(t + " is not allowed");
} }
@Override @Override
public Void visitPrimitive(PrimitiveType t, Void o) { public Void visitPrimitive(PrimitiveType t, Void o) {
switch (t.getKind()) { switch ( t.getKind() ) {
case BOOLEAN: case BOOLEAN:
signature.append("Z"); signature.append("Z");
break; break;
@ -150,13 +143,13 @@ class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
default: default:
throw new RuntimeException("Unsupported type " + t); throw new RuntimeException("Unsupported type " + t);
} }
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
@Override @Override
public Void visitNoType(NoType t, Void o) { public Void visitNoType(NoType t, Void o) {
signature.append("V"); signature.append("V");
return DEFAULT_VALUE; return DEFAULT_VALUE;
} }
} }

View File

@ -39,210 +39,209 @@ package org.lwjgl.util.generator;
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$ * @version $Revision$ $Id$
*/ */
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.opengl.GLvoid;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.nio.*; import java.nio.*;
import java.util.*; import java.util.*;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement; import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.opengl.GLvoid;
public class TypeInfo { public class TypeInfo {
public static final String UNSIGNED_PARAMETER_NAME = "unsigned"; public static final String UNSIGNED_PARAMETER_NAME = "unsigned";
private final Signedness signedness; private final Signedness signedness;
private final Class type; private final Class type;
private final String auto_type; private final String auto_type;
private TypeInfo(Class type, Signedness signedness, String auto_type) { private TypeInfo(Class type, Signedness signedness, String auto_type) {
this.type = type; this.type = type;
this.signedness = signedness; this.signedness = signedness;
this.auto_type = auto_type; this.auto_type = auto_type;
} }
public Class getType() { public Class getType() {
return type; return type;
} }
public Signedness getSignedness() { public Signedness getSignedness() {
return signedness; return signedness;
} }
public String getAutoType() { public String getAutoType() {
if (auto_type == null) { if ( auto_type == null ) {
throw new RuntimeException("No auto type assigned"); throw new RuntimeException("No auto type assigned");
} }
return auto_type; return auto_type;
} }
private static Class getTypeFromPrimitiveKind(TypeKind kind) { private static Class getTypeFromPrimitiveKind(TypeKind kind) {
Class type; Class type;
switch (kind) { switch ( kind ) {
case LONG: case LONG:
type = long.class; type = long.class;
break; break;
case INT: case INT:
type = int.class; type = int.class;
break; break;
case FLOAT: case FLOAT:
type = float.class; type = float.class;
break; break;
case DOUBLE: case DOUBLE:
type = double.class; type = double.class;
break; break;
case SHORT: case SHORT:
type = short.class; type = short.class;
break; break;
case BYTE: case BYTE:
type = byte.class; type = byte.class;
break; break;
case BOOLEAN: case BOOLEAN:
type = boolean.class; type = boolean.class;
break; break;
default: default:
throw new RuntimeException(kind + " is not allowed"); throw new RuntimeException(kind + " is not allowed");
} }
return type; return type;
} }
private static Class getBufferTypeFromPrimitiveKind(TypeKind kind, AnnotationMirror annotation) { private static Class getBufferTypeFromPrimitiveKind(TypeKind kind, AnnotationMirror annotation) {
Class type; Class type;
switch (kind) { switch ( kind ) {
case INT: case INT:
type = IntBuffer.class; type = IntBuffer.class;
break; break;
case FLOAT: case FLOAT:
type = FloatBuffer.class; type = FloatBuffer.class;
break; break;
case DOUBLE: case DOUBLE:
type = DoubleBuffer.class; type = DoubleBuffer.class;
break; break;
case SHORT: case SHORT:
type = ShortBuffer.class; type = ShortBuffer.class;
break; break;
case LONG: case LONG:
if (annotation.getAnnotationType().asElement().getAnnotation(PointerType.class) != null) { if ( annotation.getAnnotationType().asElement().getAnnotation(PointerType.class) != null ) {
type = PointerBuffer.class; type = PointerBuffer.class;
} else { } else {
type = LongBuffer.class; type = LongBuffer.class;
} }
break; break;
case BYTE: /* fall through */ case BYTE: /* fall through */
case BOOLEAN: case BOOLEAN:
type = ByteBuffer.class; type = ByteBuffer.class;
break; break;
default: default:
throw new RuntimeException(kind + " is not allowed"); throw new RuntimeException(kind + " is not allowed");
} }
return type; return type;
} }
private static TypeInfo getDefaultTypeInfo(TypeMirror t) { private static TypeInfo getDefaultTypeInfo(TypeMirror t) {
Class java_type = Utils.getJavaType(t); Class java_type = Utils.getJavaType(t);
return new TypeInfo(java_type, Signedness.NONE, null); return new TypeInfo(java_type, Signedness.NONE, null);
} }
public static Map<VariableElement, TypeInfo> getDefaultTypeInfoMap(ExecutableElement method) { public static Map<VariableElement, TypeInfo> getDefaultTypeInfoMap(ExecutableElement method) {
Map<VariableElement, TypeInfo> map = new HashMap<>(); Map<VariableElement, TypeInfo> map = new HashMap<>();
for (VariableElement param : method.getParameters()) { for ( VariableElement param : method.getParameters() ) {
TypeInfo type_info = getDefaultTypeInfo(param.asType()); TypeInfo type_info = getDefaultTypeInfo(param.asType());
map.put(param, type_info); map.put(param, type_info);
} }
return map; return map;
} }
private static Collection<TypeInfo> getTypeInfos(ProcessingEnvironment env, TypeMap type_map, VariableElement param) { private static Collection<TypeInfo> getTypeInfos(ProcessingEnvironment env, TypeMap type_map, VariableElement param) {
List<? extends AnnotationMirror> annotations = param.getAnnotationMirrors(); List<? extends AnnotationMirror> annotations = param.getAnnotationMirrors();
GLvoid void_annotation = param.getAnnotation(GLvoid.class); GLvoid void_annotation = param.getAnnotation(GLvoid.class);
Map<Class, TypeInfo> types = new HashMap<>(); Map<Class, TypeInfo> types = new HashMap<>();
Collection<TypeInfo> multityped_result = new ArrayList<>(); Collection<TypeInfo> multityped_result = new ArrayList<>();
boolean add_default_type = true; boolean add_default_type = true;
for (AnnotationMirror annotation : annotations) { for ( AnnotationMirror annotation : annotations ) {
NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class); NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
if (native_type_annotation != null) { if ( native_type_annotation != null ) {
Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType()); Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
/*env.getMessager().printMessage(Diagnostic.Kind.NOTE, "annotation_type " + annotation_type, param, annotation);*/ /*env.getMessager().printMessage(Diagnostic.Kind.NOTE, "annotation_type " + annotation_type, param, annotation);*/
Signedness signedness = type_map.getSignednessFromType(annotation_type); Signedness signedness = type_map.getSignednessFromType(annotation_type);
Class inverse_type = type_map.getInverseType(annotation_type); Class inverse_type = type_map.getInverseType(annotation_type);
String auto_type = type_map.getAutoTypeFromAnnotation(annotation); String auto_type = type_map.getAutoTypeFromAnnotation(annotation);
if (inverse_type != null) { if ( inverse_type != null ) {
if (types.containsKey(inverse_type)) { if ( types.containsKey(inverse_type) ) {
TypeInfo inverse_type_info = types.get(inverse_type); TypeInfo inverse_type_info = types.get(inverse_type);
String inverse_auto_type = inverse_type_info.getAutoType(); String inverse_auto_type = inverse_type_info.getAutoType();
auto_type = signedness == Signedness.UNSIGNED ? auto_type + " : " + inverse_auto_type auto_type = signedness == Signedness.UNSIGNED ? auto_type + " : " + inverse_auto_type
: inverse_auto_type + " : " + auto_type; : inverse_auto_type + " : " + auto_type;
auto_type = UNSIGNED_PARAMETER_NAME + " ? " + auto_type; auto_type = UNSIGNED_PARAMETER_NAME + " ? " + auto_type;
signedness = Signedness.BOTH; signedness = Signedness.BOTH;
types.remove(inverse_type); types.remove(inverse_type);
multityped_result.remove(inverse_type_info); multityped_result.remove(inverse_type_info);
} }
} }
Class type; Class type;
TypeKind kind; TypeKind kind;
kind = void_annotation == null ? type_map.getPrimitiveTypeFromNativeType(annotation_type) : void_annotation.value(); kind = void_annotation == null ? type_map.getPrimitiveTypeFromNativeType(annotation_type) : void_annotation.value();
if (Utils.getNIOBufferType(param.asType()) != null) { if ( Utils.getNIOBufferType(param.asType()) != null ) {
type = getBufferTypeFromPrimitiveKind(kind, annotation); type = getBufferTypeFromPrimitiveKind(kind, annotation);
} else { } else {
type = getTypeFromPrimitiveKind(kind); type = getTypeFromPrimitiveKind(kind);
} }
TypeInfo type_info = new TypeInfo(type, signedness, auto_type); TypeInfo type_info = new TypeInfo(type, signedness, auto_type);
types.put(annotation_type, type_info); types.put(annotation_type, type_info);
multityped_result.add(type_info); multityped_result.add(type_info);
add_default_type = false; add_default_type = false;
} }
} }
if (add_default_type) { if ( add_default_type ) {
TypeInfo default_type_info = getDefaultTypeInfo(param.asType()); TypeInfo default_type_info = getDefaultTypeInfo(param.asType());
Collection<TypeInfo> result = new ArrayList<>(); Collection<TypeInfo> result = new ArrayList<>();
result.add(default_type_info); result.add(default_type_info);
return result; return result;
} else { } else {
return multityped_result; return multityped_result;
} }
} }
private static Map<VariableElement, Collection<TypeInfo>> getTypeInfoMap(ProcessingEnvironment env, TypeMap type_map, ExecutableElement method) { private static Map<VariableElement, Collection<TypeInfo>> getTypeInfoMap(ProcessingEnvironment env, TypeMap type_map, ExecutableElement method) {
Map<VariableElement, Collection<TypeInfo>> map = new HashMap<>(); Map<VariableElement, Collection<TypeInfo>> map = new HashMap<>();
for (VariableElement param : method.getParameters()) { for ( VariableElement param : method.getParameters() ) {
Collection<TypeInfo> types = getTypeInfos(env, type_map, param); Collection<TypeInfo> types = getTypeInfos(env, type_map, param);
map.put(param, types); map.put(param, types);
} }
return map; return map;
} }
public static Collection<Map<VariableElement, TypeInfo>> getTypeInfoCrossProduct(ProcessingEnvironment env, TypeMap type_map, ExecutableElement method) { public static Collection<Map<VariableElement, TypeInfo>> getTypeInfoCrossProduct(ProcessingEnvironment env, TypeMap type_map, ExecutableElement method) {
List<? extends VariableElement> parameter_collection = method.getParameters(); List<? extends VariableElement> parameter_collection = method.getParameters();
Collection<Map<VariableElement, TypeInfo>> cross_product = new ArrayList<>(); Collection<Map<VariableElement, TypeInfo>> cross_product = new ArrayList<>();
getCrossProductRecursive(0, parameter_collection, getTypeInfoMap(env, type_map, method), getCrossProductRecursive(0, parameter_collection, getTypeInfoMap(env, type_map, method),
new HashMap<VariableElement, TypeInfo>(), cross_product); new HashMap<VariableElement, TypeInfo>(), cross_product);
return cross_product; return cross_product;
} }
private static void getCrossProductRecursive(int index, List<? extends VariableElement> parameters, Map<VariableElement, Collection<TypeInfo>> typeinfos_map, Map<VariableElement, TypeInfo> current_instance, Collection<Map<VariableElement, TypeInfo>> cross_product) { private static void getCrossProductRecursive(int index, List<? extends VariableElement> parameters, Map<VariableElement, Collection<TypeInfo>> typeinfos_map, Map<VariableElement, TypeInfo> current_instance, Collection<Map<VariableElement, TypeInfo>> cross_product) {
if (index == parameters.size()) { if ( index == parameters.size() ) {
/** /**
* the last parameter is treated as multi-type only * the last parameter is treated as multi-type only
*/ */
cross_product.add(current_instance); cross_product.add(current_instance);
return; return;
} }
VariableElement param = parameters.get(index); VariableElement param = parameters.get(index);
Collection<TypeInfo> typeinfos = typeinfos_map.get(param); Collection<TypeInfo> typeinfos = typeinfos_map.get(param);
if (typeinfos != null) { if ( typeinfos != null ) {
for (TypeInfo typeinfo : typeinfos) { for ( TypeInfo typeinfo : typeinfos ) {
Map<VariableElement, TypeInfo> instance = new HashMap<>(current_instance); Map<VariableElement, TypeInfo> instance = new HashMap<>(current_instance);
instance.put(param, typeinfo); instance.put(param, typeinfo);
getCrossProductRecursive(index + 1, parameters, typeinfos_map, instance, cross_product); getCrossProductRecursive(index + 1, parameters, typeinfos_map, instance, cross_product);
} }
} }
} }
} }

View File

@ -41,8 +41,7 @@ package org.lwjgl.util.generator;
* $Id$ * $Id$
*/ */
import java.io.PrintWriter;
import java.io.*;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;

View File

@ -41,9 +41,8 @@ package org.lwjgl.util.generator;
* $Id$ * $Id$
*/ */
import java.io.PrintWriter;
import java.io.*; import java.util.Collection;
import java.util.*;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement; import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
@ -64,7 +63,7 @@ public class TypedefsGenerator {
} }
private static void generateNativeTypedefsParameters(TypeMap type_map, PrintWriter writer, Collection<? extends VariableElement> params) { private static void generateNativeTypedefsParameters(TypeMap type_map, PrintWriter writer, Collection<? extends VariableElement> params) {
if (params.size() > 0) { if ( params.size() > 0 ) {
boolean first = true; boolean first = true;
for ( VariableElement param : params ) { for ( VariableElement param : params ) {
if ( param.getAnnotation(Helper.class) != null ) if ( param.getAnnotation(Helper.class) != null )
@ -84,13 +83,13 @@ public class TypedefsGenerator {
NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param); NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
param.asType().accept(translator, null); param.asType().accept(translator, null);
writer.print(translator.getSignature()); writer.print(translator.getSignature());
if (param.getAnnotation(Result.class) != null || param.getAnnotation(Indirect.class) != null || param.getAnnotation(PointerArray.class) != null) if ( param.getAnnotation(Result.class) != null || param.getAnnotation(Indirect.class) != null || param.getAnnotation(PointerArray.class) != null )
writer.print("*"); writer.print("*");
writer.print(" " + param.getSimpleName()); writer.print(" " + param.getSimpleName());
} }
public static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, Collection<? extends ExecutableElement> methods) { public static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, Collection<? extends ExecutableElement> methods) {
for (ExecutableElement method : methods) { for ( ExecutableElement method : methods ) {
if ( method.getAnnotation(Alternate.class) == null && method.getAnnotation(Reuse.class) == null ) if ( method.getAnnotation(Alternate.class) == null && method.getAnnotation(Reuse.class) == null )
generateNativeTypedefs(type_map, writer, method); generateNativeTypedefs(type_map, writer, method);
} }

View File

@ -38,54 +38,50 @@ package org.lwjgl.util.generator;
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ $Id$ * @version $Revision$ $Id$
*/ */
import java.io.PrintWriter;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.*;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVisitor;
import javax.lang.model.util.ElementFilter;
import javax.tools.Diagnostic;
import org.lwjgl.PointerBuffer; import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.opengl.GLboolean; import org.lwjgl.util.generator.opengl.GLboolean;
import org.lwjgl.util.generator.opengl.GLchar; import org.lwjgl.util.generator.opengl.GLchar;
import org.lwjgl.util.generator.opengl.GLcharARB; import org.lwjgl.util.generator.opengl.GLcharARB;
import org.lwjgl.util.generator.opengl.GLreturn; import org.lwjgl.util.generator.opengl.GLreturn;
import java.io.PrintWriter;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.*;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.*;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVisitor;
import javax.lang.model.util.ElementFilter;
public class Utils { public class Utils {
public static final String TYPEDEF_POSTFIX = "PROC"; public static final String TYPEDEF_POSTFIX = "PROC";
public static final String FUNCTION_POINTER_VAR_NAME = "function_pointer"; public static final String FUNCTION_POINTER_VAR_NAME = "function_pointer";
public static final String FUNCTION_POINTER_POSTFIX = "_pointer"; public static final String FUNCTION_POINTER_POSTFIX = "_pointer";
public static final String CHECKS_CLASS_NAME = "GLChecks"; public static final String CHECKS_CLASS_NAME = "GLChecks";
public static final String CONTEXT_CAPS_CLASS_NAME = "ContextCapabilities"; public static final String CONTEXT_CAPS_CLASS_NAME = "ContextCapabilities";
public static final String STUB_INITIALIZER_NAME = "initNativeStubs"; public static final String STUB_INITIALIZER_NAME = "initNativeStubs";
public static final String BUFFER_OBJECT_METHOD_POSTFIX = "BO"; public static final String BUFFER_OBJECT_METHOD_POSTFIX = "BO";
public static final String BUFFER_OBJECT_PARAMETER_POSTFIX = "_buffer_offset"; public static final String BUFFER_OBJECT_PARAMETER_POSTFIX = "_buffer_offset";
public static final String RESULT_SIZE_NAME = "result_size"; public static final String RESULT_SIZE_NAME = "result_size";
public static final String RESULT_VAR_NAME = "__result"; public static final String RESULT_VAR_NAME = "__result";
public static final String CACHED_BUFFER_LENGTH_NAME = "length"; public static final String CACHED_BUFFER_LENGTH_NAME = "length";
public static final String CACHED_BUFFER_NAME = "old_buffer"; public static final String CACHED_BUFFER_NAME = "old_buffer";
private static final String OVERLOADED_METHOD_PREFIX = "n"; private static final String OVERLOADED_METHOD_PREFIX = "n";
public static String getTypedefName(ExecutableElement method) { public static String getTypedefName(ExecutableElement method) {
Alternate alt_annotation = method.getAnnotation(Alternate.class); Alternate alt_annotation = method.getAnnotation(Alternate.class);
return (alt_annotation == null ? method.getSimpleName() : alt_annotation.value()) + TYPEDEF_POSTFIX; return (alt_annotation == null ? method.getSimpleName() : alt_annotation.value()) + TYPEDEF_POSTFIX;
} }
public static String getFunctionAddressName(TypeElement interface_decl, ExecutableElement method) { public static String getFunctionAddressName(TypeElement interface_decl, ExecutableElement method) {
return getFunctionAddressName(interface_decl, method, false); return getFunctionAddressName(interface_decl, method, false);
} }
public static String getFunctionAddressName(TypeElement interface_decl, ExecutableElement method, boolean forceAlt) { public static String getFunctionAddressName(TypeElement interface_decl, ExecutableElement method, boolean forceAlt) {
final Alternate alt_annotation = method.getAnnotation(Alternate.class); final Alternate alt_annotation = method.getAnnotation(Alternate.class);
/* Removed prefix so that we can identify reusable entry points, removed postfix because it's not needed and looks nicer. /* Removed prefix so that we can identify reusable entry points, removed postfix because it's not needed and looks nicer.
String interfaceName = interface_decl.getSimpleName(); // If we add this back, we need to fix @Reuse (add a param for the template name) String interfaceName = interface_decl.getSimpleName(); // If we add this back, we need to fix @Reuse (add a param for the template name)
@ -94,146 +90,146 @@ public class Utils {
else else
return interfaceName + "_" + alt_annotation.value() + FUNCTION_POINTER_POSTFIX; return interfaceName + "_" + alt_annotation.value() + FUNCTION_POINTER_POSTFIX;
*/ */
if (alt_annotation == null || (alt_annotation.nativeAlt() && !forceAlt)) { if ( alt_annotation == null || (alt_annotation.nativeAlt() && !forceAlt) ) {
return method.getSimpleName().toString(); return method.getSimpleName().toString();
} else { } else {
return alt_annotation.value(); return alt_annotation.value();
} }
} }
public static boolean isFinal(Element d) { public static boolean isFinal(Element d) {
Extension extension_annotation = d.getAnnotation(Extension.class); Extension extension_annotation = d.getAnnotation(Extension.class);
return extension_annotation == null || extension_annotation.isFinal(); return extension_annotation == null || extension_annotation.isFinal();
} }
private static class AnnotationMirrorComparator implements Comparator<AnnotationMirror> { private static class AnnotationMirrorComparator implements Comparator<AnnotationMirror> {
/** /**
* Sort annotations. * Sort annotations.
*/ */
@Override @Override
public int compare(AnnotationMirror a1, AnnotationMirror a2) { public int compare(AnnotationMirror a1, AnnotationMirror a2) {
String n1 = a1.getAnnotationType().toString(); String n1 = a1.getAnnotationType().toString();
String n2 = a2.getAnnotationType().toString(); String n2 = a2.getAnnotationType().toString();
int result = n1.compareTo(n2); int result = n1.compareTo(n2);
return result; return result;
} }
public boolean equals(AnnotationMirror a1, AnnotationMirror a2) { public boolean equals(AnnotationMirror a1, AnnotationMirror a2) {
return compare(a1, a2) == 0; return compare(a1, a2) == 0;
} }
} }
public static List<AnnotationMirror> getSortedAnnotations(List<? extends AnnotationMirror> annotations) { public static List<AnnotationMirror> getSortedAnnotations(List<? extends AnnotationMirror> annotations) {
List<AnnotationMirror> annotation_list = new ArrayList<>(annotations); List<AnnotationMirror> annotation_list = new ArrayList<>(annotations);
Collections.sort(annotation_list, new AnnotationMirrorComparator()); Collections.sort(annotation_list, new AnnotationMirrorComparator());
return annotation_list; return annotation_list;
} }
public static String getReferenceName(TypeElement interface_decl, ExecutableElement method, VariableElement param) { public static String getReferenceName(TypeElement interface_decl, ExecutableElement method, VariableElement param) {
return interface_decl.getSimpleName() + "_" + method.getSimpleName() + "_" + param.getSimpleName(); return interface_decl.getSimpleName() + "_" + method.getSimpleName() + "_" + param.getSimpleName();
} }
public static boolean isAddressableType(TypeMirror type) { public static boolean isAddressableType(TypeMirror type) {
return isAddressableType(getJavaType(type)); return isAddressableType(getJavaType(type));
} }
public static boolean isAddressableType(Class type) { public static boolean isAddressableType(Class type) {
if (type.isArray()) { if ( type.isArray() ) {
final Class component_type = type.getComponentType(); final Class component_type = type.getComponentType();
return isAddressableTypeImpl(component_type) || org.lwjgl.PointerWrapper.class.isAssignableFrom(component_type); return isAddressableTypeImpl(component_type) || org.lwjgl.PointerWrapper.class.isAssignableFrom(component_type);
} }
return isAddressableTypeImpl(type); return isAddressableTypeImpl(type);
} }
private static boolean isAddressableTypeImpl(Class type) { private static boolean isAddressableTypeImpl(Class type) {
return Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) || CharSequence.class.isAssignableFrom(type); return Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) || CharSequence.class.isAssignableFrom(type);
} }
public static Class getJavaType(TypeMirror type_mirror) { public static Class getJavaType(TypeMirror type_mirror) {
JavaTypeTranslator translator = new JavaTypeTranslator(); JavaTypeTranslator translator = new JavaTypeTranslator();
type_mirror.accept((TypeVisitor) translator, null); type_mirror.accept((TypeVisitor)translator, null);
return translator.getType(); return translator.getType();
} }
private static boolean hasParameterMultipleTypes(VariableElement param) { private static boolean hasParameterMultipleTypes(VariableElement param) {
int num_native_annotations = 0; int num_native_annotations = 0;
for (AnnotationMirror annotation : param.getAnnotationMirrors()) { for ( AnnotationMirror annotation : param.getAnnotationMirrors() ) {
if (NativeTypeTranslator.getAnnotation(annotation, NativeType.class) != null) { if ( NativeTypeTranslator.getAnnotation(annotation, NativeType.class) != null ) {
num_native_annotations++; num_native_annotations++;
} }
} }
return num_native_annotations > 1; return num_native_annotations > 1;
} }
public static boolean isParameterMultiTyped(VariableElement param) { public static boolean isParameterMultiTyped(VariableElement param) {
boolean result = Buffer.class.equals(Utils.getJavaType(param.asType())); boolean result = Buffer.class.equals(Utils.getJavaType(param.asType()));
if (!result && hasParameterMultipleTypes(param)) { if ( !result && hasParameterMultipleTypes(param) ) {
throw new RuntimeException(param + " not defined as java.nio.Buffer but has multiple types"); throw new RuntimeException(param + " not defined as java.nio.Buffer but has multiple types");
} }
return result; return result;
} }
public static VariableElement findParameter(ExecutableElement method, String name) { public static VariableElement findParameter(ExecutableElement method, String name) {
for (VariableElement param : method.getParameters()) { for ( VariableElement param : method.getParameters() ) {
if (param.getSimpleName().toString().equals(name)) { if ( param.getSimpleName().toString().equals(name) ) {
return param; return param;
} }
} }
throw new RuntimeException("Parameter " + name + " not found"); throw new RuntimeException("Parameter " + name + " not found");
} }
public static void printDocComment(PrintWriter writer, Element decl, ProcessingEnvironment pe) { public static void printDocComment(PrintWriter writer, Element decl, ProcessingEnvironment pe) {
final String overloadsComment; final String overloadsComment;
if ((decl instanceof ExecutableElement) && decl.getAnnotation(Alternate.class) != null) { if ( (decl instanceof ExecutableElement) && decl.getAnnotation(Alternate.class) != null ) {
overloadsComment = "Overloads " + decl.getAnnotation(Alternate.class).value() + "."; overloadsComment = "Overloads " + decl.getAnnotation(Alternate.class).value() + ".";
} else { } else {
overloadsComment = null; overloadsComment = null;
} }
String doc_comment = pe.getElementUtils().getDocComment(decl); String doc_comment = pe.getElementUtils().getDocComment(decl);
if (doc_comment != null) { if ( doc_comment != null ) {
final String tab = (decl instanceof TypeElement) ? "" : "\t"; final String tab = (decl instanceof TypeElement) ? "" : "\t";
writer.println(tab + "/**"); writer.println(tab + "/**");
if (overloadsComment != null) { if ( overloadsComment != null ) {
writer.println("\t * " + overloadsComment); writer.println("\t * " + overloadsComment);
writer.println("\t * <p>"); writer.println("\t * <p>");
} }
final StringTokenizer doc_lines = new StringTokenizer(doc_comment, "\n", true); final StringTokenizer doc_lines = new StringTokenizer(doc_comment, "\n", true);
boolean lastWasNL = false; boolean lastWasNL = false;
while (doc_lines.hasMoreTokens()) { while ( doc_lines.hasMoreTokens() ) {
final String t = doc_lines.nextToken(); final String t = doc_lines.nextToken();
if ("\n".equals(t)) { if ( "\n".equals(t) ) {
if (lastWasNL) { if ( lastWasNL ) {
writer.println(tab + " * <p>"); writer.println(tab + " * <p>");
} }
lastWasNL = true; lastWasNL = true;
} else { } else {
writer.println(tab + " * " + t); writer.println(tab + " * " + t);
lastWasNL = false; lastWasNL = false;
} }
} }
writer.println(tab + " */"); writer.println(tab + " */");
} else if (overloadsComment != null) { } else if ( overloadsComment != null ) {
writer.println("\t/** " + overloadsComment + " */"); writer.println("\t/** " + overloadsComment + " */");
} }
} }
public static AnnotationMirror getParameterAutoAnnotation(VariableElement param) { public static AnnotationMirror getParameterAutoAnnotation(VariableElement param) {
for (AnnotationMirror annotation : param.getAnnotationMirrors()) { for ( AnnotationMirror annotation : param.getAnnotationMirrors() ) {
if (NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null) { if ( NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null ) {
return annotation; return annotation;
} }
} }
return null; return null;
} }
// DISABLED: We always generate indirect methods. (affects OpenAL only at the time of this change) // DISABLED: We always generate indirect methods. (affects OpenAL only at the time of this change)
public static boolean isMethodIndirect(boolean generate_error_checks, boolean context_specific, ExecutableElement method) { public static boolean isMethodIndirect(boolean generate_error_checks, boolean context_specific, ExecutableElement method) {
/* /*
for (VariableElement param : method.getParameters()) { for (VariableElement param : method.getParameters()) {
if (isAddressableType(param.getType()) || getParameterAutoAnnotation(param) != null || if (isAddressableType(param.getType()) || getParameterAutoAnnotation(param) != null ||
param.getAnnotation(Constant.class) != null) param.getAnnotation(Constant.class) != null)
@ -244,266 +240,266 @@ public class Utils {
(generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null) || (generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null) ||
context_specific; context_specific;
*/ */
return true; return true;
} }
public static String getNativeQualifiedName(String qualified_name) { public static String getNativeQualifiedName(String qualified_name) {
return qualified_name.replaceAll("\\.", "_"); return qualified_name.replaceAll("\\.", "_");
} }
public static String getQualifiedNativeMethodName(String qualified_class_name, String method_name) { public static String getQualifiedNativeMethodName(String qualified_class_name, String method_name) {
// Escape '_' in method name // Escape '_' in method name
if (method_name.indexOf('_') != -1) { if ( method_name.indexOf('_') != -1 ) {
method_name = method_name.replace("_", "_1"); method_name = method_name.replace("_", "_1");
} }
return "Java_" + getNativeQualifiedName(qualified_class_name) + "_" + method_name; return "Java_" + getNativeQualifiedName(qualified_class_name) + "_" + method_name;
} }
public static String getQualifiedNativeMethodName(String qualified_class_name, ExecutableElement method, boolean generate_error_checks, boolean context_specific) { public static String getQualifiedNativeMethodName(String qualified_class_name, ExecutableElement method, boolean generate_error_checks, boolean context_specific) {
String method_name = getSimpleNativeMethodName(method, generate_error_checks, context_specific); String method_name = getSimpleNativeMethodName(method, generate_error_checks, context_specific);
return getQualifiedNativeMethodName(qualified_class_name, method_name); return getQualifiedNativeMethodName(qualified_class_name, method_name);
} }
public static VariableElement getResultParameter(ExecutableElement method) { public static VariableElement getResultParameter(ExecutableElement method) {
VariableElement result_param = null; VariableElement result_param = null;
for (VariableElement param : method.getParameters()) { for ( VariableElement param : method.getParameters() ) {
if (param.getAnnotation(Result.class) != null) { if ( param.getAnnotation(Result.class) != null ) {
if (result_param != null) { if ( result_param != null ) {
throw new RuntimeException("Multiple parameters annotated with Result in method " + method); throw new RuntimeException("Multiple parameters annotated with Result in method " + method);
} }
result_param = param; result_param = param;
} }
} }
return result_param; return result_param;
} }
public static TypeMirror getMethodReturnType(ExecutableElement method) { public static TypeMirror getMethodReturnType(ExecutableElement method) {
TypeMirror result_type; TypeMirror result_type;
VariableElement result_param = getResultParameter(method); VariableElement result_param = getResultParameter(method);
if (result_param != null) { if ( result_param != null ) {
result_type = result_param.asType(); result_type = result_param.asType();
} else { } else {
result_type = method.getReturnType(); result_type = method.getReturnType();
} }
return result_type; return result_type;
} }
public static String getMethodReturnType(ExecutableElement method, GLreturn return_annotation, boolean buffer) { public static String getMethodReturnType(ExecutableElement method, GLreturn return_annotation, boolean buffer) {
VariableElement return_param = null; VariableElement return_param = null;
for (VariableElement param : method.getParameters()) { for ( VariableElement param : method.getParameters() ) {
if (param.getSimpleName().toString().equals(return_annotation.value())) { if ( param.getSimpleName().toString().equals(return_annotation.value()) ) {
return_param = param; return_param = param;
break; break;
} }
} }
if (return_param == null) { if ( return_param == null ) {
throw new RuntimeException("The @GLreturn parameter \"" + return_annotation.value() + "\" could not be found in method: " + method); throw new RuntimeException("The @GLreturn parameter \"" + return_annotation.value() + "\" could not be found in method: " + method);
} }
TypeKind kind = NativeTypeTranslator.getPrimitiveKindFromBufferClass(Utils.getJavaType(return_param.asType())); TypeKind kind = NativeTypeTranslator.getPrimitiveKindFromBufferClass(Utils.getJavaType(return_param.asType()));
if (return_param.getAnnotation(GLboolean.class) != null) { if ( return_param.getAnnotation(GLboolean.class) != null ) {
kind = TypeKind.BOOLEAN; kind = TypeKind.BOOLEAN;
} }
if (kind == TypeKind.BYTE && (return_param.getAnnotation(GLchar.class) != null || return_param.getAnnotation(GLcharARB.class) != null)) { if ( kind == TypeKind.BYTE && (return_param.getAnnotation(GLchar.class) != null || return_param.getAnnotation(GLcharARB.class) != null) ) {
return "String"; return "String";
} else { } else {
final String type = JavaTypeTranslator.getPrimitiveClassFromKind(kind).getName(); final String type = JavaTypeTranslator.getPrimitiveClassFromKind(kind).getName();
return buffer ? Character.toUpperCase(type.charAt(0)) + type.substring(1) : type; return buffer ? Character.toUpperCase(type.charAt(0)) + type.substring(1) : type;
} }
} }
public static boolean needResultSize(ExecutableElement method) { public static boolean needResultSize(ExecutableElement method) {
return getNIOBufferType(getMethodReturnType(method)) != null && method.getAnnotation(AutoSize.class) == null; return getNIOBufferType(getMethodReturnType(method)) != null && method.getAnnotation(AutoSize.class) == null;
} }
public static void printExtraCallArguments(PrintWriter writer, ExecutableElement method, String size_parameter_name) { public static void printExtraCallArguments(PrintWriter writer, ExecutableElement method, String size_parameter_name) {
writer.print(size_parameter_name); writer.print(size_parameter_name);
if (method.getAnnotation(CachedResult.class) != null) { if ( method.getAnnotation(CachedResult.class) != null ) {
writer.print(", " + CACHED_BUFFER_NAME); writer.print(", " + CACHED_BUFFER_NAME);
} }
} }
private static String getClassName(TypeElement interface_decl, String opengl_name) { private static String getClassName(TypeElement interface_decl, String opengl_name) {
Extension extension_annotation = interface_decl.getAnnotation(Extension.class); Extension extension_annotation = interface_decl.getAnnotation(Extension.class);
if (extension_annotation != null && !"".equals(extension_annotation.className())) { if ( extension_annotation != null && !"".equals(extension_annotation.className()) ) {
return extension_annotation.className(); return extension_annotation.className();
} }
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
for (int i = 0; i < opengl_name.length(); i++) { for ( int i = 0; i < opengl_name.length(); i++ ) {
int ch = opengl_name.codePointAt(i); int ch = opengl_name.codePointAt(i);
if (ch == '_') { if ( ch == '_' ) {
i++; i++;
result.appendCodePoint(Character.toUpperCase(opengl_name.codePointAt(i))); result.appendCodePoint(Character.toUpperCase(opengl_name.codePointAt(i)));
} else { } else {
result.appendCodePoint(ch); result.appendCodePoint(ch);
} }
} }
return result.toString(); return result.toString();
} }
public static boolean hasMethodBufferObjectParameter(ExecutableElement method) { public static boolean hasMethodBufferObjectParameter(ExecutableElement method) {
for (VariableElement param : method.getParameters()) { for ( VariableElement param : method.getParameters() ) {
if (param.getAnnotation(BufferObject.class) != null) { if ( param.getAnnotation(BufferObject.class) != null ) {
return true; return true;
} }
} }
return false; return false;
} }
public static String getQualifiedClassName(TypeElement interface_decl) { public static String getQualifiedClassName(TypeElement interface_decl) {
return interface_decl.getEnclosingElement().asType().toString() + "." + getSimpleClassName(interface_decl); return interface_decl.getEnclosingElement().asType().toString() + "." + getSimpleClassName(interface_decl);
} }
public static String getSimpleClassName(TypeElement interface_decl) { public static String getSimpleClassName(TypeElement interface_decl) {
return getClassName(interface_decl, interface_decl.getSimpleName().toString()); return getClassName(interface_decl, interface_decl.getSimpleName().toString());
} }
public static Class<?> getNIOBufferType(TypeMirror t) { public static Class<?> getNIOBufferType(TypeMirror t) {
Class<?> param_type = getJavaType(t); Class<?> param_type = getJavaType(t);
if (Buffer.class.isAssignableFrom(param_type)) { if ( Buffer.class.isAssignableFrom(param_type) ) {
return param_type; return param_type;
} else if (param_type == CharSequence.class || param_type == CharSequence[].class || param_type == PointerBuffer.class) { } else if ( param_type == CharSequence.class || param_type == CharSequence[].class || param_type == PointerBuffer.class ) {
return ByteBuffer.class; return ByteBuffer.class;
} else { } else {
return null; return null;
} }
} }
public static String getSimpleNativeMethodName(ExecutableElement method, boolean generate_error_checks, boolean context_specific) { public static String getSimpleNativeMethodName(ExecutableElement method, boolean generate_error_checks, boolean context_specific) {
String method_name; String method_name;
Alternate alt_annotation = method.getAnnotation(Alternate.class); Alternate alt_annotation = method.getAnnotation(Alternate.class);
method_name = alt_annotation == null || alt_annotation.nativeAlt() ? method.getSimpleName().toString() : alt_annotation.value(); method_name = alt_annotation == null || alt_annotation.nativeAlt() ? method.getSimpleName().toString() : alt_annotation.value();
if (isMethodIndirect(generate_error_checks, context_specific, method)) { if ( isMethodIndirect(generate_error_checks, context_specific, method) ) {
method_name = OVERLOADED_METHOD_PREFIX + method_name; method_name = OVERLOADED_METHOD_PREFIX + method_name;
} }
return method_name; return method_name;
} }
static boolean isReturnParameter(ExecutableElement method, VariableElement param) { static boolean isReturnParameter(ExecutableElement method, VariableElement param) {
GLreturn string_annotation = method.getAnnotation(GLreturn.class); GLreturn string_annotation = method.getAnnotation(GLreturn.class);
if (string_annotation == null || !string_annotation.value().equals(param.getSimpleName().toString())) { if ( string_annotation == null || !string_annotation.value().equals(param.getSimpleName().toString()) ) {
return false; return false;
} }
if (param.getAnnotation(OutParameter.class) == null) { if ( param.getAnnotation(OutParameter.class) == null ) {
throw new RuntimeException("The parameter specified in @GLreturn is not annotated with @OutParameter in method: " + method); throw new RuntimeException("The parameter specified in @GLreturn is not annotated with @OutParameter in method: " + method);
} }
if (param.getAnnotation(Check.class) != null) { if ( param.getAnnotation(Check.class) != null ) {
throw new RuntimeException("The parameter specified in @GLreturn is annotated with @Check in method: " + method); throw new RuntimeException("The parameter specified in @GLreturn is annotated with @Check in method: " + method);
} }
if (param.getAnnotation(GLchar.class) != null && Utils.getJavaType(param.asType()).equals(ByteBuffer.class) && string_annotation.maxLength().length() == 0) { if ( param.getAnnotation(GLchar.class) != null && Utils.getJavaType(param.asType()).equals(ByteBuffer.class) && string_annotation.maxLength().length() == 0 ) {
throw new RuntimeException("The @GLreturn annotation is missing a maxLength parameter in method: " + method); throw new RuntimeException("The @GLreturn annotation is missing a maxLength parameter in method: " + method);
} }
return true; return true;
} }
static String getStringOffset(ExecutableElement method, VariableElement param) { static String getStringOffset(ExecutableElement method, VariableElement param) {
String offset = null; String offset = null;
for (VariableElement p : method.getParameters()) { for ( VariableElement p : method.getParameters() ) {
if (param != null && p.getSimpleName().equals(param.getSimpleName())) { if ( param != null && p.getSimpleName().equals(param.getSimpleName()) ) {
break; break;
} }
if (p.getAnnotation(NullTerminated.class) != null) { if ( p.getAnnotation(NullTerminated.class) != null ) {
continue; continue;
} }
final Class type = Utils.getJavaType(p.asType()); final Class type = Utils.getJavaType(p.asType());
if (type.equals(CharSequence.class)) { if ( type.equals(CharSequence.class) ) {
if (offset == null) { if ( offset == null ) {
offset = p.getSimpleName() + ".length()"; offset = p.getSimpleName() + ".length()";
} else { } else {
offset += " + " + p.getSimpleName() + ".length()"; offset += " + " + p.getSimpleName() + ".length()";
} }
//if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + 1"; //if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + 1";
} else if (type.equals(CharSequence[].class)) { } else if ( type.equals(CharSequence[].class) ) {
if (offset == null) { if ( offset == null ) {
offset = "APIUtil.getTotalLength(" + p.getSimpleName() + ")"; offset = "APIUtil.getTotalLength(" + p.getSimpleName() + ")";
} else { } else {
offset += " + APIUtil.getTotalLength(" + p.getSimpleName() + ")"; offset += " + APIUtil.getTotalLength(" + p.getSimpleName() + ")";
} }
//if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + " + p.getSimpleName() + ".length"; //if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + " + p.getSimpleName() + ".length";
} }
} }
return offset; return offset;
} }
static void printGLReturnPre(PrintWriter writer, ExecutableElement method, GLreturn return_annotation, TypeMap type_map) { static void printGLReturnPre(PrintWriter writer, ExecutableElement method, GLreturn return_annotation, TypeMap type_map) {
final String return_type = getMethodReturnType(method, return_annotation, true); final String return_type = getMethodReturnType(method, return_annotation, true);
if ("String".equals(return_type)) { if ( "String".equals(return_type) ) {
if (!return_annotation.forceMaxLength()) { if ( !return_annotation.forceMaxLength() ) {
writer.println("IntBuffer " + return_annotation.value() + "_length = APIUtil.getLengths(" + type_map.getAPIUtilParam(false) + ");"); writer.println("IntBuffer " + return_annotation.value() + "_length = APIUtil.getLengths(" + type_map.getAPIUtilParam(false) + ");");
writer.print("\t\t"); writer.print("\t\t");
} }
writer.print("ByteBuffer " + return_annotation.value() + " = APIUtil.getBufferByte(" + type_map.getAPIUtilParam(true) + return_annotation.maxLength()); writer.print("ByteBuffer " + return_annotation.value() + " = APIUtil.getBufferByte(" + type_map.getAPIUtilParam(true) + return_annotation.maxLength());
/* /*
Params that use the return buffer will advance its position while filling it. When we return, the position will be Params that use the return buffer will advance its position while filling it. When we return, the position will be
at the right spot for grabbing the returned string bytes. We only have to make sure that the original buffer was at the right spot for grabbing the returned string bytes. We only have to make sure that the original buffer was
large enough to hold everything, so that no re-allocations happen while filling. large enough to hold everything, so that no re-allocations happen while filling.
*/ */
final String offset = getStringOffset(method, null); final String offset = getStringOffset(method, null);
if (offset != null) { if ( offset != null ) {
writer.print(" + " + offset); writer.print(" + " + offset);
} }
writer.println(");"); writer.println(");");
} else { } else {
final String buffer_type = "Boolean".equals(return_type) ? "Byte" : return_type; final String buffer_type = "Boolean".equals(return_type) ? "Byte" : return_type;
writer.print(buffer_type + "Buffer " + return_annotation.value() + " = APIUtil.getBuffer" + buffer_type + "(" + type_map.getAPIUtilParam(false)); writer.print(buffer_type + "Buffer " + return_annotation.value() + " = APIUtil.getBuffer" + buffer_type + "(" + type_map.getAPIUtilParam(false));
if ("Byte".equals(buffer_type)) { if ( "Byte".equals(buffer_type) ) {
writer.print((type_map.getAPIUtilParam(false).length() > 0 ? ", " : "") + "1"); writer.print((type_map.getAPIUtilParam(false).length() > 0 ? ", " : "") + "1");
} }
writer.println(");"); writer.println(");");
} }
final Code code_annotation = method.getAnnotation(Code.class); final Code code_annotation = method.getAnnotation(Code.class);
if (code_annotation != null && code_annotation.tryBlock()) { if ( code_annotation != null && code_annotation.tryBlock() ) {
writer.println("\t\ttry {"); writer.println("\t\ttry {");
writer.print("\t\t\t"); writer.print("\t\t\t");
} else { } else {
writer.print("\t\t"); writer.print("\t\t");
} }
} }
static void printGLReturnPost(PrintWriter writer, ExecutableElement method, GLreturn return_annotation, TypeMap type_map) { static void printGLReturnPost(PrintWriter writer, ExecutableElement method, GLreturn return_annotation, TypeMap type_map) {
final String return_type = getMethodReturnType(method, return_annotation, true); final String return_type = getMethodReturnType(method, return_annotation, true);
if ("String".equals(return_type)) { if ( "String".equals(return_type) ) {
writer.print("\t\t" + return_annotation.value() + ".limit("); writer.print("\t\t" + return_annotation.value() + ".limit(");
final String offset = getStringOffset(method, null); final String offset = getStringOffset(method, null);
if (offset != null) { if ( offset != null ) {
writer.print(offset + " + "); writer.print(offset + " + ");
} }
if (return_annotation.forceMaxLength()) { if ( return_annotation.forceMaxLength() ) {
writer.print(return_annotation.maxLength()); writer.print(return_annotation.maxLength());
} else { } else {
writer.print(return_annotation.value() + "_length.get(0)"); writer.print(return_annotation.value() + "_length.get(0)");
} }
writer.println(");"); writer.println(");");
writer.println("\t\treturn APIUtil.getString(" + type_map.getAPIUtilParam(true) + return_annotation.value() + ");"); writer.println("\t\treturn APIUtil.getString(" + type_map.getAPIUtilParam(true) + return_annotation.value() + ");");
} else { } else {
writer.print("\t\treturn " + return_annotation.value() + ".get(0)"); writer.print("\t\treturn " + return_annotation.value() + ".get(0)");
if ("Boolean".equals(return_type)) { if ( "Boolean".equals(return_type) ) {
writer.print(" == 1"); writer.print(" == 1");
} }
writer.println(";"); writer.println(";");
} }
} }
public static Collection<VariableElement> getFields(TypeElement d) { public static Collection<VariableElement> getFields(TypeElement d) {
Collection<VariableElement> fields = ElementFilter.fieldsIn(new HashSet(d.getEnclosedElements())); Collection<VariableElement> fields = ElementFilter.fieldsIn(new HashSet(d.getEnclosedElements()));
return fields; return fields;
} }
public static Collection<ExecutableElement> getMethods(TypeElement d) { public static Collection<ExecutableElement> getMethods(TypeElement d) {
Collection<ExecutableElement> fields = ElementFilter.methodsIn(new HashSet(d.getEnclosedElements())); Collection<ExecutableElement> fields = ElementFilter.methodsIn(new HashSet(d.getEnclosedElements()));
return fields; return fields;
} }
} }

View File

@ -41,16 +41,17 @@ package org.lwjgl.util.generator.openal;
* $Id: ALTypeMap.java 2983 2008-04-07 18:36:09Z matzon $ * $Id: ALTypeMap.java 2983 2008-04-07 18:36:09Z matzon $
*/ */
import org.lwjgl.util.generator.Signedness;
import org.lwjgl.util.generator.TypeMap;
import java.io.*; import java.io.PrintWriter;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.nio.*; import java.nio.*;
import java.util.*; import java.util.HashMap;
import java.util.Map;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import org.lwjgl.util.generator.Signedness;
import org.lwjgl.util.generator.TypeMap;
public class ALTypeMap implements TypeMap { public class ALTypeMap implements TypeMap {
private static final Map<Class, TypeKind> native_types_to_primitive; private static final Map<Class, TypeKind> native_types_to_primitive;
@ -70,52 +71,52 @@ public class ALTypeMap implements TypeMap {
native_types_to_primitive.put(ALvoid.class, TypeKind.BYTE); native_types_to_primitive.put(ALvoid.class, TypeKind.BYTE);
} }
@Override @Override
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) { public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
TypeKind kind = native_types_to_primitive.get(native_type); TypeKind kind = native_types_to_primitive.get(native_type);
if (kind == null) if ( kind == null )
throw new RuntimeException("Unsupported type " + native_type); throw new RuntimeException("Unsupported type " + native_type);
return kind; return kind;
} }
@Override @Override
public Signedness getSignednessFromType(Class type) { public Signedness getSignednessFromType(Class type) {
if (ALuint.class.equals(type)) if ( ALuint.class.equals(type) )
return Signedness.UNSIGNED; return Signedness.UNSIGNED;
else if (ALint.class.equals(type)) else if ( ALint.class.equals(type) )
return Signedness.SIGNED; return Signedness.SIGNED;
else if (ALshort.class.equals(type)) else if ( ALshort.class.equals(type) )
return Signedness.SIGNED; return Signedness.SIGNED;
else if (ALbyte.class.equals(type)) else if ( ALbyte.class.equals(type) )
return Signedness.SIGNED; return Signedness.SIGNED;
else else
return Signedness.NONE; return Signedness.NONE;
} }
@Override @Override
public String translateAnnotation(Class annotation_type) { public String translateAnnotation(Class annotation_type) {
if (annotation_type.equals(ALuint.class)) if ( annotation_type.equals(ALuint.class) )
return "i"; return "i";
else if (annotation_type.equals(ALint.class)) else if ( annotation_type.equals(ALint.class) )
return "i"; return "i";
else if (annotation_type.equals(ALshort.class)) else if ( annotation_type.equals(ALshort.class) )
return "s"; return "s";
else if (annotation_type.equals(ALbyte.class)) else if ( annotation_type.equals(ALbyte.class) )
return "b"; return "b";
else if (annotation_type.equals(ALfloat.class)) else if ( annotation_type.equals(ALfloat.class) )
return "f"; return "f";
else if (annotation_type.equals(ALdouble.class)) else if ( annotation_type.equals(ALdouble.class) )
return "d"; return "d";
else if (annotation_type.equals(ALboolean.class) || annotation_type.equals(ALvoid.class)) else if ( annotation_type.equals(ALboolean.class) || annotation_type.equals(ALvoid.class) )
return ""; return "";
else else
throw new RuntimeException(annotation_type + " is not allowed"); throw new RuntimeException(annotation_type + " is not allowed");
} }
@Override @Override
public Class getNativeTypeFromPrimitiveType(TypeKind kind) { public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
Class type; Class type;
switch (kind) { switch ( kind ) {
case INT: case INT:
type = ALint.class; type = ALint.class;
break; break;
@ -141,124 +142,124 @@ public class ALTypeMap implements TypeMap {
} }
private static Class[] getValidBufferTypes(Class type) { private static Class[] getValidBufferTypes(Class type) {
if (type.equals(IntBuffer.class)) if ( type.equals(IntBuffer.class) )
return new Class[]{ALenum.class, ALint.class, ALsizei.class, ALuint.class}; return new Class[] { ALenum.class, ALint.class, ALsizei.class, ALuint.class };
else if (type.equals(FloatBuffer.class)) else if ( type.equals(FloatBuffer.class) )
return new Class[]{ALfloat.class}; return new Class[] { ALfloat.class };
else if (type.equals(ByteBuffer.class)) else if ( type.equals(ByteBuffer.class) )
return new Class[]{ALboolean.class, ALbyte.class, ALvoid.class}; return new Class[] { ALboolean.class, ALbyte.class, ALvoid.class };
else if (type.equals(ShortBuffer.class)) else if ( type.equals(ShortBuffer.class) )
return new Class[]{ALshort.class}; return new Class[] { ALshort.class };
else if (type.equals(DoubleBuffer.class)) else if ( type.equals(DoubleBuffer.class) )
return new Class[]{ALdouble.class}; return new Class[] { ALdouble.class };
else else
return new Class[]{}; return new Class[] { };
} }
private static Class[] getValidPrimitiveTypes(Class type) { private static Class[] getValidPrimitiveTypes(Class type) {
if (type.equals(int.class)) if ( type.equals(int.class) )
return new Class[]{ALenum.class, ALint.class, ALsizei.class, ALuint.class}; return new Class[] { ALenum.class, ALint.class, ALsizei.class, ALuint.class };
else if (type.equals(double.class)) else if ( type.equals(double.class) )
return new Class[]{ALdouble.class}; return new Class[] { ALdouble.class };
else if (type.equals(float.class)) else if ( type.equals(float.class) )
return new Class[]{ALfloat.class}; return new Class[] { ALfloat.class };
else if (type.equals(short.class)) else if ( type.equals(short.class) )
return new Class[]{ALshort.class}; return new Class[] { ALshort.class };
else if (type.equals(byte.class)) else if ( type.equals(byte.class) )
return new Class[]{ALbyte.class}; return new Class[] { ALbyte.class };
else if (type.equals(boolean.class)) else if ( type.equals(boolean.class) )
return new Class[]{ALboolean.class}; return new Class[] { ALboolean.class };
else if (type.equals(void.class)) else if ( type.equals(void.class) )
return new Class[]{ALvoid.class}; return new Class[] { ALvoid.class };
else else
return new Class[]{}; return new Class[] { };
} }
@Override @Override
public void printCapabilitiesInit(final PrintWriter writer) { public void printCapabilitiesInit(final PrintWriter writer) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override @Override
public String getCapabilities() { public String getCapabilities() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override @Override
public String getAPIUtilParam(boolean comma) { public String getAPIUtilParam(boolean comma) {
return ""; return "";
} }
@Override @Override
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) { public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) {
writer.println(tabs + "Util.checkALError();"); writer.println(tabs + "Util.checkALError();");
} }
@Override @Override
public String getRegisterNativesFunctionName() { public String getRegisterNativesFunctionName() {
return "extal_InitializeClass"; return "extal_InitializeClass";
} }
@Override @Override
public String getTypedefPostfix() { public String getTypedefPostfix() {
return ""; return "";
} }
@Override @Override
public String getFunctionPrefix() { public String getFunctionPrefix() {
return "ALAPIENTRY"; return "ALAPIENTRY";
} }
@Override @Override
public void printNativeIncludes(PrintWriter writer) { public void printNativeIncludes(PrintWriter writer) {
writer.println("#include \"extal.h\""); writer.println("#include \"extal.h\"");
} }
@Override @Override
public Class<? extends Annotation> getStringElementType() { public Class<? extends Annotation> getStringElementType() {
return ALubyte.class; return ALubyte.class;
} }
@Override @Override
public Class<? extends Annotation> getStringArrayType() { public Class<? extends Annotation> getStringArrayType() {
return ALubyte.class; return ALubyte.class;
} }
@Override @Override
public Class<? extends Annotation> getByteBufferArrayType() { public Class<? extends Annotation> getByteBufferArrayType() {
return ALubyte.class; return ALubyte.class;
} }
@Override @Override
public Class[] getValidAnnotationTypes(Class type) { public Class[] getValidAnnotationTypes(Class type) {
Class[] valid_types; Class[] valid_types;
if (Buffer.class.isAssignableFrom(type)) if ( Buffer.class.isAssignableFrom(type) )
valid_types = getValidBufferTypes(type); valid_types = getValidBufferTypes(type);
else if (type.isPrimitive()) else if ( type.isPrimitive() )
valid_types = getValidPrimitiveTypes(type); valid_types = getValidPrimitiveTypes(type);
else if (type.equals(String.class)) else if ( type.equals(String.class) )
valid_types = new Class[]{ALubyte.class}; valid_types = new Class[] { ALubyte.class };
else else
valid_types = new Class[]{}; valid_types = new Class[] { };
return valid_types; return valid_types;
} }
@Override @Override
public Class<? extends Annotation> getVoidType() { public Class<? extends Annotation> getVoidType() {
return ALvoid.class; return ALvoid.class;
} }
@Override @Override
public Class<? extends Annotation> getInverseType(Class type) { public Class<? extends Annotation> getInverseType(Class type) {
if (ALuint.class.equals(type)) if ( ALuint.class.equals(type) )
return ALint.class; return ALint.class;
else if (ALint.class.equals(type)) else if ( ALint.class.equals(type) )
return ALuint.class; return ALuint.class;
else else
return null; return null;
} }
@Override @Override
public String getAutoTypeFromAnnotation(AnnotationMirror annotation) { public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
return null; return null;
} }

View File

@ -31,13 +31,14 @@
*/ */
package org.lwjgl.util.generator.opencl; package org.lwjgl.util.generator.opencl;
import org.lwjgl.util.generator.*;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import org.lwjgl.util.generator.*;
/** /**
* CLCapabilities generator. * CLCapabilities generator.
@ -46,125 +47,125 @@ import org.lwjgl.util.generator.*;
*/ */
public class CLCapabilitiesGenerator { public class CLCapabilitiesGenerator {
static void generateClassPrologue(final PrintWriter writer) { static void generateClassPrologue(final PrintWriter writer) {
writer.println("public final class " + CLGeneratorProcessor.CLCAPS_CLASS_NAME + " {"); writer.println("public final class " + CLGeneratorProcessor.CLCAPS_CLASS_NAME + " {");
writer.println(); writer.println();
} }
static void generateSymbolAddresses(ProcessingEnvironment env, final PrintWriter writer, final TypeElement d) { static void generateSymbolAddresses(ProcessingEnvironment env, final PrintWriter writer, final TypeElement d) {
if (d.getAnnotation(CLPlatformExtension.class) == null && d.getAnnotation(CLDeviceExtension.class) == null && !d.getSimpleName().toString().startsWith("CL")) { if ( d.getAnnotation(CLPlatformExtension.class) == null && d.getAnnotation(CLDeviceExtension.class) == null && !d.getSimpleName().toString().startsWith("CL") ) {
throw new RuntimeException("An OpenCL extension is missing an extension type annotation: " + d.getSimpleName()); throw new RuntimeException("An OpenCL extension is missing an extension type annotation: " + d.getSimpleName());
} }
final Alias alias_annotation = d.getAnnotation(Alias.class); final Alias alias_annotation = d.getAnnotation(Alias.class);
final boolean aliased = alias_annotation != null && alias_annotation.postfix().length() > 0; final boolean aliased = alias_annotation != null && alias_annotation.postfix().length() > 0;
boolean foundNative = false; boolean foundNative = false;
for (final ExecutableElement method : Utils.getMethods( d)) { for ( final ExecutableElement method : Utils.getMethods(d) ) {
if (method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null) { if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null ) {
continue; continue;
} }
if (!foundNative) { if ( !foundNative ) {
//writer.println("\t// " + d.getSimpleName()); //writer.println("\t// " + d.getSimpleName());
writer.println("\tstatic final boolean " + CLGeneratorProcessor.getExtensionName(d.getSimpleName().toString() + ";")); writer.println("\tstatic final boolean " + CLGeneratorProcessor.getExtensionName(d.getSimpleName().toString() + ";"));
foundNative = true; foundNative = true;
} }
writer.print("\tstatic final long " + Utils.getFunctionAddressName(d, method) + " = CL.getFunctionAddress("); writer.print("\tstatic final long " + Utils.getFunctionAddressName(d, method) + " = CL.getFunctionAddress(");
if (aliased) { if ( aliased ) {
writer.println("new String [] {\"" + Utils.getFunctionAddressName(d, method) + "\",\"" + method.getSimpleName() + alias_annotation.postfix() + "\"});"); writer.println("new String [] {\"" + Utils.getFunctionAddressName(d, method) + "\",\"" + method.getSimpleName() + alias_annotation.postfix() + "\"});");
} else { } else {
writer.println("\"" + Utils.getFunctionAddressName(d, method) + "\");"); writer.println("\"" + Utils.getFunctionAddressName(d, method) + "\");");
} }
} }
if (foundNative) { if ( foundNative ) {
writer.println(); writer.println();
} }
} }
static void generateConstructor(ProcessingEnvironment env, final PrintWriter writer, final Set<? extends TypeElement> interface_decls) { static void generateConstructor(ProcessingEnvironment env, final PrintWriter writer, final Set<? extends TypeElement> interface_decls) {
writer.println("\tprivate " + CLGeneratorProcessor.CLCAPS_CLASS_NAME + "() {}"); writer.println("\tprivate " + CLGeneratorProcessor.CLCAPS_CLASS_NAME + "() {}");
writer.println(); writer.println();
writer.println("\tstatic {"); writer.println("\tstatic {");
for (final TypeElement d : interface_decls) { for ( final TypeElement d : interface_decls ) {
if (d.getKind().isInterface()) { if ( d.getKind().isInterface() ) {
if (Utils.getMethods( d).isEmpty()) { if ( Utils.getMethods(d).isEmpty() ) {
continue; continue;
} }
//writer.println("\t\tif ( " + getExtensionSupportedName(d.getSimpleName()) + "() )"); //writer.println("\t\tif ( " + getExtensionSupportedName(d.getSimpleName()) + "() )");
//writer.println("\t\t\t" + SUPPORTED_EXTS + ".add(\"" + CLGeneratorProcessor.getExtensionName(d.getSimpleName()) + "\");"); //writer.println("\t\t\t" + SUPPORTED_EXTS + ".add(\"" + CLGeneratorProcessor.getExtensionName(d.getSimpleName()) + "\");");
writer.println("\t\t" + CLGeneratorProcessor.getExtensionName(d.getSimpleName().toString()) + " = " + getExtensionSupportedName(d.getSimpleName().toString()) + "();"); writer.println("\t\t" + CLGeneratorProcessor.getExtensionName(d.getSimpleName().toString()) + " = " + getExtensionSupportedName(d.getSimpleName().toString()) + "();");
} }
} }
writer.println("\t}\n"); writer.println("\t}\n");
} }
static void generateExtensionChecks(ProcessingEnvironment env, final PrintWriter writer, TypeElement d) { static void generateExtensionChecks(ProcessingEnvironment env, final PrintWriter writer, TypeElement d) {
Iterator<? extends ExecutableElement> methods = Utils.getMethods( d).iterator(); Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
if (!methods.hasNext()) { if ( !methods.hasNext() ) {
return; return;
} }
writer.println("\tprivate static boolean " + getExtensionSupportedName(d.getSimpleName().toString()) + "() {"); writer.println("\tprivate static boolean " + getExtensionSupportedName(d.getSimpleName().toString()) + "() {");
writer.println("\t\treturn "); writer.println("\t\treturn ");
boolean first = true; boolean first = true;
while (methods.hasNext()) { while ( methods.hasNext() ) {
ExecutableElement method = methods.next(); ExecutableElement method = methods.next();
if (method.getAnnotation(Alternate.class) != null) { if ( method.getAnnotation(Alternate.class) != null ) {
continue; continue;
} }
if (!first) { if ( !first ) {
writer.println(" &"); writer.println(" &");
} else { } else {
first = false; first = false;
} }
final boolean optional = method.getAnnotation(Optional.class) != null; final boolean optional = method.getAnnotation(Optional.class) != null;
writer.print("\t\t\t"); writer.print("\t\t\t");
if (optional) { if ( optional ) {
writer.print('('); writer.print('(');
} }
writer.print(Utils.getFunctionAddressName(d, method) + " != 0"); writer.print(Utils.getFunctionAddressName(d, method) + " != 0");
if (optional) { if ( optional ) {
writer.print(" || true)"); writer.print(" || true)");
} }
} }
writer.println(";"); writer.println(";");
writer.println("\t}"); writer.println("\t}");
writer.println(); writer.println();
} }
private static String getExtensionSupportedName(final String class_name) { private static String getExtensionSupportedName(final String class_name) {
return "is" + class_name + "Supported"; return "is" + class_name + "Supported";
} }
public static void generateCapabilitiesGetters(final PrintWriter writer) { public static void generateCapabilitiesGetters(final PrintWriter writer) {
writer.println("\tpublic static CLPlatformCapabilities getPlatformCapabilities(final CLPlatform platform) {\n" writer.println("\tpublic static CLPlatformCapabilities getPlatformCapabilities(final CLPlatform platform) {\n"
+ "\t\tplatform.checkValid();\n" + "\t\tplatform.checkValid();\n"
+ "\n" + "\n"
+ "\t\tCLPlatformCapabilities caps = (CLPlatformCapabilities)platform.getCapabilities();\n" + "\t\tCLPlatformCapabilities caps = (CLPlatformCapabilities)platform.getCapabilities();\n"
+ "\t\tif ( caps == null )\n" + "\t\tif ( caps == null )\n"
+ "\t\t\tplatform.setCapabilities(caps = new CLPlatformCapabilities(platform));\n" + "\t\t\tplatform.setCapabilities(caps = new CLPlatformCapabilities(platform));\n"
+ "\n" + "\n"
+ "\t\treturn caps;\n" + "\t\treturn caps;\n"
+ "\t}\n"); + "\t}\n");
writer.println("\tpublic static CLDeviceCapabilities getDeviceCapabilities(final CLDevice device) {\n" writer.println("\tpublic static CLDeviceCapabilities getDeviceCapabilities(final CLDevice device) {\n"
+ "\t\tdevice.checkValid();\n" + "\t\tdevice.checkValid();\n"
+ "\n" + "\n"
+ "\t\tCLDeviceCapabilities caps = (CLDeviceCapabilities)device.getCapabilities();\n" + "\t\tCLDeviceCapabilities caps = (CLDeviceCapabilities)device.getCapabilities();\n"
+ "\t\tif ( caps == null )\n" + "\t\tif ( caps == null )\n"
+ "\t\t\tdevice.setCapabilities(caps = new CLDeviceCapabilities(device));\n" + "\t\t\tdevice.setCapabilities(caps = new CLDeviceCapabilities(device));\n"
+ "\n" + "\n"
+ "\t\treturn caps;\n" + "\t\treturn caps;\n"
+ "\t}\n"); + "\t}\n");
} }
} }

View File

@ -31,125 +31,122 @@
*/ */
package org.lwjgl.util.generator.opencl; package org.lwjgl.util.generator.opencl;
import org.lwjgl.PointerWrapper;
import org.lwjgl.opencl.CLDevice;
import org.lwjgl.opencl.CLPlatform;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.Set; import java.util.Set;
import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.*;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter; import javax.lang.model.util.ElementFilter;
import org.lwjgl.PointerWrapper;
import org.lwjgl.opencl.CLDevice;
import org.lwjgl.opencl.CLPlatform;
/** /**
* Generator tool for creating the OpenCL capabilities classes * Generator tool for creating the OpenCL capabilities classes
* *
* @author Spasi * @author Spasi
*/ */
@SupportedAnnotationTypes({"*"}) @SupportedAnnotationTypes({ "*" })
@SupportedSourceVersion(SourceVersion.RELEASE_7) @SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedOptions({"generatechecks", "contextspecific"}) @SupportedOptions({ "generatechecks", "contextspecific" })
public class CLGeneratorProcessor extends AbstractProcessor { public class CLGeneratorProcessor extends AbstractProcessor {
public static final String CLCAPS_CLASS_NAME = "CLCapabilities"; public static final String CLCAPS_CLASS_NAME = "CLCapabilities";
public static final String PLATFORM_CAPS_CLASS_NAME = "CLPlatformCapabilities"; public static final String PLATFORM_CAPS_CLASS_NAME = "CLPlatformCapabilities";
public static final String DEVICE_CAPS_CLASS_NAME = "CLDeviceCapabilities"; public static final String DEVICE_CAPS_CLASS_NAME = "CLDeviceCapabilities";
private static final String EXTENSION_PREFIX = "CL_"; private static final String EXTENSION_PREFIX = "CL_";
private static final String CORE_PREFIX = "Open"; private static final String CORE_PREFIX = "Open";
private static boolean first_round = true; private static boolean first_round = true;
static String getExtensionName(String interface_name) { static String getExtensionName(String interface_name) {
if (interface_name.startsWith("CL")) { if ( interface_name.startsWith("CL") ) {
return CORE_PREFIX + interface_name; return CORE_PREFIX + interface_name;
} else { } else {
return EXTENSION_PREFIX + interface_name; return EXTENSION_PREFIX + interface_name;
} }
} }
@Override @Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || !first_round) { if ( roundEnv.processingOver() || !first_round ) {
System.exit(0); System.exit(0);
return true; return true;
} }
try { try {
Set<TypeElement> templates = ElementFilter.typesIn(roundEnv.getRootElements()); Set<TypeElement> templates = ElementFilter.typesIn(roundEnv.getRootElements());
/** /**
* provide the full set of ex-InterfaceDeclaration * provide the full set of ex-InterfaceDeclaration
* annotated templates elements * annotated templates elements
*/ */
generateCLCapabilitiesSource(templates); generateCLCapabilitiesSource(templates);
generateCLPDCapabilitiesSource(templates, CLPlatformExtension.class, PLATFORM_CAPS_CLASS_NAME, CLPlatform.class, "platform"); generateCLPDCapabilitiesSource(templates, CLPlatformExtension.class, PLATFORM_CAPS_CLASS_NAME, CLPlatform.class, "platform");
generateCLPDCapabilitiesSource(templates, CLDeviceExtension.class, DEVICE_CAPS_CLASS_NAME, CLDevice.class, "device"); generateCLPDCapabilitiesSource(templates, CLDeviceExtension.class, DEVICE_CAPS_CLASS_NAME, CLDevice.class, "device");
first_round = false; first_round = false;
return true; return true;
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private static void printHeader(final PrintWriter writer) { private static void printHeader(final PrintWriter writer) {
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */"); writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
writer.println(); writer.println();
writer.println("package org.lwjgl.opencl;"); writer.println("package org.lwjgl.opencl;");
writer.println(); writer.println();
} }
private void generateCLCapabilitiesSource(Set<TypeElement> templates) throws IOException { private void generateCLCapabilitiesSource(Set<TypeElement> templates) throws IOException {
final PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opencl." + CLCAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opencl")).openWriter()); final PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opencl." + CLCAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opencl")).openWriter());
printHeader(writer); printHeader(writer);
CLCapabilitiesGenerator.generateClassPrologue(writer); CLCapabilitiesGenerator.generateClassPrologue(writer);
for (TypeElement d : templates) { for ( TypeElement d : templates ) {
if (d.getKind().isInterface()) { if ( d.getKind().isInterface() ) {
CLCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, d); CLCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, d);
} }
} }
writer.println(); writer.println();
CLCapabilitiesGenerator.generateConstructor(processingEnv, writer, templates); CLCapabilitiesGenerator.generateConstructor(processingEnv, writer, templates);
CLCapabilitiesGenerator.generateCapabilitiesGetters(writer); CLCapabilitiesGenerator.generateCapabilitiesGetters(writer);
for (TypeElement d : templates) { for ( TypeElement d : templates ) {
if (d.getKind().isInterface()) { if ( d.getKind().isInterface() ) {
CLCapabilitiesGenerator.generateExtensionChecks(processingEnv, writer, d); CLCapabilitiesGenerator.generateExtensionChecks(processingEnv, writer, d);
} }
} }
writer.println("}"); writer.println("}");
writer.close(); writer.close();
} }
private void generateCLPDCapabilitiesSource(Set<TypeElement> templates, final Class<? extends Annotation> capsType, final String capsName, final Class<? extends PointerWrapper> objectType, final String objectName) throws IOException { private void generateCLPDCapabilitiesSource(Set<TypeElement> templates, final Class<? extends Annotation> capsType, final String capsName, final Class<? extends PointerWrapper> objectType, final String objectName) throws IOException {
final PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opencl." + capsName, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opencl")).openWriter()); final PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opencl." + capsName, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opencl")).openWriter());
printHeader(writer); printHeader(writer);
writer.println("import java.util.*;"); writer.println("import java.util.*;");
writer.println(); writer.println();
CLPDCapabilitiesGenerator.generateClassPrologue(writer, capsName); CLPDCapabilitiesGenerator.generateClassPrologue(writer, capsName);
for (TypeElement t : templates) { for ( TypeElement t : templates ) {
if (t.getKind().isInterface() && t.getAnnotation(capsType) != null) { if ( t.getKind().isInterface() && t.getAnnotation(capsType) != null ) {
CLPDCapabilitiesGenerator.generateExtensions(writer, (TypeElement) t); CLPDCapabilitiesGenerator.generateExtensions(writer, (TypeElement)t);
} }
} }
writer.println(); writer.println();
CLPDCapabilitiesGenerator.generateConstructor(processingEnv, writer, templates, capsType, capsName, objectType, objectName); CLPDCapabilitiesGenerator.generateConstructor(processingEnv, writer, templates, capsType, capsName, objectType, objectName);
CLPDCapabilitiesGenerator.generateGetters(writer); CLPDCapabilitiesGenerator.generateGetters(writer);
CLPDCapabilitiesGenerator.generateToString(writer, templates, capsType); CLPDCapabilitiesGenerator.generateToString(writer, templates, capsType);
writer.println("}"); writer.println("}");
writer.close(); writer.close();
} }
} }

View File

@ -32,15 +32,16 @@
package org.lwjgl.util.generator.opencl; package org.lwjgl.util.generator.opencl;
import org.lwjgl.PointerWrapper;
import org.lwjgl.util.generator.Extension;
import org.lwjgl.util.generator.Private;
import org.lwjgl.util.generator.Utils;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.Set; import java.util.Set;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import org.lwjgl.PointerWrapper;
import org.lwjgl.util.generator.Extension;
import org.lwjgl.util.generator.Private;
import org.lwjgl.util.generator.Utils;
/** /**
* CL platform/device capabilities generator. * CL platform/device capabilities generator.
@ -77,8 +78,8 @@ public class CLPDCapabilitiesGenerator {
} }
static void generateConstructor(ProcessingEnvironment env, final PrintWriter writer, final Set<? extends TypeElement> templates, static void generateConstructor(ProcessingEnvironment env, final PrintWriter writer, final Set<? extends TypeElement> templates,
final Class<? extends Annotation> capsType, final String capsName, final Class<? extends Annotation> capsType, final String capsName,
final Class<? extends PointerWrapper> objectType, final String objectName) { final Class<? extends PointerWrapper> objectType, final String objectName) {
writer.println("\tpublic " + capsName + "(final " + objectType.getSimpleName() + ' ' + objectName + ") {"); writer.println("\tpublic " + capsName + "(final " + objectType.getSimpleName() + ' ' + objectName + ") {");
writer.println("\t\tfinal String extensionList = " + objectName + ".getInfoString(CL10.CL_" + objectName.toUpperCase() + "_EXTENSIONS);\n" + writer.println("\t\tfinal String extensionList = " + objectName + ".getInfoString(CL10.CL_" + objectName.toUpperCase() + "_EXTENSIONS);\n" +
@ -114,7 +115,7 @@ public class CLPDCapabilitiesGenerator {
nativeName = ext.nativeName(); nativeName = ext.nativeName();
writer.print("\t\t" + extName + " = extensions.contains(\"" + nativeName + "\")"); writer.print("\t\t" + extName + " = extensions.contains(\"" + nativeName + "\")");
if ( !Utils.getMethods( t).isEmpty() ) if ( !Utils.getMethods(t).isEmpty() )
writer.print(" && CLCapabilities." + extName); writer.print(" && CLCapabilities." + extName);
writer.println(";"); writer.println(";");
} }
@ -143,7 +144,7 @@ public class CLPDCapabilitiesGenerator {
if ( t.getAnnotation(capsType) == null ) if ( t.getAnnotation(capsType) == null )
continue; continue;
writer.println("\t\tif ( " + CLGeneratorProcessor.getExtensionName(t.getSimpleName().toString()) + " ) buf.append(\"" + CLGeneratorProcessor.getExtensionName(t.getSimpleName().toString()).toLowerCase() + " \");"); writer.println("\t\tif ( " + CLGeneratorProcessor.getExtensionName(t.getSimpleName().toString()) + " ) buf.append(\"" + CLGeneratorProcessor.getExtensionName(t.getSimpleName().toString()).toLowerCase() + " \");");
} }
writer.println("\n\t\treturn buf.toString();"); writer.println("\n\t\treturn buf.toString();");

View File

@ -39,6 +39,10 @@ package org.lwjgl.util.generator.opencl;
* @author Spasi * @author Spasi
*/ */
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.*;
import org.lwjgl.util.generator.opengl.GLreturn;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.nio.*; import java.nio.*;
@ -48,10 +52,6 @@ import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement; import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import org.lwjgl.PointerBuffer;
import org.lwjgl.util.generator.*;
import org.lwjgl.util.generator.opengl.GLreturn;
public class CLTypeMap implements TypeMap { public class CLTypeMap implements TypeMap {
@ -74,7 +74,7 @@ public class CLTypeMap implements TypeMap {
native_types_to_primitive.put(cl_double.class, TypeKind.DOUBLE); native_types_to_primitive.put(cl_double.class, TypeKind.DOUBLE);
} }
@Override @Override
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) { public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
TypeKind kind = native_types_to_primitive.get(native_type); TypeKind kind = native_types_to_primitive.get(native_type);
if ( kind == null ) if ( kind == null )
@ -82,21 +82,21 @@ public class CLTypeMap implements TypeMap {
return kind; return kind;
} }
@Override @Override
public void printCapabilitiesInit(final PrintWriter writer) { public void printCapabilitiesInit(final PrintWriter writer) {
} }
@Override @Override
public String getCapabilities() { public String getCapabilities() {
return "CLCapabilities"; return "CLCapabilities";
} }
@Override @Override
public String getAPIUtilParam(boolean comma) { public String getAPIUtilParam(boolean comma) {
return ""; return "";
} }
@Override @Override
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) { public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) {
final Check check = method.getAnnotation(Check.class); final Check check = method.getAnnotation(Check.class);
if ( check != null ) // Get the error code from an IntBuffer output parameter if ( check != null ) // Get the error code from an IntBuffer output parameter
@ -119,12 +119,12 @@ public class CLTypeMap implements TypeMap {
} }
} }
@Override @Override
public String getRegisterNativesFunctionName() { public String getRegisterNativesFunctionName() {
return "extcl_InitializeClass"; return "extcl_InitializeClass";
} }
@Override @Override
public Signedness getSignednessFromType(Class type) { public Signedness getSignednessFromType(Class type) {
if ( cl_uint.class.equals(type) ) if ( cl_uint.class.equals(type) )
return Signedness.UNSIGNED; return Signedness.UNSIGNED;
@ -134,7 +134,7 @@ public class CLTypeMap implements TypeMap {
return Signedness.NONE; return Signedness.NONE;
} }
@Override @Override
public String translateAnnotation(Class annotation_type) { public String translateAnnotation(Class annotation_type) {
if ( annotation_type.equals(cl_uint.class) || annotation_type.equals(cl_int.class) ) if ( annotation_type.equals(cl_uint.class) || annotation_type.equals(cl_int.class) )
return "i"; return "i";
@ -150,7 +150,7 @@ public class CLTypeMap implements TypeMap {
throw new RuntimeException(annotation_type + " is not allowed"); throw new RuntimeException(annotation_type + " is not allowed");
} }
@Override @Override
public Class getNativeTypeFromPrimitiveType(TypeKind kind) { public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
Class type; Class type;
switch ( kind ) { switch ( kind ) {
@ -181,22 +181,22 @@ public class CLTypeMap implements TypeMap {
return type; return type;
} }
@Override @Override
public Class<? extends Annotation> getVoidType() { public Class<? extends Annotation> getVoidType() {
return cl_void.class; return cl_void.class;
} }
@Override @Override
public Class<? extends Annotation> getStringElementType() { public Class<? extends Annotation> getStringElementType() {
return cl_char.class; return cl_char.class;
} }
@Override @Override
public Class<? extends Annotation> getStringArrayType() { public Class<? extends Annotation> getStringArrayType() {
return cl_char.class; return cl_char.class;
} }
@Override @Override
public Class<? extends Annotation> getByteBufferArrayType() { public Class<? extends Annotation> getByteBufferArrayType() {
return cl_uchar.class; return cl_uchar.class;
} }
@ -241,22 +241,22 @@ public class CLTypeMap implements TypeMap {
return new Class[] { }; return new Class[] { };
} }
@Override @Override
public String getTypedefPostfix() { public String getTypedefPostfix() {
return "CL_API_ENTRY "; return "CL_API_ENTRY ";
} }
@Override @Override
public String getFunctionPrefix() { public String getFunctionPrefix() {
return "CL_API_CALL"; return "CL_API_CALL";
} }
@Override @Override
public void printNativeIncludes(PrintWriter writer) { public void printNativeIncludes(PrintWriter writer) {
writer.println("#include \"extcl.h\""); writer.println("#include \"extcl.h\"");
} }
@Override @Override
public Class[] getValidAnnotationTypes(Class type) { public Class[] getValidAnnotationTypes(Class type) {
Class[] valid_types; Class[] valid_types;
if ( Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) ) if ( Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) )
@ -276,12 +276,12 @@ public class CLTypeMap implements TypeMap {
return valid_types; return valid_types;
} }
@Override @Override
public Class<? extends Annotation> getInverseType(Class type) { public Class<? extends Annotation> getInverseType(Class type) {
return null; return null;
} }
@Override @Override
public String getAutoTypeFromAnnotation(AnnotationMirror annotation) { public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
return null; return null;
} }

View File

@ -32,19 +32,17 @@
package org.lwjgl.util.generator.opengl; package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.*;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import org.lwjgl.util.generator.*;
/** /**
* Generator visitor for the context capabilities generator tool * Generator visitor for the context capabilities generator tool
@ -55,13 +53,13 @@ import org.lwjgl.util.generator.*;
*/ */
public class GLCapabilitiesGenerator { public class GLCapabilitiesGenerator {
private static final String STUBS_LOADED_NAME = "loaded_stubs"; private static final String STUBS_LOADED_NAME = "loaded_stubs";
private static final String ALL_INIT_METHOD_NAME = "initAllStubs"; private static final String ALL_INIT_METHOD_NAME = "initAllStubs";
private static final String POINTER_INITIALIZER_POSTFIX = "_initNativeFunctionAddresses"; private static final String POINTER_INITIALIZER_POSTFIX = "_initNativeFunctionAddresses";
private static final String CACHED_EXTS_VAR_NAME = "supported_extensions"; private static final String CACHED_EXTS_VAR_NAME = "supported_extensions";
private static final String PROFILE_MASK_VAR_NAME = "profileMask"; private static final String PROFILE_MASK_VAR_NAME = "profileMask";
private static final String EXTENSION_PREFIX = "GL_"; private static final String EXTENSION_PREFIX = "GL_";
private static final String CORE_PREFIX = "Open"; private static final String CORE_PREFIX = "Open";
public static void generateClassPrologue(PrintWriter writer, boolean context_specific, boolean generate_error_checks) { public static void generateClassPrologue(PrintWriter writer, boolean context_specific, boolean generate_error_checks) {
writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {"); writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {");
@ -105,7 +103,7 @@ public class GLCapabilitiesGenerator {
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\""); writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
writer.print(translated_field_name + "\")"); writer.print(translated_field_name + "\")");
List<? extends TypeMirror> super_interfaces = d.getInterfaces(); List<? extends TypeMirror> super_interfaces = d.getInterfaces();
if ( super_interfaces.size() > 1 ) if ( super_interfaces.size() > 1 )
throw new RuntimeException(d + " extends more than one other interface"); throw new RuntimeException(d + " extends more than one other interface");
if ( super_interfaces.size() == 1 ) { if ( super_interfaces.size() == 1 ) {
TypeMirror super_interface = super_interfaces.iterator().next(); TypeMirror super_interface = super_interfaces.iterator().next();
@ -166,14 +164,14 @@ public class GLCapabilitiesGenerator {
} }
public static void generateUnloadStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d) { public static void generateUnloadStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
if ( Utils.getMethods( d).size() > 0 ) { if ( Utils.getMethods(d).size() > 0 ) {
writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d)); writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d));
writer.println(".class);"); writer.println(".class);");
} }
} }
public static void generateInitStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean context_specific) { public static void generateInitStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean context_specific) {
if ( Utils.getMethods( d).size() > 0 ) { if ( Utils.getMethods(d).size() > 0 ) {
if ( context_specific ) { if ( context_specific ) {
final Alias alias_annotation = d.getAnnotation(Alias.class); final Alias alias_annotation = d.getAnnotation(Alias.class);
@ -219,7 +217,7 @@ public class GLCapabilitiesGenerator {
} }
public static void generateAddressesInitializers(ProcessingEnvironment env, PrintWriter writer, TypeElement d) { public static void generateAddressesInitializers(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
Iterator<? extends ExecutableElement> methods = Utils.getMethods( d).iterator(); Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
if ( !methods.hasNext() ) if ( !methods.hasNext() )
return; return;
@ -313,7 +311,7 @@ public class GLCapabilitiesGenerator {
public static void generateSymbolAddresses(ProcessingEnvironment env, PrintWriter writer, TypeElement d) { public static void generateSymbolAddresses(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
boolean first = true; boolean first = true;
for ( final ExecutableElement method : Utils.getMethods( d) ) { for ( final ExecutableElement method : Utils.getMethods(d) ) {
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null ) if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
continue; continue;

View File

@ -32,6 +32,7 @@
package org.lwjgl.util.generator.opengl; package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.*;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Arrays; import java.util.Arrays;
@ -41,9 +42,7 @@ import java.util.List;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import org.lwjgl.util.generator.*;
/** /**
* Generator visitor for the context capabilities generator tool * Generator visitor for the context capabilities generator tool
@ -54,12 +53,12 @@ import org.lwjgl.util.generator.*;
*/ */
public class GLESCapabilitiesGenerator { public class GLESCapabilitiesGenerator {
private static final String STUBS_LOADED_NAME = "loaded_stubs"; private static final String STUBS_LOADED_NAME = "loaded_stubs";
private static final String ALL_INIT_METHOD_NAME = "initAllStubs"; private static final String ALL_INIT_METHOD_NAME = "initAllStubs";
private static final String POINTER_INITIALIZER_POSTFIX = "_initNativeFunctionAddresses"; private static final String POINTER_INITIALIZER_POSTFIX = "_initNativeFunctionAddresses";
private static final String CACHED_EXTS_VAR_NAME = "supported_extensions"; private static final String CACHED_EXTS_VAR_NAME = "supported_extensions";
private static final String EXTENSION_PREFIX = "GL_"; private static final String EXTENSION_PREFIX = "GL_";
private static final String CORE_PREFIX = "Open"; private static final String CORE_PREFIX = "Open";
public static void generateClassPrologue(PrintWriter writer, boolean context_specific, boolean generate_error_checks) { public static void generateClassPrologue(PrintWriter writer, boolean context_specific, boolean generate_error_checks) {
writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {"); writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {");
@ -95,7 +94,7 @@ public class GLESCapabilitiesGenerator {
} }
} }
public static void generateInitializer(PrintWriter writer, TypeElement d,ProcessingEnvironment env) { public static void generateInitializer(PrintWriter writer, TypeElement d, ProcessingEnvironment env) {
String translated_field_name = translateFieldName(d.getSimpleName().toString()); String translated_field_name = translateFieldName(d.getSimpleName().toString());
writer.print("\t\tthis." + translated_field_name + " = "); writer.print("\t\tthis." + translated_field_name + " = ");
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\""); writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
@ -126,9 +125,9 @@ public class GLESCapabilitiesGenerator {
writer.println("\tprivate Set<String> " + ALL_INIT_METHOD_NAME + "() throws LWJGLException {"); writer.println("\tprivate Set<String> " + ALL_INIT_METHOD_NAME + "() throws LWJGLException {");
if ( context_specific ) { if ( context_specific ) {
// Load the basic pointers we need to detect OpenGL version and supported extensions. // Load the basic pointers we need to detect OpenGL version and supported extensions.
writer.println("\t\tglGetError = GLContext.getFunctionAddress(\"glGetError\");"); writer.println("\t\tglGetError = GLContext.getFunctionAddress(\"glGetError\");");
writer.println("\t\tglGetString = GLContext.getFunctionAddress(\"glGetString\");"); writer.println("\t\tglGetString = GLContext.getFunctionAddress(\"glGetString\");");
} }
// Get the supported extensions set. // Get the supported extensions set.
@ -156,14 +155,14 @@ public class GLESCapabilitiesGenerator {
public static void generateUnloadStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d) { public static void generateUnloadStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
// TODO: Remove GLES // TODO: Remove GLES
if (Utils.getMethods( d).size() > 0 && !d.getSimpleName().toString().startsWith("GLES") ) { if ( Utils.getMethods(d).size() > 0 && !d.getSimpleName().toString().startsWith("GLES") ) {
writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d)); writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d));
writer.println(".class);"); writer.println(".class);");
} }
} }
public static void generateInitStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean context_specific) { public static void generateInitStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean context_specific) {
if ( Utils.getMethods( d).size() > 0 ) { if ( Utils.getMethods(d).size() > 0 ) {
if ( context_specific ) { if ( context_specific ) {
final Alias alias_annotation = d.getAnnotation(Alias.class); final Alias alias_annotation = d.getAnnotation(Alias.class);
@ -204,7 +203,7 @@ public class GLESCapabilitiesGenerator {
} }
public static void generateAddressesInitializers(ProcessingEnvironment env, PrintWriter writer, TypeElement d) { public static void generateAddressesInitializers(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
Iterator<? extends ExecutableElement> methods = Utils.getMethods( d).iterator(); Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
if ( !methods.hasNext() ) if ( !methods.hasNext() )
return; return;
@ -290,7 +289,7 @@ public class GLESCapabilitiesGenerator {
public static void generateSymbolAddresses(ProcessingEnvironment env, PrintWriter writer, TypeElement d) { public static void generateSymbolAddresses(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
boolean first = true; boolean first = true;
for ( final ExecutableElement method : Utils.getMethods( d) ) { for ( final ExecutableElement method : Utils.getMethods(d) ) {
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null ) if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
continue; continue;

View File

@ -31,134 +31,131 @@
*/ */
package org.lwjgl.util.generator.opengl; package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.Utils;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.*;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter; import javax.lang.model.util.ElementFilter;
import org.lwjgl.util.generator.Utils;
/** /**
* Generator tool for creating the ContexCapabilities class * Generator tool for creating the ContexCapabilities class
* *
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision: 3316 $ $Id: ContextGeneratorProcessorFactory.java 3316 * @version $Revision: 3316 $ $Id: ContextGeneratorProcessorFactory.java 3316
* 2010-04-09 23:57:40Z spasi $ * 2010-04-09 23:57:40Z spasi $
*/ */
@SupportedAnnotationTypes({"*"}) @SupportedAnnotationTypes({ "*" })
@SupportedSourceVersion(SourceVersion.RELEASE_7) @SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedOptions({"contextspecific", "generatechecks"}) @SupportedOptions({ "contextspecific", "generatechecks" })
public class GLESGeneratorProcessor extends AbstractProcessor { public class GLESGeneratorProcessor extends AbstractProcessor {
private static boolean first_round = true; private static boolean first_round = true;
@Override @Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || !first_round) { if ( roundEnv.processingOver() || !first_round ) {
System.exit(0); System.exit(0);
return true; return true;
} }
Map<String, String> options = processingEnv.getOptions(); Map<String, String> options = processingEnv.getOptions();
boolean generate_error_checks = options.containsKey("generatechecks"); boolean generate_error_checks = options.containsKey("generatechecks");
boolean context_specific = options.containsKey("contextspecific"); boolean context_specific = options.containsKey("contextspecific");
try { try {
generateContextCapabilitiesSource(ElementFilter.typesIn(roundEnv.getRootElements()), context_specific, generate_error_checks); generateContextCapabilitiesSource(ElementFilter.typesIn(roundEnv.getRootElements()), context_specific, generate_error_checks);
first_round = false; first_round = false;
return true; return true;
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private void generateContextCapabilitiesSource(Set<TypeElement> templates, boolean context_specific, boolean generate_error_checks) throws IOException { private void generateContextCapabilitiesSource(Set<TypeElement> templates, boolean context_specific, boolean generate_error_checks) throws IOException {
PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengles." + Utils.CONTEXT_CAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengles")).openWriter()); PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengles." + Utils.CONTEXT_CAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengles")).openWriter());
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */"); writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
writer.println(); writer.println();
writer.println("package org.lwjgl.opengles;"); writer.println("package org.lwjgl.opengles;");
writer.println(); writer.println();
writer.println("import org.lwjgl.LWJGLException;"); writer.println("import org.lwjgl.LWJGLException;");
writer.println("import org.lwjgl.LWJGLUtil;"); writer.println("import org.lwjgl.LWJGLUtil;");
writer.println("import java.util.Set;"); writer.println("import java.util.Set;");
writer.println("import java.util.HashSet;"); writer.println("import java.util.HashSet;");
writer.println(); writer.println();
GLESCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks); GLESCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks);
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
if (Utils.isFinal(interface_decl)) { if ( Utils.isFinal(interface_decl) ) {
GLESCapabilitiesGenerator.generateField(writer, interface_decl); GLESCapabilitiesGenerator.generateField(writer, interface_decl);
} }
} }
} }
writer.println(); writer.println();
if (context_specific) { if ( context_specific ) {
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
GLESCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, interface_decl); GLESCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, interface_decl);
} }
} }
writer.println(); writer.println();
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
GLESCapabilitiesGenerator.generateAddressesInitializers(processingEnv, writer, interface_decl); GLESCapabilitiesGenerator.generateAddressesInitializers(processingEnv, writer, interface_decl);
} }
} }
writer.println(); writer.println();
} }
if (context_specific) { if ( context_specific ) {
writer.println("\tprivate static void remove(Set supported_extensions, String extension) {"); writer.println("\tprivate static void remove(Set supported_extensions, String extension) {");
writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");"); writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");");
writer.println("\t\tsupported_extensions.remove(extension);"); writer.println("\t\tsupported_extensions.remove(extension);");
writer.println("\t}\n"); writer.println("\t}\n");
} }
GLESCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific); GLESCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
GLESCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl, processingEnv); GLESCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl, processingEnv);
} }
} }
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
if ("GLES20".equals(interface_decl.getSimpleName().toString())) { if ( "GLES20".equals(interface_decl.getSimpleName().toString()) ) {
continue; continue;
} }
GLESCapabilitiesGenerator.generateInitStubs(processingEnv, writer, interface_decl, context_specific); GLESCapabilitiesGenerator.generateInitStubs(processingEnv, writer, interface_decl, context_specific);
} }
} }
GLESCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific); GLESCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
writer.println(); writer.println();
writer.println("\tstatic void unloadAllStubs() {"); writer.println("\tstatic void unloadAllStubs() {");
if (!context_specific) { if ( !context_specific ) {
writer.println("\t\tif (!loaded_stubs)"); writer.println("\t\tif (!loaded_stubs)");
writer.println("\t\t\treturn;"); writer.println("\t\t\treturn;");
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
GLESCapabilitiesGenerator.generateUnloadStubs(processingEnv, writer, interface_decl); GLESCapabilitiesGenerator.generateUnloadStubs(processingEnv, writer, interface_decl);
} }
} }
writer.println("\t\tloaded_stubs = false;"); writer.println("\t\tloaded_stubs = false;");
} }
writer.println("\t}"); writer.println("\t}");
writer.println(); writer.println();
GLESCapabilitiesGenerator.generateInitializerPrologue(writer); GLESCapabilitiesGenerator.generateInitializerPrologue(writer);
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
if (Utils.isFinal(interface_decl)) { if ( Utils.isFinal(interface_decl) ) {
GLESCapabilitiesGenerator.generateInitializer(writer, interface_decl, processingEnv); GLESCapabilitiesGenerator.generateInitializer(writer, interface_decl, processingEnv);
} }
} }
} }
writer.println("\t}"); writer.println("\t}");
writer.println("}"); writer.println("}");
writer.close(); writer.close();
} }
} }

View File

@ -41,6 +41,11 @@ package org.lwjgl.util.generator.opengl;
* $Id: GLTypeMap.java 3287 2010-03-14 23:24:40Z spasi $ * $Id: GLTypeMap.java 3287 2010-03-14 23:24:40Z spasi $
*/ */
import org.lwjgl.util.generator.NativeTypeTranslator;
import org.lwjgl.util.generator.PointerWrapper;
import org.lwjgl.util.generator.Signedness;
import org.lwjgl.util.generator.TypeMap;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.nio.*; import java.nio.*;
@ -49,10 +54,6 @@ import java.util.Map;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import org.lwjgl.util.generator.NativeTypeTranslator;
import org.lwjgl.util.generator.PointerWrapper;
import org.lwjgl.util.generator.Signedness;
import org.lwjgl.util.generator.TypeMap;
public class GLESTypeMap implements TypeMap { public class GLESTypeMap implements TypeMap {
@ -83,7 +84,7 @@ public class GLESTypeMap implements TypeMap {
native_types_to_primitive.put(GLuint64.class, TypeKind.LONG); native_types_to_primitive.put(GLuint64.class, TypeKind.LONG);
} }
@Override @Override
public TypeKind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type) { public TypeKind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type) {
TypeKind kind = native_types_to_primitive.get(native_type); TypeKind kind = native_types_to_primitive.get(native_type);
if ( kind == null ) if ( kind == null )
@ -91,32 +92,32 @@ public class GLESTypeMap implements TypeMap {
return kind; return kind;
} }
@Override @Override
public void printCapabilitiesInit(final PrintWriter writer) { public void printCapabilitiesInit(final PrintWriter writer) {
writer.println("\t\tContextCapabilities caps = GLContext.getCapabilities();"); writer.println("\t\tContextCapabilities caps = GLContext.getCapabilities();");
} }
@Override @Override
public String getCapabilities() { public String getCapabilities() {
return "caps"; return "caps";
} }
@Override @Override
public String getAPIUtilParam(boolean comma) { public String getAPIUtilParam(boolean comma) {
return ""; return "";
} }
@Override @Override
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) { public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) {
writer.println(tabs + "Util.checkGLError();"); writer.println(tabs + "Util.checkGLError();");
} }
@Override @Override
public String getRegisterNativesFunctionName() { public String getRegisterNativesFunctionName() {
return "extgl_InitializeClass"; return "extgl_InitializeClass";
} }
@Override @Override
public Signedness getSignednessFromType(Class<? extends Annotation> type) { public Signedness getSignednessFromType(Class<? extends Annotation> type) {
if ( GLuint.class.equals(type) ) if ( GLuint.class.equals(type) )
return Signedness.UNSIGNED; return Signedness.UNSIGNED;
@ -138,7 +139,7 @@ public class GLESTypeMap implements TypeMap {
return Signedness.NONE; return Signedness.NONE;
} }
@Override @Override
public String translateAnnotation(Class annotation_type) { public String translateAnnotation(Class annotation_type) {
if ( annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class) ) if ( annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class) )
return "i64"; return "i64";
@ -160,7 +161,7 @@ public class GLESTypeMap implements TypeMap {
throw new RuntimeException(annotation_type + " is not allowed"); throw new RuntimeException(annotation_type + " is not allowed");
} }
@Override @Override
public Class<? extends Annotation> getNativeTypeFromPrimitiveType(TypeKind kind) { public Class<? extends Annotation> getNativeTypeFromPrimitiveType(TypeKind kind) {
Class<? extends Annotation> type; Class<? extends Annotation> type;
switch ( kind ) { switch ( kind ) {
@ -188,22 +189,22 @@ public class GLESTypeMap implements TypeMap {
return type; return type;
} }
@Override @Override
public Class<? extends Annotation> getVoidType() { public Class<? extends Annotation> getVoidType() {
return GLvoid.class; return GLvoid.class;
} }
@Override @Override
public Class<? extends Annotation> getStringElementType() { public Class<? extends Annotation> getStringElementType() {
return GLubyte.class; return GLubyte.class;
} }
@Override @Override
public Class<? extends Annotation> getStringArrayType() { public Class<? extends Annotation> getStringArrayType() {
return GLchar.class; return GLchar.class;
} }
@Override @Override
public Class<? extends Annotation> getByteBufferArrayType() { public Class<? extends Annotation> getByteBufferArrayType() {
return GLubyte.class; return GLubyte.class;
} }
@ -242,22 +243,22 @@ public class GLESTypeMap implements TypeMap {
return new Class[] { }; return new Class[] { };
} }
@Override @Override
public String getTypedefPostfix() { public String getTypedefPostfix() {
return "GL_APICALL "; return "GL_APICALL ";
} }
@Override @Override
public String getFunctionPrefix() { public String getFunctionPrefix() {
return "GL_APIENTRY"; return "GL_APIENTRY";
} }
@Override @Override
public void printNativeIncludes(PrintWriter writer) { public void printNativeIncludes(PrintWriter writer) {
writer.println("#include \"extgl.h\""); writer.println("#include \"extgl.h\"");
} }
@Override @Override
public Class[] getValidAnnotationTypes(Class type) { public Class[] getValidAnnotationTypes(Class type) {
Class[] valid_types; Class[] valid_types;
if ( Buffer.class.isAssignableFrom(type) ) if ( Buffer.class.isAssignableFrom(type) )
@ -275,7 +276,7 @@ public class GLESTypeMap implements TypeMap {
return valid_types; return valid_types;
} }
@Override @Override
public Class<? extends Annotation> getInverseType(Class<? extends Annotation> type) { public Class<? extends Annotation> getInverseType(Class<? extends Annotation> type) {
if ( GLuint64.class.equals(type) ) if ( GLuint64.class.equals(type) )
return GLint64.class; return GLint64.class;
@ -295,7 +296,7 @@ public class GLESTypeMap implements TypeMap {
return null; return null;
} }
@Override @Override
public String getAutoTypeFromAnnotation(AnnotationMirror annotation) { public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType()); Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
if ( annotation_class.equals(GLint.class) ) if ( annotation_class.equals(GLint.class) )

View File

@ -31,134 +31,130 @@
*/ */
package org.lwjgl.util.generator.opengl; package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.Utils;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.*;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter; import javax.lang.model.util.ElementFilter;
import org.lwjgl.util.generator.Utils;
/** /**
*
* Generator tool for creating the ContexCapabilities class * Generator tool for creating the ContexCapabilities class
* *
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision: 3316 $ $Id: ContextGeneratorProcessorFactory.java 3316 * @version $Revision: 3316 $ $Id: ContextGeneratorProcessorFactory.java 3316
* 2010-04-09 23:57:40Z spasi $ * 2010-04-09 23:57:40Z spasi $
*/ */
@SupportedAnnotationTypes({"*"}) @SupportedAnnotationTypes({ "*" })
@SupportedSourceVersion(SourceVersion.RELEASE_7) @SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedOptions({"generatechecks", "contextspecific"}) @SupportedOptions({ "generatechecks", "contextspecific" })
public class GLGeneratorProcessor extends AbstractProcessor { public class GLGeneratorProcessor extends AbstractProcessor {
private static boolean first_round = true; private static boolean first_round = true;
@Override @Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || !first_round) { if ( roundEnv.processingOver() || !first_round ) {
System.exit(0); System.exit(0);
return true; return true;
} }
Map<String, String> options = processingEnv.getOptions(); Map<String, String> options = processingEnv.getOptions();
boolean generate_error_checks = options.containsKey("generatechecks"); boolean generate_error_checks = options.containsKey("generatechecks");
boolean context_specific = options.containsKey("contextspecific"); boolean context_specific = options.containsKey("contextspecific");
try { try {
generateContextCapabilitiesSource(ElementFilter.typesIn(roundEnv.getRootElements()), context_specific, generate_error_checks); generateContextCapabilitiesSource(ElementFilter.typesIn(roundEnv.getRootElements()), context_specific, generate_error_checks);
first_round = false; first_round = false;
return true; return true;
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private void generateContextCapabilitiesSource(Set<TypeElement> templates, boolean context_specific, boolean generate_error_checks) throws IOException { private void generateContextCapabilitiesSource(Set<TypeElement> templates, boolean context_specific, boolean generate_error_checks) throws IOException {
PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengl." + Utils.CONTEXT_CAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengl")).openWriter()); PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengl." + Utils.CONTEXT_CAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengl")).openWriter());
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */"); writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
writer.println(); writer.println();
writer.println("package org.lwjgl.opengl;"); writer.println("package org.lwjgl.opengl;");
writer.println(); writer.println();
writer.println("import org.lwjgl.LWJGLException;"); writer.println("import org.lwjgl.LWJGLException;");
writer.println("import org.lwjgl.LWJGLUtil;"); writer.println("import org.lwjgl.LWJGLUtil;");
writer.println("import java.util.Set;"); writer.println("import java.util.Set;");
writer.println("import java.util.HashSet;"); writer.println("import java.util.HashSet;");
writer.println(); writer.println();
GLCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks); GLCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks);
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
if (Utils.isFinal(interface_decl)) { if ( Utils.isFinal(interface_decl) ) {
GLCapabilitiesGenerator.generateField(writer, interface_decl); GLCapabilitiesGenerator.generateField(writer, interface_decl);
} }
} }
} }
writer.println(); writer.println();
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
GLCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, interface_decl); GLCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, interface_decl);
} }
} }
writer.println(); writer.println();
if (context_specific) { if ( context_specific ) {
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
GLCapabilitiesGenerator.generateAddressesInitializers(processingEnv, writer, interface_decl); GLCapabilitiesGenerator.generateAddressesInitializers(processingEnv, writer, interface_decl);
} }
} }
writer.println(); writer.println();
} }
writer.println("\tprivate static void remove(Set supported_extensions, String extension) {"); writer.println("\tprivate static void remove(Set supported_extensions, String extension) {");
writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");"); writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");");
writer.println("\t\tsupported_extensions.remove(extension);"); writer.println("\t\tsupported_extensions.remove(extension);");
writer.println("\t}\n"); writer.println("\t}\n");
GLCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific); GLCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
GLCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl, processingEnv); GLCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl, processingEnv);
} }
} }
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
String simple_name = interface_decl.getSimpleName().toString(); String simple_name = interface_decl.getSimpleName().toString();
if ("GL11".equals(simple_name)) { if ( "GL11".equals(simple_name) ) {
continue; continue;
} }
GLCapabilitiesGenerator.generateInitStubs(processingEnv, writer, interface_decl, context_specific); GLCapabilitiesGenerator.generateInitStubs(processingEnv, writer, interface_decl, context_specific);
} }
} }
GLCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific); GLCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
writer.println(); writer.println();
writer.println("\tstatic void unloadAllStubs() {"); writer.println("\tstatic void unloadAllStubs() {");
if (!context_specific) { if ( !context_specific ) {
writer.println("\t\tif (!loaded_stubs)"); writer.println("\t\tif (!loaded_stubs)");
writer.println("\t\t\treturn;"); writer.println("\t\t\treturn;");
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
GLCapabilitiesGenerator.generateUnloadStubs(processingEnv, writer, interface_decl); GLCapabilitiesGenerator.generateUnloadStubs(processingEnv, writer, interface_decl);
} }
} }
writer.println("\t\tloaded_stubs = false;"); writer.println("\t\tloaded_stubs = false;");
} }
writer.println("\t}"); writer.println("\t}");
writer.println(); writer.println();
GLCapabilitiesGenerator.generateInitializerPrologue(writer); GLCapabilitiesGenerator.generateInitializerPrologue(writer);
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
if (Utils.isFinal(interface_decl)) { if ( Utils.isFinal(interface_decl) ) {
GLCapabilitiesGenerator.generateInitializer(writer, interface_decl, processingEnv); GLCapabilitiesGenerator.generateInitializer(writer, interface_decl, processingEnv);
} }
} }
} }
writer.println("\t\ttracker.init();"); writer.println("\t\ttracker.init();");
writer.println("\t}"); writer.println("\t}");
writer.println("}"); writer.println("}");
writer.close(); writer.close();
} }
} }

View File

@ -31,161 +31,156 @@
*/ */
package org.lwjgl.util.generator.opengl; package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.Alternate;
import org.lwjgl.util.generator.CachedReference;
import org.lwjgl.util.generator.Utils;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Set; import java.util.Set;
import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.*;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement; import javax.lang.model.element.VariableElement;
import javax.lang.model.util.ElementFilter; import javax.lang.model.util.ElementFilter;
import org.lwjgl.util.generator.Alternate;
import org.lwjgl.util.generator.CachedReference;
import org.lwjgl.util.generator.Utils;
/** /**
*
* Generator tool for creating the References class * Generator tool for creating the References class
* *
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision: 3237 $ $Id: ReferencesGeneratorProcessorFactory.java 3237 * @version $Revision: 3237 $ $Id: ReferencesGeneratorProcessorFactory.java 3237
* 2009-09-08 15:07:15Z spasi $ * 2009-09-08 15:07:15Z spasi $
*/ */
@SupportedAnnotationTypes({"*"}) @SupportedAnnotationTypes({ "*" })
@SupportedSourceVersion(SourceVersion.RELEASE_7) @SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedOptions({"generatechecks", "contextspecific"}) @SupportedOptions({ "generatechecks", "contextspecific" })
public class GLReferencesGeneratorProcessor extends AbstractProcessor { public class GLReferencesGeneratorProcessor extends AbstractProcessor {
private static final String REFERENCES_CLASS_NAME = "References"; private static final String REFERENCES_CLASS_NAME = "References";
private static final String REFERENCES_PARAMETER_NAME = "references"; private static final String REFERENCES_PARAMETER_NAME = "references";
private static boolean first_round = true; private static boolean first_round = true;
@Override @Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || !first_round) { if ( roundEnv.processingOver() || !first_round ) {
System.exit(0); System.exit(0);
return true; return true;
} }
try { try {
generateReferencesSource(processingEnv, ElementFilter.typesIn(roundEnv.getRootElements())); generateReferencesSource(processingEnv, ElementFilter.typesIn(roundEnv.getRootElements()));
first_round = false; first_round = false;
return true; return true;
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private static void generateClearsFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) { private static void generateClearsFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) {
for (VariableElement param : method.getParameters()) { for ( VariableElement param : method.getParameters() ) {
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class); CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) { if ( cached_reference_annotation != null && cached_reference_annotation.name().length() == 0 ) {
Class nio_type = Utils.getNIOBufferType(param.asType()); Class nio_type = Utils.getNIOBufferType(param.asType());
String reference_name = Utils.getReferenceName(interface_decl, method, param); String reference_name = Utils.getReferenceName(interface_decl, method, param);
writer.println("\t\tthis." + reference_name + " = null;"); writer.println("\t\tthis." + reference_name + " = null;");
} }
} }
} }
private static void generateCopiesFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) { private static void generateCopiesFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) {
for (VariableElement param : method.getParameters()) { for ( VariableElement param : method.getParameters() ) {
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class); CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) { if ( cached_reference_annotation != null && cached_reference_annotation.name().length() == 0 ) {
Class nio_type = Utils.getNIOBufferType(param.asType()); Class nio_type = Utils.getNIOBufferType(param.asType());
String reference_name = Utils.getReferenceName(interface_decl, method, param); String reference_name = Utils.getReferenceName(interface_decl, method, param);
writer.print("\t\t\tthis." + reference_name + " = "); writer.print("\t\t\tthis." + reference_name + " = ");
writer.println(REFERENCES_PARAMETER_NAME + "." + reference_name + ";"); writer.println(REFERENCES_PARAMETER_NAME + "." + reference_name + ";");
} }
} }
} }
private static void generateClearsFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) { private static void generateClearsFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) {
for (ExecutableElement method : Utils.getMethods( interface_decl)) { for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
if (method.getAnnotation(Alternate.class) != null) { if ( method.getAnnotation(Alternate.class) != null ) {
continue; continue;
} }
generateClearsFromParameters(writer, interface_decl, method); generateClearsFromParameters(writer, interface_decl, method);
} }
} }
private static void generateCopiesFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) { private static void generateCopiesFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) {
for (ExecutableElement method : Utils.getMethods( interface_decl)) { for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
if (method.getAnnotation(Alternate.class) != null) { if ( method.getAnnotation(Alternate.class) != null ) {
continue; continue;
} }
generateCopiesFromParameters(writer, interface_decl, method); generateCopiesFromParameters(writer, interface_decl, method);
} }
} }
private static void generateReferencesFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) { private static void generateReferencesFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) {
for (VariableElement param : method.getParameters()) { for ( VariableElement param : method.getParameters() ) {
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class); CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) { if ( cached_reference_annotation != null && cached_reference_annotation.name().length() == 0 ) {
Class nio_type = Utils.getNIOBufferType(param.asType()); Class nio_type = Utils.getNIOBufferType(param.asType());
if (nio_type == null) { if ( nio_type == null ) {
throw new RuntimeException(param + " in method " + method + " in " + interface_decl + " is annotated with " throw new RuntimeException(param + " in method " + method + " in " + interface_decl + " is annotated with "
+ cached_reference_annotation.annotationType().getSimpleName() + " but the parameter is not a NIO buffer"); + cached_reference_annotation.annotationType().getSimpleName() + " but the parameter is not a NIO buffer");
} }
writer.print("\t" + nio_type.getName() + " " + Utils.getReferenceName(interface_decl, method, param)); writer.print("\t" + nio_type.getName() + " " + Utils.getReferenceName(interface_decl, method, param));
writer.println(";"); writer.println(";");
} }
} }
} }
private static void generateReferencesFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) { private static void generateReferencesFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) {
for (ExecutableElement method : Utils.getMethods( interface_decl)) { for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
if (method.getAnnotation(Alternate.class) != null) { if ( method.getAnnotation(Alternate.class) != null ) {
continue; continue;
} }
generateReferencesFromParameters(writer, interface_decl, method); generateReferencesFromParameters(writer, interface_decl, method);
} }
} }
private void generateReferencesSource(ProcessingEnvironment env, Set<TypeElement> templates) throws IOException { private void generateReferencesSource(ProcessingEnvironment env, Set<TypeElement> templates) throws IOException {
PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengl." + REFERENCES_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengl")).openWriter()); PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengl." + REFERENCES_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengl")).openWriter());
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */"); writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
writer.println(); writer.println();
writer.println("package org.lwjgl.opengl;"); writer.println("package org.lwjgl.opengl;");
writer.println(); writer.println();
writer.println("class " + REFERENCES_CLASS_NAME + " extends BaseReferences {"); writer.println("class " + REFERENCES_CLASS_NAME + " extends BaseReferences {");
writer.println("\t" + REFERENCES_CLASS_NAME + "(ContextCapabilities caps) {"); writer.println("\t" + REFERENCES_CLASS_NAME + "(ContextCapabilities caps) {");
writer.println("\t\tsuper(caps);"); writer.println("\t\tsuper(caps);");
writer.println("\t}"); writer.println("\t}");
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
generateReferencesFromMethods(env, writer, interface_decl); generateReferencesFromMethods(env, writer, interface_decl);
} }
} }
writer.println(); writer.println();
writer.println("\tvoid copy(" + REFERENCES_CLASS_NAME + " " + REFERENCES_PARAMETER_NAME + ", int mask) {"); writer.println("\tvoid copy(" + REFERENCES_CLASS_NAME + " " + REFERENCES_PARAMETER_NAME + ", int mask) {");
writer.println("\t\tsuper.copy(" + REFERENCES_PARAMETER_NAME + ", mask);"); writer.println("\t\tsuper.copy(" + REFERENCES_PARAMETER_NAME + ", mask);");
writer.println("\t\tif ( (mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {"); writer.println("\t\tif ( (mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {");
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
generateCopiesFromMethods(processingEnv, writer, interface_decl); generateCopiesFromMethods(processingEnv, writer, interface_decl);
} }
} }
writer.println("\t\t}"); writer.println("\t\t}");
writer.println("\t}"); writer.println("\t}");
writer.println("\tvoid clear() {"); writer.println("\tvoid clear() {");
writer.println("\t\tsuper.clear();"); writer.println("\t\tsuper.clear();");
for (TypeElement interface_decl : templates) { for ( TypeElement interface_decl : templates ) {
if (interface_decl.getKind().isInterface()) { if ( interface_decl.getKind().isInterface() ) {
generateClearsFromMethods(processingEnv, writer, interface_decl); generateClearsFromMethods(processingEnv, writer, interface_decl);
} }
} }
writer.println("\t}"); writer.println("\t}");
writer.println("}"); writer.println("}");
writer.close(); writer.close();
} }
} }

View File

@ -53,311 +53,304 @@ import java.util.Map;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import static javax.lang.model.type.TypeKind.BOOLEAN;
import static javax.lang.model.type.TypeKind.BYTE;
import static javax.lang.model.type.TypeKind.DOUBLE;
import static javax.lang.model.type.TypeKind.FLOAT;
import static javax.lang.model.type.TypeKind.INT;
import static javax.lang.model.type.TypeKind.LONG;
import static javax.lang.model.type.TypeKind.SHORT;
public class GLTypeMap implements TypeMap { public class GLTypeMap implements TypeMap {
private static final Map<Class, TypeKind> native_types_to_primitive; private static final Map<Class, TypeKind> native_types_to_primitive;
static { static {
native_types_to_primitive = new HashMap<>(); native_types_to_primitive = new HashMap<>();
native_types_to_primitive.put(GLbitfield.class, TypeKind.INT); native_types_to_primitive.put(GLbitfield.class, TypeKind.INT);
native_types_to_primitive.put(GLcharARB.class, TypeKind.BYTE); native_types_to_primitive.put(GLcharARB.class, TypeKind.BYTE);
native_types_to_primitive.put(GLclampf.class, TypeKind.FLOAT); native_types_to_primitive.put(GLclampf.class, TypeKind.FLOAT);
native_types_to_primitive.put(GLfloat.class, TypeKind.FLOAT); native_types_to_primitive.put(GLfloat.class, TypeKind.FLOAT);
native_types_to_primitive.put(GLint.class, TypeKind.INT); native_types_to_primitive.put(GLint.class, TypeKind.INT);
native_types_to_primitive.put(GLshort.class, TypeKind.SHORT); native_types_to_primitive.put(GLshort.class, TypeKind.SHORT);
native_types_to_primitive.put(GLsizeiptr.class, TypeKind.LONG); native_types_to_primitive.put(GLsizeiptr.class, TypeKind.LONG);
native_types_to_primitive.put(GLuint.class, TypeKind.INT); native_types_to_primitive.put(GLuint.class, TypeKind.INT);
native_types_to_primitive.put(GLboolean.class, TypeKind.BOOLEAN); native_types_to_primitive.put(GLboolean.class, TypeKind.BOOLEAN);
native_types_to_primitive.put(GLchar.class, TypeKind.BYTE); native_types_to_primitive.put(GLchar.class, TypeKind.BYTE);
native_types_to_primitive.put(GLdouble.class, TypeKind.DOUBLE); native_types_to_primitive.put(GLdouble.class, TypeKind.DOUBLE);
native_types_to_primitive.put(GLhalf.class, TypeKind.SHORT); native_types_to_primitive.put(GLhalf.class, TypeKind.SHORT);
native_types_to_primitive.put(GLintptrARB.class, TypeKind.LONG); native_types_to_primitive.put(GLintptrARB.class, TypeKind.LONG);
native_types_to_primitive.put(GLsizei.class, TypeKind.INT); native_types_to_primitive.put(GLsizei.class, TypeKind.INT);
native_types_to_primitive.put(GLushort.class, TypeKind.SHORT); native_types_to_primitive.put(GLushort.class, TypeKind.SHORT);
native_types_to_primitive.put(GLbyte.class, TypeKind.BYTE); native_types_to_primitive.put(GLbyte.class, TypeKind.BYTE);
native_types_to_primitive.put(GLclampd.class, TypeKind.DOUBLE); native_types_to_primitive.put(GLclampd.class, TypeKind.DOUBLE);
native_types_to_primitive.put(GLenum.class, TypeKind.INT); native_types_to_primitive.put(GLenum.class, TypeKind.INT);
native_types_to_primitive.put(GLhandleARB.class, TypeKind.INT); native_types_to_primitive.put(GLhandleARB.class, TypeKind.INT);
native_types_to_primitive.put(GLintptr.class, TypeKind.LONG); native_types_to_primitive.put(GLintptr.class, TypeKind.LONG);
native_types_to_primitive.put(GLsizeiptrARB.class, TypeKind.LONG); native_types_to_primitive.put(GLsizeiptrARB.class, TypeKind.LONG);
native_types_to_primitive.put(GLubyte.class, TypeKind.BYTE); native_types_to_primitive.put(GLubyte.class, TypeKind.BYTE);
native_types_to_primitive.put(GLvoid.class, TypeKind.BYTE); native_types_to_primitive.put(GLvoid.class, TypeKind.BYTE);
native_types_to_primitive.put(GLint64EXT.class, TypeKind.LONG); native_types_to_primitive.put(GLint64EXT.class, TypeKind.LONG);
native_types_to_primitive.put(GLuint64EXT.class, TypeKind.LONG); native_types_to_primitive.put(GLuint64EXT.class, TypeKind.LONG);
native_types_to_primitive.put(GLint64.class, TypeKind.LONG); native_types_to_primitive.put(GLint64.class, TypeKind.LONG);
native_types_to_primitive.put(GLuint64.class, TypeKind.LONG); native_types_to_primitive.put(GLuint64.class, TypeKind.LONG);
} }
@Override @Override
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) { public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
TypeKind kind = native_types_to_primitive.get(native_type); TypeKind kind = native_types_to_primitive.get(native_type);
if (kind == null) { if ( kind == null ) {
throw new RuntimeException("Unsupported type " + native_type); throw new RuntimeException("Unsupported type " + native_type);
} }
return kind; return kind;
} }
@Override @Override
public void printCapabilitiesInit(final PrintWriter writer) { public void printCapabilitiesInit(final PrintWriter writer) {
writer.println("\t\tContextCapabilities caps = GLContext.getCapabilities();"); writer.println("\t\tContextCapabilities caps = GLContext.getCapabilities();");
} }
@Override @Override
public String getCapabilities() { public String getCapabilities() {
return "caps"; return "caps";
} }
@Override @Override
public String getAPIUtilParam(boolean comma) { public String getAPIUtilParam(boolean comma) {
return comma ? "caps, " : "caps"; return comma ? "caps, " : "caps";
} }
@Override @Override
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) { public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) {
writer.println(tabs + "Util.checkGLError();"); writer.println(tabs + "Util.checkGLError();");
} }
@Override @Override
public String getRegisterNativesFunctionName() { public String getRegisterNativesFunctionName() {
return "extgl_InitializeClass"; return "extgl_InitializeClass";
} }
@Override @Override
public Signedness getSignednessFromType(Class type) { public Signedness getSignednessFromType(Class type) {
if (GLuint.class.equals(type)) { if ( GLuint.class.equals(type) ) {
return Signedness.UNSIGNED; return Signedness.UNSIGNED;
} else if (GLint.class.equals(type)) { } else if ( GLint.class.equals(type) ) {
return Signedness.SIGNED; return Signedness.SIGNED;
} else if (GLushort.class.equals(type)) { } else if ( GLushort.class.equals(type) ) {
return Signedness.UNSIGNED; return Signedness.UNSIGNED;
} else if (GLshort.class.equals(type)) { } else if ( GLshort.class.equals(type) ) {
return Signedness.SIGNED; return Signedness.SIGNED;
} else if (GLubyte.class.equals(type)) { } else if ( GLubyte.class.equals(type) ) {
return Signedness.UNSIGNED; return Signedness.UNSIGNED;
} else if (GLbyte.class.equals(type)) { } else if ( GLbyte.class.equals(type) ) {
return Signedness.SIGNED; return Signedness.SIGNED;
} else if (GLuint64EXT.class.equals(type)) { } else if ( GLuint64EXT.class.equals(type) ) {
return Signedness.UNSIGNED; return Signedness.UNSIGNED;
} else if (GLint64EXT.class.equals(type)) { } else if ( GLint64EXT.class.equals(type) ) {
return Signedness.SIGNED; return Signedness.SIGNED;
} else if (GLuint64.class.equals(type)) { } else if ( GLuint64.class.equals(type) ) {
return Signedness.UNSIGNED; return Signedness.UNSIGNED;
} else if (GLint64.class.equals(type)) { } else if ( GLint64.class.equals(type) ) {
return Signedness.SIGNED; return Signedness.SIGNED;
} else { } else {
return Signedness.NONE; return Signedness.NONE;
} }
} }
@Override @Override
public String translateAnnotation(Class annotation_type) { public String translateAnnotation(Class annotation_type) {
if (annotation_type.equals(GLuint.class) || annotation_type.equals(GLint.class)) { if ( annotation_type.equals(GLuint.class) || annotation_type.equals(GLint.class) ) {
return "i"; return "i";
} else if (annotation_type.equals(GLushort.class) || annotation_type.equals(GLshort.class)) { } else if ( annotation_type.equals(GLushort.class) || annotation_type.equals(GLshort.class) ) {
return "s"; return "s";
} else if (annotation_type.equals(GLubyte.class) || annotation_type.equals(GLbyte.class)) { } else if ( annotation_type.equals(GLubyte.class) || annotation_type.equals(GLbyte.class) ) {
return "b"; return "b";
} else if (annotation_type.equals(GLfloat.class) || annotation_type.equals(GLclampf.class)) { } else if ( annotation_type.equals(GLfloat.class) || annotation_type.equals(GLclampf.class) ) {
return "f"; return "f";
} else if (annotation_type.equals(GLdouble.class) || annotation_type.equals(GLclampd.class)) { } else if ( annotation_type.equals(GLdouble.class) || annotation_type.equals(GLclampd.class) ) {
return "d"; return "d";
} else if (annotation_type.equals(GLhalf.class)) { } else if ( annotation_type.equals(GLhalf.class) ) {
return "h"; return "h";
} else if (annotation_type.equals(GLuint64EXT.class) || annotation_type.equals(GLint64EXT.class) || annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class)) { } else if ( annotation_type.equals(GLuint64EXT.class) || annotation_type.equals(GLint64EXT.class) || annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class) ) {
return "i64"; return "i64";
} else if (annotation_type.equals(GLboolean.class) || annotation_type.equals(GLvoid.class)) { } else if ( annotation_type.equals(GLboolean.class) || annotation_type.equals(GLvoid.class) ) {
return ""; return "";
} else { } else {
throw new RuntimeException(annotation_type + " is not allowed"); throw new RuntimeException(annotation_type + " is not allowed");
} }
} }
@Override @Override
public Class getNativeTypeFromPrimitiveType(TypeKind kind) { public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
Class type; Class type;
switch (kind) { switch ( kind ) {
case INT: case INT:
type = GLint.class; type = GLint.class;
break; break;
case DOUBLE: case DOUBLE:
type = GLdouble.class; type = GLdouble.class;
break; break;
case FLOAT: case FLOAT:
type = GLfloat.class; type = GLfloat.class;
break; break;
case SHORT: case SHORT:
type = GLshort.class; type = GLshort.class;
break; break;
case BYTE: case BYTE:
type = GLbyte.class; type = GLbyte.class;
break; break;
case LONG: case LONG:
type = GLint64EXT.class; type = GLint64EXT.class;
break; break;
case BOOLEAN: case BOOLEAN:
type = GLboolean.class; type = GLboolean.class;
break; break;
default: default:
throw new RuntimeException(kind + " is not allowed"); throw new RuntimeException(kind + " is not allowed");
} }
return type; return type;
} }
@Override @Override
public Class<? extends Annotation> getVoidType() { public Class<? extends Annotation> getVoidType() {
return GLvoid.class; return GLvoid.class;
} }
@Override @Override
public Class<? extends Annotation> getStringElementType() { public Class<? extends Annotation> getStringElementType() {
return GLubyte.class; return GLubyte.class;
} }
@Override @Override
public Class<? extends Annotation> getStringArrayType() { public Class<? extends Annotation> getStringArrayType() {
return GLchar.class; return GLchar.class;
} }
@Override @Override
public Class<? extends Annotation> getByteBufferArrayType() { public Class<? extends Annotation> getByteBufferArrayType() {
return GLchar.class; return GLchar.class;
} }
private static Class[] getValidBufferTypes(Class type) { private static Class[] getValidBufferTypes(Class type) {
if (type.equals(IntBuffer.class)) { if ( type.equals(IntBuffer.class) ) {
return new Class[]{GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class, return new Class[] { GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class,
GLsizei.class, GLuint.class, GLvoid.class}; GLsizei.class, GLuint.class, GLvoid.class };
} else if (type.equals(FloatBuffer.class)) { } else if ( type.equals(FloatBuffer.class) ) {
return new Class[]{GLclampf.class, GLfloat.class}; return new Class[] { GLclampf.class, GLfloat.class };
} else if (type.equals(ByteBuffer.class)) { } else if ( type.equals(ByteBuffer.class) ) {
return new Class[]{GLboolean.class, GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class, GLvoid.class}; return new Class[] { GLboolean.class, GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class, GLvoid.class };
} else if (type.equals(ShortBuffer.class)) { } else if ( type.equals(ShortBuffer.class) ) {
return new Class[]{GLhalf.class, GLshort.class, GLushort.class}; return new Class[] { GLhalf.class, GLshort.class, GLushort.class };
} else if (type.equals(DoubleBuffer.class)) { } else if ( type.equals(DoubleBuffer.class) ) {
return new Class[]{GLclampd.class, GLdouble.class}; return new Class[] { GLclampd.class, GLdouble.class };
} else if (type.equals(LongBuffer.class)) { } else if ( type.equals(LongBuffer.class) ) {
return new Class[]{GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class}; return new Class[] { GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class };
} else { } else {
return new Class[]{}; return new Class[] { };
} }
} }
private static Class[] getValidPrimitiveTypes(Class type) { private static Class[] getValidPrimitiveTypes(Class type) {
if (type.equals(long.class)) { if ( type.equals(long.class) ) {
return new Class[]{GLintptrARB.class, GLuint.class, GLintptr.class, GLsizeiptrARB.class, GLsizeiptr.class, GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class}; return new Class[] { GLintptrARB.class, GLuint.class, GLintptr.class, GLsizeiptrARB.class, GLsizeiptr.class, GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class };
} else if (type.equals(int.class)) { } else if ( type.equals(int.class) ) {
return new Class[]{GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class, GLuint.class, return new Class[] { GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class, GLuint.class,
GLsizei.class}; GLsizei.class };
} else if (type.equals(double.class)) { } else if ( type.equals(double.class) ) {
return new Class[]{GLclampd.class, GLdouble.class}; return new Class[] { GLclampd.class, GLdouble.class };
} else if (type.equals(float.class)) { } else if ( type.equals(float.class) ) {
return new Class[]{GLclampf.class, GLfloat.class}; return new Class[] { GLclampf.class, GLfloat.class };
} else if (type.equals(short.class)) { } else if ( type.equals(short.class) ) {
return new Class[]{GLhalf.class, GLshort.class, GLushort.class}; return new Class[] { GLhalf.class, GLshort.class, GLushort.class };
} else if (type.equals(byte.class)) { } else if ( type.equals(byte.class) ) {
return new Class[]{GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class}; return new Class[] { GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class };
} else if (type.equals(boolean.class)) { } else if ( type.equals(boolean.class) ) {
return new Class[]{GLboolean.class}; return new Class[] { GLboolean.class };
} else if (type.equals(void.class)) { } else if ( type.equals(void.class) ) {
return new Class[]{GLvoid.class, GLreturn.class}; return new Class[] { GLvoid.class, GLreturn.class };
} else { } else {
return new Class[]{}; return new Class[] { };
} }
} }
@Override @Override
public String getTypedefPostfix() { public String getTypedefPostfix() {
return ""; return "";
} }
@Override @Override
public String getFunctionPrefix() { public String getFunctionPrefix() {
return "APIENTRY"; return "APIENTRY";
} }
@Override @Override
public void printNativeIncludes(PrintWriter writer) { public void printNativeIncludes(PrintWriter writer) {
writer.println("#include \"extgl.h\""); writer.println("#include \"extgl.h\"");
} }
@Override @Override
public Class[] getValidAnnotationTypes(Class type) { public Class[] getValidAnnotationTypes(Class type) {
Class[] valid_types; Class[] valid_types;
if (Buffer.class.isAssignableFrom(type)) { if ( Buffer.class.isAssignableFrom(type) ) {
valid_types = getValidBufferTypes(type); valid_types = getValidBufferTypes(type);
} else if (type.isPrimitive()) { } else if ( type.isPrimitive() ) {
valid_types = getValidPrimitiveTypes(type); valid_types = getValidPrimitiveTypes(type);
} else if (String.class.equals(type)) { } else if ( String.class.equals(type) ) {
valid_types = new Class[]{GLubyte.class}; valid_types = new Class[] { GLubyte.class };
} else if (org.lwjgl.PointerWrapper.class.isAssignableFrom(type)) { } else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) ) {
valid_types = new Class[]{PointerWrapper.class}; valid_types = new Class[] { PointerWrapper.class };
} else if (void.class.equals(type)) { } else if ( void.class.equals(type) ) {
valid_types = new Class[]{GLreturn.class}; valid_types = new Class[] { GLreturn.class };
} else if (PointerBuffer.class.equals(type)) { } else if ( PointerBuffer.class.equals(type) ) {
valid_types = new Class[]{GLintptr.class, GLintptrARB.class, GLsizeiptr.class, GLsizeiptrARB.class}; valid_types = new Class[] { GLintptr.class, GLintptrARB.class, GLsizeiptr.class, GLsizeiptrARB.class };
} else { } else {
valid_types = new Class[]{}; valid_types = new Class[] { };
} }
return valid_types; return valid_types;
} }
@Override @Override
public Class<? extends Annotation> getInverseType(Class type) { public Class<? extends Annotation> getInverseType(Class type) {
if (GLuint.class.equals(type)) { if ( GLuint.class.equals(type) ) {
return GLint.class; return GLint.class;
} else if (GLint.class.equals(type)) { } else if ( GLint.class.equals(type) ) {
return GLuint.class; return GLuint.class;
} else if (GLushort.class.equals(type)) { } else if ( GLushort.class.equals(type) ) {
return GLshort.class; return GLshort.class;
} else if (GLshort.class.equals(type)) { } else if ( GLshort.class.equals(type) ) {
return GLushort.class; return GLushort.class;
} else if (GLubyte.class.equals(type)) { } else if ( GLubyte.class.equals(type) ) {
return GLbyte.class; return GLbyte.class;
} else if (GLbyte.class.equals(type)) { } else if ( GLbyte.class.equals(type) ) {
return GLubyte.class; return GLubyte.class;
} else if (GLuint64EXT.class.equals(type)) { } else if ( GLuint64EXT.class.equals(type) ) {
return GLint64EXT.class; return GLint64EXT.class;
} else if (GLint64EXT.class.equals(type)) { } else if ( GLint64EXT.class.equals(type) ) {
return GLuint64EXT.class; return GLuint64EXT.class;
} else if (GLuint64.class.equals(type)) { } else if ( GLuint64.class.equals(type) ) {
return GLint64.class; return GLint64.class;
} else if (GLint64.class.equals(type)) { } else if ( GLint64.class.equals(type) ) {
return GLuint64.class; return GLuint64.class;
} else { } else {
return null; return null;
} }
} }
@Override @Override
public String getAutoTypeFromAnnotation(AnnotationMirror annotation) { public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType()); Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
if (annotation_class.equals(GLint.class)) { if ( annotation_class.equals(GLint.class) ) {
return "GL11.GL_INT"; return "GL11.GL_INT";
} else if (annotation_class.equals(GLbyte.class)) { } else if ( annotation_class.equals(GLbyte.class) ) {
return "GL11.GL_BYTE"; return "GL11.GL_BYTE";
} else if (annotation_class.equals(GLshort.class)) { } else if ( annotation_class.equals(GLshort.class) ) {
return "GL11.GL_SHORT"; return "GL11.GL_SHORT";
} }
if (annotation_class.equals(GLuint.class)) { if ( annotation_class.equals(GLuint.class) ) {
return "GL11.GL_UNSIGNED_INT"; return "GL11.GL_UNSIGNED_INT";
} else if (annotation_class.equals(GLubyte.class)) { } else if ( annotation_class.equals(GLubyte.class) ) {
return "GL11.GL_UNSIGNED_BYTE"; return "GL11.GL_UNSIGNED_BYTE";
} else if (annotation_class.equals(GLushort.class)) { } else if ( annotation_class.equals(GLushort.class) ) {
return "GL11.GL_UNSIGNED_SHORT"; return "GL11.GL_UNSIGNED_SHORT";
} else if (annotation_class.equals(GLfloat.class)) { } else if ( annotation_class.equals(GLfloat.class) ) {
return "GL11.GL_FLOAT"; return "GL11.GL_FLOAT";
} else if (annotation_class.equals(GLdouble.class)) { } else if ( annotation_class.equals(GLdouble.class) ) {
return "GL11.GL_DOUBLE"; return "GL11.GL_DOUBLE";
} else { } else {
return null; return null;
} }
} }
} }

View File

@ -40,12 +40,12 @@ package org.lwjgl.util.generator.opengl;
import org.lwjgl.util.generator.NativeType; import org.lwjgl.util.generator.NativeType;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
@NativeType @NativeType
@Target({ElementType.PARAMETER, ElementType.METHOD}) @Target({ ElementType.PARAMETER, ElementType.METHOD })
public @interface GLvoid { public @interface GLvoid {
TypeKind value() default TypeKind.BYTE; TypeKind value() default TypeKind.BYTE;
} }