import source from 1.3.40
[external/swig.git] / Source / Modules / main.cxx
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
10 char 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
28 Language *lang;                 // Language method
29 int CPlusPlus = 0;
30 int Extend = 0;                 // Extend flag
31 int ForceExtern = 0;            // Force extern mode
32 int GenerateDefault = 1;        // Generate default constructors
33 int Verbose = 0;
34 int AddExtern = 0;
35 int NoExcept = 0;
36 int 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
48 extern "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 */
55 static 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
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\
112 ";
113
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\
133 \n\
134 Options 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\
140 is equivalent to: \n\
141 \n\
142   $ swig -Wall -python interface.i \n\
143 \n\
144 \n";
145
146 // Local variables
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;
158 static int help = 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;
186
187 // -----------------------------------------------------------------------------
188 // check_suffix()
189 //
190 // Checks the suffix of a file to see if we should emit extern declarations.
191 // -----------------------------------------------------------------------------
192
193 static 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
211 static 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
251 static 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
274 static 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 */
288 void SWIG_config_file(const_String_or_char_ptr filename) {
289   lang_config = NewString(filename);
290 }
291
292 /* Sets the target language subdirectory name */
293 void 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)
298 const String *SWIG_output_directory() {
299   assert(outdir);
300   return outdir;
301 }
302
303 void SWIG_config_cppext(const char *ext) {
304   cpp_extension = (char *) ext;
305 }
306
307 List *SWIG_output_files() {
308   assert(all_output_files);
309   return all_output_files;
310 }
311
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);
318   Delete(name);
319   Delete(fname);
320   Delete(fvalue);
321 }
322
323
324 void 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 */
361 static 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
436 void 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         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);
619         Swig_mark_arg(i);
620       } else if (strcmp(argv[i], "-co") == 0) {
621         checkout = 1;
622         Swig_mark_arg(i);
623       } else if (strcmp(argv[i], "-features") == 0) {
624         Swig_mark_arg(i);
625         if (argv[i + 1]) {
626           SWIG_setfeatures(argv[i + 1]);
627           Swig_mark_arg(i + 1);
628         } else {
629           Swig_arg_error();
630         }
631       } else if (strcmp(argv[i], "-freeze") == 0) {
632         freeze = 1;
633         Swig_mark_arg(i);
634       } else if (strcmp(argv[i], "-includeall") == 0) {
635         Preprocessor_include_all(1);
636         Swig_mark_arg(i);
637       } else if (strcmp(argv[i], "-importall") == 0) {
638         Preprocessor_import_all(1);
639         Swig_mark_arg(i);
640       } else if (strcmp(argv[i], "-ignoremissing") == 0) {
641         Preprocessor_ignore_missing(1);
642         Swig_mark_arg(i);
643       } else if (strcmp(argv[i], "-cpperraswarn") == 0) {
644         Preprocessor_error_as_warning(1);
645         Swig_mark_arg(i);
646       } else if (strcmp(argv[i], "-nocpperraswarn") == 0) {
647         Preprocessor_error_as_warning(0);
648         Swig_mark_arg(i);
649       } else if ((strcmp(argv[i], "-debug-typemap") == 0) || (strcmp(argv[i], "-debug_typemap") == 0) || (strcmp(argv[i], "-tm_debug") == 0)) {
650         tm_debug = 1;
651         Swig_mark_arg(i);
652       } else if (strcmp(argv[i], "-module") == 0) {
653         Swig_mark_arg(i);
654         if (argv[i + 1]) {
655           ModuleName = NewString(argv[i + 1]);
656           Swig_mark_arg(i + 1);
657         } else {
658           Swig_arg_error();
659         }
660       } else if (strcmp(argv[i], "-M") == 0) {
661         depend = 1;
662         depend_only = 1;
663         Swig_mark_arg(i);
664       } else if (strcmp(argv[i], "-MM") == 0) {
665         depend = 2;
666         depend_only = 1;
667         Swig_mark_arg(i);
668       } else if (strcmp(argv[i], "-MF") == 0) {
669         Swig_mark_arg(i);
670         if (argv[i + 1]) {
671           dependencies_file = NewString(argv[i + 1]);
672           Swig_mark_arg(i + 1);
673         } else {
674           Swig_arg_error();
675         }
676       } else if (strcmp(argv[i], "-MD") == 0) {
677         depend = 1;
678         Swig_mark_arg(i);
679       } else if (strcmp(argv[i], "-MMD") == 0) {
680         depend = 2;
681         Swig_mark_arg(i);
682       } else if (strcmp(argv[i], "-MT") == 0) {
683         Swig_mark_arg(i);
684         if (argv[i + 1]) {
685           if (!dependencies_target)
686             dependencies_target = NewString(argv[i + 1]);
687           else
688             Printf(dependencies_target, " %s", argv[i + 1]);
689           Swig_mark_arg(i + 1);
690         } else {
691           Swig_arg_error();
692         }
693       } else if (strcmp(argv[i], "-outdir") == 0) {
694         Swig_mark_arg(i);
695         if (argv[i + 1]) {
696           outdir = NewString(argv[i + 1]);
697           Swig_mark_arg(i + 1);
698         } else {
699           Swig_arg_error();
700         }
701       } else if (strcmp(argv[i], "-outcurrentdir") == 0) {
702         Swig_mark_arg(i);
703         outcurrentdir = 1;
704       } else if (strcmp(argv[i], "-Wall") == 0) {
705         Swig_mark_arg(i);
706         Swig_warnall();
707       } else if (strcmp(argv[i], "-Wallkw") == 0) {
708         allkw = 1;
709         Swig_mark_arg(i);
710       } else if (strcmp(argv[i], "-Werror") == 0) {
711         werror = 1;
712         Swig_mark_arg(i);
713       } else if (strcmp(argv[i], "-Wextra") == 0) {
714         Swig_mark_arg(i);
715         Swig_warnfilter(EXTRA_WARNINGS, 0);
716       } else if (strncmp(argv[i], "-w", 2) == 0) {
717         Swig_mark_arg(i);
718         Swig_warnfilter(argv[i] + 2, 1);
719       } else if ((strcmp(argv[i], "-debug-tags") == 0) || (strcmp(argv[i], "-dump_tags") == 0)) {
720         dump_tags = 1;
721         Swig_mark_arg(i);
722       } else if (strcmp(argv[i], "-debug-top") == 0) {
723         Swig_mark_arg(i);
724         if (argv[i + 1]) {
725           String *dump_list = NewString(argv[i + 1]);
726           dump_top = decode_numbers_list(dump_list);
727           if (dump_top < STAGE1 || dump_top >= STAGEOVERFLOW)
728             Swig_arg_error();
729           else
730             Swig_mark_arg(i + 1);
731           Delete(dump_list);
732         } else {
733           Swig_arg_error();
734         }
735       } else if (strcmp(argv[i], "-debug-module") == 0) {
736         Swig_mark_arg(i);
737         if (argv[i + 1]) {
738           String *dump_list = NewString(argv[i + 1]);
739           dump_module = decode_numbers_list(dump_list);
740           if (dump_module < STAGE1 || dump_module >= STAGEOVERFLOW)
741             Swig_arg_error();
742           else
743             Swig_mark_arg(i + 1);
744           Delete(dump_list);
745         } else {
746           Swig_arg_error();
747         }
748       } else if ((strcmp(argv[i], "-dump_tree") == 0) || (strcmp(argv[i], "-dump_top") == 0)) {
749         dump_top |= STAGE4;
750         Swig_mark_arg(i);
751       } else if (strcmp(argv[i], "-dump_module") == 0) {
752         dump_module |= STAGE4;
753         Swig_mark_arg(i);
754       } else if (strcmp(argv[i], "-dump_parse_module") == 0) {
755         dump_module |= STAGE1;
756         Swig_mark_arg(i);
757       } else if (strcmp(argv[i], "-dump_parse_top") == 0) {
758         dump_top |= STAGE1;
759         Swig_mark_arg(i);
760       } else if (strcmp(argv[i], "-dump_xml") == 0) {
761         dump_xml = 1;
762         Swig_mark_arg(i);
763       } else if (strcmp(argv[i], "-xmlout") == 0) {
764         dump_xml = 1;
765         Swig_mark_arg(i);
766         if (argv[i + 1]) {
767           xmlout = NewString(argv[i + 1]);
768           Swig_mark_arg(i + 1);
769         } else {
770           Swig_arg_error();
771         }
772       } else if (strcmp(argv[i], "-nocontract") == 0) {
773         Swig_mark_arg(i);
774         Swig_contract_mode_set(0);
775       } else if (strcmp(argv[i], "-browse") == 0) {
776         browse = 1;
777         Swig_mark_arg(i);
778       } else if ((strcmp(argv[i], "-debug-typedef") == 0) || (strcmp(argv[i], "-dump_typedef") == 0)) {
779         dump_typedef = 1;
780         Swig_mark_arg(i);
781       } else if ((strcmp(argv[i], "-debug-classes") == 0) || (strcmp(argv[i], "-dump_classes") == 0)) {
782         dump_classes = 1;
783         Swig_mark_arg(i);
784       } else if ((strcmp(argv[i], "-debug-memory") == 0) || (strcmp(argv[i], "-dump_memory") == 0)) {
785         memory_debug = 1;
786         Swig_mark_arg(i);
787       } else if (strcmp(argv[i], "-Fstandard") == 0) {
788         Swig_error_msg_format(EMF_STANDARD);
789         Swig_mark_arg(i);
790       } else if (strcmp(argv[i], "-Fmicrosoft") == 0) {
791         Swig_error_msg_format(EMF_MICROSOFT);
792         Swig_mark_arg(i);
793       } else if (strcmp(argv[i], "-O") == 0) {
794         Wrapper_virtual_elimination_mode_set(1);
795         Wrapper_fast_dispatch_mode_set(1);
796         Swig_mark_arg(i);
797       } else if (strcmp(argv[i], "-help") == 0) {
798         fputs(usage1, stdout);
799         fputs(usage2, stdout);
800         fputs(usage3, stdout);
801         Swig_mark_arg(i);
802         help = 1;
803       }
804     }
805   }
806 }
807
808
809
810
811
812 int SWIG_main(int argc, char *argv[], Language *l) {
813   char *c;
814   extern void Swig_print_xml(Node *obj, String *filename);
815
816   /* Initialize the SWIG core */
817   Swig_init();
818
819   // Default warning suppression
820   Swig_warnfilter(EXTRA_WARNINGS, 1);
821
822   // Initialize the preprocessor
823   Preprocessor_init();
824
825   lang = l;
826
827   // Set up some default symbols (available in both SWIG interface files
828   // and C files)
829
830   Preprocessor_define((DOH *) "SWIG 1", 0);
831   Preprocessor_define((DOH *) "__STDC__", 0);
832 #ifdef MACSWIG
833   Preprocessor_define((DOH *) "SWIGMAC 1", 0);
834 #endif
835 #ifdef SWIGWIN32
836   Preprocessor_define((DOH *) "SWIGWIN32 1", 0);
837 #endif
838
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");
843   int count = 0;
844   while (token) {
845     int len = strlen(token);
846     assert(len == 1 || len == 2);
847     Printf(vers, "%s%s", (len == 1) ? "0" : "", token);
848     token = strtok(NULL, ".");
849     count++;
850   }
851   Delete(package_version);
852   assert(count == 3);           // Check version format is correct
853
854   /* Turn on contracts */
855
856   Swig_contract_mode_set(1);
857   Preprocessor_define(vers, 0);
858
859   /* Turn off directors mode */
860   Wrapper_director_mode_set(0);
861   Wrapper_director_protected_mode_set(1);
862
863   // Create Library search directories
864
865   // Check for SWIG_LIB environment variable
866   if ((c = getenv("SWIG_LIB")) == (char *) 0) {
867 #if defined(_WIN32)
868     char buf[MAX_PATH];
869     char *p;
870     if (!(GetModuleFileName(0, buf, MAX_PATH) == 0 || (p = strrchr(buf, '\\')) == 0)) {
871       *(p + 1) = '\0';
872       SwigLibWin = NewStringf("%sLib", buf);    // Native windows installation path
873     }
874     SwigLib = Swig_copy_string(SWIG_LIB_WIN_UNIX);      // Unix installation path using a drive letter (for msys/mingw)
875 #else
876     SwigLib = Swig_copy_string(SWIG_LIB);
877 #endif
878   } else {
879     SwigLib = Swig_copy_string(c);
880   }
881
882   libfiles = NewList();
883   all_output_files = NewList();
884
885   /* Check for SWIG_FEATURES environment variable */
886
887   SWIG_getoptions(argc, argv);
888
889   // Define the __cplusplus symbol
890   if (CPlusPlus)
891     Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
892
893   // Parse language dependent options
894   lang->main(argc, argv);
895
896   if (help) {
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
899   }
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);
903
904   install_opts(argc, argv);
905
906   // Add language dependent directory to the search path
907   {
908     String *rl = NewString("");
909     Printf(rl, ".%sswig_lib%s%s", SWIG_FILE_DELIMITER, SWIG_FILE_DELIMITER, LangSubDir);
910     Swig_add_directory(rl);
911     if (SwigLibWin) {
912       rl = NewString("");
913       Printf(rl, "%s%s%s", SwigLibWin, SWIG_FILE_DELIMITER, LangSubDir);
914       Swig_add_directory(rl);
915     }
916     rl = NewString("");
917     Printf(rl, "%s%s%s", SwigLib, SWIG_FILE_DELIMITER, LangSubDir);
918     Swig_add_directory(rl);
919   }
920
921   Swig_add_directory((String *) "." SWIG_FILE_DELIMITER "swig_lib");
922   if (SwigLibWin)
923     Swig_add_directory((String *) SwigLibWin);
924   Swig_add_directory((String *) SwigLib);
925
926   if (Verbose) {
927     printf("LangSubDir: %s\n", Char(LangSubDir));
928     printf("Search paths:\n");
929     List *sp = Swig_search_path();
930     Iterator s;
931     for (s = First(sp); s.item; s = Next(s)) {
932       Printf(stdout, "   %s\n", s.item);
933     }
934   }
935   // handle the -external-runtime argument
936   if (external_runtime)
937     SWIG_dump_runtime();
938
939   // If we made it this far, looks good. go for it....
940
941   input_file = NewString(argv[argc - 1]);
942   Swig_filename_correct(input_file);
943
944   // If the user has requested to check out a file, handle that
945   if (checkout) {
946     DOH *s;
947     char *outfile = Char(input_file);
948     if (outfile_name)
949       outfile = outfile_name;
950
951     if (Verbose)
952       printf("Handling checkout...\n");
953
954     s = Swig_include(input_file);
955     if (!s) {
956       Printf(stderr, "Unable to locate '%s' in the SWIG library.\n", input_file);
957     } else {
958       FILE *f = Swig_open(outfile);
959       if (f) {
960         fclose(f);
961         Printf(stderr, "File '%s' already exists. Checkout aborted.\n", outfile);
962       } else {
963         File *f_outfile = NewFile(outfile, "w", SWIG_output_files());
964         if (!f_outfile) {
965           FileErrorDisplay(outfile);
966           SWIG_exit(EXIT_FAILURE);
967         } else {
968           if (Verbose)
969             Printf(stdout, "'%s' checked out from the SWIG library.\n", outfile);
970           Printv(f_outfile, s, NIL);
971           Close(f_outfile);
972         }
973       }
974     }
975   } else {
976     // Run the preprocessor
977     if (Verbose)
978       printf("Preprocessing...\n");
979
980     {
981       int i;
982       String *fs = NewString("");
983       FILE *df = Swig_open(input_file);
984       if (!df) {
985         df = Swig_include_open(input_file);
986         if (!df) {
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");
991           } else {
992             Printf(stderr, "Unable to find file '%s'.\n", input_file);
993           }
994           SWIG_exit(EXIT_FAILURE);
995         } else {
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
997         }
998       }
999       if (!no_cpp) {
1000         fclose(df);
1001         Printf(fs, "%%include <swig.swg>\n");
1002         if (allkw) {
1003           Printf(fs, "%%include <allkw.swg>\n");
1004         }
1005         if (lang_config) {
1006           Printf(fs, "\n%%include <%s>\n", lang_config);
1007         }
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));
1011         }
1012         Seek(fs, 0, SEEK_SET);
1013         cpps = Preprocessor_parse(fs);
1014         Delete(fs);
1015       } else {
1016         cpps = Swig_read_file(df);
1017         fclose(df);
1018       }
1019       if (Swig_error_count()) {
1020         SWIG_exit(EXIT_FAILURE);
1021       }
1022       if (cpp_only) {
1023         Printf(stdout, "%s", cpps);
1024         SWIG_exit(EXIT_SUCCESS);
1025       }
1026       if (depend) {
1027         if (!no_cpp) {
1028           String *outfile;
1029
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);
1034             } else {
1035               outfile = NewStringf("%s_wrap.c", basename);
1036             }
1037           } else {
1038             outfile = NewString(outfile_name);
1039           }
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);
1045             }
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);
1052             }
1053           } else
1054             f_dependencies_file = stdout;
1055           if (dependencies_target) {
1056             Printf(f_dependencies_file, "%s: ", dependencies_target);
1057           } else {
1058             Printf(f_dependencies_file, "%s: ", outfile);
1059           }
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));
1064             }
1065           }
1066           Printf(f_dependencies_file, "\n");
1067           if (f_dependencies_file != stdout)
1068             Close(f_dependencies_file);
1069           if (depend_only)
1070             SWIG_exit(EXIT_SUCCESS);
1071         } else {
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);
1075         }
1076       }
1077       Seek(cpps, 0, SEEK_SET);
1078     }
1079
1080     /* Register a null file with the file handler */
1081     Swig_register_filebyname("null", NewString(""));
1082
1083     // Pass control over to the specific language interpreter
1084     if (Verbose) {
1085       fprintf(stdout, "Starting language-specific parse...\n");
1086       fflush(stdout);
1087     }
1088
1089     Node *top = Swig_cparse(cpps);
1090
1091     if (dump_top & STAGE1) {
1092       Printf(stdout, "debug-top stage 1\n");
1093       Swig_print_tree(top);
1094     }
1095     if (dump_module & STAGE1) {
1096       Printf(stdout, "debug-module stage 1\n");
1097       Swig_print_tree(Getattr(top, "module"));
1098     }
1099
1100     if (Verbose) {
1101       Printf(stdout, "Processing types...\n");
1102     }
1103     Swig_process_types(top);
1104
1105     if (dump_top & STAGE2) {
1106       Printf(stdout, "debug-top stage 2\n");
1107       Swig_print_tree(top);
1108     }
1109     if (dump_module & STAGE2) {
1110       Printf(stdout, "debug-module stage 2\n");
1111       Swig_print_tree(Getattr(top, "module"));
1112     }
1113
1114     if (Verbose) {
1115       Printf(stdout, "C++ analysis...\n");
1116     }
1117     Swig_default_allocators(top);
1118
1119     if (dump_top & STAGE3) {
1120       Printf(stdout, "debug-top stage 3\n");
1121       Swig_print_tree(top);
1122     }
1123     if (dump_module & STAGE3) {
1124       Printf(stdout, "debug-module stage 3\n");
1125       Swig_print_tree(Getattr(top, "module"));
1126     }
1127
1128     if (Verbose) {
1129       Printf(stdout, "Generating wrappers...\n");
1130     }
1131
1132     if (dump_classes) {
1133       Hash *classes = Getattr(top, "classes");
1134       if (classes) {
1135         Printf(stdout, "Classes\n");
1136         Printf(stdout, "------------\n");
1137         Iterator ki;
1138         for (ki = First(classes); ki.key; ki = Next(ki)) {
1139           Printf(stdout, "%s\n", ki.key);
1140         }
1141       }
1142     }
1143
1144     if (dump_typedef) {
1145       SwigType_print_scope(0);
1146     }
1147
1148     if (dump_tags) {
1149       Swig_print_tags(top, 0);
1150     }
1151     if (top) {
1152       if (!Getattr(top, "name")) {
1153         Printf(stderr, "No module name specified using %%module or -module.\n");
1154         SWIG_exit(EXIT_FAILURE);
1155       } else {
1156         /* Set some filename information on the object */
1157         String *infile = scanner_get_main_input_file();
1158         if (!infile) {
1159           Printf(stderr, "Missing input file in preprocessed output.\n");
1160           SWIG_exit(EXIT_FAILURE);
1161         }
1162         Setattr(top, "infile", infile); // Note: if nopreprocess then infile is the original input file, otherwise input_file
1163         Setattr(top, "inputfile", input_file);
1164
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));
1169           } else {
1170             Setattr(top, "outfile", NewStringf("%s_wrap.c", basename));
1171           }
1172         } else {
1173           Setattr(top, "outfile", outfile_name);
1174         }
1175         if (!outfile_name_h) {
1176           Setattr(top, "outfile_h", NewStringf("%s_wrap.%s", basename, hpp_extension));
1177         } else {
1178           Setattr(top, "outfile_h", outfile_name_h);
1179         }
1180         set_outdir(Swig_file_dirname(Getattr(top, "outfile")));
1181         if (Swig_contract_mode_get()) {
1182           Swig_contracts(top);
1183         }
1184
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);
1187
1188         lang->top(top);
1189
1190         if (browse) {
1191           Swig_browser(top, 0);
1192         }
1193       }
1194     }
1195     if (dump_top & STAGE4) {
1196       Printf(stdout, "debug-top stage 4\n");
1197       Swig_print_tree(top);
1198     }
1199     if (dump_module & STAGE4) {
1200       Printf(stdout, "debug-module stage 4\n");
1201       Swig_print_tree(Getattr(top, "module"));
1202     }
1203     if (dump_xml && top) {
1204       Swig_print_xml(top, xmlout);
1205     }
1206     Delete(top);
1207   }
1208   if (tm_debug)
1209     Swig_typemap_debug();
1210   if (memory_debug)
1211     DohMemoryDebug();
1212
1213   char *outfiles = getenv("CCACHE_OUTFILES");
1214   if (outfiles) {
1215     File *f_outfiles = NewFile(outfiles, "w", 0);
1216     if (!f_outfiles) {
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);
1220     } else {
1221       int i;
1222       for (i = 0; i < Len(all_output_files); i++)
1223         Printf(f_outfiles, "%s\n", Getitem(all_output_files, i));
1224       Close(f_outfiles);
1225     }
1226   }
1227
1228   // Deletes
1229   Delete(libfiles);
1230   Preprocessor_delete();
1231
1232   while (freeze) {
1233   }
1234
1235   if ((werror) && (Swig_warn_count())) {
1236     return Swig_warn_count();
1237   }
1238   return Swig_error_count();
1239 }
1240
1241 // --------------------------------------------------------------------------
1242 // SWIG_exit(int exit_code)
1243 //
1244 // Cleanup and either freeze or exit
1245 // --------------------------------------------------------------------------
1246
1247 void SWIG_exit(int exit_code) {
1248   while (freeze) {
1249   }
1250   exit(exit_code);
1251 }