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

« back to all changes in this revision

Viewing changes to Source/Modules/modula3.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * ----------------------------------------------------------------------------- */
10
10
 
11
11
char cvsroot_modula3_cxx[] =
12
 
  "$Header: /cvsroot/swig/SWIG/Source/Modules/modula3.cxx,v 1.11 2004/11/08 21:19:47 wsfulton Exp $";
 
12
  "$Header: /cvsroot/swig/SWIG/Source/Modules/modula3.cxx,v 1.19 2005/09/30 23:35:52 wsfulton Exp $";
13
13
 
14
14
/*
15
15
  Text formatted with
198
198
  bool variable_wrapper_flag;   // Flag for when wrapping a nonstatic member variable
199
199
  bool wrapping_member_flag;    // Flag for when wrapping a member variable/enum/const
200
200
  bool global_variable_flag;    // Flag for when wrapping a global variable
 
201
  bool old_variable_names;      // Flag for old style variable names in the intermediary class
201
202
  bool unsafe_module;
202
203
 
203
204
  String *m3raw_name;           // raw interface name
262
263
    variable_wrapper_flag (false),
263
264
    wrapping_member_flag (false),
264
265
    global_variable_flag (false),
 
266
    old_variable_names (false),
265
267
    unsafe_module (false),
266
268
    m3raw_name (NULL),
267
269
    m3raw_intf (),
491
493
      if ((c == '_') || (c == ':')) {
492
494
        cap = true;
493
495
      } else {
494
 
        if (isdigit(c)) {
 
496
        if (isdigit (c)) {
495
497
          m3sym[i] = c;
496
498
          cap = true;
497
499
        } else {
573
575
  File *openWriteFile (String * name)
574
576
  {
575
577
    File *file = NewFile (name, "w");
576
 
    if (file == NIL) {
577
 
      Printf (stderr, "Unable to open <%s> for writing.\n", name);
 
578
    if (!file) {
 
579
      FileErrorDisplay (name);
578
580
      SWIG_exit (EXIT_FAILURE);
579
581
    }
580
582
    Delete (name);
794
796
        } else if (strcmp (argv[i], "-noproxy") == 0) {
795
797
          Swig_mark_arg (i);
796
798
          proxy_flag = false;
 
799
        } else if (strcmp (argv[i], "-oldvarnames") == 0) {
 
800
          Swig_mark_arg (i);
 
801
          old_variable_names = true;
797
802
        } else if (strcmp (argv[i], "-help") == 0) {
798
 
          Printf (stderr, "%s\n", usage);
 
803
          Printf (stdout, "%s\n", usage);
799
804
        }
800
805
      }
801
806
    }
962
967
 
963
968
    f_runtime = NewFile (outfile, "w");
964
969
    if (!f_runtime) {
965
 
      Printf (stderr, "Unable to open %s\n", outfile);
 
970
      FileErrorDisplay (outfile);
966
971
      SWIG_exit (EXIT_FAILURE);
967
972
    }
968
973
    f_init = NewString ("");
1020
1025
 
1021
1026
    Printf (wrapper_name, "Modula3_%%f", m3raw_name);
1022
1027
    Swig_name_register ((char *) "wrapper", Char (wrapper_name));
1023
 
    Swig_name_register ((char *) "set", (char *) "set_%v");
1024
 
    Swig_name_register ((char *) "get", (char *) "get_%v");
1025
 
    Swig_name_register ((char *) "member", (char *) "%c_%m");
 
1028
    if (old_variable_names) {
 
1029
      Swig_name_register ((char *) "set", (char *) "set_%v");
 
1030
      Swig_name_register ((char *) "get", (char *) "get_%v");
 
1031
    }
1026
1032
 
1027
1033
    Delete (wrapper_name);
1028
1034
 
1531
1537
    Printv (f->code, cleanup, NIL);
1532
1538
 
1533
1539
    /* Look to see if there is any newfree cleanup code */
