void outputFunction(FILE *fp, ClassInfo *data) { int i; unsigned int rType = (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE); int args_ok = checkFunctionSignature(data); /* handle DataReader SetBinaryInputString as a special case */ if (!strcmp("SetBinaryInputString",currentFunction->Name) && (!strcmp("vtkDataReader",data->Name) || !strcmp("vtkStructuredGridReader",data->Name) || !strcmp("vtkRectilinearGridReader",data->Name) || !strcmp("vtkUnstructuredGridReader",data->Name) || !strcmp("vtkStructuredPointsReader",data->Name) || !strcmp("vtkPolyDataReader",data->Name))) { HandleDataReader(fp); wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } if (currentFunction->IsPublic && args_ok && strcmp(data->Name,currentFunction->Name) && strcmp(data->Name, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n private native "); return_result_native(fp); fprintf(fp,"%s_%i(",currentFunction->Name,numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } fprintf(fp,");\n"); fprintf(fp," public "); return_result(fp); fprintf(fp,"%s(",currentFunction->Name); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } /* if returning object, lookup in global hash */ if (rType == VTK_PARSE_VTK_OBJECT_PTR) { fprintf(fp,") {"); fprintf(fp,"\n long temp = %s_%i(",currentFunction->Name, numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } fprintf(fp,");\n"); fprintf(fp,"\n if (temp == 0) return null;"); fprintf(fp,"\n return (%s)vtkObject.JAVA_OBJECT_MANAGER.getJavaObject(temp);", currentFunction->ReturnClass); fprintf(fp,"\n }\n"); } else { /* if not void then need return otherwise none */ if (rType == VTK_PARSE_VOID) { fprintf(fp,")\n { %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } else { fprintf(fp,")\n { return %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } fprintf(fp,"); }\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } } }
void outputFunction(FILE *fp, ClassInfo *data) { int i; if (notWrappable(currentFunction)) { return; } /* if the args are OK and it is not a constructor or destructor */ if (managableArguments(currentFunction) && strcmp(data->Name,currentFunction->Name) && strcmp(data->Name,currentFunction->Name + 1)) { if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp," if (!strcmp(\"%s\",method) && msg.GetNumberOfArguments(0) == %i)\n", currentFunction->Name, currentFunction->NumberOfArguments+2); fprintf(fp, " {\n"); /* process the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { output_temp(fp, i, currentFunction->ArgTypes[i], currentFunction->ArgClasses[i], currentFunction->ArgCounts[i]); } output_temp(fp, MAX_ARGS,currentFunction->ReturnType, currentFunction->ReturnClass, 0); if(currentFunction->NumberOfArguments > 0) { const char* amps = " if("; /* now get the required args from the stack */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { fprintf(fp, "%s", amps); amps = " &&\n "; get_args(fp,i); } fprintf(fp, ")\n"); } fprintf(fp, " {\n"); if ((currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE) == VTK_PARSE_VOID) { fprintf(fp," op->%s(",currentFunction->Name); } else if ((currentFunction->ReturnType & VTK_PARSE_INDIRECT) == VTK_PARSE_REF) { fprintf(fp," temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name); } else { fprintf(fp," temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } if (((currentFunction->ArgTypes[i] & VTK_PARSE_INDIRECT) == VTK_PARSE_REF) && ((currentFunction->ArgTypes[i] & VTK_PARSE_BASE_TYPE) == VTK_PARSE_VTK_OBJECT)) { fprintf(fp,"*(temp%i)",i); } else if ((((currentFunction->ArgTypes[i] & VTK_PARSE_INDIRECT) == 0) || ((currentFunction->ArgTypes[i] & VTK_PARSE_INDIRECT) == VTK_PARSE_REF)) && ((currentFunction->ArgTypes[i] & VTK_PARSE_BASE_TYPE) == VTK_PARSE_STRING)) { /* explicit construction avoids possible ambiguity */ fprintf(fp,"vtkStdString(temp%i)",i); } else { fprintf(fp,"temp%i",i); } } fprintf(fp,");\n"); return_result(fp); fprintf(fp," return 1;\n"); fprintf(fp," }\n"); fprintf(fp," }\n"); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } #if 0 if (!strcmp("vtkObject",data->Name)) { fprintf(fp," if (!strcmp(\"AddProgressObserver\",method) && msg.NumberOfArguments == 3 &&\n"); fprintf(fp," msg.ArgumentTypes[2] == vtkClietnServerStream::string_value)\n"); fprintf(fp," {\n"); fprintf(fp," vtkClientServerProgressObserver *apo = vtkClientServerProgressObserver::New();\n"); fprintf(fp," vtkObject* obj = arlu->GetObjectFromMessage(msg, 0, 1);\n"); fprintf(fp," apo->SetFilterID(arlu->GetIDFromObject(obj));\n"); fprintf(fp," apo->SetClientServerUtil(arlu);\n"); fprintf(fp," char *temp0 = vtkClientServerInterpreter::GetString(msg,2);\n"); fprintf(fp," op->AddObserver(temp0,apo);\n"); fprintf(fp," apo->Delete();\n"); fprintf(fp," delete [] temp0;\n"); fprintf(fp," return 1;\n"); fprintf(fp," }\n"); } #endif }
void outputFunction(FILE *fp, FileInfo *data) { int i; int args_ok = 1; /* beans */ char *beanfunc; /* some functions will not get wrapped no matter what else */ if (currentFunction->IsPureVirtual || currentFunction->IsOperator || currentFunction->ArrayFailure || !currentFunction->IsPublic || !currentFunction->Name) { return; } /* make the first letter lowercase for set get methods */ beanfunc = strdup(currentFunction->Name); if (isupper(beanfunc[0])) beanfunc[0] = beanfunc[0] + 32; /* check to see if we can handle the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (currentFunction->ArgTypes[i] % 0x1000 == 0x9) args_ok = 0; if ((currentFunction->ArgTypes[i] % 0x10) == 0x8) args_ok = 0; if (((currentFunction->ArgTypes[i] % 0x1000)/0x100 != 0x3)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x109)&& ((currentFunction->ArgTypes[i] % 0x1000)/0x100)) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x313) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x314) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x315) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x316) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31A) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31B) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31C) args_ok = 0; } if ((currentFunction->ReturnType % 0x10) == 0x8) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x9) args_ok = 0; if (((currentFunction->ReturnType % 0x1000)/0x100 != 0x3)&& (currentFunction->ReturnType % 0x1000 != 0x109)&& ((currentFunction->ReturnType % 0x1000)/0x100)) args_ok = 0; /* eliminate unsigned char * and unsigned short * */ if (currentFunction->ReturnType % 0x1000 == 0x313) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x314) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x315) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x316) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31A) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31B) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31C) args_ok = 0; if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == 0x5000) &&(currentFunction->NumberOfArguments != 1)) args_ok = 0; /* make sure we have all the info we need for array arguments in */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (((currentFunction->ArgTypes[i] % 0x1000)/0x100 == 0x3)&& (currentFunction->ArgCounts[i] <= 0)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x309)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x303)) args_ok = 0; } /* if we need a return type hint make sure we have one */ switch (currentFunction->ReturnType % 0x1000) { case 0x301: case 0x302: case 0x307: case 0x304: case 0x305: case 0x306: case 0x30A: case 0x30B: case 0x30C: args_ok = currentFunction->HaveHint; break; } /* make sure it isn't a Delete or New function */ if (!strcmp("Delete",currentFunction->Name) || !strcmp("New",currentFunction->Name)) { args_ok = 0; } if (currentFunction->IsPublic && args_ok && strcmp(data->ClassName,currentFunction->Name) && strcmp(data->ClassName, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n private native "); return_result(fp); fprintf(fp,"%s_%i(",currentFunction->Name,numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); } fprintf(fp,");\n"); fprintf(fp," public "); return_result(fp); fprintf(fp,"%s(",beanfunc); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); } /* if not void then need return otherwise none */ if (currentFunction->ReturnType % 0x1000 == 0x2) { fprintf(fp,")\n { %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } else { fprintf(fp,")\n { return %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } if ((currentFunction->NumberOfArguments == 1) && (currentFunction->ArgTypes[0] == 0x5000)) fprintf(fp,",id1"); /* stick in secret beanie code for set methods */ if (currentFunction->ReturnType % 0x1000 == 0x2) { /* only care about set methods and On/Off methods */ if (!strncmp(beanfunc,"set",3) && currentFunction->NumberOfArguments == 1 && (currentFunction->ArgTypes[0] % 0x1000 < 0x10 || currentFunction->ArgTypes[0] % 0x1000 == 0x303 || currentFunction->ArgTypes[0] % 0x10 == 0x9)) { char prop[256]; strncpy(prop,beanfunc+3,strlen(beanfunc)-3); prop[strlen(beanfunc)-3] = '\0'; if (isupper(prop[0])) prop[0] = prop[0] + 32; fprintf(fp,");\n changes.firePropertyChange(\"%s\",null,",prop); /* handle basic types */ if (currentFunction->ArgTypes[0] % 0x1000 == 0x303) { fprintf(fp," id0"); } else { switch (currentFunction->ArgTypes[0] % 0x10) { case 0x1: case 0x7: fprintf(fp," new Double(id0)"); break; case 0x4: case 0x5: case 0x6: fprintf(fp," new Integer(id0)"); break; case 0x9: fprintf(fp," id0"); break; case 0x3: /* not implemented yet */ default: fprintf(fp," null"); } } } /* not a set method is it an On/Off method ? */ else { if (!strncmp(beanfunc + strlen(beanfunc) - 2, "On",2)) { /* OK we think this is a Boolean method so need to fire a change */ char prop[256]; strncpy(prop,beanfunc,strlen(beanfunc)-2); prop[strlen(beanfunc)-2] = '\0'; fprintf(fp,");\n changes.firePropertyChange(\"%s\",null,new Integer(1)", prop); } if (!strncmp(beanfunc + strlen(beanfunc) - 3, "Off",3)) { /* OK we think this is a Boolean method so need to fire a change */ char prop[256]; strncpy(prop,beanfunc,strlen(beanfunc)-3); prop[strlen(beanfunc)-3] = '\0'; fprintf(fp,");\n changes.firePropertyChange(\"%s\",null,new Integer(0)", prop); } } } fprintf(fp,"); }\n"); wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } } free(beanfunc); }
void outputFunction(FILE *fp, ClassInfo *data) { unsigned int rType = (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE); unsigned int aType = 0; int i; /* beans */ char *beanfunc; /* make the first letter lowercase for set get methods */ beanfunc = strdup(currentFunction->Name); if (isupper(beanfunc[0])) beanfunc[0] = beanfunc[0] + 32; args_ok = checkFunctionSignature(data); if (currentFunction->IsPublic && args_ok && strcmp(data->Name,currentFunction->Name) && strcmp(data->Name, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n private native "); return_result(fp); fprintf(fp,"%s_%i(",currentFunction->Name,numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } fprintf(fp,");\n"); fprintf(fp," public "); return_result(fp); fprintf(fp,"%s(",beanfunc); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } /* if not void then need return otherwise none */ if (rType == VTK_PARSE_VOID) { fprintf(fp,")\n { %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } else { fprintf(fp,")\n { return %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } if ((currentFunction->NumberOfArguments == 1) && (currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION)) fprintf(fp,",id1"); /* stick in secret beanie code for set methods */ if (rType == VTK_PARSE_VOID) { aType = (currentFunction->ArgTypes[0] & VTK_PARSE_UNQUALIFIED_TYPE); /* only care about set methods and On/Off methods */ if (!strncmp(beanfunc,"set",3) && currentFunction->NumberOfArguments == 1 && (((aType & VTK_PARSE_INDIRECT) == 0 && (aType & VTK_PARSE_UNSIGNED) == 0)|| aType == VTK_PARSE_CHAR_PTR || (aType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_OBJECT)) { char prop[256]; strncpy(prop,beanfunc+3,strlen(beanfunc)-3); prop[strlen(beanfunc)-3] = '\0'; if (isupper(prop[0])) prop[0] = prop[0] + 32; fprintf(fp,");\n changes.firePropertyChange(\"%s\",null,",prop); /* handle basic types */ if ((aType == VTK_PARSE_CHAR_PTR) || (aType == VTK_PARSE_STRING) || (aType == VTK_PARSE_STRING_REF)) { fprintf(fp," id0"); } else { switch ((aType & VTK_PARSE_BASE_TYPE) & ~VTK_PARSE_UNSIGNED) { case VTK_PARSE_FLOAT: case VTK_PARSE_DOUBLE: fprintf(fp," new Double(id0)"); break; case VTK_PARSE_INT: case VTK_PARSE_SHORT: case VTK_PARSE_LONG: fprintf(fp," new Integer(id0)"); break; case VTK_PARSE_OBJECT: fprintf(fp," id0"); break; case VTK_PARSE_CHAR: /* not implemented yet */ default: fprintf(fp," null"); } } } /* not a set method is it an On/Off method ? */ else { if (!strncmp(beanfunc + strlen(beanfunc) - 2, "On",2)) { /* OK we think this is a Boolean method so need to fire a change */ char prop[256]; strncpy(prop,beanfunc,strlen(beanfunc)-2); prop[strlen(beanfunc)-2] = '\0'; fprintf(fp,");\n changes.firePropertyChange(\"%s\",null,new Integer(1)", prop); } if (!strncmp(beanfunc + strlen(beanfunc) - 3, "Off",3)) { /* OK we think this is a Boolean method so need to fire a change */ char prop[256]; strncpy(prop,beanfunc,strlen(beanfunc)-3); prop[strlen(beanfunc)-3] = '\0'; fprintf(fp,");\n changes.firePropertyChange(\"%s\",null,new Integer(0)", prop); } } } fprintf(fp,"); }\n"); wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } } free(beanfunc); }
void outputFunction(FILE *fp, ClassInfo *data) { int i; int args_ok; unsigned int rType = (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE); const char *jniFunction = 0; char *jniFunctionNew = 0; char *jniFunctionOld = 0; size_t j; CurrentData = data; args_ok = checkFunctionSignature(data); /* handle DataReader SetBinaryInputString as a special case */ if (!strcmp("SetBinaryInputString",currentFunction->Name) && (!strcmp("vtkDataReader",data->Name) || !strcmp("vtkStructuredGridReader",data->Name) || !strcmp("vtkRectilinearGridReader",data->Name) || !strcmp("vtkUnstructuredGridReader",data->Name) || !strcmp("vtkStructuredPointsReader",data->Name) || !strcmp("vtkPolyDataReader",data->Name))) { if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } HandleDataReader(fp,data); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } if (currentFunction->IsPublic && args_ok && strcmp(data->Name,currentFunction->Name) && strcmp(data->Name, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n"); /* Underscores are escaped in method names, see http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp133 VTK class names contain no underscore and do not need to be escaped. */ jniFunction = currentFunction->Name; jniFunctionOld = 0; j = 0; while (jniFunction[j] != '\0') { /* replace "_" with "_1" */ if (jniFunction[j] == '_') { j++; jniFunctionNew = (char *)malloc(strlen(jniFunction) + 2); strncpy(jniFunctionNew, jniFunction, j); jniFunctionNew[j] = '1'; strcpy(&jniFunctionNew[j+1], &jniFunction[j]); free(jniFunctionOld); jniFunctionOld = jniFunctionNew; jniFunction = jniFunctionNew; } j++; } if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp,"extern \"C\" JNIEXPORT "); return_result(fp); fprintf(fp," JNICALL Java_vtk_%s_%s_1%i(JNIEnv *env, jobject obj", data->Name, jniFunction, numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { fprintf(fp,","); output_proto_vars(fp, i); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } fprintf(fp,")\n{\n"); /* get the object pointer */ fprintf(fp," %s *op;\n",data->Name); /* process the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { output_temp(fp, i, currentFunction->ArgTypes[i], currentFunction->ArgClasses[i], currentFunction->ArgCounts[i]); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } output_temp(fp, MAX_ARGS,currentFunction->ReturnType, currentFunction->ReturnClass,0); /* now get the required args from the stack */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { get_args(fp, i); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } fprintf(fp,"\n op = (%s *)vtkJavaGetPointerFromObject(env,obj);\n", data->Name); switch (rType) { case VTK_PARSE_VOID: fprintf(fp," op->%s(",currentFunction->Name); break; default: if ((rType & VTK_PARSE_INDIRECT) == VTK_PARSE_REF) { fprintf(fp," temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name); } else { fprintf(fp," temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name); } break; } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { fprintf(fp,"vtkJavaVoidFunc,(void *)temp%i",i); break; } else { fprintf(fp,"temp%i",i); } } /* for */ fprintf(fp,");\n"); if (currentFunction->NumberOfArguments == 2 && currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION) { fprintf(fp," op->%sArgDelete(vtkJavaVoidFuncArgDelete);\n", jniFunction); } /* now copy and release any arrays */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { copy_and_release_args(fp, i); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } do_return(fp); fprintf(fp,"}\n"); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; if (jniFunctionNew) { free(jniFunctionNew); jniFunctionNew = 0; } } /* isDone() */ } /* isAbstract */ }
void outputFunction(FILE *fp, ClassInfo *data) { static unsigned int supported_types[] = { VTK_PARSE_VOID, VTK_PARSE_BOOL, VTK_PARSE_FLOAT, VTK_PARSE_DOUBLE, VTK_PARSE_CHAR, VTK_PARSE_UNSIGNED_CHAR, VTK_PARSE_SIGNED_CHAR, VTK_PARSE_INT, VTK_PARSE_UNSIGNED_INT, VTK_PARSE_SHORT, VTK_PARSE_UNSIGNED_SHORT, VTK_PARSE_LONG, VTK_PARSE_UNSIGNED_LONG, VTK_PARSE_ID_TYPE, VTK_PARSE_UNSIGNED_ID_TYPE, VTK_PARSE_LONG_LONG, VTK_PARSE_UNSIGNED_LONG_LONG, VTK_PARSE___INT64, VTK_PARSE_UNSIGNED___INT64, VTK_PARSE_OBJECT, VTK_PARSE_STRING, 0 }; unsigned int rType = (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE); unsigned int aType = 0; unsigned int baseType = 0; int i, j; int args_ok = 1; const char *jniFunction = 0; char *jniFunctionNew = 0; const char *begPtr = 0; const char *endPtr = 0; CurrentData = data; /* some functions will not get wrapped no matter what else */ if (currentFunction->IsOperator || currentFunction->ArrayFailure || !currentFunction->IsPublic || !currentFunction->Name) { return; } /* NewInstance and SafeDownCast can not be wrapped because it is a (non-virtual) method which returns a pointer of the same type as the current pointer. Since all methods are virtual in Java, this looks like polymorphic return type. */ if (!strcmp("NewInstance",currentFunction->Name)) { return ; } if (!strcmp("SafeDownCast",currentFunction->Name)) { return ; } /* The unwrappable methods in Filtering/vtkInformation.c */ if (strcmp(data->Name, "vtkInformation") == 0 && currentFunction->IsLegacy) { return; } /* The GetInput() in vtkMapper cannot be overriden with a * different return type, Java doesn't allow this */ if (strcmp(data->Name, "vtkMapper") == 0 && strcmp(currentFunction->Name, "GetInput") == 0) { return; } /* check to see if we can handle the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { aType = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE); baseType = (aType & VTK_PARSE_BASE_TYPE); if (currentFunction->ArgTypes[i] != VTK_PARSE_FUNCTION) { for (j = 0; supported_types[j] != 0; j++) { if (baseType == supported_types[j]) { break; } } if (supported_types[j] == 0) { args_ok = 0; } } if (baseType == VTK_PARSE_OBJECT) { if ((aType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) { args_ok = 0; } else if (hierarchyInfo) { if (vtkParseHierarchy_IsExtern(hierarchyInfo, currentFunction->ArgClasses[i]) || vtkParseHierarchy_GetProperty(hierarchyInfo, currentFunction->ArgClasses[i], "WRAP_EXCLUDE") || !vtkParseHierarchy_IsTypeOf(hierarchyInfo, currentFunction->ArgClasses[i], "vtkObjectBase")) { args_ok = 0; } } } if (((aType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) && ((aType & VTK_PARSE_INDIRECT) != 0) && (aType != VTK_PARSE_STRING_REF)) args_ok = 0; if (aType == VTK_PARSE_STRING_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_CHAR_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_INT_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_SHORT_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_LONG_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0; } baseType = (rType & VTK_PARSE_BASE_TYPE); for (j = 0; supported_types[j] != 0; j++) { if (baseType == supported_types[j]) { break; } } if (supported_types[j] == 0) { args_ok = 0; } if (baseType == VTK_PARSE_OBJECT) { if ((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) { args_ok = 0; } else if (hierarchyInfo) { if (vtkParseHierarchy_IsExtern(hierarchyInfo, currentFunction->ReturnClass) || vtkParseHierarchy_GetProperty(hierarchyInfo, currentFunction->ReturnClass, "WRAP_EXCLUDE") || !vtkParseHierarchy_IsTypeOf(hierarchyInfo, currentFunction->ReturnClass, "vtkObjectBase")) { args_ok = 0; } } } if (((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) && ((rType & VTK_PARSE_INDIRECT) != 0) && (rType != VTK_PARSE_STRING_REF)) args_ok = 0; if (rType == VTK_PARSE_STRING_PTR) args_ok = 0; /* eliminate unsigned short * usigned int * etc */ if (rType == VTK_PARSE_UNSIGNED_INT_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_SHORT_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_LONG_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0; if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION) &&(currentFunction->NumberOfArguments != 1)) args_ok = 0; /* make sure we have all the info we need for array arguments in */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { aType = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE); if (((aType & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER)&& (currentFunction->ArgCounts[i] <= 0)&& (aType != VTK_PARSE_OBJECT_PTR)&& (aType != VTK_PARSE_CHAR_PTR)) args_ok = 0; } /* if we need a return type hint make sure we have one */ switch (rType) { case VTK_PARSE_FLOAT_PTR: case VTK_PARSE_VOID_PTR: case VTK_PARSE_DOUBLE_PTR: case VTK_PARSE_INT_PTR: case VTK_PARSE_SHORT_PTR: case VTK_PARSE_LONG_PTR: case VTK_PARSE_ID_TYPE_PTR: case VTK_PARSE_LONG_LONG_PTR: case VTK_PARSE___INT64_PTR: case VTK_PARSE_SIGNED_CHAR_PTR: case VTK_PARSE_BOOL_PTR: case VTK_PARSE_UNSIGNED_CHAR_PTR: args_ok = currentFunction->HaveHint; break; } /* make sure there isn't a Java-specific override */ if (!strcmp("vtkObject",data->Name)) { /* remove the original vtkCommand observer methods */ if (!strcmp(currentFunction->Name,"AddObserver") || !strcmp(currentFunction->Name,"GetCommand") || (!strcmp(currentFunction->Name,"RemoveObserver") && (currentFunction->ArgTypes[0] != VTK_PARSE_UNSIGNED_LONG)) || ((!strcmp(currentFunction->Name,"RemoveObservers") || !strcmp(currentFunction->Name,"HasObserver")) && (((currentFunction->ArgTypes[0] != VTK_PARSE_UNSIGNED_LONG) && (currentFunction->ArgTypes[0] != (VTK_PARSE_CHAR_PTR|VTK_PARSE_CONST))) || (currentFunction->NumberOfArguments > 1))) || (!strcmp(currentFunction->Name,"RemoveAllObservers") && (currentFunction->NumberOfArguments > 0))) { args_ok = 0; } } else if (!strcmp("vtkObjectBase",data->Name)) { /* remove the special vtkObjectBase methods */ if (!strcmp(currentFunction->Name,"PrintRevisions") || !strcmp(currentFunction->Name,"Print")) { args_ok = 0; } } /* make sure it isn't a Delete or New function */ if (!strcmp("Delete",currentFunction->Name) || !strcmp("New",currentFunction->Name)) { args_ok = 0; } /* handle DataReader SetBinaryInputString as a special case */ if (!strcmp("SetBinaryInputString",currentFunction->Name) && (!strcmp("vtkDataReader",data->Name) || !strcmp("vtkStructuredGridReader",data->Name) || !strcmp("vtkRectilinearGridReader",data->Name) || !strcmp("vtkUnstructuredGridReader",data->Name) || !strcmp("vtkStructuredPointsReader",data->Name) || !strcmp("vtkPolyDataReader",data->Name))) { if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } HandleDataReader(fp,data); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } if (currentFunction->IsPublic && args_ok && strcmp(data->Name,currentFunction->Name) && strcmp(data->Name, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n"); /* Underscores are escaped in method names, see http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp133 VTK class names contain no underscore and do not need to be escaped. */ jniFunction = currentFunction->Name; begPtr = currentFunction->Name; endPtr = strchr(begPtr, '_'); if(endPtr) { jniFunctionNew = (char *)malloc(2*strlen(currentFunction->Name) + 1); jniFunctionNew[0] = '\0'; while (endPtr) { strncat(jniFunctionNew, begPtr, endPtr - begPtr + 1); strcat(jniFunctionNew, "1"); begPtr = endPtr + 1; endPtr = strchr(begPtr, '_'); } strcat(jniFunctionNew, begPtr); jniFunction = jniFunctionNew; } if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp,"extern \"C\" JNIEXPORT "); return_result(fp); fprintf(fp," JNICALL Java_vtk_%s_%s_1%i(JNIEnv *env, jobject obj", data->Name, jniFunction, numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { fprintf(fp,","); output_proto_vars(fp, i); } fprintf(fp,")\n{\n"); /* get the object pointer */ fprintf(fp," %s *op;\n",data->Name); /* process the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { output_temp(fp, i, currentFunction->ArgTypes[i], currentFunction->ArgClasses[i], currentFunction->ArgCounts[i]); } output_temp(fp, MAX_ARGS,currentFunction->ReturnType, currentFunction->ReturnClass,0); /* now get the required args from the stack */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { get_args(fp, i); } fprintf(fp,"\n op = (%s *)vtkJavaGetPointerFromObject(env,obj);\n", data->Name); switch (rType) { case VTK_PARSE_VOID: fprintf(fp," op->%s(",currentFunction->Name); break; default: if ((rType & VTK_PARSE_INDIRECT) == VTK_PARSE_REF) { fprintf(fp," temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name); } else { fprintf(fp," temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name); } break; } for (i = 0; i < currentFunction->NumberOfArguments; i++) { aType = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE); if (i) { fprintf(fp,","); } if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { fprintf(fp,"vtkJavaVoidFunc,(void *)temp%i",i); } else { fprintf(fp,"temp%i",i); } } /* for */ fprintf(fp,");\n"); if (currentFunction->NumberOfArguments == 1 && currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION) { fprintf(fp," op->%sArgDelete(vtkJavaVoidFuncArgDelete);\n", jniFunction); } /* now copy and release any arrays */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { copy_and_release_args(fp, i); } do_return(fp); fprintf(fp,"}\n"); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; if (jniFunctionNew) { free(jniFunctionNew); jniFunctionNew = 0; } } /* isDone() */ } /* isAbstract */ }
void outputFunction(FILE *fp, ClassInfo *data) { int i; int required_args = 0; /* if the args are OK and it is not a constructor or destructor */ if (checkFunctionSignature(data) && strcmp(data->Name,currentFunction->Name) && strcmp(data->Name,currentFunction->Name + 1)) { /* calc the total required args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { required_args = required_args + (currentFunction->ArgCounts[i] ? currentFunction->ArgCounts[i] : 1); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp," if ((!strcmp(\"%s\",argv[1]))&&(argc == %i))\n {\n", currentFunction->Name, required_args + 2); /* process the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { output_temp(fp, i, currentFunction->ArgTypes[i], currentFunction->ArgClasses[i], currentFunction->ArgCounts[i]); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } output_temp(fp, MAX_ARGS,currentFunction->ReturnType, currentFunction->ReturnClass, 0); /* only use the error variable if we have arguments to parse */ if (currentFunction->NumberOfArguments) { fprintf(fp," error = 0;\n\n"); /* now get the required args from the stack */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { get_args(fp,i); } fprintf(fp," if (!error)\n {\n"); } switch (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE) { case VTK_PARSE_VOID: fprintf(fp," op->%s(",currentFunction->Name); break; default: if ((currentFunction->ReturnType & VTK_PARSE_INDIRECT) == VTK_PARSE_REF) { fprintf(fp," temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name); } else { fprintf(fp," temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name); } break; } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { fprintf(fp,"vtkTclVoidFunc,static_cast<void *>(temp%i)",i); break; } else { fprintf(fp,"temp%i",i); } } fprintf(fp,");\n"); if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION)) { fprintf(fp," op->%sArgDelete(vtkTclVoidFuncArgDelete);\n", currentFunction->Name); } return_result(fp); fprintf(fp," return TCL_OK;\n"); /* close the if error */ if (currentFunction->NumberOfArguments) { fprintf(fp," }\n"); } fprintf(fp," }\n"); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } }
void outputFunction(FILE *fp, FileInfo *data) { int i; int args_ok = 1; char *jniFunction = 0; char *begPtr = 0; char *endPtr = 0; CurrentData = data; /* some functions will not get wrapped no matter what else */ if (currentFunction->IsOperator || currentFunction->ArrayFailure || !currentFunction->IsPublic || !currentFunction->Name) { return; } /* NewInstance and SafeDownCast can not be wrapped because it is a (non-virtual) method which returns a pointer of the same type as the current pointer. Since all methods are virtual in Java, this looks like polymorphic return type. */ if (!strcmp("NewInstance",currentFunction->Name)) { return ; } if (!strcmp("SafeDownCast",currentFunction->Name)) { return ; } /* check to see if we can handle the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (currentFunction->ArgTypes[i] % 0x1000 == 0x9) args_ok = 0; if ((currentFunction->ArgTypes[i] % 0x10) == 0x8) args_ok = 0; if (((currentFunction->ArgTypes[i] % 0x1000)/0x100 != 0x3)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x109)&& ((currentFunction->ArgTypes[i] % 0x1000)/0x100)) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x313) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x314) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x315) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x316) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31A) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31B) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31C) args_ok = 0; } if ((currentFunction->ReturnType % 0x10) == 0x8) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x9) args_ok = 0; if (((currentFunction->ReturnType % 0x1000)/0x100 != 0x3)&& (currentFunction->ReturnType % 0x1000 != 0x109)&& ((currentFunction->ReturnType % 0x1000)/0x100)) args_ok = 0; /* eliminate unsigned short * usigned int * etc */ if (currentFunction->ReturnType % 0x1000 == 0x314) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x315) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x316) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31A) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31B) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31C) args_ok = 0; if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == 0x5000) &&(currentFunction->NumberOfArguments != 1)) args_ok = 0; /* make sure we have all the info we need for array arguments in */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (((currentFunction->ArgTypes[i] % 0x1000)/0x100 == 0x3)&& (currentFunction->ArgCounts[i] <= 0)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x309)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x303)) args_ok = 0; } /* if we need a return type hint make sure we have one */ switch (currentFunction->ReturnType % 0x1000) { case 0x301: case 0x302: case 0x307: case 0x304: case 0x305: case 0x306: case 0x30A: case 0x30B: case 0x30C: case 0x30D: case 0x30E: case 0x313: args_ok = currentFunction->HaveHint; break; } /* make sure it isn't a Delete or New function */ if (!strcmp("Delete",currentFunction->Name) || !strcmp("New",currentFunction->Name)) { args_ok = 0; } /* handle DataReader SetBinaryInputString as a special case */ if (!strcmp("SetBinaryInputString",currentFunction->Name) && (!strcmp("vtkDataReader",data->ClassName) || !strcmp("vtkStructuredGridReader",data->ClassName) || !strcmp("vtkRectilinearGridReader",data->ClassName) || !strcmp("vtkUnstructuredGridReader",data->ClassName) || !strcmp("vtkStructuredPointsReader",data->ClassName) || !strcmp("vtkPolyDataReader",data->ClassName))) { if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } HandleDataReader(fp,data); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } if (currentFunction->IsPublic && args_ok && strcmp(data->ClassName,currentFunction->Name) && strcmp(data->ClassName, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n"); /* Underscores are escaped in method names, see http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp133 VTK class names contain no underscore and do not need to be escaped. */ jniFunction = currentFunction->Name; begPtr = currentFunction->Name; endPtr = strchr(begPtr, '_'); if(endPtr) { jniFunction = (char *)malloc(2*strlen(currentFunction->Name) + 1); jniFunction[0] = '\0'; while (endPtr) { strncat(jniFunction, begPtr, endPtr - begPtr + 1); strcat(jniFunction, "1"); begPtr = endPtr + 1; endPtr = strchr(begPtr, '_'); } strcat(jniFunction, begPtr); } if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp,"extern \"C\" JNIEXPORT "); return_result(fp); fprintf(fp," JNICALL Java_vtk_%s_%s_1%i(JNIEnv *env, jobject obj", data->ClassName, jniFunction, numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { fprintf(fp,","); output_proto_vars(fp, i); } fprintf(fp,")\n{\n"); /* get the object pointer */ fprintf(fp," %s *op;\n",data->ClassName); /* process the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { output_temp(fp, i, currentFunction->ArgTypes[i], currentFunction->ArgClasses[i], currentFunction->ArgCounts[i]); } output_temp(fp, MAX_ARGS,currentFunction->ReturnType, currentFunction->ReturnClass,0); /* now get the required args from the stack */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { get_args(fp, i); } fprintf(fp,"\n op = (%s *)vtkJavaGetPointerFromObject(env,obj);\n", data->ClassName); switch (currentFunction->ReturnType % 0x1000) { case 0x2: fprintf(fp," op->%s(",currentFunction->Name); break; case 0x109: fprintf(fp," temp%i = &(op)->%s(",MAX_ARGS, currentFunction->Name); break; default: fprintf(fp," temp%i = (op)->%s(",MAX_ARGS, currentFunction->Name); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } if (currentFunction->ArgTypes[i] % 0x1000 == 0x109) { fprintf(fp,"*(temp%i)",i); } else if (currentFunction->ArgTypes[i] == 0x5000) { fprintf(fp,"vtkJavaVoidFunc,(void *)temp%i",i); } else { fprintf(fp,"temp%i",i); } } /* for */ fprintf(fp,");\n"); if (currentFunction->NumberOfArguments == 1 && currentFunction->ArgTypes[0] == 0x5000) { fprintf(fp," op->%sArgDelete(vtkJavaVoidFuncArgDelete);\n", jniFunction); } /* now copy and release any arrays */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { copy_and_release_args(fp, i); } do_return(fp); fprintf(fp,"}\n"); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; if (jniFunction != currentFunction->Name) { free(jniFunction); } } /* isDone() */ } /* isAbstract */ }
void outputFunction2(FILE *fp, FileInfo *data) { int i, j, k, is_static, is_vtkobject, fnum, occ, backnum, goto_used; int all_legacy; FunctionInfo *theFunc; FunctionInfo *backFunc; is_vtkobject = ((strcmp(data->ClassName,"vtkObjectBase") == 0) || (data->NumberOfSuperClasses != 0)); /* create a python-type signature for each method (for use in docstring) */ for (fnum = 0; fnum < numberOfWrappedFunctions; fnum++) { theFunc = wrappedFunctions[fnum]; currentFunction = theFunc; get_python_signature(); } /* create external type declarations for all object return types */ for (fnum = 0; fnum < numberOfWrappedFunctions; fnum++) { theFunc = wrappedFunctions[fnum]; currentFunction = theFunc; /* check for object return types */ if ((theFunc->ReturnType % 0x1000 == 0x309)|| (theFunc->ReturnType % 0x1000 == 0x109)) { /* check that we haven't done this type (no duplicate declarations) */ for (backnum = fnum-1; backnum >= 0; backnum--) { backFunc = wrappedFunctions[backnum]; if (((backFunc->ReturnType % 0x1000 == 0x309)|| (backFunc->ReturnType % 0x1000 == 0x109)) && (strcmp(theFunc->ReturnClass,backFunc->ReturnClass) == 0)) { break; } } } } /* for each function in the array */ for (fnum = 0; fnum < numberOfWrappedFunctions; fnum++) { /* make sure we haven't already done one of these */ theFunc = wrappedFunctions[fnum]; currentFunction = theFunc; if (theFunc->Name) { fprintf(fp,"\n"); /* check whether all signatures are static methods or legacy */ is_static = 1; all_legacy = 1; for (occ = fnum; occ < numberOfWrappedFunctions; occ++) { /* is it the same name */ if (wrappedFunctions[occ]->Name && !strcmp(theFunc->Name,wrappedFunctions[occ]->Name)) { /* check for static methods */ if (((wrappedFunctions[occ]->ReturnType/0x1000) & 0x2) != 0x2) { is_static = 0; } /* check for legacy */ if (!wrappedFunctions[occ]->IsLegacy) { all_legacy = 0; } } } if(all_legacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp,"static PyObject *Py%s_%s(PyObject *%s, PyObject *args)\n", data->ClassName,currentFunction->Name, (is_static ? "" : "self")); fprintf(fp,"{\n"); /* find all occurances of this method */ for (occ = fnum; occ < numberOfWrappedFunctions; occ++) { goto_used = 0; is_static = 0; /* is it the same name */ if (wrappedFunctions[occ]->Name && !strcmp(theFunc->Name,wrappedFunctions[occ]->Name)) { /* check for static methods */ if (((wrappedFunctions[occ]->ReturnType/0x1000) & 0x2) == 0x2) { is_static = 1; } currentFunction = wrappedFunctions[occ]; if(currentFunction->IsLegacy && !all_legacy) { fprintf(fp,"#if defined(VTK_LEGACY_REMOVE)\n"); /* avoid warnings if all signatures are legacy and removed */ if(!is_static) { fprintf(fp, " (void)self;" " /* avoid warning if all signatures removed */\n"); } fprintf(fp, " (void)args;" " /* avoid warning if all signatures removed */\n"); fprintf(fp,"#else\n"); } fprintf(fp," /* handle an occurrence */\n {\n"); /* declare the variables */ if (!is_static) { if (is_vtkobject) { fprintf(fp," %s *op;\n\n",data->ClassName); } else { fprintf(fp," %s *op = (%s *)((PyVTKSpecialObject *)self)->vtk_ptr;\n\n",data->ClassName,data->ClassName); } } /* process the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { output_temp(fp, i, currentFunction->ArgTypes[i], currentFunction->ArgClasses[i], currentFunction->ArgCounts[i]); } output_temp(fp, MAX_ARGS,currentFunction->ReturnType, currentFunction->ReturnClass,0); /* don't clear error first time around */ if (occ != fnum) { fprintf(fp," PyErr_Clear();\n"); } if (is_static || !is_vtkobject) { fprintf(fp," if ((PyArg_ParseTuple(args, (char*)\"%s\"", get_format_string()); } else { fprintf(fp," op = (%s *)PyArg_VTKParseTuple(self, args, (char*)\"%s\"", data->ClassName,get_format_string()); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if ((currentFunction->ArgTypes[i] % 0x1000 == 0x309)|| (currentFunction->ArgTypes[i] % 0x1000 == 0x109)) { fprintf(fp,", &tempH%d",i); } else if (currentFunction->ArgTypes[i] % 0x1000 == 0x302) { fprintf(fp,", &temp%d, &size%d",i,i); } else { if (currentFunction->ArgCounts[i]) { for (j = 0; j < currentFunction->ArgCounts[i]; j++) { fprintf(fp,", temp%d + %d",i,j); } } else { fprintf(fp,", &temp%d",i); } } } if (is_static || !is_vtkobject) { fprintf(fp,")))\n {\n"); } else { fprintf(fp,");\n"); fprintf(fp," if (op)\n {\n"); } /* lookup and required objects */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if ((currentFunction->ArgTypes[i] % 0x1000 == 0x309)|| (currentFunction->ArgTypes[i] % 0x1000 == 0x109)) { fprintf(fp," temp%d = (%s *)vtkPythonGetPointerFromObject(tempH%d,(char*)\"%s\");\n", i, currentFunction->ArgClasses[i], i, currentFunction->ArgClasses[i]); fprintf(fp," if (!temp%d && tempH%d != Py_None) goto break%d;\n",i,i,occ); goto_used = 1; } } /* make sure passed method is callable for VAR functions */ if (currentFunction->NumberOfArguments == 0x1 && currentFunction->ArgTypes[0] == 0x5000) { fprintf(fp," if (!PyCallable_Check(temp0) && temp0 != Py_None)\n"); fprintf(fp," {\n PyErr_SetString(PyExc_ValueError,\"vtk callback method passed to %s in %s was not callable.\");\n", currentFunction->Name,data->ClassName); fprintf(fp," return NULL;\n }\n"); fprintf(fp," Py_INCREF(temp0);\n"); } /* check for void pointers and pass appropriate info*/ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (currentFunction->ArgTypes[i] % 0x1000 == 0x302) { fprintf(fp," temp%i = vtkPythonUnmanglePointer((char *)temp%i,&size%i,(char*)\"%s\");\n",i,i,i,"void_p"); fprintf(fp," if (size%i == -1) {\n PyErr_SetString(PyExc_ValueError,\"mangled pointer to %s in %s was of incorrect type.\");\n", i,currentFunction->Name,data->ClassName); fprintf(fp," return NULL;\n }\n"); fprintf(fp," else if (size%i == -2) {\n PyErr_SetString(PyExc_ValueError,\"mangled pointer to %s in %s was poorly formed.\");\n", i,currentFunction->Name,data->ClassName); fprintf(fp," return NULL;\n }\n"); } } for (k = 0; k < (2 - (is_static || !is_vtkobject)); k++) { char methodname[256]; if (k == 0) { if (is_static) { fprintf(fp," {\n"); sprintf(methodname,"%s::%s", data->ClassName,currentFunction->Name); } else if (!is_vtkobject) { fprintf(fp," {\n"); sprintf(methodname,"op->%s",currentFunction->Name); } else { if (currentFunction->IsPureVirtual) { fprintf(fp," if (PyVTKClass_Check(self))\n {\n"); fprintf(fp," PyErr_SetString(PyExc_TypeError,\"pure virtual method call\");\n"); fprintf(fp," return NULL;\n }\n"); continue; } else { fprintf(fp," if (PyVTKClass_Check(self))\n {\n"); sprintf(methodname,"op->%s::%s", data->ClassName,currentFunction->Name); } } } else { fprintf(fp," else\n {\n"); sprintf(methodname,"op->%s",currentFunction->Name); } switch (currentFunction->ReturnType % 0x1000) { case 0x2: fprintf(fp," %s(",methodname); break; case 0x109: fprintf(fp," temp%i = &%s(",MAX_ARGS,methodname); break; default: fprintf(fp," temp%i = %s(",MAX_ARGS,methodname); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } if (currentFunction->ArgTypes[i] % 0x1000 == 0x109) { fprintf(fp,"*(temp%i)",i); } else if (currentFunction->NumberOfArguments == 1 && currentFunction->ArgTypes[i] == 0x5000) { fprintf(fp,"((temp0 != Py_None) ? vtkPythonVoidFunc : NULL),(void *)temp%i",i); } else { fprintf(fp,"temp%i",i); } } fprintf(fp,");\n"); if (currentFunction->NumberOfArguments == 1 && currentFunction->ArgTypes[0] == 0x5000) { fprintf(fp," %sArgDelete(vtkPythonVoidFuncArgDelete);\n", methodname); } fprintf(fp," }\n"); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (currentFunction->ArgCounts[i] && /* array */ currentFunction->ArgTypes[i] % 0x10 != 0 && /* not a special type */ currentFunction->ArgTypes[i] % 0x10 != 0x9 && /* not class pointer */ currentFunction->ArgTypes[i] % 0x10 != 0x8 && currentFunction->ArgTypes[i] % 0x10 != 0x2 && /* not void pointer */ (currentFunction->ArgTypes[i] % 0x2000 < 0x1000)) /* not const */ { fprintf(fp," if (vtkPythonCheckArray(args,%d,temp%d,%d)) {\n" " return 0;\n" " }\n", i, i, currentFunction->ArgCounts[i]); } } do_return(fp); fprintf(fp," }\n }\n"); if (goto_used) { fprintf(fp," break%d:\n",occ); } if(currentFunction->IsLegacy && !all_legacy) { fprintf(fp,"#endif\n"); } } } fprintf(fp," return NULL;\n}\n"); if(all_legacy) { fprintf(fp,"#endif\n"); } fprintf(fp,"\n"); /* clear all occurances of this method from further consideration */ for (occ = fnum + 1; occ < numberOfWrappedFunctions; occ++) { /* is it the same name */ if (wrappedFunctions[occ]->Name && !strcmp(theFunc->Name,wrappedFunctions[occ]->Name)) { size_t siglen = strlen(wrappedFunctions[fnum]->Signature); /* memory leak here but ... */ wrappedFunctions[occ]->Name = NULL; wrappedFunctions[fnum]->Signature = (char *) realloc(wrappedFunctions[fnum]->Signature,siglen+3+ strlen(wrappedFunctions[occ]->Signature)); strcpy(&wrappedFunctions[fnum]->Signature[siglen],"\\n"); strcpy(&wrappedFunctions[fnum]->Signature[siglen+2], wrappedFunctions[occ]->Signature); } } } /* is this method non NULL */ } /* loop over all methods */ /* output the method table */ /* for each function in the array */ fprintf(fp,"static PyMethodDef Py%sMethods[] = {\n",data->ClassName); for (fnum = 0; fnum < numberOfWrappedFunctions; fnum++) { if(wrappedFunctions[fnum]->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } if (wrappedFunctions[fnum]->Name) { fprintf(fp," {(char*)\"%s\", (PyCFunction)Py%s_%s, 1,\n (char*)\"%s\\n\\n%s\"},\n", wrappedFunctions[fnum]->Name, data->ClassName, wrappedFunctions[fnum]->Name, wrappedFunctions[fnum]->Signature, quote_string(wrappedFunctions[fnum]->Comment,1000)); } if(wrappedFunctions[fnum]->IsLegacy) { fprintf(fp,"#endif\n"); } } if (!strcmp("vtkObject",data->ClassName)) { fprintf(fp," {(char*)\"AddObserver\", (PyCFunction)Py%s_AddObserver, 1,\n (char*)\"V.AddObserver(int, function) -> int\\n\\n Add an event callback function(vtkObject, int) for an event type.\\n Returns a handle that can be used with RemoveEvent(int).\"},\n", data->ClassName); } else if (!strcmp("vtkObjectBase",data->ClassName)) { fprintf(fp," {(char*)\"GetAddressAsString\", (PyCFunction)Py%s_GetAddressAsString, 1,\n (char*)\"V.GetAddressAsString(string) -> string\\n\\n Get address of C++ object in format 'Addr=%%p' after casting to\\n the specified type. You can get the same information from V.__this__.\"},\n", data->ClassName); fprintf(fp," {(char*)\"PrintRevisions\", (PyCFunction)Py%s_PrintRevisions, 1,\n (char*)\"V.PrintRevisions() -> string\\n\\n Prints the .cxx file CVS revisions of the classes in the\\n object's inheritance chain.\"},\n", data->ClassName); } fprintf(fp," {NULL, NULL, 0, NULL}\n};\n\n"); }
void outputFunction(FILE *fp, FileInfo *data) { int i; int args_ok = 1; /* some functions will not get wrapped no matter what else */ if (currentFunction->IsOperator || currentFunction->ArrayFailure || !currentFunction->IsPublic || !currentFunction->Name) { return; } /* check to see if we can handle the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if ((currentFunction->ArgTypes[i] & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNKNOWN) args_ok = 0; /* if its a pointer arg make sure we have the ArgCount */ if (((currentFunction->ArgTypes[i] & VTK_PARSE_INDIRECT) != 0) && ((currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE) != VTK_PARSE_CHAR_PTR) && ((currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE) != VTK_PARSE_VTK_OBJECT_PTR) && ((currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE) != VTK_PARSE_VTK_OBJECT_REF)) { if (currentFunction->NumberOfArguments > 1 || !currentFunction->ArgCounts[i]) { args_ok = 0; } } if (((currentFunction->ArgTypes[i] & VTK_PARSE_UNSIGNED) != 0) && (currentFunction->ArgTypes[i] != VTK_PARSE_UNSIGNED_CHAR) && (currentFunction->ArgTypes[i] != VTK_PARSE_UNSIGNED_INT) && (currentFunction->ArgTypes[i] != VTK_PARSE_UNSIGNED_SHORT) && (currentFunction->ArgTypes[i] != VTK_PARSE_UNSIGNED_LONG) && (currentFunction->ArgTypes[i] != VTK_PARSE_UNSIGNED_ID_TYPE) && (currentFunction->ArgTypes[i] != VTK_PARSE_UNSIGNED_LONG_LONG)) { args_ok = 0; } } if ((currentFunction->ReturnType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNKNOWN) { args_ok = 0; } if (((currentFunction->ReturnType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) && ((currentFunction->ReturnType & VTK_PARSE_INDIRECT) != VTK_PARSE_REF) && ((currentFunction->ReturnType & VTK_PARSE_INDIRECT) != 0)) { args_ok = 0; } if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION) &&(currentFunction->NumberOfArguments != 1)) { args_ok = 0; } /* we can't handle void * return types */ if ((currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE) == VTK_PARSE_VOID_PTR) { args_ok = 0; } /* watch out for functions that dont have enough info */ switch (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE) { case VTK_PARSE_FLOAT_PTR: case VTK_PARSE_DOUBLE_PTR: case VTK_PARSE_INT_PTR: case VTK_PARSE_SHORT_PTR: case VTK_PARSE_LONG_PTR: case VTK_PARSE_ID_TYPE_PTR: case VTK_PARSE_LONG_LONG_PTR: case VTK_PARSE___INT64_PTR: case VTK_PARSE_SIGNED_CHAR_PTR: case VTK_PARSE_BOOL_PTR: case VTK_PARSE_UNSIGNED_CHAR_PTR: case VTK_PARSE_UNSIGNED_INT_PTR: case VTK_PARSE_UNSIGNED_SHORT_PTR: case VTK_PARSE_UNSIGNED_LONG_PTR: case VTK_PARSE_UNSIGNED_ID_TYPE_PTR: case VTK_PARSE_UNSIGNED_LONG_LONG_PTR: case VTK_PARSE_UNSIGNED___INT64_PTR: args_ok = currentFunction->HaveHint; break; } /* if the args are OK and it is not a constructor or destructor */ if (args_ok && strcmp(data->ClassName,currentFunction->Name) && strcmp(data->ClassName,currentFunction->Name + 1)) { int required_args = 0; /* calc the total required args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { required_args = required_args + (currentFunction->ArgCounts[i] ? currentFunction->ArgCounts[i] : 1); } if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp," if ((!strcmp(\"%s\",argv[1]))&&(argc == %i))\n {\n", currentFunction->Name, required_args + 2); /* process the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { output_temp(fp, i, currentFunction->ArgTypes[i], currentFunction->ArgClasses[i], currentFunction->ArgCounts[i]); } output_temp(fp, MAX_ARGS,currentFunction->ReturnType, currentFunction->ReturnClass, 0); /* only use the error variable if we have arguments to parse */ if (currentFunction->NumberOfArguments) { fprintf(fp," error = 0;\n\n"); /* now get the required args from the stack */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { get_args(fp,i); } fprintf(fp," if (!error)\n {\n"); } switch (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE) { case VTK_PARSE_VOID: fprintf(fp," op->%s(",currentFunction->Name); break; case VTK_PARSE_VTK_OBJECT_REF: fprintf(fp," temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name); break; default: fprintf(fp," temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } if (currentFunction->ArgTypes[i] == VTK_PARSE_VTK_OBJECT_REF) { fprintf(fp,"*(temp%i)",i); } else if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { fprintf(fp,"vtkTclVoidFunc,static_cast<void *>(temp%i)",i); } else { fprintf(fp,"temp%i",i); } } fprintf(fp,");\n"); if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION)) { fprintf(fp," op->%sArgDelete(vtkTclVoidFuncArgDelete);\n", currentFunction->Name); } return_result(fp); fprintf(fp," return TCL_OK;\n"); /* close the if error */ if (currentFunction->NumberOfArguments) { fprintf(fp," }\n"); } fprintf(fp," }\n"); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } }
void outputFunction(FILE *fp, FileInfo *data) { int i; int args_ok = 1; /* some functions will not get wrapped no matter what else */ if (currentFunction->IsOperator || currentFunction->ArrayFailure || !currentFunction->IsPublic || !currentFunction->Name) { return; } /* NewInstance and SafeDownCast can not be wrapped because it is a (non-virtual) method which returns a pointer of the same type as the current pointer. Since all methods are virtual in Java, this looks like polymorphic return type. */ if (!strcmp("NewInstance",currentFunction->Name)) { return ; } if (!strcmp("SafeDownCast",currentFunction->Name)) { return ; } /* check to see if we can handle the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (currentFunction->ArgTypes[i] % 0x1000 == 0x9) args_ok = 0; if ((currentFunction->ArgTypes[i] % 0x10) == 0x8) args_ok = 0; if (((currentFunction->ArgTypes[i] % 0x1000)/0x100 != 0x3)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x109)&& ((currentFunction->ArgTypes[i] % 0x1000)/0x100)) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x313) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x314) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x315) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x316) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31A) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31B) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31C) args_ok = 0; } if ((currentFunction->ReturnType % 0x10) == 0x8) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x9) args_ok = 0; if (((currentFunction->ReturnType % 0x1000)/0x100 != 0x3)&& (currentFunction->ReturnType % 0x1000 != 0x109)&& ((currentFunction->ReturnType % 0x1000)/0x100)) args_ok = 0; /* eliminate unsigned char * and unsigned short * */ if (currentFunction->ReturnType % 0x1000 == 0x314) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x315) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x316) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31A) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31B) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31C) args_ok = 0; if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == 0x5000) &&(currentFunction->NumberOfArguments != 1)) args_ok = 0; /* make sure we have all the info we need for array arguments in */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (((currentFunction->ArgTypes[i] % 0x1000)/0x100 == 0x3)&& (currentFunction->ArgCounts[i] <= 0)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x309)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x303)) args_ok = 0; } /* if we need a return type hint make sure we have one */ switch (currentFunction->ReturnType % 0x1000) { case 0x301: case 0x302: case 0x307: case 0x304: case 0x305: case 0x306: case 0x30A: case 0x30B: case 0x30C: case 0x30D: case 0x30E: case 0x313: args_ok = currentFunction->HaveHint; break; } /* make sure it isn't a Delete or New function */ if (!strcmp("Delete",currentFunction->Name) || !strcmp("New",currentFunction->Name)) { args_ok = 0; } /* handle DataReader SetBinaryInputString as a special case */ if (!strcmp("SetBinaryInputString",currentFunction->Name) && (!strcmp("vtkDataReader",data->ClassName) || !strcmp("vtkStructuredGridReader",data->ClassName) || !strcmp("vtkRectilinearGridReader",data->ClassName) || !strcmp("vtkUnstructuredGridReader",data->ClassName) || !strcmp("vtkStructuredPointsReader",data->ClassName) || !strcmp("vtkPolyDataReader",data->ClassName))) { HandleDataReader(fp,data); wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } if (currentFunction->IsPublic && args_ok && strcmp(data->ClassName,currentFunction->Name) && strcmp(data->ClassName, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n private native "); return_result_native(fp); fprintf(fp,"%s_%i(",currentFunction->Name,numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); } fprintf(fp,");\n"); fprintf(fp," public "); return_result(fp); fprintf(fp,"%s(",currentFunction->Name); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); } /* if returning object, lookup in global hash */ if (currentFunction->ReturnType % 0x1000 == 0x109 || currentFunction->ReturnType % 0x1000 == 0x309) { fprintf(fp,") {"); fprintf(fp,"\n long temp = %s_%i(",currentFunction->Name, numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } fprintf(fp,");\n"); fprintf(fp,"\n if (temp == 0) return null;"); fprintf(fp,"\n %s obj = null;", currentFunction->ReturnClass); fprintf(fp,"\n java.lang.ref.WeakReference ref = (java.lang.ref.WeakReference)vtkGlobalJavaHash.PointerToReference.get(new Long(temp));"); fprintf(fp,"\n if (ref != null) {"); fprintf(fp,"\n obj = (%s)ref.get();", currentFunction->ReturnClass); fprintf(fp,"\n }"); fprintf(fp,"\n if (obj == null) {"); fprintf(fp,"\n %s tempObj = new %s(temp);", currentFunction->ReturnClass, currentFunction->ReturnClass); fprintf(fp,"\n String className = tempObj.GetClassName();"); fprintf(fp,"\n try {"); fprintf(fp,"\n Class c = Class.forName(\"vtk.\" + className);"); fprintf(fp,"\n java.lang.reflect.Constructor cons = c.getConstructor(new Class[] {long.class} );"); fprintf(fp,"\n obj = (%s)cons.newInstance(new Object[] {new Long(temp)});", currentFunction->ReturnClass); fprintf(fp,"\n } catch (Exception e) {"); fprintf(fp,"\n e.printStackTrace();"); fprintf(fp,"\n }"); fprintf(fp,"\n tempObj.Delete();"); fprintf(fp,"\n }"); fprintf(fp,"\n return obj;"); fprintf(fp,"\n }\n"); } else { /* if not void then need return otherwise none */ if (currentFunction->ReturnType % 0x1000 == 0x2) { fprintf(fp,")\n { %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } else { fprintf(fp,")\n { return %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } if ((currentFunction->NumberOfArguments == 1) && (currentFunction->ArgTypes[0] == 0x5000)) fprintf(fp,",id1"); fprintf(fp,"); }\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } } }
void outputFunction(FILE *fp, FileInfo *data) { int i; int args_ok = 1; /* some functions will not get wrapped no matter what else */ if (currentFunction->IsOperator || currentFunction->ArrayFailure || !currentFunction->IsPublic || !currentFunction->Name) { return; } /* check to see if we can handle the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { int isPointerToData = arg_is_pointer_to_data(currentFunction->ArgTypes[i], currentFunction->ArgCounts[i]); if ((currentFunction->ArgTypes[i] % 0x10) == 0x8) args_ok = 0; /* if its a pointer arg make sure we have the ArgCount */ if ((currentFunction->ArgTypes[i] % 0x1000 >= 0x100) && !isPointerToData && (currentFunction->ArgTypes[i] % 0x1000 != 0x303)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x309)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x109)) { if (currentFunction->NumberOfArguments > 1 || !currentFunction->ArgCounts[i]) { args_ok = 0; } } if ((currentFunction->ArgTypes[i] % 0x100 >= 0x10)&& (currentFunction->ArgTypes[i] != 0x13)&& (currentFunction->ArgTypes[i] != 0x14)&& (currentFunction->ArgTypes[i] != 0x15)&& (currentFunction->ArgTypes[i] != 0x16)&& (currentFunction->ArgTypes[i] != 0x1A)&& !isPointerToData) { args_ok = 0; } } /* if it returns an unknown class we cannot wrap it */ if ((currentFunction->ReturnType % 0x10) == 0x8) { args_ok = 0; } if (((currentFunction->ReturnType % 0x1000)/0x100 != 0x3)&& ((currentFunction->ReturnType % 0x1000)/0x100 != 0x1)&& ((currentFunction->ReturnType % 0x1000)/0x100)) { args_ok = 0; } if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == 0x5000)) { args_ok = 0; } /* we can't handle void * return types */ if ((currentFunction->ReturnType % 0x1000) == 0x302) { args_ok = 0; } /* watch out for functions that dont have enough info */ switch (currentFunction->ReturnType % 0x1000) { case 0x301: case 0x307: case 0x304: case 0x305: case 0x306: case 0x30A: case 0x30B: case 0x30C: case 0x30D: case 0x313: case 0x314: case 0x315: case 0x316: case 0x31A: case 0x31B: case 0x31C: args_ok = currentFunction->HaveHint; break; } /* if the args are OK and it is not a constructor or destructor */ if (args_ok && strcmp(data->ClassName,currentFunction->Name) && strcmp(data->ClassName,currentFunction->Name + 1)) { if(currentFunction->IsLegacy) { fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp," if (!strcmp(\"%s\",method) && msg.GetNumberOfArguments(0) == %i)\n", currentFunction->Name, currentFunction->NumberOfArguments+2); fprintf(fp, " {\n"); /* process the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { output_temp(fp, i, currentFunction->ArgTypes[i], currentFunction->ArgClasses[i], currentFunction->ArgCounts[i]); } output_temp(fp, MAX_ARGS,currentFunction->ReturnType, currentFunction->ReturnClass, 0); if(currentFunction->NumberOfArguments > 0) { const char* amps = " if("; /* now get the required args from the stack */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { fprintf(fp, "%s", amps); amps = " &&\n "; get_args(fp,i); } fprintf(fp, ")\n"); } fprintf(fp, " {\n"); switch (currentFunction->ReturnType % 0x1000) { case 0x2: fprintf(fp," op->%s(",currentFunction->Name); break; case 0x109: fprintf(fp," temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name); break; default: fprintf(fp," temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } if ((currentFunction->ArgTypes[i] % 0x1000) == 0x109) { fprintf(fp,"*(temp%i)",i); } else { fprintf(fp,"temp%i",i); } } fprintf(fp,");\n"); return_result(fp); fprintf(fp," return 1;\n"); fprintf(fp," }\n"); fprintf(fp," }\n"); if(currentFunction->IsLegacy) { fprintf(fp,"#endif\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } #if 0 if (!strcmp("vtkObject",data->ClassName)) { fprintf(fp," if (!strcmp(\"AddProgressObserver\",method) && msg.NumberOfArguments == 3 &&\n"); fprintf(fp," msg.ArgumentTypes[2] == vtkClietnServerStream::string_value)\n"); fprintf(fp," {\n"); fprintf(fp," vtkClientServerProgressObserver *apo = vtkClientServerProgressObserver::New();\n"); fprintf(fp," vtkObject* obj = arlu->GetObjectFromMessage(msg, 0, 1);\n"); fprintf(fp," apo->SetFilterID(arlu->GetIDFromObject(obj));\n"); fprintf(fp," apo->SetClientServerUtil(arlu);\n"); fprintf(fp," char *temp0 = vtkClientServerInterpreter::GetString(msg,2);\n"); fprintf(fp," op->AddObserver(temp0,apo);\n"); fprintf(fp," apo->Delete();\n"); fprintf(fp," delete [] temp0;\n"); fprintf(fp," return 1;\n"); fprintf(fp," }\n"); } #endif }
void outputFunction(FILE *fp, ClassInfo *data) { static unsigned int supported_types[] = { VTK_PARSE_VOID, VTK_PARSE_BOOL, VTK_PARSE_FLOAT, VTK_PARSE_DOUBLE, VTK_PARSE_CHAR, VTK_PARSE_UNSIGNED_CHAR, VTK_PARSE_SIGNED_CHAR, VTK_PARSE_INT, VTK_PARSE_UNSIGNED_INT, VTK_PARSE_SHORT, VTK_PARSE_UNSIGNED_SHORT, VTK_PARSE_LONG, VTK_PARSE_UNSIGNED_LONG, VTK_PARSE_ID_TYPE, VTK_PARSE_UNSIGNED_ID_TYPE, VTK_PARSE_LONG_LONG, VTK_PARSE_UNSIGNED_LONG_LONG, VTK_PARSE___INT64, VTK_PARSE_UNSIGNED___INT64, VTK_PARSE_VTK_OBJECT, VTK_PARSE_STRING, 0 }; int i, j; int args_ok = 1; unsigned int rType = (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE); unsigned int aType = 0; unsigned int baseType = 0; /* some functions will not get wrapped no matter what else */ if (currentFunction->IsOperator || currentFunction->ArrayFailure || !currentFunction->IsPublic || !currentFunction->Name) { return; } /* NewInstance and SafeDownCast can not be wrapped because it is a (non-virtual) method which returns a pointer of the same type as the current pointer. Since all methods are virtual in Java, this looks like polymorphic return type. */ if (!strcmp("NewInstance",currentFunction->Name)) { return ; } if (!strcmp("SafeDownCast",currentFunction->Name)) { return ; } /* The unwrappable methods in Filtering/vtkInformation.c */ if (strcmp(data->Name, "vtkInformation") == 0 && currentFunction->IsLegacy) { return; } /* The GetInput() in vtkMapper cannot be overriden with a * different return type, Java doesn't allow this */ if (strcmp(data->Name, "vtkMapper") == 0 && strcmp(currentFunction->Name, "GetInput") == 0) { return; } /* check to see if we can handle the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { aType = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE); baseType = (aType & VTK_PARSE_BASE_TYPE); if (currentFunction->ArgTypes[i] != VTK_PARSE_FUNCTION) { for (j = 0; supported_types[j] != 0; j++) { if (baseType == supported_types[j]) { break; } } if (supported_types[j] == 0) { args_ok = 0; } } if (baseType == VTK_PARSE_OBJECT) { if ((aType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) { args_ok = 0; } else if (hierarchyInfo) { if (vtkParseHierarchy_IsExtern(hierarchyInfo, currentFunction->ArgClasses[i]) || vtkParseHierarchy_GetProperty(hierarchyInfo, currentFunction->ArgClasses[i], "WRAP_EXCLUDE") || !vtkParseHierarchy_IsTypeOf(hierarchyInfo, currentFunction->ArgClasses[i], "vtkObjectBase")) { args_ok = 0; } } } if (aType == VTK_PARSE_VTK_OBJECT) args_ok = 0; if (((aType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) && ((aType & VTK_PARSE_INDIRECT) != 0) && (aType != VTK_PARSE_STRING_REF)) args_ok = 0; if (aType == VTK_PARSE_STRING_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_CHAR_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_INT_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_SHORT_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_LONG_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0; } baseType = (rType & VTK_PARSE_BASE_TYPE); for (j = 0; supported_types[j] != 0; j++) { if (baseType == supported_types[j]) { break; } } if (supported_types[j] == 0) { args_ok = 0; } if (baseType == VTK_PARSE_OBJECT) { if ((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) { args_ok = 0; } else if (hierarchyInfo) { if (vtkParseHierarchy_IsExtern(hierarchyInfo, currentFunction->ReturnClass) || vtkParseHierarchy_GetProperty(hierarchyInfo, currentFunction->ReturnClass, "WRAP_EXCLUDE") || !vtkParseHierarchy_IsTypeOf(hierarchyInfo, currentFunction->ReturnClass, "vtkObjectBase")) { args_ok = 0; } } } if (((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) && ((rType & VTK_PARSE_INDIRECT) != 0) && (rType != VTK_PARSE_STRING_REF)) args_ok = 0; if (rType == VTK_PARSE_STRING_PTR) args_ok = 0; /* eliminate unsigned char * and unsigned short * */ if (rType == VTK_PARSE_UNSIGNED_INT_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_SHORT_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_LONG_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0; if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION) &&(currentFunction->NumberOfArguments != 1)) args_ok = 0; /* make sure we have all the info we need for array arguments in */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { aType = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE); if (((aType & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER)&& (currentFunction->ArgCounts[i] <= 0)&& (aType != VTK_PARSE_VTK_OBJECT_PTR)&& (aType != VTK_PARSE_CHAR_PTR)) args_ok = 0; } /* if we need a return type hint make sure we have one */ switch (rType) { case VTK_PARSE_FLOAT_PTR: case VTK_PARSE_VOID_PTR: case VTK_PARSE_DOUBLE_PTR: case VTK_PARSE_INT_PTR: case VTK_PARSE_SHORT_PTR: case VTK_PARSE_LONG_PTR: case VTK_PARSE_ID_TYPE_PTR: case VTK_PARSE_LONG_LONG_PTR: case VTK_PARSE___INT64_PTR: case VTK_PARSE_SIGNED_CHAR_PTR: case VTK_PARSE_BOOL_PTR: case VTK_PARSE_UNSIGNED_CHAR_PTR: args_ok = currentFunction->HaveHint; break; } /* make sure there isn't a Java-specific override */ if (!strcmp("vtkObject",data->Name)) { /* remove the original vtkCommand observer methods */ if (!strcmp(currentFunction->Name,"AddObserver") || !strcmp(currentFunction->Name,"GetCommand") || (!strcmp(currentFunction->Name,"RemoveObserver") && (currentFunction->ArgTypes[0] != VTK_PARSE_UNSIGNED_LONG)) || ((!strcmp(currentFunction->Name,"RemoveObservers") || !strcmp(currentFunction->Name,"HasObserver")) && (((currentFunction->ArgTypes[0] != VTK_PARSE_UNSIGNED_LONG) && (currentFunction->ArgTypes[0] != (VTK_PARSE_CHAR_PTR|VTK_PARSE_CONST))) || (currentFunction->NumberOfArguments > 1))) || (!strcmp(currentFunction->Name,"RemoveAllObservers") && (currentFunction->NumberOfArguments > 0))) { args_ok = 0; } } else if (!strcmp("vtkObjectBase",data->Name)) { /* remove the special vtkObjectBase methods */ if (!strcmp(currentFunction->Name,"PrintRevisions") || !strcmp(currentFunction->Name,"Print")) { args_ok = 0; } } /* make sure it isn't a Delete or New function */ if (!strcmp("Delete",currentFunction->Name) || !strcmp("New",currentFunction->Name)) { args_ok = 0; } /* handle DataReader SetBinaryInputString as a special case */ if (!strcmp("SetBinaryInputString",currentFunction->Name) && (!strcmp("vtkDataReader",data->Name) || !strcmp("vtkStructuredGridReader",data->Name) || !strcmp("vtkRectilinearGridReader",data->Name) || !strcmp("vtkUnstructuredGridReader",data->Name) || !strcmp("vtkStructuredPointsReader",data->Name) || !strcmp("vtkPolyDataReader",data->Name))) { HandleDataReader(fp,data); wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } if (currentFunction->IsPublic && args_ok && strcmp(data->Name,currentFunction->Name) && strcmp(data->Name, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n private native "); return_result_native(fp); fprintf(fp,"%s_%i(",currentFunction->Name,numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); } fprintf(fp,");\n"); fprintf(fp," public "); return_result(fp); fprintf(fp,"%s(",currentFunction->Name); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); } /* if returning object, lookup in global hash */ if (rType == VTK_PARSE_VTK_OBJECT_PTR) { fprintf(fp,") {"); fprintf(fp,"\n long temp = %s_%i(",currentFunction->Name, numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } fprintf(fp,");\n"); fprintf(fp,"\n if (temp == 0) return null;"); fprintf(fp,"\n %s obj = null;", currentFunction->ReturnClass); fprintf(fp,"\n java.lang.ref.WeakReference ref = (java.lang.ref.WeakReference)vtkGlobalJavaHash.PointerToReference.get(new Long(temp));"); fprintf(fp,"\n if (ref != null) {"); fprintf(fp,"\n obj = (%s)ref.get();", currentFunction->ReturnClass); fprintf(fp,"\n }"); fprintf(fp,"\n if (obj == null) {"); fprintf(fp,"\n %s tempObj = new %s(temp);", currentFunction->ReturnClass, currentFunction->ReturnClass); fprintf(fp,"\n String className = tempObj.GetClassName();"); fprintf(fp,"\n try {"); fprintf(fp,"\n Class c = Class.forName(\"vtk.\" + className);"); fprintf(fp,"\n java.lang.reflect.Constructor cons = c.getConstructor(new Class[] {long.class} );"); fprintf(fp,"\n obj = (%s)cons.newInstance(new Object[] {new Long(temp)});", currentFunction->ReturnClass); fprintf(fp,"\n } catch (Exception e) {"); fprintf(fp,"\n e.printStackTrace();"); fprintf(fp,"\n }"); fprintf(fp,"\n vtkObjectBase.VTKDeleteReference(temp);"); fprintf(fp,"\n }"); fprintf(fp,"\n return obj;"); fprintf(fp,"\n }\n"); } else { /* if not void then need return otherwise none */ if (rType == VTK_PARSE_VOID) { fprintf(fp,")\n { %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } else { fprintf(fp,")\n { return %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } if ((currentFunction->NumberOfArguments == 1) && (currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION)) { fprintf(fp,",id1"); } fprintf(fp,"); }\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } } }