• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..04-Nov-2021-

README.mdH A D04-Nov-202110 KiB249174

lex.yy.cH A D04-Nov-2021145.7 KiB4,7363,676

vtk.moduleH A D04-Nov-202171 65

vtkHTML.cH A D04-Nov-20214.9 KiB184159

vtkParse.hH A D04-Nov-20212.8 KiB11338

vtkParse.lH A D04-Nov-202136.7 KiB1,7621,434

vtkParse.tab.cH A D04-Nov-2021325.4 KiB10,5558,083

vtkParse.yH A D04-Nov-2021129.3 KiB5,1654,033

vtkParseAttributes.hH A D04-Nov-20211.2 KiB328

vtkParseData.cH A D04-Nov-202127 KiB1,083878

vtkParseData.hH A D04-Nov-202113 KiB450312

vtkParseExtras.cH A D04-Nov-202140.1 KiB1,7611,491

vtkParseExtras.hH A D04-Nov-20218.8 KiB23767

vtkParseHierarchy.cH A D04-Nov-202132.8 KiB1,3221,054

vtkParseHierarchy.hH A D04-Nov-20216.6 KiB19971

vtkParseJava.cH A D04-Nov-202131.4 KiB1,1971,026

vtkParseJavaBeans.cH A D04-Nov-202122.3 KiB809673

vtkParseMain.cH A D04-Nov-202113.9 KiB569443

vtkParseMain.hH A D04-Nov-20213 KiB9631

vtkParseMangle.cH A D04-Nov-20217.4 KiB360289

vtkParseMangle.hH A D04-Nov-20211.7 KiB5916

vtkParseMerge.cH A D04-Nov-202120.5 KiB848685

vtkParseMerge.hH A D04-Nov-20213.1 KiB9432

vtkParsePreprocess.cH A D04-Nov-2021109.4 KiB4,8244,229

vtkParsePreprocess.hH A D04-Nov-202110.3 KiB299119

vtkParseString.cH A D04-Nov-202117.8 KiB903779

vtkParseString.hH A D04-Nov-20218.8 KiB268112

vtkParseSystem.cH A D04-Nov-202110.4 KiB404295

vtkParseSystem.hH A D04-Nov-20212 KiB7328

vtkParseType.hH A D04-Nov-20218.8 KiB277140

vtkPrint.cH A D04-Nov-20212 KiB4338

vtkWrap.cH A D04-Nov-202133.1 KiB1,2931,014

vtkWrap.hH A D04-Nov-20219.8 KiB29780

vtkWrapHierarchy.cH A D04-Nov-202121.7 KiB982709

vtkWrapJava.cH A D04-Nov-202144.7 KiB1,5901,361

vtkWrapPython.cH A D04-Nov-202115.8 KiB578418

vtkWrapPythonClass.cH A D04-Nov-202116.5 KiB629492

vtkWrapPythonClass.hH A D04-Nov-20211.5 KiB3912

vtkWrapPythonConstant.cH A D04-Nov-20219.7 KiB344258

vtkWrapPythonConstant.hH A D04-Nov-20211.2 KiB3310

vtkWrapPythonEnum.cH A D04-Nov-20218.6 KiB297232

vtkWrapPythonEnum.hH A D04-Nov-20211.6 KiB4314

vtkWrapPythonInit.cH A D04-Nov-20216.6 KiB238194

vtkWrapPythonMethod.cH A D04-Nov-202136.6 KiB1,3131,032

vtkWrapPythonMethod.hH A D04-Nov-20211.7 KiB4415

vtkWrapPythonMethodDef.cH A D04-Nov-202134.7 KiB1,090872

vtkWrapPythonMethodDef.hH A D04-Nov-20211.2 KiB329

vtkWrapPythonNamespace.cH A D04-Nov-20211.8 KiB7039

vtkWrapPythonNamespace.hH A D04-Nov-2021971 287

vtkWrapPythonOverload.cH A D04-Nov-202115.7 KiB614433

vtkWrapPythonOverload.hH A D04-Nov-20211.6 KiB3914

vtkWrapPythonTemplate.cH A D04-Nov-202110.5 KiB427342

vtkWrapPythonTemplate.hH A D04-Nov-20211.1 KiB329

vtkWrapPythonType.cH A D04-Nov-202125.5 KiB911738

vtkWrapPythonType.hH A D04-Nov-20211.1 KiB329

vtkWrapText.cH A D04-Nov-202130.6 KiB1,2801,052

vtkWrapText.hH A D04-Nov-20212.6 KiB7820

vtkcompiletools.moduleH A D04-Nov-202183 65

README.md