1534
 
    if (Getattr (n, "feature:new")) {
 
1540
    if (GetFlag (n, "feature:new")) {
1535
1541
      String *tm = Swig_typemap_lookup_new ("newfree", n, "result", 0);
1536
1542
      if (tm != NIL) {
1537
1543
        addThrows (throws_hash, "newfree", n);
1917
1923
      if (name != NIL) {
1918
1924
        Printv (file, name, NIL);
1919
1925
      } else {
1920
 
        Printf (file, "dummy%d", i);
 
1926
        Printf (file, "Dummy%d", i);
1921
1927
      }
1922
1928
    }
1923
1929
    Printf (file, "\n};\n");
2226
2232
            newname = NewStringf ("%s%s", newprefix, newstem);
2227
2233
            Delete (newstem);
2228
2234
          } else {
2229
 
            newname = nameToModula3 (stem, false);
 
2235
            newname = nameToModula3 (stem, true);
2230
2236
          }
2231
2237
        } else {
2232
2238
          if (srcstyle != NIL) {
2316
2322
            Iterator patternit;
2317
2323
            for (patternit = First (patterndesc); patternit.item != NIL;
2318
2324
                 patternit = Next (patternit)) {
2319
 
              String *patternassign = Split (patternit.item, '=', 2);
 
2325
              List *patternassign = Split (patternit.item, '=', 2);
2320
2326
              String *tag = Getitem (patternassign, 0);
2321
2327
              String *data = Getitem (patternassign, 1);
2322
2328
              if (Strcmp (tag, "prefix") == 0) {
2569
2575
        NewStringf ("%s%s.m3", Swig_file_dirname (outfile), proxy_class_name);
2570
2576
      f_proxy = NewFile (filen, "w");
2571
2577
      if (!f_proxy) {
2572
 
        Printf (stderr, "Unable to create proxy class file: %s\n", filen);
 
2578
        FileErrorDisplay (filen);
2573
2579
        SWIG_exit (EXIT_FAILURE);
2574
2580
      }
2575
2581
      Delete (filen);
2785
2791
*/
2786
2792
      String *arguments = createM3Signature (n);
2787
2793
      String *storage = Getattr (n, "storage");
2788
 
      String *overridden = Getattr (n, "virtual:derived");
 
2794
      String *overridden = Getattr (n, "override");
2789
2795
      bool isVirtual = (storage != NIL) && (Strcmp (storage, "virtual") == 0);
2790
2796
      bool isOverridden = (overridden != NIL)
2791
2797
        && (Strcmp (overridden, "1") == 0);
2795
2801
          Printf (methods, "%s(%s)%s%s;%s\n",
2796
2802
                  methodname, arguments,
2797
2803
                  hasContent (rettype) ? ": " : "",
2798
 
                  hasContent (rettype) ? rettype : "",
 
2804
                  hasContent (rettype) ? (const String *) rettype : "",
2799
2805
                  isVirtual ? "  (* base method *)" : "");
2800
2806
        }
2801
2807
        {
2906
2912
            Getattr (n, "feature:modula3:methodmodifiers"));
2907
2913
    if (static_flag)
2908
2914
      Printf (function_code, "static ");
2909
 
    if (Getattr (n, "virtual:derived"))
 
2915
    if (Getattr (n, "override"))
2910
2916
      Printf (function_code, "override ");
2911
2917
    else if (checkAttribute (n, "storage", "virtual"))
2912
2918
      Printf (function_code, "virtual ");
2981
2987
    // Transform return type used in PInvoke function (in intermediary class) to type used in Modula 3 wrapper function (in proxy class)
2982
2988
    if ((tm = getMappedTypeNew (n, "m3out", ""))) {
2983
2989
      addThrows (throws_hash, "m3out", n);
2984
 
      if (Getattr (n, "feature:new"))
 
2990
      if (GetFlag (n, "feature:new"))
2985
2991
        Replaceall (tm, "$owner", "true");
2986
2992
      else
2987
2993
        Replaceall (tm, "$owner", "false");
2990
2996
    }
2991
2997
 
2992
2998
    generateThrowsClause (throws_hash, function_code);
2993
 
    Printf (function_code, " %s\n\n", tm ? (const String *)tm : empty_string);
 
2999
    Printf (function_code, " %s\n\n",
 
3000
            tm ? (const String *) tm : empty_string);
2994
3001
 
2995
3002
    if (proxy_flag && wrapping_member_flag && !enum_constant_flag) {
2996
3003
      // Properties
2997
3004
      if (setter_flag) {
2998
3005
        // Setter method
2999
3006
        if ((tm = getMappedTypeNew (n, "m3varin", ""))) {
3000
 
          if (Getattr (n, "feature:new"))
 
3007
          if (GetFlag (n, "feature:new"))
3001
3008
            Replaceall (tm, "$owner", "true");
3002
3009
          else
3003
3010
            Replaceall (tm, "$owner", "false");
3008
3015
      } else {
3009
3016
        // Getter method
3010
3017
        if ((tm = getMappedTypeNew (n, "m3varout", ""))) {
3011
 
          if (Getattr (n, "feature:new"))
 
3018
          if (GetFlag (n, "feature:new"))
3012
3019
            Replaceall (tm, "$owner", "true");
3013
3020
          else
3014
3021
            Replaceall (tm, "$owner", "false");
3187
3194
          String *inmode = getMappedTypeNew (n, "m3wrapinmode", "", false);
3188
3195
          String *intype = getMappedTypeNew (n, "m3wrapintype", "");
3189
3196
          Printf (methods, "set%s(%s val:%s);\n",
3190
 
                  m3name, (inmode != NIL) ? inmode : "", intype);
 
3197
                  m3name, (inmode != NIL) ? (const String *) inmode : "",
 
3198
                  intype);
3191
3199
        }
3192
3200
        {
3193
3201
          /* this was attached by functionWrapper
3307
3315
    String *raw_name = Getattr (n, "name");     /*original C function name */
3308
3316
    //String     *func_name = Getattr(n,"sym:name");  /*final Modula3 name chosen by the user*/
3309
3317
    bool setter_flag = false;
3310
 
    bool multiretval = Getattr (n, "feature:modula3:multiretval") != NIL;
 
3318
    int multiretval = GetFlag (n, "feature:modula3:multiretval");
3311
3319
 
3312
3320
    if (l) {
3313
3321
      if (SwigType_type (Getattr (l, "type")) == T_VOID) {
3746
3754
 
3747
3755
      Printf (function_code, " =\n%s%s%s%sBEGIN\n%s%sEND %s;\n\n",
3748
3756
              hasContent (local_constants) ? "CONST\n" : "", local_constants,
3749
 
              hasContent (local_variables) ? "VAR\n"   : "", local_variables,
 
3757
              hasContent (local_variables) ? "VAR\n" : "", local_variables,
3750
3758
              exc_handler, outarg, func_name);
3751
3759
 
3752
3760
      Delete (exc_handler);
3760
3768
        // Setter method
3761
3769
        String *tm = getMappedTypeNew (n, "m3varin", "");
3762
3770
        if (tm != NIL) {
3763
 
          if (Getattr (n, "feature:new")) {
 
3771
          if (GetFlag (n, "feature:new")) {
3764
3772
            Replaceall (tm, "$owner", "true");
3765
3773
          } else {
3766
3774
            Replaceall (tm, "$owner", "false");
3775
3783
        // Getter method
3776
3784
        String *tm = getMappedTypeNew (n, "m3varout", "");
3777
3785
        if (tm != NIL) {
3778
 
          if (Getattr (n, "feature:new"))
 
3786
          if (GetFlag (n, "feature:new"))
3779
3787
            Replaceall (tm, "$owner", "true");
3780
3788
          else
3781
3789
            Replaceall (tm, "$owner", "false");
4006
4014
    String *filen =
4007
4015
      NewStringf ("%s%s.m3", Swig_file_dirname (outfile), classname);
4008
4016
    File *f_swigtype = NewFile (filen, "w");
 
4017
    if (!f_swigtype) {
 
4018
      FileErrorDisplay (filen);
 
4019
      SWIG_exit (EXIT_FAILURE);
 
4020
    }
4009
4021
    String *swigtype = NewString ("");
4010
4022
 
4011
4023
    // Emit banner name
4205
4217
 
4206
4218
const char *MODULA3::usage = (char *) "\
4207
4219
Modula 3 Options (available with -modula3)\n\
4208
 
     -generateconst <file> - generate code for computing numeric values of constants\n\
4209
 
     -generaterename <file> - generate suggestions for %rename\n\
 
4220
     -generateconst <file>   - generate code for computing numeric values of constants\n\
 
4221
     -generaterename <file>  - generate suggestions for %rename\n\
4210
4222
     -generatetypemap <file> - generate templates for some basic typemaps\n\
 
4223
     -oldvarnames    - old intermediary method names for variable wrappers\n\
4211
4224
\n";
4212
4225
 
4213
4226
/*