1 /*=========================================================================
3 Program: Visualization Toolkit
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
14 =========================================================================*/
17 #include "vtkParseData.h"
18 #include "vtkParseExtras.h"
19 #include "vtkParseString.h"
24 /* -------------------------------------------------------------------- */
27 int vtkWrap_IsVoid(ValueInfo *val)
34 return ((val->Type & VTK_PARSE_UNQUALIFIED_TYPE) == VTK_PARSE_VOID);
37 int vtkWrap_IsVoidFunction(ValueInfo *val)
39 unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
41 if (t == VTK_PARSE_FUNCTION_PTR || t == VTK_PARSE_FUNCTION)
43 /* check for signature "void (*func)(void *)" */
44 if (val->Function->NumberOfParameters == 1 &&
45 val->Function->Parameters[0]->Type == VTK_PARSE_VOID_PTR &&
46 val->Function->Parameters[0]->NumberOfDimensions == 0 &&
47 val->Function->ReturnValue->Type == VTK_PARSE_VOID)
56 int vtkWrap_IsVoidPointer(ValueInfo *val)
58 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
59 return (t == VTK_PARSE_VOID && vtkWrap_IsPointer(val));
62 int vtkWrap_IsCharPointer(ValueInfo *val)
64 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
65 return (t == VTK_PARSE_CHAR && vtkWrap_IsPointer(val));
68 int vtkWrap_IsVTKObject(ValueInfo *val)
70 unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
71 return (t == VTK_PARSE_OBJECT_PTR &&
72 val->Class[0] == 'v' && strncmp(val->Class, "vtk", 3) == 0);
75 int vtkWrap_IsSpecialObject(ValueInfo *val)
77 unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
78 return ((t == VTK_PARSE_OBJECT ||
79 t == VTK_PARSE_OBJECT_REF) &&
80 val->Class[0] == 'v' && strncmp(val->Class, "vtk", 3) == 0);
83 int vtkWrap_IsQtObject(ValueInfo *val)
85 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
86 if (t == VTK_PARSE_QOBJECT &&
87 val->Class[0] == 'Q' && isupper(val->Class[1]))
94 int vtkWrap_IsQtEnum(ValueInfo *val)
96 unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
97 if ((t == VTK_PARSE_QOBJECT || t == VTK_PARSE_QOBJECT_REF) &&
98 val->Class[0] == 'Q' && strncmp("Qt::", val->Class, 4) == 0)
106 /* -------------------------------------------------------------------- */
107 /* The base types, all are mutually exclusive. */
109 int vtkWrap_IsObject(ValueInfo *val)
111 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
112 return (t == VTK_PARSE_OBJECT ||
113 t == VTK_PARSE_QOBJECT);
116 int vtkWrap_IsFunction(ValueInfo *val)
118 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
119 return (t == VTK_PARSE_FUNCTION);
122 int vtkWrap_IsStream(ValueInfo *val)
124 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
125 return (t == VTK_PARSE_ISTREAM ||
126 t == VTK_PARSE_OSTREAM);
129 int vtkWrap_IsNumeric(ValueInfo *val)
131 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
133 t = (t & ~VTK_PARSE_UNSIGNED);
136 case VTK_PARSE_FLOAT:
137 case VTK_PARSE_DOUBLE:
139 case VTK_PARSE_SHORT:
142 case VTK_PARSE_ID_TYPE:
143 case VTK_PARSE_LONG_LONG:
144 case VTK_PARSE___INT64:
145 case VTK_PARSE_SIGNED_CHAR:
146 case VTK_PARSE_SSIZE_T:
154 int vtkWrap_IsString(ValueInfo *val)
156 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
157 return (t == VTK_PARSE_STRING ||
158 t == VTK_PARSE_UNICODE_STRING);
161 /* -------------------------------------------------------------------- */
164 int vtkWrap_IsBool(ValueInfo *val)
166 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
167 return (t == VTK_PARSE_BOOL);
170 int vtkWrap_IsChar(ValueInfo *val)
172 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
173 return (t == VTK_PARSE_CHAR);
176 int vtkWrap_IsInteger(ValueInfo *val)
178 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
180 if (t != VTK_PARSE_UNSIGNED_CHAR)
182 t = (t & ~VTK_PARSE_UNSIGNED);
186 case VTK_PARSE_SHORT:
189 case VTK_PARSE_ID_TYPE:
190 case VTK_PARSE_LONG_LONG:
191 case VTK_PARSE___INT64:
192 case VTK_PARSE_UNSIGNED_CHAR:
193 case VTK_PARSE_SIGNED_CHAR:
194 case VTK_PARSE_SSIZE_T:
201 int vtkWrap_IsRealNumber(ValueInfo *val)
203 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
204 return (t == VTK_PARSE_FLOAT || t == VTK_PARSE_DOUBLE);
207 /* -------------------------------------------------------------------- */
208 /* These are mutually exclusive, as well. */
210 int vtkWrap_IsScalar(ValueInfo *val)
212 unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
216 int vtkWrap_IsPointer(ValueInfo *val)
218 unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
219 return (i == VTK_PARSE_POINTER && val->Count == 0 &&
220 val->CountHint == 0 && val->NumberOfDimensions <= 1);
223 int vtkWrap_IsArray(ValueInfo *val)
225 unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
226 return (i == VTK_PARSE_POINTER && val->NumberOfDimensions <= 1 &&
227 (val->Count != 0 || val->CountHint != 0));
230 int vtkWrap_IsNArray(ValueInfo *val)
233 unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
234 if (i != VTK_PARSE_ARRAY || val->NumberOfDimensions <= 1)
238 for (j = 0; j < val->NumberOfDimensions; j++)
240 if (val->Dimensions[j] == NULL || val->Dimensions[j][0] == '\0')
249 /* -------------------------------------------------------------------- */
250 /* Other type properties, not mutually exclusive. */
252 int vtkWrap_IsNonConstRef(ValueInfo *val)
254 return ((val->Type & VTK_PARSE_REF) != 0 &&
255 (val->Type & VTK_PARSE_CONST) == 0);
258 int vtkWrap_IsConstRef(ValueInfo *val)
260 return ((val->Type & VTK_PARSE_REF) != 0 &&
261 (val->Type & VTK_PARSE_CONST) != 0);
264 int vtkWrap_IsRef(ValueInfo *val)
266 return ((val->Type & VTK_PARSE_REF) != 0);
269 int vtkWrap_IsConst(ValueInfo *val)
271 return ((val->Type & VTK_PARSE_CONST) != 0);
274 /* -------------------------------------------------------------------- */
277 int vtkWrap_IsNewInstance(ValueInfo *val)
279 return ((val->Type & VTK_PARSE_NEWINSTANCE) != 0);
282 /* -------------------------------------------------------------------- */
283 /* Constructor/Destructor checks */
285 int vtkWrap_IsConstructor(ClassInfo *c, FunctionInfo *f)
289 const char *cp = c->Name;
291 if (cp && f->Name && !vtkWrap_IsDestructor(c, f))
293 /* remove namespaces and template parameters from the name */
294 m = vtkParse_UnscopedNameLength(cp);
295 while (cp[m] == ':' && cp[m+1] == ':')
298 m = vtkParse_UnscopedNameLength(cp);
300 for (i = 0; i < m; i++)
308 return (i == strlen(f->Name) && strncmp(cp, f->Name, i) == 0);
314 int vtkWrap_IsDestructor(ClassInfo *c, FunctionInfo *f)
319 if (c->Name && f->Name)
322 for (i = 0; cp[i] != '\0' && cp[i] != '('; i++)
334 int vtkWrap_IsSetVectorMethod(FunctionInfo *f)
336 if (f->Macro && strncmp(f->Macro, "vtkSetVector", 12) == 0)
344 int vtkWrap_IsGetVectorMethod(FunctionInfo *f)
346 if (f->Macro && strncmp(f->Macro, "vtkGetVector", 12) == 0)
354 /* -------------------------------------------------------------------- */
355 /* Argument counting */
357 int vtkWrap_CountWrappedParameters(FunctionInfo *f)
359 int totalArgs = f->NumberOfParameters;
362 (f->Parameters[0]->Type & VTK_PARSE_BASE_TYPE)
363 == VTK_PARSE_FUNCTION)
367 else if (totalArgs == 1 &&
368 (f->Parameters[0]->Type & VTK_PARSE_UNQUALIFIED_TYPE)
377 int vtkWrap_CountRequiredArguments(FunctionInfo *f)
379 int requiredArgs = 0;
383 totalArgs = vtkWrap_CountWrappedParameters(f);
385 for (i = 0; i < totalArgs; i++)
387 if (f->Parameters[i]->Value == NULL ||
388 vtkWrap_IsArray(f->Parameters[i]) ||
389 vtkWrap_IsNArray(f->Parameters[i]))
398 /* -------------------------------------------------------------------- */
399 /* Check whether the class is derived from vtkObjectBase. */
401 int vtkWrap_IsVTKObjectBaseType(
402 HierarchyInfo *hinfo, const char *classname)
404 HierarchyEntry *entry;
408 entry = vtkParseHierarchy_FindEntry(hinfo, classname);
411 if (vtkParseHierarchy_IsTypeOf(hinfo, entry, "vtkObjectBase"))
419 /* fallback if no HierarchyInfo */
420 if (strncmp("vtk", classname, 3) == 0)
428 /* -------------------------------------------------------------------- */
429 /* Check if the WRAP_SPECIAL flag is set for the class. */
431 int vtkWrap_IsSpecialType(
432 HierarchyInfo *hinfo, const char *classname)
434 HierarchyEntry *entry;
438 entry = vtkParseHierarchy_FindEntry(hinfo, classname);
439 if (entry && vtkParseHierarchy_GetProperty(entry, "WRAP_SPECIAL"))
446 /* fallback if no HierarchyInfo */
447 if (strncmp("vtk", classname, 3) == 0)
455 /* -------------------------------------------------------------------- */
456 /* Check if the class is derived from superclass */
458 int vtkWrap_IsTypeOf(
459 HierarchyInfo *hinfo, const char *classname, const char *superclass)
461 HierarchyEntry *entry;
463 if (strcmp(classname, superclass) == 0)
470 entry = vtkParseHierarchy_FindEntry(hinfo, classname);
471 if (entry && vtkParseHierarchy_IsTypeOf(hinfo, entry, superclass))
480 /* -------------------------------------------------------------------- */
481 /* Make a guess about whether a class is wrapped */
483 int vtkWrap_IsClassWrapped(
484 HierarchyInfo *hinfo, const char *classname)
488 HierarchyEntry *entry;
489 entry = vtkParseHierarchy_FindEntry(hinfo, classname);
493 if (!vtkParseHierarchy_GetProperty(entry, "WRAP_EXCLUDE") ||
494 vtkParseHierarchy_GetProperty(entry, "WRAP_SPECIAL"))
500 else if (strncmp("vtk", classname, 3) == 0)
508 /* -------------------------------------------------------------------- */
509 /* Check whether the destructor is public */
510 int vtkWrap_HasPublicDestructor(ClassInfo *data)
515 for (i = 0; i < data->NumberOfFunctions; i++)
517 func = data->Functions[i];
519 if (vtkWrap_IsDestructor(data, func) &&
520 func->Access != VTK_ACCESS_PUBLIC)
529 /* -------------------------------------------------------------------- */
530 /* Check whether the copy constructor is public */
531 int vtkWrap_HasPublicCopyConstructor(ClassInfo *data)
536 for (i = 0; i < data->NumberOfFunctions; i++)
538 func = data->Functions[i];
540 if (vtkWrap_IsConstructor(data, func) &&
541 func->NumberOfParameters == 1 &&
542 func->Parameters[0]->Class &&
543 strcmp(func->Parameters[0]->Class, data->Name) == 0 &&
544 func->Access != VTK_ACCESS_PUBLIC)
553 /* -------------------------------------------------------------------- */
554 /* Get the size for subclasses of vtkTuple */
555 int vtkWrap_GetTupleSize(ClassInfo *data, HierarchyInfo *hinfo)
557 HierarchyEntry *entry;
558 const char *classname = NULL;
562 entry = vtkParseHierarchy_FindEntry(hinfo, data->Name);
563 if (entry && vtkParseHierarchy_IsTypeOfTemplated(
564 hinfo, entry, data->Name, "vtkTuple", &classname))
566 /* attempt to get count from template parameter */
569 m = strlen(classname);
570 if (m > 2 && classname[m - 1] == '>' &&
571 isdigit(classname[m-2]) && (classname[m-3] == ' ' ||
572 classname[m-3] == ',' || classname[m-3] == '<'))
574 size = classname[m-2] - '0';
576 free((char *)classname);
583 /* -------------------------------------------------------------------- */
584 /* This sets the CountHint for vtkDataArray methods where the
585 * tuple size is equal to GetNumberOfComponents. */
586 void vtkWrap_FindCountHints(
587 ClassInfo *data, FileInfo *finfo, HierarchyInfo *hinfo)
591 const char *countMethod;
592 FunctionInfo *theFunc;
594 /* add hints for vtkInformation get methods */
595 if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkInformation"))
597 countMethod = "Length(temp0)";
599 for (i = 0; i < data->NumberOfFunctions; i++)
601 theFunc = data->Functions[i];
603 if (strcmp(theFunc->Name, "Get") == 0 &&
604 theFunc->NumberOfParameters >= 1 &&
605 theFunc->Parameters[0]->Type == VTK_PARSE_OBJECT_PTR &&
606 (strcmp(theFunc->Parameters[0]->Class,
607 "vtkInformationIntegerVectorKey") == 0 ||
608 strcmp(theFunc->Parameters[0]->Class,
609 "vtkInformationDoubleVectorKey") == 0))
611 if (theFunc->ReturnValue && theFunc->ReturnValue->Count == 0 &&
612 theFunc->NumberOfParameters == 1)
614 theFunc->ReturnValue->CountHint = countMethod;
620 /* add hints for array GetTuple methods */
621 if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkDataArray"))
623 countMethod = "GetNumberOfComponents()";
625 for (i = 0; i < data->NumberOfFunctions; i++)
627 theFunc = data->Functions[i];
629 if ((strcmp(theFunc->Name, "GetTuple") == 0 ||
630 strcmp(theFunc->Name, "GetTupleValue") == 0) &&
631 theFunc->ReturnValue && theFunc->ReturnValue->Count == 0 &&
632 theFunc->NumberOfParameters == 1 &&
633 theFunc->Parameters[0]->Type == VTK_PARSE_ID_TYPE)
635 theFunc->ReturnValue->CountHint = countMethod;
637 else if ((strcmp(theFunc->Name, "SetTuple") == 0 ||
638 strcmp(theFunc->Name, "SetTupleValue") == 0 ||
639 strcmp(theFunc->Name, "GetTuple") == 0 ||
640 strcmp(theFunc->Name, "GetTupleValue") == 0 ||
641 strcmp(theFunc->Name, "InsertTuple") == 0 ||
642 strcmp(theFunc->Name, "InsertTupleValue") == 0) &&
643 theFunc->NumberOfParameters == 2 &&
644 theFunc->Parameters[0]->Type == VTK_PARSE_ID_TYPE &&
645 theFunc->Parameters[1]->Count == 0)
647 theFunc->Parameters[1]->CountHint = countMethod;
649 else if ((strcmp(theFunc->Name, "InsertNextTuple") == 0 ||
650 strcmp(theFunc->Name, "InsertNextTupleValue") == 0) &&
651 theFunc->NumberOfParameters == 1 &&
652 theFunc->Parameters[0]->Count == 0)
654 theFunc->Parameters[0]->CountHint = countMethod;
659 /* add hints for interpolator Interpolate methods */
660 if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractImageInterpolator"))
662 countMethod = "GetNumberOfComponents()";
664 for (i = 0; i < data->NumberOfFunctions; i++)
666 theFunc = data->Functions[i];
668 if (strcmp(theFunc->Name, "Interpolate") == 0 &&
669 theFunc->NumberOfParameters == 2 &&
670 theFunc->Parameters[0]->Type == (VTK_PARSE_DOUBLE_PTR|VTK_PARSE_CONST) &&
671 theFunc->Parameters[0]->Count == 3 &&
672 theFunc->Parameters[1]->Type == VTK_PARSE_DOUBLE_PTR &&
673 theFunc->Parameters[1]->Count == 0)
675 theFunc->Parameters[1]->CountHint = countMethod;
680 for (i = 0; i < data->NumberOfFunctions; i++)
682 theFunc = data->Functions[i];
684 /* hints for constructors that take arrays */
685 if (vtkWrap_IsConstructor(data, theFunc) &&
686 theFunc->NumberOfParameters == 1 &&
687 vtkWrap_IsPointer(theFunc->Parameters[0]) &&
688 vtkWrap_IsNumeric(theFunc->Parameters[0]) &&
689 theFunc->Parameters[0]->Count == 0 &&
692 count = vtkWrap_GetTupleSize(data, hinfo);
696 sprintf(counttext, "%d", count);
697 theFunc->Parameters[0]->Count = count;
698 vtkParse_AddStringToArray(
699 &theFunc->Parameters[0]->Dimensions,
700 &theFunc->Parameters[0]->NumberOfDimensions,
701 vtkParse_CacheString(finfo->Strings, counttext, strlen(counttext)));
705 /* hints for operator[] index range */
706 if (theFunc->IsOperator && theFunc->Name &&
707 strcmp(theFunc->Name, "operator[]") == 0)
709 if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkTuple"))
711 theFunc->SizeHint = "GetSize()";
713 else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayCoordinates") ||
714 vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtents") ||
715 vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArraySort"))
717 theFunc->SizeHint = "GetDimensions()";
719 else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtentsList") ||
720 vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayWeights"))
722 theFunc->SizeHint = "GetCount()";
728 /* -------------------------------------------------------------------- */
729 /* This sets the NewInstance hint for generator methods. */
730 void vtkWrap_FindNewInstanceMethods(
731 ClassInfo *data, HierarchyInfo *hinfo)
734 FunctionInfo *theFunc;
736 for (i = 0; i < data->NumberOfFunctions; i++)
738 theFunc = data->Functions[i];
739 if (theFunc->Name && theFunc->ReturnValue &&
740 vtkWrap_IsVTKObject(theFunc->ReturnValue) &&
741 vtkWrap_IsVTKObjectBaseType(hinfo, theFunc->ReturnValue->Class))
743 if (strcmp(theFunc->Name, "NewInstance") == 0 ||
744 strcmp(theFunc->Name, "CreateInstance") == 0 ||
745 (strcmp(theFunc->Name, "CreateLookupTable") == 0 &&
746 strcmp(data->Name, "vtkColorSeries") == 0) ||
747 (strcmp(theFunc->Name, "CreateImageReader2") == 0 &&
748 strcmp(data->Name, "vtkImageReader2Factory") == 0) ||
749 (strcmp(theFunc->Name, "CreateDataArray") == 0 &&
750 strcmp(data->Name, "vtkDataArray") == 0) ||
751 (strcmp(theFunc->Name, "CreateArray") == 0 &&
752 strcmp(data->Name, "vtkAbstractArray") == 0) ||
753 (strcmp(theFunc->Name, "CreateArray") == 0 &&
754 strcmp(data->Name, "vtkArray") == 0) ||
755 (strcmp(theFunc->Name, "GetQueryInstance") == 0 &&
756 strcmp(data->Name, "vtkSQLDatabase") == 0) ||
757 (strcmp(theFunc->Name, "CreateFromURL") == 0 &&
758 strcmp(data->Name, "vtkSQLDatabase") == 0) ||
759 (strcmp(theFunc->Name, "MakeTransform") == 0 &&
760 vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractTransform")))
762 theFunc->ReturnValue->Type |= VTK_PARSE_NEWINSTANCE;
769 /* -------------------------------------------------------------------- */
770 /* Expand all typedef types that are used in function arguments */
771 void vtkWrap_ExpandTypedefs(
772 ClassInfo *data, FileInfo *finfo, HierarchyInfo *hinfo)
775 FunctionInfo *funcInfo;
776 const char *newclass;
778 n = data->NumberOfSuperClasses;
779 for (i = 0; i < n; i++)
781 newclass = vtkParseHierarchy_ExpandTypedefsInName(
782 hinfo, data->SuperClasses[i], NULL);
783 if (newclass != data->SuperClasses[i])
785 data->SuperClasses[i] =
786 vtkParse_CacheString(finfo->Strings, newclass, strlen(newclass));
787 free((char *)newclass);
791 n = data->NumberOfFunctions;
792 for (i = 0; i < n; i++)
794 funcInfo = data->Functions[i];
795 if (funcInfo->Access == VTK_ACCESS_PUBLIC)
797 for (j = 0; j < funcInfo->NumberOfParameters; j++)
799 vtkParseHierarchy_ExpandTypedefsInValue(
800 hinfo, funcInfo->Parameters[j], finfo->Strings, data->Name);
802 if (funcInfo->ReturnValue)
804 vtkParseHierarchy_ExpandTypedefsInValue(
805 hinfo, funcInfo->ReturnValue, finfo->Strings, data->Name);
812 /* -------------------------------------------------------------------- */
813 /* get the type name */
815 const char *vtkWrap_GetTypeName(ValueInfo *val)
817 unsigned int aType = val->Type;
818 const char *aClass = val->Class;
820 /* print the type itself */
821 switch (aType & VTK_PARSE_BASE_TYPE)
823 case VTK_PARSE_FLOAT: return "float";
824 case VTK_PARSE_DOUBLE: return "double";
825 case VTK_PARSE_INT: return "int";
826 case VTK_PARSE_SHORT: return "short";
827 case VTK_PARSE_LONG: return "long";
828 case VTK_PARSE_VOID: return "void ";
829 case VTK_PARSE_CHAR: return "char";
830 case VTK_PARSE_UNSIGNED_INT: return "unsigned int";
831 case VTK_PARSE_UNSIGNED_SHORT: return "unsigned short";
832 case VTK_PARSE_UNSIGNED_LONG: return "unsigned long";
833 case VTK_PARSE_UNSIGNED_CHAR: return "unsigned char";
834 case VTK_PARSE_ID_TYPE: return "vtkIdType";
835 case VTK_PARSE_LONG_LONG: return "long long";
836 case VTK_PARSE___INT64: return "__int64";
837 case VTK_PARSE_UNSIGNED_LONG_LONG: return "unsigned long long";
838 case VTK_PARSE_UNSIGNED___INT64: return "unsigned __int64";
839 case VTK_PARSE_SIGNED_CHAR: return "signed char";
840 case VTK_PARSE_BOOL: return "bool";
841 case VTK_PARSE_UNICODE_STRING: return "vtkUnicodeString";
842 case VTK_PARSE_SSIZE_T: return "ssize_t";
843 case VTK_PARSE_SIZE_T: return "size_t";
849 /* -------------------------------------------------------------------- */
850 /* variable declarations */
852 void vtkWrap_DeclareVariable(
853 FILE *fp, ValueInfo *val, const char *name, int i, int flags)
863 aType = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
865 /* do nothing for void */
866 if (aType == VTK_PARSE_VOID ||
867 (aType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_FUNCTION)
872 /* add a couple spaces */
875 /* for const * return types, prepend with const */
876 if ((flags & VTK_WRAP_RETURN) != 0)
878 if ((val->Type & VTK_PARSE_CONST) != 0 &&
879 (aType & VTK_PARSE_INDIRECT) != 0)
881 fprintf(fp,"const ");
884 /* do the same for "const char *" with initializer */
887 if ((val->Type & VTK_PARSE_CONST) != 0 &&
888 aType == VTK_PARSE_CHAR_PTR &&
890 strcmp(val->Value, "0") != 0 &&
891 strcmp(val->Value, "NULL") != 0)
893 fprintf(fp,"const ");
897 /* print the type name */
898 fprintf(fp, "%s ", vtkWrap_GetTypeName(val));
901 if ((flags & VTK_WRAP_RETURN) != 0)
903 /* ref and pointer return values are stored as pointers */
904 if ((aType & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER ||
905 (aType & VTK_PARSE_INDIRECT) == VTK_PARSE_REF)
912 /* objects refs and pointers are always handled via pointers,
913 * other refs are passed by value */
914 if (aType == VTK_PARSE_CHAR_PTR ||
915 aType == VTK_PARSE_VOID_PTR ||
916 aType == VTK_PARSE_OBJECT_PTR ||
917 aType == VTK_PARSE_OBJECT_REF ||
918 aType == VTK_PARSE_OBJECT ||
919 vtkWrap_IsQtObject(val))
923 /* arrays of unknown size are handled via pointers */
924 else if (val->CountHint)
930 /* the variable name */
933 fprintf(fp,"%s%i", name, i);
937 fprintf(fp,"%s", name);
940 if ((flags & VTK_WRAP_ARG) != 0)
942 /* print the array decorators */
943 if (((aType & VTK_PARSE_POINTER_MASK) != 0) &&
944 aType != VTK_PARSE_CHAR_PTR &&
945 aType != VTK_PARSE_VOID_PTR &&
946 aType != VTK_PARSE_OBJECT_PTR &&
947 !vtkWrap_IsQtObject(val) &&
948 val->CountHint == NULL)
950 if (val->NumberOfDimensions == 1 && val->Count > 0)
952 fprintf(fp, "[%d]", val->Count);
956 for (j = 0; j < val->NumberOfDimensions; j++)
958 fprintf(fp, "[%s]", val->Dimensions[j]);
963 /* add a default value */
966 fprintf(fp, " = %s", val->Value);
968 else if (aType == VTK_PARSE_CHAR_PTR ||
969 aType == VTK_PARSE_VOID_PTR ||
970 aType == VTK_PARSE_OBJECT_PTR ||
971 aType == VTK_PARSE_OBJECT_REF ||
972 aType == VTK_PARSE_OBJECT ||
973 vtkWrap_IsQtObject(val))
975 fprintf(fp, " = NULL");
977 else if (val->CountHint)
979 fprintf(fp, " = NULL");
981 else if (aType == VTK_PARSE_BOOL)
983 fprintf(fp, " = false");
987 /* finish off with a semicolon */
988 if ((flags & VTK_WRAP_NOSEMI) == 0)
994 void vtkWrap_DeclareVariableSize(
995 FILE *fp, ValueInfo *val, const char *name, int i)
1003 sprintf(idx, "%d", i);
1006 if (val->NumberOfDimensions > 1)
1009 " static int %s%s[%d] = ",
1010 name, idx, val->NumberOfDimensions);
1012 for (j = 0; j < val->NumberOfDimensions; j++)
1014 fprintf(fp, "%c %s", ((j == 0) ? '{' : ','), val->Dimensions[j]);
1017 fprintf(fp, " };\n");
1019 else if (val->Count != 0 || val->CountHint)
1022 " %sint %s%s = %d;\n",
1023 (val->CountHint ? "" : "const "), name, idx,
1024 (val->CountHint ? 0 : val->Count));
1026 else if (val->NumberOfDimensions == 1)
1029 " const int %s%s = %s;\n",
1030 name, idx, val->Dimensions[0]);