PageRenderTime 41ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Source/Modules/tcl8.cxx

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