41package com.jogamp.gluegen.opengl.nativesig;
43import com.jogamp.gluegen.GlueGenException;
44import com.jogamp.gluegen.JavaMethodBindingEmitter;
45import com.jogamp.gluegen.JavaType;
46import com.jogamp.gluegen.MethodBinding;
47import com.jogamp.gluegen.cgram.types.Type;
48import com.jogamp.gluegen.opengl.GLEmitter;
49import com.jogamp.gluegen.opengl.GLJavaMethodBindingEmitter;
50import com.jogamp.gluegen.procaddress.ProcAddressJavaMethodBindingEmitter;
64 super(methodToWrap,
false,
null,
false,
false, emitter);
69 buf.append(getBaseIndentString());
71 return super.appendSignature(buf);
75 if (hasModifier(JavaMethodBindingEmitter.NATIVE)) {
78 buf.append(
"@NativeSignature(\"l");
79 final MethodBinding binding = getBinding();
80 if (callThroughProcAddress) {
84 if (callThroughProcAddress) {
87 for (
int i = 0; i < binding.getNumArguments(); i++) {
99 throw new InternalError(
"Error parsing arguments -- void should not be seen aside from argument 0");
104 if (type.isNIOBuffer()) {
106 }
else if (type.isPrimitiveArray()) {
108 }
else if (type.isPrimitive()) {
109 final Class<?> clazz = type.getJavaClass();
110 if (clazz == Byte.TYPE) { buf.append(
"B"); }
111 else if (clazz == Character.TYPE) { buf.append(
"C"); }
112 else if (clazz == Double.TYPE) { buf.append(
"D"); }
113 else if (clazz == Float.TYPE) { buf.append(
"F"); }
114 else if (clazz == Integer.TYPE) { buf.append(
"I"); }
115 else if (clazz == Long.TYPE) {
117 if (cType.isPointer()) {
123 else if (clazz == Short.TYPE) { buf.append(
"S"); }
124 else if (clazz == Boolean.TYPE) { buf.append(
"Z"); }
125 else throw new InternalError(
"Unhandled primitive type " + clazz);
126 }
else if (type.isString()) {
129 throw new RuntimeException(
"Type not yet handled: " + type);
135 if (isPrivateNativeMethod()) {
136 final JavaType returnType = getBinding().getJavaReturnType();
137 if (returnType.isString() || returnType.isNIOByteBuffer()) {
142 return super.getReturnTypeString(skipArray);
147 super.emitPreCallSetup(binding);
148 for (
int i = 0; i < binding.getNumArguments(); i++) {
149 final JavaType type = binding.getJavaArgumentType(i);
150 if (type.isNIOBuffer() && !useNIODirectOnly ) {
155 }
else if (type.isString()) {
156 unit.emitln(
" long " + binding.getArgumentName(i) +
"_c_str = BuffersInternal.newCString(" + binding.getArgumentName(i) +
");");
163 return "__buffer_array_" + argNumber;
168 boolean needComma =
false;
171 if (callThroughProcAddress) {
172 if (changeNameAndArguments) {
173 buf.append(
"long procAddress");
179 if (isPrivateNativeMethod() && binding.hasContainingType()) {
186 buf.append(javaThisArgumentName());
191 for (
int i = 0; i < binding.getNumArguments(); i++) {
192 final JavaType type = binding.getJavaArgumentType(i);
196 if (binding.getNumArguments() != 1) {
197 throw new InternalError(
198 "\"void\" argument type found in " +
199 "multi-argument function \"" + binding +
"\"");
204 if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) {
213 if (isPrivateNativeMethod() &&
214 (isForDirectBufferImplementation() && type.isNIOBuffer() ||
220 buf.append(erasedTypeString(type,
false));
229 if (isForIndirectBufferAndArrayImplementation()) {
230 if (type.isNIOBuffer()) {
231 buf.append(
", int " + byteOffsetArgName(i));
232 }
else if (type.isNIOBufferArray()) {
233 buf.append(
", int[] " +
234 byteOffsetArrayArgName(i));
239 if (type.isPrimitiveArray()) {
240 buf.append(
", int " + offsetArgName(i));
249 final JavaType returnType = binding.getJavaReturnType();
250 boolean needsResultAssignment =
false;
252 if (!returnType.isVoid()) {
253 if (returnType.isCompoundTypeWrapper() ||
254 returnType.isNIOByteBuffer()) {
255 unit.emitln(
"final java.nio.ByteBuffer _res;");
256 needsResultAssignment =
true;
257 }
else if (returnType.isArrayOfCompoundTypeWrappers()) {
258 unit.emitln(
"final java.nio.ByteBuffer[] _res;");
259 needsResultAssignment =
true;
260 }
else if (returnType.isString() || returnType.isNIOByteBuffer()) {
262 unit.emit(returnType.toString());
263 unit.emitln(
" _res;");
264 needsResultAssignment =
true;
270 unit.emitln(
" _res;");
271 needsResultAssignment =
true;
275 if (binding.signatureCanUseIndirectNIO() && !useNIODirectOnly) {
278 unit.emitln(
"if (_direct) {");
282 if (needsResultAssignment) {
283 unit.emit(
" _res = ");
284 if (returnType.isString()) {
285 unit.emit(
"BuffersInternal.newJavaString(");
286 }
else if (returnType.isNIOByteBuffer()) {
287 unit.emit(
"BuffersInternal.newDirectByteBuffer(");
291 if (!returnType.isVoid()) {
292 unit.emit(
"return ");
296 if (binding.signatureUsesJavaPrimitiveArrays() &&
297 !binding.signatureCanUseIndirectNIO()) {
305 if (returnType.isString() || returnType.isNIOByteBuffer()) {
312 if (returnType.isString() || returnType.isNIOByteBuffer()) {
318 if (binding.signatureCanUseIndirectNIO() && !useNIODirectOnly) {
322 unit.emitln(
" } else {");
324 if (needsResultAssignment) {
325 unit.emit(
" _res = ");
328 if (!returnType.isVoid()) {
329 unit.emit(
"return ");
339 emitPrologueOrEpilogue(epilogue);
340 if (needsResultAssignment) {
350 boolean needComma =
false;
351 int numArgsEmitted = 0;
353 if (callThroughProcAddress) {
354 unit.emit(
"__addr_");
359 if (binding.hasContainingType()) {
361 assert(binding.getContainingType().isCompoundTypeWrapper());
362 unit.emit(
"BuffersInternal.getDirectBufferAddress(");
363 unit.emit(
"getBuffer()");
368 for (
int i = 0; i < binding.getNumArguments(); i++) {
369 final JavaType type = binding.getJavaArgumentType(i);
370 if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) {
378 assert(binding.getNumArguments() == 1);
386 if (type.isCompoundTypeWrapper()) {
387 unit.emit(
"BuffersInternal.getDirectBufferAddress(");
391 if (type.isNIOBuffer()) {
395 unit.emit(
"BuffersInternal.getDirectBufferAddress(");
403 if (type.isCompoundTypeWrapper()) {
404 unit.emit(
" == null) ? null : ");
406 unit.emit(
".getBuffer())");
410 if (type.isNIOBuffer()) {
412 unit.emit(
"+ Buffers.getDirectBufferByteOffset(" +
getArgumentName(i) +
")");
414 unit.emit(
", BuffersInternal.arrayBaseOffset(" +
416 ") + Buffers.getIndirectBufferByteOffset(" +
getArgumentName(i) +
")");
418 }
else if (type.isNIOBufferArray()) {
419 unit.emit(
", " + byteOffsetArrayArgName(i));
423 if (type.isPrimitiveArray()) {
425 unit.emit(
"BuffersInternal.arrayBaseOffset(" +
getArgumentName(i) +
") + ");
426 if(type.isFloatArray()) {
427 unit.emit(
"Buffers.SIZEOF_FLOAT * ");
428 }
else if(type.isDoubleArray()) {
429 unit.emit(
"Buffers.SIZEOF_DOUBLE * ");
430 }
else if(type.isByteArray()) {
432 }
else if(type.isLongArray()) {
433 unit.emit(
"Buffers.SIZEOF_LONG * ");
434 }
else if(type.isShortArray()) {
435 unit.emit(
"Buffers.SIZEOF_SHORT * ");
436 }
else if(type.isIntArray()) {
437 unit.emit(
"Buffers.SIZEOF_INT * ");
439 throw new GlueGenException(
"Unsupported type for calculating array offset argument for " +
441 "-- error occurred while processing Java glue code for " + binding.getCSymbol().getAliasedString(),
442 binding.getCSymbol().getASTLocusTag());
444 unit.emit(offsetArgName(i));
447 if (type.isString()) {
451 if (type.isCompoundTypeWrapper()) {
458 return numArgsEmitted;
463 for (
int i = 0; i < binding.getNumArguments(); i++) {
464 final JavaType type = binding.getJavaArgumentType(i);
465 if (type.isString()) {
467 unit.emitln(
" BuffersInternal.freeCString(" + binding.getArgumentName(i) +
"_c_str);");
472 super.emitCallResultReturn(binding);
477 final String res = super.getNativeName();
479 return res +
"BufObj";
487 name = binding.getName() +
"$0";
489 name = binding.getName() +
"$1";
492 return name +
"BufObj";
A subclass of ProcAddressEmitter with special OpenGL-specific configuration abilities.
A specialization of the proc address emitter which knows how to change argument names to take into ac...
String getArgumentName(final int i)
boolean bufferObjectVariant
Emitter producing NativeSignature attributes.
Review: This Package/Class is not used and subject to be deleted.
int emitCallArguments(final MethodBinding binding, final boolean direct)
NativeSignatureJavaMethodBindingEmitter(final GLJavaMethodBindingEmitter methodToWrap)
int appendArguments(final StringBuilder buf)
String getImplMethodName(final boolean direct)
NativeSignatureJavaMethodBindingEmitter(final JavaMethodBindingEmitter methodToWrap, final NativeSignatureEmitter emitter)
void emitPreCallSetup(final MethodBinding binding)
StringBuilder appendSignature(final StringBuilder buf)
String getReturnTypeString(final boolean skipArray)
void appendNativeSignatureAnnotation(final StringBuilder buf)
void emitReturnVariableSetupAndCall(final MethodBinding binding)
NativeSignatureJavaMethodBindingEmitter(final ProcAddressJavaMethodBindingEmitter methodToWrap, final GLEmitter emitter, final boolean bufferObjectVariant)
String getNIOBufferArrayName(final int argNumber)
void emitCallResultReturn(final MethodBinding binding)
void appendNativeSignatureElement(final StringBuilder buf, final JavaType type, final Type cType, final int index)