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

« back to all changes in this revision

Viewing changes to Source/Modules/pike.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-12-20 14:43:24 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061220144324-bps3kb06xp5oy9w1
Tags: 1.3.31-1ubuntu1
* Merge from debian unstable, remaining changes:
  - drop support for pike
  - use php5 instead of php4
  - clean Runtime/ as well
  - force a few environment variables

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 *   address, etc. for extension objects. Should we do something here?
25
25
 *
26
26
 */
27
 
 
28
 
char cvsroot_pike_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/pike.cxx,v 1.18 2006/03/06 22:50:57 wsfulton Exp $";
 
27
 
 
28
char cvsroot_pike_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/pike.cxx,v 1.19 2006/11/01 23:54:52 wsfulton Exp $";
29
29
 
30
30
#include "swigmod.h"
31
31
 
32
 
#include <ctype.h> // for isalnum()
 
32
#include <ctype.h>              // for isalnum()
33
33
 
34
 
static const char *usage = (char *)"\
 
34
static const char *usage = (char *) "\
35
35
Pike Options (available with -pike)\n\
36
36
     [None]\n\
37
37
\n";
38
38
 
39
 
class PIKE : public Language {
 
39
class PIKE:public Language {
40
40
private:
41
41
 
42
42
  File *f_runtime;
47
47
 
48
48
  String *PrefixPlusUnderscore;
49
49
  int current;
50
 
  
 
50
 
51
51
  // Wrap modes
52
52
  enum {
53
53
    NO_CPP,
68
68
   * Initialize member data
69
69
   * --------------------------------------------------------------------- */
70
70
 
71
 
