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 =========================================================================*/
15 /*-------------------------------------------------------------------------
16 Copyright (c) 2010 David Gobbi.
18 Contributed to the VisualizationToolkit by the author in May 2010
19 under the terms of the Visualization Toolkit 2008 copyright.
20 -------------------------------------------------------------------------*/
22 #include "vtkParseData.h"
26 /* Initialize the FileInfo struct */
27 void vtkParse_InitFile(FileInfo *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;
36 file_info->NumberOfIncludes = 0;
37 file_info->Includes = NULL;
38 file_info->MainClass = NULL;
39 file_info->Contents = NULL;
41 file_info->Strings = NULL;
44 /* Free the FileInfo struct */
45 void vtkParse_FreeFile(FileInfo *file_info)
49 n = file_info->NumberOfIncludes;
50 for (i = 0; i < n; i++)
52 vtkParse_FreeFile(file_info->Includes[i]);
53 free(file_info->Includes[i]);
55 if (file_info->Includes)
57 free(file_info->Includes);
60 vtkParse_FreeNamespace(file_info->Contents);
61 file_info->Contents = NULL;
64 /* Initialize a TemplateInfo struct */
65 void vtkParse_InitTemplate(TemplateInfo *info)
67 info->NumberOfParameters = 0;
68 info->Parameters = NULL;
71 /* Copy a TemplateInfo struct */
72 void vtkParse_CopyTemplate(TemplateInfo *info, const TemplateInfo *orig)
76 n = orig->NumberOfParameters;
77 info->NumberOfParameters = n;
78 info->Parameters = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
80 for (i = 0; i < n; i++)
82 info->Parameters[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
83 vtkParse_CopyValue(info->Parameters[i], orig->Parameters[i]);
87 /* Free a TemplateInfo struct */
88 void vtkParse_FreeTemplate(TemplateInfo *template_info)
92 m = template_info->NumberOfParameters;
93 for (j = 0; j < m; j++)
95 vtkParse_FreeValue(template_info->Parameters[j]);
102 /* Initialize a Function struct */
103 void vtkParse_InitFunction(FunctionInfo *func)
105 #ifndef VTK_PARSE_LEGACY_REMOVE
109 func->ItemType = VTK_FUNCTION_INFO;
110 func->Access = VTK_ACCESS_PUBLIC;
112 func->Comment = NULL;
114 func->Signature = NULL;
115 func->Template = NULL;
116 func->NumberOfParameters = 0;
117 func->Parameters = NULL;
118 func->ReturnValue = NULL;
120 func->SizeHint = NULL;
123 func->IsPureVirtual = 0;
124 func->IsOperator = 0;
125 func->IsVariadic = 0;
127 func->IsExplicit = 0;
130 #ifndef VTK_PARSE_LEGACY_REMOVE
131 /* everything below here is legacy information, *
132 * maintained only for backwards compatibility */
133 func->NumberOfArguments = 0;
134 func->ReturnType = VTK_PARSE_VOID;
135 func->ReturnClass = NULL;
138 func->ArrayFailure = 0;
140 func->IsProtected = 0;
142 for (i = 0; i < MAX_ARGS; i++)
144 func->ArgTypes[i] = 0;
145 func->ArgClasses[i] = 0;
146 func->ArgCounts[i] = 0;
151 /* Copy a Function struct */
152 void vtkParse_CopyFunction(FunctionInfo *func, const FunctionInfo *orig)
156 func->ItemType = orig->ItemType;
157 func->Access = orig->Access;
158 func->Name = orig->Name;
159 func->Comment = orig->Comment;
160 func->Class = orig->Class;
161 func->Signature = orig->Signature;
162 func->Template = NULL;
166 func->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
167 vtkParse_CopyTemplate(func->Template, orig->Template);
170 n = orig->NumberOfParameters;
171 func->NumberOfParameters = n;
174 func->Parameters = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
175 for (i = 0; i < n; i++)
177 func->Parameters[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
178 vtkParse_CopyValue(func->Parameters[i], orig->Parameters[i]);
182 func->ReturnValue = NULL;
183 if (orig->ReturnValue)
185 func->ReturnValue = (ValueInfo *)malloc(sizeof(ValueInfo));
186 vtkParse_CopyValue(func->ReturnValue, orig->ReturnValue);
189 func->Macro = orig->Macro;
190 func->SizeHint = orig->SizeHint;
191 func->IsStatic = orig->IsStatic;
192 func->IsVirtual = orig->IsVirtual;
193 func->IsPureVirtual = orig->IsPureVirtual;
194 func->IsOperator = orig->IsOperator;
195 func->IsVariadic = orig->IsVariadic;
196 func->IsConst = orig->IsConst;
197 func->IsExplicit = orig->IsExplicit;
198 func->IsLegacy = orig->IsLegacy;
200 #ifndef VTK_PARSE_LEGACY_REMOVE
201 /* everything below here is legacy information, *
202 * maintained only for backwards compatibility */
203 func->NumberOfArguments = orig->NumberOfArguments;
204 func->ReturnType = orig->ReturnType;
205 func->ReturnClass = orig->ReturnClass;
206 func->HaveHint = orig->HaveHint;
207 func->HintSize = orig->HintSize;
208 func->ArrayFailure = orig->ArrayFailure;
209 func->IsPublic = orig->IsPublic;
210 func->IsProtected = orig->IsProtected;
212 for (i = 0; i < MAX_ARGS; i++)
214 func->ArgTypes[i] = orig->ArgTypes[i];
215 func->ArgClasses[i] = orig->ArgClasses[i];
216 func->ArgCounts[i] = orig->ArgCounts[i];
221 /* Free a Function struct */
222 void vtkParse_FreeFunction(FunctionInfo *function_info)
226 if (function_info->Template)
228 vtkParse_FreeTemplate(function_info->Template);
231 m = function_info->NumberOfParameters;
232 for (j = 0; j < m; j++) { vtkParse_FreeValue(function_info->Parameters[j]); }
233 if (m > 0) { free(function_info->Parameters); }
235 if (function_info->ReturnValue)
237 vtkParse_FreeValue(function_info->ReturnValue);
244 /* Initialize a Value struct */
245 void vtkParse_InitValue(ValueInfo *val)
247 val->ItemType = VTK_VARIABLE_INFO;
248 val->Access = VTK_ACCESS_PUBLIC;
255 val->CountHint = NULL;
256 val->NumberOfDimensions = 0;
257 val->Dimensions = NULL;
258 val->Function = NULL;
259 val->Template = NULL;
264 /* Copy a Value struct */
265 void vtkParse_CopyValue(ValueInfo *val, const ValueInfo *orig)
269 val->ItemType = orig->ItemType;
270 val->Access = orig->Access;
271 val->Name = orig->Name;
272 val->Comment = orig->Comment;
273 val->Value = orig->Value;
274 val->Type = orig->Type;
275 val->Class = orig->Class;
276 val->Count = orig->Count;
277 val->CountHint = orig->CountHint;
279 n = orig->NumberOfDimensions;
280 val->NumberOfDimensions = n;
283 val->Dimensions = (const char **)malloc(n*sizeof(char *));
284 for (i = 0; i < n; i++)
286 val->Dimensions[i] = orig->Dimensions[i];
290 val->Function = NULL;
293 val->Function = (FunctionInfo *)malloc(sizeof(FunctionInfo));
294 vtkParse_CopyFunction(val->Function, orig->Function);
297 val->Template = NULL;
300 val->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
301 vtkParse_CopyTemplate(val->Template, orig->Template);
304 val->IsStatic = orig->IsStatic;
305 val->IsEnum = orig->IsEnum;
308 /* Free a Value struct */
309 void vtkParse_FreeValue(ValueInfo *value_info)
311 if (value_info->NumberOfDimensions)
313 free((char **)value_info->Dimensions);
315 if (value_info->Function)
317 vtkParse_FreeFunction(value_info->Function);
319 if (value_info->Template)
321 vtkParse_FreeTemplate(value_info->Template);
328 /* Initialize an Enum struct */
329 void vtkParse_InitEnum(EnumInfo *item)
331 item->ItemType = VTK_ENUM_INFO;
332 item->Access = VTK_ACCESS_PUBLIC;
334 item->Comment = NULL;
337 /* Copy an Enum struct */
338 void vtkParse_CopyEnum(EnumInfo *item, const EnumInfo *orig)
340 item->ItemType = orig->ItemType;
341 item->Access = orig->Access;
342 item->Name = orig->Name;
343 item->Comment = orig->Comment;
346 /* Free an Enum struct */
347 void vtkParse_FreeEnum(EnumInfo *enum_info)
353 /* Initialize a Using struct */
354 void vtkParse_InitUsing(UsingInfo *item)
356 item->ItemType = VTK_USING_INFO;
357 item->Access = VTK_ACCESS_PUBLIC;
359 item->Comment = NULL;
363 /* Copy a Using struct */
364 void vtkParse_CopyUsing(UsingInfo *item, const UsingInfo *orig)
366 item->ItemType = orig->ItemType;
367 item->Access = orig->Access;
368 item->Name = orig->Name;
369 item->Comment = orig->Comment;
370 item->Scope = orig->Scope;
373 /* Free a Using struct */
374 void vtkParse_FreeUsing(UsingInfo *using_info)
380 /* Initialize a Class struct */
381 void vtkParse_InitClass(ClassInfo *cls)
383 cls->ItemType = VTK_CLASS_INFO;
384 cls->Access = VTK_ACCESS_PUBLIC;
387 cls->Template = NULL;
388 cls->NumberOfSuperClasses = 0;
389 cls->SuperClasses = NULL;
390 cls->NumberOfItems = 0;
392 cls->NumberOfClasses = 0;
394 cls->NumberOfFunctions = 0;
395 cls->Functions = NULL;
396 cls->NumberOfConstants = 0;
397 cls->Constants = NULL;
398 cls->NumberOfVariables = 0;
399 cls->Variables = NULL;
400 cls->NumberOfEnums = 0;
402 cls->NumberOfTypedefs = 0;
403 cls->Typedefs = NULL;
404 cls->NumberOfUsings = 0;
406 cls->NumberOfNamespaces = 0;
407 cls->Namespaces = NULL;
412 /* Copy a Class struct */
413 void vtkParse_CopyClass(ClassInfo *cls, const ClassInfo *orig)
417 cls->ItemType = orig->ItemType;
418 cls->Access = orig->Access;
419 cls->Name = orig->Name;
420 cls->Comment = orig->Comment;
421 cls->Template = NULL;
425 cls->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
426 vtkParse_CopyTemplate(cls->Template, orig->Template);
429 n = orig->NumberOfSuperClasses;
430 cls->NumberOfSuperClasses = n;
433 cls->SuperClasses = (const char **)malloc(n*sizeof(char *));
434 for (i = 0; i < n; i++)
436 cls->SuperClasses[i] = orig->SuperClasses[i];
440 n = orig->NumberOfItems;
441 cls->NumberOfItems = n;
444 cls->Items = (ItemInfo *)malloc(n*sizeof(ItemInfo));
445 for (i = 0; i < n; i++)
447 cls->Items[i].Type = orig->Items[i].Type;
448 cls->Items[i].Index = orig->Items[i].Index;
452 n = orig->NumberOfClasses;
453 cls->NumberOfClasses = n;
456 cls->Classes = (ClassInfo **)malloc(n*sizeof(ClassInfo *));
457 for (i = 0; i < n; i++)
459 cls->Classes[i] = (ClassInfo *)malloc(sizeof(ClassInfo));
460 vtkParse_CopyClass(cls->Classes[i], orig->Classes[i]);
464 n = orig->NumberOfFunctions;
465 cls->NumberOfFunctions = n;
468 cls->Functions = (FunctionInfo **)malloc(n*sizeof(FunctionInfo *));
469 for (i = 0; i < n; i++)
471 cls->Functions[i] = (FunctionInfo *)malloc(sizeof(FunctionInfo));
472 vtkParse_CopyFunction(cls->Functions[i], orig->Functions[i]);
476 n = orig->NumberOfConstants;
477 cls->NumberOfConstants = n;
480 cls->Constants = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
481 for (i = 0; i < n; i++)
483 cls->Constants[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
484 vtkParse_CopyValue(cls->Constants[i], orig->Constants[i]);
488 n = orig->NumberOfVariables;
489 cls->NumberOfVariables = n;
492 cls->Variables = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
493 for (i = 0; i < n; i++)
495 cls->Variables[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
496 vtkParse_CopyValue(cls->Variables[i], orig->Variables[i]);
500 n = orig->NumberOfEnums;
501 cls->NumberOfEnums = n;
504 cls->Enums = (EnumInfo **)malloc(n*sizeof(EnumInfo *));
505 for (i = 0; i < n; i++)
507 cls->Enums[i] = (EnumInfo *)malloc(sizeof(EnumInfo));
508 vtkParse_CopyEnum(cls->Enums[i], orig->Enums[i]);
512 n = orig->NumberOfTypedefs;
513 cls->NumberOfTypedefs = n;
516 cls->Typedefs = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
517 for (i = 0; i < n; i++)
519 cls->Typedefs[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
520 vtkParse_CopyValue(cls->Typedefs[i], orig->Typedefs[i]);
524 n = orig->NumberOfUsings;
525 cls->NumberOfUsings = n;
528 cls->Usings = (UsingInfo **)malloc(n*sizeof(UsingInfo *));
529 for (i = 0; i < n; i++)
531 cls->Usings[i] = (UsingInfo *)malloc(sizeof(UsingInfo));
532 vtkParse_CopyUsing(cls->Usings[i], orig->Usings[i]);
536 n = orig->NumberOfNamespaces;
537 cls->NumberOfNamespaces = n;
540 cls->Namespaces = (NamespaceInfo **)malloc(n*sizeof(NamespaceInfo *));
541 for (i = 0; i < n; i++)
543 cls->Namespaces[i] = (NamespaceInfo *)malloc(sizeof(NamespaceInfo));
544 vtkParse_CopyNamespace(cls->Namespaces[i], orig->Namespaces[i]);
548 cls->IsAbstract = orig->IsAbstract;
549 cls->HasDelete = orig->HasDelete;
552 /* Free a Class struct */
553 void vtkParse_FreeClass(ClassInfo *class_info)
557 if (class_info->Template) { vtkParse_FreeTemplate(class_info->Template); }
559 m = class_info->NumberOfSuperClasses;
560 if (m > 0) { free((char **)class_info->SuperClasses); }
562 m = class_info->NumberOfClasses;
563 for (j = 0; j < m; j++) { vtkParse_FreeClass(class_info->Classes[j]); }
564 if (m > 0) { free(class_info->Classes); }
566 m = class_info->NumberOfFunctions;
567 for (j = 0; j < m; j++) { vtkParse_FreeFunction(class_info->Functions[j]); }
568 if (m > 0) { free(class_info->Functions); }
570 m = class_info->NumberOfConstants;
571 for (j = 0; j < m; j++) { vtkParse_FreeValue(class_info->Constants[j]); }
572 if (m > 0) { free(class_info->Constants); }
574 m = class_info->NumberOfVariables;
575 for (j = 0; j < m; j++) { vtkParse_FreeValue(class_info->Variables[j]); }
576 if (m > 0) { free(class_info->Variables); }
578 m = class_info->NumberOfEnums;
579 for (j = 0; j < m; j++) { vtkParse_FreeEnum(class_info->Enums[j]); }
580 if (m > 0) { free(class_info->Enums); }
582 m = class_info->NumberOfTypedefs;
583 for (j = 0; j < m; j++) { vtkParse_FreeValue(class_info->Typedefs[j]); }
584 if (m > 0) { free(class_info->Typedefs); }
586 m = class_info->NumberOfUsings;
587 for (j = 0; j < m; j++) { vtkParse_FreeUsing(class_info->Usings[j]); }
588 if (m > 0) { free(class_info->Usings); }
590 m = class_info->NumberOfNamespaces;
591 for (j = 0; j < m; j++) { vtkParse_FreeNamespace(class_info->Namespaces[j]); }
592 if (m > 0) { free(class_info->Namespaces); }
594 if (class_info->NumberOfItems > 0) { free(class_info->Items); }
600 /* Initialize a Namespace struct */
601 void vtkParse_InitNamespace(NamespaceInfo *name_info)
603 vtkParse_InitClass(name_info);
604 name_info->ItemType = VTK_NAMESPACE_INFO;
607 /* Copy a Namespace struct */
608 void vtkParse_CopyNamespace(NamespaceInfo *ninfo, const NamespaceInfo *orig)
610 vtkParse_CopyClass(ninfo, orig);
613 /* Free a Namespace struct */
614 void vtkParse_FreeNamespace(NamespaceInfo *namespace_info)
616 vtkParse_FreeClass(namespace_info);
620 /* This method is used for extending dynamic arrays in a progression of
621 * powers of two. If "n" reaches a power of two, then the array size is
622 * doubled so that "n" can be safely incremented. */
623 static void *array_size_check(
624 void *arraymem, size_t size, int n)
626 /* if empty, alloc for the first time */
631 /* if count is power of two, reallocate with double size */
632 else if ((n & (n-1)) == 0)
634 return realloc(arraymem, (n << 1)*size);
637 /* no reallocation, just return the original array */
642 /* Utility method to add an included file to a FileInfo */
643 void vtkParse_AddIncludeToFile(
644 FileInfo *file_info, FileInfo *include_file)
646 file_info->Includes = (FileInfo **)array_size_check(
647 (FileInfo **)file_info->Includes, sizeof(FileInfo *),
648 file_info->NumberOfIncludes);
650 file_info->Includes[file_info->NumberOfIncludes++] = include_file;
652 if (!include_file->Strings)
654 include_file->Strings = file_info->Strings;
658 /* Utility method to add a const char pointer to an array */
659 void vtkParse_AddStringToArray(
660 const char ***valueArray, int *count, const char *value)
662 *valueArray = (const char **)array_size_check(
663 (char **)*valueArray, sizeof(const char *), *count);
665 (*valueArray)[(*count)++] = value;
668 /* Utility method to add an item to an array */
669 void vtkParse_AddItemToArray(
670 ItemInfo **valueArray, int *count, parse_item_t type, int idx)
673 ItemInfo *values = *valueArray;
675 values = (ItemInfo *)array_size_check(values, sizeof(ItemInfo), n);
677 values[n].Type = type;
678 values[n].Index = idx;
680 *valueArray = values;
683 /* Add a ClassInfo to a ClassInfo */
684 void vtkParse_AddClassToClass(ClassInfo *info, ClassInfo *item)
686 vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
687 item->ItemType, info->NumberOfClasses);
688 info->Classes = (ClassInfo **)array_size_check(
689 info->Classes, sizeof(ClassInfo *), info->NumberOfClasses);
690 info->Classes[info->NumberOfClasses++] = item;
693 /* Add a FunctionInfo to a ClassInfo */
694 void vtkParse_AddFunctionToClass(ClassInfo *info, FunctionInfo *item)
696 vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
697 item->ItemType, info->NumberOfFunctions);
698 info->Functions = (FunctionInfo **)array_size_check(
699 info->Functions, sizeof(FunctionInfo *), info->NumberOfFunctions);
700 info->Functions[info->NumberOfFunctions++] = item;
703 /* Add a EnumInfo to a ClassInfo */
704 void vtkParse_AddEnumToClass(ClassInfo *info, EnumInfo *item)
706 vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
707 item->ItemType, info->NumberOfEnums);
708 info->Enums = (EnumInfo **)array_size_check(
709 info->Enums, sizeof(EnumInfo *), info->NumberOfEnums);
710 info->Enums[info->NumberOfEnums++] = item;
713 /* Add a Constant ValueInfo to a ClassInfo */
714 void vtkParse_AddConstantToClass(ClassInfo *info, ValueInfo *item)
716 vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
717 item->ItemType, info->NumberOfConstants);
718 info->Constants = (ValueInfo **)array_size_check(
719 info->Constants, sizeof(ValueInfo *), info->NumberOfConstants);
720 info->Constants[info->NumberOfConstants++] = item;
723 /* Add a Variable ValueInfo to a ClassInfo */
724 void vtkParse_AddVariableToClass(ClassInfo *info, ValueInfo *item)
726 vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
727 item->ItemType, info->NumberOfVariables);
728 info->Variables = (ValueInfo **)array_size_check(
729 info->Variables, sizeof(ValueInfo *), info->NumberOfVariables);
730 info->Variables[info->NumberOfVariables++] = item;
733 /* Add a Typedef ValueInfo to a ClassInfo */
734 void vtkParse_AddTypedefToClass(ClassInfo *info, ValueInfo *item)
736 vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
737 item->ItemType, info->NumberOfTypedefs);
738 info->Typedefs = (ValueInfo **)array_size_check(
739 info->Typedefs, sizeof(ValueInfo *), info->NumberOfTypedefs);
740 info->Typedefs[info->NumberOfTypedefs++] = item;
743 /* Add a UsingInfo to a ClassInfo */
744 void vtkParse_AddUsingToClass(ClassInfo *info, UsingInfo *item)
746 vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
747 item->ItemType, info->NumberOfUsings);
748 info->Usings = (UsingInfo **)array_size_check(
749 info->Usings, sizeof(UsingInfo *), info->NumberOfUsings);
750 info->Usings[info->NumberOfUsings++] = item;
754 /* Add a NamespaceInfo to a NamespaceInfo */
755 void vtkParse_AddNamespaceToNamespace(NamespaceInfo *info, NamespaceInfo *item)
757 vtkParse_AddItemToArray(&info->Items, &info->NumberOfItems,
758 item->ItemType, info->NumberOfNamespaces);
759 info->Namespaces = (NamespaceInfo **)array_size_check(
760 info->Namespaces, sizeof(NamespaceInfo *), info->NumberOfNamespaces);
761 info->Namespaces[info->NumberOfNamespaces++] = item;
764 /* Add a ClassInfo to a NamespaceInfo */
765 void vtkParse_AddClassToNamespace(NamespaceInfo *info, ClassInfo *item)
767 vtkParse_AddClassToClass(info, item);
770 /* Add a FunctionInfo to a NamespaceInfo */
771 void vtkParse_AddFunctionToNamespace(NamespaceInfo *info, FunctionInfo *item)
773 vtkParse_AddFunctionToClass(info, item);
776 /* Add a EnumInfo to a NamespaceInfo */
777 void vtkParse_AddEnumToNamespace(NamespaceInfo *info, EnumInfo *item)
779 vtkParse_AddEnumToClass(info, item);
782 /* Add a Constant ValueInfo to a NamespaceInfo */
783 void vtkParse_AddConstantToNamespace(NamespaceInfo *info, ValueInfo *item)
785 vtkParse_AddConstantToClass(info, item);
788 /* Add a Variable ValueInfo to a NamespaceInfo */
789 void vtkParse_AddVariableToNamespace(NamespaceInfo *info, ValueInfo *item)
791 vtkParse_AddVariableToClass(info, item);
794 /* Add a Typedef ValueInfo to a NamespaceInfo */
795 void vtkParse_AddTypedefToNamespace(NamespaceInfo *info, ValueInfo *item)
797 vtkParse_AddTypedefToClass(info, item);
800 /* Add a UsingInfo to a NamespaceInfo */
801 void vtkParse_AddUsingToNamespace(NamespaceInfo *info, UsingInfo *item)
803 vtkParse_AddUsingToClass(info, item);
807 /* Add a ValueInfo parameter to a FunctionInfo */
808 void vtkParse_AddParameterToFunction(FunctionInfo *info, ValueInfo *item)
810 info->Parameters = (ValueInfo **)array_size_check(
811 info->Parameters, sizeof(ValueInfo *), info->NumberOfParameters);
812 info->Parameters[info->NumberOfParameters++] = item;
816 /* Add a ValueInfo to a TemplateInfo */
817 void vtkParse_AddParameterToTemplate(TemplateInfo *info, ValueInfo *item)
819 info->Parameters = (ValueInfo **)array_size_check(
820 info->Parameters, sizeof(ValueInfo *), info->NumberOfParameters);
821 info->Parameters[info->NumberOfParameters++] = item;
825 /* Add default constructors if they do not already exist */
826 void vtkParse_AddDefaultConstructors(ClassInfo *cls, StringCache *cache)
832 int default_constructor = 1;
833 int copy_constructor = 1;
837 if (cls == NULL || cls->Name == NULL)
842 n = cls->NumberOfFunctions;
843 for (i = 0; i < n; i++)
845 func = cls->Functions[i];
846 if (func->Name && strcmp(func->Name, cls->Name) == 0)
848 default_constructor = 0;
850 if (func->NumberOfParameters == 1)
852 param = func->Parameters[0];
854 strcmp(param->Class, cls->Name) == 0 &&
855 (param->Type & VTK_PARSE_POINTER_MASK) == 0)
857 copy_constructor = 0;
863 if (default_constructor)
865 func = (FunctionInfo *)malloc(sizeof(FunctionInfo));
866 vtkParse_InitFunction(func);
867 func->Class = cls->Name;
868 func->Name = cls->Name;
869 k = strlen(cls->Name);
870 tname = vtkParse_NewString(cache, k + 2);
871 strcpy(tname, cls->Name);
872 strcpy(&tname[k], "()");
873 func->Signature = tname;
874 vtkParse_AddFunctionToClass(cls, func);
877 if (copy_constructor)
883 /* specialize the name */
884 n = cls->Template->NumberOfParameters;
886 k = strlen(cls->Name) + 2;
887 for (i = 0; i < n; i++)
889 if (cls->Template->Parameters[i]->Name)
891 k += strlen(cls->Template->Parameters[i]->Name) + 2;
894 tname = vtkParse_NewString(cache, k);
895 strcpy(tname, cls->Name);
898 for (i = 0; i < n; i++)
900 if (cls->Template->Parameters[i]->Name)
902 strcpy(&tname[k], cls->Template->Parameters[i]->Name);
903 k += strlen(cls->Template->Parameters[i]->Name);
916 func = (FunctionInfo *)malloc(sizeof(FunctionInfo));
917 vtkParse_InitFunction(func);
918 func->Class = cls->Name;
919 func->Name = cls->Name;
920 k = strlen(cls->Name);
922 tname = vtkParse_NewString(cache, k + l + 9);
923 strcpy(tname, cls->Name);
924 strcpy(&tname[k], "(const &");
925 strcpy(&tname[k+8], ccname);
926 strcpy(&tname[k+8+l], ")");
927 func->Signature = tname;
928 param = (ValueInfo *)malloc(sizeof(ValueInfo));
929 vtkParse_InitValue(param);
930 param->Type = (VTK_PARSE_OBJECT_REF | VTK_PARSE_CONST);
931 param->Class = ccname;
932 vtkParse_AddParameterToFunction(func, param);
933 vtkParse_AddFunctionToClass(cls, func);