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

« back to all changes in this revision

Viewing changes to Source/Modules/guile.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:
13
13
 * can be used and distributed.
14
14
 *****************************************************************************/
15
15
 
16
 
char cvsroot_guile_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/guile.cxx,v 1.25 2004/11/04 01:02:21 wuzzeb Exp $";
 
16
char cvsroot_guile_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/guile.cxx,v 1.33 2005/09/30 23:01:13 wsfulton Exp $";
17
17
 
18
18
/***********************************************************************
19
 
 * $Header: /cvsroot/swig/SWIG/Source/Modules/guile.cxx,v 1.25 2004/11/04 01:02:21 wuzzeb Exp $
 
19
 * $Header: /cvsroot/swig/SWIG/Source/Modules/guile.cxx,v 1.33 2005/09/30 23:01:13 wsfulton Exp $
20
20
 *
21
21
 * guile.cxx
22
22
 *
126
126
static int     exportprimitive = 0; // -exportprimitive argument
127
127
static String *memberfunction_name = 0;
128
128
 
 
129
extern "C" {
 
130
  static int has_classname(Node *class_node)
 
131
  {
 
132
    return Getattr(class_node, "guile:goopsclassname") != NULL;
 
133
  }
 
134
}
 
135
  
129
136
class GUILE : public Language {
130
137
public:
131
138
 
143
150
    for (i = 1; i < argc; i++) {
144
151
      if (argv[i]) {
145
152
        if (strcmp (argv[i], "-help") == 0) {
146
 
          fputs (guile_usage, stderr);
 
153
          fputs (guile_usage, stdout);
147
154
          SWIG_exit (EXIT_SUCCESS);
148
155
        }
149
156
        else if (strcmp (argv[i], "-prefix") == 0) {
193
200
        else if (strcmp (argv[i], "-procdoc") == 0) {
194
201
          if (argv[i + 1]) {
195
202
            procdoc = NewFile(argv[i + 1], (char *) "w");
 
203
            if (!procdoc) {
 
204
              FileErrorDisplay(argv[i + 1]);
 
205
              SWIG_exit(EXIT_FAILURE);
 
206
            }
196
207
            Swig_mark_arg (i);
197
208
            Swig_mark_arg (i + 1);
198
209
            i++;
331
342
    
332
343
    f_runtime = NewFile(outfile,"w");
333
344
    if (!f_runtime) {
334
 
      Printf(stderr,"*** Can't open '%s'\n", outfile);
 
345
      FileErrorDisplay(outfile);
335
346
      SWIG_exit(EXIT_FAILURE);
336
347
    }
337
348
    f_init = NewString("");
377
388
      /* Simple linkage; we have to export the SWIG_init function. The user can
378
389
         rename the function by a #define. */
379
390
      Printf (f_runtime, "extern void\nSWIG_init (void)\n;\n");
380
 
      Printf (f_init, "extern void\nSWIG_init (void)\n{\n");
 
391
      Printf (f_init, "#define SWIG_GUILE_INIT_STATIC static\n");
381
392
      break;
382
393
    default:
383
394
      /* Other linkage; we make the SWIG_init function static */
384
395
      Printf (f_runtime, "static void\nSWIG_init (void)\n;\n");
385
 
      Printf (f_init, "static void\nSWIG_init (void)\n{\n");
 
396
      Printf (f_init, "#define SWIG_GUILE_INIT_STATIC extern\n");
386
397
      break;
387
398
    }
388
399
    if (CPlusPlus) {
536
547
      Delete(primitive_name);
537
548
      File *scmstubfile = NewFile(fname, (char *) "w");
538
549
      if (!scmstubfile) {
539
 
        Printf(stderr,"*** Can't open '%s' for writing\n", fname);
 
550
        FileErrorDisplay(fname);
540
551
        SWIG_exit(EXIT_FAILURE);
541
552
      } 
542
553
      Delete(fname);
568
579
                                 module_name);
569
580
      File *goopsfile = NewFile(fname, (char *)"w");
570
581
      if (!goopsfile) {
571
 
        Printf(stderr,"*** Can't open '%s' for writing\n", fname);
 
582
        FileErrorDisplay(fname);
572
583
        SWIG_exit(EXIT_FAILURE);
573
584
      } 
574
585
      Delete(fname);
663
674
    if (maybe_delimiter && Len(output) > 0 && Len(tm) > 0) {
664
675
      Printv(output, maybe_delimiter, NIL);
665
676
    }
666
 
    const String *pn = (name == NULL) ? Getattr(p,"name") : name;
 
677
    const String *pn = (name == NULL) ? (const String *)Getattr(p,"name") : name;
667
678
    String *pt = Getattr(p,"type");
668
679
    Replaceall(tm, "$name", pn); // legacy for $parmname
669
680
    Replaceall(tm, "$type", SwigType_str(pt,0));
683
694
   * functionWrapper()
684
695
   * Create a function declaration and register it with the interpreter.
685
696
   * ------------------------------------------------------------ */
686
 
 
 
697
  
