7
7
* Main entry point to the SWIG core.
8
8
* ----------------------------------------------------------------------------- */
10
char cvsroot_main_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/main.cxx,v 1.93 2006/11/15 23:45:47 wsfulton Exp $";
10
char cvsroot_main_cxx[] = "$Id: main.cxx 10095 2007-11-09 08:59:44Z olly $";
12
12
#include "swigconfig.h"
35
36
int SwigRuntime = 0; // 0 = no option, 1 = -c or -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"
39
49
extern String *ModuleName;
42
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 */
43
55
static const char *usage1 = (const char *) "\
44
56
\nGeneral Options\n\
45
57
-addextern - Add extra extern declarations\n\
48
60
-copyctor - Automatically generate copy constructors wherever possible\n\
49
61
-cpperraswarn - Treat the preprocessor #error statement as #warning (default)\n\
50
62
-copyright - Display copyright notices\n\
51
-debug_template - Display information for debugging templates\n\
52
-debug_typemap - Display information for debugging typemaps\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\
53
70
-directors - Turn on director mode for all the classes, mainly for testing\n\
54
71
-dirprot - Turn on wrapping of protected members for director classes (default)\n\
55
72
-D<symbol> - Define a symbol <symbol> (for conditional compilation)\n\
56
-dump_classes - Display information about the classes found in the interface\n\
57
-dump_module - Display information on the module node tree avoiding system nodes\n\
58
-dump_parse_module - Display information on the module node tree after parsing avoiding system nodes\n\
59
-dump_parse_top - Display information on the node tree after parsing including system nodes\n\
60
-dump_tags - Display information about the tags found in the interface\n\
61
-dump_top - Display information on the entire node tree including system nodes\n\
62
-dump_typedef - Display information about the types and typedefs in the interface\n\
63
73
-E - Preprocess only, does not generate wrapper code\n\
64
74
-external-runtime [file] - Export the SWIG runtime stack\n\
65
75
-fakeversion <v>- Make SWIG fake the program version number to <v>\n\
81
91
-importall - Follow all #include statements as imports\n\
82
92
-includeall - Follow all #include statements\n\
83
93
-l<ifile> - Include SWIG library file <ifile>\n\
94
-macroerrors - Report errors inside macros\n\
84
95
-makedefault - Create default constructors/destructors (the default)\n\
85
96
-M - List all dependencies\n\
86
97
-MD - Is equivalent to `-M -MF <file>', except `-E' is not implied\n\
102
113
static const char *usage3 = (const char *) "\
103
114
-notemplatereduce - Disable reduction of the typedefs in templates\n\
104
-O - Enable the optimizations options: \n\
115
-O - Enable the optimization options: \n\
105
116
-fastdispatch -fvirtual \n\
106
117
-o <outfile> - Set name of the output file to <outfile>\n\
107
118
-oh <headfile> - Set name of the output header file to <headfile>\n\
111
122
-templatereduce - Reduce all the typedefs in templates\n\
112
123
-v - Run in verbose mode\n\
113
124
-version - Display SWIG version number\n\
114
-Wall - Enable all warning messages\n\
125
-Wall - Remove all warning suppression, also implies -Wextra\n\
115
126
-Wallkw - Enable keyword warnings for all the supported languages\n\
116
127
-Werror - Treat warnings as errors\n\
128
-Wextra - Adds the following additional warnings: " EXTRA_WARNINGS "\n\
117
129
-w<list> - Suppress/add warning messages, eg -w401,+321 - see Warnings.html\n\
118
130
-xmlout <file> - Write XML version of the parse tree to <file> after normal processing\n\
120
132
Options can also be defined using the SWIG_FEATURES environment variable, for example:\n\
122
134
$ SWIG_FEATURES=\"-Wall\"\n\
123
$ swig -python interface.i \n\
135
$ export SWIG_FEATURES\n\
136
$ swig -python interface.i\n\
125
138
is equivalent to: \n\
147
160
static char *outfile_name_h = 0;
148
161
static int tm_debug = 0;
149
162
static int dump_tags = 0;
163
static int dump_module = 0;
150
164
static int dump_top = 0;
151
static int dump_module = 0;
152
static int dump_parse_module = 0;
153
static int dump_parse_top = 0;
154
165
static int dump_xml = 0;
155
166
static int browse = 0;
156
167
static int dump_typedef = 0;
166
177
static File *f_dependencies_file = 0;
167
178
static int external_runtime = 0;
168
179
static String *external_runtime_name = 0;
180
enum { STAGE1=1, STAGE2=2, STAGE3=4, STAGE4=8, STAGEOVERFLOW=16 };
170
182
// -----------------------------------------------------------------------------
171
183
// check_suffix(char *name)
173
185
// Checks the suffix of a file to see if we should emit extern declarations.
174
186
// -----------------------------------------------------------------------------
176
static int check_suffix(char *name) {
188
static int check_suffix(const char *name) {
180
192
c = Swig_file_suffix(name);
227
239
// -----------------------------------------------------------------------------
240
// decode_numbers_list(String *numlist)
241
// Decode comma separated list into a binary number of the inputs or'd together
242
// eg list="1,4" will return (2^0 || 2^3) = 0x1001
243
// -----------------------------------------------------------------------------
245
static unsigned int decode_numbers_list(String *numlist) {
246
unsigned int decoded_number = 0;
248
List *numbers = Split(numlist, ',', INT_MAX);
249
if (numbers && Len(numbers) > 0) {
250
for (Iterator it = First(numbers); it.item; it = Next(it)) {
251
String *numstring = it.item;
252
// TODO: check that it is a number
253
int number = atoi(Char(numstring));
254
if (number > 0 && number <= 16) {
255
decoded_number |= (1 << (number-1));
260
return decoded_number;
263
// -----------------------------------------------------------------------------
228
264
// Sets the output directory for language specific (proxy) files if not set and
229
265
// adds trailing file separator if necessary.
230
266
// -----------------------------------------------------------------------------
234
270
// Add file delimiter if not present in output directory name
235
271
if (outdir && Len(outdir) != 0) {
236
272
const char *outd = Char(outdir);
237
if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMETER), SWIG_FILE_DELIMETER) != 0)
238
Printv(outdir, SWIG_FILE_DELIMETER, NIL);
273
if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMITER), SWIG_FILE_DELIMITER) != 0)
274
Printv(outdir, SWIG_FILE_DELIMITER, NIL);
240
276
// Use the C wrapper file's directory if the output directory has not been set by user
396
432
Swig_mark_arg(i);
397
433
} else if (strncmp(argv[i], "-I", 2) == 0) {
398
434
// Add a new directory search path
399
Swig_add_directory((DOH *) Swig_copy_string(argv[i] + 2));
435
char *a = Swig_copy_string(argv[i] + 2);
436
Swig_add_directory((DOH *) a);
400
438
Swig_mark_arg(i);
401
439
} else if (strncmp(argv[i], "-D", 2) == 0) {
402
440
String *d = NewString(argv[i] + 2);
493
531
} else if (strcmp(argv[i], "-addextern") == 0) {
495
533
Swig_mark_arg(i);
496
} else if ((strcmp(argv[i], "-show_templates") == 0) || (strcmp(argv[i], "-debug_template") == 0)) {
534
} else if ((strcmp(argv[i], "-debug-template") == 0) || (strcmp(argv[i], "-debug_template") == 0) || (strcmp(argv[i], "-show_templates") == 0)) {
497
535
Swig_cparse_debug_templates(1);
498
536
Swig_mark_arg(i);
499
537
} else if (strcmp(argv[i], "-templatereduce") == 0) {
502
540
} else if (strcmp(argv[i], "-notemplatereduce") == 0) {
503
541
SWIG_cparse_template_reduce(0);
504
542
Swig_mark_arg(i);
543
} else if (strcmp(argv[i], "-macroerrors") == 0) {
544
Swig_cparse_follow_locators(1);
505
546
} else if (strcmp(argv[i], "-swiglib") == 0) {
507
548
printf("%s\n", Char(SwigLibWin));
593
634
} else if (strcmp(argv[i], "-nocpperraswarn") == 0) {
594
635
Preprocessor_error_as_warning(0);
595
636
Swig_mark_arg(i);
596
} else if ((strcmp(argv[i], "-tm_debug") == 0) || (strcmp(argv[i], "-debug_typemap") == 0)) {
637
} else if ((strcmp(argv[i], "-debug-typemap") == 0) || (strcmp(argv[i], "-debug_typemap") == 0) || (strcmp(argv[i], "-tm_debug") == 0)) {
598
639
Swig_mark_arg(i);
599
640
} else if (strcmp(argv[i], "-module") == 0) {
643
684
} else if (strcmp(argv[i], "-Werror") == 0) {
645
686
Swig_mark_arg(i);
687
} else if (strcmp(argv[i], "-Wextra") == 0) {
689
Swig_warnfilter(EXTRA_WARNINGS, 0);
646
690
} else if (strncmp(argv[i], "-w", 2) == 0) {
647
691
Swig_mark_arg(i);
648
692
Swig_warnfilter(argv[i] + 2, 1);
649
} else if (strcmp(argv[i], "-dump_tags") == 0) {
693
} else if ((strcmp(argv[i], "-debug-tags") == 0) || (strcmp(argv[i], "-dump_tags") == 0)) {
651
695
Swig_mark_arg(i);
696
} else if (strcmp(argv[i], "-debug-top") == 0) {
699
String *dump_list = NewString(argv[i + 1]);
700
dump_top = decode_numbers_list(dump_list);
701
if (dump_top < STAGE1 || dump_top >= STAGEOVERFLOW)
704
Swig_mark_arg(i + 1);
709
} else if (strcmp(argv[i], "-debug-module") == 0) {
712
String *dump_list = NewString(argv[i + 1]);
713
dump_module = decode_numbers_list(dump_list);
714
if (dump_module < STAGE1 || dump_module >= STAGEOVERFLOW)
717
Swig_mark_arg(i + 1);
652
722
} else if ((strcmp(argv[i], "-dump_tree") == 0) || (strcmp(argv[i], "-dump_top") == 0)) {
654
724
Swig_mark_arg(i);
655
725
} else if (strcmp(argv[i], "-dump_module") == 0) {
726
dump_module |= STAGE4;
657
727
Swig_mark_arg(i);
658
728
} else if (strcmp(argv[i], "-dump_parse_module") == 0) {
659
dump_parse_module = 1;
729
dump_module |= STAGE1;
660
730
Swig_mark_arg(i);
661
731
} else if (strcmp(argv[i], "-dump_parse_top") == 0) {
663
733
Swig_mark_arg(i);
664
734
} else if (strcmp(argv[i], "-dump_xml") == 0) {
679
749
} else if (strcmp(argv[i], "-browse") == 0) {
681
751
Swig_mark_arg(i);
682
} else if (strcmp(argv[i], "-dump_typedef") == 0) {
752
} else if ((strcmp(argv[i], "-debug-typedef") == 0) || (strcmp(argv[i], "-dump_typedef") == 0)) {
683
753
dump_typedef = 1;
684
754
Swig_mark_arg(i);
685
} else if (strcmp(argv[i], "-dump_classes") == 0) {
755
} else if ((strcmp(argv[i], "-debug-classes") == 0) || (strcmp(argv[i], "-dump_classes") == 0)) {
686
756
dump_classes = 1;
687
757
Swig_mark_arg(i);
688
} else if (strcmp(argv[i], "-dump_memory") == 0) {
758
} else if ((strcmp(argv[i], "-debug-memory") == 0) || (strcmp(argv[i], "-dump_memory") == 0)) {
689
759
memory_debug = 1;
690
760
Swig_mark_arg(i);
691
761
} else if (strcmp(argv[i], "-Fstandard") == 0) {
716
786
int SWIG_main(int argc, char *argv[], Language *l) {
788
extern void Swig_print_xml(Node *obj, String *filename);
719
790
/* Initialize the SWIG core */
722
/* Suppress warning messages for private inheritance, preprocessor
723
evaluation, might be abstract, overloaded const, and ...
725
WARN_PP_EVALUATION 202
726
WARN_PARSE_PRIVATE_INHERIT 309
727
WARN_TYPE_ABSTRACT 403
728
WARN_LANG_OVERLOAD_CONST 512
729
WARN_PARSE_BUILTIN_NAME 321
730
WARN_PARSE_REDUNDANT 322
732
Swig_warnfilter("202,309,403,512,321,322", 1);
793
// Default warning suppression
794
Swig_warnfilter(EXTRA_WARNINGS, 1);
734
796
// Initialize the preprocessor
735
797
Preprocessor_init();
817
879
// Add language dependent directory to the search path
819
881
String *rl = NewString("");
820
Printf(rl, ".%sswig_lib%s%s", SWIG_FILE_DELIMETER, SWIG_FILE_DELIMETER, LangSubDir);
882
Printf(rl, ".%sswig_lib%s%s", SWIG_FILE_DELIMITER, SWIG_FILE_DELIMITER, LangSubDir);
821
883
Swig_add_directory(rl);
822
884
if (SwigLibWin) {
823
885
rl = NewString("");
824
Printf(rl, "%s%s%s", SwigLibWin, SWIG_FILE_DELIMETER, LangSubDir);
886
Printf(rl, "%s%s%s", SwigLibWin, SWIG_FILE_DELIMITER, LangSubDir);
825
887
Swig_add_directory(rl);
827
889
rl = NewString("");
828
Printf(rl, "%s%s%s", SwigLib, SWIG_FILE_DELIMETER, LangSubDir);
890
Printf(rl, "%s%s%s", SwigLib, SWIG_FILE_DELIMITER, LangSubDir);
829
891
Swig_add_directory(rl);
832
Swig_add_directory((String *) "." SWIG_FILE_DELIMETER "swig_lib");
894
Swig_add_directory((String *) "." SWIG_FILE_DELIMITER "swig_lib");
834
896
Swig_add_directory((String *) SwigLibWin);
835
897
Swig_add_directory((String *) SwigLib);
898
961
char *cfile = Char(input_file);
899
962
if (cfile && cfile[0] == '-') {
900
963
Printf(stderr, "Unable to find option or file '%s', ", input_file);
901
Printf(stderr, "use 'swig -help' for more information.\n", input_file);
964
Printf(stderr, "use 'swig -help' for more information.\n");
903
966
Printf(stderr, "Unable to find file '%s'.\n", input_file);
986
1049
Node *top = Swig_cparse(cpps);
988
if (dump_parse_top) {
1051
if (dump_top & STAGE1) {
1052
Printf(stdout, "debug-top stage 1\n");
989
1053
Swig_print_tree(top);
991
if (dump_parse_module) {
1055
if (dump_module & STAGE1) {
1056
Printf(stdout, "debug-module stage 1\n");
992
1057
Swig_print_tree(Getattr(top, "module"));
998
1063
Swig_process_types(top);
1065
if (dump_top & STAGE2) {
1066
Printf(stdout, "debug-top stage 2\n");
1067
Swig_print_tree(top);
1069
if (dump_module & STAGE2) {
1070
Printf(stdout, "debug-module stage 2\n");
1071
Swig_print_tree(Getattr(top, "module"));
1001
1075
Printf(stdout, "C++ analysis...\n");
1003
1077
Swig_default_allocators(top);
1079
if (dump_top & STAGE3) {
1080
Printf(stdout, "debug-top stage 3\n");
1081
Swig_print_tree(top);
1083
if (dump_module & STAGE3) {
1084
Printf(stdout, "debug-module stage 3\n");
1085
Swig_print_tree(Getattr(top, "module"));
1006
1089
Printf(stdout, "Generating wrappers...\n");
1142
if (dump_top & STAGE4) {
1143
Printf(stdout, "debug-top stage 4\n");
1060
1144
Swig_print_tree(top);
1146
if (dump_module & STAGE4) {
1147
Printf(stdout, "debug-module stage 4\n");
1063
1148
Swig_print_tree(Getattr(top, "module"));
1150
if (dump_xml && top) {
1066
1151
Swig_print_xml(top, xmlout);