153
154
String *stripped_one;
155
156
while ((stripped_one = Strstr(p, "::"))) {
156
p = Char(stripped_one)+2;
157
p = Char(stripped_one) + 2;
159
160
int len = p - start - 1;
160
result = (char *)malloc(len);
161
strncpy(result, start, len-1);
161
result = (char *) malloc(len);
162
strncpy(result, start, len - 1);
164
165
return Char(result);
167
168
void add_linked_type(Node *n) {
168
169
#ifdef ALLEGROCL_CLASS_DEBUG
169
Printf(stderr,"Adding linked node of type: %s(%s) %s(%x)\n\n", nodeType(n),
170
Getattr(n,"storage"), Getattr(n,"name"),n);
170
Printf(stderr, "Adding linked node of type: %s(%s) %s(%x)\n\n", nodeType(n), Getattr(n, "storage"), Getattr(n, "name"), n);
172
if(!first_linked_type) {
172
if (!first_linked_type) {
173
173
first_linked_type = n;
174
Setattr(n,"allegrocl:last_linked_type",n);
174
Setattr(n, "allegrocl:last_linked_type", n);
176
Node *t = Getattr(first_linked_type,"allegrocl:last_linked_type");
177
Setattr(t,"allegrocl:next_linked_type",n);
178
Setattr(first_linked_type,"allegrocl:last_linked_type",n);
176
Node *t = Getattr(first_linked_type, "allegrocl:last_linked_type");
177
Setattr(t, "allegrocl:next_linked_type", n);
178
Setattr(first_linked_type, "allegrocl:last_linked_type", n);
182
182
void replace_linked_type(Node *old, Node *new_node) {
183
Node *prev = Getattr(old,"allegrocl:prev_linked_type");
185
Setattr(new_node,"allegrocl:next_linked_type",
186
Getattr(old,"allegrocl:next_linked_type"));
187
if(prev) Setattr(prev,"allegrocl:next_linked_type",new_node);
188
Delattr(old,"allegrocl:next_linked_type");
189
Delattr(old,"allegrocl:prev_linked_type");
183
Node *prev = Getattr(old, "allegrocl:prev_linked_type");
185
Setattr(new_node, "allegrocl:next_linked_type", Getattr(old, "allegrocl:next_linked_type"));
187
Setattr(prev, "allegrocl:next_linked_type", new_node);
188
Delattr(old, "allegrocl:next_linked_type");
189
Delattr(old, "allegrocl:prev_linked_type");
191
191
// check if we're replacing the first link.
192
if(first_linked_type == old) {
192
if (first_linked_type == old) {
193
193
first_linked_type = new_node;
194
Setattr(first_linked_type,"allegrocl:last_linked_type",
195
Getattr(old,"allegrocl:last_linked_type"));
194
Setattr(first_linked_type, "allegrocl:last_linked_type", Getattr(old, "allegrocl:last_linked_type"));
198
196
// check if we're replacing the last link.
199
if(Getattr(first_linked_type,"allegrocl:last_linked_type") == old)
200
Setattr(first_linked_type,"allegrocl:last_linked_type",new_node);
197
if (Getattr(first_linked_type, "allegrocl:last_linked_type") == old)
198
Setattr(first_linked_type, "allegrocl:last_linked_type", new_node);
203
201
void insert_linked_type_at(Node *old, Node *new_node, int before = 1) {
206
if(!first_linked_type) {
204
if (!first_linked_type) {
207
205
add_linked_type(new_node);
212
Setattr(new_node,"allegrocl:next_linked_type",
213
Getattr(old,"allegrocl:next_linked_type"));
214
Setattr(old,"allegrocl:next_linked_type",new_node);
215
if(Getattr(first_linked_type,"allegrocl:last_linked_type") == old)
216
Setattr(first_linked_type,"allegrocl:last_linked_type",new_node);
210
Setattr(new_node, "allegrocl:next_linked_type", Getattr(old, "allegrocl:next_linked_type"));
211
Setattr(old, "allegrocl:next_linked_type", new_node);
212
if (Getattr(first_linked_type, "allegrocl:last_linked_type") == old)
213
Setattr(first_linked_type, "allegrocl:last_linked_type", new_node);
218
215
Node *c = first_linked_type;
224
c = Getattr(c,"allegrocl:next_linked_type");
221
c = Getattr(c, "allegrocl:next_linked_type");
228
Setattr(new_node,"allegrocl:next_linked_type",c);
229
if(first_linked_type == c) {
225
Setattr(new_node, "allegrocl:next_linked_type", c);
226
if (first_linked_type == c) {
230
227
first_linked_type = new_node;
231
Setattr(first_linked_type,"allegrocl:last_linked_type",
232
Getattr(c,"allegrocl:last_linked_type"));
233
Delattr(c,"allegrocl:last_linked_type");
228
Setattr(first_linked_type, "allegrocl:last_linked_type", Getattr(c, "allegrocl:last_linked_type"));
229
Delattr(c, "allegrocl:last_linked_type");
235
if(p) Setattr(p,"allegrocl:next_linked_type",new_node);
232
Setattr(p, "allegrocl:next_linked_type", new_node);
305
void add_defined_foreign_type(Node *n,
309
String *ns=current_namespace) {
300
void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, String *name = 0, String *ns = current_namespace) {
312
303
String *ns_list = listify_namespace(ns);
313
String *templated = n ? Getattr(n,"template") : 0;
314
String *cDeclName = n ? Getattr(n,"classDeclaration:name") : 0;
304
String *templated = n ? Getattr(n, "template") : 0;
305
String *cDeclName = n ? Getattr(n, "classDeclaration:name") : 0;
316
#ifdef ALLEGROCL_TYPE_DEBUG
317
Printf(stderr,"IN A-D-F-T. (n=%x, ow=%d, k=%s, name=%s, ns=%s\n",
318
n, overwrite, k, name, ns);
319
Printf(stderr," templated = '%x', classDecl = '%x'\n", templated, cDeclName);
307
#ifdef ALLEGROCL_CLASS_DEBUG
308
Printf(stderr, "IN A-D-F-T. (n=%x, ow=%d, k=%s, name=%s, ns=%s\n", n, overwrite, k, name, ns);
309
Printf(stderr, " templated = '%x', classDecl = '%x'\n", templated, cDeclName);
322
name=Getattr(n,"sym:name");
323
if(!name) name = Getattr(n,"name");
313
name = Getattr(n, "sym:name");
315
name = Getattr(n, "name");
325
317
k = namespaced_name(n);
327
String *kind_of_type = Getattr(n,"kind");
319
String *kind_of_type = Getattr(n, "kind");
330
For typedefs of the form:
332
typedef __xxx { ... } xxx;
334
add_defined_foreign_type will be called once via classHandler
335
to define the type for 'struct __xxx', and once via typedefHandler
336
to associate xxx with 'struct __xxx'.
338
We create the following type to identifier mappings:
340
struct __xxx -> (swig-insert-id "xxx") via classHand
341
xxx -> (swig-insert-id "xxx") via typedefHand
343
and all references to this typedef'd struct will appear in
344
generated code as 'xxx'. For non-typedef'd structs, the
345
classHand mapping will be
347
struct __xxx -> (swig-insert-id "__xxx")
322
For typedefs of the form:
324
typedef __xxx { ... } xxx;
326
add_defined_foreign_type will be called once via classHandler
327
to define the type for 'struct __xxx', and once via typedefHandler
328
to associate xxx with 'struct __xxx'.
330
We create the following type to identifier mappings:
332
struct __xxx -> (swig-insert-id "xxx") via classHand
333
xxx -> (swig-insert-id "xxx") via typedefHand
335
and all references to this typedef'd struct will appear in
336
generated code as 'xxx'. For non-typedef'd structs, the
337
classHand mapping will be
339
struct __xxx -> (swig-insert-id "__xxx")
349
341
// Swig_print_node(n);
350
String *unnamed = Getattr(n,"unnamed");
351
if(kind_of_type && (!Strcmp(kind_of_type,"struct")
352
|| !Strcmp(kind_of_type,"union")) && cDeclName
342
String *unnamed = Getattr(n, "unnamed");
343
if (kind_of_type && (!Strcmp(kind_of_type, "struct")
344
|| !Strcmp(kind_of_type, "union")) && cDeclName && !unnamed) {
354
345
k = NewStringf("%s %s", kind_of_type, cDeclName);
356
if (!Strcmp(nodeType(n),"enum") && unnamed) {
347
if (!Strcmp(nodeType(n), "enum") && unnamed) {
357
348
name = NewStringf("%s%d", anon_type_name, anon_type_count++);
358
349
k = NewStringf("enum %s", name);
359
Setattr(n,"allegrocl:name",name);
350
Setattr(n, "allegrocl:name", name);
362
k = k ? k : Getattr(n,"name");
353
k = k ? k : Getattr(n, "name");
366
357
// Swig_print_node(n);
369
if(SwigType_istemplate(name)) {
360
if (SwigType_istemplate(name)) {
370
361
String *temp = strip_namespaces(SwigType_templateprefix(name));
371
362
name = NewStringf("%s%s%s", temp, SwigType_templateargs(name), SwigType_templatesuffix(name));
374
365
val = lookup_defined_foreign_type(k);
376
367
int is_fwd_ref = 0;
377
if(val) is_fwd_ref = !Strcmp(val,"forward-reference");
369
is_fwd_ref = !Strcmp(val, "forward-reference");
379
if(!val || overwrite || is_fwd_ref) {
380
#ifdef ALLEGROCL_TYPE_DEBUG
381
Printf(stderr, "Adding defined type '%s' = '%s' '%s' (overwrite=%d)\n",
382
k, ns, name, overwrite);
371
if (!val || overwrite || is_fwd_ref) {
372
#ifdef ALLEGROCL_CLASS_DEBUG
373
Printf(stderr, "Adding defined type '%s' = '%s' '%s' (overwrite=%d, in-class=%d)\n", k, ns, name, overwrite, in_class);
384
String *mangled_name_gen =
385
NewStringf("#.(swig-insert-id \"%s\" %s)", name, ns_list);
386
String *mangled_lname_gen =
387
NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", name, ns_list);
389
Setattr(defined_foreign_types,Copy(k),Copy(mangled_name_gen));
390
Setattr(defined_foreign_ltypes,Copy(k),Copy(mangled_lname_gen));
375
String *mangled_name_gen = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)", name, ns_list);
376
String *mangled_lname_gen = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", name, ns_list);
378
Setattr(defined_foreign_types, Copy(k), Copy(mangled_name_gen));
379
Setattr(defined_foreign_ltypes, Copy(k), Copy(mangled_lname_gen));
393
382
bool cpp_struct = Strstr(k, "struct ") ? true : false;
394
bool cpp_union = Strstr(k, "union ") ? true : false;
383
bool cpp_union = Strstr(k, "union ") ? true : false;
396
385
String *cpp_type = 0;
398
387
cpp_type = Copy(k);
399
388
Replaceall(cpp_type, "struct ", "");
400
389
} else if (cpp_union) {
402
391
Replaceall(cpp_type, "union ", "");
405
if(cpp_struct || cpp_union) {
406
#ifdef ALLEGROCL_TYPE_DEBUG
407
Printf(stderr, " Also adding defined type '%s' = '%s' '%s' (overwrite=%d)\n",
408
cpp_type, ns, name, overwrite);
394
if (cpp_struct || cpp_union) {
395
#ifdef ALLEGROCL_CLASS_DEBUG
396
Printf(stderr, " Also adding defined type '%s' = '%s' '%s' (overwrite=%d)\n", cpp_type, ns, name, overwrite);
410
Setattr(defined_foreign_types,Copy(cpp_type),Copy(mangled_name_gen));
411
Setattr(defined_foreign_ltypes,Copy(cpp_type),Copy(mangled_lname_gen));
398
Setattr(defined_foreign_types, Copy(cpp_type), Copy(mangled_name_gen));
399
Setattr(defined_foreign_ltypes, Copy(cpp_type), Copy(mangled_lname_gen));
414
#ifdef ALLEGROCL_TYPE_DEBUG
415
Printf(stderr,"looking to add %s/%s(%x) to linked_type_list...\n", k, name, n);
418
// Printf(stderr,"*** 1\n");
421
// Printf(stderr,"*** 1-a\n");
422
if(SwigType_istemplate(k)) {
423
SwigType *resolved = SwigType_typedef_resolve_all(k);
424
// Printf(stderr,"*** 1-b\n");
425
Node *match = find_linked_type_by_name(resolved);
427
// Printf(stderr, "*** temp-1\n");
431
#ifdef ALLEGROCL_CLASS_DEBUG
432
Printf(stderr,"Creating a new templateInst:\n");
433
Printf(stderr," name = %s\n", resolved);
434
Printf(stderr," sym:name = %s\n", name);
435
Printf(stderr," real-name = %s\n", k);
436
Printf(stderr," type = %s\n", resolved);
437
Printf(stderr," ns = %s\n\n", ns);
439
new_node = NewHash();
440
Setattr(new_node,"nodeType","templateInst");
441
Setattr(new_node,"name",Copy(resolved));
442
Setattr(new_node,"sym:name",Copy(name));
443
Setattr(new_node,"real-name",Copy(k));
444
Setattr(new_node,"type",Copy(resolved));
445
Setattr(new_node,"allegrocl:namespace",ns);
446
Setattr(new_node,"allegrocl:package",ns);
402
#ifdef ALLEGROCL_CLASS_DEBUG
403
Printf(stderr, "looking to add %s/%s(%x) to linked_type_list...\n", k, name, n);
406
// Printf(stderr,"*** 1\n");
409
// Printf(stderr,"*** 1-a\n");
410
if (SwigType_istemplate(k)) {
411
SwigType *resolved = SwigType_typedef_resolve_all(k);
412
// Printf(stderr,"*** 1-b\n");
413
Node *match = find_linked_type_by_name(resolved);
415
// Printf(stderr, "*** temp-1\n");
419
#ifdef ALLEGROCL_CLASS_DEBUG
420
Printf(stderr, "Creating a new templateInst:\n");
421
Printf(stderr, " name = %s\n", resolved);
422
Printf(stderr, " sym:name = %s\n", name);
423
Printf(stderr, " real-name = %s\n", k);
424
Printf(stderr, " type = %s\n", resolved);
425
Printf(stderr, " ns = %s\n\n", ns);
427
new_node = NewHash();
428
Setattr(new_node, "nodeType", "templateInst");
429
Setattr(new_node, "name", Copy(resolved));
430
Setattr(new_node, "sym:name", Copy(name));
431
Setattr(new_node, "real-name", Copy(k));
432
Setattr(new_node, "type", Copy(resolved));
433
Setattr(new_node, "allegrocl:namespace", ns);
434
Setattr(new_node, "allegrocl:package", ns);
450
if(!Strcmp(nodeType(new_node),"templateInst") && in_class) {
451
/* this is an implicit template instantiation found while
452
walking a class. need to insert this into the
453
linked_type list before the current class definition */
454
#ifdef ALLEGROCL_CLASS_DEBUG
455
Printf(stderr,"trying to insert a templateInst before a class\n");
457
insert_linked_type_at(in_class,new_node);
458
#ifdef ALLEGROCL_CLASS_DEBUG
459
Printf(stderr,"DID IT!\n");
462
// Printf(stderr,"*** 3\n");
463
add_linked_type(new_node);
465
Setattr(new_node,"allegrocl:synonym:is-primary","1");
438
if (!Strcmp(nodeType(new_node), "templateInst") && in_class) {
439
/* this is an implicit template instantiation found while
440
walking a class. need to insert this into the
441
linked_type list before the current class definition */
442
#ifdef ALLEGROCL_CLASS_DEBUG
443
Printf(stderr, "trying to insert a templateInst before a class\n");
445
insert_linked_type_at(in_class, new_node);
446
#ifdef ALLEGROCL_CLASS_DEBUG
447
Printf(stderr, "DID IT!\n");
467
// a synonym type was found (held in variable 'match')
468
// Printf(stderr, "setting primary synonym of %x to %x\n", new_node, match);
469
if(new_node == match) Printf(stderr,"Hey-4 * - '%s' is a synonym of iteself!\n", Getattr(new_node,"name"));
470
Setattr(new_node,"allegrocl:synonym-of",match);
471
// Printf(stderr,"*** 4\n");
450
// Printf(stderr,"*** 3\n");
472
451
add_linked_type(new_node);
453
Setattr(new_node, "allegrocl:synonym:is-primary", "1");
477
if(!Strcmp(nodeType(n),"cdecl") &&
478
!Strcmp(Getattr(n,"storage"),"typedef")) {
479
SwigType *type = SwigType_strip_qualifiers(Getattr(n,"type"));
480
#ifdef ALLEGROCL_TYPE_DEBUG
481
Printf(stderr,"Examining typedef '%s' for class references.\n", type);
482
// Printf(stderr, "type = %s, d-f-t=0x%x\n", type, Getattr(defined_foreign_types,type));
483
// bool a = Strstr(type,"struct ") && !Strcmp(Getattr(defined_foreign_types,type),Getattr(defined_foreign_types,k));
485
// Printf(stderr,", and'd=%d, not-and'd=%d\n", a, b);
487
if(SwigType_isclass(type)) {
488
#ifdef ALLEGROCL_CLASS_DEBUG
489
Printf(stderr,"Found typedef of a class '%s'\n", type);
492
For the following parsed expression:
494
typedef struct __xxx { ... } xxx;
496
if n is of kind "class" (defining the class 'struct __xxx'
497
then we add n to the linked type list.
499
if n is "cdecl" node of storage "typedef" (to note
500
that xxx is equivalent to 'struct __xxx' then we don't
501
want to add this node to the linked type list.
503
String *defined_type = lookup_defined_foreign_type(type);
504
String *defined_key_type = lookup_defined_foreign_type(k);
506
if(Strstr(type,"struct ") && defined_type &&
507
!Strcmp(defined_type,defined_key_type)) {
508
// mark as a synonym but don't add to linked_type list
509
Setattr(n,"allegrocl:synonym","1");
455
// a synonym type was found (held in variable 'match')
456
// Printf(stderr, "setting primary synonym of %x to %x\n", new_node, match);
457
if (new_node == match)
458
Printf(stderr, "Hey-4 * - '%s' is a synonym of iteself!\n", Getattr(new_node, "name"));
459
Setattr(new_node, "allegrocl:synonym-of", match);
460
// Printf(stderr,"*** 4\n");
461
add_linked_type(new_node);
466
if (!Strcmp(nodeType(n), "cdecl") && !Strcmp(Getattr(n, "storage"), "typedef")) {
467
SwigType *type = SwigType_strip_qualifiers(Getattr(n, "type"));
468
#ifdef ALLEGROCL_CLASS_DEBUG
469
Printf(stderr, "Examining typedef '%s' for class references.\n", type);
471
if (SwigType_isclass(type)) {
472
#ifdef ALLEGROCL_CLASS_DEBUG
473
Printf(stderr, "Found typedef of a class '%s'\n", type);
476
For the following parsed expression:
478
typedef struct __xxx { ... } xxx;
480
if n is of kind "class" (defining the class 'struct __xxx'
481
then we add n to the linked type list.
483
if n is "cdecl" node of storage "typedef" (to note
484
that xxx is equivalent to 'struct __xxx' then we don't
485
want to add this node to the linked type list.
487
String *defined_type = lookup_defined_foreign_type(type);
488
String *defined_key_type = lookup_defined_foreign_type(k);
490
if ((Strstr(type, "struct ") || Strstr(type, "union "))
491
&& defined_type && !Strcmp(defined_type, defined_key_type)) {
492
// mark as a synonym but don't add to linked_type list
493
// Printf(stderr,"*** 4.8\n");
494
Setattr(n, "allegrocl:synonym", "1");
496
SwigType *lookup_type = SwigType_istemplate(type) ? SwigType_typedef_resolve_all(type) : Copy(type);
497
match = find_linked_type_by_name(lookup_type);
499
Setattr(n, "allegrocl:synonym", "1");
500
Setattr(n, "allegrocl:synonym-of", match);
501
Setattr(n, "real-name", Copy(lookup_type));
503
// Printf(stderr, "*** pre-5: found match of '%s'(%x)\n", Getattr(match,"name"),match);
504
// if(n == match) Printf(stderr, "Hey-5 *** setting synonym of %x to %x\n", n, match);
505
// Printf(stderr,"*** 5\n");
511
SwigType *lookup_type = SwigType_istemplate(type) ?
512
SwigType_typedef_resolve_all(type) : Copy(type);
513
match = find_linked_type_by_name(lookup_type);
515
Setattr(n,"allegrocl:synonym","1");
516
Setattr(n,"allegrocl:synonym-of",match);
517
// if(n == match) Printf(stderr, "Hey-5 * setting synonym of %x to %x\n", n, match);
518
// Printf(stderr,"*** 5\n");
521
508
#ifdef ALLEGROCL_CLASS_DEBUG
522
Printf(stderr,"Creating classfoward node for struct stub in typedef.\n");
509
Printf(stderr, "Creating classfoward node for struct stub in typedef.\n");
524
Node *new_node = NewHash();
525
String *symname = Copy(type);
526
Replaceall(symname,"struct ","");
527
Setattr(new_node,"nodeType","classforward");
528
Setattr(new_node,"name",Copy(type));
529
Setattr(new_node,"sym:name",symname);
530
Setattr(new_node,"allegrocl:namespace",ns);
531
Setattr(new_node,"allegrocl:package",ns);
533
String *mangled_new_name =
534
NewStringf("#.(swig-insert-id \"%s\" %s)", symname, ns_list);
535
String *mangled_new_lname =
536
NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", symname, ns_list);
537
Setattr(defined_foreign_types,Copy(symname),Copy(mangled_new_name));
538
Setattr(defined_foreign_ltypes,Copy(symname),Copy(mangled_new_lname));
540
// Printf(stderr,"Weird! Can't find the type!\n");
541
add_forward_referenced_type(new_node);
542
add_linked_type(new_node);
544
Setattr(n,"allegrocl:synonym","1");
545
Setattr(n,"allegrocl:synonym-of",new_node);
552
// check if it's a pointer or reference to a class.
553
// Printf(stderr,"Checking if '%s' is a p. or r. to a class\n", type);
554
String *class_ref = class_from_class_or_class_ref(type);
556
match = find_linked_type_by_name(class_ref);
557
Setattr(n,"allegrocl:synonym","1");
558
Setattr(n,"allegrocl:synonym-of",match);
511
Node *new_node = NewHash();
512
String *symname = Copy(type);
513
Replaceall(symname, "struct ", "");
514
Setattr(new_node, "nodeType", "classforward");
515
Setattr(new_node, "name", Copy(type));
516
Setattr(new_node, "sym:name", symname);
517
Setattr(new_node, "allegrocl:namespace", ns);
518
Setattr(new_node, "allegrocl:package", ns);
520
String *mangled_new_name = NewStringf("#.(swig-insert-id \"%s\" %s)", symname, ns_list);
521
String *mangled_new_lname = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", symname, ns_list);
522
Setattr(defined_foreign_types, Copy(symname), Copy(mangled_new_name));
523
Setattr(defined_foreign_ltypes, Copy(symname), Copy(mangled_new_lname));
525
// Printf(stderr,"Weird! Can't find the type!\n");
526
add_forward_referenced_type(new_node);
527
add_linked_type(new_node);
529
Setattr(n, "allegrocl:synonym", "1");
530
Setattr(n, "allegrocl:synonym-of", new_node);
559
532
add_linked_type(n);
563
// synonym types have already been added.
564
// Printf(stderr,"*** 10\n");
565
if(!Getattr(n,"allegrocl:synonym")) add_linked_type(n);
566
} else if(Getattr(n,"template")) {
567
// Printf(stderr, "this is a class template node(%s)\n", nodeType(n));
568
String *resolved = SwigType_typedef_resolve_all(Getattr(n,"name"));
570
#ifdef ALLEGROCL_CLASS_DEBUG
571
Printf(stderr, " looking up %s for linked type match with %s...\n", Getattr(n,"sym:name"), resolved);
573
match = find_linked_type_by_name(resolved);
575
#ifdef ALLEGROCL_CLASS_DEBUG
576
Printf(stderr, "found no implicit instantiation of %%template node %s(%x)\n", Getattr(n,"name"),n);
580
Node *primary = get_primary_synonym_of(match);
582
Setattr(n,"allegrocl:synonym:is-primary","1");
583
Delattr(primary,"allegrocl:synonym:is-primary");
584
if(n == match) Printf(stderr, "Hey-7 * setting synonym of %x to %x\n (match = %x)", primary, n, match);
585
Setattr(primary,"allegrocl:synonym-of",n);
586
// Printf(stderr,"*** 7\n");
590
#ifdef ALLEGROCL_CLASS_DEBUG
591
Printf(stderr, "linking type %s(%x)\n", k, n);
593
// Printf(stderr,"*** 8\n");
537
// check if it's a pointer or reference to a class.
538
// Printf(stderr,"Checking if '%s' is a p. or r. to a class\n", type);
539
String *class_ref = class_from_class_or_class_ref(type);
541
match = find_linked_type_by_name(class_ref);
542
Setattr(n, "allegrocl:synonym", "1");
543
Setattr(n, "allegrocl:synonym-of", match);
548
// synonym types have already been added.
549
// Printf(stderr,"*** 10\n");
550
if (!Getattr(n, "allegrocl:synonym"))
552
} else if (Getattr(n, "template")) {
553
// Printf(stderr, "this is a class template node(%s)\n", nodeType(n));
554
String *resolved = SwigType_typedef_resolve_all(Getattr(n, "name"));
556
#ifdef ALLEGROCL_CLASS_DEBUG
557
Printf(stderr, " looking up %s for linked type match with %s...\n", Getattr(n, "sym:name"), resolved);
559
match = find_linked_type_by_name(resolved);
561
#ifdef ALLEGROCL_CLASS_DEBUG
562
Printf(stderr, "found no implicit instantiation of %%template node %s(%x)\n", Getattr(n, "name"), n);
566
Node *primary = get_primary_synonym_of(match);
568
Setattr(n, "allegrocl:synonym:is-primary", "1");
569
Delattr(primary, "allegrocl:synonym:is-primary");
571
Printf(stderr, "Hey-7 * setting synonym of %x to %x\n (match = %x)", primary, n, match);
572
Setattr(primary, "allegrocl:synonym-of", n);
573
// Printf(stderr,"*** 7\n");
577
#ifdef ALLEGROCL_CLASS_DEBUG
578
Printf(stderr, "linking type '%s'(%x)\n", k, n);
580
// Printf(stderr,"*** 8\n");
598
Delete(mangled_name_gen);
599
Delete(mangled_lname_gen);
585
Delete(mangled_name_gen);
586
Delete(mangled_lname_gen);
601
Swig_warning(WARN_TYPE_REDEFINED, Getfile(n), Getline(n),
602
"Attempting to store a foreign type that exists: %s\n", k);
588
Swig_warning(WARN_TYPE_REDEFINED, Getfile(n), Getline(n), "Attempting to store a foreign type that exists: %s (%s)\n", k, val);
607
#ifdef ALLEGROCL_TYPE_DEBUG
608
Printf(stderr,"OUT A-D-F-T\n");
593
#ifdef ALLEGROCL_CLASS_DEBUG
594
Printf(stderr, "OUT A-D-F-T\n");
1036
1017
// Printf(f_clhead, ";; from emit-stub-class\n");
1037
update_package_if_needed(n,f_clhead);
1018
update_package_if_needed(n, f_clhead);
1038
1019
Printf(f_clhead, ";; class template stub.\n");
1039
Printf(f_clhead,"(swig-def-foreign-stub \"%s\")\n", name);
1020
Printf(f_clhead, "(swig-def-foreign-stub \"%s\")\n", name);
1041
Setattr(n,"allegrocl:synonym:already-been-stubbed","1");
1022
Setattr(n, "allegrocl:synonym:already-been-stubbed", "1");
1043
1024
#ifdef ALLEGROCL_WRAP_DEBUG
1044
Printf(stderr,"emit_stub_class: EXIT\n");
1025
Printf(stderr, "emit_stub_class: EXIT\n");
1048
1029
void emit_synonym(Node *synonym) {
1050
1031
#ifdef ALLEGROCL_WRAP_DEBUG
1051
Printf(stderr,"emit_synonym: ENTER... \n");
1032
Printf(stderr, "emit_synonym: ENTER... \n");
1054
1035
// Printf(stderr,"in emit_synonym for %s(%x)\n", Getattr(synonym,"name"),synonym);
1055
int is_tempInst = !Strcmp(nodeType(synonym),"templateInst");
1036
int is_tempInst = !Strcmp(nodeType(synonym), "templateInst");
1056
1037
String *synonym_type;
1058
1039
Node *of = get_primary_synonym_of(synonym);
1061
synonym_type = Getattr(synonym,"real-name");
1042
// Printf(stderr, "*** using real-name '%s'\n", Getattr(synonym,"real-name"));
1043
synonym_type = Getattr(synonym, "real-name");
1063
synonym_type = Getattr(synonym,"name");
1045
// Printf(stderr, "*** using name '%s'\n", Getattr(synonym,"name"));
1046
synonym_type = Getattr(synonym, "name");
1066
String *synonym_ns = listify_namespace(Getattr(synonym,"allegrocl:namespace"));
1049
String *synonym_ns = listify_namespace(Getattr(synonym, "allegrocl:namespace"));
1050
String *syn_ltype, *syn_type, *of_ltype;
1067
1051
// String *of_cdeclname = Getattr(of,"allegrocl:classDeclarationName");
1068
String *of_ns = Getattr(of,"allegrocl:namespace");
1052
String *of_ns = Getattr(of, "allegrocl:namespace");
1069
1053
String *of_ns_list = listify_namespace(of_ns);
1070
1054
// String *of_name = of_cdeclname ? NewStringf("struct %s", Getattr(of,"name")) : NewStringf("%s::%s", of_ns, Getattr(of,"sym:name"));
1071
1055
// String *of_name = NewStringf("%s::%s", of_ns, Getattr(of,"sym:name"));
1072
1056
String *of_name = namespaced_name(of, of_ns);
1073
String *syn_ltype = lookup_defined_foreign_ltype(synonym_type);
1074
String *syn_type = lookup_defined_foreign_type(synonym_type);
1075
String *of_ltype = lookup_defined_foreign_ltype(of_name);
1058
if (CPlusPlus && !Strcmp(nodeType(synonym), "cdecl")) {
1059
syn_ltype = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", Getattr(synonym, "real-name"), synonym_ns);
1060
syn_type = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)", Getattr(synonym, "real-name"), synonym_ns);
1062
syn_ltype = lookup_defined_foreign_ltype(synonym_type);
1063
syn_type = lookup_defined_foreign_type(synonym_type);
1066
of_ltype = lookup_defined_foreign_ltype(of_name);
1077
1068
// Printf(f_clhead,";; from emit-synonym\n");
1078
Printf(f_clhead,"(swig-def-synonym-type %s\n %s\n %s)\n", syn_ltype, of_ltype, syn_type);
1069
Printf(f_clhead, "(swig-def-synonym-type %s\n %s\n %s)\n", syn_ltype, of_ltype, syn_type);
1080
1071
Delete(synonym_ns);
1081
1072
Delete(of_ns_list);
1082
1073
Delete(of_name);
1084
1075
#ifdef ALLEGROCL_WRAP_DEBUG
1085
Printf(stderr,"emit_synonym: EXIT\n");
1076
Printf(stderr, "emit_synonym: EXIT\n");
1089
1080
void emit_full_class(Node *n) {
1091
1082
#ifdef ALLEGROCL_WRAP_DEBUG
1092
Printf(stderr,"emit_full_class: ENTER... \n");
1083
Printf(stderr, "emit_full_class: ENTER... \n");
1095
String *name=Getattr(n, "sym:name");
1096
String *kind = Getattr(n,"kind");
1086
String *name = Getattr(n, "sym:name");
1087
String *kind = Getattr(n, "kind");
1098
1089
// Printf(stderr,"in emit_full_class: '%s'(%x).", Getattr(n,"name"),n);
1099
if(Getattr(n,"allegrocl:synonym-of")) {
1090
if (Getattr(n, "allegrocl:synonym-of")) {
1100
1091
// Printf(stderr,"but it's a synonym of something.\n");
1101
update_package_if_needed(n,f_clhead);
1092
update_package_if_needed(n, f_clhead);
1102
1093
emit_synonym(n);
1106
1096
// collect superclasses
1107
String *bases = Getattr(n,"bases");
1097
String *bases = Getattr(n, "bases");
1108
1098
String *supers = NewString("(");
1111
for (Iterator i=First(bases); i.item; i = Next(i)) {
1112
if (!first) Printf(supers," ");
1113
String *s = lookup_defined_foreign_ltype(Getattr(i.item,"name"));
1101
for (Iterator i = First(bases); i.item; i = Next(i)) {
1103
Printf(supers, " ");
1104
String *s = lookup_defined_foreign_ltype(Getattr(i.item, "name"));
1114
1105
// String *name = Getattr(i.item,"name");
1116
Printf(supers,"%s",s);
1107
Printf(supers, "%s", s);
1118
1109
#ifdef ALLEGROCL_TYPE_DEBUG
1119
Printf(stderr,"emit_templ_inst: did not find ltype for base class %s (%s)", Getattr(i.item,"name"), Getattr(n,"allegrocl:namespace"));
1110
Printf(stderr, "emit_templ_inst: did not find ltype for base class %s (%s)", Getattr(i.item, "name"), Getattr(n, "allegrocl:namespace"));
1124
Printf(supers,"ff:foreign-pointer");
1115
Printf(supers, "ff:foreign-pointer");
1118
Printf(supers, ")");
1129
1120
// Walk children to generate type definition.
1130
1121
String *slotdefs = NewString(" ");
1137
for (c=firstChild(n); c; c=nextSibling(c)) {
1138
String *storage_type = Getattr(c,"storage");
1139
if((!Strcmp(nodeType(c),"cdecl") &&
1140
(!storage_type || Strcmp(storage_type,"typedef")))) {
1141
String *access = Getattr(c,"access");
1128
for (c = firstChild(n); c; c = nextSibling(c)) {
1129
String *storage_type = Getattr(c, "storage");
1130
if ((!Strcmp(nodeType(c), "cdecl") && (!storage_type || Strcmp(storage_type, "typedef")))) {
1131
String *access = Getattr(c, "access");
1143
1133
// hack. why would decl have a value of "variableHandler" and now "0"?
1144
String *childDecl = Getattr(c,"decl");
1134
String *childDecl = Getattr(c, "decl");
1145
1135
// Printf(stderr,"childDecl = '%s' (%s)\n", childDecl, Getattr(c,"view"));
1146
if(!Strcmp(childDecl,"0"))
1136
if (!Strcmp(childDecl, "0"))
1147
1137
childDecl = NewString("");
1149
SwigType *childType=NewStringf("%s%s", childDecl,
1151
String *cname = (access && Strcmp(access,"public")) ?
1152
NewString("nil") : Copy(Getattr(c,"name"));
1139
SwigType *childType = NewStringf("%s%s", childDecl,
1140
Getattr(c, "type"));
1141
String *cname = (access && Strcmp(access, "public")) ? NewString("nil") : Copy(Getattr(c, "name"));
1154
if(!SwigType_isfunction(childType)) {
1155
// Printf(slotdefs, ";;; member functions don't appear as slots.\n ");
1156
// Printf(slotdefs, ";; ");
1157
String *ns = listify_namespace(Getattr(n, "allegrocl:package"));
1143
if (!SwigType_isfunction(childType)) {
1144
// Printf(slotdefs, ";;; member functions don't appear as slots.\n ");
1145
// Printf(slotdefs, ";; ");
1146
String *ns = listify_namespace(Getattr(n, "allegrocl:package"));
1159
1148
#ifdef ALLEGROCL_WRAP_DEBUG
1160
Printf(stderr, "slot name = '%s' ns = '%s' class-of '%s' and type = '%s'\n",
1161
cname, ns, name, childType);
1149
Printf(stderr, "slot name = '%s' ns = '%s' class-of '%s' and type = '%s'\n", cname, ns, name, childType);
1163
Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)",
1164
cname, ns, name, compose_foreign_type(childType));
1166
if(access && Strcmp(access,"public"))
1167
Printf(slotdefs, " ;; %s member", access);
1151
Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)", cname, ns, name, compose_foreign_type(childType));
1153
if (access && Strcmp(access, "public"))
1154
Printf(slotdefs, " ;; %s member", access);
1169
Printf(slotdefs, "\n ");
1156
Printf(slotdefs, "\n ");
1171
1158
Delete(childType);
1176
String *ns_list = listify_namespace(Getattr(n,"allegrocl:namespace"));
1177
update_package_if_needed(n,f_clhead);
1179
"(swig-def-foreign-class \"%s\"\n %s\n (:%s\n%s))\n\n",
1180
name, supers, kind, slotdefs);
1163
String *ns_list = listify_namespace(Getattr(n, "allegrocl:namespace"));
1164
update_package_if_needed(n, f_clhead);
1165
Printf(f_clhead, "(swig-def-foreign-class \"%s\"\n %s\n (:%s\n%s))\n\n", name, supers, kind, slotdefs);
1182
1167
Delete(supers);
1183
1168
Delete(ns_list);
1185
Setattr(n,"allegrocl:synonym:already-been-stubbed","1");
1170
Setattr(n, "allegrocl:synonym:already-been-stubbed", "1");
1186
1171
#ifdef ALLEGROCL_WRAP_DEBUG
1187
Printf(stderr,"emit_full_class: EXIT\n");
1172
Printf(stderr, "emit_full_class: EXIT\n");
1644
1622
* languages ignore the first method parsed.
1645
1623
* ----------------------------------------------------------------------------- */
1648
Swig_overload_rank(Node *n, bool script_lang_wrapping) {
1649
Overloaded nodes[MAX_OVERLOAD];
1651
Node *o = Getattr(n,"sym:overloaded");
1625
static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
1626
Overloaded nodes[MAX_OVERLOAD];
1628
Node *o = Getattr(n, "sym:overloaded");
1658
if (Getattr(c,"error")) {
1659
c = Getattr(c,"sym:nextSibling");
1636
if (Getattr(c, "error")) {
1637
c = Getattr(c, "sym:nextSibling");
1662
1640
/* if (SmartPointer && Getattr(c,"cplus:staticbase")) {
1663
c = Getattr(c,"sym:nextSibling");
1641
c = Getattr(c,"sym:nextSibling");
1667
1645
/* Make a list of all the declarations (methods) that are overloaded with
1668
1646
* this one particular method name */
1669
if (Getattr(c,"wrap:name")) {
1647
if (Getattr(c, "wrap:name")) {
1670
1648
nodes[nnodes].n = c;
1671
nodes[nnodes].parms = Getattr(c,"wrap:parms");
1649
nodes[nnodes].parms = Getattr(c, "wrap:parms");
1672
1650
nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms);
1673
1651
nodes[nnodes].error = 0;
1676
c = Getattr(c,"sym:nextSibling");
1654
c = Getattr(c, "sym:nextSibling");
1679
1657
/* Sort the declarations by required argument count */
1682
1660
for (i = 0; i < nnodes; i++) {
1683
for (j = i+1; j < nnodes; j++) {
1684
if (nodes[i].argc > nodes[j].argc) {
1685
Overloaded t = nodes[i];
1686
nodes[i] = nodes[j];
1661
for (j = i + 1; j < nnodes; j++) {
1662
if (nodes[i].argc > nodes[j].argc) {
1663
Overloaded t = nodes[i];
1664
nodes[i] = nodes[j];
1693
1671
/* Sort the declarations by argument types */
1696
for (i = 0; i < nnodes-1; i++) {
1697
if (nodes[i].argc == nodes[i+1].argc) {
1698
for (j = i+1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) {
1699
Parm *p1 = nodes[i].parms;
1700
Parm *p2 = nodes[j].parms;
1702
int num_checked = 0;
1703
while (p1 && p2 && (num_checked < nodes[i].argc)) {
1704
// Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type"));
1705
if (checkAttribute(p1,"tmap:in:numinputs","0")) {
1706
p1 = Getattr(p1,"tmap:in:next");
1709
if (checkAttribute(p2,"tmap:in:numinputs","0")) {
1710
p2 = Getattr(p2,"tmap:in:next");
1713
String *t1 = Getattr(p1,"tmap:typecheck:precedence");
1714
String *t2 = Getattr(p2,"tmap:typecheck:precedence");
1715
if ((!t1) && (!nodes[i].error)) {
1716
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n),
1717
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
1718
Getattr(nodes[i].n,"name"),ParmList_str_defaultargs(Getattr(nodes[i].n,"parms")),
1719
SwigType_str(Getattr(p1,"type"),0));
1721
} else if ((!t2) && (!nodes[j].error)) {
1722
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n),
1723
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
1724
Getattr(nodes[j].n,"name"),ParmList_str_defaultargs(Getattr(nodes[j].n,"parms")),
1725
SwigType_str(Getattr(p2,"type"),0));
1730
t1v = atoi(Char(t1));
1731
t2v = atoi(Char(t2));
1734
else if (!t1 && t2) differ = 1;
1735
else if (t2 && !t1) differ = -1;
1736
else if (!t1 && !t2) differ = -1;
1739
Overloaded t = nodes[i];
1740
nodes[i] = nodes[j];
1743
} else if ((differ == 0) && (Strcmp(t1,"0") == 0)) {
1744
t1 = Getattr(p1,"ltype");
1746
t1 = SwigType_ltype(Getattr(p1,"type"));
1747
if (Getattr(p1,"tmap:typecheck:SWIGTYPE")) {
1748
SwigType_add_pointer(t1);
1750
Setattr(p1,"ltype",t1);
1752
t2 = Getattr(p2,"ltype");
1754
t2 = SwigType_ltype(Getattr(p2,"type"));
1755
if (Getattr(p2,"tmap:typecheck:SWIGTYPE")) {
1756
SwigType_add_pointer(t2);
1758
Setattr(p2,"ltype",t2);
1761
/* Need subtype check here. If t2 is a subtype of t1, then we need to change the
1764
if (SwigType_issubtype(t2,t1)) {
1765
Overloaded t = nodes[i];
1766
nodes[i] = nodes[j];
1770
if (Strcmp(t1,t2) != 0) {
1774
} else if (differ) {
1777
if (Getattr(p1,"tmap:in:next")) {
1778
p1 = Getattr(p1,"tmap:in:next");
1780
p1 = nextSibling(p1);
1782
if (Getattr(p2,"tmap:in:next")) {
1783
p2 = Getattr(p2,"tmap:in:next");
1785
p2 = nextSibling(p2);
1789
/* See if declarations differ by const only */
1790
String *d1 = Getattr(nodes[i].n,"decl");
1791
String *d2 = Getattr(nodes[j].n,"decl");
1793
String *dq1 = Copy(d1);
1794
String *dq2 = Copy(d2);
1795
if (SwigType_isconst(d1)) {
1796
Delete(SwigType_pop(dq1));
1798
if (SwigType_isconst(d2)) {
1799
Delete(SwigType_pop(dq2));
1801
if (Strcmp(dq1,dq2) == 0) {
1803
if (SwigType_isconst(d1) && !SwigType_isconst(d2)) {
1804
if (script_lang_wrapping) {
1805
// Swap nodes so that the const method gets ignored (shadowed by the non-const method)
1806
Overloaded t = nodes[i];
1807
nodes[i] = nodes[j];
1811
if (!nodes[j].error) {
1812
if (script_lang_wrapping) {
1813
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
1814
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
1815
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
1816
Getfile(nodes[i].n), Getline(nodes[i].n));
1818
if (!Getattr(nodes[j].n, "overload:ignore"))
1819
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
1820
"Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n",
1821
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
1822
Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms),
1823
Getfile(nodes[i].n), Getline(nodes[i].n));
1827
} else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) {
1829
if (!nodes[j].error) {
1830
if (script_lang_wrapping) {
1831
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
1832
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
1833
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
1834
Getfile(nodes[i].n), Getline(nodes[i].n));
1836
if (!Getattr(nodes[j].n, "overload:ignore"))
1837
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
1838
"Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n",
1839
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
1840
Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms),
1841
Getfile(nodes[i].n), Getline(nodes[i].n));
1852
if (!nodes[j].error) {
1853
if (script_lang_wrapping) {
1854
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
1855
"Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n",
1856
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
1857
SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "",
1858
Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms),
1859
SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "",
1860
Getfile(nodes[i].n),Getline(nodes[i].n));
1862
if (!Getattr(nodes[j].n, "overload:ignore"))
1863
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
1864
"Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n",
1865
Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms),
1866
SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "",
1867
Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms),
1868
SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "",
1869
Getfile(nodes[i].n),Getline(nodes[i].n));
1674
for (i = 0; i < nnodes - 1; i++) {
1675
if (nodes[i].argc == nodes[i + 1].argc) {
1676
for (j = i + 1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) {
1677
Parm *p1 = nodes[i].parms;
1678
Parm *p2 = nodes[j].parms;
1680
int num_checked = 0;
1681
while (p1 && p2 && (num_checked < nodes[i].argc)) {
1682
// Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type"));
1683
if (checkAttribute(p1, "tmap:in:numinputs", "0")) {
1684
p1 = Getattr(p1, "tmap:in:next");
1687
if (checkAttribute(p2, "tmap:in:numinputs", "0")) {
1688
p2 = Getattr(p2, "tmap:in:next");
1691
String *t1 = Getattr(p1, "tmap:typecheck:precedence");
1692
String *t2 = Getattr(p2, "tmap:typecheck:precedence");
1693
if ((!t1) && (!nodes[i].error)) {
1694
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n),
1695
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
1696
Getattr(nodes[i].n, "name"), ParmList_str_defaultargs(Getattr(nodes[i].n, "parms")), SwigType_str(Getattr(p1, "type"), 0));
1698
} else if ((!t2) && (!nodes[j].error)) {
1699
Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n),
1700
"Overloaded %s(%s) not supported (no type checking rule for '%s').\n",
1701
Getattr(nodes[j].n, "name"), ParmList_str_defaultargs(Getattr(nodes[j].n, "parms")), SwigType_str(Getattr(p2, "type"), 0));
1706
t1v = atoi(Char(t1));
1707
t2v = atoi(Char(t2));
1709
} else if (!t1 && t2)
1713
else if (!t1 && !t2)
1717
Overloaded t = nodes[i];
1718
nodes[i] = nodes[j];
1721
} else if ((differ == 0) && (Strcmp(t1, "0") == 0)) {
1722
t1 = Getattr(p1, "ltype");
1724
t1 = SwigType_ltype(Getattr(p1, "type"));
1725
if (Getattr(p1, "tmap:typecheck:SWIGTYPE")) {
1726
SwigType_add_pointer(t1);
1728
Setattr(p1, "ltype", t1);
1730
t2 = Getattr(p2, "ltype");
1732
t2 = SwigType_ltype(Getattr(p2, "type"));
1733
if (Getattr(p2, "tmap:typecheck:SWIGTYPE")) {
1734
SwigType_add_pointer(t2);
1736
Setattr(p2, "ltype", t2);
1739
/* Need subtype check here. If t2 is a subtype of t1, then we need to change the
1742
if (SwigType_issubtype(t2, t1)) {
1743
Overloaded t = nodes[i];
1744
nodes[i] = nodes[j];
1748
if (Strcmp(t1, t2) != 0) {
1752
} else if (differ) {
1755
if (Getattr(p1, "tmap:in:next")) {
1756
p1 = Getattr(p1, "tmap:in:next");
1758
p1 = nextSibling(p1);
1760
if (Getattr(p2, "tmap:in:next")) {
1761
p2 = Getattr(p2, "tmap:in:next");
1763
p2 = nextSibling(p2);
1767
/* See if declarations differ by const only */
1768
String *d1 = Getattr(nodes[i].n, "decl");
1769
String *d2 = Getattr(nodes[j].n, "decl");
1771
String *dq1 = Copy(d1);
1772
String *dq2 = Copy(d2);
1773
if (SwigType_isconst(d1)) {
1774
Delete(SwigType_pop(dq1));
1776
if (SwigType_isconst(d2)) {
1777
Delete(SwigType_pop(dq2));
1779
if (Strcmp(dq1, dq2) == 0) {
1781
if (SwigType_isconst(d1) && !SwigType_isconst(d2)) {
1782
if (script_lang_wrapping) {
1783
// Swap nodes so that the const method gets ignored (shadowed by the non-const method)
1784
Overloaded t = nodes[i];
1785
nodes[i] = nodes[j];
1789
if (!nodes[j].error) {
1790
if (script_lang_wrapping) {
1791
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
1792
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
1793
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
1795
if (!Getattr(nodes[j].n, "overload:ignore"))
1796
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
1797
"Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n",
1798
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
1799
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
1803
} else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) {
1805
if (!nodes[j].error) {
1806
if (script_lang_wrapping) {
1807
Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n),
1808
"Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n",
1809
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
1811
if (!Getattr(nodes[j].n, "overload:ignore"))
1812
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
1813
"Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n",
1814
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
1815
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n));
1826
if (!nodes[j].error) {
1827
if (script_lang_wrapping) {
1828
Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n),
1829
"Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n",
1830
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
1831
SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "",
1832
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms),
1833
SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n));
1835
if (!Getattr(nodes[j].n, "overload:ignore"))
1836
Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n),
1837
"Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n",
1838
Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms),
1839
SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "",
1840
Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms),
1841
SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n));
1949
1918
/* DB 04/02/2003: Not sure this is necessary with tmap:in:numinputs */
1951
if (parms && (p = Getattr(parms,"emit:varargs"))) {
1952
if (!nextSibling(p)) {
1920
if (parms && (p = Getattr(parms,"emit:varargs"))) {
1921
if (!nextSibling(p)) {
1960
String *id_converter_type(SwigType const *type)
1929
String *id_converter_type(SwigType const *type) {
1962
1930
SwigType *t = Copy(type);
1963
1931
String *result = 0;
1965
if (SwigType_ispointer(t))
1933
if (SwigType_ispointer(t)) {
1967
1934
SwigType_pop(t);
1968
1935
String *pointee = id_converter_type(t);
1969
1936
result = NewStringf("(:* %s)", pointee);
1970
1937
Delete(pointee);
1972
else if (SwigType_ismemberpointer(t))
1938
} else if (SwigType_ismemberpointer(t)) {
1974
1939
String *klass = SwigType_parm(t);
1975
1940
SwigType_pop(t);
1976
1941
String *member = id_converter_type(t);
1977
1942
result = NewStringf("(:member \"%s\" %s)", klass, member);
1979
1944
Delete(member);
1981
else if (SwigType_isreference(t))
1945
} else if (SwigType_isreference(t)) {
1983
1946
SwigType_pop(t);
1984
1947
String *referencee = id_converter_type(t);
1985
1948
result = NewStringf("(:& %s)", referencee);
1986
1949
Delete(referencee);
1988
else if (SwigType_isarray(t))
1950
} else if (SwigType_isarray(t)) {
1990
1951
String *size = SwigType_parm(t);
1991
1952
SwigType_pop(t);
1992
1953
String *element_type = id_converter_type(t);
1993
1954
result = NewStringf("(:array %s \"%s\")", element_type, size);
1995
1956
Delete(element_type);
1997
else if (SwigType_isfunction(t))
1957
} else if (SwigType_isfunction(t)) {
1999
1958
result = NewString("(:function (");
2000
1959
String *parmlist_str = SwigType_parm(t);
2001
1960
List *parms = SwigType_parmlist(parmlist_str);
2003
for (Iterator i = First(parms); i.item; )
2005
String *parm = id_converter_type((SwigType *)i.item);
1962
for (Iterator i = First(parms); i.item;) {
1963
String *parm = id_converter_type((SwigType *) i.item);
2006
1964
Printf(result, "%s", parm);
2008
if (i.item) Printf(result, " ");
1967
Printf(result, " ");
2011
1970
SwigType_pop(t);
2012
1971
String *ret = id_converter_type(t);
2013
1972
Printf(result, ") %s)", ret);
2015
1974
Delete(parmlist_str);
2019
else if (SwigType_isqualifier(t))
1977
} else if (SwigType_isqualifier(t)) {
2021
1978
result = NewString("(:qualified (");
2022
String *qualifiers_str = Copy(SwigType_parm(t)); // ?!
2023
// Replaceall below SEGVs if we don't put the Copy here...
1979
String *qualifiers_str = Copy(SwigType_parm(t)); // ?!
1980
// Replaceall below SEGVs if we don't put the Copy here...
2024
1981
SwigType_pop(t);
2025
1982
String *qualifiee = id_converter_type(t);
2027
1984
Replaceall(qualifiers_str, " ", " :");
2028
if (Len(qualifiers_str) > 0) Printf(result, ":");
1985
if (Len(qualifiers_str) > 0)
1986
Printf(result, ":");
2029
1987
Printf(result, "%s) %s)", qualifiers_str, qualifiee);
2031
1989
Delete(qualifiers_str);
2032
1990
Delete(qualifiee);
2034
else if (SwigType_istemplate(t))
1991
} else if (SwigType_istemplate(t)) {
2036
1992
result = NewStringf("(:template \"%s\")", t);
2038
else /* if (SwigType_issimple(t)) */
2040
if (Strstr(Char(t), "::"))
1993
} else { /* if (SwigType_issimple(t)) */
1995
if (Strstr(Char(t), "::")) {
2042
1996
result = listify_namespace(t);
2046
1998
result = NewStringf("\"%s\"", t);
2054
static ParmList *parmlist_with_names(ParmList *pl)
2056
ParmList* pl2 = CopyParmList(pl);
2057
for (Parm *p = pl, *p2 = pl2; p2;
2058
p=nextSibling(p), p2=nextSibling(p2))
2006
static ParmList *parmlist_with_names(ParmList *pl) {
2007
ParmList *pl2 = CopyParmList(pl);
2008
for (Parm *p = pl, *p2 = pl2; p2; p = nextSibling(p), p2 = nextSibling(p2)) {
2060
2009
if (!Getattr(p2, "name"))
2061
2010
Setattr(p2, "name", Getattr(p2, "lname"));
2062
2011
Setattr(p2, "name", strip_namespaces(Getattr(p2, "name")));
2063
2012
Setattr(p2, "tmap:ctype", Getattr(p, "tmap:ctype"));
2065
String *temp = Getattr(p,"tmap:lin");
2014
String *temp = Getattr(p, "tmap:lin");
2067
2016
Setattr(p2, "tmap:lin", temp);
2068
Setattr(p2, "tmap:lin:next", Getattr(p,"tmap:lin:next"));
2017
Setattr(p2, "tmap:lin:next", Getattr(p, "tmap:lin:next"));
2074
static String *parmlist_str_id_converter(ParmList *pl)
2023
static String *parmlist_str_id_converter(ParmList *pl) {
2076
2024
String *result = NewString("");
2077
for (Parm *p = pl; p; )
2079
String *lispy_type = id_converter_type(Getattr(p, "type"));
2025
for (Parm *p = pl; p;) {
2026
String *lispy_type = id_converter_type(Getattr(p, "type"));
2080
2027
Printf(result, "(\"%s\" %s)", Getattr(p, "name"), lispy_type);
2081
2028
Delete(lispy_type);
2082
if ((p=nextSibling(p))) Printf(result, " ");
2029
if ((p = nextSibling(p)))
2030
Printf(result, " ");
2087
2035
String *collect_others_args(Node *overload) {
2088
String *overloaded_from = Getattr(overload,"sym:overloaded");
2036
String *overloaded_from = Getattr(overload, "sym:overloaded");
2089
2037
String *others_args = NewString("");
2090
2038
int first_overload = 1;
2092
for (Node *overload2 = overloaded_from;
2094
overload2 = Getattr(overload2,"sym:nextSibling"))
2096
if (overload2 == overload ||
2097
GetInt(overload2, "overload:ignore"))
2100
ParmList *opl = parmlist_with_names(Getattr(overload2, "wrap:parms"));
2101
String *args = parmlist_str_id_converter(opl);
2102
if (!first_overload)
2103
Printf(others_args, "\n ");
2104
Printf(others_args, "(%s)", args);
2040
for (Node *overload2 = overloaded_from; overload2; overload2 = Getattr(overload2, "sym:nextSibling")) {
2041
if (overload2 == overload || GetInt(overload2, "overload:ignore"))
2044
ParmList *opl = parmlist_with_names(Getattr(overload2, "wrap:parms"));
2045
String *args = parmlist_str_id_converter(opl);
2046
if (!first_overload)
2047
Printf(others_args, "\n ");
2048
Printf(others_args, "(%s)", args);
2109
2053
return others_args;
2112
2056
struct IDargs {
2118
IDargs() : name(0), type(0), klass(0), arity(0) {}
2120
String* full_quoted_str() {
2062
IDargs():name(0), type(0), klass(0), arity(0) {
2063
} String *full_quoted_str() {
2121
2064
String *result = no_others_quoted_str();
2122
if (arity) Printf(result, " :arity %s", arity);
2066
Printf(result, " :arity %s", arity);
2126
String* no_others_quoted_str() {
2070
String *no_others_quoted_str() {
2127
2071
String *result = NewString("");
2128
2072
Printf(result, "\"%s\" :type :%s", name, type);
2129
if (klass) Printf(result, " :class \"%s\"", klass);
2074
Printf(result, " :class \"%s\"", klass);
2133
String* noname_str() {
2078
String *noname_str() {
2134
2079
String *result = NewString("");
2135
2080
Printf(result, " :type :%s", type);
2136
if (klass) Printf(result, " :class \"%s\"", klass);
2137
if (arity) Printf(result, " :arity %s", arity);
2082
Printf(result, " :class \"%s\"", klass);
2084
Printf(result, " :arity %s", arity);
2141
IDargs* id_converter_arguments(Node *n)
2143
IDargs* result = (IDargs*)GetVoid(n, "allegrocl:id-converter-args");
2144
if (!result) result = new IDargs;
2088
IDargs *id_converter_arguments(Node *n) {
2089
IDargs *result = (IDargs *) GetVoid(n, "allegrocl:id-converter-args");
2091
result = new IDargs;
2147
2094
if (!result->name) {
2148
2095
result->name = Getattr(n, "allegrocl:old-sym:name");
2149
if (!result->name) result->name = Getattr(n, "sym:name");
2097
result->name = Getattr(n, "sym:name");
2150
2098
result->name = Copy(result->name);
2154
if (result->type) Delete(result->type);
2102
Delete(result->type);
2155
2103
if (!Getattr(n, "allegrocl:kind"))
2156
2104
Setattr(n, "allegrocl:kind", "function");
2157
2105
if (Strstr(Getattr(n, "name"), "operator "))
2158
2106
Replaceall(Getattr(n, "allegrocl:kind"), "function", "operator");
2159
if (Strstr(Getattr(n, "allegrocl:kind"), "variable"))
2107
if (Strstr(Getattr(n, "allegrocl:kind"), "variable")) {
2161
2108
int name_end = Len(Getattr(n, "sym:name")) - 4;
2162
2109
char *str = Char(Getattr(n, "sym:name"));
2163
String *get_set = NewString(str+name_end+1);
2110
String *get_set = NewString(str + name_end + 1);
2164
2111
result->type = Copy(Getattr(n, "allegrocl:kind"));
2165
2112
Replaceall(result->type, "variable", "");
2166
2113
Printf(result->type, "%ster", get_set);
2167
2114
Delete(get_set);
2171
2116
result->type = Copy(Getattr(n, "allegrocl:kind"));
2175
if (Strstr(result->type, "member "))
2120
if (Strstr(result->type, "member ")) {
2177
2121
Replaceall(result->type, "member ", "");
2178
2122
if (!result->klass)
2179
result->klass = Copy(Getattr(parent_node_skipping_extends(n),
2123
result->klass = Copy(Getattr(parent_node_skipping_extends(n), "sym:name"));
2184
2126
if (Getattr(n, "sym:overloaded")) {
2185
if(result->arity) Delete(result->arity);
2128
Delete(result->arity);
2186
2129
result->arity = NewStringf("%d",
2187
2130
// emit_num_arguments(Getattr(n, "wrap:parms")));
2188
2131
emit_num_lin_arguments(Getattr(n, "wrap:parms")));
2132
Printf(stderr, "got arity of '%s' node '%s' '%x'\n", result->arity, Getattr(n,"name"), Getattr(n,"wrap:parms"));
2191
2135
SetVoid(n, "allegrocl:id-converter-args", result);
2195
int ALLEGROCL :: emit_buffered_defuns(Node *n) {
2139
int ALLEGROCL::emit_buffered_defuns(Node *n) {
2197
Node *overloaded_from = Getattr(n,"sym:overloaded");
2141
Node *overloaded_from = Getattr(n, "sym:overloaded");
2201
2145
if (!overloaded_from) {
2202
wrap = Getattr(n,"allegrocl:lisp-wrap");
2146
wrap = Getattr(n, "allegrocl:lisp-wrap");
2204
Printf(f_clwrap,"%s\n",wrap);
2205
Delattr(n,"allegrocl:lisp-wrap");
2148
Printf(f_clwrap, "%s\n", wrap);
2149
Delattr(n, "allegrocl:lisp-wrap");
2208
for (Node *overload = overloaded_from;
2210
overload = Getattr(overload,"sym:nextSibling"))
2212
String *others_args = collect_others_args(overload);
2213
wrap = Getattr(overload, "allegrocl:lisp-wrap");
2152
for (Node *overload = overloaded_from; overload; overload = Getattr(overload, "sym:nextSibling")) {
2153
String *others_args = collect_others_args(overload);
2154
wrap = Getattr(overload, "allegrocl:lisp-wrap");
2215
Replaceall(wrap, "@@OTHERS-ARGS-GO-HERE@@", others_args);
2156
Replaceall(wrap, "@@OTHERS-ARGS-GO-HERE@@", others_args);
2216
2157
// IDargs* id_args = id_converter_arguments(overload);
2217
2158
// Replaceall(id_args->others_args, "@@OTHERS-ARGS-GO-HERE@@", others_args);
2219
if (!GetInt(overload, "overload:ignore"))
2220
Printf(f_clwrap, "%s", wrap);
2160
if (!GetInt(overload, "overload:ignore"))
2161
Printf(f_clwrap, "%s", wrap);
2222
Delattr(overload, "allegrocl:lisp-wrap");
2163
Delattr(overload, "allegrocl:lisp-wrap");
2226
2167
return SWIG_OK;
2229
String *dispatching_type(Parm* p) {
2170
String *dispatching_type(Parm *p) {
2230
2171
String *result = 0;
2232
String *parsed = Getattr(p, "type"); //Swig_cparse_type(Getattr(p,"tmap:ctype"));
2173
String *parsed = Getattr(p, "type"); //Swig_cparse_type(Getattr(p,"tmap:ctype"));
2233
2174
String *cl_t = SwigType_typedef_resolve_all(parsed);
2235
2176
Hash *typemap = Swig_typemap_search("lispclass", parsed, Getattr(p, "name"), 0);
2236
2177
// Printf(stderr,"inspecting type '%s' for class\n", parsed);
2237
2178
// Printf(stderr," cfcocr = '%s' res_all = '%s'\n",
2238
// class_from_class_or_class_ref(parsed), cl_t);
2179
// class_from_class_or_class_ref(parsed), cl_t);
2240
2181
result = Copy(Getattr(typemap, "code"));
2242
2183
String *lookup_type = class_from_class_or_class_ref(parsed);
2243
if(lookup_type) result = lookup_defined_foreign_ltype(lookup_type);
2185
result = lookup_defined_foreign_ltype(lookup_type);
2246
2188
// if (!result && SwigType_ispointer(cl_t)) {
2247
2189
// SwigType_pop(cl_t);
2248
2190
// result = lookup_defined_foreign_ltype(cl_t);
2285
2228
int last_arity = -1;
2286
2229
for (Iterator i = First(overloads); i.item; i = Next(i)) {
2287
2230
int arity = emit_num_lin_arguments(Getattr(i.item, "wrap:parms"));
2288
if (arity == last_arity) continue;
2231
if (arity == last_arity)
2290
2234
Printf(f_clwrap, "%s%d", last_arity == -1 ? "" : " ", arity);
2292
2236
last_arity = arity;
2294
2238
Printf(f_clwrap, ")))\n");
2296
2240
Delete(id_args);
2297
2241
Delete(overloads);
2299
2243
#ifdef ALLEGROCL_WRAP_DEBUG
2300
Printf(stderr,"emit_dispatch_defun: EXIT\n");
2244
Printf(stderr, "emit_dispatch_defun: EXIT\n");
2303
2247
return SWIG_OK;
2306
int ALLEGROCL :: emit_defun(Node *n, File *f_cl) {
2250
int ALLEGROCL::emit_defun(Node *n, File *f_cl) {
2307
2251
#ifdef ALLEGROCL_WRAP_DEBUG
2308
Printf(stderr,"emit_defun: ENTER... ");
2252
Printf(stderr, "emit_defun: ENTER... ");
2311
2255
#ifdef ALLEGROCL_DEBUG
2312
2256
int auto_generated = Cmp(Getattr(n, "view"), "globalfunctionHandler");
2313
Printf(stderr, "%s%sfunction %s%s%s\n",
2314
auto_generated ? "> " : "", Getattr(n, "sym:overloaded")
2315
? "overloaded " : "", current_namespace,
2316
(current_namespace) > 0 ? "::" : "", Getattr(n, "sym:name"));
2257
Printf(stderr, "%s%sfunction %s%s%s\n", auto_generated ? "> " : "", Getattr(n, "sym:overloaded")
2258
? "overloaded " : "", current_namespace, (current_namespace) > 0 ? "::" : "", Getattr(n, "sym:name"));
2317
2259
Printf(stderr, " (view: %s)\n", Getattr(n, "view"));
2320
2262
String *funcname = Getattr(n, "allegrocl:old-sym:name");
2321
if (!funcname) funcname = Getattr(n, "sym:name");
2322
String *mangled_name = Getattr(n,"wrap:name");
2264
funcname = Getattr(n, "sym:name");
2265
String *mangled_name = Getattr(n, "wrap:name");
2323
2266
ParmList *pl = parmlist_with_names(Getattr(n, "wrap:parms"));
2325
2268
// attach typemap info.
2326
2269
Wrapper *wrap = NewWrapper();
2327
2270
Swig_typemap_attach_parms("lin", pl, wrap);
2328
Swig_typemap_lookup_new("lout",n,"result",0);
2271
Swig_typemap_lookup_new("lout", n, "result", 0);
2330
SwigType *result_type = Swig_cparse_type(Getattr(n,"tmap:ctype"));
2273
SwigType *result_type = Swig_cparse_type(Getattr(n, "tmap:ctype"));
2331
2274
// prime the pump, with support for OUTPUT, INOUT typemaps.
2332
Printf(wrap->code,"(let ((ACL_ffresult swig:*void*)\n ACL_result)\n $body\n (if (eq ACL_ffresult swig:*void*)\n (values-list ACL_result)\n (values-list (cons ACL_ffresult ACL_result))))");
2276
"(cl::let ((ACL_ffresult %s:*void*)\n ACL_result)\n $body\n (cl::if (cl::eq ACL_ffresult %s:*void*)\n (cl::values-list ACL_result)\n (cl::values-list (cl::cons ACL_ffresult ACL_result))))",
2277
swig_package, swig_package);
2335
int largnum = 0, argnum=0, first=1;
2280
int largnum = 0, argnum = 0, first = 1;
2336
2281
// int varargs=0;
2337
if (Generate_Wrapper)
2282
if (Generate_Wrapper) {
2339
2283
String *extra_parms = id_converter_arguments(n)->noname_str();
2340
2284
if (Getattr(n, "sym:overloaded"))
2341
Printf(f_cl, "(swig-defmethod (\"%s\" \"%s\"%s)\n",
2342
funcname, mangled_name, extra_parms);
2285
Printf(f_cl, "(swig-defmethod (\"%s\" \"%s\"%s)\n", funcname, mangled_name, extra_parms);
2344
Printf(f_cl, "(swig-defun (\"%s\" \"%s\"%s)\n",
2345
funcname, mangled_name, extra_parms);
2287
Printf(f_cl, "(swig-defun (\"%s\" \"%s\"%s)\n", funcname, mangled_name, extra_parms);
2346
2288
Delete(extra_parms);
2351
Printf(f_cl, "(swig-defun (\"%s\" \"%s\")\n", funcname,
2352
Generate_Wrapper ? mangled_name : funcname);
2292
Printf(f_cl, "(swig-defun (\"%s\" \"%s\")\n", funcname, Generate_Wrapper ? mangled_name : funcname);
2355
2295
//////////////////////////////////////
2463
2414
int ff_foreign_ptr = 0;
2465
2416
ff_foreign_ptr = 1;
2466
2417
lclass = NewStringf("ff:foreign-pointer");
2469
2419
#ifdef ALLEGROCL_WRAP_DEBUG
2470
Printf(stderr,"for output wrapping %s: type=%s, ctype=%s\n",
2471
Getattr(n,"name"), Getattr(n,"type"),
2472
Swig_cparse_type(Getattr(n,"tmap:ctype")));
2475
if(lclass) Replaceall(wrap->code,"$lclass", lclass);
2420
Printf(stderr, "for output wrapping %s: type=%s, ctype=%s\n", Getattr(n, "name"), Getattr(n, "type"), Swig_cparse_type(Getattr(n, "tmap:ctype")));
2424
Replaceall(wrap->code, "$lclass", lclass);
2426
Replaceall(wrap->code, "$out_fftype", out_ffitype);
2427
if (deref_out_ffitype)
2428
Replaceall(wrap->code, "$*out_fftype", deref_out_ffitype);
2477
2429
// if(Replaceall(wrap->code,"$lclass", lclass) && !isPtrReturn) {
2478
2430
// Swig_warning(WARN_LANG_RETURN_TYPE,Getfile(n), Getline(n),
2479
2431
// "While Wrapping %s, replaced a $lclass reference when return type is non-pointer %s!\n",
2480
2432
// Getattr(n,"name"), cl_t);
2483
Replaceall(wrap->code,"$body", NewStringf("(swig-ff-call%s)", wrap->locals));
2435
Replaceall(wrap->code, "$body", NewStringf("(swig-ff-call%s)", wrap->locals));
2484
2436
// Replaceall(wrap->code,"$body",
2485
// (!Strcmp(result_type,"void") ?
2486
// NewStringf("(swig-ff-call%s)", wrap->locals) :
2487
// NewStringf("(push (swig-ff-call%s) ACL_result)", wrap->locals)));
2488
String* ldestructor = Copy(lclass);
2437
// (!Strcmp(result_type,"void") ?
2438
// NewStringf("(swig-ff-call%s)", wrap->locals) :
2439
// NewStringf("(push (swig-ff-call%s) ACL_result)", wrap->locals)));
2440
String *ldestructor = Copy(lclass);
2489
2441
if (ff_foreign_ptr)
2490
2442
Replaceall(ldestructor, ldestructor, "identity");
2492
2444
Replaceall(ldestructor, ":type :class", ":type :destructor");
2493
if (Replaceall(wrap->code,"$ldestructor", ldestructor) > 0 &&
2445
if (Replaceall(wrap->code, "$ldestructor", ldestructor) > 0 && ff_foreign_ptr) {
2495
2446
Swig_warning(WARN_LANG_RETURN_TYPE, Getfile(n), Getline(n),
2496
"While wrapping %s, replaced an $ldestructor reference "
2497
"when there was no Lisp class.\n",
2447
"While wrapping %s, replaced an $ldestructor reference " "when there was no Lisp class.\n", Getattr(n, "name"));
2500
2449
Delete(ldestructor);
2502
Printf(f_cl, ")\n"); /* finish arg list */
2451
Printf(f_cl, ")\n"); /* finish arg list */
2504
2453
/////////////////////////////////////////////////////
2505
2454
// Lisp foreign call return type and optimizations //
2506
2455
/////////////////////////////////////////////////////
2507
Printf(f_cl, " (:returning (%s %s)",
2508
compose_foreign_type(result_type),
2509
get_lisp_type(Getattr(n, "type"), "result"));
2456
Printf(f_cl, " (:returning (%s %s)", compose_foreign_type(result_type), get_lisp_type(Getattr(n, "type"), "result"));
2511
2458
for (Iterator option = First(n); option.item; option = Next(option)) {
2512
if (Strncmp("feature:ffargs:", option.key, 15)) continue;
2459
if (Strncmp("feature:ffargs:", option.key, 15))
2513
2461
String *option_val = option.item;
2514
2462
String *option_name = NewString(Char(option.key) + 14);
2515
2463
Replaceall(option_name, "_", "-");
2517
2465
// TODO: varargs vs call-direct ?
2518
2466
Printf(f_cl, "\n %s %s", option_name, option_val);
2520
2468
Delete(option_name);
2523
Printf(f_cl,")\n %s)\n\n", wrap->code);
2471
Printf(f_cl, ")\n %s)\n\n", wrap->code);
2524
2472
// Wrapper_print(wrap, stderr);
2526
2474
Delete(result_type);
2708
2654
return SWIG_OK;
2711
int ALLEGROCL :: constructorHandler(Node *n)
2657
int ALLEGROCL::constructorHandler(Node *n) {
2713
2658
#ifdef ALLEGROCL_DEBUG
2714
2659
Printf(stderr, "constructor %s\n", Getattr(n, "name"));
2716
2661
// Swig_print_node(n);
2717
2662
Setattr(n, "allegrocl:kind", "constructor");
2718
2663
Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name"));
2720
2665
// Let SWIG generate a global forwarding function.
2721
2666
return Language::constructorHandler(n);
2724
int ALLEGROCL :: destructorHandler(Node *n)
2669
int ALLEGROCL::destructorHandler(Node *n) {
2726
2670
#ifdef ALLEGROCL_DEBUG
2727
2671
Printf(stderr, "destructor %s\n", Getattr(n, "name"));
2730
2674
Setattr(n, "allegrocl:kind", "destructor");
2731
2675
Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name"));
2733
2677
// Let SWIG generate a global forwarding function.
2734
2678
return Language::destructorHandler(n);
2737
int ALLEGROCL :: constantWrapper(Node *n) {
2681
int ALLEGROCL::constantWrapper(Node *n) {
2739
2683
#ifdef ALLEGROCL_DEBUG
2740
2684
Printf(stderr, "constant %s\n", Getattr(n, "name"));
2743
if(Generate_Wrapper) {
2687
if (Generate_Wrapper) {
2744
2688
// Setattr(n,"wrap:name",mangle_name(n, "ACLPP"));
2745
String *const_type = Getattr(n,"type");
2689
String *const_type = Getattr(n, "type");
2747
2691
String *const_val = 0;
2748
String *raw_const = Getattr(n,"value");
2692
String *raw_const = Getattr(n, "value");
2750
if(SwigType_type(const_type) == T_STRING) {
2751
const_val = NewStringf("\"%s\"",raw_const);
2694
if (SwigType_type(const_type) == T_STRING) {
2695
const_val = NewStringf("\"%s\"", raw_const);
2752
2696
} else if (SwigType_type(const_type) == T_CHAR) {
2753
const_val = NewStringf("'%s'",raw_const);
2697
const_val = NewStringf("'%s'", raw_const);
2755
2699
const_val = Copy(raw_const);
2758
SwigType_add_qualifier(const_type,"const");
2759
SwigType_add_qualifier(const_type,"static");
2761
String *ppcname = NewStringf("ACLppc_%s",Getattr(n,"name"));
2762
Printf(f_cxx,"static const %s = %s;\n", SwigType_lstr(const_type,ppcname),
2765
Setattr(n,"name",ppcname);
2766
SetFlag(n,"feature:immutable");
2702
SwigType_add_qualifier(const_type, "const");
2703
SwigType_add_qualifier(const_type, "static");
2705
String *ppcname = NewStringf("ACLppc_%s", Getattr(n, "name"));
2706
Printf(f_cxx, "static const %s = %s;\n", SwigType_lstr(const_type, ppcname), const_val);
2708
Setattr(n, "name", ppcname);
2709
SetFlag(n, "feature:immutable");
2768
2711
Delete(const_val);
2769
2712
return variableWrapper(n);
2772
String *type=Getattr(n, "type");
2773
String *value = Getattr(n,"value");
2774
String *converted_value=convert_literal(value, type);
2775
String *name=Getattr(n, "sym:name");
2715
String *type = Getattr(n, "type");
2716
String *value = Getattr(n, "value");
2717
String *converted_value = convert_literal(value, type);
2718
String *name = Getattr(n, "sym:name");
2777
2720
Setattr(n, "allegrocl:kind", "constant");
2778
2721
Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name"));
2781
Printf(stdout, "constant %s is of type %s. value: %s\n",
2782
name, type, converted_value);
2724
Printf(stdout, "constant %s is of type %s. value: %s\n", name, type, converted_value);
2785
if(converted_value) {
2786
Printf(f_clwrap, "(swig-defconstant \"%s\" %s)\n",
2787
name, converted_value);
2727
if (converted_value) {
2728
Printf(f_clwrap, "(swig-defconstant \"%s\" %s)\n", name, converted_value);
2789
Swig_warning(WARN_LANG_DISCARD_CONST, Getfile(n), Getline(n),
2790
"Unable to parse constant value '%s'. Setting to NIL\n", value);
2730
Swig_warning(WARN_LANG_DISCARD_CONST, Getfile(n), Getline(n), "Unable to parse constant value '%s'. Setting to NIL\n", value);
2791
2731
Printf(f_clwrap, "(swig-defconstant \"%s\" nil #| %s |#)\n", name, value);
2794
2734
Delete(converted_value);
2796
2736
return SWIG_OK;
2799
int ALLEGROCL :: globalvariableHandler(Node *n) {
2800
if(Generate_Wrapper) return Language::globalvariableHandler(n);
2739
int ALLEGROCL::globalvariableHandler(Node *n) {
2740
if (Generate_Wrapper)
2741
return Language::globalvariableHandler(n);
2802
2743
// String *name = Getattr(n, "name");
2803
SwigType *type = Getattr(n,"type");
2744
SwigType *type = Getattr(n, "type");
2804
2745
SwigType *ctype;
2805
2746
SwigType *rtype = SwigType_typedef_resolve_all(type);
2807
2748
int pointer_added = 0;
2809
if(SwigType_isclass(rtype)) {
2750
if (SwigType_isclass(rtype)) {
2810
2751
SwigType_add_pointer(type);
2811
2752
SwigType_add_pointer(rtype);
2812
2753
pointer_added = 1;
2815
ctype = SwigType_str(type,0);
2756
ctype = SwigType_str(type, 0);
2816
2757
// EXPORT <SwigType_str> <mangled_name>;
2817
2758
// <SwigType_str> <mangled_name> = <name>;
2818
2759
// Printf(f_cxx, "EXPORT %s %s;\n%s %s = %s%s;\n", ctype, mangled_name,
2819
// ctype, mangled_name, (pointer_added ? "&" : ""), name);
2760
// ctype, mangled_name, (pointer_added ? "&" : ""), name);
2821
2762
Printf(f_clwrap, "(swig-defvar \"%s\" \"%s\" :type %s)\n",
2822
Getattr(n,"sym:name"), Getattr(n,"sym:name"),
2823
((SwigType_isconst(type)) ? ":constant" : ":variable"));
2763
Getattr(n, "sym:name"), Getattr(n, "sym:name"), ((SwigType_isconst(type)) ? ":constant" : ":variable"));
2825
2765
return SWIG_OK;
2828
int ALLEGROCL :: variableWrapper(Node *n) {
2768
int ALLEGROCL::variableWrapper(Node *n) {
2829
2769
#ifdef ALLEGROCL_DEBUG
2830
2770
Printf(stderr, "variable %s\n", Getattr(n, "name"));
2893
2829
return Language::membervariableHandler(n);
2896
int ALLEGROCL :: typedefHandler(Node *n) {
2832
int ALLEGROCL::typedefHandler(Node *n) {
2898
2834
#ifdef ALLEGROCL_TYPE_DEBUG
2899
Printf(stderr,"In typedefHAND\n");
2835
Printf(stderr, "In typedefHAND\n");
2900
2836
// Swig_print_node(n);
2903
2839
// has the side-effect of noting any implicit
2904
2840
// template instantiations in type.
2905
Delete(compose_foreign_type(Getattr(n,"type")));
2841
Delete(compose_foreign_type(Getattr(n, "type")));
2907
String *sym_name = Getattr(n,"sym:name");
2843
String *sym_name = Getattr(n, "sym:name");
2910
2846
String *type_ref;
2913
2849
#ifdef ALLEGROCL_TYPE_DEBUG
2914
Printf(stderr, " typedef in class '%s'(%x)\n", Getattr(in_class,"sym:name"),in_class);
2916
Setattr(n,"allegrocl:typedef:in-class",in_class);
2850
Printf(stderr, " typedef in class '%s'(%x)\n", Getattr(in_class, "sym:name"), in_class);
2852
Setattr(n, "allegrocl:typedef:in-class", in_class);
2920
String *class_name = Getattr(in_class,"name");
2921
name = NewStringf("%s__%s",class_name,sym_name);
2856
String *class_name = Getattr(in_class, "name");
2857
name = NewStringf("%s__%s", class_name, sym_name);
2922
2858
type_ref = NewStringf("%s::%s", class_name, sym_name);
2923
Setattr(n,"allegrocl:in-class",in_class);
2859
Setattr(n, "allegrocl:in-class", in_class);
2925
2861
name = Copy(sym_name);
2926
type_ref = Copy(Getattr(n,"name"));
2862
type_ref = Copy(Getattr(n, "name"));
2929
Setattr(n,"allegrocl:namespace",current_namespace);
2865
Setattr(n, "allegrocl:namespace", current_namespace);
2930
2866
add_defined_foreign_type(n, 0, type_ref, name);
2932
2868
#ifdef ALLEGROCL_TYPE_DEBUG
2933
Printf(stderr,"Out typedefHAND\n");
2869
Printf(stderr, "Out typedefHAND\n");
2936
2872
return SWIG_OK;
2939
2875
// forward referenced classes are added specially to defined_foreign_types
2940
int ALLEGROCL :: classforwardDeclaration(Node *n) {
2876
int ALLEGROCL::classforwardDeclaration(Node *n) {
2941
2877
add_forward_referenced_type(n);
2942
2878
return SWIG_OK;
2945
int ALLEGROCL :: classHandler(Node *n) {
2881
int ALLEGROCL::classHandler(Node *n) {
2946
2882
#ifdef ALLEGROCL_DEBUG
2947
Printf(stderr, "class %s::%s\n", current_namespace,
2948
Getattr(n, "sym:name"));
2883
Printf(stderr, "class %s::%s\n", current_namespace, Getattr(n, "sym:name"));
2950
String *name=Getattr(n, "sym:name");
2951
String *kind = Getattr(n,"kind");
2885
String *name = Getattr(n, "sym:name");
2886
String *kind = Getattr(n, "kind");
2953
2888
// maybe just remove this check and get rid of the else clause below.
2954
if (Strcmp(kind, "struct") == 0 ||
2955
Strcmp(kind, "class") == 0 ||
2956
Strcmp(kind, "union") == 0)
2889
if (Strcmp(kind, "struct") == 0 || Strcmp(kind, "class") == 0 || Strcmp(kind, "union") == 0) {
2958
2890
if (Generate_Wrapper)
2959
2891
return cppClassHandler(n);
2961
2893
return cClassHandler(n);
2965
Printf(stderr, "Don't know how to deal with %s kind of class yet.\n",
2895
Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", kind);
2967
2896
Printf(stderr, " (name: %s)\n", name);
2968
2897
SWIG_exit(EXIT_FAILURE);
2969
2898
return SWIG_OK;
2972
2901
return SWIG_OK;
2975
int ALLEGROCL :: cClassHandler(Node *n) {
2904
int ALLEGROCL::cClassHandler(Node *n) {
2976
2905
// String *cDeclName = Getattr(n,"classDeclaration:name");
2977
2906
// String *name= Getattr(n, "sym:name");
2978
2907
// String *kind = Getattr(n,"kind");