]>
Commit | Line | Data |
---|---|---|
6a30d63a RD |
1 | Index: Source/Modules/python.cxx |
2 | =================================================================== | |
6c7eee75 | 3 | RCS file: /cvsroot/swig/SWIG/Source/Modules/python.cxx,v |
0cb6df6e RD |
4 | retrieving revision 1.40 |
5 | diff -u -4 -r1.40 python.cxx | |
6 | --- Source/Modules/python.cxx 24 Jan 2004 00:25:31 -0000 1.40 | |
6c7eee75 RD |
7 | +++ Source/Modules/python.cxx 22 Apr 2004 16:38:43 -0000 |
8 | @@ -8,9 +8,9 @@ | |
9 | * Copyright (C) 1999-2000. The University of Chicago | |
10 | * See the file LICENSE for information on usage and redistribution. | |
11 | * ----------------------------------------------------------------------------- */ | |
12 | ||
13 | -char cvsroot_python_cxx[] = "$Header$"; | |
14 | +char cvsroot_python_cxx[] = "$Header$"; | |
15 | ||
16 | #include "swigmod.h" | |
17 | ||
18 | #include <ctype.h> | |
19 | @@ -50,8 +50,18 @@ | |
1e9b37a2 RD |
20 | static int have_constructor; |
21 | static int have_repr; | |
22 | static String *real_classname; | |
6a30d63a | 23 | |
6a30d63a RD |
24 | +/* flags for the make_autodoc function */ |
25 | +enum autodoc_t { | |
26 | + AUTODOC_CLASS, | |
27 | + AUTODOC_CTOR, | |
28 | + AUTODOC_DTOR, | |
29 | + AUTODOC_STATICFUNC, | |
6c7eee75 RD |
30 | + AUTODOC_FUNC, |
31 | + AUTODOC_METHOD | |
6a30d63a RD |
32 | +}; |
33 | + | |
1e9b37a2 RD |
34 | static const char *usage = (char *)"\ |
35 | Python Options (available with -python)\n\ | |
36 | -ldflags - Print runtime libraries to link with\n\ | |
37 | -globals <name> - Set <name> used to access C global variable [default: 'cvar']\n\ | |
6c7eee75 | 38 | @@ -417,17 +427,25 @@ |
6977316f | 39 | * functions. |
6a30d63a RD |
40 | * ------------------------------------------------------------ */ |
41 | ||
42 | void emitFunctionShadowHelper(Node *n, File *f_dest, String *name, int kw) { | |
43 | - if ( ! have_addtofunc(n) ) { | |
6977316f | 44 | - /* If there is no addtofunc directive then just assign from the extension module */ |
6c7eee75 RD |
45 | + if ( !have_pythonprepend(n) && !have_pythonappend(n) && !have_docstring(n) ) { |
46 | + /* If there is no pythonappend or docstring directive then just assign from the extension module */ | |
6a30d63a RD |
47 | Printv(f_dest, "\n", name, " = ", module, ".", name, "\n", NIL); |
48 | } else { | |
49 | /* Otherwise make a wrapper function to insert the code into */ | |
50 | Printv(f_dest, "\ndef ", name, "(*args", (kw ? ", **kwargs" : ""), "):\n", NIL); | |
51 | - Printv(f_dest, tab4, "val = ", funcCallHelper(name, kw), "\n", NIL); | |
52 | - Printv(f_dest, tab4, addtofunc(n), "\n", NIL); | |
53 | - Printv(f_dest, tab4, "return val\n", NIL); | |
54 | + if ( have_docstring(n) ) | |
6977316f | 55 | + Printv(f_dest, tab4, docstring(n, AUTODOC_FUNC, tab4), "\n", NIL); |
6c7eee75 RD |
56 | + if ( have_pythonprepend(n) ) |
57 | + Printv(f_dest, tab4, pythonprepend(n), "\n", NIL); | |
58 | + if ( have_pythonappend(n) ) { | |
6a30d63a | 59 | + Printv(f_dest, tab4, "val = ", funcCallHelper(name, kw), "\n", NIL); |
6c7eee75 | 60 | + Printv(f_dest, tab4, pythonappend(n), "\n", NIL); |
6a30d63a RD |
61 | + Printv(f_dest, tab4, "return val\n", NIL); |
62 | + } else { | |
63 | + Printv(f_dest, tab4, "return ", funcCallHelper(name, kw), "\n", NIL); | |
64 | + } | |
65 | } | |
66 | } | |
67 | ||
6977316f | 68 | |
6c7eee75 | 69 | @@ -441,24 +459,303 @@ |
6977316f | 70 | } |
6a30d63a RD |
71 | |
72 | ||
73 | /* ------------------------------------------------------------ | |
6c7eee75 RD |
74 | - * have_addtofunc() |
75 | - * Check if there is a %addtofunc directive and it has text | |
6a30d63a RD |
76 | + * have_docstring() |
77 | + * Check if there is a docstring directive and it has text, | |
78 | + * or there is an autodoc flag set | |
79 | + * ------------------------------------------------------------ */ | |
80 | + | |
81 | + bool have_docstring(Node *n) { | |
82 | + String* str = Getattr(n, "feature:docstring"); | |
83 | + return (str != NULL && Len(str) > 0) || | |
84 | + (Getattr(n,"feature:autodoc") && !Getattr(n, "feature:noautodoc")); | |
85 | + } | |
86 | + | |
87 | + /* ------------------------------------------------------------ | |
88 | + * docstring() | |
89 | + * Get the docstring text, stripping off {} if neccessary, | |
6977316f | 90 | + * and enclose in triple double quotes. If autodoc is also |
6a30d63a RD |
91 | + * set then it will build a combined docstring. |
92 | + * ------------------------------------------------------------ */ | |
93 | + | |
6977316f | 94 | + String *docstring(Node *n, autodoc_t ad_type, const String* indent) { |
6a30d63a RD |
95 | + String* str = Getattr(n, "feature:docstring"); |
96 | + bool have_ds = (str != NULL && Len(str) > 0); | |
97 | + bool have_auto = (Getattr(n,"feature:autodoc") && !Getattr(n, "feature:noautodoc")); | |
98 | + char* triple_double = "\"\"\""; | |
6977316f RD |
99 | + String* autodoc = NULL; |
100 | + String* doc = NULL; | |
6a30d63a RD |
101 | + |
102 | + if ( have_ds ) { | |
103 | + char* t = Char(str); | |
104 | + if (*t == '{') { | |
105 | + Delitem(str ,0); | |
106 | + Delitem(str,DOH_END); | |
107 | + } | |
108 | + } | |
109 | + | |
110 | + if ( have_auto ) { | |
111 | + autodoc = make_autodoc(n, ad_type); | |
112 | + have_auto = (autodoc != NULL && Len(autodoc) > 0); | |
113 | + } | |
114 | + | |
6977316f RD |
115 | + // If there is more than one line then make docstrings like this: |
116 | + // | |
117 | + // """ | |
118 | + // This is line1 | |
119 | + // And here is line2 followed by the rest of them | |
120 | + // """ | |
121 | + // | |
122 | + // otherwise, put it all on a single line | |
123 | + // | |
124 | + if ( have_auto && have_ds ) { // Both autodoc and docstring are present | |
125 | + doc = NewString(""); | |
126 | + Printv(doc, triple_double, "\n", | |
127 | + pythoncode(autodoc, indent), "\n", | |
128 | + pythoncode(str, indent), | |
129 | + indent, triple_double, NIL); | |
130 | + } | |
131 | + else if ( !have_auto && have_ds ) { // only docstring | |
132 | + if (Strchr(str, '\n') == NULL) { | |
133 | + doc = NewStringf("%s%s%s", triple_double, str, triple_double); | |
134 | + } | |
135 | + else { | |
136 | + doc = NewString(""); | |
137 | + Printv(doc, triple_double, "\n", | |
138 | + pythoncode(str, indent), | |
139 | + indent, triple_double, NIL); | |
140 | + } | |
141 | + } | |
142 | + else if ( have_auto && !have_ds ) { // only autodoc | |
143 | + if (Strchr(autodoc, '\n') == NULL) { | |
144 | + doc = NewStringf("%s%s%s", triple_double, autodoc, triple_double); | |
145 | + } | |
146 | + else { | |
147 | + doc = NewString(""); | |
148 | + Printv(doc, triple_double, "\n", | |
149 | + pythoncode(autodoc, indent), | |
150 | + indent, triple_double, NIL); | |
151 | + } | |
152 | + } | |
6a30d63a | 153 | + else |
6977316f | 154 | + doc = NewString(""); |
6a30d63a | 155 | + |
6977316f RD |
156 | + // Save the generated strings in the parse tree in case they are used later |
157 | + // by post processing tools | |
6a30d63a RD |
158 | + Setattr(n, "python:docstring", doc); |
159 | + Setattr(n, "python:autodoc", autodoc); | |
160 | + return doc; | |
161 | + } | |
162 | + | |
163 | + | |
164 | + /* ------------------------------------------------------------ | |
165 | + * make_autodoc() | |
166 | + * Build a docstring for the node, using parameter and other | |
167 | + * info in the parse tree. If the value of the autodoc | |
168 | + * attribute is "0" then do not include parameter types, if | |
169 | + * it is "1" (the default) then do. If it has some other | |
170 | + * value then assume it is supplied by the extension writer | |
171 | + * and use it directly. | |
6c7eee75 RD |
172 | * ------------------------------------------------------------ */ |
173 | ||
174 | - bool have_addtofunc(Node *n) { | |
175 | - String* str = Getattr(n, "feature:addtofunc"); | |
6a30d63a RD |
176 | + String* make_autodoc(Node *n, autodoc_t ad_type) { |
177 | + | |
178 | + if (ad_type == AUTODOC_CLASS) | |
80f33439 | 179 | + return NULL; // No function call to document in this case |
6a30d63a | 180 | + |
6a30d63a RD |
181 | + // If the function is overloaded then this funciton is called |
182 | + // for the last one. Rewind to the first so the docstrings are | |
183 | + // in order. | |
184 | + while ( Getattr(n, "sym:previousSibling") ) | |
185 | + n = Getattr(n, "sym:previousSibling"); | |
186 | + | |
187 | + String* doc = NewString(""); | |
188 | + while (n) { | |
80f33439 RD |
189 | + bool showTypes = false; |
190 | + bool skipAuto = false; | |
191 | + | |
192 | + // check how should the parameters be rendered? | |
193 | + String* autodoc = Getattr(n, "feature:autodoc"); | |
194 | + if (Strcmp(autodoc, "0") == 0) | |
195 | + showTypes = false; | |
196 | + else if (Strcmp(autodoc, "1") == 0) | |
197 | + showTypes = true; | |
198 | + else { | |
199 | + // if not "0" or "1" then autodoc is already the string that should be used | |
200 | + Printf(doc, "%s", autodoc); | |
201 | + skipAuto = true; | |
202 | + } | |
203 | + | |
204 | + if (!skipAuto) { | |
6a30d63a RD |
205 | + String* symname = Getattr(n, "sym:name"); |
206 | + SwigType* type = Getattr(n, "type"); | |
207 | + | |
208 | + if (type) { | |
209 | + if (Strcmp(type, "void") == 0) | |
210 | + type = NULL; | |
211 | + else { | |
28a15b3e RD |
212 | + SwigType* qt = SwigType_typedef_resolve_all(type); |
213 | + if (SwigType_isenum(qt)) | |
214 | + type = NewString("int"); | |
215 | + else { | |
216 | + type = SwigType_base(type); | |
217 | + Node* lookup = Swig_symbol_clookup(type, 0); | |
218 | + if (lookup) | |
219 | + type = Getattr(lookup, "sym:name"); | |
220 | + } | |
80f33439 | 221 | + } |
6a30d63a RD |
222 | + } |
223 | + | |
224 | + switch ( ad_type ) { | |
225 | + case AUTODOC_CTOR: | |
6c7eee75 RD |
226 | + if ( Strcmp(class_name, symname) == 0) { |
227 | + String* paramList = make_autodocParmList(n, showTypes); | |
228 | + if (Len(paramList)) | |
229 | + Printf(doc, "__init__(self, %s) -> %s", paramList, class_name); | |
230 | + else | |
231 | + Printf(doc, "__init__(self) -> %s", class_name); | |
232 | + } | |
6a30d63a RD |
233 | + else |
234 | + Printf(doc, "%s(%s) -> %s", symname, make_autodocParmList(n, showTypes), class_name); | |
235 | + break; | |
236 | + | |
237 | + case AUTODOC_DTOR: | |
6c7eee75 | 238 | + Printf(doc, "__del__(self)"); |
6a30d63a | 239 | + break; |
80f33439 | 240 | + |
6a30d63a | 241 | + case AUTODOC_STATICFUNC: |
6c7eee75 | 242 | + Printf(doc, "%s.%s(%s)", class_name, symname, make_autodocParmList(n, showTypes)); |
6a30d63a RD |
243 | + if (type) Printf(doc, " -> %s", type); |
244 | + break; | |
245 | + | |
246 | + case AUTODOC_FUNC: | |
247 | + Printf(doc, "%s(%s)", symname, make_autodocParmList(n, showTypes)); | |
248 | + if (type) Printf(doc, " -> %s", type); | |
249 | + break; | |
6c7eee75 RD |
250 | + |
251 | + case AUTODOC_METHOD: | |
252 | + String* paramList = make_autodocParmList(n, showTypes); | |
253 | + if (Len(paramList)) | |
254 | + Printf(doc, "%s(self, %s)", symname, paramList); | |
255 | + else | |
256 | + Printf(doc, "%s(self)", symname); | |
257 | + if (type) Printf(doc, " -> %s", type); | |
258 | + break; | |
6a30d63a | 259 | + } |
80f33439 RD |
260 | + } |
261 | + | |
262 | + // if it's overloaded then get the next decl and loop around again | |
263 | + n = Getattr(n, "sym:nextSibling"); | |
264 | + if (n) | |
265 | + Printf(doc, "\n"); | |
6a30d63a RD |
266 | + } |
267 | + | |
268 | + return doc; | |
269 | + } | |
270 | + | |
271 | + | |
272 | + String* make_autodocParmList(Node* n, bool showTypes) { | |
273 | + String* doc = NewString(""); | |
274 | + ParmList* plist = Getattr(n,"parms"); | |
275 | + Parm* p; | |
276 | + Node* lookup; | |
277 | + int lines = 0; | |
278 | + const int maxwidth = 50; | |
279 | + | |
280 | + | |
281 | + for (p = plist; p; p = nextSibling(p)) { | |
282 | + String* name = Getattr(p, "name"); | |
283 | + String* value = Getattr(p, "value"); | |
284 | + | |
285 | + if ( Len(doc) ) { | |
286 | + // add a comma to the previous one if any | |
287 | + Printf(doc, ", "); | |
288 | + | |
289 | + // Do we need to wrap a long line? | |
290 | + if ((Len(doc) - lines*maxwidth) > maxwidth) { | |
6977316f | 291 | + Printf(doc, "\n%s", tab4); |
6a30d63a RD |
292 | + lines += 1; |
293 | + } | |
294 | + } | |
295 | + | |
296 | + // Do the param type too? | |
297 | + if (showTypes) { | |
298 | + SwigType* type = SwigType_base(Getattr(p, "type")); | |
28a15b3e RD |
299 | + SwigType* qt = SwigType_typedef_resolve_all(type); |
300 | + if (SwigType_isenum(qt)) | |
301 | + type = NewString("int"); | |
302 | + else { | |
303 | + lookup = Swig_symbol_clookup(type, 0); | |
304 | + if (lookup) | |
305 | + type = Getattr(lookup, "sym:name"); | |
306 | + } | |
6a30d63a RD |
307 | + Printf(doc, "%s ", type); |
308 | + } | |
309 | + | |
310 | + if (name) | |
311 | + Printf(doc, "%s", name); | |
312 | + else | |
313 | + Printf(doc, "??"); | |
314 | + | |
315 | + if (value) { | |
316 | + if (Strcmp(value, "NULL") == 0) | |
317 | + value = NewString("None"); | |
318 | + else { | |
319 | + lookup = Swig_symbol_clookup(value, 0); | |
320 | + if (lookup) | |
321 | + value = Getattr(lookup, "sym:name"); | |
322 | + } | |
323 | + Printf(doc, "=%s", value); | |
324 | + } | |
325 | + } | |
326 | + | |
327 | + return doc; | |
328 | + } | |
329 | + | |
330 | + | |
331 | + /* ------------------------------------------------------------ | |
6c7eee75 RD |
332 | + * have_pythonprepend() |
333 | + * Check if there is a %pythonprepend directive and it has text | |
334 | + * ------------------------------------------------------------ */ | |
335 | + | |
336 | + bool have_pythonprepend(Node *n) { | |
337 | + String* str = Getattr(n, "feature:pythonprepend"); | |
338 | + return (str != NULL && Len(str) > 0); | |
339 | + } | |
340 | + | |
341 | + /* ------------------------------------------------------------ | |
342 | + * pythonprepend() | |
343 | + * Get the %pythonprepend code, stripping off {} if neccessary | |
344 | + * ------------------------------------------------------------ */ | |
345 | + | |
346 | + String *pythonprepend(Node *n) { | |
347 | + String* str = Getattr(n, "feature:pythonprepend"); | |
348 | + char* t = Char(str); | |
349 | + if (*t == '{') { | |
350 | + Delitem(str ,0); | |
351 | + Delitem(str,DOH_END); | |
352 | + } | |
353 | + return str; | |
354 | + } | |
355 | + | |
356 | + /* ------------------------------------------------------------ | |
357 | + * have_pythonappend() | |
358 | + * Check if there is a %pythonappend directive and it has text | |
359 | + * ------------------------------------------------------------ */ | |
360 | + | |
361 | + bool have_pythonappend(Node *n) { | |
362 | + String* str = Getattr(n, "feature:pythonappend"); | |
363 | return (str != NULL && Len(str) > 0); | |
364 | } | |
365 | ||
366 | /* ------------------------------------------------------------ | |
367 | - * addtofunc() | |
368 | - * Get the %addtofunc code, stripping off {} if neccessary | |
369 | + * pythonappend() | |
370 | + * Get the %pythonappend code, stripping off {} if neccessary | |
6a30d63a | 371 | * ------------------------------------------------------------ */ |
6977316f | 372 | |
6c7eee75 RD |
373 | - String *addtofunc(Node *n) { |
374 | - String* str = Getattr(n, "feature:addtofunc"); | |
375 | + String *pythonappend(Node *n) { | |
376 | + String* str = Getattr(n, "feature:pythonappend"); | |
377 | char* t = Char(str); | |
378 | if (*t == '{') { | |
379 | Delitem(str ,0); | |
380 | Delitem(str,DOH_END); | |
381 | @@ -1731,9 +2028,11 @@ | |
6977316f | 382 | Printf(f_shadow, modern ? "(object)" : "(_object)"); |
6a30d63a RD |
383 | } |
384 | } | |
385 | Printf(f_shadow,":\n"); | |
386 | - | |
6977316f RD |
387 | + if ( Getattr(n, "feature:docstring") ) // don't use have_docstring in this case because autodoc doesn't apply |
388 | + Printv(f_shadow, tab4, docstring(n, AUTODOC_CLASS, tab4), "\n", NIL); | |
6a30d63a RD |
389 | + |
390 | if (!modern) { | |
391 | Printv(f_shadow,tab4,"__swig_setmethods__ = {}\n",NIL); | |
392 | if (Len(base_class)) { | |
6977316f | 393 | Printf(f_shadow,"%sfor _s in [%s]: __swig_setmethods__.update(_s.__swig_setmethods__)\n",tab4,base_class); |
6c7eee75 | 394 | @@ -1866,16 +2165,24 @@ |
6977316f | 395 | Delete(pyaction); |
6a30d63a RD |
396 | Printv(f_shadow,pycode,"\n",NIL); |
397 | } else { | |
398 | ||
399 | - Printv(f_shadow, tab4, "def ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "): ", NIL); | |
400 | - if ( have_addtofunc(n) ) { | |
401 | - Printv(f_shadow, "\n", NIL); | |
402 | - Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); | |
403 | - Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); | |
404 | - Printv(f_shadow, tab8, "return val\n", NIL); | |
405 | + Printv(f_shadow, tab4, "def ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "):", NIL); | |
6c7eee75 | 406 | + if ( !have_pythonprepend(n) && !have_pythonappend(n) && !have_docstring(n)) { |
6a30d63a RD |
407 | + Printv(f_shadow, " return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); |
408 | } else { | |
409 | - Printv(f_shadow, "return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); | |
410 | + Printv(f_shadow, "\n", NIL); | |
411 | + if ( have_docstring(n) ) | |
6c7eee75 RD |
412 | + Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); |
413 | + if ( have_pythonprepend(n) ) | |
414 | + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); | |
415 | + if ( have_pythonappend(n) ) { | |
6a30d63a | 416 | + Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); |
6c7eee75 | 417 | + Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); |
6a30d63a RD |
418 | + Printv(f_shadow, tab8, "return val\n\n", NIL); |
419 | + } else { | |
420 | + Printv(f_shadow, tab8, "return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n\n", NIL); | |
421 | + } | |
422 | } | |
423 | } | |
424 | ||
6977316f | 425 | } |
6c7eee75 | 426 | @@ -1890,14 +2197,22 @@ |
6977316f | 427 | virtual int staticmemberfunctionHandler(Node *n) { |
6a30d63a RD |
428 | String *symname = Getattr(n,"sym:name"); |
429 | Language::staticmemberfunctionHandler(n); | |
430 | if (shadow) { | |
431 | - if ( !classic && have_addtofunc(n) ) { | |
6c7eee75 | 432 | + if ( !classic && (have_pythonprepend(n) || have_pythonappend(n) || have_docstring(n)) ) { |
6a30d63a RD |
433 | int kw = (check_kwargs(n) && !Getattr(n,"sym:overloaded")) ? 1 : 0; |
434 | Printv(f_shadow, tab4, "def ", symname, "(*args", (kw ? ", **kwargs" : ""), "):\n", NIL); | |
435 | - Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n", NIL); | |
436 | - Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); | |
437 | - Printv(f_shadow, tab8, "return val\n", NIL); | |
438 | + if ( have_docstring(n) ) | |
6977316f | 439 | + Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); |
6c7eee75 RD |
440 | + if ( have_pythonprepend(n) ) |
441 | + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); | |
442 | + if ( have_pythonappend(n) ) { | |
6a30d63a | 443 | + Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n", NIL); |
6c7eee75 | 444 | + Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); |
6a30d63a RD |
445 | + Printv(f_shadow, tab8, "return val\n\n", NIL); |
446 | + } else { | |
447 | + Printv(f_shadow, tab8, "return ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n\n", NIL); | |
448 | + } | |
449 | Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, | |
450 | " = staticmethod(", symname, ")\n", NIL); | |
451 | ||
6977316f | 452 | if (!modern) { |
6c7eee75 | 453 | @@ -1982,8 +2297,12 @@ |
6977316f | 454 | } |
6a30d63a RD |
455 | |
456 | Printv(f_shadow, tab4, "def __init__(self, *args", | |
457 | (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL); | |
458 | + if ( have_docstring(n) ) | |
6977316f | 459 | + Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); |
6c7eee75 RD |
460 | + if ( have_pythonprepend(n) ) |
461 | + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); | |
6a30d63a RD |
462 | Printv(f_shadow, pass_self, NIL); |
463 | if (!modern) { | |
464 | Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'this', ", | |
6977316f | 465 | funcCallHelper(Swig_name_construct(symname), allow_kwargs), ")\n", NIL); |
6c7eee75 RD |
466 | @@ -1996,10 +2315,10 @@ |
467 | Printv(f_shadow, tab8, "self.this = newobj.this\n", NIL); | |
6977316f | 468 | Printv(f_shadow, tab8, "self.thisown = 1\n", NIL); |
6a30d63a RD |
469 | Printv(f_shadow, tab8, "del newobj.thisown\n", NIL); |
470 | } | |
6c7eee75 | 471 | - if ( have_addtofunc(n) ) |
6a30d63a | 472 | - Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); |
6c7eee75 RD |
473 | + if ( have_pythonappend(n) ) |
474 | + Printv(f_shadow, tab8, pythonappend(n), "\n\n", NIL); | |
6a30d63a RD |
475 | Delete(pass_self); |
476 | } | |
477 | have_constructor = 1; | |
6977316f | 478 | } else { |
6c7eee75 | 479 | @@ -2015,13 +2334,17 @@ |
6977316f | 480 | } else { |
6a30d63a RD |
481 | |
482 | Printv(f_shadow_stubs, "\ndef ", symname, "(*args", | |
483 | (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL); | |
484 | + if ( have_docstring(n) ) | |
6977316f | 485 | + Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); |
6c7eee75 RD |
486 | + if ( have_pythonprepend(n) ) |
487 | + Printv(f_shadow_stubs, tab4, pythonprepend(n), "\n", NIL); | |
6a30d63a RD |
488 | Printv(f_shadow_stubs, tab4, "val = ", |
489 | funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL); | |
490 | Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); | |
6c7eee75 RD |
491 | - if ( have_addtofunc(n) ) |
492 | - Printv(f_shadow_stubs, tab4, addtofunc(n), "\n", NIL); | |
493 | + if ( have_pythonappend(n) ) | |
494 | + Printv(f_shadow_stubs, tab4, pythonappend(n), "\n", NIL); | |
495 | Printv(f_shadow_stubs, tab4, "return val\n", NIL); | |
496 | } | |
497 | } | |
498 | } | |
499 | @@ -2048,13 +2371,18 @@ | |
6977316f | 500 | Delete(pyaction); |
6a30d63a RD |
501 | Printv(f_shadow,pycode,"\n", NIL); |
502 | } else { | |
503 | Printv(f_shadow, tab4, "def __del__(self, destroy=", module, ".", Swig_name_destroy(symname), "):\n", NIL); | |
6c7eee75 RD |
504 | - if ( have_addtofunc(n) ) |
505 | - Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); | |
6a30d63a | 506 | + if ( have_docstring(n) ) |
6977316f | 507 | + Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL); |
6c7eee75 RD |
508 | + if ( have_pythonprepend(n) ) |
509 | + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); | |
6a30d63a | 510 | Printv(f_shadow, tab8, "try:\n", NIL); |
6977316f | 511 | - Printv(f_shadow, tab4, tab8, "if self.thisown: destroy(self)\n", NIL); |
6977316f | 512 | + Printv(f_shadow, tab8, tab4, "if self.thisown: destroy(self)\n", NIL); |
6c7eee75 RD |
513 | Printv(f_shadow, tab8, "except: pass\n", NIL); |
514 | + if ( have_pythonappend(n) ) | |
515 | + Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); | |
516 | + Printv(f_shadow, "\n", NIL); | |
6a30d63a RD |
517 | } |
518 | } | |
519 | return SWIG_OK; | |
6977316f | 520 | } |