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;
129 func->IsExplicit = 0;
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;
140 func->ArrayFailure = 0;
142 func->IsProtected = 0;
144 for (i = 0; i < MAX_ARGS; i++)
146 func->ArgTypes[i] = 0;
147 func->ArgClasses[i] = 0;
148 func->ArgCounts[i] = 0;
153 /* Copy a Function struct */
154 void vtkParse_CopyFunction(FunctionInfo *func, const FunctionInfo *orig)
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;
168 func->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
169 vtkParse_CopyTemplate(func->Template, orig->Template);
172 n = orig->NumberOfParameters;
173 func->NumberOfParameters = n;
176 func->Parameters = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
177 for (i = 0; i < n; i++)
179 func->Parameters[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
180 vtkParse_CopyValue(func->Parameters[i], orig->Parameters[i]);
184 func->ReturnValue = NULL;
185 if (orig->ReturnValue)
187 func->ReturnValue = (ValueInfo *)malloc(sizeof(ValueInfo));
188 vtkParse_CopyValue(func->ReturnValue, orig->ReturnValue);
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;
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;
216 for (i = 0; i < MAX_ARGS; i++)
218 func->ArgTypes[i] = orig->ArgTypes[i];
219 func->ArgClasses[i] = orig->ArgClasses[i];
220 func->ArgCounts[i] = orig->ArgCounts[i];
225 /* Free a Function struct */
226 void vtkParse_FreeFunction(FunctionInfo *function_info)
230 if (function_info->Template)
232 vtkParse_FreeTemplate(function_info->Template);
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); }
239 if (function_info->ReturnValue)
241 vtkParse_FreeValue(function_info->ReturnValue);
248 /* Initialize a Value struct */
249 void vtkParse_InitValue(ValueInfo *val)
251 val->ItemType = VTK_VARIABLE_INFO;
252 val->Access = VTK_ACCESS_PUBLIC;
259 val->CountHint = NULL;
260 val->NumberOfDimensions = 0;
261 val->Dimensions = NULL;
262 val->Function = NULL;
263 val->Template = NULL;
269 /* Copy a Value struct */
270 void vtkParse_CopyValue(ValueInfo *val, const ValueInfo *orig)
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;
284 n = orig->NumberOfDimensions;
285 val->NumberOfDimensions = n;
288 val->Dimensions = (const char **)malloc(n*sizeof(char *));
289 for (i = 0; i < n; i++)
291 val->Dimensions[i] = orig->Dimensions[i];
295 val->Function = NULL;
298 val->Function = (FunctionInfo *)malloc(sizeof(FunctionInfo));
299 vtkParse_CopyFunction(val->Function, orig->Function);
302 val->Template = NULL;
305 val->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
306 vtkParse_CopyTemplate(val->Template, orig->Template);
309 val->IsStatic = orig->IsStatic;
310 val->IsEnum = orig->IsEnum;
311 val->IsPack = orig->IsPack;
314 /* Free a Value struct */
315 void vtkParse_FreeValue(ValueInfo *value_info)
317 if (value_info->NumberOfDimensions)
319 free((char **)value_info->Dimensions);
321 if (value_info->Function)
323 vtkParse_FreeFunction(value_info->Function);
325 if (value_info->Template)
327 vtkParse_FreeTemplate(value_info->Template);
334 /* Initialize an Enum struct */
335 void vtkParse_InitEnum(EnumInfo *item)
337 vtkParse_InitClass(item);
338 item->ItemType = VTK_ENUM_INFO;
341 /* Copy an Enum struct */
342 void vtkParse_CopyEnum(EnumInfo *item, const EnumInfo *orig)
344 vtkParse_CopyClass(item, orig);
347 /* Free an Enum struct */
348 void vtkParse_FreeEnum(EnumInfo *enum_info)
354 /* Initialize a Using struct */
355 void vtkParse_InitUsing(UsingInfo *item)
357 item->ItemType = VTK_USING_INFO;
358 item->Access = VTK_ACCESS_PUBLIC;
360 item->Comment = NULL;
364 /* Copy a Using struct */
365 void vtkParse_CopyUsing(UsingInfo *item, const UsingInfo *orig)
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;
374 /* Free a Using struct */
375 void vtkParse_FreeUsing(UsingInfo *using_info)
381 /* Initialize a Class struct */
382 void vtkParse_InitClass(ClassInfo *cls)
384 cls->ItemType = VTK_CLASS_INFO;
385 cls->Access = VTK_ACCESS_PUBLIC;
388 cls->Template = NULL;
389 cls->NumberOfSuperClasses = 0;
390 cls->SuperClasses = NULL;
391 cls->NumberOfItems = 0;
393 cls->NumberOfClasses = 0;
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;
403 cls->NumberOfTypedefs = 0;
404 cls->Typedefs = NULL;
405 cls->NumberOfUsings = 0;
407 cls->NumberOfNamespaces = 0;
408 cls->Namespaces = NULL;
414 /* Copy a Class struct */
415 void vtkParse_CopyClass(ClassInfo *cls, const ClassInfo *orig)
419 cls->ItemType = orig->ItemType;
420 cls->Access = orig->Access;
421 cls->Name = orig->Name;
422 cls->Comment = orig->Comment;
423 cls->Template = NULL;
427 cls->Template = (TemplateInfo *)malloc(sizeof(TemplateInfo));
428 vtkParse_CopyTemplate(cls->Template, orig->Template);
431 n = orig->NumberOfSuperClasses;
432 cls->NumberOfSuperClasses = n;
435 cls->SuperClasses = (const char **)malloc(n*sizeof(char *));
436 for (i = 0; i < n; i++)
438 cls->SuperClasses[i] = orig->SuperClasses[i];
442 n = orig->NumberOfItems;
443 cls->NumberOfItems = n;
446 cls->Items = (ItemInfo *)malloc(n*sizeof(ItemInfo));
447 for (i = 0; i < n; i++)
449 cls->Items[i].Type = orig->Items[i].Type;
450 cls->Items[i].Index = orig->Items[i].Index;
454 n = orig->NumberOfClasses;
455 cls->NumberOfClasses = n;
458 cls->Classes = (ClassInfo **)malloc(n*sizeof(ClassInfo *));
459 for (i = 0; i < n; i++)
461 cls->Classes[i] = (ClassInfo *)malloc(sizeof(ClassInfo));
462 vtkParse_CopyClass(cls->Classes[i], orig->Classes[i]);
466 n = orig->NumberOfFunctions;
467 cls->NumberOfFunctions = n;
470 cls->Functions = (FunctionInfo **)malloc(n*sizeof(FunctionInfo *));
471 for (i = 0; i < n; i++)
473 cls->Functions[i] = (FunctionInfo *)malloc(sizeof(FunctionInfo));
474 vtkParse_CopyFunction(cls->Functions[i], orig->Functions[i]);
478 n = orig->NumberOfConstants;
479 cls->NumberOfConstants = n;
482 cls->Constants = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
483 for (i = 0; i < n; i++)
485 cls->Constants[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
486 vtkParse_CopyValue(cls->Constants[i], orig->Constants[i]);
490 n = orig->NumberOfVariables;
491 cls->NumberOfVariables = n;
494 cls->Variables = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
495 for (i = 0; i < n; i++)
497 cls->Variables[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
498 vtkParse_CopyValue(cls->Variables[i], orig->Variables[i]);
502 n = orig->NumberOfEnums;
503 cls->NumberOfEnums = n;
506 cls->Enums = (EnumInfo **)malloc(n*sizeof(EnumInfo *));
507 for (i = 0; i < n; i++)
509 cls->Enums[i] = (EnumInfo *)malloc(sizeof(EnumInfo));
510 vtkParse_CopyEnum(cls->Enums[i], orig->Enums[i]);
514 n = orig->NumberOfTypedefs;
515 cls->NumberOfTypedefs = n;
518 cls->Typedefs = (ValueInfo **)malloc(n*sizeof(ValueInfo *));
519 for (i = 0; i < n; i++)
521 cls->Typedefs[i] = (ValueInfo *)malloc(sizeof(ValueInfo));
522 vtkParse_CopyValue(cls->Typedefs[i], orig->Typedefs[i]);
526 n = orig->NumberOfUsings;
527 cls->NumberOfUsings = n;
530 cls->Usings = (UsingInfo **)malloc(n*sizeof(UsingInfo *));
531 for (i = 0; i < n; i++)
533 cls->Usings[i] = (UsingInfo *)malloc(sizeof(UsingInfo));
534 vtkParse_CopyUsing(cls->Usings[i], orig->Usings[i]);
538 n = orig->NumberOfNamespaces;
539 cls->NumberOfNamespaces = n;
542 cls->Namespaces = (NamespaceInfo **)malloc(n*sizeof(NamespaceInfo *));
543 for (i = 0; i < n; i++)
545 cls->Namespaces[i] = (NamespaceInfo *)malloc(sizeof(NamespaceInfo));
546 vtkParse_CopyNamespace(cls->Namespaces[i], orig->Namespaces[i]);
550 cls->IsAbstract = orig->IsAbstract;
551 cls->IsFinal = orig->IsFinal;
552 cls->HasDelete = orig->HasDelete;
555 /* Free a Class struct */
556 void vtkParse_FreeClass(ClassInfo *class_info)
560 if (class_info->Template) { vtkParse_FreeTemplate(class_info->Template); }
562 m = class_info->NumberOfSuperClasses;
563 if (m > 0) { free((char **)class_info->SuperClasses); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
597 if (class_info->NumberOfItems > 0) { free(class_info->Items); }
603 /* Initialize a Namespace struct */
604 void vtkParse_InitNamespace(NamespaceInfo *name_info)
606 vtkParse_InitClass(name_info);
607 name_info->ItemType = VTK_NAMESPACE_INFO;
610 /* Copy a Namespace struct */
611 void vtkParse_CopyNamespace(NamespaceInfo *ninfo, const NamespaceInfo *orig)
613 vtkParse_CopyClass(ninfo, orig);
616 /* Free a Namespace struct */
617 void vtkParse_FreeNamespace(NamespaceInfo *namespace_info)
619 vtkParse_FreeClass(namespace_info);
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)
629 /* if empty, alloc for the first time */
634 /* if count is power of two, reallocate with double size */
635 else if ((n & (n-1)) == 0)
637 return realloc(arraymem, (n << 1)*size);
640 /* no reallocation, just return the original array */
645 /* Utility method to add an included file to a FileInfo */
646 void vtkParse_AddIncludeToFile(
647 FileInfo *file_info, FileInfo *include_file)
649 file_info->Includes = (FileInfo **)array_size_check(
650 (FileInfo **)file_info->Includes, sizeof(FileInfo *),
651 file_info->NumberOfIncludes);
653 file_info->Includes[file_info->NumberOfIncludes++] = include_file;
655 if (!include_file->Strings)
657 include_file->Strings = file_info->Strings;
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)
665 *valueArray = (const char **)array_size_check(
666 (char **)*valueArray, sizeof(const char *), *count);
668 (*valueArray)[(*count)++] = value;
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)
676 ItemInfo *values = *valueArray;
678 values = (ItemInfo *)array_size_check(values, sizeof(ItemInfo), n);
680 values[n].Type = type;
681 values[n].Index = idx;
683 *valueArray = values;
686 /* Add a ClassInfo to a ClassInfo */
687 void vtkParse_AddClassToClass(ClassInfo *info, ClassInfo *item)
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;
696 /* Add a FunctionInfo to a ClassInfo */
697 void vtkParse_AddFunctionToClass(ClassInfo *info, FunctionInfo *item)
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;
706 /* Add a EnumInfo to a ClassInfo */
707 void vtkParse_AddEnumToClass(ClassInfo *info, EnumInfo *item)
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;
716 /* Add a Constant ValueInfo to a ClassInfo */
717 void vtkParse_AddConstantToClass(ClassInfo *info, ValueInfo *item)
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;
726 /* Add a Variable ValueInfo to a ClassInfo */
727 void vtkParse_AddVariableToClass(ClassInfo *info, ValueInfo *item)
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;
736 /* Add a Typedef ValueInfo to a ClassInfo */
737 void vtkParse_AddTypedefToClass(ClassInfo *info, ValueInfo *item)
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;
746 /* Add a UsingInfo to a ClassInfo */
747 void vtkParse_AddUsingToClass(ClassInfo *info, UsingInfo *item)
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;
757 /* Add a NamespaceInfo to a NamespaceInfo */
758 void vtkParse_AddNamespaceToNamespace(NamespaceInfo *info, NamespaceInfo *item)
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;
767 /* Add a ClassInfo to a NamespaceInfo */
768 void vtkParse_AddClassToNamespace(NamespaceInfo *info, ClassInfo *item)
770 vtkParse_AddClassToClass(info, item);
773 /* Add a FunctionInfo to a NamespaceInfo */
774 void vtkParse_AddFunctionToNamespace(NamespaceInfo *info, FunctionInfo *item)
776 vtkParse_AddFunctionToClass(info, item);
779 /* Add a EnumInfo to a NamespaceInfo */
780 void vtkParse_AddEnumToNamespace(NamespaceInfo *info, EnumInfo *item)
782 vtkParse_AddEnumToClass(info, item);
785 /* Add a Constant ValueInfo to a NamespaceInfo */
786 void vtkParse_AddConstantToNamespace(NamespaceInfo *info, ValueInfo *item)
788 vtkParse_AddConstantToClass(info, item);
791 /* Add a Variable ValueInfo to a NamespaceInfo */
792 void vtkParse_AddVariableToNamespace(NamespaceInfo *info, ValueInfo *item)
794 vtkParse_AddVariableToClass(info, item);
797 /* Add a Typedef ValueInfo to a NamespaceInfo */
798 void vtkParse_AddTypedefToNamespace(NamespaceInfo *info, ValueInfo *item)
800 vtkParse_AddTypedefToClass(info, item);
803 /* Add a UsingInfo to a NamespaceInfo */
804 void vtkParse_AddUsingToNamespace(NamespaceInfo *info, UsingInfo *item)
806 vtkParse_AddUsingToClass(info, item);
810 /* Add a ValueInfo parameter to a FunctionInfo */
811 void vtkParse_AddParameterToFunction(FunctionInfo *info, ValueInfo *item)
813 info->Parameters = (ValueInfo **)array_size_check(
814 info->Parameters, sizeof(ValueInfo *), info->NumberOfParameters);
815 info->Parameters[info->NumberOfParameters++] = item;
819 /* Add a ValueInfo to a TemplateInfo */
820 void vtkParse_AddParameterToTemplate(TemplateInfo *info, ValueInfo *item)
822 info->Parameters = (ValueInfo **)array_size_check(
823 info->Parameters, sizeof(ValueInfo *), info->NumberOfParameters);
824 info->Parameters[info->NumberOfParameters++] = item;
828 /* Add default constructors if they do not already exist */
829 void vtkParse_AddDefaultConstructors(ClassInfo *cls, StringCache *cache)
835 int default_constructor = 1;
836 int copy_constructor = 1;
840 if (cls == NULL || cls->Name == NULL)
845 n = cls->NumberOfFunctions;
846 for (i = 0; i < n; i++)
848 func = cls->Functions[i];
849 if (func->Name && strcmp(func->Name, cls->Name) == 0)
851 default_constructor = 0;
853 if (func->NumberOfParameters == 1)
855 param = func->Parameters[0];
857 strcmp(param->Class, cls->Name) == 0 &&
858 (param->Type & VTK_PARSE_POINTER_MASK) == 0)
860 copy_constructor = 0;
866 if (default_constructor)
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);
880 if (copy_constructor)
886 /* specialize the name */
887 n = cls->Template->NumberOfParameters;
889 k = strlen(cls->Name) + 2;
890 for (i = 0; i < n; i++)
892 if (cls->Template->Parameters[i]->Name)
894 k += strlen(cls->Template->Parameters[i]->Name) + 2;
897 tname = vtkParse_NewString(cache, k);
898 strcpy(tname, cls->Name);
901 for (i = 0; i < n; i++)
903 if (cls->Template->Parameters[i]->Name)
905 strcpy(&tname[k], cls->Template->Parameters[i]->Name);
906 k += strlen(cls->Template->Parameters[i]->Name);
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);
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);