687
698
  virtual int functionWrapper(Node *n) {
688
699
    String *iname = Getattr(n,"sym:name");
689
700
    SwigType *d = Getattr(n,"type");
829
840
        if (goops) {
830
841
          if (i < numreq) {
831
842
            if (strcmp("void", Char(pt)) != 0) {
832
 
              Node *class_node = Swig_symbol_clookup(pb, Getattr(n, "sym:symtab"));
 
843
              Node *class_node = Swig_symbol_clookup_check(pb, Getattr(n, "sym:symtab"),
 
844
                                                           has_classname);
833
845
              String *goopsclassname = (class_node == NULL) ? NULL :
834
846
                Getattr(class_node, "guile:goopsclassname");
835
847
              /* do input conversion */
935
947
      Replaceall(tm,"$result","gswig_result");
936
948
      Replaceall(tm,"$target","gswig_result");
937
949
      Replaceall(tm,"$source","result");
938
 
      if (Getattr(n, "feature:new"))
 
950
      if (GetFlag(n, "feature:new"))
939
951
        Replaceall(tm, "$owner", "1");
940
952
      else 
941
953
        Replaceall(tm, "$owner", "0");
953
965
    
954
966
    // Look for any remaining cleanup
955
967
    
956
 
    if (Getattr(n,"feature:new")) {
 
968
    if (GetFlag(n,"feature:new")) {
957
969
      if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) {
958
970
        Replaceall(tm,"$source","result");
959
971
        Printv(f->code,tm,"\n",NIL);
1242
1254
      
1243
1255
      Wrapper_add_local (f, "gswig_result", "SCM gswig_result");
1244
1256
      
1245
 
      if (!Getattr(n,"feature:immutable")) {
 
1257
      if (!GetFlag(n,"feature:immutable")) {
1246
1258
        /* Check for a setting of the variable value */
1247
1259
        Printf (f->code, "if (s_0 != SCM_UNDEFINED) {\n");
1248
1260
        if ((tm = Swig_typemap_lookup_new("varin",n,name,0))) {
1278
1290
      // Now add symbol to the Guile interpreter
1279
1291
      
1280
1292
      if (!emit_setters
1281
 
          || Getattr(n,"feature:immutable")) {
 
1293
          || GetFlag(n,"feature:immutable")) {
1282
1294
        /* Read-only variables become a simple procedure returning the
1283
1295
           value; read-write variables become a simple procedure with
1284
1296
           an optional argument. */
1285
1297
        if (use_scm_interface) {
1286
1298
          Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n",
1287
 
                proc_name, Getattr(n, "feature:immutable") ? 0 : 1, var_name);
 
1299
                proc_name, !GetFlag(n, "feature:immutable"), var_name);
1288
1300
        } else {
1289
1301
          Printf (f_init, "\t gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, %d, 0);\n",
1290
 
                proc_name, var_name, Getattr(n,"feature:immutable") ? 0 : 1);
 
1302
                proc_name, var_name, !GetFlag(n,"feature:immutable"));
1291
1303
        }
1292
1304
      }
1293
1305
      else {
1329
1341
        String *signature2 = NULL;
1330
1342
        String *doc = NewString("");
1331
1343
        
1332
 
        if (Getattr(n,"feature:immutable")) {
 
1344
        if (GetFlag(n,"feature:immutable")) {
1333
1345
          Printv(signature, proc_name, NIL);
1334
1346
          Printv(doc, "Returns constant ", NIL);
1335
1347
          if ((tm = Getattr(n,"tmap:varout:doc"))) {
1460
1472
      Setattr(n,"name",var_name);
1461
1473
      Setattr(n,"sym:name",iname);
1462
1474
      Setattr(n,"type", nctype);
1463
 
      Setattr(n,"feature:immutable", "1");
 
1475
      SetFlag(n,"feature:immutable");
1464
1476
      variableWrapper(n);
1465
1477
      Delete(n);
1466
1478
    }
1639
1651
    Printv(goopscode, "\n   #:slot-ref (lambda (obj) (",
1640
1652
           primRenamer ? "primitive:" : "", 
1641
1653
           short_class_name, "-", proc, "-get", " obj))", NIL);
1642
 
    if (!Getattr(n,"feature:immutable")) {
 
1654
    if (!GetFlag(n,"feature:immutable")) {
1643
1655
      Printv(goopscode, "\n   #:slot-set! (lambda (obj value) (",
1644
1656
             primRenamer ? "primitive:" : "", 
1645
1657
             short_class_name, "-", proc, "-set", " obj value))", NIL);
1647
1659
      Printf(goopscode, "\n   #:slot-set! (lambda (obj value) (error \"Immutable slot\"))");
1648
1660
    }
1649
1661
    if (emit_slot_accessors) {
1650
 
      if (Getattr(n, "feature:immutable")) {
 
1662
      if (GetFlag(n, "feature:immutable")) {
1651
1663
        Printv(goopscode, "\n   #:getter ", goops_name, NIL);
1652
1664
      } else {
1653
1665
        Printv(goopscode, "\n   #:accessor ", goops_name, NIL);
1772
1784
    }
1773
1785
    return 1;
1774
1786
  }
 
1787
 
 
1788
  String *runtimeCode() {
 
1789
    String *s;
 
1790
    if (use_scm_interface) {
 
1791
      s = Swig_include_sys("guile_scm_run.swg");
 
1792
      if (!s) {
 
1793
        Printf(stderr, "*** Unable to open 'guile_scm_run.swg");
 
1794
        s = NewString("");
 
1795
      }
 
1796
    } else {
 
1797
      s = Swig_include_sys("guile_gh_run.swg");
 
1798
      if (!s) {
 
1799
        Printf(stderr, "*** Unable to open 'guile_gh_run.swg");
 
1800
        s = NewString("");
 
1801
      }
 
1802
    }
 
1803
    return s;
 
1804
  }
 
1805
 
 
1806
  String *defaultExternalRuntimeFilename() {
 
1807
    if (use_scm_interface) {
 
1808
      return NewString("swigguilerun.h");
 
1809
    } else {
 
1810
      return NewString("swigguileghrun.h");
 
1811
    }
 
1812
  }
1775
1813
};
1776
1814
 
1777
1815
/* -----------------------------------------------------------------------------