1# The Wrapping Tools
2
3The wrapping tools consist of executables that pull information from C++
4header files, and produce wrapper code that allows the C++ interfaces to
5be used from other programming languages (Python and Java).  One can think
6of the wrappers as having a front-end that parses C++ header files, and a
7back-end that produces language-specific glue code.
8
9All of the code in this directory is C, rather than C++.  One might think
10this is silly, since the front-end parses C++ .h files and the back-end
11generates .cxx files.  The original reason for this is that the parser
12uses lex and yacc, which are written in C and previously could not easily
13be linked into C++ programs.
14
15
16## The C++ Parser
17
18### vtkParse
19
20The header vtkParse.h provides a C API for the C++ parser that wrappers use
21to read the VTK header files.  The parser consists of three critical pieces:
22a preprocessor (see below), a lex-based lexical analyzer (lex.yy.c, generated
23from vtkParse.l) and a bison-based glr parser (vtkParse.tab.c, generated from
24vtkParse.y).  Instructions on rebuilding the parser are provided at the end
25of this document.
26
27### vtkParsePreprocess
28
29This is a preprocessor that can run independently of the parser.  In general,
30the parser does not recursively parse `#include` files, but it does
31recursively preprocess them in order to gather all of the macro definitions
32within them.
33
34### vtkParseString
35
36This provides low-level string handling routines that are used by the parser
37and the preprocessor.  Most importantly, it contains a C++ tokenizer.  It also
38contains a cache for storing strings (type names, etc.) that are
39encountered during the parse.
40
41### vtkParseSystem
42
43This contains utilities for file system access.  One of its functionalities
44is to manage a cache of where header files are located on the file system, so
45that header file lookups can be done inexpensively even on slow file systems.
46
47### vtkParseType
48
49This is a header file that defines numerical constants that we use to identify
50C++ types, type qualifiers, and specifiers.  These contants are used in the
51vtkParseData data structures described below.
52
53### vtkParseAttributes
54
55This is a header file that defines numerical constants for wrapper-specific
56attributes that can be added to declarations in the VTK header files.  For
57example, `[[vtk::wrapexclude]]` and ``[[vtk::deprecated]]``.  These attribute
58constants are stored in the vtkParseData data structures.
59
60### vtkParseData
61
62The data structures defined in vtkParseData.h are used for the output of the
63parser.  This header provies data structures for namespaces, classes, methods,
64typedefs, and for other entities that can be declared in a C++ file.  The
65wrappers convert this data into wrapper code.
66
67
68## Parser Utilities
69
70### vtkParseExtras
71
72This file provides routines for managing certain abstractions of the data that
73is produced by the parser.  Most specifically, it provides facilities for
74expanding typedefs and for instantiating templates.  Its code is not pretty.
75
76### vtkParseMerge
77
78This provides methods for dealing with method resolution order.  It defines
79a data structure for managing a class along with all the classes it derives
80from.  It is needed for managing tricky details relating to inheritance,
81such as "using" declarations, overrides, virtual methods, etc.
82
83### vtkParseMangle
84
85The Python wrappers rely on name-mangling routines to convert C++ names into
86names that can be used in Python.  The mangling is done according to the
87rules of the IA64 ABI (this same mangling is used to convert C++ APIs into
88C APIs)
89
90### vtkParseHierarchy
91
92A hierarchy file is a text file that lists information about all the types
93defined in a VTK module.  The wrappers use these files to look up types from
94names.  Through the use of vtkParseHierarchy, the wrappers can get detailed
95information about a type even if the header file only contains a forward
96reference, as long as the type is defined somewhere in another header.
97
98### vtkParseMain
99
100A common main() function for use by wrapper tool executables.  It provides a
101standard set of command-line options as well as response-file handling.  It
102also invokes the parser.
103
104
105## Wrapper Utilities
106
107### vtkWrap
108
109This has functions that are common to the wrapper tools for all the wrapper
110languages.  Unlikely vtkParse, it deals with the generation of code, rather
111than the parsing of code.
112
113### vtkWrapText
114
115This has functions for automatically generating documentation from the
116header files that are parsed.  It produces the Python docstrings.
117
118
119## Python-Specific Utilities
120
121These are named according to the pieces of wrapper code they produce.
122
123* __vtkWrapPythonClass__ creates type objects for vtkObjectBase classes
124* __vtkWrapPythonType__ creates type objects for other wrapped classes
125* __vtkWrapPythonMethod__ for calling C++ methods from Python
126* __vtkWrapPythonOverload__ maps a Python method to multiple C++ overloads
127* __vtkWrapPythonMethodDef__ generates the method tables for wrapped classes
128* __vtkWrapPythonTemplate__ for wrapping of C++ class templates
129* __vtkWrapPythonNamespace__ for wrapping namespaces
130* __vtkWrapPythonEnum__ creates type objects for enum types
131* __vtkWrapPythonConstant__ adds C++ constants to Python classes, namespaces
132
133
134## Python Wrapper Executables
135
136### vtkWrapPython
137
138This executable will parse the C++ declarations from a header file and
139produce wrapper code that can be linked into a Python extension module.
140
141### vtkWrapPythonInit
142
143This will produce the PyInit entry point for a Python extension module,
144as well as code for loading all the dependent modules.  The .cxx file
145produced by vtkWrapPythonInit is linked together to the .cxx files that
146are produced by vtkWrapPython to create the module.
147
148
149## Java Wrapper Executables
150
151* __vtkWrapJava__ produces C++ wrapper code that uses the JNI
152* __vtkParseJava__ produces Java code that sits on top of the C++ code
153
154
155## Other Executables
156
157### vtkWrapHierarchy
158
159This will slurp up all the header files in a VTK module and produce a
160"hierarchy.txt" file that provides information about all of the types that
161are defined in that module.  In other words, it provides a summary of the
162module's contents.  The Python and Java wrapper executables rely on these
163"hierarchy.txt" files in order to look up types by name.
164
165
166## Rebuilding the Parser
167
168The code for the C++ parser is generated from the files vtkParse.l and
169vtkParse.y with the classic compiler-generator tools lex and yacc (or,
170more specifically, with their modern incarnations flex and bison).  These
171tools are readily available on macOS and Linux systems, and they can be
172installed (with some difficulty) on Windows systems.
173
174The C code that flex and bison generate is not styled according to VTK
175standards, and must be cleaned up in order to compile without warnings and
176in order to satisfy VTK's git hooks and style checks.
177
178### vtkParse.l
179
180The file vtkParse.l contains regular expressions for tokenizing a C++
181header file.  It is used to generate the file lex.yy.c, which is directly
182included (i.e. as a C file) by the main parser file, vtkParse.tab.c.
183
184To generate lex.yy.c from vtkParse.l, use the following steps.
185
1861. Get a copy of flex, version 2.6.4 or later
1872. Run `flex --nodefault --noline -olex.yy.c vtkParse.l`
1883. In an editor, remove blank lines from the top and bottom of lex.yy.c
1894. Replace all tabs with two spaces (e.g. `:%s/\t/  /g` in vi)
1905. Remove spaces from the ends of lines (e.g. `:%s/  *$//` in vi)
1916. Remove `struct yy_trans_info`, which is used nowhere in the code
1927. Add the following code at line 23 (after "`end standard C headers`")
193
194    #ifndef __cplusplus
195    extern int isatty(int);
196    #endif /* __cplusplus */
197
198Finally, if you have clang-format installed, you can use it to re-style
199the code.
200
201### vtkParse.y
202
203The file vtkParse.y contains the rules for parsing a C++ header file.
204Many of the rules in this file have the same names as in the description
205of the grammar in the official ISO standard.  The file vtkParse.y is
206used to generate the file vtkParse.tab.c, which contains the parser.
207
2081. Get a copy of bison 3.2.3 or later, it has a yacc-compatible front end.
2092. Run `bison --no-lines -b vtkParse vtkParse.y`, to generate vtkParse.tab.c
2103. In an editor, replace every `static inline` in vtkParse.tab.c with `static`
2114. Replace `#if ! defined lint || defined __GNUC__` with `#if 1`
2125. remove `YY_ATTRIBUTE_UNUSED` from `yyfillin`, `yyfill`, and `yynormal`
2136. comment out the `break;` after `return yyreportAmbiguity`
2147. replace `(1-yyrhslen)` with `(1-(int)yyrhslen)`
2158. replace `sizeof yynewStates[0]` with `sizeof (yyGLRState*)`
2169. replace `sizeof yynewLookaheadNeeds[0]` with `sizeof (yybool)`
217
218If you are familiar with "diff" and "patch" and if you have clang-format,
219you can automate these code changes as follows.  For this, you must use
220exactly version 3.2.3 of bison to ensure that the code that is produced
221is as similar as possible to what is currently in the VTK repository.
222
2231. Run bison (as above) on the vtkParse.y from the master branch
2242. Use clang-format-8 to re-style vtkParse.tab.c to match VTK code style
2253. Use "git diff -R vtkParse.tab.c" to produce a patch file
226
227If done correctly, this will produce a patch file that contains all the
228changes above (steps 3 through 9 in the original list).  Load the patch
229file into a text editor to verify that this is so, and remove any superfluous
230changes from the patch file.
231
232Then, switch to your new vtkParse.y (the one you have modified).  Repeat
233steps 1 and 2 (generate vtkParse.tab.c and reformat it with clang-format).
234Now you can apply the patch file to automate the original steps 3 through 9.
235Note that as you continue to edit vtkParse.y and regenerate vtkParse.tab.c,
236you can continue to use the same patch.  Just remember to run clang-format
237every time that you run bison.
238
239### Debugging the Parser
240
241When bison is run, it should not report any shift/reduce or reduce/reduce
242warnings.  If modifications to the rules cause these warnings to occur,
243you can run bison with the `--debug` and `--verbose` options:
244
245    bison --debug --verbose -b vtkParse vtkParse.y
246
247This will cause bison to produce a file called "vtkParse.output" that
248will show which rules conflict with other rules.
249