1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: vtkParseExtras.h
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) 2011 David Gobbi.
18 Contributed to the VisualizationToolkit by the author in May 2011
19 under the terms of the Visualization Toolkit 2008 copyright.
20 -------------------------------------------------------------------------*/
23 * This file contains extra utilities for parsing and wrapping.
26 #ifndef VTK_PARSE_EXTRAS_H
27 #define VTK_PARSE_EXTRAS_H
36 * Skip over a sequence of characters that begin with an alphabetic
37 * character or an underscore, and include only alphanumeric
38 * characters or underscores. Return the number of characters.
40 size_t vtkParse_IdentifierLength(const char *text);
43 * Skip over a name, including any namespace prefixes and
44 * any template arguments. Return the number of characters.
46 size_t vtkParse_NameLength(const char *text);
49 * Skip over a name, including any template parameters, but stopping
50 * if a '::' is encoutered. Return the number of characters.
52 size_t vtkParse_UnscopedNameLength(const char *text);
55 * Skip over a literal, which may be a number, a char in single
56 * quotes, a string in double quotes, or a name, or a name followed
57 * by arguments in parentheses.
59 size_t vtkParse_LiteralLength(const char *text);
62 * Get a type from a type name, and return the number of characters used.
63 * If the "classname" argument is not NULL, then it is used to return
64 * the short name for the type, e.g. "long int" becomes "long", while
65 * typedef names and class names are returned unchanged. If "const"
66 * appears in the type name, then the const bit flag is set for the
67 * type, but "const" will not appear in the returned classname.
69 size_t vtkParse_BasicTypeFromString(
70 const char *text, unsigned int *type,
71 const char **classname, size_t *classname_len);
74 * Generate a ValueInfo by parsing the type from the provided text.
75 * Only simple text strings are supported, e.g. "const T **".
77 void vtkParse_ValueInfoFromString(ValueInfo *val, const char *text);
80 * Expand a typedef within a variable, parameter, or typedef declaration.
81 * The expansion is done in-place.
83 void vtkParse_ExpandTypedef(ValueInfo *valinfo, ValueInfo *typedefinfo);
86 * Expand any unrecognized types within a variable, parameter, or typedef
87 * that match any of the supplied typedefs. The expansion is done in-place.
89 void vtkParse_ExpandTypedefs(
90 ValueInfo *valinfo, int n, const char *name[], const char *val[],
91 ValueInfo *typedefinfo[]);
94 * Wherever one of the specified names exists inside a Value or inside
95 * a Dimension size, replace it with the corresponding val string.
96 * This is used to replace constants with their values.
98 void vtkParse_ExpandValues(
99 ValueInfo *valinfo, int n, const char *name[], const char *val[]);
102 * Search for all occurences of "name" and replace with the corresponding
103 * "val", return the initial string if no replacements occurred, otherwise
104 * return a new string allocated with malloc.
106 const char *vtkParse_StringReplace(
107 const char *str1, int n, const char *name[], const char *val[]);
110 * Extract the class name and template args from a templated
111 * class type ID. Returns the full number of characters that
112 * were consumed during the decomposition.
114 size_t vtkParse_DecomposeTemplatedType(
115 const char *text, const char **classname,
116 int n, const char ***args, const char *defaults[]);
119 * Free the list of strings returned by ExtractTemplateArgs.
121 void vtkParse_FreeTemplateDecomposition(
122 const char *classname, int n, const char **args);
125 * Instantiate a class template by substituting the provided arguments
126 * for the template parameters. If "n" is less than the number of template
127 * parameters, then default parameter values (if present) will be used.
128 * If an error occurs, the error will be printed to stderr and NULL will
131 void vtkParse_InstantiateClassTemplate(
132 ClassInfo *data, int n, const char *args[]);
135 * Instantiate a function or class method template by substituting the
136 * provided arguments for the template parameters. If "n" is less than
137 * the number of template parameters, then default parameter values
138 * (if present) will be used. If an error occurs, the error will be
139 * printed to stderr and NULL will be returned.
141 void vtkParse_IntantiateFunctionTemplate(
142 FunctionInfo *data, int n, const char *args);
145 * Generate a mangled name for a type, use gcc ia64 ABI.
146 * The result is placed in new_name, which must be large enough
147 * to accept the result.
149 size_t vtkParse_MangledTypeName(const char *name, char *new_name);
152 * Generate a mangled name for a literal. Only handles decimal
153 * integer literals. It guesses type from suffix "u", "ul",
154 * "ull", "l", "ll" so only certain types are supported.
156 size_t vtkParse_MangledLiteral(const char *name, char *new_name);
159 * Get a zero-terminated array of the types in vtkTemplateMacro.
161 const char **vtkParse_GetTemplateMacroTypes();
164 * Get a zero-terminated array of the types in vtkArray.
166 const char **vtkParse_GetArrayTypes();