PageRenderTime 140ms CodeModel.GetById 18ms app.highlight 111ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Source/Modules/tcl8.cxx

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