1 /*
2  * The main header file for SIP.
3  *
4  * Copyright (c) 2020 Riverbank Computing Limited <info@riverbankcomputing.com>
5  *
6  * This file is part of SIP.
7  *
8  * This copy of SIP is licensed for use under the terms of the SIP License
9  * Agreement.  See the file LICENSE for more details.
10  *
11  * This copy of SIP may also used under the terms of the GNU General Public
12  * License v2 or v3 as published by the Free Software Foundation which can be
13  * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package.
14  *
15  * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  */
18 
19 
20 #ifndef SIP_H
21 #define SIP_H
22 
23 #include <stdio.h>
24 #include <sys/types.h>
25 
26 
27 #ifdef TRUE
28 #undef TRUE
29 #endif
30 
31 #ifdef FALSE
32 #undef FALSE
33 #endif
34 
35 #define TRUE    1
36 #define FALSE   0
37 
38 
39 /* Some convenient compiler extensions. */
40 
41 #if defined(__GNUC__)
42 #define SIP_NORETURN    __attribute__((__noreturn__))
43 #define SIP_UNUSED      __attribute__((__unused__))
44 #elif defined(_MSC_VER)
45 #define SIP_NORETURN    __declspec(noreturn)
46 #endif
47 
48 #if !defined(SIP_NORETURN)
49 #define SIP_NORETURN
50 #endif
51 #if !defined(SIP_UNUSED)
52 #define SIP_UNUSED
53 #endif
54 
55 
56 #define DEFAULT_OFILE_EXT   ".o"    /* Default object file extension. */
57 
58 #define MAX_NR_ARGS         20      /* Max. nr. args. to a function or template. */
59 #define MAX_NR_DEREFS       5       /* Max. nr. type derefences. */
60 
61 
62 /* For convenience. */
63 
64 #define classBaseName(cd)   scopedNameTail((cd)->iff->fqcname)
65 #define classFQCName(cd)    ((cd)->iff->fqcname)
66 
67 /* Return the Python scope corresponding to a C/C++ scope. */
68 #define pyScope(c)          ((c) != NULL && isHiddenNamespace(c) ? NULL : (c))
69 
70 /* Control how scopes should be stripped. */
71 #define STRIP_NONE      0       /* This must be 0. */
72 #define STRIP_GLOBAL    (-1)    /* This must be -ve. */
73 
74 
75 /* Handle module flags. */
76 
77 #define MOD_HAS_DELAYED_DTORS   0x0001  /* It has a class with a delayed dtor. */
78 #define MOD_IS_CONSOLIDATED     0x0002  /* It is a consolidated module. */
79 #define MOD_IS_COMPOSITE        0x0004  /* It is a composite module. */
80 #define MOD_IS_TRANSFORMED      0x0008  /* It's types have been transformed. */
81 #define MOD_USE_ARG_NAMES       0x0010  /* Use real argument names. */
82 #define MOD_USE_LIMITED_API     0x0020  /* Use the limited API. */
83 #define MOD_ALL_RAISE_PY_EXC    0x0040  /* All callable raise a Python exception. */
84 #define MOD_SUPER_INIT_NO       0x0080  /* Don't call super().__init__(). */
85 #define MOD_SUPER_INIT_YES      0x0100  /* Call super().__init__(). */
86 #define MOD_SUPER_INIT_UNDEF    0x0000  /* Calling super().__init__() is undefined. */
87 #define MOD_SUPER_INIT_MASK     0x0180  /* The mask for the above flags. */
88 #define MOD_SETTING_IMPORTS     0x0200  /* Imports are being set. */
89 
90 #define hasDelayedDtors(m)  ((m)->modflags & MOD_HAS_DELAYED_DTORS)
91 #define setHasDelayedDtors(m)   ((m)->modflags |= MOD_HAS_DELAYED_DTORS)
92 #define isConsolidated(m)   ((m)->modflags & MOD_IS_CONSOLIDATED)
93 #define setIsConsolidated(m)    ((m)->modflags |= MOD_IS_CONSOLIDATED)
94 #define isComposite(m)      ((m)->modflags & MOD_IS_COMPOSITE)
95 #define setIsComposite(m)   ((m)->modflags |= MOD_IS_COMPOSITE)
96 #define isContainer(m)      ((m)->modflags & (MOD_IS_CONSOLIDATED | MOD_IS_COMPOSITE))
97 #define setIsTransformed(m) ((m)->modflags |= MOD_IS_TRANSFORMED)
98 #define isTransformed(m)    ((m)->modflags & MOD_IS_TRANSFORMED)
99 #define setUseArgNames(m)   ((m)->modflags |= MOD_USE_ARG_NAMES)
100 #define useArgNames(m)      ((m)->modflags & MOD_USE_ARG_NAMES)
101 #define setUseLimitedAPI(m) ((m)->modflags |= MOD_USE_LIMITED_API)
102 #define useLimitedAPI(m)    ((m)->modflags & MOD_USE_LIMITED_API)
103 #define setAllRaisePyException(m)   ((m)->modflags |= MOD_ALL_RAISE_PY_EXC)
104 #define allRaisePyException(m)  ((m)->modflags & MOD_ALL_RAISE_PY_EXC)
105 #define setCallSuperInitNo(m)   ((m)->modflags = ((m)->modflags & ~MOD_SUPER_INIT_MASK) | MOD_SUPER_INIT_NO)
106 #define setCallSuperInitYes(m)  ((m)->modflags = ((m)->modflags & ~MOD_SUPER_INIT_MASK) | MOD_SUPER_INIT_YES)
107 #define isCallSuperInitYes(m)   (((m)->modflags & MOD_SUPER_INIT_MASK) == MOD_SUPER_INIT_YES)
108 #define isCallSuperInitUndefined(m) (((m)->modflags & MOD_SUPER_INIT_MASK) == MOD_SUPER_INIT_UNDEF)
109 #define settingImports(m)   ((m)->modflags & MOD_SETTING_IMPORTS)
110 #define setSettingImports(m)    ((m)->modflags |= MOD_SETTING_IMPORTS)
111 #define resetSettingImports(m)  ((m)->modflags &= ~MOD_SETTING_IMPORTS)
112 
113 
114 /* Handle section flags. */
115 
116 #define SECT_IS_PUBLIC      0x01        /* It is public. */
117 #define SECT_IS_PROT        0x02        /* It is protected. */
118 #define SECT_IS_PRIVATE     0x04        /* It is private. */
119 #define SECT_IS_SLOT        0x08        /* It is a slot. */
120 #define SECT_IS_SIGNAL      0x10        /* It is a signal. */
121 #define SECT_MASK           0x1f        /* The mask of all flags. */
122 
123 
124 /* Handle class flags.  These are combined with the section flags. */
125 
126 #define CLASS_HAS_SIGSLOTS  0x00000200  /* It has signals or slots. */
127 #define CLASS_IS_ABSTRACT   0x00000400  /* It is an abstract class. */
128 #define CLASS_HAS_SHADOW    0x00000800  /* It is has a shadow class. */
129 #define CLASS_IS_OPAQUE     0x00001000  /* It is opaque. */
130 #define CLASS_HAS_VAR_HANDLERS  0x00002000  /* It has variable handlers. */
131 #define CLASS_DTOR_RELEASE_GIL  0x00004000  /* The dtor releases the GIL. */
132 #define CLASS_IS_PROTECTED  0x00008000  /* It is protected. */
133 #define CLASS_IS_PROTECTED_SAV  0x00010000  /* It is protected (saved). */
134 #define CLASS_IS_INCOMPLETE 0x00020000  /* The specification is incomplete. */
135 #define CLASS_CAN_CREATE    0x00040000  /* It has usable ctors. */
136 #define CLASS_IS_EXTERNAL   0x00080000  /* It is external. */
137 #define CLASS_IS_DELAYED_DTOR   0x00100000  /* The dtor is delayed. */
138 #define CLASS_NO_DEFAULT_CTORS  0x00200000  /* Don't create default ctors. */
139 #define CLASS_QOBJECT_SUB   0x00400000  /* It is derived from QObject. */
140 #define CLASS_DTOR_HOLD_GIL 0x00800000  /* The dtor holds the GIL. */
141 #define CLASS_ARRAY_HELPER  0x01000000  /* Generate an array helper. */
142 #define CLASS_NO_QMETAOBJECT    0x02000000  /* It has no QMetaObject. */
143 #define CLASS_IS_TEMPLATE   0x04000000  /* It is a template class. */
144 #define CLASS_IS_DEPRECATED 0x08000000  /* It is deprecated. */
145 #define CLASS_CANNOT_COPY   0x10000000  /* It cannot be copied. */
146 #define CLASS_CANNOT_ASSIGN 0x20000000  /* It cannot be assigned. */
147 #define CLASS_ALLOW_NONE    0x40000000  /* The class will handle None. */
148 #define CLASS_HAS_NONLAZY   0x80000000  /* The class has non-lazy methods. */
149 
150 #define hasSigSlots(cd)     ((cd)->classflags & CLASS_HAS_SIGSLOTS)
151 #define setHasSigSlots(cd)  ((cd)->classflags |= CLASS_HAS_SIGSLOTS)
152 #define isAbstractClass(cd) ((cd)->classflags & CLASS_IS_ABSTRACT)
153 #define setIsAbstractClass(cd)  ((cd)->classflags |= CLASS_IS_ABSTRACT)
154 #define hasShadow(cd)       ((cd)->classflags & CLASS_HAS_SHADOW)
155 #define setHasShadow(cd)    ((cd)->classflags |= CLASS_HAS_SHADOW)
156 #define resetHasShadow(cd)  ((cd)->classflags &= ~CLASS_HAS_SHADOW)
157 #define isOpaque(cd)        ((cd)->classflags & CLASS_IS_OPAQUE)
158 #define setIsOpaque(cd)     ((cd)->classflags |= CLASS_IS_OPAQUE)
159 #define hasVarHandlers(cd)  ((cd)->classflags & CLASS_HAS_VAR_HANDLERS)
160 #define setHasVarHandlers(cd)   ((cd)->classflags |= CLASS_HAS_VAR_HANDLERS)
161 #define isProtectedClass(cd)    ((cd)->classflags & CLASS_IS_PROTECTED)
162 #define setIsProtectedClass(cd) ((cd)->classflags |= CLASS_IS_PROTECTED)
163 #define resetIsProtectedClass(cd)   ((cd)->classflags &= ~CLASS_IS_PROTECTED)
164 #define wasProtectedClass(cd)   ((cd)->classflags & CLASS_IS_PROTECTED_SAV)
165 #define setWasProtectedClass(cd)    ((cd)->classflags |= CLASS_IS_PROTECTED_SAV)
166 #define resetWasProtectedClass(cd)  ((cd)->classflags &= ~CLASS_IS_PROTECTED_SAV)
167 #define isReleaseGILDtor(cd)    ((cd)->classflags & CLASS_DTOR_RELEASE_GIL)
168 #define setIsReleaseGILDtor(cd) ((cd)->classflags |= CLASS_DTOR_RELEASE_GIL)
169 #define isIncomplete(cd)    ((cd)->classflags & CLASS_IS_INCOMPLETE)
170 #define setIsIncomplete(cd) ((cd)->classflags |= CLASS_IS_INCOMPLETE)
171 #define canCreate(cd)       ((cd)->classflags & CLASS_CAN_CREATE)
172 #define setCanCreate(cd)    ((cd)->classflags |= CLASS_CAN_CREATE)
173 #define resetCanCreate(cd)  ((cd)->classflags &= ~CLASS_CAN_CREATE)
174 #define isExternal(cd)      ((cd)->classflags & CLASS_IS_EXTERNAL)
175 #define setIsExternal(cd)   ((cd)->classflags |= CLASS_IS_EXTERNAL)
176 #define isDelayedDtor(cd)   ((cd)->classflags & CLASS_IS_DELAYED_DTOR)
177 #define setIsDelayedDtor(cd)    ((cd)->classflags |= CLASS_IS_DELAYED_DTOR)
178 #define noDefaultCtors(cd)  ((cd)->classflags & CLASS_NO_DEFAULT_CTORS)
179 #define setNoDefaultCtors(cd)   ((cd)->classflags |= CLASS_NO_DEFAULT_CTORS)
180 #define isQObjectSubClass(cd)   ((cd)->classflags & CLASS_QOBJECT_SUB)
181 #define setIsQObjectSubClass(cd)    ((cd)->classflags |= CLASS_QOBJECT_SUB)
182 #define isHoldGILDtor(cd)   ((cd)->classflags & CLASS_DTOR_HOLD_GIL)
183 #define setIsHoldGILDtor(cd) ((cd)->classflags |= CLASS_DTOR_HOLD_GIL)
184 #define arrayHelper(cd)     ((cd)->classflags & CLASS_ARRAY_HELPER)
185 #define setArrayHelper(cd)  ((cd)->classflags |= CLASS_ARRAY_HELPER)
186 #define noPyQtQMetaObject(cd)   ((cd)->classflags & CLASS_NO_QMETAOBJECT)
187 #define setPyQtNoQMetaObject(cd)    ((cd)->classflags |= CLASS_NO_QMETAOBJECT)
188 #define isTemplateClass(cd) ((cd)->classflags & CLASS_IS_TEMPLATE)
189 #define setIsTemplateClass(cd)  ((cd)->classflags |= CLASS_IS_TEMPLATE)
190 #define resetIsTemplateClass(cd)    ((cd)->classflags &= ~CLASS_IS_TEMPLATE)
191 #define isDeprecatedClass(cd)   ((cd)->classflags & CLASS_IS_DEPRECATED)
192 #define setIsDeprecatedClass(cd)    ((cd)->classflags |= CLASS_IS_DEPRECATED)
193 #define cannotCopy(cd)      ((cd)->classflags & CLASS_CANNOT_COPY)
194 #define setCannotCopy(cd)   ((cd)->classflags |= CLASS_CANNOT_COPY)
195 #define cannotAssign(cd)    ((cd)->classflags & CLASS_CANNOT_ASSIGN)
196 #define setCannotAssign(cd) ((cd)->classflags |= CLASS_CANNOT_ASSIGN)
197 #define classHandlesNone(cd)    ((cd)->classflags & CLASS_ALLOW_NONE)
198 #define setClassHandlesNone(cd) ((cd)->classflags |= CLASS_ALLOW_NONE)
199 #define hasNonlazyMethod(cd)    ((cd)->classflags & CLASS_HAS_NONLAZY)
200 #define setHasNonlazyMethod(cd) ((cd)->classflags |= CLASS_HAS_NONLAZY)
201 
202 #define isPublicDtor(cd)    ((cd)->classflags & SECT_IS_PUBLIC)
203 #define setIsPublicDtor(cd) ((cd)->classflags |= SECT_IS_PUBLIC)
204 #define isProtectedDtor(cd) ((cd)->classflags & SECT_IS_PROT)
205 #define isPrivateDtor(cd)   ((cd)->classflags & SECT_IS_PRIVATE)
206 
207 #define isDtor(cd)          ((cd)->classflags & (SECT_IS_PUBLIC | SECT_IS_PROT | SECT_IS_PRIVATE))
208 
209 
210 /* Handle the second group of class flags. */
211 
212 #define CLASS2_TMPL_ARG     0x01        /* The class is a template argument. */
213 #define CLASS2_MIXIN        0x02        /* The class is a mixin. */
214 #define CLASS2_EXPORT_DERIVED   0x04    /* Export the derived class declaration. */
215 #define CLASS2_HIDDEN_NS    0x08        /* The namespace is hidden. */
216 #define CLASS2_USE_TMPL_NAME    0x10    /* Use the template name. */
217 #define CLASS2_NEEDS_SHADOW 0x20        /* The class needs a shadow class. */
218 #define CLASS2_COPY_HELPER  0x40        /* Generate a copy helper. */
219 
220 #define isTemplateArg(cd)   ((cd)->classflags2 & CLASS2_TMPL_ARG)
221 #define setTemplateArg(cd)  ((cd)->classflags2 |= CLASS2_TMPL_ARG)
222 #define resetTemplateArg(cd)    ((cd)->classflags2 &= ~CLASS2_TMPL_ARG)
223 #define isMixin(cd)         ((cd)->classflags2 & CLASS2_MIXIN)
224 #define setMixin(cd)        ((cd)->classflags2 |= CLASS2_MIXIN)
225 #define isExportDerived(cd) ((cd)->classflags2 & CLASS2_EXPORT_DERIVED)
226 #define setExportDerived(cd)    ((cd)->classflags2 |= CLASS2_EXPORT_DERIVED)
227 #define isHiddenNamespace(cd)   ((cd)->classflags2 & CLASS2_HIDDEN_NS)
228 #define setHiddenNamespace(cd)  ((cd)->classflags2 |= CLASS2_HIDDEN_NS)
229 #define useTemplateName(cd) ((cd)->classflags2 & CLASS2_USE_TMPL_NAME)
230 #define setUseTemplateName(cd)  ((cd)->classflags2 |= CLASS2_USE_TMPL_NAME)
231 #define needsShadow(cd)      ((cd)->classflags2 & CLASS2_NEEDS_SHADOW)
232 #define setNeedsShadow(cd)   ((cd)->classflags2 |= CLASS2_NEEDS_SHADOW)
233 #define copyHelper(cd)      ((cd)->classflags2 & CLASS2_COPY_HELPER)
234 #define setCopyHelper(cd)   ((cd)->classflags2 |= CLASS2_COPY_HELPER)
235 
236 
237 /* Handle ctor flags.  These are combined with the section flags. */
238 
239 #define CTOR_RELEASE_GIL    0x00000100  /* The ctor releases the GIL. */
240 #define CTOR_EXPLICIT       0x00000200  /* The ctor is explicit. */
241 #define CTOR_CAST           0x00000400  /* The ctor is a cast. */
242 #define CTOR_HOLD_GIL       0x00000800  /* The ctor holds the GIL. */
243 #define CTOR_XFERRED        0x00001000  /* Ownership is transferred. */
244 #define CTOR_IS_DEPRECATED  0x00002000  /* The ctor is deprecated. */
245 #define CTOR_RAISES_PY_EXC  0x00004000  /* It raises a Python exception. */
246 
247 #define isPublicCtor(c)     ((c)->ctorflags & SECT_IS_PUBLIC)
248 #define setIsPublicCtor(c)  ((c)->ctorflags |= SECT_IS_PUBLIC)
249 #define isProtectedCtor(c)  ((c)->ctorflags & SECT_IS_PROT)
250 #define setIsProtectedCtor(c)   ((c)->ctorflags |= SECT_IS_PROT)
251 #define isPrivateCtor(c)    ((c)->ctorflags & SECT_IS_PRIVATE)
252 #define setIsPrivateCtor(c) ((c)->ctorflags |= SECT_IS_PRIVATE)
253 
254 #define isReleaseGILCtor(c) ((c)->ctorflags & CTOR_RELEASE_GIL)
255 #define setIsReleaseGILCtor(c)  ((c)->ctorflags |= CTOR_RELEASE_GIL)
256 #define isExplicitCtor(c)   ((c)->ctorflags & CTOR_EXPLICIT)
257 #define setIsExplicitCtor(c)    ((c)->ctorflags |= CTOR_EXPLICIT)
258 #define isCastCtor(c)       ((c)->ctorflags & CTOR_CAST)
259 #define isHoldGILCtor(c)    ((c)->ctorflags & CTOR_HOLD_GIL)
260 #define setIsHoldGILCtor(c) ((c)->ctorflags |= CTOR_HOLD_GIL)
261 #define isResultTransferredCtor(c)  ((c)->ctorflags & CTOR_XFERRED)
262 #define setIsResultTransferredCtor(c)   ((c)->ctorflags |= CTOR_XFERRED)
263 #define isDeprecatedCtor(c) ((c)->ctorflags & CTOR_IS_DEPRECATED)
264 #define setIsDeprecatedCtor(c)  ((c)->ctorflags |= CTOR_IS_DEPRECATED)
265 #define raisesPyExceptionCtor(c)    ((c)->ctorflags & CTOR_RAISES_PY_EXC)
266 #define setRaisesPyExceptionCtor(c) ((c)->ctorflags |= CTOR_RAISES_PY_EXC)
267 
268 
269 /* Handle member flags. */
270 
271 #define MEMBR_NUMERIC       0x0001      /* It is a numeric slot. */
272 #define MEMBR_SEQUENCE      0x0002      /* It is a sequnce slot. */
273 #define MEMBR_NO_ARG_PARSER 0x0004      /* Don't generate an argument parser. */
274 #define MEMBR_NOT_VERSIONED 0x0008      /* There is an unversioned overload. */
275 #define MEMBR_KEYWORD_ARGS  0x0010      /* It allows keyword arguments. */
276 #define MEMBR_HAS_PROTECTED 0x0020      /* It has a protected overload. */
277 
278 #define isNumeric(m)        ((m)->memberflags & MEMBR_NUMERIC)
279 #define setIsNumeric(m)     ((m)->memberflags |= MEMBR_NUMERIC)
280 #define isSequence(m)       ((m)->memberflags & MEMBR_SEQUENCE)
281 #define setIsSequence(m)    ((m)->memberflags |= MEMBR_SEQUENCE)
282 #define noArgParser(m)      ((m)->memberflags & MEMBR_NO_ARG_PARSER)
283 #define setNoArgParser(m)   ((m)->memberflags |= MEMBR_NO_ARG_PARSER)
284 #define notVersioned(m)     ((m)->memberflags & MEMBR_NOT_VERSIONED)
285 #define setNotVersioned(m)  ((m)->memberflags |= MEMBR_NOT_VERSIONED)
286 #define useKeywordArgs(m)   ((m)->memberflags & MEMBR_KEYWORD_ARGS)
287 #define setUseKeywordArgs(m)    ((m)->memberflags |= MEMBR_KEYWORD_ARGS)
288 #define hasProtected(m)     ((m)->memberflags & MEMBR_HAS_PROTECTED)
289 #define setHasProtected(m)  ((m)->memberflags |= MEMBR_HAS_PROTECTED)
290 
291 
292 /* Handle enum flags.  These are combined with the section flags. */
293 
294 #define ENUM_WAS_PROT       0x00000100  /* It was defined as protected. */
295 #define ENUM_NO_SCOPE       0x00000200  /* Omit the member scopes. */
296 #define ENUM_NEEDS_ENUM     0x00000400  /* The module needs it. */
297 #define ENUM_SCOPED         0x00000800  /* A C++0x11 scoped enum. */
298 
299 #define isProtectedEnum(e)  ((e)->enumflags & SECT_IS_PROT)
300 #define setIsProtectedEnum(e)   ((e)->enumflags |= SECT_IS_PROT)
301 #define resetIsProtectedEnum(e) ((e)->enumflags &= ~SECT_IS_PROT)
302 
303 #define wasProtectedEnum(e) ((e)->enumflags & ENUM_WAS_PROT)
304 #define setWasProtectedEnum(e)  ((e)->enumflags |= ENUM_WAS_PROT)
305 #define resetWasProtectedEnum(e)    ((e)->enumflags &= ~ENUM_WAS_PROT)
306 #define isNoScope(e)        ((e)->enumflags & ENUM_NO_SCOPE)
307 #define setIsNoScope(e)     ((e)->enumflags |= ENUM_NO_SCOPE)
308 #define needsEnum(e)        ((e)->enumflags & ENUM_NEEDS_ENUM)
309 #define setNeedsEnum(e)     ((e)->enumflags |= ENUM_NEEDS_ENUM)
310 #define isScopedEnum(e)     ((e)->enumflags & ENUM_SCOPED)
311 #define setIsScopedEnum(e)  ((e)->enumflags |= ENUM_SCOPED)
312 
313 
314 /* Handle hierarchy flags. */
315 
316 #define HIER_BEING_SET      0x0001      /* The MRO is being set. */
317 #define IN_A_DIAMOND        0x0002      /* The class is in a diamond. */
318 
319 #define hierBeingSet(m)     ((m)->mroflags & HIER_BEING_SET)
320 #define setHierBeingSet(m)  ((m)->mroflags |= HIER_BEING_SET)
321 #define resetHierBeingSet(m)    ((m)->mroflags &= ~HIER_BEING_SET)
322 #define inADiamond(m)       ((m)->mroflags & IN_A_DIAMOND)
323 #define setInADiamond(m)    ((m)->mroflags |= IN_A_DIAMOND)
324 
325 
326 /* Handle overload flags.  These are combined with the section flags. */
327 
328 #define OVER_IS_VIRTUAL     0x00000100  /* It is virtual. */
329 #define OVER_IS_ABSTRACT    0x00000200  /* It is abstract. */
330 #define OVER_IS_CONST       0x00000400  /* It is a const function. */
331 #define OVER_IS_STATIC      0x00000800  /* It is a static function. */
332 #define OVER_IS_AUTOGEN     0x00001000  /* It is auto-generated. */
333 #define OVER_IS_NEW_THREAD  0x00002000  /* It is in a new thread. */
334 #define OVER_IS_FACTORY     0x00004000  /* It is a factory method. */
335 #define OVER_XFERRED_BACK   0x00008000  /* Ownership is transferred back. */
336 #define OVER_XFERRED        0x00010000  /* Ownership is transferred. */
337 #define OVER_IS_VIRTUAL_REIMP   0x00020000  /* It is a re-implementation of a virtual. */
338 #define OVER_DONT_DEREF_SELF    0x00040000  /* For comparison operators, don't dereference self. */
339 #define OVER_HOLD_GIL       0x00080000  /* The function holds the GIL. */
340 #define OVER_RELEASE_GIL    0x00100000  /* The function releases the GIL. */
341 #define OVER_THIS_XFERRED   0x00200000  /* Ownership of this is transferred. */
342 #define OVER_IS_GLOBAL      0x00400000  /* It is a global operator. */
343 #define OVER_IS_COMPLEMENTARY   0x00800000  /* It is a complementary operator. */
344 #define OVER_IS_DEPRECATED  0x01000000  /* It is deprecated. */
345 #define OVER_REALLY_PROT    0x02000000  /* It really is protected. */
346 #define OVER_IS_DELATTR     0x04000000  /* It is __delattr__. */
347 #define OVER_RAISES_PY_EXC  0x08000000  /* It raises a Python exception. */
348 #define OVER_NO_ERROR_HANDLER   0x10000000  /* It doesn't use a virtual error handler. */
349 #define OVER_ABORT_ON_EXC   0x20000000  /* It aborts on an exception. */
350 #define OVER_IS_FINAL       0x40000000  /* It is a final method. */
351 #define OVER_IS_REFLECTED   0x80000000  /* It is a reflected slot. */
352 
353 #define isPublic(o)         ((o)->overflags & SECT_IS_PUBLIC)
354 #define setIsPublic(o)      ((o)->overflags |= SECT_IS_PUBLIC)
355 #define isProtected(o)      ((o)->overflags & SECT_IS_PROT)
356 #define setIsProtected(o)   ((o)->overflags |= SECT_IS_PROT)
357 #define isPrivate(o)        ((o)->overflags & SECT_IS_PRIVATE)
358 #define setIsPrivate(o)     ((o)->overflags |= SECT_IS_PRIVATE)
359 #define isSlot(o)           ((o)->overflags & SECT_IS_SLOT)
360 #define setIsSlot(o)        ((o)->overflags |= SECT_IS_SLOT)
361 #define resetIsSlot(o)      ((o)->overflags &= ~SECT_IS_SLOT)
362 #define isSignal(o)         ((o)->overflags & SECT_IS_SIGNAL)
363 #define setIsSignal(o)      ((o)->overflags |= SECT_IS_SIGNAL)
364 #define resetIsSignal(o)    ((o)->overflags &= ~SECT_IS_SIGNAL)
365 
366 #define isVirtual(o)        ((o)->overflags & OVER_IS_VIRTUAL)
367 #define setIsVirtual(o)     ((o)->overflags |= OVER_IS_VIRTUAL)
368 #define resetIsVirtual(o)   ((o)->overflags &= ~OVER_IS_VIRTUAL)
369 #define isAbstract(o)       ((o)->overflags & OVER_IS_ABSTRACT)
370 #define setIsAbstract(o)    ((o)->overflags |= OVER_IS_ABSTRACT)
371 #define isConst(o)          ((o)->overflags & OVER_IS_CONST)
372 #define setIsConst(o)       ((o)->overflags |= OVER_IS_CONST)
373 #define isStatic(o)         ((o)->overflags & OVER_IS_STATIC)
374 #define setIsStatic(o)      ((o)->overflags |= OVER_IS_STATIC)
375 #define isAutoGen(o)        ((o)->overflags & OVER_IS_AUTOGEN)
376 #define setIsAutoGen(o)     ((o)->overflags |= OVER_IS_AUTOGEN)
377 #define resetIsAutoGen(o)   ((o)->overflags &= ~OVER_IS_AUTOGEN)
378 #define isNewThread(o)      ((o)->overflags & OVER_IS_NEW_THREAD)
379 #define setIsNewThread(o)   ((o)->overflags |= OVER_IS_NEW_THREAD)
380 #define isFactory(o)        ((o)->overflags & OVER_IS_FACTORY)
381 #define setIsFactory(o)     ((o)->overflags |= OVER_IS_FACTORY)
382 #define isResultTransferredBack(o)  ((o)->overflags & OVER_XFERRED_BACK)
383 #define setIsResultTransferredBack(o)   ((o)->overflags |= OVER_XFERRED_BACK)
384 #define isResultTransferred(o)  ((o)->overflags & OVER_XFERRED)
385 #define setIsResultTransferred(o)   ((o)->overflags |= OVER_XFERRED)
386 #define isVirtualReimp(o)   ((o)->overflags & OVER_IS_VIRTUAL_REIMP)
387 #define setIsVirtualReimp(o)    ((o)->overflags |= OVER_IS_VIRTUAL_REIMP)
388 #define dontDerefSelf(o)    ((o)->overflags & OVER_DONT_DEREF_SELF)
389 #define setDontDerefSelf(o) ((o)->overflags |= OVER_DONT_DEREF_SELF)
390 #define isHoldGIL(o)        ((o)->overflags & OVER_HOLD_GIL)
391 #define setIsHoldGIL(o)     ((o)->overflags |= OVER_HOLD_GIL)
392 #define isReleaseGIL(o)     ((o)->overflags & OVER_RELEASE_GIL)
393 #define setIsReleaseGIL(o)  ((o)->overflags |= OVER_RELEASE_GIL)
394 #define isThisTransferredMeth(o)    ((o)->overflags & OVER_THIS_XFERRED)
395 #define setIsThisTransferredMeth(o) ((o)->overflags |= OVER_THIS_XFERRED)
396 #define isGlobal(o)         ((o)->overflags & OVER_IS_GLOBAL)
397 #define setIsGlobal(o)      ((o)->overflags |= OVER_IS_GLOBAL)
398 #define isComplementary(o)  ((o)->overflags & OVER_IS_COMPLEMENTARY)
399 #define setIsComplementary(o)   ((o)->overflags |= OVER_IS_COMPLEMENTARY)
400 #define isDeprecated(o)     ((o)->overflags & OVER_IS_DEPRECATED)
401 #define setIsDeprecated(o)  ((o)->overflags |= OVER_IS_DEPRECATED)
402 #define isReallyProtected(o)    ((o)->overflags & OVER_REALLY_PROT)
403 #define setIsReallyProtected(o) ((o)->overflags |= OVER_REALLY_PROT)
404 #define isDelattr(o)        ((o)->overflags & OVER_IS_DELATTR)
405 #define setIsDelattr(o)     ((o)->overflags |= OVER_IS_DELATTR)
406 #define raisesPyException(o)    ((o)->overflags & OVER_RAISES_PY_EXC)
407 #define setRaisesPyException(o) ((o)->overflags |= OVER_RAISES_PY_EXC)
408 #define noErrorHandler(o)   ((o)->overflags & OVER_NO_ERROR_HANDLER)
409 #define setNoErrorHandler(o)    ((o)->overflags |= OVER_NO_ERROR_HANDLER)
410 #define abortOnException(o)     ((o)->overflags & OVER_ABORT_ON_EXC)
411 #define setAbortOnException(o)  ((o)->overflags |= OVER_ABORT_ON_EXC)
412 #define isFinal(o)          ((o)->overflags & OVER_IS_FINAL)
413 #define setIsFinal(o)       ((o)->overflags |= OVER_IS_FINAL)
414 #define isReflected(o)      ((o)->overflags & OVER_IS_REFLECTED)
415 #define setIsReflected(o)   ((o)->overflags |= OVER_IS_REFLECTED)
416 
417 
418 /* Handle variable flags. */
419 
420 #define VAR_IS_STATIC       0x01    /* It is a static variable. */
421 #define VAR_NEEDS_HANDLER   0x02    /* The variable needs a handler. */
422 #define VAR_NO_SETTER       0x04    /* The variable has no setter. */
423 
424 #define isStaticVar(v)      ((v)->varflags & VAR_IS_STATIC)
425 #define setIsStaticVar(v)   ((v)->varflags |= VAR_IS_STATIC)
426 #define needsHandler(v)     ((v)->varflags & VAR_NEEDS_HANDLER)
427 #define setNeedsHandler(v)  ((v)->varflags |= VAR_NEEDS_HANDLER)
428 #define noSetter(v)         ((v)->varflags & VAR_NO_SETTER)
429 #define setNoSetter(v)      ((v)->varflags |= VAR_NO_SETTER)
430 
431 
432 /* Handle argument flags. */
433 
434 #define ARG_IS_REF          0x00000001  /* It is a reference. */
435 #define ARG_IS_CONST        0x00000002  /* It is a const. */
436 #define ARG_XFERRED         0x00000004  /* Ownership is transferred. */
437 #define ARG_THIS_XFERRED    0x00000008  /* Ownership of this is transferred. */
438 #define ARG_XFERRED_BACK    0x00000010  /* Ownership is transferred back. */
439 #define ARG_ARRAY           0x00000020  /* Used as an array. */
440 #define ARG_ARRAY_SIZE      0x00000040  /* Used as an array size. */
441 #define ARG_ALLOW_NONE      0x00000080  /* Allow None as a value. */
442 #define ARG_GET_WRAPPER     0x00000100  /* Get the wrapper object. */
443 #define ARG_IN              0x00000200  /* It passes an argument. */
444 #define ARG_OUT             0x00000400  /* It returns a result. */
445 #define ARG_CONSTRAINED     0x00000800  /* Suppress type conversion. */
446 #define ARG_SINGLE_SHOT     0x00001000  /* The slot is only ever fired once. */
447 #define ARG_RESULT_SIZE     0x00002000  /* It defines the result size. */
448 #define ARG_KEEP_REF        0x00004000  /* Keep a reference. */
449 #define ARG_NO_COPY         0x00008000  /* Disable copying of const refs. */
450 #define ARG_DISALLOW_NONE   0x00010000  /* Disallow None as a value. */
451 
452 #define isReference(a)      ((a)->argflags & ARG_IS_REF)
453 #define setIsReference(a)   ((a)->argflags |= ARG_IS_REF)
454 #define resetIsReference(a) ((a)->argflags &= ~ARG_IS_REF)
455 #define isConstArg(a)       ((a)->argflags & ARG_IS_CONST)
456 #define setIsConstArg(a)    ((a)->argflags |= ARG_IS_CONST)
457 #define resetIsConstArg(a)  ((a)->argflags &= ~ARG_IS_CONST)
458 #define isTransferred(a)    ((a)->argflags & ARG_XFERRED)
459 #define setIsTransferred(a) ((a)->argflags |= ARG_XFERRED)
460 #define resetIsTransferred(a)   ((a)->argflags &= ~ARG_XFERRED)
461 #define isThisTransferred(a)    ((a)->argflags & ARG_THIS_XFERRED)
462 #define setIsThisTransferred(a) ((a)->argflags |= ARG_THIS_XFERRED)
463 #define isTransferredBack(a)    ((a)->argflags & ARG_XFERRED_BACK)
464 #define setIsTransferredBack(a) ((a)->argflags |= ARG_XFERRED_BACK)
465 #define isArray(a)          ((a)->argflags & ARG_ARRAY)
466 #define setArray(a)         ((a)->argflags |= ARG_ARRAY)
467 #define isArraySize(a)      ((a)->argflags & ARG_ARRAY_SIZE)
468 #define setArraySize(a)     ((a)->argflags |= ARG_ARRAY_SIZE)
469 #define isAllowNone(a)      ((a)->argflags & ARG_ALLOW_NONE)
470 #define setAllowNone(a)     ((a)->argflags |= ARG_ALLOW_NONE)
471 #define isGetWrapper(a)     ((a)->argflags & ARG_GET_WRAPPER)
472 #define setGetWrapper(a)    ((a)->argflags |= ARG_GET_WRAPPER)
473 #define isInArg(a)          ((a)->argflags & ARG_IN)
474 #define setIsInArg(a)       ((a)->argflags |= ARG_IN)
475 #define isOutArg(a)         ((a)->argflags & ARG_OUT)
476 #define setIsOutArg(a)      ((a)->argflags |= ARG_OUT)
477 #define isConstrained(a)    ((a)->argflags & ARG_CONSTRAINED)
478 #define setIsConstrained(a) ((a)->argflags |= ARG_CONSTRAINED)
479 #define resetIsConstrained(a)   ((a)->argflags &= ~ARG_CONSTRAINED)
480 #define isSingleShot(a)     ((a)->argflags & ARG_SINGLE_SHOT)
481 #define isResultSize(a)     ((a)->argflags & ARG_RESULT_SIZE)
482 #define setResultSize(a)    ((a)->argflags |= ARG_RESULT_SIZE)
483 #define keepReference(a)    ((a)->argflags & ARG_KEEP_REF)
484 #define setKeepReference(a) ((a)->argflags |= ARG_KEEP_REF)
485 #define noCopy(a)           ((a)->argflags & ARG_NO_COPY)
486 #define setNoCopy(a)        ((a)->argflags |= ARG_NO_COPY)
487 #define isDisallowNone(a)   ((a)->argflags & ARG_DISALLOW_NONE)
488 #define setDisallowNone(a)  ((a)->argflags |= ARG_DISALLOW_NONE)
489 
490 
491 /* Handle name flags. */
492 
493 #define NAME_IS_USED        0x01    /* It is used in the main module. */
494 #define NAME_IS_SUBSTR      0x02    /* It is a substring of another. */
495 
496 #define isUsedName(n)       ((n)->nameflags & NAME_IS_USED)
497 #define setIsUsedName(n)    ((n)->nameflags |= NAME_IS_USED)
498 #define resetIsUsedName(n)  ((n)->nameflags &= ~NAME_IS_USED)
499 #define isSubstring(n)      ((n)->nameflags & NAME_IS_SUBSTR)
500 #define setIsSubstring(n)   ((n)->nameflags |= NAME_IS_SUBSTR)
501 
502 
503 /* Handle virtual handler flags. */
504 
505 #define VH_TRANSFERS        0x01    /* It transfers ownership of the result. */
506 #define VH_ABORT_ON_EXC     0x02    /* It aborts on an exception. */
507 
508 #define isTransferVH(vh)    ((vh)->vhflags & VH_TRANSFERS)
509 #define setIsTransferVH(vh) ((vh)->vhflags |= VH_TRANSFERS)
510 #define abortOnExceptionVH(vh)  ((vh)->vhflags & VH_ABORT_ON_EXC)
511 #define setAbortOnExceptionVH(vh)   ((vh)->vhflags |= VH_ABORT_ON_EXC)
512 
513 
514 /* Handle mapped type flags. */
515 
516 #define MT_NO_RELEASE       0x01    /* Do not generate a release function. */
517 #define MT_ALLOW_NONE       0x02    /* The mapped type will handle None. */
518 
519 #define noRelease(mt)       ((mt)->mtflags & MT_NO_RELEASE)
520 #define setNoRelease(mt)    ((mt)->mtflags |= MT_NO_RELEASE)
521 #define handlesNone(mt)     ((mt)->mtflags & MT_ALLOW_NONE)
522 #define setHandlesNone(mt)  ((mt)->mtflags |= MT_ALLOW_NONE)
523 
524 
525 /* Handle typedef flags. */
526 
527 #define TD_NO_TYPE_NAME     0x01    /* Do not use the typedef name. */
528 
529 #define noTypeName(td)      ((td)->tdflags & TD_NO_TYPE_NAME)
530 #define setNoTypeName(td)   ((td)->tdflags |= TD_NO_TYPE_NAME)
531 
532 
533 /* Warning categories. */
534 typedef enum {
535     ParserWarning,
536     DeprecationWarning
537 } Warning;
538 
539 
540 /* Docstring formatting. */
541 typedef enum {
542     raw,
543     deindented
544 } Format;
545 
546 
547 /* Docstring signature positioning. */
548 typedef enum {
549     discarded,
550     prepended,
551     appended
552 } Signature;
553 
554 
555 /* Levels of keyword argument support. */
556 typedef enum {
557     NoKwArgs = 0,
558     AllKwArgs,
559     OptionalKwArgs
560 } KwArgs;
561 
562 
563 /* Slot types. */
564 typedef enum {
565     str_slot,
566     int_slot,
567     float_slot,
568     len_slot,
569     contains_slot,
570     add_slot,
571     concat_slot,
572     sub_slot,
573     mul_slot,
574     repeat_slot,
575     div_slot,       /* No longer used. */
576     mod_slot,
577     floordiv_slot,
578     truediv_slot,
579     and_slot,
580     or_slot,
581     xor_slot,
582     lshift_slot,
583     rshift_slot,
584     iadd_slot,
585     iconcat_slot,
586     isub_slot,
587     imul_slot,
588     irepeat_slot,
589     idiv_slot,      /* No longer used. */
590     imod_slot,
591     ifloordiv_slot,
592     itruediv_slot,
593     iand_slot,
594     ior_slot,
595     ixor_slot,
596     ilshift_slot,
597     irshift_slot,
598     invert_slot,
599     call_slot,
600     getitem_slot,
601     setitem_slot,
602     delitem_slot,
603     lt_slot,
604     le_slot,
605     eq_slot,
606     ne_slot,
607     gt_slot,
608     ge_slot,
609     cmp_slot,
610     bool_slot,
611     neg_slot,
612     pos_slot,
613     abs_slot,
614     repr_slot,
615     hash_slot,
616     index_slot,
617     iter_slot,
618     next_slot,
619     setattr_slot,
620     delattr_slot,       /* This is local to the parser. */
621     matmul_slot,
622     imatmul_slot,
623     await_slot,
624     aiter_slot,
625     anext_slot,
626     no_slot
627 } slotType;
628 
629 
630 /*
631  * Argument types.  Always add new ones at the end because the numeric values
632  * can appear in generated code.
633  */
634 typedef enum {
635     no_type,
636     defined_type,
637     class_type,
638     struct_type,
639     void_type,
640     enum_type,
641     template_type,
642     signal_type_unused,
643     slot_type_unused,
644     rxcon_type_unused,
645     rxdis_type_unused,
646     slotcon_type_unused,
647     slotdis_type_unused,
648     ustring_type,
649     string_type,
650     short_type,
651     ushort_type,
652     cint_type,
653     int_type,
654     uint_type,
655     long_type,
656     ulong_type,
657     float_type,
658     cfloat_type,
659     double_type,
660     cdouble_type,
661     bool_type,
662     mapped_type,
663     pyobject_type,
664     pytuple_type,
665     pylist_type,
666     pydict_type,
667     pycallable_type,
668     pyslice_type,
669     qobject_type_unused,
670     function_type,
671     pytype_type,
672     ellipsis_type,
673     longlong_type,
674     ulonglong_type,
675     anyslot_type_unused,
676     cbool_type,
677     sstring_type,
678     wstring_type,
679     fake_void_type,
680     ssize_type,
681     ascii_string_type,
682     latin1_string_type,
683     utf8_string_type,
684     byte_type,
685     sbyte_type,
686     ubyte_type,
687     capsule_type,
688     pybuffer_type,
689     size_type
690 } argType;
691 
692 
693 /* Value types. */
694 typedef enum {
695     qchar_value,
696     string_value,
697     numeric_value,
698     real_value,
699     scoped_value,
700     fcall_value,
701     empty_value
702 } valueType;
703 
704 
705 /* Version types. */
706 typedef enum {
707     time_qualifier,
708     platform_qualifier,
709     feature_qualifier
710 } qualType;
711 
712 
713 /* Interface file types. */
714 typedef enum {
715     exception_iface,
716     mappedtype_iface,
717     namespace_iface,
718     class_iface
719 } ifaceFileType;
720 
721 
722 /* Type hint parse status. */
723 typedef enum {
724     needs_parsing,
725     being_parsed,
726     parsed
727 } typeHintParseStatus;
728 
729 
730 /* Type hint node type. */
731 typedef enum {
732     typing_node,
733     class_node,
734     enum_node,
735     other_node
736 } typeHintNodeType;
737 
738 
739 /* A location in a .sip source file. */
740 typedef struct {
741     int linenr;                         /* The line number. */
742     const char *name;                   /* The filename. */
743 } sourceLocation;
744 
745 
746 /* A software license. */
747 typedef struct {
748     const char *type;                   /* The license type. */
749     const char *licensee;               /* The licensee. */
750     const char *timestamp;              /* The timestamp. */
751     const char *sig;                    /* The signature. */
752 } licenseDef;
753 
754 
755 /* A version qualifier. */
756 typedef struct _qualDef {
757     const char *name;                   /* The qualifier name. */
758     qualType qtype;                     /* The qualifier type. */
759     struct _moduleDef *module;          /* The defining module. */
760     int line;                           /* Timeline if it is a time. */
761     unsigned order;                     /* Order if it is a time. */
762     int default_enabled;                /* Enabled by default. */
763     struct _qualDef *next;              /* Next in the list. */
764 } qualDef;
765 
766 
767 /* A platform. */
768 typedef struct _platformDef {
769     struct _qualDef *qualifier;         /* The platform qualifier. */
770     struct _platformDef *next;          /* Next in the list. */
771 } platformDef;
772 
773 
774 /* A scoped name. */
775 typedef struct _scopedNameDef {
776     char *name;                         /* The name. */
777     struct _scopedNameDef *next;        /* Next in the scope list. */
778 } scopedNameDef;
779 
780 
781 /* A name. */
782 typedef struct _nameDef {
783     int nameflags;                      /* The name flags. */
784     const char *text;                   /* The text of the name. */
785     size_t len;                         /* The length of the name. */
786     size_t offset;                      /* The offset in the string pool. */
787     struct _nameDef *next;              /* Next in the list. */
788 } nameDef;
789 
790 
791 /* A literal code block. */
792 typedef struct _codeBlock {
793     char *frag;                         /* The code itself. */
794     const char *filename;               /* The original file. */
795     int linenr;                         /* The line in the file. */
796 } codeBlock;
797 
798 
799 /* A list of literal code blocks. */
800 typedef struct _codeBlockList {
801     codeBlock *block;                   /* The code block. */
802     struct _codeBlockList *next;        /* The next in the list. */
803 } codeBlockList;
804 
805 
806 /* The arguments to a throw specifier. */
807 typedef struct _throwArgs {
808     int nrArgs;                         /* The number of arguments. */
809     struct _exceptionDef *args[MAX_NR_ARGS];    /* The arguments. */
810 } throwArgs;
811 
812 
813 /* An exception. */
814 typedef struct _exceptionDef {
815     int exceptionnr;                    /* The exception number. */
816     int needed;                         /* The module needs it. */
817     struct _ifaceFileDef *iff;          /* The interface file. */
818     const char *pyname;                 /* The exception Python name. */
819     struct _classDef *cd;               /* The exception class. */
820     char *bibase;                       /* The builtin base exception. */
821     struct _exceptionDef *base;         /* The defined base exception. */
822     codeBlockList *raisecode;           /* Raise exception code. */
823     struct _exceptionDef *next;         /* The next in the list. */
824 } exceptionDef;
825 
826 
827 /* A value. */
828 typedef struct _valueDef {
829     valueType vtype;                    /* The type. */
830     char vunop;                         /* Any unary operator. */
831     char vbinop;                        /* Any binary operator. */
832     scopedNameDef *cast;                /* Any cast. */
833     union {
834         char vqchar;                    /* Quoted character value. */
835         long vnum;                      /* Numeric value. */
836         double vreal;                   /* Real value. */
837         char *vstr;                     /* String value. */
838         scopedNameDef *vscp;            /* Scoped value. */
839         struct _fcallDef *fcd;          /* Function call. */
840     } u;
841     struct _valueDef *next;             /* Next in the expression. */
842 } valueDef;
843 
844 
845 /* A member function argument (or result). */
846 typedef struct {
847     argType atype;                      /* The type. */
848     nameDef *name;                      /* The name. */
849     struct _typeHintDef *typehint_in;   /* The PEP 484 input type hint. */
850     struct _typeHintDef *typehint_out;  /* The PEP 484 output type hint. */
851     const char *typehint_value;         /* The type hint value. */
852     int argflags;                       /* The argument flags. */
853     int nrderefs;                       /* Nr. of dereferences. */
854     int derefs[MAX_NR_DEREFS];          /* The const for each dereference. */
855     valueDef *defval;                   /* The default value. */
856     int scopes_stripped;                /* Nr. of scopes to be stripped. */
857     int key;                            /* The optional /KeepReference/ key. */
858     struct _typedefDef *original_type;  /* The original type if typedef'd. */
859     union {
860         struct _signatureDef *sa;       /* If it is a function. */
861         struct _templateDef *td;        /* If it is a template. */
862         struct _scopedNameDef *snd;     /* If it is a defined type. */
863         struct _classDef *cd;           /* If it is a class. */
864         struct _enumDef *ed;            /* If it is an enum. */
865         struct _scopedNameDef *sname;   /* If it is a struct. */
866         struct _mappedTypeDef *mtd;     /* If it is a mapped type. */
867         struct _scopedNameDef *cap;     /* If it is a capsule. */
868     } u;
869 } argDef;
870 
871 
872 /* An entry in a linked argument list. */
873 typedef struct _argList {
874     argDef arg;                         /* The argument itself. */
875     struct _argList *next;              /* Next in the list. */
876 } argList;
877 
878 
879 /* A function call. */
880 typedef struct _fcallDef {
881     argDef type;                        /* The type. */
882     int nrArgs;                         /* The number of arguments. */
883     struct _valueDef *args[MAX_NR_ARGS];    /* The arguments. */
884 } fcallDef;
885 
886 
887 /* An API version range definition. */
888 typedef struct _apiVersionRangeDef {
889     nameDef *api_name;                  /* The API name. */
890     int from;                           /* The lower bound. */
891     int to;                             /* The upper bound. */
892     int index;                          /* The range index. */
893     struct _apiVersionRangeDef *next;   /* The next in the list. */
894 } apiVersionRangeDef;
895 
896 
897 /* A virtual error handler. */
898 typedef struct _virtErrorHandler {
899     const char *name;                   /* The name of the handler. */
900     codeBlockList *code;                /* The handler code. */
901     struct _moduleDef *mod;             /* The defining module. */
902     int index;                          /* The index within the module. */
903     struct _virtErrorHandler *next;     /* The next in the list. */
904 } virtErrorHandler;
905 
906 
907 /* A parsed PEP 484 compliant type hint. */
908 typedef struct _typeHintDef {
909     typeHintParseStatus status;         /* The state of the type hint parse. */
910     char *raw_hint;                     /* The raw hint. */
911     struct _typeHintNodeDef *root;      /* The root of parsed nodes. */
912 } typeHintDef;
913 
914 
915 /* A node of a parsed type hint. */
916 typedef struct _typeHintNodeDef {
917     typeHintNodeType type;              /* The type of the node. */
918     union {
919         const char *name;               /* For typing objects and others. */
920         struct _classDef *cd;           /* For class nodes. */
921         struct _enumDef *ed;            /* For enum nodes. */
922     } u;
923     struct _typeHintNodeDef *children;  /* The list of children. */
924     struct _typeHintNodeDef *next;      /* The next sibling. */
925 } typeHintNodeDef;
926 
927 
928 /* An explicit docstring. */
929 typedef struct _docstringDef {
930     Signature signature;                /* How the signature should be positioned. */
931     char *text;                         /* The text of the docstring. */
932 } docstringDef;
933 
934 
935 /* A module definition. */
936 typedef struct _moduleDef {
937     nameDef *fullname;                  /* The full module name. */
938     const char *name;                   /* The module base name. */
939     docstringDef *docstring;            /* The docstring. */
940     apiVersionRangeDef *api_versions;   /* The defined APIs. */
941     apiVersionRangeDef *api_ranges;     /* The list of API version ranges. */
942     int modflags;                       /* The module flags. */
943     KwArgs kwargs;                      /* The style of keyword argument support. */
944     struct _memberDef *othfuncs;        /* List of other functions. */
945     struct _overDef *overs;             /* Global overloads. */
946     Format defdocstringfmt;             /* The default docstring format. */
947     Signature defdocstringsig;          /* The default docstring signature. */
948     argType encoding;                   /* The default string encoding. */
949     nameDef *defmetatype;               /* The optional default meta-type. */
950     nameDef *defsupertype;              /* The optional default super-type. */
951     struct _exceptionDef *defexception; /* The default exception. */
952     codeBlockList *hdrcode;             /* Header code. */
953     codeBlockList *cppcode;             /* Global C++ code. */
954     codeBlockList *copying;             /* Software license. */
955     codeBlockList *preinitcode;         /* Pre-initialisation code. */
956     codeBlockList *initcode;            /* Initialisation code. */
957     codeBlockList *postinitcode;        /* Post-initialisation code. */
958     codeBlockList *unitcode;            /* Compilation unit code. */
959     codeBlockList *unitpostinccode;     /* Compilation unit post-include code. */
960     codeBlockList *typehintcode;        /* Type hint code. */
961     const char *virt_error_handler;     /* The virtual error handler. */
962     int parts;                          /* The number of parts generated. */
963     const char *file;                   /* The filename. */
964     qualDef *qualifiers;                /* The list of qualifiers. */
965     argDef *needed_types;               /* The array of needed types. */
966     int nr_needed_types;                /* The number of needed types. */
967     int nrtimelines;                    /* The nr. of timelines. */
968     int nrexceptions;                   /* The nr. of exceptions. */
969     int nrtypedefs;                     /* The nr. of typedefs. */
970     int nrvirterrorhandlers;            /* The nr. of virtual error handlers. */
971     int next_key;                       /* The next key to allocate. */
972     licenseDef *license;                /* The software license. */
973     struct _classDef *proxies;          /* The list of proxy classes. */
974     struct _moduleDef *container;       /* The container module, if any. */
975     struct _ifaceFileList *used;        /* Interface files used. */
976     struct _moduleListDef *allimports;  /* The list of all imports. */
977     struct _moduleListDef *imports;     /* The list of direct imports. */
978     struct _autoPyNameDef *autopyname;  /* The Python naming rules. */
979     struct _moduleDef *next;            /* Next in the list. */
980 } moduleDef;
981 
982 
983 /* An entry in a linked module list. */
984 typedef struct _moduleListDef {
985     moduleDef *module;                  /* The module itself. */
986     struct _moduleListDef *next;        /* The next in the list. */
987 } moduleListDef;
988 
989 
990 /* An interface file definition. */
991 typedef struct _ifaceFileDef {
992     nameDef *name;                      /* The name. */
993     int needed;                         /* The main module needs it. */
994     apiVersionRangeDef *api_range;      /* The optional API version range. */
995     struct _ifaceFileDef *first_alt;    /* The first alternate API. */
996     struct _ifaceFileDef *next_alt;     /* The next alternate API. */
997     ifaceFileType type;                 /* Interface file type. */
998     int ifacenr;                        /* The index into the types table. */
999     scopedNameDef *fqcname;             /* The fully qualified C++ name. */
1000     moduleDef *module;                  /* The owning module. */
1001     codeBlockList *hdrcode;             /* Header code. */
1002     const char *file_extension;         /* The optional file extension. */
1003     struct _ifaceFileList *used;        /* Interface files used. */
1004     platformDef *platforms;             /* The platforms. */
1005     struct _ifaceFileDef *next;         /* Next in the list. */
1006 } ifaceFileDef;
1007 
1008 
1009 /* An entry in a linked interface file list. */
1010 
1011 typedef struct _ifaceFileList {
1012     ifaceFileDef *iff;                  /* The interface file itself. */
1013     struct _ifaceFileList *next;        /* Next in the list. */
1014 } ifaceFileList;
1015 
1016 
1017 /* A mapped type. */
1018 typedef struct _mappedTypeDef {
1019     int mtflags;                        /* The mapped type flags. */
1020     argDef type;                        /* The type being mapped. */
1021     nameDef *pyname;                    /* The Python name. */
1022     nameDef *cname;                     /* The C/C++ name. */
1023     typeHintDef *typehint_in;           /* The PEP 484 input type hint. */
1024     typeHintDef *typehint_out;          /* The PEP 484 output type hint. */
1025     const char *typehint_value;         /* The type hint value. */
1026     ifaceFileDef *iff;                  /* The interface file. */
1027     struct _memberDef *members;         /* The static member functions. */
1028     struct _overDef *overs;             /* The static overloads. */
1029     codeBlockList *instancecode;        /* Create instance code. */
1030     codeBlockList *typecode;            /* Type code. */
1031     codeBlockList *convfromcode;        /* Convert from C++ code. */
1032     codeBlockList *convtocode;          /* Convert to C++ code. */
1033     struct _mappedTypeDef *real;        /* The original definition. */
1034     struct _mappedTypeDef *next;        /* Next in the list. */
1035 } mappedTypeDef;
1036 
1037 
1038 /* A function signature. */
1039 typedef struct _signatureDef {
1040     argDef result;                      /* The result. */
1041     int nrArgs;                         /* The number of arguments. */
1042     argDef args[MAX_NR_ARGS];           /* The arguments. */
1043 } signatureDef;
1044 
1045 
1046 /* A list of function signatures. */
1047 typedef struct _signatureList {
1048     struct _signatureDef *sd;           /* The signature. */
1049     struct _signatureList *next;        /* Next in the list. */
1050 } signatureList;
1051 
1052 
1053 /* A template type. */
1054 typedef struct _templateDef {
1055     scopedNameDef *fqname;              /* The name. */
1056     signatureDef types;                 /* The types. */
1057 } templateDef;
1058 
1059 
1060 /* A list of virtual handlers. */
1061 typedef struct _virtHandlerDef {
1062     int virthandlernr;                  /* The nr. of the virtual handler. */
1063     int vhflags;                        /* The virtual handler flags. */
1064     signatureDef *pysig;                /* The Python signature. */
1065     signatureDef *cppsig;               /* The C++ signature. */
1066     codeBlockList *virtcode;            /* Virtual handler code. */
1067     virtErrorHandler *veh;              /* The virtual error handler. */
1068     struct _virtHandlerDef *next;       /* Next in the list. */
1069 } virtHandlerDef;
1070 
1071 
1072 /* A typedef definition. */
1073 typedef struct _typedefDef {
1074     int tdflags;                        /* The typedef flags. */
1075     scopedNameDef *fqname;              /* The fully qualified name. */
1076     struct _classDef *ecd;              /* The enclosing class. */
1077     moduleDef *module;                  /* The owning module. */
1078     argDef type;                        /* The actual type. */
1079     platformDef *platforms;             /* The platforms. */
1080     struct _typedefDef *next;           /* Next in the list. */
1081 } typedefDef;
1082 
1083 
1084 /* A variable definition. */
1085 typedef struct _varDef {
1086     scopedNameDef *fqcname;             /* The fully qualified C/C++ name. */
1087     nameDef *pyname;                    /* The variable Python name. */
1088     int no_typehint;                    /* The type hint will be suppressed. */
1089     struct _classDef *ecd;              /* The enclosing class. */
1090     moduleDef *module;                  /* The owning module. */
1091     int varflags;                       /* The variable flags. */
1092     argDef type;                        /* The actual type. */
1093     codeBlockList *accessfunc;          /* The access function. */
1094     codeBlockList *getcode;             /* The get code. */
1095     codeBlockList *setcode;             /* The set code. */
1096     platformDef *platforms;             /* The platforms. */
1097     struct _varDef *next;               /* Next in the list. */
1098 } varDef;
1099 
1100 
1101 /* A property definition. */
1102 typedef struct _propertyDef {
1103     nameDef *name;                      /* The property name. */
1104     docstringDef *docstring;            /* The docstring. */
1105     const char *get;                    /* The name of the getter method. */
1106     const char *set;                    /* The name of the setter method. */
1107     platformDef *platforms;             /* The platforms. */
1108     struct _propertyDef *next;          /* Next in the list. */
1109 } propertyDef;
1110 
1111 
1112 /* An overloaded member function definition. */
1113 typedef struct _overDef {
1114     sourceLocation sloc;                /* The source location. */
1115     const char *cppname;                /* The C++ name. */
1116     docstringDef *docstring;            /* The docstring. */
1117     int overflags;                      /* The overload flags. */
1118     int no_typehint;                    /* The type hint will be suppressed. */
1119     int pyqt_signal_hack;               /* The PyQt signal hack. */
1120     KwArgs kwargs;                      /* The keyword argument support. */
1121     struct _memberDef *common;          /* Common parts. */
1122     apiVersionRangeDef *api_range;      /* The optional API version range. */
1123     signatureDef pysig;                 /* The Python signature. */
1124     signatureDef *cppsig;               /* The C++ signature. */
1125     throwArgs *exceptions;              /* The exceptions. */
1126     codeBlockList *methodcode;          /* Method code. */
1127     codeBlockList *premethodcode;       /* Code to insert before the method code. */
1128     codeBlockList *virtcallcode;        /* Virtual call code. */
1129     codeBlockList *virtcode;            /* Virtual handler code. */
1130     char *prehook;                      /* The pre-hook name. */
1131     char *posthook;                     /* The post-hook name. */
1132     const char *virt_error_handler;     /* The virtual error handler. */
1133     platformDef *platforms;             /* The platforms. */
1134     struct _overDef *next;              /* Next in the list. */
1135 } overDef;
1136 
1137 
1138 /* An overloaded constructor definition. */
1139 typedef struct _ctorDef {
1140     docstringDef *docstring;            /* The docstring. */
1141     int ctorflags;                      /* The ctor flags. */
1142     int no_typehint;                    /* The type hint will be suppressed. */
1143     KwArgs kwargs;                      /* The keyword argument support. */
1144     apiVersionRangeDef *api_range;      /* The optional API version range. */
1145     signatureDef pysig;                 /* The Python signature. */
1146     signatureDef *cppsig;               /* The C++ signature, NULL if /NoDerived/. */
1147     throwArgs *exceptions;              /* The exceptions. */
1148     codeBlockList *methodcode;          /* Method code. */
1149     codeBlockList *premethodcode;       /* Code to insert before the method code. */
1150     char *prehook;                      /* The pre-hook name. */
1151     char *posthook;                     /* The post-hook name. */
1152     platformDef *platforms;             /* The platforms. */
1153     struct _ctorDef *next;              /* Next in the list. */
1154 } ctorDef;
1155 
1156 
1157 /* An enumerated type member definition. */
1158 typedef struct _enumMemberDef {
1159     nameDef *pyname;                    /* The Python name. */
1160     int no_typehint;                    /* The type hint will be suppressed. */
1161     char *cname;                        /* The C/C++ name. */
1162     struct _enumDef *ed;                /* The enclosing enum. */
1163     platformDef *platforms;             /* The platforms. */
1164     struct _enumMemberDef *next;        /* Next in the list. */
1165 } enumMemberDef;
1166 
1167 
1168 /* An enumerated type definition. */
1169 typedef struct _enumDef {
1170     int enumflags;                      /* The enum flags. */
1171     scopedNameDef *fqcname;             /* The C/C++ name (may be NULL). */
1172     nameDef *cname;                     /* The C/C++ name (may be NULL). */
1173     nameDef *pyname;                    /* The Python name (may be NULL). */
1174     int no_typehint;                    /* The type hint will be suppressed. */
1175     struct _enumDef *first_alt;         /* The first alternate API. */
1176     struct _enumDef *next_alt;          /* The next alternate API. */
1177     int enumnr;                         /* The enum number. */
1178     int enum_idx;                       /* The enum index within the module. */
1179     struct _classDef *ecd;              /* The enclosing class, if any. */
1180     struct _mappedTypeDef *emtd;        /* The enclosing mapped type, if any. */
1181     moduleDef *module;                  /* The owning module. */
1182     enumMemberDef *members;             /* The list of members. */
1183     struct _memberDef *slots;           /* The list of slots. */
1184     struct _overDef *overs;             /* The list of slot overloads. */
1185     platformDef *platforms;             /* The platforms. */
1186     struct _enumDef *next;              /* Next in the list. */
1187 } enumDef;
1188 
1189 
1190 /* An member function definition. */
1191 typedef struct _memberDef {
1192     nameDef *pyname;                    /* The Python name. */
1193     int memberflags;                    /* The member flags. */
1194     int membernr;                       /* The index in the method table. */
1195     slotType slot;                      /* The slot type. */
1196     moduleDef *module;                  /* The owning module. */
1197     struct _ifaceFileDef *ns_scope;     /* The scope if it has been moved. */
1198     struct _memberDef *next;            /* Next in the list. */
1199 } memberDef;
1200 
1201 
1202 /* A list of visible member functions. */
1203 typedef struct _visibleList {
1204     memberDef *m;                       /* The member definition. */
1205     struct _classDef *cd;               /* The class. */
1206     struct _visibleList *next;          /* Next in the list. */
1207 } visibleList;
1208 
1209 
1210 /* An entry in a linked class list. */
1211 typedef struct _classList {
1212     struct _classDef *cd;               /* The class itself. */
1213     struct _classList *next;            /* Next in the list. */
1214 } classList;
1215 
1216 
1217 /* A virtual overload definition. */
1218 typedef struct _virtOverDef {
1219     overDef *od;                        /* The overload. */
1220     virtHandlerDef *virthandler;        /* The virtual handler. */
1221     struct _virtOverDef *next;          /* Next in the list. */
1222 } virtOverDef;
1223 
1224 
1225 /* A class that appears in a class's hierarchy. */
1226 typedef struct _mroDef {
1227     struct _classDef *cd;               /* The class. */
1228     int mroflags;                       /* The hierarchy flags. */
1229     struct _mroDef *next;               /* The next in the list. */
1230 } mroDef;
1231 
1232 
1233 /* A class definition. */
1234 typedef struct _classDef {
1235     docstringDef *docstring;            /* The class docstring. */
1236     unsigned classflags;                /* The class flags. */
1237     unsigned classflags2;               /* The class flags, part 2. */
1238     int pyqt_flags;                     /* The PyQt specific flags. */
1239     struct _stringList *pyqt_flags_enums;   /* The names of the flagged enum. */
1240     const char *pyqt_interface;         /* The Qt interface name. */
1241     nameDef *pyname;                    /* The Python name. */
1242     int no_typehint;                    /* The type hint will be suppressed. */
1243     ifaceFileDef *iff;                  /* The interface file. */
1244     struct _classDef *ecd;              /* The enclosing scope. */
1245     struct _classDef *real;             /* The real class if this is a proxy or extender. */
1246     classList *supers;                  /* The parent classes. */
1247     mroDef *mro;                        /* The super-class hierarchy. */
1248     nameDef *metatype;                  /* The meta-type. */
1249     nameDef *supertype;                 /* The super-type. */
1250     templateDef *td;                    /* The instantiated template. */
1251     ctorDef *ctors;                     /* The constructors. */
1252     ctorDef *defctor;                   /* The default ctor. */
1253     codeBlockList *dealloccode;         /* Handwritten dealloc code. */
1254     codeBlockList *dtorcode;            /* Handwritten dtor code. */
1255     throwArgs *dtorexceptions;          /* The dtor exceptions. */
1256     memberDef *members;                 /* The member functions. */
1257     overDef *overs;                     /* The overloads. */
1258     argList *casts;                     /* The operator casts. */
1259     virtOverDef *vmembers;              /* The virtual members. */
1260     visibleList *visible;               /* The visible members. */
1261     codeBlockList *cppcode;             /* Class C++ code. */
1262     codeBlockList *convtosubcode;       /* Convert to sub C++ code. */
1263     struct _classDef *subbase;          /* Sub-class base class. */
1264     codeBlockList *instancecode;        /* Create instance code. */
1265     codeBlockList *convtocode;          /* Convert to C++ code. */
1266     codeBlockList *convfromcode;        /* Convert from C++ code. */
1267     codeBlockList *travcode;            /* Traverse code. */
1268     codeBlockList *clearcode;           /* Clear code. */
1269     codeBlockList *getbufcode;          /* Get buffer code. */
1270     codeBlockList *releasebufcode;      /* Release buffer code. */
1271     codeBlockList *picklecode;          /* Pickle code. */
1272     codeBlockList *finalcode;           /* Finalisation code. */
1273     codeBlockList *typehintcode;        /* Type hint code. */
1274     propertyDef *properties;            /* The properties. */
1275     const char *virt_error_handler;     /* The virtual error handler. */
1276     typeHintDef *typehint_in;           /* The PEP 484 input type hint. */
1277     typeHintDef *typehint_out;          /* The PEP 484 output type hint. */
1278     const char *typehint_value;         /* The type hint value. */
1279     struct _classDef *next;             /* Next in the list. */
1280 } classDef;
1281 
1282 
1283 /* A class template definition. */
1284 typedef struct _classTmplDef {
1285     signatureDef sig;                   /* The template arguments. */
1286     classDef *cd;                       /* The class itself. */
1287     struct _classTmplDef *next;         /* The next in the list. */
1288 } classTmplDef;
1289 
1290 
1291 /* A mapped type template definition. */
1292 typedef struct _mappedTypeTmplDef {
1293     signatureDef sig;                   /* The template arguments. */
1294     mappedTypeDef *mt;                  /* The mapped type itself. */
1295     struct _mappedTypeTmplDef *next;    /* The next in the list. */
1296 } mappedTypeTmplDef;
1297 
1298 
1299 /* The extracts for an identifier. */
1300 typedef struct _extractDef {
1301     const char *id;                     /* The identifier. */
1302     struct _extractPartDef *parts;      /* The ordered list of parts. */
1303     struct _extractDef *next;           /* The next in the list. */
1304 } extractDef;
1305 
1306 
1307 /* Part of an extract for an identifier. */
1308 typedef struct _extractPartDef {
1309     int order;                          /* The order of the part. */
1310     codeBlock *part;                    /* The part itself. */
1311     struct _extractPartDef *next;       /* The next in the list. */
1312 } extractPartDef;
1313 
1314 
1315 /* A rule for automatic Python naming. */
1316 typedef struct _autoPyNameDef {
1317     const char *remove_leading;         /* Leading string to remove. */
1318     struct _autoPyNameDef *next;        /* The next in the list. */
1319 } autoPyNameDef;
1320 
1321 
1322 /* The parse tree corresponding to the specification file. */
1323 typedef struct {
1324     moduleDef *module;                  /* The module being generated. */
1325     moduleDef *modules;                 /* The list of modules. */
1326     nameDef *namecache;                 /* The name cache. */
1327     ifaceFileDef *ifacefiles;           /* The list of interface files. */
1328     classDef *classes;                  /* The list of classes. */
1329     classTmplDef *classtemplates;       /* The list of class templates. */
1330     exceptionDef *exceptions;           /* The list of exceptions. */
1331     mappedTypeDef *mappedtypes;         /* The mapped types. */
1332     mappedTypeTmplDef *mappedtypetemplates; /* The list of mapped type templates. */
1333     enumDef *enums;                     /* List of enums. */
1334     varDef *vars;                       /* List of variables. */
1335     typedefDef *typedefs;               /* List of typedefs. */
1336     int nrvirthandlers;                 /* The number of virtual handlers. */
1337     virtHandlerDef *virthandlers;       /* The virtual handlers. */
1338     virtErrorHandler *errorhandlers;    /* The list of virtual error handlers. */
1339     codeBlockList *exphdrcode;          /* Exported header code. */
1340     codeBlockList *exptypehintcode;     /* Exported type hint code. */
1341     codeBlockList *docs;                /* Documentation. */
1342     classDef *qobject_cd;               /* QObject class, NULL if none. */
1343     int sigslots;                       /* Set if signals or slots are used. */
1344     int genc;                           /* Set if we are generating C code. */
1345     struct _stringList *plugins;        /* The list of plugins. */
1346     struct _extractDef *extracts;       /* The list of extracts. */
1347 } sipSpec;
1348 
1349 
1350 /* A list of strings. */
1351 typedef struct _stringList {
1352     const char *s;                      /* The string. */
1353     struct _stringList *next;           /* The next in the list. */
1354 } stringList;
1355 
1356 
1357 /* File specific context information for the parser. */
1358 typedef struct _parserContext {
1359     const char *filename;               /* The %Import or %Include filename. */
1360     int ifdepth;                        /* The depth of nested if's. */
1361     moduleDef *prevmod;                 /* The previous module. */
1362 } parserContext;
1363 
1364 
1365 extern unsigned sipVersion;             /* The version of SIP. */
1366 extern const char *sipVersionStr;       /* The version of SIP as a string. */
1367 extern unsigned abiMajor;               /* The ABI major version number. */
1368 extern unsigned abiMinor;               /* The ABI minor version number. */
1369 extern stringList *includeDirList;      /* The include directory list for SIP files. */
1370 
1371 
1372 void parse(sipSpec *, FILE *, char *, int, stringList **, stringList *,
1373         stringList **, int, stringList **sip_files);
1374 void get_bindings_configuration(const char *sip_file, stringList **tags,
1375         stringList **disabled);
1376 void parserEOF(const char *,parserContext *);
1377 void transform(sipSpec *, int);
1378 stringList *generateCode(sipSpec *, char *, const char *, int, int, int, int,
1379         stringList *needed_qualifiers, stringList *, int, int, const char *,
1380         const char **api_header);
1381 void generateExtracts(sipSpec *pt, const stringList *extracts);
1382 void addExtractPart(sipSpec *pt, const char *id, int order, codeBlock *part);
1383 void generateAPI(sipSpec *pt, moduleDef *mod, const char *apiFile);
1384 void generateXML(sipSpec *pt, moduleDef *mod, const char *xmlFile);
1385 void generateTypeHints(sipSpec *pt, moduleDef *mod, const char *pyiFile);
1386 void generateExpression(valueDef *vd, int in_str, FILE *fp);
1387 void warning(Warning w, const char *fmt, ...);
1388 void deprecated(const char *msg);
1389 SIP_NORETURN void fatal(const char *fmt, ...);
1390 void fatalAppend(const char *fmt, ...);
1391 void fatalScopedName(scopedNameDef *);
1392 void getSourceLocation(sourceLocation *slp);
1393 int setInputFile(FILE *open_fp, parserContext *pc, int optional);
1394 void resetLexerState(void);
1395 void *sipMalloc(size_t n);
1396 void *sipCalloc(size_t nr, size_t n);
1397 char *sipStrdup(const char *);
1398 char *concat(const char *, ...);
1399 void append(char **, const char *);
1400 void appendToIfaceFileList(ifaceFileList **ifflp, ifaceFileDef *iff);
1401 int selectedQualifier(stringList *needed_qualifiers, qualDef *qd);
1402 int excludedFeature(stringList *,qualDef *);
1403 int sameSignature(signatureDef *,signatureDef *,int);
1404 int sameTemplateSignature(signatureDef *tmpl_sd, signatureDef *args_sd,
1405         int deep);
1406 int compareScopedNames(scopedNameDef *snd1, scopedNameDef *snd2);
1407 int sameBaseType(argDef *,argDef *);
1408 char *scopedNameTail(scopedNameDef *);
1409 scopedNameDef *copyScopedName(scopedNameDef *);
1410 void appendScopedName(scopedNameDef **,scopedNameDef *);
1411 scopedNameDef *text2scopePart(char *text);
1412 void freeScopedName(scopedNameDef *);
1413 void appendToClassList(classList **,classDef *);
1414 void appendCodeBlockList(codeBlockList **headp, codeBlockList *cbl);
1415 void prcode(FILE *fp, const char *fmt, ...);
1416 void prCopying(FILE *fp, moduleDef *mod, const char *comment);
1417 void prOverloadName(FILE *fp, overDef *od);
1418 void prDefaultValue(argDef *ad, int in_str, FILE *fp);
1419 void prScopedPythonName(FILE *fp, classDef *scope, const char *pyname);
1420 void searchTypedefs(sipSpec *pt, scopedNameDef *snd, argDef *ad);
1421 int isZeroArgSlot(memberDef *md);
1422 int isIntReturnSlot(memberDef *md);
1423 int isSSizeReturnSlot(memberDef *md);
1424 int isLongReturnSlot(memberDef *md);
1425 int isVoidReturnSlot(memberDef *md);
1426 int isNumberSlot(memberDef *md);
1427 int isInplaceNumberSlot(memberDef *md);
1428 int isRichCompareSlot(memberDef *md);
1429 mappedTypeDef *allocMappedType(sipSpec *pt, argDef *type);
1430 void appendString(stringList **headp, const char *s);
1431 void appendTypeStrings(scopedNameDef *ename, signatureDef *patt, signatureDef *src, signatureDef *known, scopedNameDef **names, scopedNameDef **values);
1432 codeBlockList *templateCode(sipSpec *pt, ifaceFileList **used,
1433         codeBlockList *ocbl, scopedNameDef *names, scopedNameDef *values);
1434 ifaceFileDef *findIfaceFile(sipSpec *pt, moduleDef *mod,
1435         scopedNameDef *fqname, ifaceFileType iftype,
1436         apiVersionRangeDef *api_range, argDef *ad);
1437 int pluginPyQt5(sipSpec *pt);
1438 SIP_NORETURN void yyerror(char *);
1439 void yywarning(char *);
1440 int yylex(void);
1441 nameDef *cacheName(sipSpec *pt, const char *name);
1442 scopedNameDef *encodedTemplateName(templateDef *td);
1443 apiVersionRangeDef *findAPI(sipSpec *pt, const char *name);
1444 memberDef *findMethod(classDef *cd, const char *name);
1445 typeHintDef *newTypeHint(char *raw_hint);
1446 int isPyKeyword(const char *word);
1447 void getDefaultImplementation(sipSpec *pt, argType atype, classDef **cdp,
1448         mappedTypeDef **mtdp);
1449 char *templateString(const char *src, scopedNameDef *names,
1450         scopedNameDef *values);
1451 int inDefaultAPI(sipSpec *pt, apiVersionRangeDef *range);
1452 void dsCtor(sipSpec *pt, classDef *cd, ctorDef *ct, FILE *fp);
1453 void dsOverload(sipSpec *pt, overDef *od, int is_method, FILE *fp);
1454 scopedNameDef *getFQCNameOfType(argDef *ad);
1455 scopedNameDef *removeGlobalScope(scopedNameDef *snd);
1456 void pyiTypeHint(sipSpec *pt, typeHintDef *thd, moduleDef *mod, int out,
1457         ifaceFileList *defined, int pep484, int rest, FILE *fp);
1458 void restPyClass(classDef *cd, FILE *fp);
1459 void restPyEnum(enumDef *ed, FILE *fp);
1460 void generateBaseType(ifaceFileDef *scope, argDef *ad, int use_typename,
1461         int strip, FILE *fp);
1462 void normaliseArgs(signatureDef *sd);
1463 void restoreArgs(signatureDef *sd);
1464 void initialiseLexer(void);
1465 
1466 
1467 /* These are only here because bison publically references them. */
1468 
1469 /* Represent a set of option flags. */
1470 
1471 #define MAX_NR_FLAGS    5
1472 
1473 typedef enum {
1474     bool_flag,
1475     string_flag,
1476     string_list_flag,
1477     name_flag,
1478     opt_name_flag,
1479     dotted_name_flag,
1480     integer_flag,
1481     opt_integer_flag,
1482     api_range_flag
1483 } flagType;
1484 
1485 typedef struct {
1486     const char *fname;                  /* The flag name. */
1487     flagType ftype;                     /* The flag type. */
1488     union {                             /* The flag value. */
1489         char *sval;                     /* A string value. */
1490         struct _stringList *slval;      /* A string list value. */
1491         long ival;                      /* An integer value. */
1492         apiVersionRangeDef *aval;       /* An API range value. */
1493     } fvalue;
1494 } optFlag;
1495 
1496 typedef struct {
1497     int nrFlags;                        /* The number of flags. */
1498     optFlag flags[MAX_NR_FLAGS];        /* Each flag. */
1499 } optFlags;
1500 
1501 
1502 /* These represent the configuration of different directives. */
1503 
1504 /* %API */
1505 typedef struct _apiCfg {
1506     int token;
1507     const char *name;
1508     int version;
1509 } apiCfg;
1510 
1511 /* %AutoPyName */
1512 typedef struct _autoPyNameCfg {
1513     int token;
1514     const char *remove_leading;
1515 } autoPyNameCfg;
1516 
1517 /* %CompositeModule */
1518 typedef struct _compModuleCfg {
1519     int token;
1520     const char *name;
1521     docstringDef *docstring;
1522 } compModuleCfg;
1523 
1524 /* %DefaultDocstringFormat */
1525 typedef struct _defDocstringFmtCfg {
1526     int token;
1527     const char *name;
1528 } defDocstringFmtCfg;
1529 
1530 /* %DefaultDocstringSignature */
1531 typedef struct _defDocstringSigCfg {
1532     int token;
1533     const char *name;
1534 } defDocstringSigCfg;
1535 
1536 /* %DefaultEncoding */
1537 typedef struct _defEncodingCfg {
1538     int token;
1539     const char *name;
1540 } defEncodingCfg;
1541 
1542 /* %DefaultMetatype */
1543 typedef struct _defMetatypeCfg {
1544     int token;
1545     const char *name;
1546 } defMetatypeCfg;
1547 
1548 /* %DefaultSupertype */
1549 typedef struct _defSupertypeCfg {
1550     int token;
1551     const char *name;
1552 } defSupertypeCfg;
1553 
1554 /* %Docstring */
1555 typedef struct _docstringCfg {
1556     int token;
1557     Format format;
1558     Signature signature;
1559 } docstringCfg;
1560 
1561 /* %Exception */
1562 typedef struct _exceptionCfg {
1563     int token;
1564     codeBlock *type_header_code;
1565     codeBlock *raise_code;
1566 } exceptionCfg;
1567 
1568 /* %Extract */
1569 typedef struct _extractCfg {
1570     int token;
1571     const char *id;
1572     int order;
1573 } extractCfg;
1574 
1575 /* %Feature */
1576 typedef struct _featureCfg {
1577     int token;
1578     const char *name;
1579 } featureCfg;
1580 
1581 /* %HiddenNamespace */
1582 typedef struct _hiddenNsCfg {
1583     int token;
1584     scopedNameDef *name;
1585 } hiddenNsCfg;
1586 
1587 /* %Import */
1588 typedef struct _importCfg {
1589     int token;
1590     const char *name;
1591 } importCfg;
1592 
1593 /* %Include */
1594 typedef struct _includeCfg {
1595     int token;
1596     const char *name;
1597     int optional;
1598 } includeCfg;
1599 
1600 /* %License */
1601 typedef struct _licenseCfg {
1602     int token;
1603     const char *type;
1604     const char *licensee;
1605     const char *signature;
1606     const char *timestamp;
1607 } licenseCfg;
1608 
1609 /* %Module and its sub-directives. */
1610 typedef struct _moduleCfg {
1611     int token;
1612     int c_module;
1613     KwArgs kwargs;
1614     const char *name;
1615     int use_arg_names;
1616     int use_limited_api;
1617     int all_raise_py_exc;
1618     int call_super_init;
1619     const char *def_error_handler;
1620     docstringDef *docstring;
1621 } moduleCfg;
1622 
1623 /* %Plugin */
1624 typedef struct _pluginCfg {
1625     int token;
1626     const char *name;
1627 } pluginCfg;
1628 
1629 /* %Property */
1630 typedef struct _propertyCfg {
1631     int token;
1632     const char *get;
1633     const char *name;
1634     const char *set;
1635     docstringDef *docstring;
1636 } propertyCfg;
1637 
1638 /* Variable sub-directives. */
1639 typedef struct _variableCfg {
1640     int token;
1641     codeBlock *access_code;
1642     codeBlock *get_code;
1643     codeBlock *set_code;
1644 } variableCfg;
1645 
1646 /* %VirtualErrorHandler */
1647 typedef struct _vehCfg {
1648     int token;
1649     const char *name;
1650 } vehCfg;
1651 
1652 #endif
1653