  PIKE() {
 
71
   PIKE() {
72
72
    f_runtime = 0;
73
73
    f_header = 0;
74
74
    f_wrappers = 0;
83
83
   *
84
84
   * Parse command line options and initializes variables.
85
85
   * --------------------------------------------------------------------- */
86
 
 
87
 
  virtual void main(int argc, char *argv[]) {
 
86
  
 
87
   virtual void main(int argc, char *argv[]) {
88
88
 
89
89
    /* Set location of SWIG library */
90
90
    SWIG_library_directory("pike");
92
92
    /* Look for certain command line options */
93
93
    for (int i = 1; i < argc; i++) {
94
94
      if (argv[i]) {
95
 
        if (strcmp(argv[i],"-help") == 0) {
96
 
          fputs(usage,stdout);
 
95
        if (strcmp(argv[i], "-help") == 0) {
 
96
          fputs(usage, stdout);
97
97
        }
98
98
      }
99
99
    }
101
101
    /* Add a symbol to the parser for conditional compilation */
102
102
    Preprocessor_define("SWIGPIKE 1", 0);
103
103
 
104
 
    /* Set language-specific configuration file */    
 
104
    /* Set language-specific configuration file */
105
105
    SWIG_config_file("pike.swg");
106
106
 
107
107
    /* Set typemap language */
108
108
    SWIG_typemap_lang("pike");
109
 
    
 
109
 
110
110
    /* Enable overloaded methods support */
111
111
    allow_overloading();
112
112
  }
118
118
  virtual int top(Node *n) {
119
119
    /* Get the module name */
120
120
    String *module = Getattr(n, "name");
121
 
    
 
121
 
122
122
    /* Get the output file name */
123
123
    String *outfile = Getattr(n, "outfile");
124
 
    
 
124
 
125
125
    /* Open the output file */
126
126
    f_runtime = NewFile(outfile, "w");
127
127
    if (!f_runtime) {
140
140
    Swig_register_filebyname("init", f_init);
141
141
    Swig_register_filebyname("classInit", f_classInit);
142
142
 
143
 
    /* Standard stuff for the SWIG runtime section */    
 
143
    /* Standard stuff for the SWIG runtime section */
144
144
    Swig_banner(f_runtime);
145
145
 
146
146
    Printf(f_header, "#define SWIG_init    pike_module_init\n");
147
147
    Printf(f_header, "#define SWIG_name    \"%s\"\n\n", module);
148
 
    
 
148
 
149
149
    /* Change naming scheme for constructors and destructors */
150
 
    Swig_name_register("construct","%c_create");
151
 
    Swig_name_register("destroy","%c_destroy");
152
 
    
 
150
    Swig_name_register("construct", "%c_create");
 
151
    Swig_name_register("destroy", "%c_destroy");
 
152
 
153
153
    /* Current wrap type */
154
154
    current = NO_CPP;
155
155
 
156
156
    /* Emit code for children */
157
157
    Language::top(n);
158
 
    
 
158
 
159
159
    /* Close the initialization function */
160
160
    Printf(f_init, "}\n");
161
161
    SwigType_emit_type_table(f_runtime, f_wrappers);
162
 
    
 
162
 
163
163
    /* Close all of the files */
164
164
    Dump(f_header, f_runtime);
165
165
    Dump(f_wrappers, f_runtime);
176
176
    /* Done */
177
177
    return SWIG_OK;
178
178
  }
179
 
  
 
179
 
180
180
  /* ------------------------------------------------------------
181
181
   * validIdentifier()
182
182
   * ------------------------------------------------------------ */
187
187
    const char *c1 = c0 + 1;
188
188
    while (*c) {
189
189
      if (*c == '`' && c == c0) {
190
 
        c++; continue;
 
190
        c++;
 
191
        continue;
191
192
      }
192
193
      if ((*c == '+' || *c == '-' || *c == '*' || *c == '/') && c == c1) {
193
 
        c++; continue;
 
194
        c++;
 
195
        continue;
194
196
      }
195
197
      if (!(isalnum(*c) || (*c == '_')))
196
198
        return 0;
198
200
    }
199
201
    return 1;
200
202
  }
201
 
  
 
203
 
202
204
  /* ------------------------------------------------------------
203
205
   * importDirective()
204
206
   * ------------------------------------------------------------ */
205
207
 
206
208
  virtual int importDirective(Node *n) {
207
 
    String *modname = Getattr(n,"module");
 
209
    String *modname = Getattr(n, "module");
208
210
    if (modname) {
209
 
      Printf(f_init,"pike_require(\"%s\");\n", modname);
 
211
      Printf(f_init, "pike_require(\"%s\");\n", modname);
210
212
    }
211
213
    return Language::importDirective(n);
212
214
  }
213
 
  
 
215
 
214
216
  /* ------------------------------------------------------------
215
217
   * strip()
216
218
   *
235
237
  void add_method(const DOHString_or_char *name, const DOHString_or_char *function, const DOHString_or_char *description) {
236
238
    String *rename = NULL;
237
239
    switch (current) {
238
 
      case NO_CPP:
239
 
        rename = NewString(name);
240
 
        Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
241
 
        break;
242
 
      case STATIC_FUNC:
243
 
      case STATIC_VAR:
244
 
        rename = NewString(name);
245
 
        Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
246
 
        break;
247
 
      case CONSTRUCTOR:
248
 
      case DESTRUCTOR:
249
 
      case MEMBER_FUNC:
250
 
      case MEMBER_VAR:
251
 
        rename = strip(name);
252
 
        Printf(f_classInit, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
253
 
        break;
254
 
      case CLASS_CONST:
255
 
        assert(false); // shouldn't have gotten here for CLASS_CONST nodes
256
 
      default:
257
 
        assert(false); // what is this?
 
240
    case NO_CPP:
 
241
      rename = NewString(name);
 
242
      Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
 
243
      break;
 
244
    case STATIC_FUNC:
 
245
    case STATIC_VAR:
 
246
      rename = NewString(name);
 
247
      Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
 
248
      break;
 
249
    case CONSTRUCTOR:
 
250
    case DESTRUCTOR:
 
251
    case MEMBER_FUNC:
 
252
    case MEMBER_VAR:
 
253
      rename = strip(name);
 
254
      Printf(f_classInit, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
 
255
      break;
 
256
    case CLASS_CONST:
 
257
      assert(false);            // shouldn't have gotten here for CLASS_CONST nodes
 
258
    default:
 
259
      assert(false);            // what is this?
258
260
    }
259
261
    Delete(rename);
260
262
  }
267
269
 
268
270
  virtual int functionWrapper(Node *n) {
269
271
 
270
 
    String  *name  = Getattr(n,"name");
271
 
    String  *iname = Getattr(n,"sym:name");
272
 
    SwigType *d    = Getattr(n,"type");
273
 
    ParmList *l    = Getattr(n,"parms");
 
272
    String *name = Getattr(n, "name");
 
273
    String *iname = Getattr(n, "sym:name");
 
274
    SwigType *d = Getattr(n, "type");
 
275
    ParmList *l = Getattr(n, "parms");
274
276
 
275
277
    Parm *p;
276
 
    String *tm;    
 
278
    String *tm;
277
279
    int i;
278
280
 
279
281
    String *overname = 0;
280
 
    if (Getattr(n,"sym:overloaded")) {
281
 
      overname = Getattr(n,"sym:overname");
 
282
    if (Getattr(n, "sym:overloaded")) {
 
283
      overname = Getattr(n, "sym:overname");
282
284
    } else {
283
 
      if (!addSymbol(iname,n)) return SWIG_ERROR;
 
285
      if (!addSymbol(iname, n))
 
286
        return SWIG_ERROR;
284
287
    }
285
288
 
286
289
    Wrapper *f = NewWrapper();
287
 
    
 
290
 
288
291
    /* Write code to extract function parameters. */
289
292
    emit_args(d, l, f);
290
293
 
291
294
    /* Attach the standard typemaps */
292
 
    emit_attach_parmmaps(l,f);
293
 
    Setattr(n,"wrap:parms",l);
 
295
    emit_attach_parmmaps(l, f);
 
296
    Setattr(n, "wrap:parms", l);
294
297
 
295
298
    /* Get number of required and total arguments */
296
299
    int num_arguments = emit_num_arguments(l);
297
300
    int varargs = emit_isvarargs(l);
298
 
    
 
301
 
299
302
    /* Which input argument to start with? */
300
303
    int start = (current == MEMBER_FUNC || current == MEMBER_VAR || current == DESTRUCTOR) ? 1 : 0;
301
304
 
302
 
    /* Offset to skip over the attribute name */    
 
305
    /* Offset to skip over the attribute name */
303
306
    // int offset = (current == MEMBER_VAR) ? 1 : 0;
304
307
    int offset = 0;
305
 
    
 
308
 
306
309
    String *wname = Swig_name_wrapper(iname);
307
310
    if (overname) {
308
 
      Append(wname,overname);
 
311
      Append(wname, overname);
309
312
    }
310
 
    
 
313
 
311
314
    Printv(f->def, "static void ", wname, "(INT32 args) {", NIL);
312
 
    
 
315
 
313
316
    /* Generate code for argument marshalling */
314
317
    String *description = NewString("");
315
318
    char source[64];
316
319
    for (i = 0, p = l; i < num_arguments; i++) {
317
320
 
318
 
      while (checkAttribute(p,"tmap:in:numinputs","0")) {
319
 
        p = Getattr(p,"tmap:in:next");
 
321
      while (checkAttribute(p, "tmap:in:numinputs", "0")) {
 
322
        p = Getattr(p, "tmap:in:next");
320
323
      }
321
 
      
322
 
      SwigType *pt = Getattr(p,"type");
323
 
      String   *ln = Getattr(p,"lname");
 
324
 
 
325
      SwigType *pt = Getattr(p, "type");
 
326
      String *ln = Getattr(p, "lname");
324
327
 
325
328
      if (i < start) {
326
 
        String *lstr = SwigType_lstr(pt,0);
327
 
        Printf(f->code, "%s = (%s) THIS;\n", ln, lstr);
 
329
        String *lstr = SwigType_lstr(pt, 0);
 
330
        Printf(f->code, "%s = (%s) THIS;\n", ln, lstr);
328
331
        Delete(lstr);
329
 
      } else {      
 
332
      } else {
330
333
        /* Look for an input typemap */
331
 
        sprintf(source, "Pike_sp[%d-args]", i-start+offset);
332
 
        if ((tm = Getattr(p,"tmap:in"))) {
333
 
          Replaceall(tm, "$source", source);
 
334
        sprintf(source, "Pike_sp[%d-args]", i - start + offset);
 
335
        if ((tm = Getattr(p, "tmap:in"))) {
 
336
          Replaceall(tm, "$source", source);
334
337
          Replaceall(tm, "$target", ln);
335
338
          Replaceall(tm, "$input", source);
336
339
          Setattr(p, "emit:input", source);
337
340
          Printf(f->code, "%s\n", tm);
338
 
          String *pikedesc = Getattr(p, "tmap:in:pikedesc");
 
341
          String *pikedesc = Getattr(p, "tmap:in:pikedesc");
339
342
          if (pikedesc) {
340
343
            Printv(description, pikedesc, " ", NIL);
341
344
          }
342
 
          p = Getattr(p,"tmap:in:next");
 
345
          p = Getattr(p, "tmap:in:next");
343
346
          continue;
344
347
        } else {
345
 
          Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, 
346
 
                       "Unable to use type %s as a function argument.\n",SwigType_str(pt,0));
 
348
          Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
347
349
          break;
348
350
        }
349
351
      }
352
354
 
353
355
    /* Check for trailing varargs */
354
356
    if (varargs) {
355
 
      if (p && (tm = Getattr(p,"tmap:in"))) {
356
 
        Replaceall(tm,"$input", "varargs");
357
 
        Printv(f->code,tm,"\n",NIL);
 
357
      if (p && (tm = Getattr(p, "tmap:in"))) {
 
358
        Replaceall(tm, "$input", "varargs");
 
359
        Printv(f->code, tm, "\n", NIL);
358
360
      }
359
361
    }
360
362
 
361
363
    /* Insert constraint checking code */
362
364
    for (p = l; p;) {
363
 
      if ((tm = Getattr(p,"tmap:check"))) {
364
 
        Replaceall(tm,"$target",Getattr(p,"lname"));
365
 
        Printv(f->code,tm,"\n",NIL);
366
 
        p = Getattr(p,"tmap:check:next");
 
365
      if ((tm = Getattr(p, "tmap:check"))) {
 
366
        Replaceall(tm, "$target", Getattr(p, "lname"));
 
367
        Printv(f->code, tm, "\n", NIL);
 
368
        p = Getattr(p, "tmap:check:next");
367
369
      } else {
368
370
        p = nextSibling(p);
369
371
      }
370
372
    }
371
 
  
 
373
 
372
374
    /* Insert cleanup code */
373
375
    String *cleanup = NewString("");
374
376
    for (p = l; p;) {
375
 
      if ((tm = Getattr(p,"tmap:freearg"))) {
376
 
        Replaceall(tm,"$source",Getattr(p,"lname"));
377
 
        Printv(cleanup,tm,"\n",NIL);
378
 
        p = Getattr(p,"tmap:freearg:next");
 
377
      if ((tm = Getattr(p, "tmap:freearg"))) {
 
378
        Replaceall(tm, "$source", Getattr(p, "lname"));
 
379
        Printv(cleanup, tm, "\n", NIL);
 
380
        p = Getattr(p, "tmap:freearg:next");
379
381
      } else {
380
382
        p = nextSibling(p);
381
383
      }
384
386
    /* Insert argument output code */
385
387
    String *outarg = NewString("");
386
388
    for (p = l; p;) {
387
 
      if ((tm = Getattr(p,"tmap:argout"))) {
388
 
        Replaceall(tm,"$source",Getattr(p,"lname"));
389
 
        Replaceall(tm,"$target","resultobj");
390
 
        Replaceall(tm,"$arg",Getattr(p,"emit:input"));
391
 
        Replaceall(tm,"$input",Getattr(p,"emit:input"));
392
 
        Printv(outarg,tm,"\n",NIL);
393
 
        p = Getattr(p,"tmap:argout:next");
 
389
      if ((tm = Getattr(p, "tmap:argout"))) {
 
390
        Replaceall(tm, "$source", Getattr(p, "lname"));
 
391
        Replaceall(tm, "$target", "resultobj");
 
392
        Replaceall(tm, "$arg", Getattr(p, "emit:input"));
 
393
        Replaceall(tm, "$input", Getattr(p, "emit:input"));
 
394
        Printv(outarg, tm, "\n", NIL);
 
395
        p = Getattr(p, "tmap:argout:next");
394
396
      } else {
395
397
        p = nextSibling(p);
396
398
      }
397
399
    }
398
400
 
399
401
    /* Emit the function call */
400
 
    emit_action(n,f);
 
402
    emit_action(n, f);
401
403
 
402
404
    /* Clear the return stack */
403
405
    Printf(f->code, "pop_n_elems(args);\n");
411
413
    } else {
412
414
      // Wrapper_add_local(f, "resultobj", "struct object *resultobj");
413
415
      Printv(description, ", ", NIL);
414
 
      if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) {
415
 
        Replaceall(tm,"$source", "result");
416
 
        Replaceall(tm,"$target", "resultobj");
417
 
        Replaceall(tm,"$result", "resultobj");
418
 
        if (GetFlag(n,"feature:new")) {
419
 
          Replaceall(tm,"$owner","1");
 
416
      if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) {
 
417
        Replaceall(tm, "$source", "result");
 
418
        Replaceall(tm, "$target", "resultobj");
 
419
        Replaceall(tm, "$result", "resultobj");
 
420
        if (GetFlag(n, "feature:new")) {
 
421
          Replaceall(tm, "$owner", "1");
420
422
        } else {
421
 
          Replaceall(tm,"$owner","0");
 
423
          Replaceall(tm, "$owner", "0");
422
424
        }
423
425
        String *pikedesc = Getattr(n, "tmap:out:pikedesc");
424
426
        if (pikedesc) {
425
427
          Printv(description, pikedesc, NIL);
426
428
        }
427
 
        Printf(f->code,"%s\n", tm);
 
429
        Printf(f->code, "%s\n", tm);
428
430
      } else {
429
 
        Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number,
430
 
                     "Unable to use return type %s in function %s.\n", SwigType_str(d,0), name);
 
431
        Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);
431
432
      }
432
433
    }
433
434
 
434
435
    /* Output argument output code */
435
 
    Printv(f->code,outarg,NIL);
 
436
    Printv(f->code, outarg, NIL);
436
437
 
437
438
    /* Output cleanup code */
438
 
    Printv(f->code,cleanup,NIL);
 
439
    Printv(f->code, cleanup, NIL);
439
440
 
440
441
    /* Look to see if there is any newfree cleanup code */
441
 
    if (GetFlag(n,"feature:new")) {
442
 
      if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) {
443
 
        Replaceall(tm,"$source","result");
444
 
        Printf(f->code,"%s\n",tm);
 
442
    if (GetFlag(n, "feature:new")) {
 
443
      if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) {
 
444
        Replaceall(tm, "$source", "result");
 
445
        Printf(f->code, "%s\n", tm);
445
446
      }
446
447
    }
447
448
 
448
449
    /* See if there is any return cleanup code */
449
450
    if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) {
450
 
      Replaceall(tm,"$source","result");
451
 
      Printf(f->code,"%s\n",tm);
 
451
      Replaceall(tm, "$source", "result");
 
452
      Printf(f->code, "%s\n", tm);
452
453
    }
453
 
    
 
454
 
454
455
    /* Close the function */
455
456
    Printf(f->code, "}\n");
456
457
 
457
458
    /* Substitute the cleanup code */
458
 
    Replaceall(f->code,"$cleanup",cleanup);
459
 
    
 
459
    Replaceall(f->code, "$cleanup", cleanup);
 
460
 
460
461
    /* Substitute the function name */
461
 
    Replaceall(f->code,"$symname",iname);
462
 
    Replaceall(f->code,"$result","resultobj");
 
462
    Replaceall(f->code, "$symname", iname);
 
463
    Replaceall(f->code, "$result", "resultobj");
463
464
 
464
465
    /* Dump the function out */
465
 
    Wrapper_print(f,f_wrappers);
 
466
    Wrapper_print(f, f_wrappers);
466
467
 
467
468
    /* Now register the function with the interpreter. */
468
 
    if (!Getattr(n,"sym:overloaded")) {
 
469
    if (!Getattr(n, "sym:overloaded")) {
469
470
      add_method(iname, wname, description);
470
471
    } else {
471
 
      Setattr(n,"wrap:name", wname);
472
 
      if (!Getattr(n,"sym:nextSibling")) {
 
472
      Setattr(n, "wrap:name", wname);
 
473
      if (!Getattr(n, "sym:nextSibling")) {
473
474
        dispatchFunction(n);
474
475
      }
475
476
    }
495
496
    int maxargs;
496
497
    String *tmp = NewString("");
497
498
    String *dispatch = Swig_overload_dispatch(n, "%s(args); return;", &maxargs);
498
 
        
 
499
 
499
500
    /* Generate a dispatch wrapper for all overloaded functions */
500
501
 
501
 
    Wrapper *f       = NewWrapper();
502
 
    String  *symname = Getattr(n,"sym:name");
503
 
    String  *wname   = Swig_name_wrapper(symname);
 
502
    Wrapper *f = NewWrapper();
 
503
    String *symname = Getattr(n, "sym:name");
 
504
    String *wname = Swig_name_wrapper(symname);
504
505
 
505
506
    Printf(f->def, "static void %s(INT32 args) {", wname);
506
 
    
 
507
 
507
508
    Wrapper_add_local(f, "argc", "INT32 argc");
508
509
    Printf(tmp, "struct svalue argv[%d]", maxargs);
509
510
    Wrapper_add_local(f, "argv", tmp);
510
511
    Wrapper_add_local(f, "ii", "INT32 ii");
511
 
    
 
512
 
512
513
    Printf(f->code, "argc = args;\n");
513
514
    Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", maxargs);
514
515
    Printf(f->code, "argv[ii] = Pike_sp[ii-args];\n");
515
516
    Printf(f->code, "}\n");
516
 
    
 
517
 
517
518
    Replaceall(dispatch, "$args", "self, args");
518
519
    Printv(f->code, dispatch, "\n", NIL);
519
520
    Printf(f->code, "Pike_error(\"No matching function for overloaded '%s'.\");\n", symname);
520
521
    Printv(f->code, "}\n", NIL);
521
 
    
 
522
 
522
523
    Wrapper_print(f, f_wrappers);
523
 
    
 
524
 
524
525
    String *description = NewString("");
525
526
    Printf(description, "tAny,");
526
527
    if (current == CONSTRUCTOR || current == DESTRUCTOR) {
553
554
 
554
555
  virtual int constantWrapper(Node *n) {
555
556
 
556
 
    Swig_require("constantWrapper",n, "*sym:name", "type", "value", NIL);
557
 
    
 
557
    Swig_require("constantWrapper", n, "*sym:name", "type", "value", NIL);
 
558
 
558
559
    String *symname = Getattr(n, "sym:name");
559
 
    SwigType *type  = Getattr(n, "type");
560
 
    String *value   = Getattr(n, "value");
561
 
    
 
560
    SwigType *type = Getattr(n, "type");
 
561
    String *value = Getattr(n, "value");
 
562
 
562
563
    /* Special hook for member pointer */
563
564
    if (SwigType_type(type) == T_MPOINTER) {
564
565
      String *wname = Swig_name_wrapper(symname);
575
576
      Replaceall(tm, "$value", value);
576
577
      Printf(f_init, "%s\n", tm);
577
578
    } else {
578
 
      Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number,
579
 
                   "Unsupported constant value %s = %s\n", SwigType_str(type, 0), value);
 
579
      Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value %s = %s\n", SwigType_str(type, 0), value);
580
580
    }
581
581
 
582
582
    Swig_restore(n);
583
 
    
 
583
 
584
584
    return SWIG_OK;
585
585
  }
586
586
 
590
590
 
591
591
  virtual int nativeWrapper(Node *n) {
592
592
    //   return Language::nativeWrapper(n);
593
 
    String *name     = Getattr(n,"sym:name");
594
 
    String *wrapname = Getattr(n,"wrap:name");
595
 
 
596
 
    if (!addSymbol(wrapname,n)) return SWIG_ERROR;
597
 
 
598
 
    add_method(name, wrapname,0);
 
593
    String *name = Getattr(n, "sym:name");
 
594
    String *wrapname = Getattr(n, "wrap:name");
 
595
 
 
596
    if (!addSymbol(wrapname, n))
 
597
      return SWIG_ERROR;
 
598
 
 
599
    add_method(name, wrapname, 0);
599
600
    return SWIG_OK;
600
 
  }  
 
601
  }
601
602
 
602
603
  /* ------------------------------------------------------------
603
604
   * enumDeclaration()
604
605
   * ------------------------------------------------------------ */
605
 
  
 
606
 
606
607
  virtual int enumDeclaration(Node *n) {
607
608
    return Language::enumDeclaration(n);
608
609
  }
610
611
  /* ------------------------------------------------------------
611
612
   * enumvalueDeclaration()
612
613
   * ------------------------------------------------------------ */
613
 
   
 
614
 
614
615
  virtual int enumvalueDeclaration(Node *n) {
615
616
    return Language::enumvalueDeclaration(n);
616
617
  }
622
623
  virtual int classDeclaration(Node *n) {
623
624
    return Language::classDeclaration(n);
624
625
  }
625
 
  
 
626
 
626
627
  /* ------------------------------------------------------------
627
628
   * classHandler()
628
629
   * ------------------------------------------------------------ */
632
633
    String *symname = Getattr(n, "sym:name");
633
634
    if (!addSymbol(symname, n))
634
635
      return SWIG_ERROR;
635
 
      
 
636
 
636
637
    PrefixPlusUnderscore = NewStringf("%s_", getClassPrefix());
637
638
 
638
639
    Printf(f_classInit, "start_new_program();\n");
639
640
 
640
641
    /* Handle inheritance */
641
 
    List *baselist = Getattr(n,"bases");
 
642
    List *baselist = Getattr(n, "bases");
642
643
    if (baselist && Len(baselist) > 0) {
643
644
      Iterator base = First(baselist);
644
645
      while (base.item) {
645
 
        String *basename = Getattr(base.item,"name");
646
 
        SwigType *basetype = NewString(basename);
647
 
        SwigType_add_pointer(basetype);
648
 
        SwigType_remember(basetype);
649
 
        String *basemangle = SwigType_manglestr(basetype);
650
 
        Printf(f_classInit, "low_inherit((struct program *) SWIGTYPE%s->clientdata, 0, 0, 0, 0, 0);\n", basemangle);
 
646
        String *basename = Getattr(base.item, "name");
 
647
        SwigType *basetype = NewString(basename);
 
648
        SwigType_add_pointer(basetype);
 
649
        SwigType_remember(basetype);
 
650
        String *basemangle = SwigType_manglestr(basetype);
 
651
        Printf(f_classInit, "low_inherit((struct program *) SWIGTYPE%s->clientdata, 0, 0, 0, 0, 0);\n", basemangle);
651
652
        Delete(basemangle);
652
653
        Delete(basetype);
653
 
        base = Next(base);
 
654
        base = Next(base);
654
655
      }
655
656
    } else {
656
657
      Printf(f_classInit, "ADD_STORAGE(swig_object_wrapper);\n");
657
658
    }
658
 
        
 
659
 
659
660
    Language::classHandler(n);
660
 
    
 
661
 
661
662
    /* Accessors for member variables */
662
663
    /*
663
 
    List *membervariables = Getattr(n,"membervariables");
664
 
    if (membervariables && Len(membervariables) > 0) {
665
 
      membervariableAccessors(membervariables);
666
 
    }
667
 
    */
668
 
    
 
664
       List *membervariables = Getattr(n,"membervariables");
 
665
       if (membervariables && Len(membervariables) > 0) {
 
666
       membervariableAccessors(membervariables);
 
667
       }
 
668
     */
 
669
 
669
670
    /* Done, close the class and dump its definition to the init function */
670
671
    Printf(f_classInit, "add_program_constant(\"%s\", pr = end_program(), 0);\n", symname);
671
672
    Dump(f_classInit, f_init);
672
673
    Clear(f_classInit);
673
 
    
 
674
 
674
675
    SwigType *tt = NewString(symname);
675
676
    SwigType_add_pointer(tt);
676
677
    SwigType_remember(tt);
678
679
    Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) pr);\n", tm);
679
680
    Delete(tm);
680
681
    Delete(tt);
681
 
    
682
 
    Delete(PrefixPlusUnderscore); PrefixPlusUnderscore = 0;
 
682
 
 
683
    Delete(PrefixPlusUnderscore);
 
684
    PrefixPlusUnderscore = 0;
683
685
 
684
686
    return SWIG_OK;
685
687
  }
720
722
    current = NO_CPP;
721
723
    return SWIG_OK;
722
724
  }
723
 
  
 
725
 
724
726
  /* ------------------------------------------------------------
725
727
   * membervariableAccessors()
726
728
   * ------------------------------------------------------------ */
730
732
    Iterator i;
731
733
    bool need_setter;
732
734
    String *funcname;
733
 
    
 
735
 
734
736
    /* If at least one of them is mutable, we need a setter */
735
737
    need_setter = false;
736
738
    i = First(membervariables);
737
739
    while (i.item) {
738
740
      if (!GetFlag(i.item, "feature:immutable")) {
739
 
        need_setter = true;
 
741
        need_setter = true;
740
742
        break;
741
743
      }
742
744
      i = Next(i);
743
745
    }
744
 
    
 
746
 
745
747
    /* Create a function to set the values of the (mutable) variables */
746
748
    if (need_setter) {
747
749
      Wrapper *wrapper = NewWrapper();
749
751
      String *wname = Swig_name_wrapper(setter);
750
752
      Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL);
751
753
      Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n");
752
 
      
 
754
 
753
755
      i = First(membervariables);
754
756
      while (i.item) {
755
757
        if (!GetFlag(i.item, "feature:immutable")) {
770
772
 
771
773
      /* Dump wrapper code to the output file */
772
774
      Wrapper_print(wrapper, f_wrappers);
773
 
      
 
775
 
774
776
      /* Register it with Pike */
775
777
      String *description = NewString("tStr tFloat, tVoid");
776
778
      add_method("`->=", wname, description);
781
783
      Delete(setter);
782
784
      DelWrapper(wrapper);
783
785
    }
784
 
    
 
786
 
785
787
    /* Create a function to get the values of the (mutable) variables */
786
788
    Wrapper *wrapper = NewWrapper();
787
789
    String *getter = Swig_name_member(getClassPrefix(), (char *) "`->");
807
809
 
808
810
    /* Dump wrapper code to the output file */
809
811
    Wrapper_print(wrapper, f_wrappers);
810
 
    
 
812
 
811
813
    /* Register it with Pike */
812
814
    String *description = NewString("tStr, tMix");
813
815
    add_method("`->", wname, description);
814
816
    Delete(description);
815
 
    
 
817
 
816
818
    /* Clean up */
817
819
    Delete(wname);
818
820
    Delete(getter);
824
826
   * ------------------------------------------------------------ */
825
827
 
826
828
  virtual int membervariableHandler(Node *n) {
827
 
    List *membervariables = Getattr(getCurrentClass(),"membervariables");
 
829
    List *membervariables = Getattr(getCurrentClass(), "membervariables");
828
830
    if (!membervariables) {
829
831
      membervariables = NewList();
830
 
      Setattr(getCurrentClass(),"membervariables",membervariables);
 
832
      Setattr(getCurrentClass(), "membervariables", membervariables);
831
833
    }
832
 
    Append(membervariables,n);
 
834
    Append(membervariables, n);
833
835
    current = MEMBER_VAR;
834
836
    Language::membervariableHandler(n);
835
837
    current = NO_CPP;
848
850
    current = NO_CPP;
849
851
    return SWIG_OK;
850
852
  }
851
 
  
 
853
 
852
854
  /* ------------------------------------------------------------
853
855
   * memberconstantHandler()
854
856
   *
878
880
 * swig_pike()    - Instantiate module
879
881
 * ----------------------------------------------------------------------------- */
880
882
 
881
 
static Language * new_swig_pike() {
 
883
static Language *new_swig_pike() {
882
884
  return new PIKE();
883
885
}
884
 
extern "C" Language * swig_pike(void) {
 
886
extern "C" Language *swig_pike(void) {
885
887
  return new_swig_pike();
886
888
}