~ubuntu-branches/ubuntu/oneiric/swig1.3/oneiric

« back to all changes in this revision

Viewing changes to Source/Modules/main.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-06 10:27:08 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20071206102708-t37t62i45n595w0e
Tags: 1.3.33-2ubuntu1
* Merge with Debian; remaining changes:
  - Drop support for pike.
  - Use python2.5 instead of python2.4.
  - Clean Runtime/ as well.
  - Force a few environment variables.
* debian/Rules (clean): Remove Lib/ocaml/swigp4.ml.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 * Main entry point to the SWIG core.
8
8
 * ----------------------------------------------------------------------------- */
9
9
 
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 $";
11
11
 
12
12
#include "swigconfig.h"
13
13
 
21
21
#include "swigwarn.h"
22
22
#include "cparse.h"
23
23
#include <ctype.h>
 
24
#include <limits.h>             // for INT_MAX
24
25
 
25
26
// Global variables
26
27
 
34
35
int NoExcept = 0;
35
36
int SwigRuntime = 0;            // 0 = no option, 1 = -c or -runtime, 2 = -noruntime
36
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"
37
47
 
38
48
extern "C" {
39
49
  extern String *ModuleName;
40
50
}
41
51
 
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\
101
112
 
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\
119
131
\n\
120
132
Options can also be defined using the SWIG_FEATURES environment variable, for example:\n\
121
133
\n\
122
134
  $ SWIG_FEATURES=\"-Wall\"\n\
123
 
  $ swig -python interface.i \n\
 
135
  $ export SWIG_FEATURES\n\
 
136
  $ swig -python interface.i\n\
124
137
\n\
125
138
is equivalent to: \n\
126
139
\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 };
169
181
 
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
// -----------------------------------------------------------------------------
175
187
 
176
 
static int check_suffix(char *name) {
177
 
  char *c;
 
188
static int check_suffix(const char *name) {
 
189
  const char *c;
178
190
  if (!name)
179
191
    return 0;
180
192
  c = Swig_file_suffix(name);
225
237
}
226
238
 
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
// ----------------------------------------------------------------------------- 
 
244
 
 
245
static unsigned int decode_numbers_list(String *numlist) {
 
246
  unsigned int decoded_number = 0;
 
247
  if (numlist) {
 
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));
 
256
        }
 
257
      }
 
258
    }
 
259
  }
 
260
  return decoded_number;
 
261
}
 
262
 
 
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);
239
275
  }
240
276
  // Use the C wrapper file's directory if the output directory has not been set by user
241
277
  if (!outdir)
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);
 
437
        free(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) {
494
532
        AddExtern = 1;
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);
 
545
        Swig_mark_arg(i);
505
546
      } else if (strcmp(argv[i], "-swiglib") == 0) {
506
547
        if (SwigLibWin)
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)) {
597
638
        tm_debug = 1;
598
639
        Swig_mark_arg(i);
599
640
      } else if (strcmp(argv[i], "-module") == 0) {
643
684
      } else if (strcmp(argv[i], "-Werror") == 0) {
644
685
        werror = 1;
645
686
        Swig_mark_arg(i);
 
687
      } else if (strcmp(argv[i], "-Wextra") == 0) {
 
688
        Swig_mark_arg(i);
 
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)) {
650
694
        dump_tags = 1;
651
695
        Swig_mark_arg(i);
 
696
      } else if (strcmp(argv[i], "-debug-top") == 0) {
 
697
        Swig_mark_arg(i);
 
698
        if (argv[i + 1]) {
 
699
          String *dump_list = NewString(argv[i + 1]);
 
700
          dump_top = decode_numbers_list(dump_list);
 
701
          if (dump_top < STAGE1 || dump_top >= STAGEOVERFLOW)
 
702
            Swig_arg_error();
 
703
          else
 
704
            Swig_mark_arg(i + 1);
 
705
          Delete(dump_list);
 
706
        } else {
 
707
          Swig_arg_error();
 
708
        }
 
709
      } else if (strcmp(argv[i], "-debug-module") == 0) {
 
710
        Swig_mark_arg(i);
 
711
        if (argv[i + 1]) {
 
712
          String *dump_list = NewString(argv[i + 1]);
 
713
          dump_module = decode_numbers_list(dump_list);
 
714
          if (dump_module < STAGE1 || dump_module >= STAGEOVERFLOW)
 
715
            Swig_arg_error();
 
716
          else
 
717
            Swig_mark_arg(i + 1);
 
718
          Delete(dump_list);
 
719
        } else {
 
720
          Swig_arg_error();
 
721
        }
652
722
      } else if ((strcmp(argv[i], "-dump_tree") == 0) || (strcmp(argv[i], "-dump_top") == 0)) {
653
 
        dump_top = 1;
 
723
        dump_top |= STAGE4;
654
724
        Swig_mark_arg(i);
655
725
      } else if (strcmp(argv[i], "-dump_module") == 0) {
656
 
        dump_module = 1;
 
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) {
662
 
        dump_parse_top = 1;
 
732
        dump_top |= STAGE1;
663
733
        Swig_mark_arg(i);
664
734
      } else if (strcmp(argv[i], "-dump_xml") == 0) {
665
735
        dump_xml = 1;
679
749
      } else if (strcmp(argv[i], "-browse") == 0) {
680
750
        browse = 1;
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) {
715
785
 
716
786
int SWIG_main(int argc, char *argv[], Language *l) {
717
787
  char *c;
 
788
  extern void Swig_print_xml(Node *obj, String *filename);
718
789
 
719
790
  /* Initialize the SWIG core */
720
791
  Swig_init();
721
792
 
722
 
  /* Suppress warning messages for private inheritance, preprocessor
723
 
     evaluation, might be abstract, overloaded const, and ...
724
 
 
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
731
 
   */
732
 
  Swig_warnfilter("202,309,403,512,321,322", 1);
 
793
  // Default warning suppression
 
794
  Swig_warnfilter(EXTRA_WARNINGS, 1);
733
795
 
734
796
  // Initialize the preprocessor
735
797
  Preprocessor_init();
817
879
  // Add language dependent directory to the search path
818
880
  {
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);
826
888
    }
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);
830
892
  }
