1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * Main entry point to the SWIG core.
8 * ----------------------------------------------------------------------------- */
10 char cvsroot_main_cxx[] = "$Id: main.cxx 11135 2009-02-20 20:55:16Z wsfulton $";
12 #include "swigconfig.h"
15 #define WIN32_LEAN_AND_MEAN
24 #include <limits.h> // for INT_MAX
28 Language *lang; // Language method
30 int Extend = 0; // Extend flag
31 int ForceExtern = 0; // Force extern mode
32 int GenerateDefault = 1; // Generate default constructors
36 int SwigRuntime = 0; // 0 = no option, 1 = -runtime, 2 = -noruntime
38 /* Suppress warning messages for private inheritance, preprocessor evaluation etc...
39 WARN_PP_EVALUATION 202
40 WARN_PARSE_PRIVATE_INHERIT 309
41 WARN_TYPE_ABSTRACT 403
42 WARN_LANG_OVERLOAD_CONST 512
43 WARN_PARSE_BUILTIN_NAME 321
44 WARN_PARSE_REDUNDANT 322
46 #define EXTRA_WARNINGS "202,309,403,512,321,322"
49 extern String *ModuleName;
52 /* usage string split into multiple parts otherwise string is too big for some compilers */
53 /* naming conventions for commandline options - no underscores, no capital letters, join words together
54 * except when using a common prefix, then use '-' to separate, eg the debug-xxx options */
55 static const char *usage1 = (const char *) "\
57 -addextern - Add extra extern declarations\n\
58 -c++ - Enable C++ processing\n\
59 -co <file> - Check <file> out of the SWIG library\n\
60 -copyctor - Automatically generate copy constructors wherever possible\n\
61 -cpperraswarn - Treat the preprocessor #error statement as #warning (default)\n\
62 -copyright - Display copyright notices\n\
63 -debug-classes - Display information about the classes found in the interface\n\
64 -debug-module <n>- Display module parse tree at stages 1-4, <n> is a csv list of stages\n\
65 -debug-tags - Display information about the tags found in the interface\n\
66 -debug-template - Display information for debugging templates\n\
67 -debug-top <n> - Display entire parse tree at stages 1-4, <n> is a csv list of stages\n\
68 -debug-typedef - Display information about the types and typedefs in the interface\n\
69 -debug-typemap - Display information for debugging typemaps\n\
70 -directors - Turn on director mode for all the classes, mainly for testing\n\
71 -dirprot - Turn on wrapping of protected members for director classes (default)\n\
72 -D<symbol> - Define a symbol <symbol> (for conditional compilation)\n\
73 -E - Preprocess only, does not generate wrapper code\n\
74 -external-runtime [file] - Export the SWIG runtime stack\n\
75 -fakeversion <v>- Make SWIG fake the program version number to <v>\n\
76 -fcompact - Compile in compact mode\n\
77 -features <list>- Set global features, where <list> is a comma separated list of\n\
78 features, eg -features directors,autodoc=1\n\
79 If no explicit value is given to the feature, a default of 1 is used\n\
82 static const char *usage2 = (const char *) "\
83 -fastdispatch - Enable fast dispatch mode to produce faster overload dispatcher code\n\
84 -Fmicrosoft - Display error/warning messages in Microsoft format\n\
85 -Fstandard - Display error/warning messages in commonly used format\n\
86 -fvirtual - Compile in virtual elimination mode\n\
87 -help - This output\n\
88 -I- - Don't search the current directory\n\
89 -I<dir> - Look for SWIG files in directory <dir>\n\
90 -ignoremissing - Ignore missing include files\n\
91 -importall - Follow all #include statements as imports\n\
92 -includeall - Follow all #include statements\n\
93 -l<ifile> - Include SWIG library file <ifile>\n\
94 -macroerrors - Report errors inside macros\n\
95 -makedefault - Create default constructors/destructors (the default)\n\
96 -M - List all dependencies\n\
97 -MD - Is equivalent to `-M -MF <file>', except `-E' is not implied\n\
98 -MF <file> - Generate dependencies into <file> and continue generating wrappers\n\
99 -MM - List dependencies, but omit files in SWIG library\n\
100 -MMD - Like `-MD', but omit files in SWIG library\n\
101 -module <name> - Set module name to <name>\n\
102 -MT <target> - Set the target of the rule emitted by dependency generation\n\
103 -nocontract - Turn off contract checking\n\
104 -nocpperraswarn - Do not treat the preprocessor #error statement as #warning\n\
105 -nodefault - Do not generate default constructors nor default destructors\n\
106 -nodefaultctor - Do not generate implicit default constructors\n\
107 -nodefaultdtor - Do not generate implicit default destructors\n\
108 -nodirprot - Do not wrap director protected members\n\
109 -noexcept - Do not wrap exception specifiers\n\
110 -nofastdispatch - Disable fast dispatch mode (default)\n\
111 -nopreprocess - Skip the preprocessor step\n\
114 static const char *usage3 = (const char *) "\
115 -notemplatereduce - Disable reduction of the typedefs in templates\n\
116 -O - Enable the optimization options: \n\
117 -fastdispatch -fvirtual \n\
118 -o <outfile> - Set name of the output file to <outfile>\n\
119 -oh <headfile> - Set name of the output header file to <headfile>\n\
120 -outcurrentdir - Set default output dir to current dir instead of input file's path\n\
121 -outdir <dir> - Set language specific files output directory to <dir>\n\
122 -small - Compile in virtual elimination & compact mode\n\
123 -swiglib - Report location of SWIG library and exit\n\
124 -templatereduce - Reduce all the typedefs in templates\n\
125 -v - Run in verbose mode\n\
126 -version - Display SWIG version number\n\
127 -Wall - Remove all warning suppression, also implies -Wextra\n\
128 -Wallkw - Enable keyword warnings for all the supported languages\n\
129 -Werror - Treat warnings as errors\n\
130 -Wextra - Adds the following additional warnings: " EXTRA_WARNINGS "\n\
131 -w<list> - Suppress/add warning messages, eg -w401,+321 - see Warnings.html\n\
132 -xmlout <file> - Write XML version of the parse tree to <file> after normal processing\n\
134 Options can also be defined using the SWIG_FEATURES environment variable, for example:\n\
136 $ SWIG_FEATURES=\"-Wall\"\n\
137 $ export SWIG_FEATURES\n\
138 $ swig -python interface.i\n\
140 is equivalent to: \n\
142 $ swig -Wall -python interface.i \n\
147 static String *LangSubDir = 0; // Target language library subdirectory
148 static char *SwigLib = 0; // Library directory
149 static String *SwigLibWin = 0; // Extra Library directory for Windows
150 static int freeze = 0;
151 static String *lang_config = 0;
152 static char *hpp_extension = (char *) "h";
153 static char *cpp_extension = (char *) "cxx";
154 static char *depends_extension = (char *) "d";
155 static String *outdir = 0;
156 static String *xmlout = 0;
157 static int outcurrentdir = 0;
159 static int checkout = 0;
160 static int cpp_only = 0;
161 static int no_cpp = 0;
162 static char *outfile_name = 0;
163 static char *outfile_name_h = 0;
164 static int tm_debug = 0;
165 static int dump_tags = 0;
166 static int dump_module = 0;
167 static int dump_top = 0;
168 static int dump_xml = 0;
169 static int browse = 0;
170 static int dump_typedef = 0;
171 static int dump_classes = 0;
172 static int werror = 0;
173 static int depend = 0;
174 static int depend_only = 0;
175 static int memory_debug = 0;
176 static int allkw = 0;
177 static DOH *libfiles = 0;
178 static DOH *cpps = 0;
179 static String *dependencies_file = 0;
180 static File *f_dependencies_file = 0;
181 static String *dependencies_target = 0;
182 static int external_runtime = 0;
183 static String *external_runtime_name = 0;
184 enum { STAGE1=1, STAGE2=2, STAGE3=4, STAGE4=8, STAGEOVERFLOW=16 };
185 static List *all_output_files = 0;
187 // -----------------------------------------------------------------------------
190 // Checks the suffix of a file to see if we should emit extern declarations.
191 // -----------------------------------------------------------------------------
193 static int check_suffix(String *filename) {
194 const char *name = Char(filename);
198 c = Swig_file_suffix(name);
199 if ((strcmp(c, ".c") == 0) ||
200 (strcmp(c, ".C") == 0) || (strcmp(c, ".cc") == 0) || (strcmp(c, ".cxx") == 0) || (strcmp(c, ".c++") == 0) || (strcmp(c, ".cpp") == 0)) {
206 // -----------------------------------------------------------------------------
207 // install_opts(int argc, char *argv[])
208 // Install all command line options as preprocessor symbols
209 // -----------------------------------------------------------------------------
211 static void install_opts(int argc, char *argv[]) {
215 for (i = 1; i < (argc - 1); i++) {
217 if ((*argv[i] == '-') && (!isupper(*(argv[i] + 1)))) {
218 String *opt = NewStringf("SWIGOPT%(upper)s", argv[i]);
219 Replaceall(opt, "-", "_");
223 if (!(isalnum(*c) || (*c == '_'))) {
229 if (((i + 1) < (argc - 1)) && (argv[i + 1]) && (*argv[i + 1] != '-')) {
230 Printf(opt, " %s", argv[i + 1]);
236 /* Printf(stdout,"%s\n", opt); */
237 Preprocessor_define(opt, 0);
245 // -----------------------------------------------------------------------------
246 // decode_numbers_list(String *numlist)
247 // Decode comma separated list into a binary number of the inputs or'd together
248 // eg list="1,4" will return (2^0 || 2^3) = 0x1001
249 // -----------------------------------------------------------------------------
251 static unsigned int decode_numbers_list(String *numlist) {
252 unsigned int decoded_number = 0;
254 List *numbers = Split(numlist, ',', INT_MAX);
255 if (numbers && Len(numbers) > 0) {
256 for (Iterator it = First(numbers); it.item; it = Next(it)) {
257 String *numstring = it.item;
258 // TODO: check that it is a number
259 int number = atoi(Char(numstring));
260 if (number > 0 && number <= 16) {
261 decoded_number |= (1 << (number-1));
266 return decoded_number;
269 // -----------------------------------------------------------------------------
270 // Sets the output directory for language specific (proxy) files if not set and
271 // adds trailing file separator if necessary.
272 // -----------------------------------------------------------------------------
274 static void set_outdir(const String *c_wrapper_file_dir) {
276 // Add file delimiter if not present in output directory name
277 if (outdir && Len(outdir) != 0) {
278 const char *outd = Char(outdir);
279 if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMITER), SWIG_FILE_DELIMITER) != 0)
280 Printv(outdir, SWIG_FILE_DELIMITER, NIL);
282 // Use the C wrapper file's directory if the output directory has not been set by user
284 outdir = NewString(c_wrapper_file_dir);
287 /* This function sets the name of the configuration file */
288 void SWIG_config_file(const_String_or_char_ptr filename) {
289 lang_config = NewString(filename);
292 /* Sets the target language subdirectory name */
293 void SWIG_library_directory(const char *subdirectory) {
294 LangSubDir = NewString(subdirectory);
297 // Returns the directory for generating language specific files (non C/C++ files)
298 const String *SWIG_output_directory() {
303 void SWIG_config_cppext(const char *ext) {
304 cpp_extension = (char *) ext;
307 List *SWIG_output_files() {
308 assert(all_output_files);
309 return all_output_files;
312 void SWIG_setfeature(const char *cfeature, const char *cvalue) {
313 Hash *features_hash = Swig_cparse_features();
314 String *name = NewString("");
315 String *fname = NewString(cfeature);
316 String *fvalue = NewString(cvalue);
317 Swig_feature_set(features_hash, name, 0, fname, fvalue, 0);
324 void SWIG_setfeatures(const char *c) {
328 Hash *features_hash = Swig_cparse_features();
329 String *name = NewString("");
330 /* Printf(stderr,"all features %s\n", c); */
333 String *fname = NewString("feature:");
334 String *fvalue = NewString("");
335 while ((f != fe) && *c != '=' && *c != ',' && *c) {
339 Printf(fname, "%s", feature);
340 if (*c && *(c++) == '=') {
344 while ((v != ve) && *c != ',' && *c && !isspace(*c)) {
348 Printf(fvalue, "%s", value);
352 /* Printf(stderr,"%s %s\n", fname, fvalue); */
353 Swig_feature_set(features_hash, name, 0, fname, fvalue, 0);
360 /* This function handles the -external-runtime command option */
361 static void SWIG_dump_runtime() {
366 outfile = external_runtime_name;
368 outfile = lang->defaultExternalRuntimeFilename();
370 Printf(stderr, "*** Please provide a filename for the external runtime\n");
371 SWIG_exit(EXIT_FAILURE);
375 runtime = NewFile(outfile, "w", SWIG_output_files());
377 FileErrorDisplay(outfile);
378 SWIG_exit(EXIT_FAILURE);
381 Swig_banner(runtime);
382 Printf(runtime, "\n");
384 s = Swig_include_sys("swiglabels.swg");
386 Printf(stderr, "*** Unable to open 'swiglabels.swg'\n");
388 SWIG_exit(EXIT_FAILURE);
390 Printf(runtime, "%s", s);
393 s = Swig_include_sys("swigerrors.swg");
395 Printf(stderr, "*** Unable to open 'swigerrors.swg'\n");
397 SWIG_exit(EXIT_FAILURE);
399 Printf(runtime, "%s", s);
402 s = Swig_include_sys("swigerrors.swg");
404 Printf(stderr, "*** Unable to open 'swigerrors.swg'\n");
406 SWIG_exit(EXIT_FAILURE);
408 Printf(runtime, "%s", s);
409 s = Swig_include_sys("swigrun.swg");
411 Printf(stderr, "*** Unable to open 'swigrun.swg'\n");
413 SWIG_exit(EXIT_FAILURE);
415 Printf(runtime, "%s", s);
418 s = lang->runtimeCode();
419 Printf(runtime, "%s", s);
422 s = Swig_include_sys("runtime.swg");
424 Printf(stderr, "*** Unable to open 'runtime.swg'\n");
426 SWIG_exit(EXIT_FAILURE);
428 Printf(runtime, "%s", s);
433 SWIG_exit(EXIT_SUCCESS);
436 void SWIG_getoptions(int argc, char *argv[]) {
439 for (i = 1; i < argc; i++) {
440 if (argv[i] && !Swig_check_marked(i)) {
441 if (strncmp(argv[i], "-I-", 3) == 0) {
442 // Don't push/pop directories
443 Swig_set_push_dir(0);
445 } else if (strncmp(argv[i], "-I", 2) == 0) {
446 // Add a new directory search path
447 char *a = Swig_copy_string(argv[i] + 2);
448 Swig_add_directory((DOH *) a);
451 } else if (strncmp(argv[i], "-D", 2) == 0) {
452 String *d = NewString(argv[i] + 2);
453 Replace(d, (char *) "=", (char *) " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
454 Preprocessor_define((DOH *) d, 0);
458 } else if (strcmp(argv[i], "-E") == 0) {
461 } else if (strcmp(argv[i], "-nopreprocess") == 0) {
464 } else if ((strcmp(argv[i], "-verbose") == 0) || (strcmp(argv[i], "-v") == 0)) {
467 } else if (strcmp(argv[i], "-c++") == 0) {
469 Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
470 Swig_cparse_cplusplus(1);
472 } else if (strcmp(argv[i], "-fcompact") == 0) {
473 Wrapper_compact_print_mode_set(1);
475 } else if (strcmp(argv[i], "-fvirtual") == 0) {
476 Wrapper_virtual_elimination_mode_set(1);
478 } else if (strcmp(argv[i], "-fastdispatch") == 0) {
479 Wrapper_fast_dispatch_mode_set(1);
481 } else if (strcmp(argv[i], "-nofastdispatch") == 0) {
482 Wrapper_fast_dispatch_mode_set(0);
484 } else if (strcmp(argv[i], "-naturalvar") == 0) {
485 Wrapper_naturalvar_mode_set(1);
487 } else if (strcmp(argv[i], "-nonaturalvar") == 0) {
488 Wrapper_naturalvar_mode_set(0);
490 } else if (strcmp(argv[i], "-directors") == 0) {
491 SWIG_setfeature("feature:director", "1");
492 Wrapper_director_mode_set(1);
494 } else if (strcmp(argv[i], "-dirprot") == 0) {
495 Wrapper_director_protected_mode_set(1);
497 } else if (strcmp(argv[i], "-nodirprot") == 0) {
498 Wrapper_director_protected_mode_set(0);
500 } else if (strcmp(argv[i], "-small") == 0) {
501 Wrapper_compact_print_mode_set(1);
502 Wrapper_virtual_elimination_mode_set(1);
504 } else if (strcmp(argv[i], "-runtime") == 0) { // Used to also accept -c. removed in swig-1.3.36
506 Swig_warning(WARN_DEPRECATED_OPTC, "SWIG", 1, "-runtime, -noruntime command line options are deprecated.\n");
508 } else if (strcmp(argv[i], "-noruntime") == 0) {
510 Swig_warning(WARN_DEPRECATED_OPTC, "SWIG", 1, "-runtime, -noruntime command line options are deprecated.\n");
512 } else if (strcmp(argv[i], "-external-runtime") == 0) {
513 external_runtime = 1;
516 external_runtime_name = NewString(argv[i + 1]);
517 Swig_mark_arg(i + 1);
520 } else if ((strcmp(argv[i], "-make_default") == 0) || (strcmp(argv[i], "-makedefault") == 0)) {
523 } else if ((strcmp(argv[i], "-no_default") == 0) || (strcmp(argv[i], "-nodefault") == 0)) {
525 Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG", 1, "dangerous, use -nodefaultctor, -nodefaultdtor instead.\n");
527 } else if ((strcmp(argv[i], "-nodefaultctor") == 0)) {
528 SWIG_setfeature("feature:nodefaultctor", "1");
530 } else if ((strcmp(argv[i], "-nodefaultdtor") == 0)) {
531 SWIG_setfeature("feature:nodefaultdtor", "1");
533 } else if ((strcmp(argv[i], "-copyctor") == 0)) {
534 SWIG_setfeature("feature:copyctor", "1");
536 } else if (strcmp(argv[i], "-noexcept") == 0) {
539 } else if (strcmp(argv[i], "-noextern") == 0) {
540 Swig_warning(WARN_DEPRECATED_NOEXTERN, "SWIG", 1, "-noextern command line option is deprecated; extern is no longer generated by default.\n");
543 } else if (strcmp(argv[i], "-addextern") == 0) {
546 } else if ((strcmp(argv[i], "-debug-template") == 0) || (strcmp(argv[i], "-debug_template") == 0) || (strcmp(argv[i], "-show_templates") == 0)) {
547 Swig_cparse_debug_templates(1);
549 } else if (strcmp(argv[i], "-templatereduce") == 0) {
550 SWIG_cparse_template_reduce(1);
552 } else if (strcmp(argv[i], "-notemplatereduce") == 0) {
553 SWIG_cparse_template_reduce(0);
555 } else if (strcmp(argv[i], "-macroerrors") == 0) {
556 Swig_cparse_follow_locators(1);
558 } else if (strcmp(argv[i], "-swiglib") == 0) {
560 printf("%s\n", Char(SwigLibWin));
561 printf("%s\n", SwigLib);
562 SWIG_exit(EXIT_SUCCESS);
563 } else if (strcmp(argv[i], "-o") == 0) {
566 outfile_name = Swig_copy_string(argv[i + 1]);
567 if (!outfile_name_h || !dependencies_file) {
568 char *ext = strrchr(outfile_name, '.');
569 String *basename = ext ? NewStringWithSize(outfile_name, ext - outfile_name) : NewString(outfile_name);
570 if (!dependencies_file) {
571 dependencies_file = NewStringf("%s.%s", basename, depends_extension);
573 if (!outfile_name_h) {
574 Printf(basename, ".%s", hpp_extension);
575 outfile_name_h = Swig_copy_string(Char(basename));
579 Swig_mark_arg(i + 1);
584 } else if (strcmp(argv[i], "-oh") == 0) {
587 outfile_name_h = Swig_copy_string(argv[i + 1]);
588 Swig_mark_arg(i + 1);
593 } else if (strcmp(argv[i], "-fakeversion") == 0) {
596 Swig_set_fakeversion(argv[i + 1]);
597 Swig_mark_arg(i + 1);
602 } else if (strcmp(argv[i], "-version") == 0) {
603 fprintf(stdout, "\nSWIG Version %s\n", Swig_package_version());
604 fprintf(stdout, "\nCompiled with %s [%s]\n", SWIG_CXX, SWIG_PLATFORM);
605 fprintf(stdout, "Please see %s for reporting bugs and further information\n", PACKAGE_BUGREPORT);
606 SWIG_exit(EXIT_SUCCESS);
607 } else if (strcmp(argv[i], "-copyright") == 0) {
608 fprintf(stdout, "\nSWIG Version %s\n", Swig_package_version());
609 fprintf(stdout, "Copyright (c) 1995-1998\n");
610 fprintf(stdout, "University of Utah and the Regents of the University of California\n");
611 fprintf(stdout, "Copyright (c) 1998-2005\n");
612 fprintf(stdout, "University of Chicago\n");
613 fprintf(stdout, "Copyright (c) 2005-2006\n");
614 fprintf(stdout, "Arizona Board of Regents (University of Arizona)\n");
615 SWIG_exit(EXIT_SUCCESS);
616 } else if (strncmp(argv[i], "-l", 2) == 0) {
617 // Add a new directory search path
618 Append(libfiles, argv[i] + 2);
620 } else if (strcmp(argv[i], "-co") == 0) {
623 } else if (strcmp(argv[i], "-features") == 0) {
626 SWIG_setfeatures(argv[i + 1]);
627 Swig_mark_arg(i + 1);
631 } else if (strcmp(argv[i], "-freeze") == 0) {
634 } else if (strcmp(argv[i], "-includeall") == 0) {
635 Preprocessor_include_all(1);
637 } else if (strcmp(argv[i], "-importall") == 0) {
638 Preprocessor_import_all(1);
640 } else if (strcmp(argv[i], "-ignoremissing") == 0) {
641 Preprocessor_ignore_missing(1);
643 } else if (strcmp(argv[i], "-cpperraswarn") == 0) {
644 Preprocessor_error_as_warning(1);
646 } else if (strcmp(argv[i], "-nocpperraswarn") == 0) {
647 Preprocessor_error_as_warning(0);
649 } else if ((strcmp(argv[i], "-debug-typemap") == 0) || (strcmp(argv[i], "-debug_typemap") == 0) || (strcmp(argv[i], "-tm_debug") == 0)) {
652 } else if (strcmp(argv[i], "-module") == 0) {
655 ModuleName = NewString(argv[i + 1]);
656 Swig_mark_arg(i + 1);
660 } else if (strcmp(argv[i], "-M") == 0) {
664 } else if (strcmp(argv[i], "-MM") == 0) {
668 } else if (strcmp(argv[i], "-MF") == 0) {
671 dependencies_file = NewString(argv[i + 1]);
672 Swig_mark_arg(i + 1);
676 } else if (strcmp(argv[i], "-MD") == 0) {
679 } else if (strcmp(argv[i], "-MMD") == 0) {
682 } else if (strcmp(argv[i], "-MT") == 0) {
685 if (!dependencies_target)
686 dependencies_target = NewString(argv[i + 1]);
688 Printf(dependencies_target, " %s", argv[i + 1]);
689 Swig_mark_arg(i + 1);
693 } else if (strcmp(argv[i], "-outdir") == 0) {
696 outdir = NewString(argv[i + 1]);
697 Swig_mark_arg(i + 1);
701 } else if (strcmp(argv[i], "-outcurrentdir") == 0) {
704 } else if (strcmp(argv[i], "-Wall") == 0) {
707 } else if (strcmp(argv[i], "-Wallkw") == 0) {
710 } else if (strcmp(argv[i], "-Werror") == 0) {
713 } else if (strcmp(argv[i], "-Wextra") == 0) {
715 Swig_warnfilter(EXTRA_WARNINGS, 0);
716 } else if (strncmp(argv[i], "-w", 2) == 0) {
718 Swig_warnfilter(argv[i] + 2, 1);
719 } else if ((strcmp(argv[i], "-debug-tags") == 0) || (strcmp(argv[i], "-dump_tags") == 0)) {
722 } else if (strcmp(argv[i], "-debug-top") == 0) {
725 String *dump_list = NewString(argv[i + 1]);
726 dump_top = decode_numbers_list(dump_list);
727 if (dump_top < STAGE1 || dump_top >= STAGEOVERFLOW)
730 Swig_mark_arg(i + 1);
735 } else if (strcmp(argv[i], "-debug-module") == 0) {
738 String *dump_list = NewString(argv[i + 1]);
739 dump_module = decode_numbers_list(dump_list);
740 if (dump_module < STAGE1 || dump_module >= STAGEOVERFLOW)
743 Swig_mark_arg(i + 1);
748 } else if ((strcmp(argv[i], "-dump_tree") == 0) || (strcmp(argv[i], "-dump_top") == 0)) {
751 } else if (strcmp(argv[i], "-dump_module") == 0) {
752 dump_module |= STAGE4;
754 } else if (strcmp(argv[i], "-dump_parse_module") == 0) {
755 dump_module |= STAGE1;
757 } else if (strcmp(argv[i], "-dump_parse_top") == 0) {
760 } else if (strcmp(argv[i], "-dump_xml") == 0) {
763 } else if (strcmp(argv[i], "-xmlout") == 0) {
767 xmlout = NewString(argv[i + 1]);
768 Swig_mark_arg(i + 1);
772 } else if (strcmp(argv[i], "-nocontract") == 0) {
774 Swig_contract_mode_set(0);
775 } else if (strcmp(argv[i], "-browse") == 0) {
778 } else if ((strcmp(argv[i], "-debug-typedef") == 0) || (strcmp(argv[i], "-dump_typedef") == 0)) {
781 } else if ((strcmp(argv[i], "-debug-classes") == 0) || (strcmp(argv[i], "-dump_classes") == 0)) {
784 } else if ((strcmp(argv[i], "-debug-memory") == 0) || (strcmp(argv[i], "-dump_memory") == 0)) {
787 } else if (strcmp(argv[i], "-Fstandard") == 0) {
788 Swig_error_msg_format(EMF_STANDARD);
790 } else if (strcmp(argv[i], "-Fmicrosoft") == 0) {
791 Swig_error_msg_format(EMF_MICROSOFT);
793 } else if (strcmp(argv[i], "-O") == 0) {
794 Wrapper_virtual_elimination_mode_set(1);
795 Wrapper_fast_dispatch_mode_set(1);
797 } else if (strcmp(argv[i], "-help") == 0) {
798 fputs(usage1, stdout);
799 fputs(usage2, stdout);
800 fputs(usage3, stdout);
812 int SWIG_main(int argc, char *argv[], Language *l) {
814 extern void Swig_print_xml(Node *obj, String *filename);
816 /* Initialize the SWIG core */
819 // Default warning suppression
820 Swig_warnfilter(EXTRA_WARNINGS, 1);
822 // Initialize the preprocessor
827 // Set up some default symbols (available in both SWIG interface files
830 Preprocessor_define((DOH *) "SWIG 1", 0);
831 Preprocessor_define((DOH *) "__STDC__", 0);
833 Preprocessor_define((DOH *) "SWIGMAC 1", 0);
836 Preprocessor_define((DOH *) "SWIGWIN32 1", 0);
839 // Set the SWIG version value in format 0xAABBCC from package version expected to be in format A.B.C
840 String *package_version = NewString(PACKAGE_VERSION); /* Note that the fakeversion has not been set at this point */
841 char *token = strtok(Char(package_version), ".");
842 String *vers = NewString("SWIG_VERSION 0x");
845 int len = strlen(token);
846 assert(len == 1 || len == 2);
847 Printf(vers, "%s%s", (len == 1) ? "0" : "", token);
848 token = strtok(NULL, ".");
851 Delete(package_version);
852 assert(count == 3); // Check version format is correct
854 /* Turn on contracts */
856 Swig_contract_mode_set(1);
857 Preprocessor_define(vers, 0);
859 /* Turn off directors mode */
860 Wrapper_director_mode_set(0);
861 Wrapper_director_protected_mode_set(1);
863 // Create Library search directories
865 // Check for SWIG_LIB environment variable
866 if ((c = getenv("SWIG_LIB")) == (char *) 0) {
870 if (!(GetModuleFileName(0, buf, MAX_PATH) == 0 || (p = strrchr(buf, '\\')) == 0)) {
872 SwigLibWin = NewStringf("%sLib", buf); // Native windows installation path
874 SwigLib = Swig_copy_string(SWIG_LIB_WIN_UNIX); // Unix installation path using a drive letter (for msys/mingw)
876 SwigLib = Swig_copy_string(SWIG_LIB);
879 SwigLib = Swig_copy_string(c);
882 libfiles = NewList();
883 all_output_files = NewList();
885 /* Check for SWIG_FEATURES environment variable */
887 SWIG_getoptions(argc, argv);
889 // Define the __cplusplus symbol
891 Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
893 // Parse language dependent options
894 lang->main(argc, argv);
897 Printf(stdout, "\nNote: 'swig -<lang> -help' displays options for a specific target language.\n\n");
898 SWIG_exit(EXIT_SUCCESS); // Exit if we're in help mode
900 // Check all of the options to make sure we're cool.
901 // Don't check for an input file if -external-runtime is passed
902 Swig_check_options(external_runtime ? 0 : 1);
904 install_opts(argc, argv);
906 // Add language dependent directory to the search path
908 String *rl = NewString("");
909 Printf(rl, ".%sswig_lib%s%s", SWIG_FILE_DELIMITER, SWIG_FILE_DELIMITER, LangSubDir);
910 Swig_add_directory(rl);
913 Printf(rl, "%s%s%s", SwigLibWin, SWIG_FILE_DELIMITER, LangSubDir);
914 Swig_add_directory(rl);
917 Printf(rl, "%s%s%s", SwigLib, SWIG_FILE_DELIMITER, LangSubDir);
918 Swig_add_directory(rl);
921 Swig_add_directory((String *) "." SWIG_FILE_DELIMITER "swig_lib");
923 Swig_add_directory((String *) SwigLibWin);
924 Swig_add_directory((String *) SwigLib);
927 printf("LangSubDir: %s\n", Char(LangSubDir));
928 printf("Search paths:\n");
929 List *sp = Swig_search_path();
931 for (s = First(sp); s.item; s = Next(s)) {
932 Printf(stdout, " %s\n", s.item);
935 // handle the -external-runtime argument
936 if (external_runtime)
939 // If we made it this far, looks good. go for it....
941 input_file = NewString(argv[argc - 1]);
942 Swig_filename_correct(input_file);
944 // If the user has requested to check out a file, handle that
947 char *outfile = Char(input_file);
949 outfile = outfile_name;
952 printf("Handling checkout...\n");
954 s = Swig_include(input_file);
956 Printf(stderr, "Unable to locate '%s' in the SWIG library.\n", input_file);
958 FILE *f = Swig_open(outfile);
961 Printf(stderr, "File '%s' already exists. Checkout aborted.\n", outfile);
963 File *f_outfile = NewFile(outfile, "w", SWIG_output_files());
965 FileErrorDisplay(outfile);
966 SWIG_exit(EXIT_FAILURE);
969 Printf(stdout, "'%s' checked out from the SWIG library.\n", outfile);
970 Printv(f_outfile, s, NIL);
976 // Run the preprocessor
978 printf("Preprocessing...\n");
982 String *fs = NewString("");
983 FILE *df = Swig_open(input_file);
985 df = Swig_include_open(input_file);
987 char *cfile = Char(input_file);
988 if (cfile && cfile[0] == '-') {
989 Printf(stderr, "Unable to find option or file '%s', ", input_file);
990 Printf(stderr, "use 'swig -help' for more information.\n");
992 Printf(stderr, "Unable to find file '%s'.\n", input_file);
994 SWIG_exit(EXIT_FAILURE);
996 Swig_warning(WARN_DEPRECATED_INPUT_FILE, "SWIG", 1, "Use of the include path to find the input file is deprecated and will not work with ccache. Please include the path when specifying the input file.\n"); // so that behaviour is like c/c++ compilers
1001 Printf(fs, "%%include <swig.swg>\n");
1003 Printf(fs, "%%include <allkw.swg>\n");
1006 Printf(fs, "\n%%include <%s>\n", lang_config);
1008 Printf(fs, "%%include(maininput=\"%s\") \"%s\"\n", Swig_filename_escape(input_file), Swig_last_file());
1009 for (i = 0; i < Len(libfiles); i++) {
1010 Printf(fs, "\n%%include \"%s\"\n", Getitem(libfiles, i));
1012 Seek(fs, 0, SEEK_SET);
1013 cpps = Preprocessor_parse(fs);
1016 cpps = Swig_read_file(df);
1019 if (Swig_error_count()) {
1020 SWIG_exit(EXIT_FAILURE);
1023 Printf(stdout, "%s", cpps);
1024 SWIG_exit(EXIT_SUCCESS);
1030 char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(input_file): Char(input_file));
1031 if (!outfile_name) {
1032 if (CPlusPlus || lang->cplus_runtime_mode()) {
1033 outfile = NewStringf("%s_wrap.%s", basename, cpp_extension);
1035 outfile = NewStringf("%s_wrap.c", basename);
1038 outfile = NewString(outfile_name);
1040 if (dependencies_file && Len(dependencies_file) != 0) {
1041 f_dependencies_file = NewFile(dependencies_file, "w", SWIG_output_files());
1042 if (!f_dependencies_file) {
1043 FileErrorDisplay(dependencies_file);
1044 SWIG_exit(EXIT_FAILURE);
1046 } else if (!depend_only) {
1047 String *filename = NewStringf("%s_wrap.%s", basename, depends_extension);
1048 f_dependencies_file = NewFile(filename, "w", SWIG_output_files());
1049 if (!f_dependencies_file) {
1050 FileErrorDisplay(filename);
1051 SWIG_exit(EXIT_FAILURE);
1054 f_dependencies_file = stdout;
1055 if (dependencies_target) {
1056 Printf(f_dependencies_file, "%s: ", dependencies_target);
1058 Printf(f_dependencies_file, "%s: ", outfile);
1060 List *files = Preprocessor_depend();
1061 for (int i = 0; i < Len(files); i++) {
1062 if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) != 0))) {
1063 Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
1066 Printf(f_dependencies_file, "\n");
1067 if (f_dependencies_file != stdout)
1068 Close(f_dependencies_file);
1070 SWIG_exit(EXIT_SUCCESS);
1072 Printf(stderr, "Cannot generate dependencies with -nopreprocess\n");
1073 // Actually we could but it would be inefficient when just generating dependencies, as it would be done after Swig_cparse
1074 SWIG_exit(EXIT_FAILURE);
1077 Seek(cpps, 0, SEEK_SET);
1080 /* Register a null file with the file handler */
1081 Swig_register_filebyname("null", NewString(""));
1083 // Pass control over to the specific language interpreter
1085 fprintf(stdout, "Starting language-specific parse...\n");
1089 Node *top = Swig_cparse(cpps);
1091 if (dump_top & STAGE1) {
1092 Printf(stdout, "debug-top stage 1\n");
1093 Swig_print_tree(top);
1095 if (dump_module & STAGE1) {
1096 Printf(stdout, "debug-module stage 1\n");
1097 Swig_print_tree(Getattr(top, "module"));
1101 Printf(stdout, "Processing types...\n");
1103 Swig_process_types(top);
1105 if (dump_top & STAGE2) {
1106 Printf(stdout, "debug-top stage 2\n");
1107 Swig_print_tree(top);
1109 if (dump_module & STAGE2) {
1110 Printf(stdout, "debug-module stage 2\n");
1111 Swig_print_tree(Getattr(top, "module"));
1115 Printf(stdout, "C++ analysis...\n");
1117 Swig_default_allocators(top);
1119 if (dump_top & STAGE3) {
1120 Printf(stdout, "debug-top stage 3\n");
1121 Swig_print_tree(top);
1123 if (dump_module & STAGE3) {
1124 Printf(stdout, "debug-module stage 3\n");
1125 Swig_print_tree(Getattr(top, "module"));
1129 Printf(stdout, "Generating wrappers...\n");
1133 Hash *classes = Getattr(top, "classes");
1135 Printf(stdout, "Classes\n");
1136 Printf(stdout, "------------\n");
1138 for (ki = First(classes); ki.key; ki = Next(ki)) {
1139 Printf(stdout, "%s\n", ki.key);
1145 SwigType_print_scope(0);
1149 Swig_print_tags(top, 0);
1152 if (!Getattr(top, "name")) {
1153 Printf(stderr, "No module name specified using %%module or -module.\n");
1154 SWIG_exit(EXIT_FAILURE);
1156 /* Set some filename information on the object */
1157 String *infile = scanner_get_main_input_file();
1159 Printf(stderr, "Missing input file in preprocessed output.\n");
1160 SWIG_exit(EXIT_FAILURE);
1162 Setattr(top, "infile", infile); // Note: if nopreprocess then infile is the original input file, otherwise input_file
1163 Setattr(top, "inputfile", input_file);
1165 char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(infile): Char(infile));
1166 if (!outfile_name) {
1167 if (CPlusPlus || lang->cplus_runtime_mode()) {
1168 Setattr(top, "outfile", NewStringf("%s_wrap.%s", basename, cpp_extension));
1170 Setattr(top, "outfile", NewStringf("%s_wrap.c", basename));
1173 Setattr(top, "outfile", outfile_name);
1175 if (!outfile_name_h) {
1176 Setattr(top, "outfile_h", NewStringf("%s_wrap.%s", basename, hpp_extension));
1178 Setattr(top, "outfile_h", outfile_name_h);
1180 set_outdir(Swig_file_dirname(Getattr(top, "outfile")));
1181 if (Swig_contract_mode_get()) {
1182 Swig_contracts(top);
1185 // Check the suffix for a c/c++ file. If so, we're going to declare everything we see as "extern"
1186 ForceExtern = check_suffix(input_file);
1191 Swig_browser(top, 0);
1195 if (dump_top & STAGE4) {
1196 Printf(stdout, "debug-top stage 4\n");
1197 Swig_print_tree(top);
1199 if (dump_module & STAGE4) {
1200 Printf(stdout, "debug-module stage 4\n");
1201 Swig_print_tree(Getattr(top, "module"));
1203 if (dump_xml && top) {
1204 Swig_print_xml(top, xmlout);
1209 Swig_typemap_debug();
1213 char *outfiles = getenv("CCACHE_OUTFILES");
1215 File *f_outfiles = NewFile(outfiles, "w", 0);
1217 Printf(stderr, "Failed to write list of output files to the filename '%s' specified in CCACHE_OUTFILES environment variable - ", outfiles);
1218 FileErrorDisplay(outfiles);
1219 SWIG_exit(EXIT_FAILURE);
1222 for (i = 0; i < Len(all_output_files); i++)
1223 Printf(f_outfiles, "%s\n", Getitem(all_output_files, i));
1230 Preprocessor_delete();
1235 if ((werror) && (Swig_warn_count())) {
1236 return Swig_warn_count();
1238 return Swig_error_count();
1241 // --------------------------------------------------------------------------
1242 // SWIG_exit(int exit_code)
1244 // Cleanup and either freeze or exit
1245 // --------------------------------------------------------------------------
1247 void SWIG_exit(int exit_code) {