/tags/rel-1.3.35/Source/Modules/tcl8.cxx
C++ | 1297 lines | 945 code | 215 blank | 137 comment | 192 complexity | c0c472aad3ff1b074c95fcbad7e2cebb MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
- /* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * tcl8.cxx
- *
- * Tcl8 language module for SWIG.
- * ----------------------------------------------------------------------------- */
- char cvsroot_tcl8_cxx[] = "$Id: tcl8.cxx 10270 2008-02-27 15:29:55Z wsfulton $";
- #include "swigmod.h"
- #include "cparse.h"
- static int treduce = SWIG_cparse_template_reduce(0);
- static const char *usage = (char *) "\
- Tcl 8 Options (available with -tcl)\n\
- -itcl - Enable ITcl support\n\
- -nosafe - Leave out SafeInit module function.\n\
- -prefix <name> - Set a prefix <name> to be prepended to all names\n\
- -namespace - Build module into a Tcl 8 namespace\n\
- -pkgversion - Set package version\n\n";
- static String *cmd_tab = 0; /* Table of command names */
- static String *var_tab = 0; /* Table of global variables */
- static String *const_tab = 0; /* Constant table */
- static String *methods_tab = 0; /* Methods table */
- static String *attr_tab = 0; /* Attribute table */
- static String *prefix = 0;
- static String *module = 0;
- static int nspace = 0;
- static String *init_name = 0;
- static String *ns_name = 0;
- static int have_constructor;
- static String *constructor_name;
- static int have_destructor;
- static int have_base_classes;
- static String *destructor_action = 0;
- static String *version = (String *) "0.0";
- static String *class_name = 0;
- static int have_attributes;
- static int have_methods;
- static int nosafe = 0;
- static File *f_header = 0;
- static File *f_wrappers = 0;
- static File *f_init = 0;
- static File *f_runtime = 0;
- // Itcl support
- static int itcl = 0;
- static File *f_shadow = 0;
- static File *f_shadow_stubs = 0;
- static String *constructor = 0;
- static String *destructor = 0;
- static String *base_classes = 0;
- static String *base_class_init = 0;
- static String *methods = 0;
- static String *imethods = 0;
- static String *attributes = 0;
- static String *attribute_traces = 0;
- static String *iattribute_traces = 0;
- class TCL8:public Language {
- public:
- /* ------------------------------------------------------------
- * TCL8::main()
- * ------------------------------------------------------------ */
- virtual void main(int argc, char *argv[]) {
- int cppcast = 1;
- SWIG_library_directory("tcl");
- for (int i = 1; i < argc; i++) {
- if (argv[i]) {
- if (strcmp(argv[i], "-prefix") == 0) {
- if (argv[i + 1]) {
- prefix = NewString(argv[i + 1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i + 1);
- i++;
- } else
- Swig_arg_error();
- } else if (strcmp(argv[i], "-pkgversion") == 0) {
- if (argv[i + 1]) {
- version = NewString(argv[i + 1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i + 1);
- i++;
- }
- } else if (strcmp(argv[i], "-namespace") == 0) {
- nspace = 1;
- Swig_mark_arg(i);
- } else if (strcmp(argv[i], "-itcl") == 0) {
- itcl = 1;
- Swig_mark_arg(i);
- } else if (strcmp(argv[i], "-nosafe") == 0) {
- nosafe = 1;
- Swig_mark_arg(i);
- } else if (strcmp(argv[i], "-cppcast") == 0) {
- cppcast = 1;
- Swig_mark_arg(i);
- } else if (strcmp(argv[i], "-nocppcast") == 0) {
- cppcast = 0;
- Swig_mark_arg(i);
- } else if (strcmp(argv[i], "-help") == 0) {
- fputs(usage, stdout);
- }
- }
- }
- if (cppcast) {
- Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0);
- }
- Preprocessor_define("SWIGTCL 1", 0);
- Preprocessor_define("SWIGTCL8 1", 0);
- SWIG_typemap_lang("tcl8");
- SWIG_config_file("tcl8.swg");
- allow_overloading();
- }
- /* ------------------------------------------------------------
- * top()
- * ------------------------------------------------------------ */
- virtual int top(Node *n) {
- /* Initialize all of the output files */
- String *outfile = Getattr(n, "outfile");
- f_runtime = NewFile(outfile, "w");
- if (!f_runtime) {
- FileErrorDisplay(outfile);
- SWIG_exit(EXIT_FAILURE);
- }
- f_init = NewString("");
- f_header = NewString("");
- f_wrappers = NewString("");
- /* Register file targets with the SWIG file handler */
- Swig_register_filebyname("header", f_header);
- Swig_register_filebyname("wrapper", f_wrappers);
- Swig_register_filebyname("runtime", f_runtime);
- Swig_register_filebyname("init", f_init);
- /* Initialize some variables for the object interface */
- cmd_tab = NewString("");
- var_tab = NewString("");
- methods_tab = NewString("");
- const_tab = NewString("");
- Swig_banner(f_runtime);
- /* Set the module name, namespace, and prefix */
- module = NewStringf("%(lower)s", Getattr(n, "name"));
- init_name = NewStringf("%(title)s_Init", module);
- ns_name = prefix ? Copy(prefix) : Copy(module);
- if (prefix)
- Append(prefix, "_");
- /* If shadow classing is enabled, we're going to change the module name to "_module" */
- if (itcl) {
- String *filen;
- filen = NewStringf("%s%s.itcl", Swig_file_dirname(outfile), module);
- Insert(module, 0, "_");
- if ((f_shadow = NewFile(filen, "w")) == 0) {
- FileErrorDisplay(filen);
- SWIG_exit(EXIT_FAILURE);
- }
- f_shadow_stubs = NewString("");
- Swig_register_filebyname("shadow", f_shadow);
- Swig_register_filebyname("itcl", f_shadow);
- Printf(f_shadow, "# This file was automatically generated by SWIG (http://www.swig.org).\n");
- Printf(f_shadow, "# Version %s\n", Swig_package_version());
- Printf(f_shadow, "#\n");
- Printf(f_shadow, "# Don't modify this file, modify the SWIG interface instead.\n");
- Printv(f_shadow, "\npackage require Itcl\n\n", NIL);
- Delete(filen);
- }
- /* Generate some macros used throughout code generation */
- Printf(f_header, "#define SWIG_init %s\n", init_name);
- Printf(f_header, "#define SWIG_name \"%s\"\n", module);
- if (nspace) {
- Printf(f_header, "#define SWIG_prefix \"%s::\"\n", ns_name);
- Printf(f_header, "#define SWIG_namespace \"%s\"\n\n", ns_name);
- } else {
- Printf(f_header, "#define SWIG_prefix \"%s\"\n", prefix);
- }
- Printf(f_header, "#define SWIG_version \"%s\"\n", version);
- Printf(cmd_tab, "\nstatic swig_command_info swig_commands[] = {\n");
- Printf(var_tab, "\nstatic swig_var_info swig_variables[] = {\n");
- Printf(const_tab, "\nstatic swig_const_info swig_constants[] = {\n");
- Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
- /* Start emitting code */
- Language::top(n);
- /* Done. Close up the module */
- Printv(cmd_tab, tab4, "{0, 0, 0}\n", "};\n", NIL);
- Printv(var_tab, tab4, "{0,0,0,0}\n", "};\n", NIL);
- Printv(const_tab, tab4, "{0,0,0,0,0,0}\n", "};\n", NIL);
- Printv(f_wrappers, cmd_tab, var_tab, const_tab, NIL);
- /* Dump the pointer equivalency table */
- SwigType_emit_type_table(f_runtime, f_wrappers);
- Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n");
- /* Close the init function and quit */
- Printf(f_init, "return TCL_OK;\n}\n");
- if (!nosafe) {
- Printf(f_init, "SWIGEXPORT int %(title)s_SafeInit(Tcl_Interp *interp) {\n", module);
- Printf(f_init, " return SWIG_init(interp);\n");
- Printf(f_init, "}\n");
- }
- if (itcl) {
- Printv(f_shadow, f_shadow_stubs, "\n", NIL);
- Close(f_shadow);
- Delete(f_shadow);
- }
- /* Close all of the files */
- Printv(f_runtime, f_header, f_wrappers, NIL);
-