1/* ----------------------------------------------------------------------------- 2 * See the LICENSE file for information on copyright, usage and redistribution 3 * of SWIG, and the README file for authors - http://www.swig.org/release.html. 4 * 5 * main.cxx 6 * 7 * Main entry point to the SWIG core. 8 * ----------------------------------------------------------------------------- */ 9 10char cvsroot_main_cxx[] = "$Id: main.cxx 11135 2009-02-20 20:55:16Z wsfulton $"; 11 12#include "swigconfig.h" 13 14#if defined(_WIN32) 15#define WIN32_LEAN_AND_MEAN 16#include <windows.h> 17#endif 18 19#include "swigmod.h" 20 21#include "swigwarn.h" 22#include "cparse.h" 23#include <ctype.h> 24#include <limits.h> // for INT_MAX 25 26// Global variables 27 28Language *lang; // Language method 29int CPlusPlus = 0; 30int Extend = 0; // Extend flag 31int ForceExtern = 0; // Force extern mode 32int GenerateDefault = 1; // Generate default constructors 33int Verbose = 0; 34int AddExtern = 0; 35int NoExcept = 0; 36int SwigRuntime = 0; // 0 = no option, 1 = -runtime, 2 = -noruntime 37 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 45 */ 46#define EXTRA_WARNINGS "202,309,403,512,321,322" 47 48extern "C" { 49 extern String *ModuleName; 50} 51 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 */ 55static const char *usage1 = (const char *) "\ 56\nGeneral Options\n\ 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\ 80"; 81 82static 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\ 112"; 113 114static 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\ 133\n\ 134Options can also be defined using the SWIG_FEATURES environment variable, for example:\n\ 135\n\ 136 $ SWIG_FEATURES=\"-Wall\"\n\ 137 $ export SWIG_FEATURES\n\ 138 $ swig -python interface.i\n\ 139\n\ 140is equivalent to: \n\ 141\n\ 142 $ swig -Wall -python interface.i \n\ 143\n\ 144\n"; 145 146// Local variables 147static String *LangSubDir = 0; // Target language library subdirectory 148static char *SwigLib = 0; // Library directory 149static String *SwigLibWin = 0; // Extra Library directory for Windows 150static int freeze = 0; 151static String *lang_config = 0; 152static char *hpp_extension = (char *) "h"; 153static char *cpp_extension = (char *) "cxx"; 154static char *depends_extension = (char *) "d"; 155static String *outdir = 0; 156static String *xmlout = 0; 157static int outcurrentdir = 0; 158static int help = 0; 159static int checkout = 0; 160static int cpp_only = 0; 161static int no_cpp = 0; 162static char *outfile_name = 0; 163static char *outfile_name_h = 0; 164static int tm_debug = 0; 165static int dump_tags = 0; 166static int dump_module = 0; 167static int dump_top = 0; 168static int dump_xml = 0; 169static int browse = 0; 170static int dump_typedef = 0; 171static int dump_classes = 0; 172static int werror = 0; 173static int depend = 0; 174static int depend_only = 0; 175static int memory_debug = 0; 176static int allkw = 0; 177static DOH *libfiles = 0; 178static DOH *cpps = 0; 179static String *dependencies_file = 0; 180static File *f_dependencies_file = 0; 181static String *dependencies_target = 0; 182static int external_runtime = 0; 183static String *external_runtime_name = 0; 184enum { STAGE1=1, STAGE2=2, STAGE3=4, STAGE4=8, STAGEOVERFLOW=16 }; 185static List *all_output_files = 0; 186 187// ----------------------------------------------------------------------------- 188// check_suffix() 189// 190// Checks the suffix of a file to see if we should emit extern declarations. 191// ----------------------------------------------------------------------------- 192 193static int check_suffix(String *filename) { 194 const char *name = Char(filename); 195 const char *c; 196 if (!name) 197 return 0; 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)) { 201 return 1; 202 } 203 return 0; 204} 205 206// ----------------------------------------------------------------------------- 207// install_opts(int argc, char *argv[]) 208// Install all command line options as preprocessor symbols 209// ----------------------------------------------------------------------------- 210 211static void install_opts(int argc, char *argv[]) { 212 int i; 213 int noopt = 0; 214 char *c; 215 for (i = 1; i < (argc - 1); i++) { 216 if (argv[i]) { 217 if ((*argv[i] == '-') && (!isupper(*(argv[i] + 1)))) { 218 String *opt = NewStringf("SWIGOPT%(upper)s", argv[i]); 219 Replaceall(opt, "-", "_"); 220 c = Char(opt); 221 noopt = 0; 222 while (*c) { 223 if (!(isalnum(*c) || (*c == '_'))) { 224 noopt = 1; 225 break; 226 } 227 c++; 228 } 229 if (((i + 1) < (argc - 1)) && (argv[i + 1]) && (*argv[i + 1] != '-')) { 230 Printf(opt, " %s", argv[i + 1]); 231 i++; 232 } else { 233 Printf(opt, " 1"); 234 } 235 if (!noopt) { 236 /* Printf(stdout,"%s\n", opt); */ 237 Preprocessor_define(opt, 0); 238 } 239 Delete(opt); 240 } 241 } 242 } 243} 244 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// ----------------------------------------------------------------------------- 250 251static unsigned int decode_numbers_list(String *numlist) { 252 unsigned int decoded_number = 0; 253 if (numlist) { 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)); 262 } 263 } 264 } 265 } 266 return decoded_number; 267} 268 269// ----------------------------------------------------------------------------- 270// Sets the output directory for language specific (proxy) files if not set and 271// adds trailing file separator if necessary. 272// ----------------------------------------------------------------------------- 273 274static void set_outdir(const String *c_wrapper_file_dir) { 275 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); 281 } 282 // Use the C wrapper file's directory if the output directory has not been set by user 283 if (!outdir) 284 outdir = NewString(c_wrapper_file_dir); 285} 286 287/* This function sets the name of the configuration file */ 288void SWIG_config_file(const_String_or_char_ptr filename) { 289 lang_config = NewString(filename); 290} 291 292/* Sets the target language subdirectory name */ 293void SWIG_library_directory(const char *subdirectory) { 294 LangSubDir = NewString(subdirectory); 295} 296 297// Returns the directory for generating language specific files (non C/C++ files) 298const String *SWIG_output_directory() { 299 assert(outdir); 300 return outdir; 301} 302 303void SWIG_config_cppext(const char *ext) { 304 cpp_extension = (char *) ext; 305} 306 307List *SWIG_output_files() { 308 assert(all_output_files); 309 return all_output_files; 310} 311 312void 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); 318 Delete(name); 319 Delete(fname); 320 Delete(fvalue); 321} 322 323 324void SWIG_setfeatures(const char *c) { 325 char feature[64]; 326 char *fb = feature; 327 char *fe = fb + 63; 328 Hash *features_hash = Swig_cparse_features(); 329 String *name = NewString(""); 330 /* Printf(stderr,"all features %s\n", c); */ 331 while (*c) { 332 char *f = fb; 333 String *fname = NewString("feature:"); 334 String *fvalue = NewString(""); 335 while ((f != fe) && *c != '=' && *c != ',' && *c) { 336 *(f++) = *(c++); 337 } 338 *f = 0; 339 Printf(fname, "%s", feature); 340 if (*c && *(c++) == '=') { 341 char value[64]; 342 char *v = value; 343 char *ve = v + 63; 344 while ((v != ve) && *c != ',' && *c && !isspace(*c)) { 345 *(v++) = *(c++); 346 } 347 *v = 0; 348 Printf(fvalue, "%s", value); 349 } else { 350 Printf(fvalue, "1"); 351 } 352 /* Printf(stderr,"%s %s\n", fname, fvalue); */ 353 Swig_feature_set(features_hash, name, 0, fname, fvalue, 0); 354 Delete(fname); 355 Delete(fvalue); 356 } 357 Delete(name); 358} 359 360/* This function handles the -external-runtime command option */ 361static void SWIG_dump_runtime() { 362 String *outfile; 363 File *runtime; 364 String *s; 365 366 outfile = external_runtime_name; 367 if (!outfile) { 368 outfile = lang->defaultExternalRuntimeFilename(); 369 if (!outfile) { 370 Printf(stderr, "*** Please provide a filename for the external runtime\n"); 371 SWIG_exit(EXIT_FAILURE); 372 } 373 } 374 375 runtime = NewFile(outfile, "w", SWIG_output_files()); 376 if (!runtime) { 377 FileErrorDisplay(outfile); 378 SWIG_exit(EXIT_FAILURE); 379 } 380 381 Swig_banner(runtime); 382 Printf(runtime, "\n"); 383 384 s = Swig_include_sys("swiglabels.swg"); 385 if (!s) { 386 Printf(stderr, "*** Unable to open 'swiglabels.swg'\n"); 387 Close(runtime); 388 SWIG_exit(EXIT_FAILURE); 389 } 390 Printf(runtime, "%s", s); 391 Delete(s); 392 393 s = Swig_include_sys("swigerrors.swg"); 394 if (!s) { 395 Printf(stderr, "*** Unable to open 'swigerrors.swg'\n"); 396 Close(runtime); 397 SWIG_exit(EXIT_FAILURE); 398 } 399 Printf(runtime, "%s", s); 400 Delete(s); 401 402 s = Swig_include_sys("swigerrors.swg"); 403 if (!s) { 404 Printf(stderr, "*** Unable to open 'swigerrors.swg'\n"); 405 Close(runtime); 406 SWIG_exit(EXIT_FAILURE); 407 } 408 Printf(runtime, "%s", s); 409 s = Swig_include_sys("swigrun.swg"); 410 if (!s) { 411 Printf(stderr, "*** Unable to open 'swigrun.swg'\n"); 412 Close(runtime); 413 SWIG_exit(EXIT_FAILURE); 414 } 415 Printf(runtime, "%s", s); 416 Delete(s); 417 418 s = lang->runtimeCode(); 419 Printf(runtime, "%s", s); 420 Delete(s); 421 422 s = Swig_include_sys("runtime.swg"); 423 if (!s) { 424 Printf(stderr, "*** Unable to open 'runtime.swg'\n"); 425 Close(runtime); 426 SWIG_exit(EXIT_FAILURE); 427 } 428 Printf(runtime, "%s", s); 429 Delete(s); 430 431 Close(runtime); 432 Delete(runtime); 433 SWIG_exit(EXIT_SUCCESS); 434} 435 436void SWIG_getoptions(int argc, char *argv[]) { 437 int i; 438 // Get options 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); 444 Swig_mark_arg(i); 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); 449 free(a); 450 Swig_mark_arg(i); 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); 455 Delete(d); 456 // Create a symbol 457 Swig_mark_arg(i); 458 } else if (strcmp(argv[i], "-E") == 0) { 459 cpp_only = 1; 460 Swig_mark_arg(i); 461 } else if (strcmp(argv[i], "-nopreprocess") == 0) { 462 no_cpp = 1; 463 Swig_mark_arg(i); 464 } else if ((strcmp(argv[i], "-verbose") == 0) || (strcmp(argv[i], "-v") == 0)) { 465 Verbose = 1; 466 Swig_mark_arg(i); 467 } else if (strcmp(argv[i], "-c++") == 0) { 468 CPlusPlus = 1; 469 Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0); 470 Swig_cparse_cplusplus(1); 471 Swig_mark_arg(i); 472 } else if (strcmp(argv[i], "-fcompact") == 0) { 473 Wrapper_compact_print_mode_set(1); 474 Swig_mark_arg(i); 475 } else if (strcmp(argv[i], "-fvirtual") == 0) { 476 Wrapper_virtual_elimination_mode_set(1); 477 Swig_mark_arg(i); 478 } else if (strcmp(argv[i], "-fastdispatch") == 0) { 479 Wrapper_fast_dispatch_mode_set(1); 480 Swig_mark_arg(i); 481 } else if (strcmp(argv[i], "-nofastdispatch") == 0) { 482 Wrapper_fast_dispatch_mode_set(0); 483 Swig_mark_arg(i); 484 } else if (strcmp(argv[i], "-naturalvar") == 0) { 485 Wrapper_naturalvar_mode_set(1); 486 Swig_mark_arg(i); 487 } else if (strcmp(argv[i], "-nonaturalvar") == 0) { 488 Wrapper_naturalvar_mode_set(0); 489 Swig_mark_arg(i); 490 } else if (strcmp(argv[i], "-directors") == 0) { 491 SWIG_setfeature("feature:director", "1"); 492 Wrapper_director_mode_set(1); 493 Swig_mark_arg(i); 494 } else if (strcmp(argv[i], "-dirprot") == 0) { 495 Wrapper_director_protected_mode_set(1); 496 Swig_mark_arg(i); 497 } else if (strcmp(argv[i], "-nodirprot") == 0) { 498 Wrapper_director_protected_mode_set(0); 499 Swig_mark_arg(i); 500 } else if (strcmp(argv[i], "-small") == 0) { 501 Wrapper_compact_print_mode_set(1); 502 Wrapper_virtual_elimination_mode_set(1); 503 Swig_mark_arg(i); 504 } else if (strcmp(argv[i], "-runtime") == 0) { // Used to also accept -c. removed in swig-1.3.36 505 Swig_mark_arg(i); 506 Swig_warning(WARN_DEPRECATED_OPTC, "SWIG", 1, "-runtime, -noruntime command line options are deprecated.\n"); 507 SwigRuntime = 1; 508 } else if (strcmp(argv[i], "-noruntime") == 0) { 509 Swig_mark_arg(i); 510 Swig_warning(WARN_DEPRECATED_OPTC, "SWIG", 1, "-runtime, -noruntime command line options are deprecated.\n"); 511 SwigRuntime = 2; 512 } else if (strcmp(argv[i], "-external-runtime") == 0) { 513 external_runtime = 1; 514 Swig_mark_arg(i); 515 if (argv[i + 1]) { 516 external_runtime_name = NewString(argv[i + 1]); 517 Swig_mark_arg(i + 1); 518 i++; 519 } 520 } else if ((strcmp(argv[i], "-make_default") == 0) || (strcmp(argv[i], "-makedefault") == 0)) { 521 GenerateDefault = 1; 522 Swig_mark_arg(i); 523 } else if ((strcmp(argv[i], "-no_default") == 0) || (strcmp(argv[i], "-nodefault") == 0)) { 524 GenerateDefault = 0; 525 Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG", 1, "dangerous, use -nodefaultctor, -nodefaultdtor instead.\n"); 526 Swig_mark_arg(i); 527 } else if ((strcmp(argv[i], "-nodefaultctor") == 0)) { 528 SWIG_setfeature("feature:nodefaultctor", "1"); 529 Swig_mark_arg(i); 530 } else if ((strcmp(argv[i], "-nodefaultdtor") == 0)) { 531 SWIG_setfeature("feature:nodefaultdtor", "1"); 532 Swig_mark_arg(i); 533 } else if ((strcmp(argv[i], "-copyctor") == 0)) { 534 SWIG_setfeature("feature:copyctor", "1"); 535 Swig_mark_arg(i); 536 } else if (strcmp(argv[i], "-noexcept") == 0) { 537 NoExcept = 1; 538 Swig_mark_arg(i); 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"); 541 AddExtern = 0; 542 Swig_mark_arg(i); 543 } else if (strcmp(argv[i], "-addextern") == 0) { 544 AddExtern = 1; 545 Swig_mark_arg(i); 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); 548 Swig_mark_arg(i); 549 } else if (strcmp(argv[i], "-templatereduce") == 0) { 550 SWIG_cparse_template_reduce(1); 551 Swig_mark_arg(i); 552 } else if (strcmp(argv[i], "-notemplatereduce") == 0) { 553 SWIG_cparse_template_reduce(0); 554 Swig_mark_arg(i); 555 } else if (strcmp(argv[i], "-macroerrors") == 0) { 556 Swig_cparse_follow_locators(1); 557 Swig_mark_arg(i); 558 } else if (strcmp(argv[i], "-swiglib") == 0) { 559 if (SwigLibWin) 560 printf("%s\n", Char(SwigLibWin)); 561 printf("%s\n", SwigLib); 562 SWIG_exit(EXIT_SUCCESS); 563 } else if (strcmp(argv[i], "-o") == 0) { 564 Swig_mark_arg(i); 565 if (argv[i + 1]) { 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); 572 } 573 if (!outfile_name_h) { 574 Printf(basename, ".%s", hpp_extension); 575 outfile_name_h = Swig_copy_string(Char(basename)); 576 } 577 Delete(basename); 578 } 579 Swig_mark_arg(i + 1); 580 i++; 581 } else { 582 Swig_arg_error(); 583 } 584 } else if (strcmp(argv[i], "-oh") == 0) { 585 Swig_mark_arg(i); 586 if (argv[i + 1]) { 587 outfile_name_h = Swig_copy_string(argv[i + 1]); 588 Swig_mark_arg(i + 1); 589 i++; 590 } else { 591 Swig_arg_error(); 592 } 593 } else if (strcmp(argv[i], "-fakeversion") == 0) { 594 Swig_mark_arg(i); 595 if (argv[i + 1]) { 596 Swig_set_fakeversion(argv[i + 1]); 597 Swig_mark_arg(i + 1); 598 i++; 599 } else { 600 Swig_arg_error(); 601 } 602 } else if (strcmp(argv[i], "-version") == 0) { 603 fprintf(stdout, "\nSWIG Version %s\n", Swig_package_version()); 604#ifndef __APPLE__ 605 fprintf(stdout, "\nCompiled with %s [%s]\n", SWIG_CXX, SWIG_PLATFORM); 606 fprintf(stdout, "Please see %s for reporting bugs and further information\n", PACKAGE_BUGREPORT); 607#endif 608 SWIG_exit(EXIT_SUCCESS); 609 } else if (strcmp(argv[i], "-copyright") == 0) { 610 fprintf(stdout, "\nSWIG Version %s\n", Swig_package_version()); 611 fprintf(stdout, "Copyright (c) 1995-1998\n"); 612 fprintf(stdout, "University of Utah and the Regents of the University of California\n"); 613 fprintf(stdout, "Copyright (c) 1998-2005\n"); 614 fprintf(stdout, "University of Chicago\n"); 615 fprintf(stdout, "Copyright (c) 2005-2006\n"); 616 fprintf(stdout, "Arizona Board of Regents (University of Arizona)\n"); 617 SWIG_exit(EXIT_SUCCESS); 618 } else if (strncmp(argv[i], "-l", 2) == 0) { 619 // Add a new directory search path 620 Append(libfiles, argv[i] + 2); 621 Swig_mark_arg(i); 622 } else if (strcmp(argv[i], "-co") == 0) { 623 checkout = 1; 624 Swig_mark_arg(i); 625 } else if (strcmp(argv[i], "-features") == 0) { 626 Swig_mark_arg(i); 627 if (argv[i + 1]) { 628 SWIG_setfeatures(argv[i + 1]); 629 Swig_mark_arg(i + 1); 630 } else { 631 Swig_arg_error(); 632 } 633 } else if (strcmp(argv[i], "-freeze") == 0) { 634 freeze = 1; 635 Swig_mark_arg(i); 636 } else if (strcmp(argv[i], "-includeall") == 0) { 637 Preprocessor_include_all(1); 638 Swig_mark_arg(i); 639 } else if (strcmp(argv[i], "-importall") == 0) { 640 Preprocessor_import_all(1); 641 Swig_mark_arg(i); 642 } else if (strcmp(argv[i], "-ignoremissing") == 0) { 643 Preprocessor_ignore_missing(1); 644 Swig_mark_arg(i); 645 } else if (strcmp(argv[i], "-cpperraswarn") == 0) { 646 Preprocessor_error_as_warning(1); 647 Swig_mark_arg(i); 648 } else if (strcmp(argv[i], "-nocpperraswarn") == 0) { 649 Preprocessor_error_as_warning(0); 650 Swig_mark_arg(i); 651 } else if ((strcmp(argv[i], "-debug-typemap") == 0) || (strcmp(argv[i], "-debug_typemap") == 0) || (strcmp(argv[i], "-tm_debug") == 0)) { 652 tm_debug = 1; 653 Swig_mark_arg(i); 654 } else if (strcmp(argv[i], "-module") == 0) { 655 Swig_mark_arg(i); 656 if (argv[i + 1]) { 657 ModuleName = NewString(argv[i + 1]); 658 Swig_mark_arg(i + 1); 659 } else { 660 Swig_arg_error(); 661 } 662 } else if (strcmp(argv[i], "-M") == 0) { 663 depend = 1; 664 depend_only = 1; 665 Swig_mark_arg(i); 666 } else if (strcmp(argv[i], "-MM") == 0) { 667 depend = 2; 668 depend_only = 1; 669 Swig_mark_arg(i); 670 } else if (strcmp(argv[i], "-MF") == 0) { 671 Swig_mark_arg(i); 672 if (argv[i + 1]) { 673 dependencies_file = NewString(argv[i + 1]); 674 Swig_mark_arg(i + 1); 675 } else { 676 Swig_arg_error(); 677 } 678 } else if (strcmp(argv[i], "-MD") == 0) { 679 depend = 1; 680 Swig_mark_arg(i); 681 } else if (strcmp(argv[i], "-MMD") == 0) { 682 depend = 2; 683 Swig_mark_arg(i); 684 } else if (strcmp(argv[i], "-MT") == 0) { 685 Swig_mark_arg(i); 686 if (argv[i + 1]) { 687 if (!dependencies_target) 688 dependencies_target = NewString(argv[i + 1]); 689 else 690 Printf(dependencies_target, " %s", argv[i + 1]); 691 Swig_mark_arg(i + 1); 692 } else { 693 Swig_arg_error(); 694 } 695 } else if (strcmp(argv[i], "-outdir") == 0) { 696 Swig_mark_arg(i); 697 if (argv[i + 1]) { 698 outdir = NewString(argv[i + 1]); 699 Swig_mark_arg(i + 1); 700 } else { 701 Swig_arg_error(); 702 } 703 } else if (strcmp(argv[i], "-outcurrentdir") == 0) { 704 Swig_mark_arg(i); 705 outcurrentdir = 1; 706 } else if (strcmp(argv[i], "-Wall") == 0) { 707 Swig_mark_arg(i); 708 Swig_warnall(); 709 } else if (strcmp(argv[i], "-Wallkw") == 0) { 710 allkw = 1; 711 Swig_mark_arg(i); 712 } else if (strcmp(argv[i], "-Werror") == 0) { 713 werror = 1; 714 Swig_mark_arg(i); 715 } else if (strcmp(argv[i], "-Wextra") == 0) { 716 Swig_mark_arg(i); 717 Swig_warnfilter(EXTRA_WARNINGS, 0); 718 } else if (strncmp(argv[i], "-w", 2) == 0) { 719 Swig_mark_arg(i); 720 Swig_warnfilter(argv[i] + 2, 1); 721 } else if ((strcmp(argv[i], "-debug-tags") == 0) || (strcmp(argv[i], "-dump_tags") == 0)) { 722 dump_tags = 1; 723 Swig_mark_arg(i); 724 } else if (strcmp(argv[i], "-debug-top") == 0) { 725 Swig_mark_arg(i); 726 if (argv[i + 1]) { 727 String *dump_list = NewString(argv[i + 1]); 728 dump_top = decode_numbers_list(dump_list); 729 if (dump_top < STAGE1 || dump_top >= STAGEOVERFLOW) 730 Swig_arg_error(); 731 else 732 Swig_mark_arg(i + 1); 733 Delete(dump_list); 734 } else { 735 Swig_arg_error(); 736 } 737 } else if (strcmp(argv[i], "-debug-module") == 0) { 738 Swig_mark_arg(i); 739 if (argv[i + 1]) { 740 String *dump_list = NewString(argv[i + 1]); 741 dump_module = decode_numbers_list(dump_list); 742 if (dump_module < STAGE1 || dump_module >= STAGEOVERFLOW) 743 Swig_arg_error(); 744 else 745 Swig_mark_arg(i + 1); 746 Delete(dump_list); 747 } else { 748 Swig_arg_error(); 749 } 750 } else if ((strcmp(argv[i], "-dump_tree") == 0) || (strcmp(argv[i], "-dump_top") == 0)) { 751 dump_top |= STAGE4; 752 Swig_mark_arg(i); 753 } else if (strcmp(argv[i], "-dump_module") == 0) { 754 dump_module |= STAGE4; 755 Swig_mark_arg(i); 756 } else if (strcmp(argv[i], "-dump_parse_module") == 0) { 757 dump_module |= STAGE1; 758 Swig_mark_arg(i); 759 } else if (strcmp(argv[i], "-dump_parse_top") == 0) { 760 dump_top |= STAGE1; 761 Swig_mark_arg(i); 762 } else if (strcmp(argv[i], "-dump_xml") == 0) { 763 dump_xml = 1; 764 Swig_mark_arg(i); 765 } else if (strcmp(argv[i], "-xmlout") == 0) { 766 dump_xml = 1; 767 Swig_mark_arg(i); 768 if (argv[i + 1]) { 769 xmlout = NewString(argv[i + 1]); 770 Swig_mark_arg(i + 1); 771 } else { 772 Swig_arg_error(); 773 } 774 } else if (strcmp(argv[i], "-nocontract") == 0) { 775 Swig_mark_arg(i); 776 Swig_contract_mode_set(0); 777 } else if (strcmp(argv[i], "-browse") == 0) { 778 browse = 1; 779 Swig_mark_arg(i); 780 } else if ((strcmp(argv[i], "-debug-typedef") == 0) || (strcmp(argv[i], "-dump_typedef") == 0)) { 781 dump_typedef = 1; 782 Swig_mark_arg(i); 783 } else if ((strcmp(argv[i], "-debug-classes") == 0) || (strcmp(argv[i], "-dump_classes") == 0)) { 784 dump_classes = 1; 785 Swig_mark_arg(i); 786 } else if ((strcmp(argv[i], "-debug-memory") == 0) || (strcmp(argv[i], "-dump_memory") == 0)) { 787 memory_debug = 1; 788 Swig_mark_arg(i); 789 } else if (strcmp(argv[i], "-Fstandard") == 0) { 790 Swig_error_msg_format(EMF_STANDARD); 791 Swig_mark_arg(i); 792 } else if (strcmp(argv[i], "-Fmicrosoft") == 0) { 793 Swig_error_msg_format(EMF_MICROSOFT); 794 Swig_mark_arg(i); 795 } else if (strcmp(argv[i], "-O") == 0) { 796 Wrapper_virtual_elimination_mode_set(1); 797 Wrapper_fast_dispatch_mode_set(1); 798 Swig_mark_arg(i); 799 } else if (strcmp(argv[i], "-help") == 0) { 800 fputs(usage1, stdout); 801 fputs(usage2, stdout); 802 fputs(usage3, stdout); 803 Swig_mark_arg(i); 804 help = 1; 805 } 806 } 807 } 808} 809 810 811 812 813 814int SWIG_main(int argc, char *argv[], Language *l) { 815 char *c; 816 extern void Swig_print_xml(Node *obj, String *filename); 817 818 /* Initialize the SWIG core */ 819 Swig_init(); 820 821 // Default warning suppression 822 Swig_warnfilter(EXTRA_WARNINGS, 1); 823 824 // Initialize the preprocessor 825 Preprocessor_init(); 826 827 lang = l; 828 829 // Set up some default symbols (available in both SWIG interface files 830 // and C files) 831 832 Preprocessor_define((DOH *) "SWIG 1", 0); 833 Preprocessor_define((DOH *) "__STDC__", 0); 834#ifdef MACSWIG 835 Preprocessor_define((DOH *) "SWIGMAC 1", 0); 836#endif 837#ifdef SWIGWIN32 838 Preprocessor_define((DOH *) "SWIGWIN32 1", 0); 839#endif 840 841 // Set the SWIG version value in format 0xAABBCC from package version expected to be in format A.B.C 842 String *package_version = NewString(PACKAGE_VERSION); /* Note that the fakeversion has not been set at this point */ 843 char *token = strtok(Char(package_version), "."); 844 String *vers = NewString("SWIG_VERSION 0x"); 845 int count = 0; 846 while (token) { 847 int len = strlen(token); 848 assert(len == 1 || len == 2); 849 Printf(vers, "%s%s", (len == 1) ? "0" : "", token); 850 token = strtok(NULL, "."); 851 count++; 852 } 853 Delete(package_version); 854 assert(count == 3); // Check version format is correct 855 856 /* Turn on contracts */ 857 858 Swig_contract_mode_set(1); 859 Preprocessor_define(vers, 0); 860 861 /* Turn off directors mode */ 862 Wrapper_director_mode_set(0); 863 Wrapper_director_protected_mode_set(1); 864 865 // Create Library search directories 866 867 // Check for SWIG_LIB environment variable 868 if ((c = getenv("SWIG_LIB")) == (char *) 0) { 869#if defined(_WIN32) 870 char buf[MAX_PATH]; 871 char *p; 872 if (!(GetModuleFileName(0, buf, MAX_PATH) == 0 || (p = strrchr(buf, '\\')) == 0)) { 873 *(p + 1) = '\0'; 874 SwigLibWin = NewStringf("%sLib", buf); // Native windows installation path 875 } 876 SwigLib = Swig_copy_string(SWIG_LIB_WIN_UNIX); // Unix installation path using a drive letter (for msys/mingw) 877#else 878 SwigLib = Swig_copy_string(SWIG_LIB); 879#endif 880 } else { 881 SwigLib = Swig_copy_string(c); 882 } 883 884 libfiles = NewList(); 885 all_output_files = NewList(); 886 887 /* Check for SWIG_FEATURES environment variable */ 888 889 SWIG_getoptions(argc, argv); 890 891 // Define the __cplusplus symbol 892 if (CPlusPlus) 893 Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0); 894 895 // Parse language dependent options 896 lang->main(argc, argv); 897 898 if (help) { 899 Printf(stdout, "\nNote: 'swig -<lang> -help' displays options for a specific target language.\n\n"); 900 SWIG_exit(EXIT_SUCCESS); // Exit if we're in help mode 901 } 902 // Check all of the options to make sure we're cool. 903 // Don't check for an input file if -external-runtime is passed 904 Swig_check_options(external_runtime ? 0 : 1); 905 906 install_opts(argc, argv); 907 908 // Add language dependent directory to the search path 909 { 910 String *rl = NewString(""); 911 Printf(rl, ".%sswig_lib%s%s", SWIG_FILE_DELIMITER, SWIG_FILE_DELIMITER, LangSubDir); 912 Swig_add_directory(rl); 913 if (SwigLibWin) { 914 rl = NewString(""); 915 Printf(rl, "%s%s%s", SwigLibWin, SWIG_FILE_DELIMITER, LangSubDir); 916 Swig_add_directory(rl); 917 } 918 rl = NewString(""); 919 Printf(rl, "%s%s%s", SwigLib, SWIG_FILE_DELIMITER, LangSubDir); 920 Swig_add_directory(rl); 921 } 922 923 Swig_add_directory((String *) "." SWIG_FILE_DELIMITER "swig_lib"); 924 if (SwigLibWin) 925 Swig_add_directory((String *) SwigLibWin); 926 Swig_add_directory((String *) SwigLib); 927 928 if (Verbose) { 929 printf("LangSubDir: %s\n", Char(LangSubDir)); 930 printf("Search paths:\n"); 931 List *sp = Swig_search_path(); 932 Iterator s; 933 for (s = First(sp); s.item; s = Next(s)) { 934 Printf(stdout, " %s\n", s.item); 935 } 936 } 937 // handle the -external-runtime argument 938 if (external_runtime) 939 SWIG_dump_runtime(); 940 941 // If we made it this far, looks good. go for it.... 942 943 input_file = NewString(argv[argc - 1]); 944 Swig_filename_correct(input_file); 945 946 // If the user has requested to check out a file, handle that 947 if (checkout) { 948 DOH *s; 949 char *outfile = Char(input_file); 950 if (outfile_name) 951 outfile = outfile_name; 952 953 if (Verbose) 954 printf("Handling checkout...\n"); 955 956 s = Swig_include(input_file); 957 if (!s) { 958 Printf(stderr, "Unable to locate '%s' in the SWIG library.\n", input_file); 959 } else { 960 FILE *f = Swig_open(outfile); 961 if (f) { 962 fclose(f); 963 Printf(stderr, "File '%s' already exists. Checkout aborted.\n", outfile); 964 } else { 965 File *f_outfile = NewFile(outfile, "w", SWIG_output_files()); 966 if (!f_outfile) { 967 FileErrorDisplay(outfile); 968 SWIG_exit(EXIT_FAILURE); 969 } else { 970 if (Verbose) 971 Printf(stdout, "'%s' checked out from the SWIG library.\n", outfile); 972 Printv(f_outfile, s, NIL); 973 Close(f_outfile); 974 } 975 } 976 } 977 } else { 978 // Run the preprocessor 979 if (Verbose) 980 printf("Preprocessing...\n"); 981 982 { 983 int i; 984 String *fs = NewString(""); 985 FILE *df = Swig_open(input_file); 986 if (!df) { 987 df = Swig_include_open(input_file); 988 if (!df) { 989 char *cfile = Char(input_file); 990 if (cfile && cfile[0] == '-') { 991 Printf(stderr, "Unable to find option or file '%s', ", input_file); 992 Printf(stderr, "use 'swig -help' for more information.\n"); 993 } else { 994 Printf(stderr, "Unable to find file '%s'.\n", input_file); 995 } 996 SWIG_exit(EXIT_FAILURE); 997 } else { 998 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 999 } 1000 } 1001 if (!no_cpp) { 1002 fclose(df); 1003 Printf(fs, "%%include <swig.swg>\n"); 1004 if (allkw) { 1005 Printf(fs, "%%include <allkw.swg>\n"); 1006 } 1007 if (lang_config) { 1008 Printf(fs, "\n%%include <%s>\n", lang_config); 1009 } 1010 Printf(fs, "%%include(maininput=\"%s\") \"%s\"\n", Swig_filename_escape(input_file), Swig_last_file()); 1011 for (i = 0; i < Len(libfiles); i++) { 1012 Printf(fs, "\n%%include \"%s\"\n", Getitem(libfiles, i)); 1013 } 1014 Seek(fs, 0, SEEK_SET); 1015 cpps = Preprocessor_parse(fs); 1016 Delete(fs); 1017 } else { 1018 cpps = Swig_read_file(df); 1019 fclose(df); 1020 } 1021 if (Swig_error_count()) { 1022 SWIG_exit(EXIT_FAILURE); 1023 } 1024 if (cpp_only) { 1025 Printf(stdout, "%s", cpps); 1026 SWIG_exit(EXIT_SUCCESS); 1027 } 1028 if (depend) { 1029 if (!no_cpp) { 1030 String *outfile; 1031 1032 char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(input_file): Char(input_file)); 1033 if (!outfile_name) { 1034 if (CPlusPlus || lang->cplus_runtime_mode()) { 1035 outfile = NewStringf("%s_wrap.%s", basename, cpp_extension); 1036 } else { 1037 outfile = NewStringf("%s_wrap.c", basename); 1038 } 1039 } else { 1040 outfile = NewString(outfile_name); 1041 } 1042 if (dependencies_file && Len(dependencies_file) != 0) { 1043 f_dependencies_file = NewFile(dependencies_file, "w", SWIG_output_files()); 1044 if (!f_dependencies_file) { 1045 FileErrorDisplay(dependencies_file); 1046 SWIG_exit(EXIT_FAILURE); 1047 } 1048 } else if (!depend_only) { 1049 String *filename = NewStringf("%s_wrap.%s", basename, depends_extension); 1050 f_dependencies_file = NewFile(filename, "w", SWIG_output_files()); 1051 if (!f_dependencies_file) { 1052 FileErrorDisplay(filename); 1053 SWIG_exit(EXIT_FAILURE); 1054 } 1055 } else 1056 f_dependencies_file = stdout; 1057 if (dependencies_target) { 1058 Printf(f_dependencies_file, "%s: ", dependencies_target); 1059 } else { 1060 Printf(f_dependencies_file, "%s: ", outfile); 1061 } 1062 List *files = Preprocessor_depend(); 1063 for (int i = 0; i < Len(files); i++) { 1064 if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) != 0))) { 1065 Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i)); 1066 } 1067 } 1068 Printf(f_dependencies_file, "\n"); 1069 if (f_dependencies_file != stdout) 1070 Close(f_dependencies_file); 1071 if (depend_only) 1072 SWIG_exit(EXIT_SUCCESS); 1073 } else { 1074 Printf(stderr, "Cannot generate dependencies with -nopreprocess\n"); 1075 // Actually we could but it would be inefficient when just generating dependencies, as it would be done after Swig_cparse 1076 SWIG_exit(EXIT_FAILURE); 1077 } 1078 } 1079 Seek(cpps, 0, SEEK_SET); 1080 } 1081 1082 /* Register a null file with the file handler */ 1083 Swig_register_filebyname("null", NewString("")); 1084 1085 // Pass control over to the specific language interpreter 1086 if (Verbose) { 1087 fprintf(stdout, "Starting language-specific parse...\n"); 1088 fflush(stdout); 1089 } 1090 1091 Node *top = Swig_cparse(cpps); 1092 1093 if (dump_top & STAGE1) { 1094 Printf(stdout, "debug-top stage 1\n"); 1095 Swig_print_tree(top); 1096 } 1097 if (dump_module & STAGE1) { 1098 Printf(stdout, "debug-module stage 1\n"); 1099 Swig_print_tree(Getattr(top, "module")); 1100 } 1101 1102 if (Verbose) { 1103 Printf(stdout, "Processing types...\n"); 1104 } 1105 Swig_process_types(top); 1106 1107 if (dump_top & STAGE2) { 1108 Printf(stdout, "debug-top stage 2\n"); 1109 Swig_print_tree(top); 1110 } 1111 if (dump_module & STAGE2) { 1112 Printf(stdout, "debug-module stage 2\n"); 1113 Swig_print_tree(Getattr(top, "module")); 1114 } 1115 1116 if (Verbose) { 1117 Printf(stdout, "C++ analysis...\n"); 1118 } 1119 Swig_default_allocators(top); 1120 1121 if (dump_top & STAGE3) { 1122 Printf(stdout, "debug-top stage 3\n"); 1123 Swig_print_tree(top); 1124 } 1125 if (dump_module & STAGE3) { 1126 Printf(stdout, "debug-module stage 3\n"); 1127 Swig_print_tree(Getattr(top, "module")); 1128 } 1129 1130 if (Verbose) { 1131 Printf(stdout, "Generating wrappers...\n"); 1132 } 1133 1134 if (dump_classes) { 1135 Hash *classes = Getattr(top, "classes"); 1136 if (classes) { 1137 Printf(stdout, "Classes\n"); 1138 Printf(stdout, "------------\n"); 1139 Iterator ki; 1140 for (ki = First(classes); ki.key; ki = Next(ki)) { 1141 Printf(stdout, "%s\n", ki.key); 1142 } 1143 } 1144 } 1145 1146 if (dump_typedef) { 1147 SwigType_print_scope(0); 1148 } 1149 1150 if (dump_tags) { 1151 Swig_print_tags(top, 0); 1152 } 1153 if (top) { 1154 if (!Getattr(top, "name")) { 1155 Printf(stderr, "No module name specified using %%module or -module.\n"); 1156 SWIG_exit(EXIT_FAILURE); 1157 } else { 1158 /* Set some filename information on the object */ 1159 String *infile = scanner_get_main_input_file(); 1160 if (!infile) { 1161 Printf(stderr, "Missing input file in preprocessed output.\n"); 1162 SWIG_exit(EXIT_FAILURE); 1163 } 1164 Setattr(top, "infile", infile); // Note: if nopreprocess then infile is the original input file, otherwise input_file 1165 Setattr(top, "inputfile", input_file); 1166 1167 char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(infile): Char(infile)); 1168 if (!outfile_name) { 1169 if (CPlusPlus || lang->cplus_runtime_mode()) { 1170 Setattr(top, "outfile", NewStringf("%s_wrap.%s", basename, cpp_extension)); 1171 } else { 1172 Setattr(top, "outfile", NewStringf("%s_wrap.c", basename)); 1173 } 1174 } else { 1175 Setattr(top, "outfile", outfile_name); 1176 } 1177 if (!outfile_name_h) { 1178 Setattr(top, "outfile_h", NewStringf("%s_wrap.%s", basename, hpp_extension)); 1179 } else { 1180 Setattr(top, "outfile_h", outfile_name_h); 1181 } 1182 set_outdir(Swig_file_dirname(Getattr(top, "outfile"))); 1183 if (Swig_contract_mode_get()) { 1184 Swig_contracts(top); 1185 } 1186 1187 // Check the suffix for a c/c++ file. If so, we're going to declare everything we see as "extern" 1188 ForceExtern = check_suffix(input_file); 1189 1190 lang->top(top); 1191 1192 if (browse) { 1193 Swig_browser(top, 0); 1194 } 1195 } 1196 } 1197 if (dump_top & STAGE4) { 1198 Printf(stdout, "debug-top stage 4\n"); 1199 Swig_print_tree(top); 1200 } 1201 if (dump_module & STAGE4) { 1202 Printf(stdout, "debug-module stage 4\n"); 1203 Swig_print_tree(Getattr(top, "module")); 1204 } 1205 if (dump_xml && top) { 1206 Swig_print_xml(top, xmlout); 1207 } 1208 Delete(top); 1209 } 1210 if (tm_debug) 1211 Swig_typemap_debug(); 1212 if (memory_debug) 1213 DohMemoryDebug(); 1214 1215 char *outfiles = getenv("CCACHE_OUTFILES"); 1216 if (outfiles) { 1217 File *f_outfiles = NewFile(outfiles, "w", 0); 1218 if (!f_outfiles) { 1219 Printf(stderr, "Failed to write list of output files to the filename '%s' specified in CCACHE_OUTFILES environment variable - ", outfiles); 1220 FileErrorDisplay(outfiles); 1221 SWIG_exit(EXIT_FAILURE); 1222 } else { 1223 int i; 1224 for (i = 0; i < Len(all_output_files); i++) 1225 Printf(f_outfiles, "%s\n", Getitem(all_output_files, i)); 1226 Close(f_outfiles); 1227 } 1228 } 1229 1230 // Deletes 1231 Delete(libfiles); 1232 Preprocessor_delete(); 1233 1234 while (freeze) { 1235 } 1236 1237 if ((werror) && (Swig_warn_count())) { 1238 return Swig_warn_count(); 1239 } 1240 return Swig_error_count(); 1241} 1242 1243// -------------------------------------------------------------------------- 1244// SWIG_exit(int exit_code) 1245// 1246// Cleanup and either freeze or exit 1247// -------------------------------------------------------------------------- 1248 1249void SWIG_exit(int exit_code) { 1250 while (freeze) { 1251 } 1252 exit(exit_code); 1253} 1254