1/* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
4 *
5 * tcl8.cxx
6 *
7 * Tcl8 language module for SWIG.
8 * ----------------------------------------------------------------------------- */
9
10char cvsroot_tcl8_cxx[] = "$Id: tcl8.cxx 11518 2009-08-08 22:56:10Z wsfulton $";
11
12#include "swigmod.h"
13#include "cparse.h"
14static int treduce = SWIG_cparse_template_reduce(0);
15
16static const char *usage = (char *) "\
17Tcl 8 Options (available with -tcl)\n\
18     -itcl           - Enable ITcl support\n\
19     -nosafe         - Leave out SafeInit module function.\n\
20     -prefix <name>  - Set a prefix <name> to be prepended to all names\n\
21     -namespace      - Build module into a Tcl 8 namespace\n\
22     -pkgversion     - Set package version\n\n";
23
24static String *cmd_tab = 0;	/* Table of command names    */
25static String *var_tab = 0;	/* Table of global variables */
26static String *const_tab = 0;	/* Constant table            */
27static String *methods_tab = 0;	/* Methods table             */
28static String *attr_tab = 0;	/* Attribute table           */
29static String *prefix = 0;
30static String *module = 0;
31static int nspace = 0;
32static String *init_name = 0;
33static String *ns_name = 0;
34static int have_constructor;
35static String *constructor_name;
36static int have_destructor;
37static int have_base_classes;
38static String *destructor_action = 0;
39static String *version = (String *) "0.0";
40static String *class_name = 0;
41
42static int have_attributes;
43static int have_methods;
44static int nosafe = 0;
45
46static File *f_header = 0;
47static File *f_wrappers = 0;
48static File *f_init = 0;
49static File *f_begin = 0;
50static File *f_runtime = 0;
51
52
53//  Itcl support
54static int itcl = 0;
55static File *f_shadow = 0;
56static File *f_shadow_stubs = 0;
57
58static String *constructor = 0;
59static String *destructor = 0;
60static String *base_classes = 0;
61static String *base_class_init = 0;
62static String *methods = 0;
63static String *imethods = 0;
64static String *attributes = 0;
65static String *attribute_traces = 0;
66static String *iattribute_traces = 0;
67
68
69
70class TCL8:public Language {
71public:
72
73  /* ------------------------------------------------------------
74   * TCL8::main()
75   * ------------------------------------------------------------ */
76
77  virtual void main(int argc, char *argv[]) {
78    int cppcast = 1;
79
80     SWIG_library_directory("tcl");
81
82    for (int i = 1; i < argc; i++) {
83      if (argv[i]) {
84	if (strcmp(argv[i], "-prefix") == 0) {
85	  if (argv[i + 1]) {
86	    prefix = NewString(argv[i + 1]);
87	    Swig_mark_arg(i);
88	    Swig_mark_arg(i + 1);
89	    i++;
90	  } else
91	     Swig_arg_error();
92	} else if (strcmp(argv[i], "-pkgversion") == 0) {
93	  if (argv[i + 1]) {
94	    version = NewString(argv[i + 1]);
95	    Swig_mark_arg(i);
96	    Swig_mark_arg(i + 1);
97	    i++;
98	  }
99	} else if (strcmp(argv[i], "-namespace") == 0) {
100	  nspace = 1;
101	  Swig_mark_arg(i);
102	} else if (strcmp(argv[i], "-itcl") == 0) {
103	  itcl = 1;
104	  Swig_mark_arg(i);
105	} else if (strcmp(argv[i], "-nosafe") == 0) {
106	  nosafe = 1;
107	  Swig_mark_arg(i);
108	} else if (strcmp(argv[i], "-cppcast") == 0) {
109	  cppcast = 1;
110	  Swig_mark_arg(i);
111	} else if (strcmp(argv[i], "-nocppcast") == 0) {
112	  cppcast = 0;
113	  Swig_mark_arg(i);
114	} else if (strcmp(argv[i], "-help") == 0) {
115	  fputs(usage, stdout);
116	}
117      }
118    }
119
120    if (cppcast) {
121      Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0);
122    }
123
124    Preprocessor_define("SWIGTCL 1", 0);
125    // SWIGTCL8 is deprecated, and no longer documented.
126    Preprocessor_define("SWIGTCL8 1", 0);
127    SWIG_typemap_lang("tcl8");
128    SWIG_config_file("tcl8.swg");
129    allow_overloading();
130  }
131
132  /* ------------------------------------------------------------
133   * top()
134   * ------------------------------------------------------------ */
135
136  virtual int top(Node *n) {
137
138    /* Initialize all of the output files */
139    String *outfile = Getattr(n, "outfile");
140
141    f_begin = NewFile(outfile, "w", SWIG_output_files());
142    if (!f_begin) {
143      FileErrorDisplay(outfile);
144      SWIG_exit(EXIT_FAILURE);
145    }
146    f_runtime = NewString("");
147    f_init = NewString("");
148    f_header = NewString("");
149    f_wrappers = NewString("");
150
151    /* Register file targets with the SWIG file handler */
152    Swig_register_filebyname("header", f_header);
153    Swig_register_filebyname("wrapper", f_wrappers);
154    Swig_register_filebyname("begin", f_begin);
155    Swig_register_filebyname("runtime", f_runtime);
156    Swig_register_filebyname("init", f_init);
157
158    /* Initialize some variables for the object interface */
159
160    cmd_tab = NewString("");
161    var_tab = NewString("");
162    methods_tab = NewString("");
163    const_tab = NewString("");
164
165    Swig_banner(f_begin);
166
167    Printf(f_runtime, "\n");
168    Printf(f_runtime, "#define SWIGTCL\n");
169    Printf(f_runtime, "\n");
170
171    /* Set the module name, namespace, and prefix */
172
173    module = NewStringf("%(lower)s", Getattr(n, "name"));
174    init_name = NewStringf("%(title)s_Init", module);
175
176    ns_name = prefix ? Copy(prefix) : Copy(module);
177    if (prefix)
178      Append(prefix, "_");
179
180
181    /* If shadow classing is enabled, we're going to change the module name to "_module" */
182    if (itcl) {
183      String *filen;
184      filen = NewStringf("%s%s.itcl", Swig_file_dirname(outfile), module);
185
186      Insert(module, 0, "_");
187
188      if ((f_shadow = NewFile(filen, "w", SWIG_output_files())) == 0) {
189	FileErrorDisplay(filen);
190	SWIG_exit(EXIT_FAILURE);
191      }
192      f_shadow_stubs = NewString("");
193
194      Swig_register_filebyname("shadow", f_shadow);
195      Swig_register_filebyname("itcl", f_shadow);
196
197      Swig_banner_target_lang(f_shadow, "#");
198
199      Printv(f_shadow, "\npackage require Itcl\n\n", NIL);
200      Delete(filen);
201    }
202
203    /* Generate some macros used throughout code generation */
204
205    Printf(f_header, "#define SWIG_init    %s\n", init_name);
206    Printf(f_header, "#define SWIG_name    \"%s\"\n", module);
207    if (nspace) {
208      Printf(f_header, "#define SWIG_prefix  \"%s::\"\n", ns_name);
209      Printf(f_header, "#define SWIG_namespace \"%s\"\n\n", ns_name);
210    } else {
211      Printf(f_header, "#define SWIG_prefix  \"%s\"\n", prefix);
212    }
213    Printf(f_header, "#define SWIG_version \"%s\"\n", version);
214
215    Printf(cmd_tab, "\nstatic swig_command_info swig_commands[] = {\n");
216    Printf(var_tab, "\nstatic swig_var_info swig_variables[] = {\n");
217    Printf(const_tab, "\nstatic swig_const_info swig_constants[] = {\n");
218
219    Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
220
221    /* Start emitting code */
222    Language::top(n);
223
224    /* Done.  Close up the module */
225    Printv(cmd_tab, tab4, "{0, 0, 0}\n", "};\n", NIL);
226    Printv(var_tab, tab4, "{0,0,0,0}\n", "};\n", NIL);
227    Printv(const_tab, tab4, "{0,0,0,0,0,0}\n", "};\n", NIL);
228
229    Printv(f_wrappers, cmd_tab, var_tab, const_tab, NIL);
230
231    /* Dump the pointer equivalency table */
232    SwigType_emit_type_table(f_runtime, f_wrappers);
233
234    Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n");
235
236    /* Close the init function and quit */
237    Printf(f_init, "return TCL_OK;\n}\n");
238
239    if (!nosafe) {
240      Printf(f_init, "SWIGEXPORT int %(title)s_SafeInit(Tcl_Interp *interp) {\n", module);
241      Printf(f_init, "    return SWIG_init(interp);\n");
242      Printf(f_init, "}\n");
243    }
244
245    if (itcl) {
246      Printv(f_shadow, f_shadow_stubs, "\n", NIL);
247      Close(f_shadow);
248      Delete(f_shadow);
249    }
250
251    /* Close all of the files */
252    Dump(f_runtime, f_begin);
253    Printv(f_begin, f_header, f_wrappers, NIL);
254    Wrapper_pretty_print(f_init, f_begin);
255    Delete(f_header);
256    Delete(f_wrappers);
257    Delete(f_init);
258    Close(f_begin);
259    Delete(f_runtime);
260    Delete(f_begin);
261    return SWIG_OK;
262  }
263
264  /* ------------------------------------------------------------
265   * functionWrapper()
266   * ------------------------------------------------------------ */
267
268  virtual int functionWrapper(Node *n) {
269    String *name = Getattr(n, "name");	/* Like to get rid of this */
270    String *iname = Getattr(n, "sym:name");
271    SwigType *type = Getattr(n, "type");
272    ParmList *parms = Getattr(n, "parms");
273    String *overname = 0;
274
275    Parm *p;
276    int i;
277    String *tm;
278    Wrapper *f;
279    String *incode, *cleanup, *outarg, *argstr, *args;
280    int num_arguments = 0;
281    int num_required = 0;
282    int varargs = 0;
283
284    char source[64];
285
286    if (Getattr(n, "sym:overloaded")) {
287      overname = Getattr(n, "sym:overname");
288    } else {
289      if (!addSymbol(iname, n))
290	return SWIG_ERROR;
291    }
292
293    incode = NewString("");
294    cleanup = NewString("");
295    outarg = NewString("");
296    argstr = NewString("\"");
297    args = NewString("");
298
299    f = NewWrapper();
300
301#ifdef SWIG_USE_RESULTOBJ
302    Wrapper_add_local(f, "resultobj", "Tcl_Obj *resultobj = NULL");
303#endif
304
305
306    String *wname = Swig_name_wrapper(iname);
307    if (overname) {
308      Append(wname, overname);
309    }
310    Setattr(n, "wrap:name", wname);
311
312    Printv(f->def, "SWIGINTERN int\n ", wname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {", NIL);
313
314    // Emit all of the local variables for holding arguments.
315    emit_parameter_variables(parms, f);
316
317    /* Attach standard typemaps */
318    emit_attach_parmmaps(parms, f);
319    Setattr(n, "wrap:parms", parms);
320
321    /* Get number of require and total arguments */
322    num_arguments = emit_num_arguments(parms);
323    num_required = emit_num_required(parms);
324    varargs = emit_isvarargs(parms);
325
326    /* Unmarshal parameters */
327
328    for (i = 0, p = parms; i < num_arguments; i++) {
329      /* Skip ignored arguments */
330
331      while (checkAttribute(p, "tmap:in:numinputs", "0")) {
332	p = Getattr(p, "tmap:in:next");
333      }
334
335      SwigType *pt = Getattr(p, "type");
336      String *ln = Getattr(p, "lname");
337
338      /* Produce string representations of the source and target arguments */
339      sprintf(source, "objv[%d]", i + 1);
340
341      if (i == num_required)
342	Putc('|', argstr);
343      if ((tm = Getattr(p, "tmap:in"))) {
344	String *parse = Getattr(p, "tmap:in:parse");
345	if (!parse) {
346	  Replaceall(tm, "$target", ln);
347	  Replaceall(tm, "$source", source);
348	  Replaceall(tm, "$input", source);
349	  Setattr(p, "emit:input", source);
350
351	  if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) {
352	    Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
353	  } else {
354	    Replaceall(tm, "$disown", "0");
355	  }
356
357	  Putc('o', argstr);
358	  Printf(args, ",(void *)0");
359	  if (i >= num_required) {
360	    Printf(incode, "if (objc > %d) {\n", i + 1);
361	  }
362	  Printf(incode, "%s\n", tm);
363	  if (i >= num_required) {
364	    Printf(incode, "}\n");
365	  }
366	} else {
367	  Printf(argstr, "%s", parse);
368	  Printf(args, ",&%s", ln);
369	  if (Strcmp(parse, "p") == 0) {
370	    SwigType *lt = SwigType_ltype(pt);
371	    SwigType_remember(pt);
372	    if (Cmp(lt, "p.void") == 0) {
373	      Printf(args, ",(void *)0");
374	    } else {
375	      Printf(args, ",SWIGTYPE%s", SwigType_manglestr(pt));
376	    }
377	    Delete(lt);
378	  }
379	}
380	p = Getattr(p, "tmap:in:next");
381	continue;
382      } else {
383	Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
384      }
385      p = nextSibling(p);
386    }
387
388    if (!varargs) {
389      Putc(':', argstr);
390    } else {
391      Putc(';', argstr);
392      /* If variable length arguments we need to emit the in typemap here */
393      if (p && (tm = Getattr(p, "tmap:in"))) {
394	sprintf(source, "objv[%d]", i + 1);
395	Printf(incode, "if (objc > %d) {\n", i);
396	Replaceall(tm, "$input", source);
397	Printv(incode, tm, "\n", NIL);
398	Printf(incode, "}\n");
399      }
400    }
401
402    Printf(argstr, "%s\"", usage_string(Char(iname), type, parms));
403
404    Printv(f->code, "if (SWIG_GetArgs(interp, objc, objv,", argstr, args, ") == TCL_ERROR) SWIG_fail;\n", NIL);
405
406    Printv(f->code, incode, NIL);
407
408    /* Insert constraint checking code */
409    for (p = parms; p;) {
410      if ((tm = Getattr(p, "tmap:check"))) {
411	Replaceall(tm, "$target", Getattr(p, "lname"));
412	Printv(f->code, tm, "\n", NIL);
413	p = Getattr(p, "tmap:check:next");
414      } else {
415	p = nextSibling(p);
416      }
417    }
418
419    /* Insert cleanup code */
420    for (i = 0, p = parms; p; i++) {
421      if (!checkAttribute(p, "tmap:in:numinputs", "0")
422	  && !Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) {
423	if (Len(tm) != 0) {
424	  Replaceall(tm, "$source", Getattr(p, "lname"));
425	  Printv(cleanup, tm, "\n", NIL);
426	}
427	p = Getattr(p, "tmap:freearg:next");
428      } else {
429	p = nextSibling(p);
430      }
431    }
432
433    /* Insert argument output code */
434    for (i = 0, p = parms; p; i++) {
435      if ((tm = Getattr(p, "tmap:argout"))) {
436	Replaceall(tm, "$source", Getattr(p, "lname"));
437#ifdef SWIG_USE_RESULTOBJ
438	Replaceall(tm, "$target", "resultobj");
439	Replaceall(tm, "$result", "resultobj");
440#else
441	Replaceall(tm, "$target", "(Tcl_GetObjResult(interp))");
442	Replaceall(tm, "$result", "(Tcl_GetObjResult(interp))");
443#endif
444	Replaceall(tm, "$arg", Getattr(p, "emit:input"));
445	Replaceall(tm, "$input", Getattr(p, "emit:input"));
446	Printv(outarg, tm, "\n", NIL);
447	p = Getattr(p, "tmap:argout:next");
448      } else {
449	p = nextSibling(p);
450      }
451    }
452
453    /* Now write code to make the function call */
454    String *actioncode = emit_action(n);
455
456    /* Need to redo all of this code (eventually) */
457
458    /* Return value if necessary  */
459    if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) {
460      Replaceall(tm, "$source", "result");
461#ifdef SWIG_USE_RESULTOBJ
462      Replaceall(tm, "$target", "resultobj");
463      Replaceall(tm, "$result", "resultobj");
464#else
465      Replaceall(tm, "$target", "(Tcl_GetObjResult(interp))");
466      Replaceall(tm, "$result", "(Tcl_GetObjResult(interp))");
467#endif
468      if (GetFlag(n, "feature:new")) {
469	Replaceall(tm, "$owner", "SWIG_POINTER_OWN");
470      } else {
471	Replaceall(tm, "$owner", "0");
472      }
473      Printf(f->code, "%s\n", tm);
474    } else {
475      Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(type, 0), name);
476    }
477    emit_return_variable(n, type, f);
478
479    /* Dump output argument code */
480    Printv(f->code, outarg, NIL);
481
482    /* Dump the argument cleanup code */
483    Printv(f->code, cleanup, NIL);
484
485    /* Look for any remaining cleanup */
486    if (GetFlag(n, "feature:new")) {
487      if ((tm = Swig_typemap_lookup("newfree", n, "result", 0))) {
488	Replaceall(tm, "$source", "result");
489	Printf(f->code, "%s\n", tm);
490      }
491    }
492
493    if ((tm = Swig_typemap_lookup("ret", n, "result", 0))) {
494      Replaceall(tm, "$source", "result");
495      Printf(f->code, "%s\n", tm);
496    }
497#ifdef SWIG_USE_RESULTOBJ
498    Printv(f->code, "if (resultobj) Tcl_SetObjResult(interp, resultobj);\n", NIL);
499#endif
500    Printv(f->code, "return TCL_OK;\n", NIL);
501    Printv(f->code, "fail:\n", cleanup, "return TCL_ERROR;\n", NIL);
502    Printv(f->code, "}\n", NIL);
503
504    /* Substitute the cleanup code */
505    Replaceall(f->code, "$cleanup", cleanup);
506    Replaceall(f->code, "$symname", iname);
507
508    /* Dump out the function */
509    Wrapper_print(f, f_wrappers);
510
511    if (!Getattr(n, "sym:overloaded")) {
512      /* Register the function with Tcl */
513      Printv(cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), ", NULL},\n", NIL);
514    } else {
515      if (!Getattr(n, "sym:nextSibling")) {
516	/* Emit overloading dispatch function */
517
518	int maxargs;
519	String *dispatch = Swig_overload_dispatch(n, "return %s(clientData, interp, objc, argv - 1);", &maxargs);
520
521	/* Generate a dispatch wrapper for all overloaded functions */
522
523	Wrapper *df = NewWrapper();
524	String *dname = Swig_name_wrapper(iname);
525
526	Printv(df->def, "SWIGINTERN int\n", dname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {", NIL);
527	Printf(df->code, "Tcl_Obj *CONST *argv = objv+1;\n");
528	Printf(df->code, "int argc = objc-1;\n");
529	Printv(df->code, dispatch, "\n", NIL);
530	Printf(df->code, "Tcl_SetResult(interp,(char *) \"No matching function for overloaded '%s'\", TCL_STATIC);\n", iname);
531	Printf(df->code, "return TCL_ERROR;\n");
532	Printv(df->code, "}\n", NIL);
533	Wrapper_print(df, f_wrappers);
534	Printv(cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", dname, ", NULL},\n", NIL);
535	DelWrapper(df);
536	Delete(dispatch);
537	Delete(dname);
538      }
539    }
540
541    Delete(incode);
542    Delete(cleanup);
543    Delete(outarg);
544    Delete(argstr);
545    Delete(args);
546    DelWrapper(f);
547    return SWIG_OK;
548  }
549
550  /* ------------------------------------------------------------
551   * variableWrapper()
552   * ------------------------------------------------------------ */
553
554  virtual int variableWrapper(Node *n) {
555
556    String *name = Getattr(n, "name");
557    String *iname = Getattr(n, "sym:name");
558    SwigType *t = Getattr(n, "type");
559
560    String *setname = 0;
561    String *setfname = 0;
562    Wrapper *setf = 0, *getf = 0;
563    int readonly = 0;
564    String *tm;
565
566    if (!addSymbol(iname, n))
567      return SWIG_ERROR;
568
569    /* Create a function for getting a variable */
570    int addfail = 0;
571    getf = NewWrapper();
572    String *getname = Swig_name_get(iname);
573    String *getfname = Swig_name_wrapper(getname);
574    Setattr(n, "wrap:name", getfname);
575    Printv(getf->def, "SWIGINTERN const char *", getfname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2, int flags) {", NIL);
576    Wrapper_add_local(getf, "value", "Tcl_Obj *value = 0");
577    if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
578      Replaceall(tm, "$source", name);
579      Replaceall(tm, "$target", "value");
580      Replaceall(tm, "$result", "value");
581      /* Printf(getf->code, "%s\n",tm); */
582      addfail = emit_action_code(n, getf->code, tm);
583      Printf(getf->code, "if (value) {\n");
584      Printf(getf->code, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n");
585      Printf(getf->code, "Tcl_DecrRefCount(value);\n");
586      Printf(getf->code, "}\n");
587      Printf(getf->code, "return NULL;\n");
588      if (addfail) {
589	Append(getf->code, "fail:\n");
590	Printf(getf->code, "return \"%s\";\n", iname);
591      }
592      Printf(getf->code, "}\n");
593      Wrapper_print(getf, f_wrappers);
594    } else {
595      Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0));
596      DelWrapper(getf);
597      return SWIG_NOWRAP;
598    }
599    DelWrapper(getf);
600
601    /* Try to create a function setting a variable */
602    if (is_assignable(n)) {
603      setf = NewWrapper();
604      setname = Swig_name_set(iname);
605      setfname = Swig_name_wrapper(setname);
606      Setattr(n, "wrap:name", setfname);
607      if (setf) {
608        Printv(setf->def, "SWIGINTERN const char *", setfname,
609	     "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2 SWIGUNUSED, int flags) {", NIL);
610        Wrapper_add_local(setf, "value", "Tcl_Obj *value = 0");
611        Wrapper_add_local(setf, "name1o", "Tcl_Obj *name1o = 0");
612
613        if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
614	  Replaceall(tm, "$source", "value");
615	  Replaceall(tm, "$target", name);
616	  Replaceall(tm, "$input", "value");
617	  Printf(setf->code, "name1o = Tcl_NewStringObj(name1,-1);\n");
618	  Printf(setf->code, "value = Tcl_ObjGetVar2(interp, name1o, 0, flags);\n");
619	  Printf(setf->code, "Tcl_DecrRefCount(name1o);\n");
620	  Printf(setf->code, "if (!value) SWIG_fail;\n");
621	  /* Printf(setf->code,"%s\n", tm); */
622	  emit_action_code(n, setf->code, tm);
623	  Printf(setf->code, "return NULL;\n");
624	  Printf(setf->code, "fail:\n");
625	  Printf(setf->code, "return \"%s\";\n", iname);
626	  Printf(setf->code, "}\n");
627	  Wrapper_print(setf, f_wrappers);
628        } else {
629	  Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0));
630	  readonly = 1;
631        }
632      }
633      DelWrapper(setf);
634    } else {
635      readonly = 1;
636    }
637
638
639    Printv(var_tab, tab4, "{ SWIG_prefix \"", iname, "\", 0, (swig_variable_func) ", getfname, ",", NIL);
640    if (readonly) {
641      static int readonlywrap = 0;
642      if (!readonlywrap) {
643	Wrapper *ro = NewWrapper();
644	Printf(ro->def,
645	       "SWIGINTERN const char *swig_readonly(ClientData clientData SWIGUNUSED, Tcl_Interp *interp SWIGUNUSED, char *name1 SWIGUNUSED, char *name2 SWIGUNUSED, int flags SWIGUNUSED) {");
646	Printv(ro->code, "return \"Variable is read-only\";\n", "}\n", NIL);
647	Wrapper_print(ro, f_wrappers);
648	readonlywrap = 1;
649	DelWrapper(ro);
650      }
651      Printf(var_tab, "(swig_variable_func) swig_readonly},\n");
652    } else {
653      Printv(var_tab, "(swig_variable_func) ", setfname, "},\n", NIL);
654    }
655    Delete(getfname);
656    Delete(setfname);
657    Delete(setname);
658    Delete(getname);
659    return SWIG_OK;
660  }
661
662  /* ------------------------------------------------------------
663   * constantWrapper()
664   * ------------------------------------------------------------ */
665
666  virtual int constantWrapper(Node *n) {
667    String *name = Getattr(n, "name");
668    String *iname = Getattr(n, "sym:name");
669    String *nsname = !nspace ? Copy(iname) : NewStringf("%s::%s", ns_name, iname);
670    SwigType *type = Getattr(n, "type");
671    String *rawval = Getattr(n, "rawval");
672    String *value = rawval ? rawval : Getattr(n, "value");
673    String *tm;
674
675    if (!addSymbol(iname, n))
676      return SWIG_ERROR;
677    if (nspace)
678      Setattr(n, "sym:name", nsname);
679
680    /* Special hook for member pointer */
681    if (SwigType_type(type) == T_MPOINTER) {
682      String *wname = Swig_name_wrapper(iname);
683      Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type, wname), value);
684      value = Char(wname);
685    }
686
687    if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
688      Replaceall(tm, "$source", value);
689      Replaceall(tm, "$target", name);
690      Replaceall(tm, "$value", value);
691      Replaceall(tm, "$nsname", nsname);
692      Printf(const_tab, "%s,\n", tm);
693    } else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
694      Replaceall(tm, "$source", value);
695      Replaceall(tm, "$target", name);
696      Replaceall(tm, "$value", value);
697      Replaceall(tm, "$nsname", nsname);
698      Printf(f_init, "%s\n", tm);
699    } else {
700      Delete(nsname);
701      Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n");
702      return SWIG_NOWRAP;
703    }
704    Delete(nsname);
705    return SWIG_OK;
706  }
707
708  /* ------------------------------------------------------------
709   * nativeWrapper()
710   * ------------------------------------------------------------ */
711
712  virtual int nativeWrapper(Node *n) {
713    String *name = Getattr(n, "sym:name");
714    String *funcname = Getattr(n, "wrap:name");
715    if (!addSymbol(funcname, n))
716      return SWIG_ERROR;
717
718    Printf(f_init, "\t Tcl_CreateObjCommand(interp, SWIG_prefix \"%s\", (swig_wrapper_func) %s, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);\n", name,
719	   funcname);
720    return SWIG_OK;
721  }
722
723  /* ------------------------------------------------------------
724   * classHandler()
725   * ------------------------------------------------------------ */
726
727  virtual int classHandler(Node *n) {
728    static Hash *emitted = NewHash();
729    String *mangled_classname = 0;
730    String *real_classname = 0;
731
732    have_constructor = 0;
733    have_destructor = 0;
734    destructor_action = 0;
735
736    if (itcl) {
737      constructor = NewString("");
738      destructor = NewString("");
739      base_classes = NewString("");
740      base_class_init = NewString("");
741      methods = NewString("");
742      imethods = NewString("");
743      attributes = NewString("");
744      attribute_traces = NewString("");
745      iattribute_traces = NewString("");
746
747      have_base_classes = 0;
748      have_methods = 0;
749      have_attributes = 0;
750    }
751
752    class_name = Getattr(n, "sym:name");
753    if (!addSymbol(class_name, n))
754      return SWIG_ERROR;
755
756    real_classname = Getattr(n, "name");
757    mangled_classname = Swig_name_mangle(real_classname);
758
759    if (Getattr(emitted, mangled_classname))
760      return SWIG_NOWRAP;
761    Setattr(emitted, mangled_classname, "1");
762
763    attr_tab = NewString("");
764    Printf(attr_tab, "static swig_attribute swig_");
765    Printv(attr_tab, mangled_classname, "_attributes[] = {\n", NIL);
766
767    methods_tab = NewStringf("");
768    Printf(methods_tab, "static swig_method swig_");
769    Printv(methods_tab, mangled_classname, "_methods[] = {\n", NIL);
770
771    /* Generate normal wrappers */
772    Language::classHandler(n);
773
774    SwigType *t = Copy(Getattr(n, "name"));
775    SwigType_add_pointer(t);
776
777    // Catch all: eg. a class with only static functions and/or variables will not have 'remembered'
778    // SwigType_remember(t);
779    String *wrap_class = NewStringf("&_wrap_class_%s", mangled_classname);
780    SwigType_remember_clientdata(t, wrap_class);
781
782    //    t = Copy(Getattr(n,"classtype"));
783    //    SwigType_add_pointer(t);
784
785    String *rt = Copy(Getattr(n, "classtype"));
786    SwigType_add_pointer(rt);
787
788    // Register the class structure with the type checker
789    /*    Printf(f_init,"SWIG_TypeClientData(SWIGTYPE%s, (void *) &_wrap_class_%s);\n", SwigType_manglestr(t), mangled_classname); */
790    if (have_destructor) {
791      Printv(f_wrappers, "SWIGINTERN void swig_delete_", class_name, "(void *obj) {\n", NIL);
792      if (destructor_action) {
793	Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL);
794	Printv(f_wrappers, destructor_action, "\n", NIL);
795      } else {
796	if (CPlusPlus) {
797	  Printv(f_wrappers, "    delete (", SwigType_str(rt, 0), ") obj;\n", NIL);
798	} else {
799	  Printv(f_wrappers, "    free((char *) obj);\n", NIL);
800	}
801      }
802      Printf(f_wrappers, "}\n");
803    }
804
805    Printf(methods_tab, "    {0,0}\n};\n");
806    Printv(f_wrappers, methods_tab, NIL);
807
808    Printf(attr_tab, "    {0,0,0}\n};\n");
809    Printv(f_wrappers, attr_tab, NIL);
810
811    /* Handle inheritance */
812
813    String *base_class = NewString("");
814    String *base_class_names = NewString("");
815
816    if (itcl) {
817      base_classes = NewString("");
818    }
819
820    List *baselist = Getattr(n, "bases");
821    if (baselist && Len(baselist)) {
822      Iterator b;
823      int index = 0;
824      b = First(baselist);
825      while (b.item) {
826	String *bname = Getattr(b.item, "name");
827	if ((!bname) || GetFlag(b.item, "feature:ignore") || (!Getattr(b.item, "module"))) {
828	  b = Next(b);
829	  continue;
830	}
831	if (itcl) {
832	  have_base_classes = 1;
833	  Printv(base_classes, bname, " ", NIL);
834	  Printv(base_class_init, "    ", bname, "Ptr::constructor $ptr\n", NIL);
835	}
836	String *bmangle = Swig_name_mangle(bname);
837	//      Printv(f_wrappers,"extern swig_class _wrap_class_", bmangle, ";\n", NIL);
838	//      Printf(base_class,"&_wrap_class_%s",bmangle);
839	Printf(base_class, "0");
840	Printf(base_class_names, "\"%s *\",", SwigType_namestr(bname));
841	/* Put code to register base classes in init function */
842
843	//Printf(f_init,"/* Register base : %s */\n", bmangle);
844	//Printf(f_init,"swig_%s_bases[%d] = (swig_class *) SWIG_TypeQuery(\"%s *\")->clientdata;\n",  mangled_classname, index, SwigType_namestr(bname));
845	b = Next(b);
846	index++;
847	Putc(',', base_class);
848	Delete(bmangle);
849      }
850    }
851
852    if (itcl) {
853      String *ptrclass = NewString("");
854
855      // First, build the pointer base class
856      Printv(ptrclass, "itcl::class ", class_name, "Ptr {\n", NIL);
857      if (have_base_classes)
858	Printv(ptrclass, "  inherit ", base_classes, "\n", NIL);
859
860      //  Define protected variables for SWIG object pointer
861      Printv(ptrclass, "  protected variable swigobj\n", "  protected variable thisown\n", NIL);
862
863      //  Define public variables
864      if (have_attributes) {
865	Printv(ptrclass, attributes, NIL);
866
867	// base class swig_getset was being called for complex inheritance trees
868	if (nspace) {
869
870	  Printv(ptrclass, "  protected method ", class_name, "_swig_getset {var name1 name2 op} {\n", NIL);
871
872	  Printv(ptrclass,
873		 "    switch -exact -- $op {\n",
874		 "      r {set $var [", ns_name, "::", class_name, "_[set var]_get $swigobj]}\n",
875		 "      w {", ns_name, "::", class_name, "_${var}_set $swigobj [set $var]}\n", "    }\n", "  }\n", NIL);
876	} else {
877	  Printv(ptrclass,
878		 "  protected method ", class_name, "_swig_getset {var name1 name2 op} {\n",
879		 "    switch -exact -- $op {\n",
880		 "      r {set $var [", class_name, "_[set var]_get $swigobj]}\n",
881		 "      w {", class_name, "_${var}_set $swigobj [set $var]}\n", "    }\n", "  }\n", NIL);
882	}
883      }
884      //  Add the constructor, which may include
885      //  calls to base class class constructors
886
887      Printv(ptrclass, "  constructor { ptr } {\n", NIL);
888      if (have_base_classes) {
889	Printv(ptrclass, base_class_init, NIL);
890	Printv(ptrclass, "  } {\n", NIL);
891      }
892
893      Printv(ptrclass, "    set swigobj $ptr\n", "    set thisown 0\n", NIL);
894
895      if (have_attributes) {
896	Printv(ptrclass, attribute_traces, NIL);
897      }
898      Printv(ptrclass, "  }\n", NIL);
899
900
901      //  Add destructor
902      Printv(ptrclass, "  destructor {\n",
903	     "    set d_func delete_", class_name, "\n",
904	     "    if { $thisown && ([info command $d_func] != \"\") } {\n" "      $d_func $swigobj\n", "    }\n", "  }\n", NIL);
905
906      //  Add methods
907      if (have_methods) {
908	Printv(ptrclass, imethods, NIL);
909      };
910
911      //  Close out the pointer class
912      Printv(ptrclass, "}\n\n", NIL);
913      Printv(f_shadow, ptrclass, NIL);
914      // pointer class end
915
916
917      //  Create the "real" class.
918      Printv(f_shadow, "itcl::class ", class_name, " {\n", NIL);
919      Printv(f_shadow, "  inherit ", class_name, "Ptr\n", NIL);
920
921      //  If we have a constructor, then use it.
922      //  If not, then we must have an abstract class without
923      //  any constructor.  So we create a class constructor
924      //  which will fail for this class (but not for inherited
925      //  classes).  Note that the constructor must fail before
926      //  calling the ptrclass constructor.
927
928      if (have_constructor) {
929	Printv(f_shadow, constructor, NIL);
930      } else {
931	Printv(f_shadow, "  constructor { } {\n", NIL);
932	Printv(f_shadow, "    # This constructor will fail if called directly\n", NIL);
933	Printv(f_shadow, "    if { [info class] == \"::", class_name, "\" } {\n", NIL);
934	Printv(f_shadow, "      error \"No constructor for class ", class_name, (Getattr(n, "abstract") ? " - class is abstract" : ""), "\"\n", NIL);
935	Printv(f_shadow, "    }\n", NIL);
936	Printv(f_shadow, "  }\n", NIL);
937      }
938
939      Printv(f_shadow, "}\n\n", NIL);
940    }
941
942    Printv(f_wrappers, "static swig_class *swig_", mangled_classname, "_bases[] = {", base_class, "0};\n", NIL);
943    Printv(f_wrappers, "static const char * swig_", mangled_classname, "_base_names[] = {", base_class_names, "0};\n", NIL);
944    Delete(base_class);
945    Delete(base_class_names);
946
947    Printv(f_wrappers, "static swig_class _wrap_class_", mangled_classname, " = { \"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL);
948
949    if (have_constructor) {
950      Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(constructor_name)));
951      Delete(constructor_name);
952      constructor_name = 0;
953    } else {
954      Printf(f_wrappers, "0");
955    }
956    if (have_destructor) {
957      Printv(f_wrappers, ", swig_delete_", class_name, NIL);
958    } else {
959      Printf(f_wrappers, ",0");
960    }
961    Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname, "_bases,",
962	   "swig_", mangled_classname, "_base_names, &swig_module };\n", NIL);
963
964    if (!itcl) {
965      Printv(cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, (ClientData)&_wrap_class_", mangled_classname,
966	     "},\n", NIL);
967    };
968
969    Delete(t);
970    Delete(mangled_classname);
971    return SWIG_OK;
972  }
973
974
975  /* ------------------------------------------------------------
976   * memberfunctionHandler()
977   * ------------------------------------------------------------ */
978
979  virtual int memberfunctionHandler(Node *n) {
980    String *name = Getattr(n, "name");
981    String *iname = GetChar(n, "sym:name");
982
983    String *realname, *rname;
984
985    Language::memberfunctionHandler(n);
986
987    realname = iname ? iname : name;
988    rname = Swig_name_wrapper(Swig_name_member(class_name, realname));
989    if (!Getattr(n, "sym:nextSibling")) {
990      Printv(methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL);
991    }
992
993    if (itcl) {
994      ParmList *l = Getattr(n, "parms");
995      Parm *p = 0;
996      String *pname = NewString("");
997
998      // Add this member to our class handler function
999      Printv(imethods, tab2, "method ", realname, " [list ", NIL);
1000
1001      int pnum = 0;
1002      for (p = l; p; p = nextSibling(p)) {
1003
1004	String *pn = Getattr(p, "name");
1005	String *dv = Getattr(p, "value");
1006	SwigType *pt = Getattr(p, "type");
1007
1008	Printv(pname, ",(", pt, ")", NIL);
1009	Clear(pname);
1010
1011	/* Only print an argument if not void */
1012	if (Cmp(pt, "void") != 0) {
1013	  if (Len(pn) > 0) {
1014	    Printv(pname, pn, NIL);
1015	  } else {
1016	    Printf(pname, "p%d", pnum);
1017	  }
1018
1019	  if (Len(dv) > 0) {
1020	    String *defval = NewString(dv);
1021	    if (nspace) {
1022	      Insert(defval, 0, "::");
1023	      Insert(defval, 0, ns_name);
1024	    }
1025	    if (Strncmp(dv, "(", 1) == 0) {
1026	      Insert(defval, 0, "$");
1027	      Replaceall(defval, "(", "");
1028	      Replaceall(defval, ")", "");
1029	    }
1030	    Printv(imethods, "[list ", pname, " ", defval, "] ", NIL);
1031	  } else {
1032	    Printv(imethods, pname, " ", NIL);
1033	  }
1034	}
1035	++pnum;
1036      }
1037      Printv(imethods, "] ", NIL);
1038
1039      if (nspace) {
1040	Printv(imethods, "{ ", ns_name, "::", class_name, "_", realname, " $swigobj", NIL);
1041      } else {
1042	Printv(imethods, "{ ", class_name, "_", realname, " $swigobj", NIL);
1043      };
1044
1045      pnum = 0;
1046      for (p = l; p; p = nextSibling(p)) {
1047
1048	String *pn = Getattr(p, "name");
1049	SwigType *pt = Getattr(p, "type");
1050	Clear(pname);
1051
1052	/* Only print an argument if not void */
1053	if (Cmp(pt, "void") != 0) {
1054	  if (Len(pn) > 0) {
1055	    Printv(pname, pn, NIL);
1056	  } else {
1057	    Printf(pname, "p%d", pnum);
1058	  }
1059	  Printv(imethods, " $", pname, NIL);
1060	}
1061	++pnum;
1062      }
1063      Printv(imethods, " }\n", NIL);
1064      have_methods = 1;
1065    }
1066
1067    Delete(rname);
1068    return SWIG_OK;
1069  }
1070
1071  /* ------------------------------------------------------------
1072   * membervariableHandler()
1073   * ------------------------------------------------------------ */
1074
1075  virtual int membervariableHandler(Node *n) {
1076    String *symname = Getattr(n, "sym:name");
1077    String *rname;
1078
1079    Language::membervariableHandler(n);
1080    Printv(attr_tab, tab4, "{ \"-", symname, "\",", NIL);
1081    rname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name, symname)));
1082    Printv(attr_tab, rname, ", ", NIL);
1083    Delete(rname);
1084    if (!GetFlag(n, "feature:immutable")) {
1085      rname = Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name, symname)));
1086      Printv(attr_tab, rname, "},\n", NIL);
1087      Delete(rname);
1088    } else {
1089      Printf(attr_tab, "0 },\n");
1090    }
1091
1092    if (itcl) {
1093      Printv(attributes, "  public variable ", symname, "\n", NIL);
1094
1095      Printv(attribute_traces, "    trace variable ", symname, " rw [list ", class_name, "_swig_getset ", symname, "]\n", NIL);
1096      Printv(attribute_traces, "    set ", symname, "\n", NIL);
1097
1098      have_attributes = 1;
1099    }
1100    return SWIG_OK;
1101  }
1102
1103  /* ------------------------------------------------------------
1104   * constructorHandler()
1105   * ------------------------------------------------------------ */
1106
1107  virtual int constructorHandler(Node *n) {
1108    Language::constructorHandler(n);
1109
1110    if (itcl) {
1111      String *name = Getattr(n, "name");
1112      String *iname = GetChar(n, "sym:name");
1113
1114      String *realname;
1115
1116      ParmList *l = Getattr(n, "parms");
1117      Parm *p = 0;
1118
1119      String *pname = NewString("");
1120
1121      realname = iname ? iname : name;
1122
1123      if (!have_constructor) {
1124	// Add this member to our class handler function
1125	Printf(constructor, "  constructor { ");
1126
1127	//  Add parameter list
1128	int pnum = 0;
1129	for (p = l; p; p = nextSibling(p)) {
1130
1131	  SwigType *pt = Getattr(p, "type");
1132	  String *pn = Getattr(p, "name");
1133	  String *dv = Getattr(p, "value");
1134	  Clear(pname);
1135
1136	  /* Only print an argument if not void */
1137	  if (Cmp(pt, "void") != 0) {
1138	    if (Len(pn) > 0) {
1139	      Printv(pname, pn, NIL);
1140	    } else {
1141	      Printf(pname, "p%d", pnum);
1142	    }
1143
1144	    if (Len(dv) > 0) {
1145	      Printv(constructor, "{", pname, " {", dv, "} } ", NIL);
1146	    } else {
1147	      Printv(constructor, pname, " ", NIL);
1148	    }
1149	  }
1150	  ++pnum;
1151	}
1152	Printf(constructor, "} { \n");
1153
1154	// [BRE] 08/17/00 Added test to see if we are instantiating this object
1155	// type, or, if this constructor is being called as part of the itcl
1156	// inheritance hierarchy.
1157	// In the former case, we need to call the C++ constructor, in the
1158	// latter we don't, or we end up with two C++ objects.
1159	// Check to see if we are instantiating a 'realname' or something
1160	// derived from it.
1161	//
1162	Printv(constructor, "    if { [string equal -nocase \"", realname, "\" \"[namespace tail [info class]]\" ] } {\n", NIL);
1163
1164	// Call to constructor wrapper and parent Ptr class
1165	// [BRE] add -namespace/-prefix support
1166
1167	if (nspace) {
1168	  Printv(constructor, "      ", realname, "Ptr::constructor [", ns_name, "::new_", realname, NIL);
1169	} else {
1170	  Printv(constructor, "      ", realname, "Ptr::constructor [new_", realname, NIL);
1171	}
1172
1173	pnum = 0;
1174	for (p = l; p; p = nextSibling(p)) {
1175
1176	  SwigType *pt = Getattr(p, "type");
1177	  String *pn = Getattr(p, "name");
1178	  Clear(pname);
1179
1180	  /* Only print an argument if not void */
1181	  if (Cmp(pt, "void") != 0) {
1182	    if (Len(pn) > 0) {
1183	      Printv(pname, pn, NIL);
1184	    } else {
1185	      Printf(pname, "p%d", pnum);
1186	    }
1187	    Printv(constructor, " $", pname, NIL);
1188	  }
1189	  ++pnum;
1190	}
1191
1192	Printv(constructor, "]\n", "    }\n", "  } {\n", "    set thisown 1\n", "  }\n", NIL);
1193      }
1194    }
1195
1196    constructor_name = NewString(Getattr(n, "sym:name"));
1197    have_constructor = 1;
1198    return SWIG_OK;
1199  }
1200
1201  /* ------------------------------------------------------------
1202   * destructorHandler()
1203   * ------------------------------------------------------------ */
1204
1205  virtual int destructorHandler(Node *n) {
1206    Language::destructorHandler(n);
1207    have_destructor = 1;
1208    destructor_action = Getattr(n, "wrap:action");
1209    return SWIG_OK;
1210  }
1211
1212  /* ------------------------------------------------------------
1213   * validIdentifier()
1214   * ------------------------------------------------------------ */
1215
1216  virtual int validIdentifier(String *s) {
1217    if (Strchr(s, ' '))
1218      return 0;
1219    return 1;
1220  }
1221
1222  /* ------------------------------------------------------------
1223   * usage_string()
1224   * ------------------------------------------------------------ */
1225
1226  char *usage_string(char *iname, SwigType *, ParmList *l) {
1227    static String *temp = 0;
1228    Parm *p;
1229    int i, numopt, pcount;
1230
1231    if (!temp)
1232      temp = NewString("");
1233    Clear(temp);
1234    if (nspace) {
1235      Printf(temp, "%s::%s ", ns_name, iname);
1236    } else {
1237      Printf(temp, "%s ", iname);
1238    }
1239    /* Now go through and print parameters */
1240    i = 0;
1241    pcount = emit_num_arguments(l);
1242    numopt = pcount - emit_num_required(l);
1243    for (p = l; p; p = nextSibling(p)) {
1244
1245      SwigType *pt = Getattr(p, "type");
1246      String *pn = Getattr(p, "name");
1247      /* Only print an argument if not ignored */
1248      if (!checkAttribute(p, "tmap:in:numinputs", "0")) {
1249	if (i >= (pcount - numopt))
1250	  Putc('?', temp);
1251	if (Len(pn) > 0) {
1252	  Printf(temp, "%s", pn);
1253	} else {
1254	  Printf(temp, "%s", SwigType_str(pt, 0));
1255	}
1256	if (i >= (pcount - numopt))
1257	  Putc('?', temp);
1258	Putc(' ', temp);
1259	i++;
1260      }
1261    }
1262    return Char(temp);
1263  }
1264
1265  String *runtimeCode() {
1266    String *s = NewString("");
1267    String *serrors = Swig_include_sys("tclerrors.swg");
1268    if (!serrors) {
1269      Printf(stderr, "*** Unable to open 'tclerrors.swg'\n");
1270    } else {
1271      Append(s, serrors);
1272      Delete(serrors);
1273    }
1274    String *sapi = Swig_include_sys("tclapi.swg");
1275    if (!sapi) {
1276      Printf(stderr, "*** Unable to open 'tclapi.swg'\n");
1277    } else {
1278      Append(s, sapi);
1279      Delete(sapi);
1280    }
1281    String *srun = Swig_include_sys("tclrun.swg");
1282    if (!srun) {
1283      Printf(stderr, "*** Unable to open 'tclrun.swg'\n");
1284    } else {
1285      Append(s, srun);
1286      Delete(srun);
1287    }
1288
1289    return s;
1290  }
1291
1292  String *defaultExternalRuntimeFilename() {
1293    return NewString("swigtclrun.h");
1294  }
1295};
1296
1297/* ----------------------------------------------------------------------
1298 * swig_tcl()    - Instantiate module
1299 * ---------------------------------------------------------------------- */
1300
1301static Language *new_swig_tcl() {
1302  return new TCL8();
1303}
1304extern "C" Language *swig_tcl(void) {
1305  return new_swig_tcl();
1306}
1307