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_IsPODPointer(ValueInfo *val)
70 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
71 return (t != VTK_PARSE_CHAR && vtkWrap_IsNumeric(val) &&
72 vtkWrap_IsPointer(val));
75 int vtkWrap_IsVTKObject(ValueInfo *val)
77 unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
78 return (t == VTK_PARSE_OBJECT_PTR &&
79 val->Class[0] == 'v' && strncmp(val->Class, "vtk", 3) == 0);
82 int vtkWrap_IsSpecialObject(ValueInfo *val)
84 unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
85 return ((t == VTK_PARSE_OBJECT ||
86 t == VTK_PARSE_OBJECT_REF) &&
87 val->Class[0] == 'v' && strncmp(val->Class, "vtk", 3) == 0);
90 int vtkWrap_IsQtObject(ValueInfo *val)
92 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
93 if (t == VTK_PARSE_QOBJECT &&
94 val->Class[0] == 'Q' && isupper(val->Class[1]))
101 int vtkWrap_IsQtEnum(ValueInfo *val)
103 unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
104 if ((t == VTK_PARSE_QOBJECT || t == VTK_PARSE_QOBJECT_REF) &&
105 val->Class[0] == 'Q' && strncmp("Qt::", val->Class, 4) == 0)
113 /* -------------------------------------------------------------------- */
114 /* The base types, all are mutually exclusive. */
116 int vtkWrap_IsObject(ValueInfo *val)
118 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
119 return (t == VTK_PARSE_OBJECT ||
120 t == VTK_PARSE_QOBJECT);
123 int vtkWrap_IsFunction(ValueInfo *val)
125 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
126 return (t == VTK_PARSE_FUNCTION);
129 int vtkWrap_IsStream(ValueInfo *val)
131 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
132 return (t == VTK_PARSE_ISTREAM ||
133 t == VTK_PARSE_OSTREAM);
136 int vtkWrap_IsNumeric(ValueInfo *val)
138 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
140 t = (t & ~VTK_PARSE_UNSIGNED);
143 case VTK_PARSE_FLOAT:
144 case VTK_PARSE_DOUBLE:
146 case VTK_PARSE_SHORT:
149 case VTK_PARSE_ID_TYPE:
150 case VTK_PARSE_LONG_LONG:
151 case VTK_PARSE___INT64:
152 case VTK_PARSE_SIGNED_CHAR:
153 case VTK_PARSE_SSIZE_T:
161 int vtkWrap_IsString(ValueInfo *val)
163 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
164 return (t == VTK_PARSE_STRING ||
165 t == VTK_PARSE_UNICODE_STRING);
168 /* -------------------------------------------------------------------- */
171 int vtkWrap_IsBool(ValueInfo *val)
173 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
174 return (t == VTK_PARSE_BOOL);
177 int vtkWrap_IsChar(ValueInfo *val)
179 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
180 return (t == VTK_PARSE_CHAR);
183 int vtkWrap_IsInteger(ValueInfo *val)
185 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
187 if (t != VTK_PARSE_UNSIGNED_CHAR)
189 t = (t & ~VTK_PARSE_UNSIGNED);
193 case VTK_PARSE_SHORT:
196 case VTK_PARSE_ID_TYPE:
197 case VTK_PARSE_LONG_LONG:
198 case VTK_PARSE___INT64:
199 case VTK_PARSE_UNSIGNED_CHAR:
200 case VTK_PARSE_SIGNED_CHAR:
201 case VTK_PARSE_SSIZE_T:
208 int vtkWrap_IsRealNumber(ValueInfo *val)
210 unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
211 return (t == VTK_PARSE_FLOAT || t == VTK_PARSE_DOUBLE);
214 /* -------------------------------------------------------------------- */
215 /* These are mutually exclusive, as well. */
217 int vtkWrap_IsScalar(ValueInfo *val)
219 unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
223 int vtkWrap_IsPointer(ValueInfo *val)
225 unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
226 return (i == VTK_PARSE_POINTER && val->Count == 0 &&
227 val->CountHint == 0 && val->NumberOfDimensions <= 1);
230 int vtkWrap_IsArray(ValueInfo *val)
232 unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
233 return (i == VTK_PARSE_POINTER && val->NumberOfDimensions <= 1 &&
234 (val->Count != 0 || val->CountHint != 0));
237 int vtkWrap_IsNArray(ValueInfo *val)
240 unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
241 if (i != VTK_PARSE_ARRAY || val->NumberOfDimensions <= 1)
245 for (j = 0; j < val->NumberOfDimensions; j++)
247 if (val->Dimensions[j] == NULL || val->Dimensions[j][0] == '\0')
256 /* -------------------------------------------------------------------- */
257 /* Other type properties, not mutually exclusive. */
259 int vtkWrap_IsNonConstRef(ValueInfo *val)
261 return ((val->Type & VTK_PARSE_REF) != 0 &&
262 (val->Type & VTK_PARSE_CONST) == 0);
265 int vtkWrap_IsConstRef(ValueInfo *val)
267 return ((val->Type & VTK_PARSE_REF) != 0 &&
268 (val->Type & VTK_PARSE_CONST) != 0);
271 int vtkWrap_IsRef(ValueInfo *val)
273 return ((val->Type & VTK_PARSE_REF) != 0);
276 int vtkWrap_IsConst(ValueInfo *val)
278 return ((val->Type & VTK_PARSE_CONST) != 0);
281 /* -------------------------------------------------------------------- */
284 int vtkWrap_IsNewInstance(ValueInfo *val)
286 return ((val->Type & VTK_PARSE_NEWINSTANCE) != 0);
289 /* -------------------------------------------------------------------- */
290 /* Constructor/Destructor checks */
292 int vtkWrap_IsConstructor(ClassInfo *c, FunctionInfo *f)
296 const char *cp = c->Name;
298 if (cp && f->Name && !vtkWrap_IsDestructor(c, f))
300 /* remove namespaces and template parameters from the name */
301 m = vtkParse_UnscopedNameLength(cp);
302 while (cp[m] == ':' && cp[m+1] == ':')
305 m = vtkParse_UnscopedNameLength(cp);
307 for (i = 0; i < m; i++)
315 return (i == strlen(f->Name) && strncmp(cp, f->Name, i) == 0);
321 int vtkWrap_IsDestructor(ClassInfo *c, FunctionInfo *f)
326 if (c->Name && f->Name)
329 for (i = 0; cp[i] != '\0' && cp[i] != '('; i++)
341 int vtkWrap_IsSetVectorMethod(FunctionInfo *f)
343 if (f->Macro && strncmp(f->Macro, "vtkSetVector", 12) == 0)
351 int vtkWrap_IsGetVectorMethod(FunctionInfo *f)
353 if (f->Macro && strncmp(f->Macro, "vtkGetVector", 12) == 0)
361 /* -------------------------------------------------------------------- */
362 /* Argument counting */
364 int vtkWrap_CountWrappedParameters(FunctionInfo *f)
366 int totalArgs = f->NumberOfParameters;
369 (f->Parameters[0]->Type & VTK_PARSE_BASE_TYPE)
370 == VTK_PARSE_FUNCTION)
374 else if (totalArgs == 1 &&
375 (f->Parameters[0]->Type & VTK_PARSE_UNQUALIFIED_TYPE)
384 int vtkWrap_CountRequiredArguments(FunctionInfo *f)
386 int requiredArgs = 0;
390 totalArgs = vtkWrap_CountWrappedParameters(f);
392 for (i = 0; i < totalArgs; i++)
394 if (f->Parameters[i]->Value == NULL ||
395 vtkWrap_IsArray(f->Parameters[i]) ||
396 vtkWrap_IsNArray(f->Parameters[i]))
405 /* -------------------------------------------------------------------- */
406 /* Check whether the class is derived from vtkObjectBase. */
408 int vtkWrap_IsVTKObjectBaseType(
409 HierarchyInfo *hinfo, const char *classname)
411 HierarchyEntry *entry;
415 entry = vtkParseHierarchy_FindEntry(hinfo, classname);
418 if (vtkParseHierarchy_IsTypeOf(hinfo, entry, "vtkObjectBase"))
426 /* fallback if no HierarchyInfo */
427 if (strncmp("vtk", classname, 3) == 0)
435 /* -------------------------------------------------------------------- */
436 /* Check if the WRAP_SPECIAL flag is set for the class. */
438 int vtkWrap_IsSpecialType(
439 HierarchyInfo *hinfo, const char *classname)
441 HierarchyEntry *entry;
445 entry = vtkParseHierarchy_FindEntry(hinfo, classname);
446 if (entry && vtkParseHierarchy_GetProperty(entry, "WRAP_SPECIAL"))
453 /* fallback if no HierarchyInfo */
454 if (strncmp("vtk", classname, 3) == 0)
462 /* -------------------------------------------------------------------- */
463 /* Check if the class is derived from superclass */
465 int vtkWrap_IsTypeOf(
466 HierarchyInfo *hinfo, const char *classname, const char *superclass)
468 HierarchyEntry *entry;
470 if (strcmp(classname, superclass) == 0)
477 entry = vtkParseHierarchy_FindEntry(hinfo, classname);
478 if (entry && vtkParseHierarchy_IsTypeOf(hinfo, entry, superclass))
487 /* -------------------------------------------------------------------- */
488 /* Make a guess about whether a class is wrapped */
490 int vtkWrap_IsClassWrapped(
491 HierarchyInfo *hinfo, const char *classname)
495 HierarchyEntry *entry;
496 entry = vtkParseHierarchy_FindEntry(hinfo, classname);
500 if (!vtkParseHierarchy_GetProperty(entry, "WRAP_EXCLUDE") ||
501 vtkParseHierarchy_GetProperty(entry, "WRAP_SPECIAL"))
507 else if (strncmp("vtk", classname, 3) == 0)
515 /* -------------------------------------------------------------------- */
516 /* Check whether the destructor is public */
517 int vtkWrap_HasPublicDestructor(ClassInfo *data)
522 for (i = 0; i < data->NumberOfFunctions; i++)
524 func = data->Functions[i];
526 if (vtkWrap_IsDestructor(data, func) &&
527 func->Access != VTK_ACCESS_PUBLIC)
536 /* -------------------------------------------------------------------- */
537 /* Check whether the copy constructor is public */
538 int vtkWrap_HasPublicCopyConstructor(ClassInfo *data)
543 for (i = 0; i < data->NumberOfFunctions; i++)
545 func = data->Functions[i];
547 if (vtkWrap_IsConstructor(data, func) &&
548 func->NumberOfParameters == 1 &&
549 func->Parameters[0]->Class &&
550 strcmp(func->Parameters[0]->Class, data->Name) == 0 &&
551 func->Access != VTK_ACCESS_PUBLIC)
560 /* -------------------------------------------------------------------- */
561 /* Get the size for subclasses of vtkTuple */
562 int vtkWrap_GetTupleSize(ClassInfo *data, HierarchyInfo *hinfo)
564 HierarchyEntry *entry;
565 const char *classname = NULL;
569 entry = vtkParseHierarchy_FindEntry(hinfo, data->Name);
570 if (entry && vtkParseHierarchy_IsTypeOfTemplated(
571 hinfo, entry, data->Name, "vtkTuple", &classname))
573 /* attempt to get count from template parameter */
576 m = strlen(classname);
577 if (m > 2 && classname[m - 1] == '>' &&
578 isdigit(classname[m-2]) && (classname[m-3] == ' ' ||
579 classname[m-3] == ',' || classname[m-3] == '<'))
581 size = classname[m-2] - '0';
583 free((char *)classname);
590 /* -------------------------------------------------------------------- */
591 /* This sets the CountHint for vtkDataArray methods where the
592 * tuple size is equal to GetNumberOfComponents. */
593 void vtkWrap_FindCountHints(
594 ClassInfo *data, FileInfo *finfo, HierarchyInfo *hinfo)
598 const char *countMethod;
599 FunctionInfo *theFunc;
601 /* add hints for vtkInformation get methods */
602 if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkInformation"))
604 countMethod = "Length(temp0)";
606 for (i = 0; i < data->NumberOfFunctions; i++)
608 theFunc = data->Functions[i];
610 if (strcmp(theFunc->Name, "Get") == 0 &&
611 theFunc->NumberOfParameters >= 1 &&
612 theFunc->Parameters[0]->Type == VTK_PARSE_OBJECT_PTR &&
613 (strcmp(theFunc->Parameters[0]->Class,
614 "vtkInformationIntegerVectorKey") == 0 ||
615 strcmp(theFunc->Parameters[0]->Class,
616 "vtkInformationDoubleVectorKey") == 0))
618 if (theFunc->ReturnValue && theFunc->ReturnValue->Count == 0 &&
619 theFunc->NumberOfParameters == 1)
621 theFunc->ReturnValue->CountHint = countMethod;
627 /* add hints for array GetTuple methods */
628 if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkDataArray"))
630 countMethod = "GetNumberOfComponents()";
632 for (i = 0; i < data->NumberOfFunctions; i++)
634 theFunc = data->Functions[i];
636 if ((strcmp(theFunc->Name, "GetTuple") == 0 ||
637 strcmp(theFunc->Name, "GetTupleValue") == 0) &&
638 theFunc->ReturnValue && theFunc->ReturnValue->Count == 0 &&
639 theFunc->NumberOfParameters == 1 &&
640 theFunc->Parameters[0]->Type == VTK_PARSE_ID_TYPE)
642 theFunc->ReturnValue->CountHint = countMethod;
644 else if ((strcmp(theFunc->Name, "SetTuple") == 0 ||
645 strcmp(theFunc->Name, "SetTupleValue") == 0 ||
646 strcmp(theFunc->Name, "GetTuple") == 0 ||
647 strcmp(theFunc->Name, "GetTupleValue") == 0 ||
648 strcmp(theFunc->Name, "InsertTuple") == 0 ||
649 strcmp(theFunc->Name, "InsertTupleValue") == 0) &&
650 theFunc->NumberOfParameters == 2 &&
651 theFunc->Parameters[0]->Type == VTK_PARSE_ID_TYPE &&
652 theFunc->Parameters[1]->Count == 0)
654 theFunc->Parameters[1]->CountHint = countMethod;
656 else if ((strcmp(theFunc->Name, "InsertNextTuple") == 0 ||
657 strcmp(theFunc->Name, "InsertNextTupleValue") == 0) &&
658 theFunc->NumberOfParameters == 1 &&
659 theFunc->Parameters[0]->Count == 0)
661 theFunc->Parameters[0]->CountHint = countMethod;
666 /* add hints for interpolator Interpolate methods */
667 if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractImageInterpolator"))
669 countMethod = "GetNumberOfComponents()";
671 for (i = 0; i < data->NumberOfFunctions; i++)
673 theFunc = data->Functions[i];
675 if (strcmp(theFunc->Name, "Interpolate") == 0 &&
676 theFunc->NumberOfParameters == 2 &&
677 theFunc->Parameters[0]->Type == (VTK_PARSE_DOUBLE_PTR|VTK_PARSE_CONST) &&
678 theFunc->Parameters[0]->Count == 3 &&
679 theFunc->Parameters[1]->Type == VTK_PARSE_DOUBLE_PTR &&
680 theFunc->Parameters[1]->Count == 0)
682 theFunc->Parameters[1]->CountHint = countMethod;
687 for (i = 0; i < data->NumberOfFunctions; i++)
689 theFunc = data->Functions[i];
691 /* hints for constructors that take arrays */
692 if (vtkWrap_IsConstructor(data, theFunc) &&
693 theFunc->NumberOfParameters == 1 &&
694 vtkWrap_IsPointer(theFunc->Parameters[0]) &&
695 vtkWrap_IsNumeric(theFunc->Parameters[0]) &&
696 theFunc->Parameters[0]->Count == 0 &&
699 count = vtkWrap_GetTupleSize(data, hinfo);
703 sprintf(counttext, "%d", count);
704 theFunc->Parameters[0]->Count = count;
705 vtkParse_AddStringToArray(
706 &theFunc->Parameters[0]->Dimensions,
707 &theFunc->Parameters[0]->NumberOfDimensions,
708 vtkParse_CacheString(finfo->Strings, counttext, strlen(counttext)));
712 /* hints for operator[] index range */
713 if (theFunc->IsOperator && theFunc->Name &&
714 strcmp(theFunc->Name, "operator[]") == 0)
716 if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkTuple"))
718 theFunc->SizeHint = "GetSize()";
720 else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayCoordinates") ||
721 vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtents") ||
722 vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArraySort"))
724 theFunc->SizeHint = "GetDimensions()";
726 else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtentsList") ||
727 vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayWeights"))
729 theFunc->SizeHint = "GetCount()";
735 /* -------------------------------------------------------------------- */
736 /* This sets the NewInstance hint for generator methods. */
737 void vtkWrap_FindNewInstanceMethods(
738 ClassInfo *data, HierarchyInfo *hinfo)
741 FunctionInfo *theFunc;
743 for (i = 0; i < data->NumberOfFunctions; i++)
745 theFunc = data->Functions[i];
746 if (theFunc->Name && theFunc->ReturnValue &&
747 vtkWrap_IsVTKObject(theFunc->ReturnValue) &&
748 vtkWrap_IsVTKObjectBaseType(hinfo, theFunc->ReturnValue->Class))
750 if (strcmp(theFunc->Name, "NewInstance") == 0 ||
751 strcmp(theFunc->Name, "CreateInstance") == 0 ||
752 (strcmp(theFunc->Name, "CreateLookupTable") == 0 &&
753 strcmp(data->Name, "vtkColorSeries") == 0) ||
754 (strcmp(theFunc->Name, "CreateImageReader2") == 0 &&
755 strcmp(data->Name, "vtkImageReader2Factory") == 0) ||
756 (strcmp(theFunc->Name, "CreateDataArray") == 0 &&
757 strcmp(data->Name, "vtkDataArray") == 0) ||
758 (strcmp(theFunc->Name, "CreateArray") == 0 &&
759 strcmp(data->Name, "vtkAbstractArray") == 0) ||
760 (strcmp(theFunc->Name, "CreateArray") == 0 &&
761 strcmp(data->Name, "vtkArray") == 0) ||
762 (strcmp(theFunc->Name, "GetQueryInstance") == 0 &&
763 strcmp(data->Name, "vtkSQLDatabase") == 0) ||
764 (strcmp(theFunc->Name, "CreateFromURL") == 0 &&
765 strcmp(data->Name, "vtkSQLDatabase") == 0) ||
766 (strcmp(theFunc->Name, "MakeTransform") == 0 &&
767 vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractTransform")))
769 theFunc->ReturnValue->Type |= VTK_PARSE_NEWINSTANCE;
776 /* -------------------------------------------------------------------- */
777 /* Expand all typedef types that are used in function arguments */
778 void vtkWrap_ExpandTypedefs(
779 ClassInfo *data, FileInfo *finfo, HierarchyInfo *hinfo)
782 FunctionInfo *funcInfo;
783 const char *newclass;
785 n = data->NumberOfSuperClasses;
786 for (i = 0; i < n; i++)
788 newclass = vtkParseHierarchy_ExpandTypedefsInName(
789 hinfo, data->SuperClasses[i], NULL);
790 if (newclass != data->SuperClasses[i])
792 data->SuperClasses[i] =
793 vtkParse_CacheString(finfo->Strings, newclass, strlen(newclass));
794 free((char *)newclass);
798 n = data->NumberOfFunctions;
799 for (i = 0; i < n; i++)
801 funcInfo = data->Functions[i];
802 if (funcInfo->Access == VTK_ACCESS_PUBLIC)
804 for (j = 0; j < funcInfo->NumberOfParameters; j++)
806 vtkParseHierarchy_ExpandTypedefsInValue(
807 hinfo, funcInfo->Parameters[j], finfo->Strings, data->Name);
809 if (funcInfo->ReturnValue)
811 vtkParseHierarchy_ExpandTypedefsInValue(
812 hinfo, funcInfo->ReturnValue, finfo->Strings, data->Name);
819 /* -------------------------------------------------------------------- */
820 /* get the type name */
822 const char *vtkWrap_GetTypeName(ValueInfo *val)
824 unsigned int aType = val->Type;
825 const char *aClass = val->Class;
827 /* print the type itself */
828 switch (aType & VTK_PARSE_BASE_TYPE)
830 case VTK_PARSE_FLOAT: return "float";
831 case VTK_PARSE_DOUBLE: return "double";
832 case VTK_PARSE_INT: return "int";
833 case VTK_PARSE_SHORT: return "short";
834 case VTK_PARSE_LONG: return "long";
835 case VTK_PARSE_VOID: return "void ";
836 case VTK_PARSE_CHAR: return "char";
837 case VTK_PARSE_UNSIGNED_INT: return "unsigned int";
838 case VTK_PARSE_UNSIGNED_SHORT: return "unsigned short";
839 case VTK_PARSE_UNSIGNED_LONG: return "unsigned long";
840 case VTK_PARSE_UNSIGNED_CHAR: return "unsigned char";
841 case VTK_PARSE_ID_TYPE: return "vtkIdType";
842 case VTK_PARSE_LONG_LONG: return "long long";
843 case VTK_PARSE___INT64: return "__int64";
844 case VTK_PARSE_UNSIGNED_LONG_LONG: return "unsigned long long";
845 case VTK_PARSE_UNSIGNED___INT64: return "unsigned __int64";
846 case VTK_PARSE_SIGNED_CHAR: return "signed char";
847 case VTK_PARSE_BOOL: return "bool";
848 case VTK_PARSE_UNICODE_STRING: return "vtkUnicodeString";
849 case VTK_PARSE_SSIZE_T: return "ssize_t";
850 case VTK_PARSE_SIZE_T: return "size_t";
856 /* -------------------------------------------------------------------- */
857 /* variable declarations */
859 void vtkWrap_DeclareVariable(
860 FILE *fp, ValueInfo *val, const char *name, int i, int flags)
870 aType = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
872 /* do nothing for void */
873 if (aType == VTK_PARSE_VOID ||
874 (aType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_FUNCTION)
879 /* add a couple spaces */
882 /* for const * return types, prepend with const */
883 if ((flags & VTK_WRAP_RETURN) != 0)
885 if ((val->Type & VTK_PARSE_CONST) != 0 &&
886 (aType & VTK_PARSE_INDIRECT) != 0)
888 fprintf(fp,"const ");
891 /* do the same for "const char *" with initializer */
894 if ((val->Type & VTK_PARSE_CONST) != 0 &&
895 aType == VTK_PARSE_CHAR_PTR &&
897 strcmp(val->Value, "0") != 0 &&
898 strcmp(val->Value, "NULL") != 0)
900 fprintf(fp,"const ");
904 /* print the type name */
905 fprintf(fp, "%s ", vtkWrap_GetTypeName(val));
908 if ((flags & VTK_WRAP_RETURN) != 0)
910 /* ref and pointer return values are stored as pointers */
911 if ((aType & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER ||
912 (aType & VTK_PARSE_INDIRECT) == VTK_PARSE_REF)
919 /* objects refs and pointers are always handled via pointers,
920 * other refs are passed by value */
921 if (aType == VTK_PARSE_CHAR_PTR ||
922 aType == VTK_PARSE_VOID_PTR ||
923 aType == VTK_PARSE_OBJECT_PTR ||
924 aType == VTK_PARSE_OBJECT_REF ||
925 aType == VTK_PARSE_OBJECT ||
926 vtkWrap_IsQtObject(val))
930 /* arrays of unknown size are handled via pointers */
931 else if (val->CountHint || vtkWrap_IsPODPointer(val))
937 /* the variable name */
940 fprintf(fp,"%s%i", name, i);
944 fprintf(fp,"%s", name);
947 if ((flags & VTK_WRAP_ARG) != 0)
949 /* print the array decorators */
950 if (((aType & VTK_PARSE_POINTER_MASK) != 0) &&
951 aType != VTK_PARSE_CHAR_PTR &&
952 aType != VTK_PARSE_VOID_PTR &&
953 aType != VTK_PARSE_OBJECT_PTR &&
954 !vtkWrap_IsQtObject(val) &&
955 val->CountHint == NULL &&
956 !vtkWrap_IsPODPointer(val))
958 if (val->NumberOfDimensions == 1 && val->Count > 0)
960 fprintf(fp, "[%d]", val->Count);
964 for (j = 0; j < val->NumberOfDimensions; j++)
966 fprintf(fp, "[%s]", val->Dimensions[j]);
971 /* add a default value */
974 fprintf(fp, " = %s", val->Value);
976 else if (aType == VTK_PARSE_CHAR_PTR ||
977 aType == VTK_PARSE_VOID_PTR ||
978 aType == VTK_PARSE_OBJECT_PTR ||
979 aType == VTK_PARSE_OBJECT_REF ||
980 aType == VTK_PARSE_OBJECT ||
981 vtkWrap_IsQtObject(val))
983 fprintf(fp, " = NULL");
985 else if (val->CountHint || vtkWrap_IsPODPointer(val))
987 fprintf(fp, " = NULL");
989 else if (aType == VTK_PARSE_BOOL)
991 fprintf(fp, " = false");
995 /* finish off with a semicolon */
996 if ((flags & VTK_WRAP_NOSEMI) == 0)
1002 void vtkWrap_DeclareVariableSize(
1003 FILE *fp, ValueInfo *val, const char *name, int i)
1011 sprintf(idx, "%d", i);
1014 if (val->NumberOfDimensions > 1)
1017 " static int %s%s[%d] = ",
1018 name, idx, val->NumberOfDimensions);
1020 for (j = 0; j < val->NumberOfDimensions; j++)
1022 fprintf(fp, "%c %s", ((j == 0) ? '{' : ','), val->Dimensions[j]);
1025 fprintf(fp, " };\n");
1027 else if (val->Count != 0 || val->CountHint || vtkWrap_IsPODPointer(val))
1030 " %sint %s%s = %d;\n",
1031 (val->Count == 0 ? "" : "const "), name, idx,
1032 (val->Count == 0 ? 0 : val->Count));
1034 else if (val->NumberOfDimensions == 1)
1037 " const int %s%s = %s;\n",
1038 name, idx, val->Dimensions[0]);