]> SALOME platform Git repositories - modules/paravis.git/blob - src/VTKWrapping/ParaView/vtkParseData.c
Salome HOME
Merge branch 'origin/abn/openfile_fix'
[modules/paravis.git] / src / VTKWrapping / ParaView / vtkParseData.c
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    vtkParseData.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   Copyright (c) 2010 David Gobbi.
17
18   Contributed to the VisualizationToolkit by the author in May 2010
19   under the terms of the Visualization Toolkit 2008 copyright.
20 -------------------------------------------------------------------------*/
21
22 #include "vtkParseData.h"
23 #include <stdlib.h>
24 #include <string.h>
25
26 /* Initialize the FileInfo struct */
27 void vtkParse_InitFile(FileInfo *file_info)
28 {
29   /* file info */
30   file_info->FileName = NULL;
31   file_info->NameComment = NULL;
32   file_info->Description = NULL;
33   file_info->Caveats = NULL;
34   file_info->SeeAlso = NULL;
35
36   file_info->NumberOfIncludes = 0;
37   file_info->Includes = NULL;
38   file_info->MainClass = NULL;
39   file_info->Contents = NULL;
40
41   file_info->Strings = NULL;
42 }
43
44 /* Free the FileInfo struct */
45 void vtkParse_FreeFile(FileInfo *file_info)
46 {
47   int i, n;
48
49   n = file_info->NumberOfIncludes;
50   for (i = 0; i < n; i++)
51     {
52     vtkParse_FreeFile(file_info->Includes[i]);
53     free(file_info->Includes[i]);
54     }
55   if (file_info->Includes)
56     {
57     free(file_info->Includes);
58     }
59
60   vtkParse_FreeNamespace(file_info->Contents);
61   file_info->Contents = NULL;
62 }
63
64 /* Initialize a TemplateInfo struct */
65 void vtkParse_InitTemplate(TemplateInfo *info)
66 {
67   info->NumberOfParameters = 0;
68   info->Parameters = NULL;
69 }
70
71 /* Copy a TemplateInfo struct */
72 void vtkParse_CopyTemplate(TemplateInfo *info, const TemplateInfo *orig)
73 {
74   int i, n;
75
76   n = orig->NumberOfParameters;
77   info->NumberOfParameters = n;
78   info->Parameters = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
79
80   for (i = 0; i < n; i++)
81     {
82     info->Parameters[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
83     vtkParse_CopyValue(info->Parameters[i], orig->Parameters[i]);
84     }
85 }
86
87 /* Free a TemplateInfo struct */
88 void vtkParse_FreeTemplate(TemplateInfo *template_info)
89 {
90   int j, m;
91
92   m = template_info->NumberOfParameters;
93   for (j = 0; j < m; j++)
94     {
95     vtkParse_FreeValue(template_info->Parameters[j]);
96     }
97
98   free(template_info);
99 }
100
101
102 /* Initialize a Function struct */
103 void vtkParse_InitFunction(FunctionInfo *func)
104 {
105 #ifndef VTK_PARSE_LEGACY_REMOVE
106   int i;
107 #endif
108
109   func->ItemType = VTK_FUNCTION_INFO;
110   func->Access = VTK_ACCESS_PUBLIC;
111   func->Name = NULL;
112   func->Comment = NULL;
113   func->Class = NULL;
114   func->Signature = NULL;
115   func->Template = NULL;
116   func->NumberOfParameters = 0;
117   func->Parameters = NULL;
118   func->ReturnValue = NULL;
119   func->Macro = NULL;
120   func->SizeHint = NULL;
121   func->IsStatic = 0;
122   func->IsVirtual = 0;
123   func->IsPureVirtual = 0;
124   func->IsOperator = 0;
125   func->IsVariadic = 0;
126   func->IsConst = 0;
127   func->IsDeleted = 0;
128   func->IsFinal = 0;
129   func->IsExplicit = 0;
130   func->IsLegacy = 0;
131
132 #ifndef VTK_PARSE_LEGACY_REMOVE
133   /* everything below here is legacy information, *
134    * maintained only for backwards compatibility  */
135   func->NumberOfArguments = 0;
136   func->ReturnType = VTK_PARSE_VOID;
137   func->ReturnClass = NULL;
138   func->HaveHint = 0;
139   func->HintSize = 0;
140   func->ArrayFailure = 0;
141   func->IsPublic = 0;
142   func->IsProtected = 0;
143
144   for (i = 0; i < MAX_ARGS; i++)
145     {
146     func->ArgTypes[i] = 0;
147     func->ArgClasses[i] = 0;
148     func->ArgCounts[i] = 0;
149     }
150 #endif
151 }
152
153 /* Copy a Function struct */
154 void vtkParse_CopyFunction(FunctionInfo *func, const FunctionInfo *orig)
155 {
156   int i, n;
157
158   func->ItemType = orig->ItemType;
159   func->Access = orig->Access;
160   func->Name = orig->Name;
161   func->Comment = orig->Comment;
162   func->Class = orig->Class;
163   func->Signature = orig->Signature;
164   func->Template = NULL;
165
166   if (orig->Template)
167     {
168     func->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
169     vtkParse_CopyTemplate(func->Template, orig->Template);
170     }
171
172   n = orig->NumberOfParameters;
173   func->NumberOfParameters = n;
174   if (n)
175     {
176     func->Parameters = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
177     for (i = 0; i < n; i++)
178       {
179       func->Parameters[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
180       vtkParse_CopyValue(func->Parameters[i], orig->Parameters[i]);
181       }
182     }
183
184   func->ReturnValue = NULL;
185   if (orig->ReturnValue)
186     {
187     func->ReturnValue = (ValueInfo *)malloc(sizeof(ValueInfo));
188     vtkParse_CopyValue(func->ReturnValue, orig->ReturnValue);
189     }
190
191   func->Macro = orig->Macro;
192   func->SizeHint = orig->SizeHint;
193   func->IsStatic = orig->IsStatic;
194   func->IsVirtual = orig->IsVirtual;
195   func->IsPureVirtual = orig->IsPureVirtual;
196   func->IsOperator = orig->IsOperator;
197   func->IsVariadic = orig->IsVariadic;
198   func->IsConst = orig->IsConst;
199   func->IsDeleted = orig->IsDeleted;
200   func->IsFinal = orig->IsFinal;
201   func->IsExplicit = orig->IsExplicit;
202   func->IsLegacy = orig->IsLegacy;
203
204 #ifndef VTK_PARSE_LEGACY_REMOVE
205   /* everything below here is legacy information, *
206    * maintained only for backwards compatibility  */
207   func->NumberOfArguments = orig->NumberOfArguments;
208   func->ReturnType = orig->ReturnType;
209   func->ReturnClass = orig->ReturnClass;
210   func->HaveHint = orig->HaveHint;
211   func->HintSize = orig->HintSize;
212   func->ArrayFailure = orig->ArrayFailure;
213   func->IsPublic = orig->IsPublic;
214   func->IsProtected = orig->IsProtected;
215
216   for (i = 0; i < MAX_ARGS; i++)
217     {
218     func->ArgTypes[i] = orig->ArgTypes[i];
219     func->ArgClasses[i] = orig->ArgClasses[i];
220     func->ArgCounts[i] = orig->ArgCounts[i];
221     }
222 #endif
223 }
224
225 /* Free a Function struct */
226 void vtkParse_FreeFunction(FunctionInfo *function_info)
227 {
228   int j, m;
229
230   if (function_info->Template)
231     {
232     vtkParse_FreeTemplate(function_info->Template);
233     }
234
235   m = function_info->NumberOfParameters;
236   for (j = 0; j < m; j++) { vtkParse_FreeValue(function_info->Parameters[j]); }
237   if (m > 0) { free(function_info->Parameters); }
238
239   if (function_info->ReturnValue)
240     {
241     vtkParse_FreeValue(function_info->ReturnValue);
242     }
243
244   free(function_info);
245 }
246
247
248 /* Initialize a Value struct */
249 void vtkParse_InitValue(ValueInfo *val)
250 {
251   val->ItemType = VTK_VARIABLE_INFO;
252   val->Access = VTK_ACCESS_PUBLIC;
253   val->Name = NULL;
254   val->Comment = NULL;
255   val->Value = NULL;
256   val->Type = 0;
257   val->Class = NULL;
258   val->Count = 0;
259   val->CountHint = NULL;
260   val->NumberOfDimensions = 0;
261   val->Dimensions = NULL;
262   val->Function = NULL;
263   val->Template = NULL;
264   val->IsStatic = 0;
265   val->IsEnum = 0;
266   val->IsPack = 0;
267 }
268
269 /* Copy a Value struct */
270 void vtkParse_CopyValue(ValueInfo *val, const ValueInfo *orig)
271 {
272   int i, n;
273
274   val->ItemType = orig->ItemType;
275   val->Access = orig->Access;
276   val->Name = orig->Name;
277   val->Comment = orig->Comment;
278   val->Value = orig->Value;
279   val->Type = orig->Type;
280   val->Class = orig->Class;
281   val->Count = orig->Count;
282   val->CountHint = orig->CountHint;
283
284   n = orig->NumberOfDimensions;
285   val->NumberOfDimensions = n;
286   if (n)
287     {
288     val->Dimensions = (const char **)malloc(n*sizeof(char *));
289     for (i = 0; i < n; i++)
290       {
291       val->Dimensions[i] = orig->Dimensions[i];
292       }
293     }
294
295   val->Function = NULL;
296   if (orig->Function)
297     {
298     val->Function = (FunctionInfo *)malloc(sizeof(FunctionInfo));
299     vtkParse_CopyFunction(val->Function, orig->Function);
300     }
301
302   val->Template = NULL;
303   if (orig->Template)
304     {
305     val->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
306     vtkParse_CopyTemplate(val->Template, orig->Template);
307     }
308
309   val->IsStatic = orig->IsStatic;
310   val->IsEnum = orig->IsEnum;
311   val->IsPack = orig->IsPack;
312 }
313
314 /* Free a Value struct */
315 void vtkParse_FreeValue(ValueInfo *value_info)
316 {
317   if (value_info->NumberOfDimensions)
318     {
319     free((char **)value_info->Dimensions);
320     }
321   if (value_info->Function)
322     {
323     vtkParse_FreeFunction(value_info->Function);
324     }
325   if (value_info->Template)
326     {
327     vtkParse_FreeTemplate(value_info->Template);
328     }
329
330   free(value_info);
331 }
332
333
334 /* Initialize an Enum struct */
335 void vtkParse_InitEnum(EnumInfo *item)
336 {
337   vtkParse_InitClass(item);
338   item->ItemType = VTK_ENUM_INFO;
339 }
340
341 /* Copy an Enum struct */
342 void vtkParse_CopyEnum(EnumInfo *item, const EnumInfo *orig)
343 {
344   vtkParse_CopyClass(item, orig);
345 }
346
347 /* Free an Enum struct */
348 void vtkParse_FreeEnum(EnumInfo *enum_info)
349 {
350   free(enum_info);
351 }
352
353
354 /* Initialize a Using struct */
355 void vtkParse_InitUsing(UsingInfo *item)
356 {
357   item->ItemType = VTK_USING_INFO;
358   item->Access = VTK_ACCESS_PUBLIC;
359   item->Name = NULL;
360   item->Comment = NULL;
361   item->Scope = NULL;
362 }
363
364 /* Copy a Using struct */
365 void vtkParse_CopyUsing(UsingInfo *item, const UsingInfo *orig)
366 {
367   item->ItemType = orig->ItemType;
368   item->Access = orig->Access;
369   item->Name = orig->Name;
370   item->Comment = orig->Comment;
371   item->Scope = orig->Scope;
372 }
373
374 /* Free a Using struct */
375 void vtkParse_FreeUsing(UsingInfo *using_info)
376 {
377   free(using_info);
378 }
379
380
381 /* Initialize a Class struct */
382 void vtkParse_InitClass(ClassInfo *cls)
383 {
384   cls->ItemType = VTK_CLASS_INFO;
385   cls->Access = VTK_ACCESS_PUBLIC;
386   cls->Name = NULL;
387   cls->Comment = NULL;
388   cls->Template = NULL;
389   cls->NumberOfSuperClasses = 0;
390   cls->SuperClasses = NULL;
391   cls->NumberOfItems = 0;
392   cls->Items = NULL;
393   cls->NumberOfClasses = 0;
394   cls->Classes = NULL;
395   cls->NumberOfFunctions = 0;
396   cls->Functions = NULL;
397   cls->NumberOfConstants = 0;
398   cls->Constants = NULL;
399   cls->NumberOfVariables = 0;
400   cls->Variables = NULL;
401   cls->NumberOfEnums = 0;
402   cls->Enums = NULL;
403   cls->NumberOfTypedefs = 0;
404   cls->Typedefs = NULL;
405   cls->NumberOfUsings = 0;
406   cls->Usings = NULL;
407   cls->NumberOfNamespaces = 0;
408   cls->Namespaces = NULL;
409   cls->IsAbstract = 0;
410   cls->IsFinal = 0;
411   cls->HasDelete = 0;
412 }
413
414 /* Copy a Class struct */
415 void vtkParse_CopyClass(ClassInfo *cls, const ClassInfo *orig)
416 {
417   int i, n;
418
419   cls->ItemType = orig->ItemType;
420   cls->Access = orig->Access;
421   cls->Name = orig->Name;
422   cls->Comment = orig->Comment;
423   cls->Template = NULL;
424
425   if (orig->Template)
426     {
427     cls->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
428     vtkParse_CopyTemplate(cls->Template, orig->Template);
429     }
430
431   n = orig->NumberOfSuperClasses;
432   cls->NumberOfSuperClasses = n;
433   if (n)
434     {
435     cls->SuperClasses = (const char **)malloc(n*sizeof(char *));
436     for (i = 0; i < n; i++)
437       {
438       cls->SuperClasses[i] = orig->SuperClasses[i];
439       }
440     }
441
442   n = orig->NumberOfItems;
443   cls->NumberOfItems = n;
444   if (n)
445     {
446     cls->Items = (ItemInfo *)malloc(n*sizeof(ItemInfo));
447     for (i = 0; i < n; i++)
448       {
449       cls->Items[i].Type = orig->Items[i].Type;
450       cls->Items[i].Index = orig->Items[i].Index;
451       }
452     }
453
454   n = orig->NumberOfClasses;
455   cls->NumberOfClasses = n;
456   if (n)
457     {
458     cls->Classes = (ClassInfo **)malloc(n*sizeof(ClassInfo *));
459     for (i = 0; i < n; i++)
460       {
461       cls->Classes[i] = (ClassInfo *)malloc(sizeof(ClassInfo));
462       vtkParse_CopyClass(cls->Classes[i], orig->Classes[i]);
463       }
464     }
465
466   n = orig->NumberOfFunctions;
467   cls->NumberOfFunctions = n;
468   if (n)
469     {
470     cls->Functions = (FunctionInfo **)malloc(n*sizeof(FunctionInfo *));
471     for (i = 0; i < n; i++)
472       {
473       cls->Functions[i] = (FunctionInfo *)malloc(sizeof(FunctionInfo));
474       vtkParse_CopyFunction(cls->Functions[i], orig->Functions[i]);
475       }
476     }
477
478   n = orig->NumberOfConstants;
479   cls->NumberOfConstants = n;
480   if (n)
481     {
482     cls->Constants = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
483     for (i = 0; i < n; i++)
484       {
485       cls->Constants[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
486       vtkParse_CopyValue(cls->Constants[i], orig->Constants[i]);
487       }
488     }
489
490   n = orig->NumberOfVariables;
491   cls->NumberOfVariables = n;
492   if (n)
493     {
494     cls->Variables = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
495     for (i = 0; i < n; i++)
496       {
497       cls->Variables[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
498       vtkParse_CopyValue(cls->Variables[i], orig->Variables[i]);
499       }
500     }
501
502   n = orig->NumberOfEnums;
503   cls->NumberOfEnums = n;
504   if (n)
505     {
506     cls->Enums = (EnumInfo **)malloc(n*sizeof(EnumInfo *));
507     for (i = 0; i < n; i++)
508       {
509       cls->Enums[i] = (EnumInfo *)malloc(sizeof(EnumInfo));
510       vtkParse_CopyEnum(cls->Enums[i], orig->Enums[i]);
511       }
512     }
513
514   n = orig->NumberOfTypedefs;
515   cls->NumberOfTypedefs = n;
516   if (n)
517     {
518     cls->Typedefs = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
519     for (i = 0; i < n; i++)
520       {
521       cls->Typedefs[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
522       vtkParse_CopyValue(cls->Typedefs[i], orig->Typedefs[i]);
523       }
524     }
525
526   n = orig->NumberOfUsings;
527   cls->NumberOfUsings = n;
528   if (n)
529     {
530     cls->Usings = (UsingInfo **)malloc(n*sizeof(UsingInfo *));
531     for (i = 0; i < n; i++)
532       {
533       cls->Usings[i] = (UsingInfo *)malloc(sizeof(UsingInfo));
534       vtkParse_CopyUsing(cls->Usings[i], orig->Usings[i]);
535       }
536     }
537
538   n = orig->NumberOfNamespaces;
539   cls->NumberOfNamespaces = n;
540   if (n)
541     {
542     cls->Namespaces = (NamespaceInfo **)malloc(n*sizeof(NamespaceInfo *));
543     for (i = 0; i < n; i++)
544       {
545       cls->Namespaces[i] = (NamespaceInfo *)malloc(sizeof(NamespaceInfo));
546       vtkParse_CopyNamespace(cls->Namespaces[i], orig->Namespaces[i]);
547       }
548     }
549
550   cls->IsAbstract = orig->IsAbstract;
551   cls->IsFinal = orig->IsFinal;
552   cls->HasDelete = orig->HasDelete;
553 }
554
555 /* Free a Class struct */
556 void vtkParse_FreeClass(ClassInfo *class_info)
557 {
558   int j, m;
559
560   if (class_info->Template) { vtkParse_FreeTemplate(class_info->Template); }
561
562   m = class_info->NumberOfSuperClasses;
563   if (m > 0) { free((char **)class_info->SuperClasses); }
564
565   m = class_info->NumberOfClasses;
566   for (j = 0; j < m; j++) { vtkParse_FreeClass(class_info->Classes[j]); }
567   if (m > 0) { free(class_info->Classes); }
568
569   m = class_info->NumberOfFunctions;
570   for (j = 0; j < m; j++) { vtkParse_FreeFunction(class_info->Functions[j]); }
571   if (m > 0) { free(class_info->Functions); }
572
573   m = class_info->NumberOfConstants;
574   for (j = 0; j < m; j++) { vtkParse_FreeValue(class_info->Constants[j]); }
575   if (m > 0) { free(class_info->Constants); }
576
577   m = class_info->NumberOfVariables;
578   for (j = 0; j < m; j++) { vtkParse_FreeValue(class_info->Variables[j]); }
579   if (m > 0) { free(class_info->Variables); }
580
581   m = class_info->NumberOfEnums;
582   for (j = 0; j < m; j++) { vtkParse_FreeEnum(class_info->Enums[j]); }
583   if (m > 0) { free(class_info->Enums); }
584
585   m = class_info->NumberOfTypedefs;
586   for (j = 0; j < m; j++) { vtkParse_FreeValue(class_info->Typedefs[j]); }
587   if (m > 0) { free(class_info->Typedefs); }
588
589   m = class_info->NumberOfUsings;
590   for (j = 0; j < m; j++) { vtkParse_FreeUsing(class_info->Usings[j]); }
591   if (m > 0) { free(class_info->Usings); }
592
593   m = class_info->NumberOfNamespaces;
594   for (j = 0; j < m; j++) { vtkParse_FreeNamespace(class_info->Namespaces[j]); }
595   if (m > 0) { free(class_info->Namespaces); }
596
597   if (class_info->NumberOfItems > 0) { free(class_info->Items); }
598
599   free(class_info);
600 }
601
602
603 /* Initialize a Namespace struct */
604 void vtkParse_InitNamespace(NamespaceInfo *name_info)
605 {
606   vtkParse_InitClass(name_info);
607   name_info->ItemType = VTK_NAMESPACE_INFO;
608 }
609
610 /* Copy a Namespace struct */
611 void vtkParse_CopyNamespace(NamespaceInfo *ninfo, const NamespaceInfo *orig)
612 {
613   vtkParse_CopyClass(ninfo, orig);
614 }
615
616 /* Free a Namespace struct */
617 void vtkParse_FreeNamespace(NamespaceInfo *namespace_info)
618 {
619   vtkParse_FreeClass(namespace_info);
620 }
621
622
623 /* This method is used for extending dynamic arrays in a progression of
624  * powers of two.  If "n" reaches a power of two, then the array size is
625  * doubled so that "n" can be safely incremented. */
626 static void *array_size_check(
627   void *arraymem, size_t size, int n)
628 {
629   /* if empty, alloc for the first time */
630   if (n == 0)
631     {
632     return malloc(size);
633     }
634   /* if count is power of two, reallocate with double size */
635   else if ((n & (n-1)) == 0)
636     {
637     return realloc(arraymem, (n << 1)*size);
638     }
639
640   /* no reallocation, just return the original array */
641   return arraymem;
642 }
643
644
645 /* Utility method to add an included file to a FileInfo */
646 void vtkParse_AddIncludeToFile(
647   FileInfo *file_info, FileInfo *include_file)
648 {
649   file_info->Includes = (FileInfo **)array_size_check(
650     (FileInfo **)file_info->Includes, sizeof(FileInfo *),
651     file_info->NumberOfIncludes);
652
653   file_info->Includes[file_info->NumberOfIncludes++] = include_file;
654
655   if (!include_file->Strings)
656     {
657     include_file->Strings = file_info->Strings;
658     }
659 }
660
661 /* Utility method to add a const char pointer to an array */
662 void vtkParse_AddStringToArray(
663   const char ***valueArray, int *count, const char *value)
664 {
665   *valueArray = (const char **)array_size_check(
666     (char **)*valueArray, sizeof(const char *), *count);
667
668   (*valueArray)[(*count)++] = value;
669 }
670
671 /* Utility method to add an item to an array */
672 void vtkParse_AddItemToArray(
673   ItemInfo **valueArray, int *count, parse_item_t type, int idx)
674 {
675   int n = *count;
676   ItemInfo *values = *valueArray;
677
678   values = (ItemInfo *)array_size_check(values, sizeof(ItemInfo), n);
679
680   values[n].Type = type;
681   values[n].Index = idx;
682   *count = n+1;
683   *valueArray = values;
684 }
685
686 /* Add a ClassInfo to a ClassInfo */
687 void vtkParse_AddClassToClass(ClassInfo *info, ClassInfo *item)
688 {
689   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
690     item->ItemType, info->NumberOfClasses);
691   info->Classes = (ClassInfo **)array_size_check(
692     info->Classes, sizeof(ClassInfo *), info->NumberOfClasses);
693   info->Classes[info->NumberOfClasses++] = item;
694 }
695
696 /* Add a FunctionInfo to a ClassInfo */
697 void vtkParse_AddFunctionToClass(ClassInfo *info, FunctionInfo *item)
698 {
699   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
700     item->ItemType, info->NumberOfFunctions);
701   info->Functions = (FunctionInfo **)array_size_check(
702     info->Functions, sizeof(FunctionInfo *), info->NumberOfFunctions);
703   info->Functions[info->NumberOfFunctions++] = item;
704 }
705
706 /* Add a EnumInfo to a ClassInfo */
707 void vtkParse_AddEnumToClass(ClassInfo *info, EnumInfo *item)
708 {
709   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
710     item->ItemType, info->NumberOfEnums);
711   info->Enums = (EnumInfo **)array_size_check(
712     info->Enums, sizeof(EnumInfo *), info->NumberOfEnums);
713   info->Enums[info->NumberOfEnums++] = item;
714 }
715
716 /* Add a Constant ValueInfo to a ClassInfo */
717 void vtkParse_AddConstantToClass(ClassInfo *info, ValueInfo *item)
718 {
719   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
720     item->ItemType, info->NumberOfConstants);
721   info->Constants = (ValueInfo **)array_size_check(
722     info->Constants, sizeof(ValueInfo *), info->NumberOfConstants);
723   info->Constants[info->NumberOfConstants++] = item;
724 }
725
726 /* Add a Variable ValueInfo to a ClassInfo */
727 void vtkParse_AddVariableToClass(ClassInfo *info, ValueInfo *item)
728 {
729   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
730     item->ItemType, info->NumberOfVariables);
731   info->Variables = (ValueInfo **)array_size_check(
732     info->Variables, sizeof(ValueInfo *), info->NumberOfVariables);
733   info->Variables[info->NumberOfVariables++] = item;
734 }
735
736 /* Add a Typedef ValueInfo to a ClassInfo */
737 void vtkParse_AddTypedefToClass(ClassInfo *info, ValueInfo *item)
738 {
739   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
740     item->ItemType, info->NumberOfTypedefs);
741   info->Typedefs = (ValueInfo **)array_size_check(
742     info->Typedefs, sizeof(ValueInfo *), info->NumberOfTypedefs);
743   info->Typedefs[info->NumberOfTypedefs++] = item;
744 }
745
746 /* Add a UsingInfo to a ClassInfo */
747 void vtkParse_AddUsingToClass(ClassInfo *info, UsingInfo *item)
748 {
749   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
750     item->ItemType, info->NumberOfUsings);
751   info->Usings = (UsingInfo **)array_size_check(
752     info->Usings, sizeof(UsingInfo *), info->NumberOfUsings);
753   info->Usings[info->NumberOfUsings++] = item;
754 }
755
756
757 /* Add a NamespaceInfo to a NamespaceInfo */
758 void vtkParse_AddNamespaceToNamespace(NamespaceInfo *info, NamespaceInfo *item)
759 {
760   vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
761     item->ItemType, info->NumberOfNamespaces);
762   info->Namespaces = (NamespaceInfo **)array_size_check(
763     info->Namespaces, sizeof(NamespaceInfo *), info->NumberOfNamespaces);
764   info->Namespaces[info->NumberOfNamespaces++] = item;
765 }
766
767 /* Add a ClassInfo to a NamespaceInfo */
768 void vtkParse_AddClassToNamespace(NamespaceInfo *info, ClassInfo *item)
769 {
770   vtkParse_AddClassToClass(info, item);
771 }
772
773 /* Add a FunctionInfo to a NamespaceInfo */
774 void vtkParse_AddFunctionToNamespace(NamespaceInfo *info, FunctionInfo *item)
775 {
776   vtkParse_AddFunctionToClass(info, item);
777 }
778
779 /* Add a EnumInfo to a NamespaceInfo */
780 void vtkParse_AddEnumToNamespace(NamespaceInfo *info, EnumInfo *item)
781 {
782   vtkParse_AddEnumToClass(info, item);
783 }
784
785 /* Add a Constant ValueInfo to a NamespaceInfo */
786 void vtkParse_AddConstantToNamespace(NamespaceInfo *info, ValueInfo *item)
787 {
788   vtkParse_AddConstantToClass(info, item);
789 }
790
791 /* Add a Variable ValueInfo to a NamespaceInfo */
792 void vtkParse_AddVariableToNamespace(NamespaceInfo *info, ValueInfo *item)
793 {
794   vtkParse_AddVariableToClass(info, item);
795 }
796
797 /* Add a Typedef ValueInfo to a NamespaceInfo */
798 void vtkParse_AddTypedefToNamespace(NamespaceInfo *info, ValueInfo *item)
799 {
800   vtkParse_AddTypedefToClass(info, item);
801 }
802
803 /* Add a UsingInfo to a NamespaceInfo */
804 void vtkParse_AddUsingToNamespace(NamespaceInfo *info, UsingInfo *item)
805 {
806   vtkParse_AddUsingToClass(info, item);
807 }
808
809
810 /* Add a ValueInfo parameter to a FunctionInfo */
811 void vtkParse_AddParameterToFunction(FunctionInfo *info, ValueInfo *item)
812 {
813   info->Parameters = (ValueInfo **)array_size_check(
814     info->Parameters, sizeof(ValueInfo *), info->NumberOfParameters);
815   info->Parameters[info->NumberOfParameters++] = item;
816 }
817
818
819 /* Add a ValueInfo to a TemplateInfo */
820 void vtkParse_AddParameterToTemplate(TemplateInfo *info, ValueInfo *item)
821 {
822   info->Parameters = (ValueInfo **)array_size_check(
823     info->Parameters, sizeof(ValueInfo *), info->NumberOfParameters);
824   info->Parameters[info->NumberOfParameters++] = item;
825 }
826
827
828 /* Add default constructors if they do not already exist */
829 void vtkParse_AddDefaultConstructors(ClassInfo *cls, StringCache *cache)
830 {
831   FunctionInfo *func;
832   ValueInfo *param;
833   size_t k, l;
834   int i, n;
835   int default_constructor = 1;
836   int copy_constructor = 1;
837   char *tname;
838   const char *ccname;
839
840   if (cls == NULL || cls->Name == NULL)
841     {
842     return;
843     }
844
845   n = cls->NumberOfFunctions;
846   for (i = 0; i < n; i++)
847     {
848     func = cls->Functions[i];
849     if (func->Name && strcmp(func->Name, cls->Name) == 0)
850       {
851       default_constructor = 0;
852
853       if (func->NumberOfParameters == 1)
854         {
855         param = func->Parameters[0];
856         if (param->Class &&
857             strcmp(param->Class, cls->Name) == 0 &&
858             (param->Type & VTK_PARSE_POINTER_MASK) == 0)
859           {
860           copy_constructor = 0;
861           }
862         }
863       }
864     }
865
866   if (default_constructor)
867     {
868     func = (FunctionInfo *)malloc(sizeof(FunctionInfo));
869     vtkParse_InitFunction(func);
870     func->Class = cls->Name;
871     func->Name = cls->Name;
872     k = strlen(cls->Name);
873     tname = vtkParse_NewString(cache, k + 2);
874     strcpy(tname, cls->Name);
875     strcpy(&tname[k], "()");
876     func->Signature = tname;
877     vtkParse_AddFunctionToClass(cls, func);
878     }
879
880   if (copy_constructor)
881     {
882     ccname = cls->Name;
883
884     if (cls->Template)
885       {
886       /* specialize the name */
887       n = cls->Template->NumberOfParameters;
888
889       k = strlen(cls->Name) + 2;
890       for (i = 0; i < n; i++)
891         {
892         if (cls->Template->Parameters[i]->Name)
893           {
894           k += strlen(cls->Template->Parameters[i]->Name) + 2;
895           }
896         }
897       tname = vtkParse_NewString(cache, k);
898       strcpy(tname, cls->Name);
899       k = strlen(tname);
900       tname[k++] = '<';
901       for (i = 0; i < n; i++)
902         {
903         if (cls->Template->Parameters[i]->Name)
904           {
905           strcpy(&tname[k], cls->Template->Parameters[i]->Name);
906           k += strlen(cls->Template->Parameters[i]->Name);
907           }
908         if (i+1 < n)
909           {
910           tname[k++] = ',';
911           tname[k++] = ' ';
912           }
913         }
914       tname[k++] = '>';
915       tname[k] = '\0';
916       ccname = tname;
917       }
918
919     func = (FunctionInfo *)malloc(sizeof(FunctionInfo));
920     vtkParse_InitFunction(func);
921     func->Class = cls->Name;
922     func->Name = cls->Name;
923     k = strlen(cls->Name);
924     l = strlen(ccname);
925     tname = vtkParse_NewString(cache, k + l + 9);
926     strcpy(tname, cls->Name);
927     strcpy(&tname[k], "(const &");
928     strcpy(&tname[k+8], ccname);
929     strcpy(&tname[k+8+l], ")");
930     func->Signature = tname;
931     param = (ValueInfo *)malloc(sizeof(ValueInfo));
932     vtkParse_InitValue(param);
933     param->Type = (VTK_PARSE_OBJECT_REF | VTK_PARSE_CONST);
934     param->Class = ccname;
935     vtkParse_AddParameterToFunction(func, param);
936     vtkParse_AddFunctionToClass(cls, func);
937     }
938 }