831
893
 
832
 
  Swig_add_directory((String *) "." SWIG_FILE_DELIMETER "swig_lib");
 
894
  Swig_add_directory((String *) "." SWIG_FILE_DELIMITER "swig_lib");
833
895
  if (SwigLibWin)
834
896
    Swig_add_directory((String *) SwigLibWin);
835
897
  Swig_add_directory((String *) SwigLib);
890
952
    // Run the preprocessor
891
953
    if (Verbose)
892
954
      printf("Preprocessing...\n");
 
955
 
893
956
    {
894
957
      int i;
895
958
      String *fs = NewString("");
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");
902
965
        } else {
903
966
          Printf(stderr, "Unable to find file '%s'.\n", input_file);
904
967
        }
985
1048
 
986
1049
    Node *top = Swig_cparse(cpps);
987
1050
 
988
 
    if (dump_parse_top) {
 
1051
    if (dump_top & STAGE1) {
 
1052
      Printf(stdout, "debug-top stage 1\n");
989
1053
      Swig_print_tree(top);
990
1054
    }
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"));
993
1058
    }
994
1059
 
997
1062
    }
998
1063
    Swig_process_types(top);
999
1064
 
 
1065
    if (dump_top & STAGE2) {
 
1066
      Printf(stdout, "debug-top stage 2\n");
 
1067
      Swig_print_tree(top);
 
1068
    }
 
1069
    if (dump_module & STAGE2) {
 
1070
      Printf(stdout, "debug-module stage 2\n");
 
1071
      Swig_print_tree(Getattr(top, "module"));
 
1072
    }
 
1073
 
1000
1074
    if (Verbose) {
1001
1075
      Printf(stdout, "C++ analysis...\n");
1002
1076
    }
1003
1077
    Swig_default_allocators(top);
1004
1078
 
 
1079
    if (dump_top & STAGE3) {
 
1080
      Printf(stdout, "debug-top stage 3\n");
 
1081
      Swig_print_tree(top);
 
1082
    }
 
1083
    if (dump_module & STAGE3) {
 
1084
      Printf(stdout, "debug-module stage 3\n");
 
1085
      Swig_print_tree(Getattr(top, "module"));
 
1086
    }
 
1087
 
1005
1088
    if (Verbose) {
1006
1089
      Printf(stdout, "Generating wrappers...\n");
1007
1090
    }
1056
1139
        }
1057
1140
      }
1058
1141
    }
1059
 
    if (dump_top) {
 
1142
    if (dump_top & STAGE4) {
 
1143
      Printf(stdout, "debug-top stage 4\n");
1060
1144
      Swig_print_tree(top);
1061
1145
    }
1062
 
    if (dump_module) {
 
1146
    if (dump_module & STAGE4) {
 
1147
      Printf(stdout, "debug-module stage 4\n");
1063
1148
      Swig_print_tree(Getattr(top, "module"));
1064
1149
    }
1065
 
    if (dump_xml) {
 
1150
    if (dump_xml && top) {
1066
1151
      Swig_print_xml(top, xmlout);
1067
1152
    }
1068
1153
    Delete(top);