]> SALOME platform Git repositories - modules/paravis.git/blob - src/ParaView/vtkWrap.c
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/paravis.git] / src / ParaView / vtkWrap.c
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    vtkWrap.c
5
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
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.
13
14 =========================================================================*/
15
16 #include "vtkWrap.h"
17 #include "vtkParseInternal.h"
18 #include "vtkParseExtras.h"
19 #include <stdlib.h>
20 #include <string.h>
21 #include <ctype.h>
22
23 /* -------------------------------------------------------------------- */
24 /* Common types. */
25
26 int vtkWrap_IsVoid(ValueInfo *val)
27 {
28   if (val == 0)
29     {
30     return 1;
31     }
32
33   return ((val->Type & VTK_PARSE_UNQUALIFIED_TYPE) == VTK_PARSE_VOID);
34 }
35
36 int vtkWrap_IsVoidFunction(ValueInfo *val)
37 {
38   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
39   return (t == VTK_PARSE_FUNCTION);
40 }
41
42 int vtkWrap_IsVoidPointer(ValueInfo *val)
43 {
44   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
45   return (t == VTK_PARSE_VOID && vtkWrap_IsPointer(val));
46 }
47
48 int vtkWrap_IsCharPointer(ValueInfo *val)
49 {
50   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
51   return (t == VTK_PARSE_CHAR && vtkWrap_IsPointer(val));
52 }
53
54 int vtkWrap_IsVTKObject(ValueInfo *val)
55 {
56   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
57   return (t == VTK_PARSE_OBJECT_PTR &&
58           val->Class[0] == 'v' && strncmp(val->Class, "vtk", 3) == 0);
59 }
60
61 int vtkWrap_IsSpecialObject(ValueInfo *val)
62 {
63   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
64   return ((t == VTK_PARSE_OBJECT ||
65            t == VTK_PARSE_OBJECT_REF) &&
66           val->Class[0] == 'v' && strncmp(val->Class, "vtk", 3) == 0);
67 }
68
69 int vtkWrap_IsQtObject(ValueInfo *val)
70 {
71   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
72   if (t == VTK_PARSE_QOBJECT &&
73       val->Class[0] == 'Q' && isupper(val->Class[1]))
74     {
75     return 1;
76     }
77   return 0;
78 }
79
80 int vtkWrap_IsQtEnum(ValueInfo *val)
81 {
82   unsigned int t = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
83   if ((t == VTK_PARSE_QOBJECT || t == VTK_PARSE_QOBJECT_REF) &&
84       val->Class[0] == 'Q' && strncmp("Qt::", val->Class, 4) == 0)
85     {
86     return 1;
87     }
88   return 0;
89 }
90
91
92 /* -------------------------------------------------------------------- */
93 /* The base types, all are mutually exclusive. */
94
95 int vtkWrap_IsObject(ValueInfo *val)
96 {
97   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
98   return (t == VTK_PARSE_OBJECT ||
99           t == VTK_PARSE_QOBJECT);
100 }
101
102 int vtkWrap_IsFunction(ValueInfo *val)
103 {
104   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
105   return (t == VTK_PARSE_FUNCTION);
106 }
107
108 int vtkWrap_IsStream(ValueInfo *val)
109 {
110   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
111   return (t == VTK_PARSE_ISTREAM ||
112           t == VTK_PARSE_OSTREAM);
113 }
114
115 int vtkWrap_IsNumeric(ValueInfo *val)
116 {
117   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
118
119   t = (t & ~VTK_PARSE_UNSIGNED);
120   switch (t)
121     {
122     case VTK_PARSE_FLOAT:
123     case VTK_PARSE_DOUBLE:
124     case VTK_PARSE_CHAR:
125     case VTK_PARSE_SHORT:
126     case VTK_PARSE_INT:
127     case VTK_PARSE_LONG:
128     case VTK_PARSE_ID_TYPE:
129     case VTK_PARSE_LONG_LONG:
130     case VTK_PARSE___INT64:
131     case VTK_PARSE_SIGNED_CHAR:
132     case VTK_PARSE_SSIZE_T:
133     case VTK_PARSE_BOOL:
134       return 1;
135     }
136
137   return 0;
138 }
139
140 int vtkWrap_IsString(ValueInfo *val)
141 {
142   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
143   return (t == VTK_PARSE_STRING ||
144           t == VTK_PARSE_UNICODE_STRING);
145 }
146
147 /* -------------------------------------------------------------------- */
148 /* Subcategories */
149
150 int vtkWrap_IsBool(ValueInfo *val)
151 {
152   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
153   return (t == VTK_PARSE_BOOL);
154 }
155
156 int vtkWrap_IsChar(ValueInfo *val)
157 {
158   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
159   return (t == VTK_PARSE_CHAR);
160 }
161
162 int vtkWrap_IsInteger(ValueInfo *val)
163 {
164   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
165
166   if (t != VTK_PARSE_UNSIGNED_CHAR)
167     {
168     t = (t & ~VTK_PARSE_UNSIGNED);
169     }
170   switch (t)
171     {
172     case VTK_PARSE_SHORT:
173     case VTK_PARSE_INT:
174     case VTK_PARSE_LONG:
175     case VTK_PARSE_ID_TYPE:
176     case VTK_PARSE_LONG_LONG:
177     case VTK_PARSE___INT64:
178     case VTK_PARSE_UNSIGNED_CHAR:
179     case VTK_PARSE_SIGNED_CHAR:
180     case VTK_PARSE_SSIZE_T:
181       return 1;
182     }
183
184   return 0;
185 }
186
187 int vtkWrap_IsRealNumber(ValueInfo *val)
188 {
189   unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE);
190   return (t == VTK_PARSE_FLOAT || t == VTK_PARSE_DOUBLE);
191 }
192
193 /* -------------------------------------------------------------------- */
194 /* These are mutually exclusive, as well. */
195
196 int vtkWrap_IsScalar(ValueInfo *val)
197 {
198   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
199   return (i == 0);
200 }
201
202 int vtkWrap_IsPointer(ValueInfo *val)
203 {
204   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
205   return (i == VTK_PARSE_POINTER && val->Count == 0 &&
206           val->CountHint == 0 && val->NumberOfDimensions <= 1);
207 }
208
209 int vtkWrap_IsArray(ValueInfo *val)
210 {
211   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
212   return (i == VTK_PARSE_POINTER && val->NumberOfDimensions <= 1 &&
213           (val->Count != 0 || val->CountHint != 0));
214 }
215
216 int vtkWrap_IsNArray(ValueInfo *val)
217 {
218   int j = 0;
219   unsigned int i = (val->Type & VTK_PARSE_POINTER_MASK);
220   if (i != VTK_PARSE_ARRAY || val->NumberOfDimensions <= 1)
221     {
222     return 0;
223     }
224   for (j = 0; j < val->NumberOfDimensions; j++)
225     {
226     if (val->Dimensions[j] == NULL || val->Dimensions[j][0] == '\0')
227       {
228       return 0;
229       }
230     }
231   return 1;
232 }
233
234
235 /* -------------------------------------------------------------------- */
236 /* Other type properties, not mutually exclusive. */
237
238 int vtkWrap_IsNonConstRef(ValueInfo *val)
239 {
240   return ((val->Type & VTK_PARSE_REF) != 0 &&
241           (val->Type & VTK_PARSE_CONST) == 0);
242 }
243
244 int vtkWrap_IsConstRef(ValueInfo *val)
245 {
246   return ((val->Type & VTK_PARSE_REF) != 0 &&
247           (val->Type & VTK_PARSE_CONST) != 0);
248 }
249
250 int vtkWrap_IsRef(ValueInfo *val)
251 {
252   return ((val->Type & VTK_PARSE_REF) != 0);
253 }
254
255 int vtkWrap_IsConst(ValueInfo *val)
256 {
257   return ((val->Type & VTK_PARSE_CONST) != 0);
258 }
259
260 /* -------------------------------------------------------------------- */
261 /* Hints */
262
263 int vtkWrap_IsNewInstance(ValueInfo *val)
264 {
265   return ((val->Type & VTK_PARSE_NEWINSTANCE) != 0);
266 }
267
268 /* -------------------------------------------------------------------- */
269 /* Constructor/Destructor checks */
270
271 int vtkWrap_IsConstructor(ClassInfo *c, FunctionInfo *f)
272
273 {
274   size_t i, m;
275   const char *cp = c->Name;
276
277   if (cp && f->Name && !vtkWrap_IsDestructor(c, f))
278     {
279     /* remove namespaces and template parameters from the name */
280     m = vtkParse_UnscopedNameLength(cp);
281     while (cp[m] == ':' && cp[m+1] == ':')
282       {
283       cp += m + 2;
284       m = vtkParse_UnscopedNameLength(cp);
285       }
286     for (i = 0; i < m; i++)
287       {
288       if (cp[i] == '<')
289         {
290         break;
291         }
292       }
293
294     return (i == strlen(f->Name) && strncmp(cp, f->Name, i) == 0);
295     }
296
297   return 0;
298 }
299
300 int vtkWrap_IsDestructor(ClassInfo *c, FunctionInfo *f)
301 {
302   size_t i;
303   const char *cp;
304
305   if (c->Name && f->Name)
306     {
307     cp = f->Signature;
308     for (i = 0; cp[i] != '\0' && cp[i] != '('; i++)
309       {
310       if (cp[i] == '~')
311         {
312         return 1;
313         }
314       }
315     }
316
317   return 0;
318 }
319
320 int vtkWrap_IsSetVectorMethod(FunctionInfo *f)
321 {
322   if (f->Macro && strncmp(f->Macro, "vtkSetVector", 12) == 0)
323     {
324     return 1;
325     }
326
327   return 0;
328 }
329
330 int vtkWrap_IsGetVectorMethod(FunctionInfo *f)
331 {
332   if (f->Macro && strncmp(f->Macro, "vtkGetVector", 12) == 0)
333     {
334     return 1;
335     }
336
337   return 0;
338 }
339
340 /* -------------------------------------------------------------------- */
341 /* Argument counting */
342
343 int vtkWrap_CountWrappedArgs(FunctionInfo *f)
344 {
345   int totalArgs = f->NumberOfArguments;
346
347   if (totalArgs > 0 &&
348       (f->Arguments[0]->Type & VTK_PARSE_BASE_TYPE)
349        == VTK_PARSE_FUNCTION)
350     {
351     totalArgs = 1;
352     }
353   else if (totalArgs == 1 &&
354            (f->Arguments[0]->Type & VTK_PARSE_UNQUALIFIED_TYPE)
355             == VTK_PARSE_VOID)
356     {
357     totalArgs = 0;
358     }
359
360   return totalArgs;
361 }
362
363 int vtkWrap_CountRequiredArgs(FunctionInfo *f)
364 {
365   int requiredArgs = 0;
366   int totalArgs;
367   int i;
368
369   totalArgs = vtkWrap_CountWrappedArgs(f);
370
371   for (i = 0; i < totalArgs; i++)
372     {
373     if (f->Arguments[i]->Value == NULL ||
374         vtkWrap_IsArray(f->Arguments[i]) ||
375         vtkWrap_IsNArray(f->Arguments[i]))
376       {
377       requiredArgs = i+1;
378       }
379     }
380
381   return requiredArgs;
382 }
383
384 /* -------------------------------------------------------------------- */
385 /* Check whether the class is derived from vtkObjectBase. */
386
387 int vtkWrap_IsVTKObjectBaseType(
388   HierarchyInfo *hinfo, const char *classname)
389 {
390   HierarchyEntry *entry;
391
392   if (hinfo)
393     {
394     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
395     if (entry)
396       {
397       if (vtkParseHierarchy_IsTypeOf(hinfo, entry, "vtkObjectBase"))
398         {
399         return 1;
400         }
401       return 0;
402       }
403     }
404
405   /* fallback if no HierarchyInfo */
406   if (strncmp("vtk", classname, 3) == 0)
407     {
408     return 1;
409     }
410
411   return 0;
412 }
413
414 /* -------------------------------------------------------------------- */
415 /* Check if the WRAP_SPECIAL flag is set for the class. */
416
417 int vtkWrap_IsSpecialType(
418   HierarchyInfo *hinfo, const char *classname)
419 {
420   HierarchyEntry *entry;
421
422   if (hinfo)
423     {
424     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
425     if (entry && vtkParseHierarchy_GetProperty(entry, "WRAP_SPECIAL"))
426       {
427       return 1;
428       }
429     return 0;
430     }
431
432   /* fallback if no HierarchyInfo */
433   if (strncmp("vtk", classname, 3) == 0)
434     {
435     return -1;
436     }
437
438   return 0;
439 }
440
441 /* -------------------------------------------------------------------- */
442 /* Check if the class is derived from superclass */
443
444 int vtkWrap_IsTypeOf(
445   HierarchyInfo *hinfo, const char *classname, const char *superclass)
446 {
447   HierarchyEntry *entry;
448
449   if (strcmp(classname, superclass) == 0)
450     {
451     return 1;
452     }
453
454   if (hinfo)
455     {
456     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
457     if (entry && vtkParseHierarchy_IsTypeOf(hinfo, entry, superclass))
458       {
459       return 1;
460       }
461     }
462
463   return 0;
464 }
465
466 /* -------------------------------------------------------------------- */
467 /* Make a guess about whether a class is wrapped */
468
469 int vtkWrap_IsClassWrapped(
470   HierarchyInfo *hinfo, const char *classname)
471 {
472   if (hinfo)
473     {
474     HierarchyEntry *entry;
475     entry = vtkParseHierarchy_FindEntry(hinfo, classname);
476
477     if (entry)
478       {
479       if (!vtkParseHierarchy_GetProperty(entry, "WRAP_EXCLUDE") ||
480           vtkParseHierarchy_GetProperty(entry, "WRAP_SPECIAL"))
481         {
482         return 1;
483         }
484       }
485     }
486   else if (strncmp("vtk", classname, 3) == 0)
487     {
488     return 1;
489     }
490
491   return 0;
492 }
493
494 /* -------------------------------------------------------------------- */
495 /* Check whether the destructor is public */
496 int vtkWrap_HasPublicDestructor(ClassInfo *data)
497 {
498   FunctionInfo *func;
499   int i;
500
501   for (i = 0; i < data->NumberOfFunctions; i++)
502     {
503     func = data->Functions[i];
504
505     if (vtkWrap_IsDestructor(data, func) &&
506         func->Access != VTK_ACCESS_PUBLIC)
507       {
508       return 0;
509       }
510     }
511
512   return 1;
513 }
514
515 /* -------------------------------------------------------------------- */
516 /* Check whether the copy constructor is public */
517 int vtkWrap_HasPublicCopyConstructor(ClassInfo *data)
518 {
519   FunctionInfo *func;
520   int i;
521
522   for (i = 0; i < data->NumberOfFunctions; i++)
523     {
524     func = data->Functions[i];
525
526     if (vtkWrap_IsConstructor(data, func) &&
527         func->NumberOfArguments == 1 &&
528         func->Arguments[0]->Class &&
529         strcmp(func->Arguments[0]->Class, data->Name) == 0 &&
530         func->Access != VTK_ACCESS_PUBLIC)
531       {
532       return 0;
533       }
534     }
535
536   return 1;
537 }
538
539 /* -------------------------------------------------------------------- */
540 /* This sets the CountHint for vtkDataArray methods where the
541  * tuple size is equal to GetNumberOfComponents. */
542 void vtkWrap_FindCountHints(
543   ClassInfo *data, HierarchyInfo *hinfo)
544 {
545   int i;
546   const char *countMethod;
547   const char *classname;
548   FunctionInfo *theFunc;
549   HierarchyEntry *entry;
550   size_t m;
551   char digit;
552
553   /* add hints for array GetTuple methods */
554   if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkDataArray"))
555     {
556     countMethod = "GetNumberOfComponents()";
557
558     for (i = 0; i < data->NumberOfFunctions; i++)
559       {
560       theFunc = data->Functions[i];
561
562       if ((strcmp(theFunc->Name, "GetTuple") == 0 ||
563            strcmp(theFunc->Name, "GetTupleValue") == 0) &&
564           theFunc->ReturnValue && theFunc->ReturnValue->Count == 0 &&
565           theFunc->NumberOfArguments == 1 &&
566           theFunc->Arguments[0]->Type == VTK_PARSE_ID_TYPE)
567         {
568         theFunc->ReturnValue->CountHint = countMethod;
569         }
570       else if ((strcmp(theFunc->Name, "SetTuple") == 0 ||
571                 strcmp(theFunc->Name, "SetTupleValue") == 0 ||
572                 strcmp(theFunc->Name, "GetTuple") == 0 ||
573                 strcmp(theFunc->Name, "GetTupleValue") == 0 ||
574                 strcmp(theFunc->Name, "InsertTuple") == 0 ||
575                 strcmp(theFunc->Name, "InsertTupleValue") == 0) &&
576                theFunc->NumberOfArguments == 2 &&
577                theFunc->Arguments[0]->Type == VTK_PARSE_ID_TYPE &&
578                theFunc->Arguments[1]->Count == 0)
579         {
580         theFunc->Arguments[1]->CountHint = countMethod;
581         }
582       else if ((strcmp(theFunc->Name, "InsertNextTuple") == 0 ||
583                 strcmp(theFunc->Name, "InsertNextTupleValue") == 0) &&
584                theFunc->NumberOfArguments == 1 &&
585                theFunc->Arguments[0]->Count == 0)
586         {
587         theFunc->Arguments[0]->CountHint = countMethod;
588         }
589       }
590     }
591
592   /* add hints for interpolator Interpolate methods */
593   if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractImageInterpolator"))
594     {
595     countMethod = "GetNumberOfComponents()";
596
597     for (i = 0; i < data->NumberOfFunctions; i++)
598       {
599       theFunc = data->Functions[i];
600
601       if (strcmp(theFunc->Name, "Interpolate") == 0 &&
602            theFunc->NumberOfArguments == 2 &&
603            theFunc->Arguments[0]->Type == (VTK_PARSE_DOUBLE_PTR|VTK_PARSE_CONST) &&
604            theFunc->Arguments[0]->Count == 3 &&
605            theFunc->Arguments[1]->Type == VTK_PARSE_DOUBLE_PTR &&
606            theFunc->Arguments[1]->Count == 0)
607         {
608         theFunc->Arguments[1]->CountHint = countMethod;
609         }
610       }
611     }
612
613   for (i = 0; i < data->NumberOfFunctions; i++)
614     {
615     theFunc = data->Functions[i];
616
617     /* hints for constructors that take arrays */
618     if (vtkWrap_IsConstructor(data, theFunc) &&
619         theFunc->NumberOfArguments == 1 &&
620         vtkWrap_IsPointer(theFunc->Arguments[0]) &&
621         vtkWrap_IsNumeric(theFunc->Arguments[0]) &&
622         theFunc->Arguments[0]->Count == 0 &&
623         hinfo)
624       {
625       entry = vtkParseHierarchy_FindEntry(hinfo, data->Name);
626       if (entry && vtkParseHierarchy_IsTypeOfTemplated(
627             hinfo, entry, data->Name, "vtkTuple", &classname))
628         {
629         /* attempt to get count from template parameter */
630         if (classname)
631           {
632           m = strlen(classname);
633           if (m > 2 && classname[m - 1] == '>' &&
634               isdigit(classname[m-2]) && (classname[m-3] == ' ' ||
635               classname[m-3] == ',' || classname[m-3] == '<'))
636             {
637             digit = classname[m-2];
638             theFunc->Arguments[0]->Count = digit - '0';
639             vtkParse_AddStringToArray(
640               &theFunc->Arguments[0]->Dimensions,
641               &theFunc->Arguments[0]->NumberOfDimensions,
642               vtkParse_DuplicateString(&digit, 1));
643             }
644           free((char *)classname);
645           }
646         }
647       }
648
649     /* hints for operator[] index range */
650     if (theFunc->IsOperator && theFunc->Name &&
651         strcmp(theFunc->Name, "operator[]") == 0)
652       {
653       if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkTuple"))
654         {
655         theFunc->SizeHint = "GetSize()";
656         }
657       else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayCoordinates") ||
658                vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtents") ||
659                vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArraySort"))
660         {
661         theFunc->SizeHint = "GetDimensions()";
662         }
663       else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtentsList") ||
664                vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayWeights"))
665         {
666         theFunc->SizeHint = "GetCount()";
667         }
668       }
669     }
670 }
671
672 /* -------------------------------------------------------------------- */
673 /* This sets the NewInstance hint for generator methods. */
674 void vtkWrap_FindNewInstanceMethods(
675   ClassInfo *data, HierarchyInfo *hinfo)
676 {
677   int i;
678   FunctionInfo *theFunc;
679
680   for (i = 0; i < data->NumberOfFunctions; i++)
681     {
682     theFunc = data->Functions[i];
683     if (theFunc->Name && theFunc->ReturnValue &&
684         vtkWrap_IsVTKObject(theFunc->ReturnValue) &&
685         vtkWrap_IsVTKObjectBaseType(hinfo, theFunc->ReturnValue->Class))
686       {
687       if (strcmp(theFunc->Name, "NewInstance") == 0 ||
688           strcmp(theFunc->Name, "CreateInstance") == 0 ||
689           (strcmp(theFunc->Name, "CreateImageReader2") == 0 &&
690            strcmp(data->Name, "vtkImageReader2Factory") == 0) ||
691           (strcmp(theFunc->Name, "CreateDataArray") == 0 &&
692            strcmp(data->Name, "vtkDataArray") == 0) ||
693           (strcmp(theFunc->Name, "CreateArray") == 0 &&
694            strcmp(data->Name, "vtkAbstractArray") == 0) ||
695           (strcmp(theFunc->Name, "CreateArray") == 0 &&
696            strcmp(data->Name, "vtkArray") == 0) ||
697           (strcmp(theFunc->Name, "GetQueryInstance") == 0 &&
698            strcmp(data->Name, "vtkSQLDatabase") == 0) ||
699           (strcmp(theFunc->Name, "CreateFromURL") == 0 &&
700            strcmp(data->Name, "vtkSQLDatabase") == 0) ||
701           (strcmp(theFunc->Name, "MakeTransform") == 0 &&
702            vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractTransform")))
703         {
704         theFunc->ReturnValue->Type |= VTK_PARSE_NEWINSTANCE;
705         }
706       }
707     }
708 }
709
710
711 /* -------------------------------------------------------------------- */
712 /* Expand all typedef types that are used in function arguments */
713 void vtkWrap_ExpandTypedefs(ClassInfo *data, HierarchyInfo *hinfo)
714 {
715   int i, j, n;
716   FunctionInfo *funcInfo;
717   const char *newclass;
718
719   n = data->NumberOfSuperClasses;
720   for (i = 0; i < n; i++)
721     {
722     newclass = vtkParseHierarchy_ExpandTypedefsInName(
723       hinfo, data->SuperClasses[i], NULL);
724     if (newclass != data->SuperClasses[i])
725       {
726       data->SuperClasses[i] =
727         vtkParse_DuplicateString(newclass, strlen(newclass));
728       free((char *)newclass);
729       }
730     }
731
732   n = data->NumberOfFunctions;
733   for (i = 0; i < n; i++)
734     {
735     funcInfo = data->Functions[i];
736     if (funcInfo->Access == VTK_ACCESS_PUBLIC)
737       {
738       for (j = 0; j < funcInfo->NumberOfArguments; j++)
739         {
740         vtkParseHierarchy_ExpandTypedefsInValue(
741           hinfo, funcInfo->Arguments[j], data->Name);
742         }
743       if (funcInfo->ReturnValue)
744         {
745         vtkParseHierarchy_ExpandTypedefsInValue(
746           hinfo, funcInfo->ReturnValue, data->Name);
747         }
748       }
749     }
750 }
751
752
753 /* -------------------------------------------------------------------- */
754 /* get the type name */
755
756 const char *vtkWrap_GetTypeName(ValueInfo *val)
757 {
758   unsigned int aType = val->Type;
759   const char *aClass = val->Class;
760
761   /* print the type itself */
762   switch (aType & VTK_PARSE_BASE_TYPE)
763     {
764     case VTK_PARSE_FLOAT:          return "float";
765     case VTK_PARSE_DOUBLE:         return "double";
766     case VTK_PARSE_INT:            return "int";
767     case VTK_PARSE_SHORT:          return "short";
768     case VTK_PARSE_LONG:           return "long";
769     case VTK_PARSE_VOID:           return "void ";
770     case VTK_PARSE_CHAR:           return "char";
771     case VTK_PARSE_UNSIGNED_INT:   return "unsigned int";
772     case VTK_PARSE_UNSIGNED_SHORT: return "unsigned short";
773     case VTK_PARSE_UNSIGNED_LONG:  return "unsigned long";
774     case VTK_PARSE_UNSIGNED_CHAR:  return "unsigned char";
775     case VTK_PARSE_ID_TYPE:        return "vtkIdType";
776     case VTK_PARSE_LONG_LONG:      return "long long";
777     case VTK_PARSE___INT64:        return "__int64";
778     case VTK_PARSE_UNSIGNED_LONG_LONG: return "unsigned long long";
779     case VTK_PARSE_UNSIGNED___INT64:   return "unsigned __int64";
780     case VTK_PARSE_SIGNED_CHAR:    return "signed char";
781     case VTK_PARSE_BOOL:           return "bool";
782     case VTK_PARSE_UNICODE_STRING: return "vtkUnicodeString";
783     case VTK_PARSE_SSIZE_T:        return "ssize_t";
784     case VTK_PARSE_SIZE_T:         return "size_t";
785     }
786
787   return aClass;
788 }
789
790 /* -------------------------------------------------------------------- */
791 /* variable declarations */
792
793 void vtkWrap_DeclareVariable(
794   FILE *fp, ValueInfo *val, const char *name, int i, int flags)
795 {
796   unsigned int aType;
797   int j;
798
799   if (val == NULL)
800     {
801     return;
802     }
803
804   aType = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
805
806   /* do nothing for void */
807   if (aType == VTK_PARSE_VOID ||
808       (aType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_FUNCTION)
809     {
810     return;
811     }
812
813   /* add a couple spaces */
814   fprintf(fp,"  ");
815
816   /* for const * return types, prepend with const */
817   if ((flags & VTK_WRAP_RETURN) != 0)
818     {
819     if ((val->Type & VTK_PARSE_CONST) != 0 &&
820         (aType & VTK_PARSE_INDIRECT) != 0)
821       {
822       fprintf(fp,"const ");
823       }
824     }
825   /* do the same for "const char *" with initializer */
826   else
827     {
828     if ((val->Type & VTK_PARSE_CONST) != 0 &&
829         aType == VTK_PARSE_CHAR_PTR &&
830         val->Value &&
831         strcmp(val->Value, "0") != 0 &&
832         strcmp(val->Value, "NULL") != 0)
833       {
834       fprintf(fp,"const ");
835       }
836     }
837
838   /* print the type name */
839   fprintf(fp, "%s ", vtkWrap_GetTypeName(val));
840
841   /* indirection */
842   if ((flags & VTK_WRAP_RETURN) != 0)
843     {
844     /* ref and pointer return values are stored as pointers */
845     if ((aType & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER ||
846         (aType & VTK_PARSE_INDIRECT) == VTK_PARSE_REF)
847       {
848       fprintf(fp, "*");
849       }
850     }
851   else
852     {
853     /* objects refs and pointers are always handled via pointers,
854      * other refs are passed by value */
855     if (aType == VTK_PARSE_CHAR_PTR ||
856         aType == VTK_PARSE_VOID_PTR ||
857         aType == VTK_PARSE_OBJECT_PTR ||
858         aType == VTK_PARSE_OBJECT_REF ||
859         aType == VTK_PARSE_OBJECT ||
860         vtkWrap_IsQtObject(val))
861       {
862       fprintf(fp, "*");
863       }
864     /* arrays of unknown size are handled via pointers */
865     else if (val->CountHint)
866       {
867       fprintf(fp, "*");
868       }
869     }
870
871   /* the variable name */
872   if (i >= 0)
873     {
874     fprintf(fp,"%s%i", name, i);
875     }
876   else
877     {
878     fprintf(fp,"%s", name);
879     }
880
881   if ((flags & VTK_WRAP_ARG) != 0)
882     {
883     /* print the array decorators */
884     if (((aType & VTK_PARSE_POINTER_MASK) != 0) &&
885         aType != VTK_PARSE_CHAR_PTR &&
886         aType != VTK_PARSE_VOID_PTR &&
887         aType != VTK_PARSE_OBJECT_PTR &&
888         !vtkWrap_IsQtObject(val) &&
889         val->CountHint == NULL)
890       {
891       if (val->NumberOfDimensions == 1 && val->Count > 0)
892         {
893         fprintf(fp, "[%d]", val->Count);
894         }
895       else
896         {
897         for (j = 0; j < val->NumberOfDimensions; j++)
898           {
899           fprintf(fp, "[%s]", val->Dimensions[j]);
900           }
901         }
902       }
903
904     /* add a default value */
905     else if (val->Value)
906       {
907       fprintf(fp, " = %s", val->Value);
908       }
909     else if (aType == VTK_PARSE_CHAR_PTR ||
910              aType == VTK_PARSE_VOID_PTR ||
911              aType == VTK_PARSE_OBJECT_PTR ||
912              aType == VTK_PARSE_OBJECT_REF ||
913              aType == VTK_PARSE_OBJECT ||
914              vtkWrap_IsQtObject(val))
915       {
916       fprintf(fp, " = NULL");
917       }
918     else if (val->CountHint)
919       {
920       fprintf(fp, " = NULL");
921       }
922     else if (aType == VTK_PARSE_BOOL)
923       {
924       fprintf(fp, " = false");
925       }
926     }
927
928   /* finish off with a semicolon */
929   if ((flags & VTK_WRAP_NOSEMI) == 0)
930     {
931     fprintf(fp, ";\n");
932     }
933 }
934
935 void vtkWrap_DeclareVariableSize(
936   FILE *fp, ValueInfo *val, const char *name, int i)
937 {
938   char idx[32];
939   int j;
940
941   idx[0] = '\0';
942   if (i >= 0)
943     {
944     sprintf(idx, "%d", i);
945     }
946
947   if (val->NumberOfDimensions > 1)
948     {
949     fprintf(fp,
950             "  static int %s%s[%d] = ",
951             name, idx, val->NumberOfDimensions);
952
953     for (j = 0; j < val->NumberOfDimensions; j++)
954       {
955       fprintf(fp, "%c %s", ((j == 0) ? '{' : ','), val->Dimensions[j]);
956       }
957
958     fprintf(fp, " };\n");
959     }
960   else if (val->Count != 0 || val->CountHint)
961     {
962     fprintf(fp,
963             "  %sint %s%s = %d;\n",
964             (val->CountHint ? "" : "const "), name, idx,
965             (val->CountHint ? 0 : val->Count));
966     }
967   else if (val->NumberOfDimensions == 1)
968     {
969     fprintf(fp,
970             "  const int %s%s = %s;\n",
971             name, idx, val->Dimensions[0]);
972     }
973 }