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

« back to all changes in this revision

Viewing changes to Source/Swig/symbol.c

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * See the file LICENSE for information on usage and redistribution.
10
10
 * ----------------------------------------------------------------------------- */
11
11
 
12
 
char cvsroot_symbol_c[] = "$Header: /cvsroot/swig/SWIG/Source/Swig/symbol.c,v 1.20 2004/12/01 00:56:35 marcelomatus Exp $";
 
12
char cvsroot_symbol_c[] = "$Header: /cvsroot/swig/SWIG/Source/Swig/symbol.c,v 1.31 2005/10/14 13:36:12 marcelomatus Exp $";
13
13
 
14
14
#include "swig.h"
15
15
#include "swigwarn.h"
16
16
#include <ctype.h>
17
17
 
 
18
/* #define SWIG_DEBUG*/
18
19
/* -----------------------------------------------------------------------------
19
20
 * Synopsis
20
21
 *
173
174
static Hash *symtabs = 0;         /* Hash of all symbol tables by fully-qualified name */
174
175
static Hash *global_scope = 0;    /* Global scope */
175
176
 
 
177
/* common attribute keys, to avoid calling find_key all the times */
 
178
static String *k_name = 0;
 
179
static String *k_coloncolon = 0;
 
180
static String *k_decl = 0;
 
181
static String *k_cdecl = 0;
 
182
static String *k_uname = 0;
 
183
static String *k_type = 0;
 
184
static String *k_templateparms = 0;
 
185
static String *k_symtab = 0;
 
186
static String *k_csymtab = 0;
 
187
static String *k_using = 0;
 
188
static String *k_inherit = 0;
 
189
static String *k_value = 0;
 
190
static String *k_symboltable = 0;
 
191
static String *k_storage = 0;
 
192
static String *k_typedef = 0;
 
193
static String *k_symname = 0;
 
194
static String *k_symsymtab = 0;
 
195
static String *k_sympreviousSibling = 0;
 
196
static String *k_symnextSibling = 0;
 
197
static String *k_symovername = 0;
 
198
static String *k_symoverloaded = 0;
 
199
static String *k_csympreviousSibling = 0;
 
200
static String *k_csymnextSibling = 0;
 
201
static String *k_enumitem = 0;
 
202
 
 
203
 
176
204
#if 0
177
205
void
178
206
Swig_symbol_dump_symtable() {
196
224
 
197
225
void
198
226
Swig_symbol_init() {
 
227
  k_name = NewString("name");
 
228
  k_coloncolon = NewString("::");
 
229
  k_decl = NewString("decl");
 
230
  k_cdecl = NewString("cdecl");
 
231
  k_uname = NewString("uname");
 
232
  k_type = NewString("type");
 
233
  k_templateparms = NewString("templateparms");
 
234
  k_symtab = NewString("symtab");
 
235
  k_symsymtab = NewString("sym:symtab");
 
236
  k_csymtab = NewString("csymtab");
 
237
  k_using = NewString("using");
 
238
  k_inherit = NewString("inherit");
 
239
  k_value = NewString("value");
 
240
  k_symboltable = NewString("symboltable");
 
241
  k_storage = NewString("storage");
 
242
  k_typedef = NewString("typedef");
 
243
  k_symname = NewString("sym:name");
 
244
  k_sympreviousSibling = NewString("sym:previousSibling");
 
245
  k_symnextSibling = NewString("sym:nextSibling");
 
246
  k_symovername = NewString("sym:overname");
 
247
  k_symoverloaded = NewString("sym:overloaded");
 
248
  k_csympreviousSibling = NewString("csym:previousSibling");
 
249
  k_csymnextSibling = NewString("csym:nextSibling");
 
250
  k_enumitem = NewString("enumitem");
 
251
 
199
252
  current = NewHash();
200
253
  current_symtab = NewHash();
201
254
  ccurrent = NewHash();
202
 
  set_nodeType(current_symtab,"symboltable");
203
 
  Setattr(current_symtab,"symtab",current);
204
 
  Setattr(current_symtab,"csymtab", ccurrent);
 
255
  set_nodeType(current_symtab,k_symboltable);
 
256
  Setattr(current_symtab,k_symtab,current);
 
257
  Setattr(current_symtab,k_csymtab, ccurrent);
205
258
 
206
259
  /* Set the global scope */
207
260
  symtabs = NewHash();
218
271
void
219
272
Swig_symbol_setscopename(const String_or_char *name) {
220
273
  String *qname;
221
 
  assert(!Getattr(current_symtab,"name"));
222
 
  Setattr(current_symtab,"name",name);
 
274
  assert(!Getattr(current_symtab,k_name));
 
275
  Setattr(current_symtab,k_name,name);
223
276
 
224
277
  /* Set nested scope in parent */
225
278
 
227
280
 
228
281
  /* Save a reference to this scope */
229
282
  Setattr(symtabs,qname,current_symtab);
 
283
  Delete(qname);
230
284
}
231
285
 
232
286
/* -----------------------------------------------------------------------------
237
291
 
238
292
String *
239
293
Swig_symbol_getscopename() {
240
 
  return Getattr(current_symtab,"name");
 
294
  return Getattr(current_symtab,k_name);
241
295
}
242
296
 
243
297
/* -----------------------------------------------------------------------------
249
303
Symtab *
250
304
Swig_symbol_getscope(const String_or_char *name) {
251
305
  if (!symtabs) return 0;
252
 
  if (Strcmp(name,"::") == 0) name = "";
 
306
  if (Strcmp(name,k_coloncolon) == 0) name = "";
253
307
  return Getattr(symtabs,name);
254
308
}
255
309
 
270
324
  if (parent) {
271
325
    result = Swig_symbol_qualifiedscopename(parent);
272
326
  }
273
 
  name = Getattr(symtab,"name");
 
327
  name = Getattr(symtab,k_name);
274
328
  if (name) {
275
329
    if (!result) {
276
330
      result = NewString("");
299
353
  hsyms = NewHash();
300
354
  h = NewHash();
301
355
 
302
 
  set_nodeType(h,"symboltable");  
303
 
  Setattr(h,"symtab",hsyms);
 
356
  set_nodeType(h,k_symboltable);  
 
357
  Setattr(h,k_symtab,hsyms);
304
358
  set_parentNode(h,current_symtab);
305
359
  
306
360
  n = lastChild(current_symtab);
312
366
  set_lastChild(current_symtab,h);
313
367
  current = hsyms;
314
368
  ccurrent = NewHash();
315
 
  Setattr(h,"csymtab",ccurrent);
 
369
  Setattr(h,k_csymtab,ccurrent);
316
370
  current_symtab = h;
317
371
  return current_symtab;
318
372
}
327
381
Swig_symbol_setscope(Symtab *sym) {
328
382
  Symtab *ret = current_symtab;
329
383
  current_symtab = sym;
330
 
  current = Getattr(sym,"symtab");
 
384
  current = Getattr(sym,k_symtab);
331
385
  assert(current);
332
 
  ccurrent = Getattr(sym,"csymtab");
 
386
  ccurrent = Getattr(sym,k_csymtab);
333
387
  assert(ccurrent);
334
388
  return ret;
335
389
}
346
400
  Hash *h = current_symtab;
347
401
  current_symtab = parentNode(current_symtab);
348
402
  assert(current_symtab);
349
 
  current = Getattr(current_symtab,"symtab");
 
403
  current = Getattr(current_symtab,k_symtab);
350
404
  assert(current);
351
 
  ccurrent = Getattr(current_symtab,"csymtab");
 
405
  ccurrent = Getattr(current_symtab,k_csymtab);
352
406
  assert(ccurrent);
353
407
  return h;
354
408
}
372
426
 
373
427
void
374
428
Swig_symbol_alias(String_or_char *aliasname, Symtab *s) {
375
 
  String *qname;
376
 
  qname = Swig_symbol_qualifiedscopename(current_symtab);
 
429
  String *qname = Swig_symbol_qualifiedscopename(current_symtab);
377
430
  if (qname) {
378
431
    Printf(qname,"::%s", aliasname);
379
432
  } else {
382
435
  if (!Getattr(symtabs,qname)) {
383
436
    Setattr(symtabs,qname,s);
384
437
  }
 
438
  Delete(qname);
385
439
}
386
440
 
387
441
/* -----------------------------------------------------------------------------
392
446
 
393
447
void Swig_symbol_inherit(Symtab *s) {
394
448
  int i;
395
 
  List *inherit = Getattr(current_symtab,"inherit");
 
449
  List *inherit = Getattr(current_symtab,k_inherit);
396
450
  if (!inherit) {
397
451
    inherit = NewList();
398
 
    Setattr(current_symtab,"inherit", inherit);
 
452
    Setattr(current_symtab,k_inherit, inherit);
399
453
  }
400
454
  assert(s != current_symtab);
401
455
  for (i = 0; i < Len(inherit); i++) {
433
487
   */
434
488
 
435
489
  if (!name) return;
 
490
  if (SwigType_istemplate(name)) {
 
491
    String *cname = NewString(name);
 
492
    String *dname = Swig_symbol_template_deftype(cname,0);
 
493
    if (Strcmp(dname,name)) {    
 
494
      Swig_symbol_cadd(dname, n);
 
495
    }
 
496
    Delete(dname);
 
497
    Delete(cname);
 
498
  }
 
499
 
 
500
#ifdef SWIG_DEBUG
 
501
  Printf(stderr,"symbol_cadd %s %x\n", name, n);
 
502
#endif
436
503
  cn = Getattr(ccurrent,name);
437
504
 
438
505
  if (cn && (Getattr(cn,"sym:typename"))) {
474
541
        /* already added. Bail */
475
542
        return;
476
543
      }
477
 
      fn = Getattr(fn,"csym:nextSibling");
 
544
      fn = Getattr(fn,k_csymnextSibling);
478
545
    }
479
546
    if (pn) {
480
 
      Setattr(pn,"csym:nextSibling",append);
 
547
      Setattr(pn,k_csymnextSibling,append);
481
548
    }
482
549
  }
483
550
 
494
561
 
495
562
  {
496
563
    Node *td = n;
497
 
    while (td && (Strcmp(nodeType(td),"cdecl") == 0) && (checkAttribute(td,"storage","typedef"))) {
 
564
    while (td && (Strcmp(nodeType(td),k_cdecl) == 0) && (checkAttribute(td,k_storage,k_typedef))) {
498
565
      SwigType *type;
499
566
      Node *td1;
500
 
      type = Copy(Getattr(td,"type"));
501
 
      SwigType_push(type,Getattr(td,"decl"));
 
567
      type = Copy(Getattr(td,k_type));
 
568
      SwigType_push(type,Getattr(td,k_decl));
502
569
      td1 = Swig_symbol_clookup(type,0);
 
570
 
 
571
      /* Fix patetic case #1214313:
 
572
         
 
573
         class Foo
 
574
         {
 
575
         };
 
576
         
 
577
         typedef Foo FooBar;
 
578
         
 
579
         class CBaz
 
580
         {
 
581
         public:
 
582
         typedef FooBar Foo;
 
583
         };
 
584
 
 
585
         ie, when Foo -> FooBar -> Foo, jump one scope up when possible.
 
586
         
 
587
      */
 
588
      if (td1 && checkAttribute(td1,k_storage,k_typedef)) {
 
589
        String *st = Getattr(td1,k_type);
 
590
        String *sn = Getattr(td,k_name);
 
591
        if (st && sn && (Strcmp(st, sn) == 0)) {
 
592
          Symtab *sc = parentNode(current_symtab);
 
593
          if (sc) td1 = Swig_symbol_clookup(type,sc);
 
594
        }
 
595
      }
 
596
 
503
597
      Delete(type);
504
598
      if (td1 == td) break;
505
599
      td = td1;
506
600
      if (td) {
507
 
        Symtab *st = Getattr(td,"symtab");
 
601
        Symtab *st = Getattr(td,k_symtab);
508
602
        if (st) {
509
 
          Swig_symbol_alias(Getattr(n,"name"),st);
 
603
          Swig_symbol_alias(Getattr(n,k_name),st);
510
604
          break;
511
605
        }
512
606
      }
532
626
  int      nt = 0, ct = 0;
533
627
  int      pn = 0;
534
628
  int      u1 = 0, u2 = 0;
535
 
  String   *name;
 
629
  String   *name, *overname;
536
630
 
537
631
  /* See if the node has a name.  If so, we place in the C symbol table for this
538
632
     scope. We don't worry about overloading here---the primary purpose of this
557
651
     stays in the C symbol table (so that it can be expanded using %template).
558
652
   */
559
653
 
560
 
  name = Getattr(n,"name");
561
 
  if (name) {
 
654
  name = Getattr(n,k_name);
 
655
  if (name && Len(name)) {
562
656
    Swig_symbol_cadd(name,n);
563
657
  }
564
658
 
565
659
  /* No symbol name defined.  We return. */
566
660
  if (!symname) {
567
 
    Setattr(n,"sym:symtab",current_symtab);
 
661
    Setattr(n,k_symsymtab,current_symtab);
568
662
    return n;
569
663
  }
570
664
 
571
665
  /* If node is ignored. We don't proceed any further */
572
 
  if (Getattr(n,"feature:ignore")) return n;
 
666
  if (GetFlag(n,"feature:ignore")) return n;
573
667
 
574
668
  /* See if the symbol already exists in the table */
575
669
  c = Getattr(current,symname);
603
697
      cl = c;
604
698
      while (cl) {
605
699
        pcl = cl;
606
 
        cl = Getattr(cl,"sym:nextSibling");
 
700
        cl = Getattr(cl,k_symnextSibling);
607
701
      }
608
 
      Setattr(pcl,"sym:nextSibling",n);
609
 
      Setattr(n,"sym:symtab", current_symtab);
610
 
      Setattr(n,"sym:name", symname);
611
 
      Setattr(n,"sym:previousSibling", pcl);
 
702
      Setattr(pcl,k_symnextSibling,n);
 
703
      Setattr(n,k_symsymtab, current_symtab);
 
704
      Setattr(n,k_symname, symname);
 
705
      Setattr(n,k_sympreviousSibling, pcl);
612
706
      return n;
613
707
    }
614
708
    if (Getattr(n,"allows_typedef")) nt = 1;
630
724
        other = n;
631
725
      }
632
726
      /* Make sure the other node is a typedef */
633
 
      s = Getattr(other,"storage");
634
 
      if (!s || (Strcmp(s,"typedef"))) return c;  /* No.  This is a conflict */
 
727
      s = Getattr(other,k_storage);
 
728
      if (!s || (Strcmp(s,k_typedef))) return c;  /* No.  This is a conflict */
635
729
      
636
730
      /* Hmmm.  This appears to be okay.  Make sure the symbol table refers to the allow_type node */
637
731
      
638
732
      if (td != c) {
639
733
        Setattr(current,symname, td);
640
 
        Setattr(td,"sym:symtab", current_symtab);
641
 
        Setattr(td,"sym:name", symname);
 
734
        Setattr(td,k_symsymtab, current_symtab);
 
735
        Setattr(td,k_symname, symname);
642
736
      }
643
737
      return n;
644
738
    }
645
739
     
646
 
    decl = Getattr(c,"decl");
647
 
    ndecl = Getattr(n,"decl");
 
740
    decl = Getattr(c,k_decl);
 
741
    ndecl = Getattr(n,k_decl);
648
742
 
649
743
    {
650
744
      String *nt1, *nt2;
666
760
    
667
761
    /* Hmmm. Declarator seems to indicate that this is a function */
668
762
    /* Look at storage class to see if compatible */
669
 
    cstorage = Getattr(c,"storage");
670
 
    nstorage = Getattr(n,"storage");
 
763
    cstorage = Getattr(c,k_storage);
 
764
    nstorage = Getattr(n,k_storage);
671
765
 
672
766
    /* If either one is declared as typedef, forget it. We're hosed */
673
 
    if (Cmp(cstorage,"typedef") == 0) {
 
767
    if (Cmp(cstorage,k_typedef) == 0) {
674
768
      return c;
675
769
    }
676
 
    if (Cmp(nstorage,"typedef") == 0) {
 
770
    if (Cmp(nstorage,k_typedef) == 0) {
677
771
      return c;
678
772
    }
679
773
 
680
774
    /* Okay. Walk down the list of symbols and see if we get a declarator match */
681
775
    {
682
 
      int n_template = (Strcmp(nodeType(n),"template") == 0) && (Strcmp(Getattr(n,"templatetype"),"cdecl") == 0);
683
 
      int n_plain_cdecl = (Strcmp(nodeType(n),"cdecl") == 0);
 
776
      int n_template = (Strcmp(nodeType(n),"template") == 0) && (Strcmp(Getattr(n,"templatetype"),k_cdecl) == 0);
 
777
      int n_plain_cdecl = (Strcmp(nodeType(n),k_cdecl) == 0);
684
778
      cn = c;
685
779
      pn = 0;
686
780
      while (cn) {
687
 
        decl = Getattr(cn,"decl");
 
781
        decl = Getattr(cn,k_decl);
688
782
        if (!(u1 || u2)) {
689
783
          if (Cmp(ndecl,decl) == 0) {
690
784
            /* Declarator conflict */
691
785
            /* Now check we don't have a non-templated function overloaded by a templated function with same params,
692
786
             * eg void foo(); template<typename> void foo(); */
693
 
            int cn_template = (Strcmp(nodeType(cn),"template") == 0) && (Strcmp(Getattr(cn,"templatetype"),"cdecl") == 0);
694
 
            int cn_plain_cdecl = (Strcmp(nodeType(cn),"cdecl") == 0);
 
787
            int cn_template = (Strcmp(nodeType(cn),"template") == 0) && (Strcmp(Getattr(cn,"templatetype"),k_cdecl) == 0);
 
788
            int cn_plain_cdecl = (Strcmp(nodeType(cn),k_cdecl) == 0);
695
789
            if (!((n_template && cn_plain_cdecl) || (cn_template && n_plain_cdecl))) {
696
790
              /* found a conflict */
697
791
              return cn;
699
793
          }
700
794
        }
701
795
        cl = cn;
702
 
        cn = Getattr(cn,"sym:nextSibling");
 
796
        cn = Getattr(cn,k_symnextSibling);
703
797
        pn++;
704
798
      }
705
799
    }
706
800
    /* Well, we made it this far.  Guess we can drop the symbol in place */
707
 
    Setattr(n,"sym:symtab",current_symtab);
708
 
    Setattr(n,"sym:name",symname);
709
 
    /* Printf(stdout,"%s %x\n", Getattr(n,"sym:overname"), current_symtab); */
710
 
    assert(!Getattr(n,"sym:overname"));
711
 
    Setattr(n,"sym:overname", NewStringf("__SWIG_%d", pn));
712
 
    /*Printf(stdout,"%s %s %s\n", symname, Getattr(n,"decl"), Getattr(n,"sym:overname")); */
713
 
    Setattr(cl,"sym:nextSibling",n);
714
 
    Setattr(n,"sym:previousSibling",cl);
715
 
    Setattr(cl,"sym:overloaded",c);
716
 
    Setattr(n,"sym:overloaded",c);
 
801
    Setattr(n,k_symsymtab,current_symtab);
 
802
    Setattr(n,k_symname,symname);
 
803
    /* Printf(stdout,"%s %x\n", Getattr(n,k_symovername), current_symtab); */
 
804
    assert(!Getattr(n,k_symovername));
 
805
    overname = NewStringf("__SWIG_%d", pn);
 
806
    Setattr(n,k_symovername, overname);
 
807
    /*Printf(stdout,"%s %s %s\n", symname, Getattr(n,k_decl), Getattr(n,k_symovername)); */
 
808
    Setattr(cl,k_symnextSibling,n);
 
809
    Setattr(n,k_sympreviousSibling,cl);
 
810
    Setattr(cl,k_symoverloaded,c);
 
811
    Setattr(n,k_symoverloaded,c);
 
812
    Delete(overname);
717
813
    return n;
718
814
  }
719
815
 
720
816
  /* No conflict.  Just add it */
721
 
  Setattr(n,"sym:symtab",current_symtab);
722
 
  Setattr(n,"sym:name",symname);
723
 
  /* Printf(stdout,"%s\n", Getattr(n,"sym:overname")); */
724
 
  Setattr(n,"sym:overname", NewStringf("__SWIG_%d", pn));
725
 
  /* Printf(stdout,"%s %s %s\n", symname, Getattr(n,"decl"), Getattr(n,"sym:overname")); */
 
817
  Setattr(n,k_symsymtab,current_symtab);
 
818
  Setattr(n,k_symname,symname);
 
819
  /* Printf(stdout,"%s\n", Getattr(n,k_symovername)); */
 
820
  overname = NewStringf("__SWIG_%d", pn);
 
821
  Setattr(n,k_symovername, overname);
 
822
  Delete(overname);
 
823
  /* Printf(stdout,"%s %s %s\n", symname, Getattr(n,k_decl), Getattr(n,k_symovername)); */
726
824
  Setattr(current,symname,n);
727
825
  return n;
728
826
}
745
843
symbol_lookup(String_or_char *name, Symtab *symtab, int (*check)(Node *n)) {
746
844
  Node *n;
747
845
  List *inherit;
748
 
  Hash *sym = Getattr(symtab,"csymtab");
749
 
  
 
846
  Hash *sym = Getattr(symtab,k_csymtab);
750
847
  if (Getmark(symtab)) return 0;
751
848
  Setmark(symtab,1);
752
849
 
 
850
 
753
851
  n = Getattr(sym,name);
 
852
 
 
853
#ifdef SWIG_DEBUG
 
854
  Printf(stderr,"symbol_look %s %x %x %s\n", name, n, symtab, Getattr(symtab,k_name));
 
855
#endif
 
856
  
754
857
  if (n) {
755
858
    /* if a check-function is defined.  Call it to determine a match */
756
859
    if (check) {
770
873
    }
771
874
  }
772
875
 
773
 
  inherit = Getattr(symtab,"inherit");
 
876
  if (!n && SwigType_istemplate(name)) {
 
877
    String *dname = 0;
 
878
    Setmark(symtab,0);
 
879
    dname = Swig_symbol_template_deftype(name,symtab);
 
880
    if (Strcmp(name,dname)) {
 
881
      n = symbol_lookup(dname, symtab, check);
 
882
    }
 
883
    Delete(dname);
 
884
    if (n) return n;
 
885
  }
 
886
 
 
887
  inherit = Getattr(symtab,k_inherit);
774
888
  if (inherit) {
775
889
    int  i,len;
776
890
    len = Len(inherit);
782
896
      }
783
897
    }
784
898
  }
 
899
 
785
900
  Setmark(symtab,0);
786
901
  return 0;
787
902
}
811
926
    Node *n = 0;
812
927
    /* Make qualified name of current scope */
813
928
    qname = Swig_symbol_qualifiedscopename(symtab);
814
 
    if (qname && Len(qname)) {
 
929
    if (Len(qname)) {
815
930
      if (Len(prefix)) {
816
 
        Append(qname,"::");
 
931
        Append(qname,k_coloncolon);
817
932
        Append(qname,prefix);
818
933
      }
819
934
    } else {
 
935
      Delete(qname);
820
936
      qname = NewString(prefix);
821
937
    }
822
938
    st = Getattr(symtabs,qname);
825
941
      if (!name) return st;
826
942
      n = symbol_lookup(name, st,checkfunc);
827
943
    }
 
944
 
828
945
    Delete(qname);
829
946
    if (!n) {
830
947
      if (!local) {
854
971
  if (!n) {
855
972
    hsym = current_symtab;
856
973
  } else {
857
 
    if (Strcmp(nodeType(n),"symboltable")) {
858
 
      n = Getattr(n,"sym:symtab");
 
974
    if (Strcmp(nodeType(n),k_symboltable)) {
 
975
      n = Getattr(n,k_symsymtab);
859
976
    }
860
977
    assert(n);
861
978
    if (n) {
864
981
  }
865
982
  
866
983
  if (Swig_scopename_check(name)) {
867
 
    if (Strncmp(name,"::",2) == 0) {
 
984
    if (Strncmp(name,k_coloncolon,2) == 0) {
868
985
      String *nname = NewString(Char(name)+2);
869
986
      if (Swig_scopename_check(nname)) {
870
987
        s = symbol_lookup_qualified(nname,global_scope,0,0,0);
871
988
      }
 
989
      Delete(nname);
872
990
    } else {
873
991
      String *prefix = Swig_scopename_prefix(name);
874
992
      if (prefix) {
892
1010
    return 0;
893
1011
  }
894
1012
  /* Check if s is a 'using' node */
895
 
  while (s && Strcmp(nodeType(s),"using") == 0) {
896
 
    Node *ss;
897
 
    ss = Swig_symbol_clookup(Getattr(s,"uname"), Getattr(s,"sym:symtab"));
 
1013
  while (s && Strcmp(nodeType(s),k_using) == 0) {
 
1014
    String *uname = Getattr(s,k_uname);
 
1015
    Symtab *un = Getattr(s,k_symsymtab);
 
1016
    Node *ss = (Strcmp(name,uname) || (un != n)) ?
 
1017
      Swig_symbol_clookup(uname, un) : 0; /* avoid infinity loop */
898
1018
    if (!ss) {
899
 
      Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s,"uname"));
 
1019
      Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s,k_uname));
900
1020
    }
901
1021
    s = ss;
902
1022
  }
921
1041
  if (!n) {
922
1042
    hsym = current_symtab;
923
1043
  } else {
924
 
    if (Strcmp(nodeType(n),"symboltable")) {
925
 
      n = Getattr(n,"sym:symtab");
 
1044
    if (Strcmp(nodeType(n),k_symboltable)) {
 
1045
      n = Getattr(n,k_symsymtab);
926
1046
    }
927
1047
    assert(n);
928
1048
    if (n) {
931
1051
  }
932
1052
  
933
1053
  if (Swig_scopename_check(name)) {
934
 
    if (Strncmp(name,"::",2) == 0) {
 
1054
    if (Strncmp(name,k_coloncolon,2) == 0) {
935
1055
      String *nname = NewString(Char(name)+2);
936
1056
      if (Swig_scopename_check(nname)) {
937
1057
        s = symbol_lookup_qualified(nname,global_scope,0,0,checkfunc);
938
1058
      }
 
1059
      Delete(nname);
939
1060
    } else {
940
1061
      String *prefix = Swig_scopename_prefix(name);
941
1062
      if (prefix) {
959
1080
    return 0;
960
1081
  }
961
1082
  /* Check if s is a 'using' node */
962
 
  while (s && Strcmp(nodeType(s),"using") == 0) {
 
1083
  while (s && Strcmp(nodeType(s),k_using) == 0) {
963
1084
    Node *ss;
964
 
    ss = Swig_symbol_clookup(Getattr(s,"uname"), Getattr(s,"sym:symtab"));
 
1085
    ss = Swig_symbol_clookup(Getattr(s,k_uname), Getattr(s,k_symsymtab));
965
1086
    if (!ss && !checkfunc) {
966
 
      Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s,"uname"));
 
1087
      Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s,k_uname));
967
1088
    }
968
1089
    s = ss;
969
1090
  }
983
1104
    hsym = current_symtab;
984
1105
    h = ccurrent;
985
1106
  } else {
986
 
    if (Strcmp(nodeType(n),"symboltable")) {
987
 
      n = Getattr(n,"sym:symtab");
 
1107
    if (Strcmp(nodeType(n),k_symboltable)) {
 
1108
      n = Getattr(n,k_symsymtab);
988
1109
    }
989
1110
    assert(n);
990
1111
    hsym = n;
991
 
    h = Getattr(n,"csymtab");
 
1112
    h = Getattr(n,k_csymtab);
992
1113
  }
993
1114
 
994
1115
  if (Swig_scopename_check(name)) {
995
 
    if (Strncmp(name,"::",2) == 0) {
996
 
      s = symbol_lookup_qualified(Char(name)+2,global_scope,0,0,0);
 
1116
    if (Strncmp(name,k_coloncolon,2) == 0) {
 
1117
      String *nname = NewString(Char(name)+2);
 
1118
      if (Swig_scopename_check(nname)) {
 
1119
        s = symbol_lookup_qualified(nname,global_scope,0,0,0);
 
1120
      }
 
1121
      Delete(nname);
997
1122
    } else {
998
1123
      s = symbol_lookup_qualified(name,hsym,0,0,0);
999
1124
    }
1003
1128
  }
1004
1129
  if (!s) return 0;
1005
1130
  /* Check if s is a 'using' node */
1006
 
  while (s && Strcmp(nodeType(s),"using") == 0) {
1007
 
    Node *ss = Swig_symbol_clookup_local(Getattr(s,"uname"), Getattr(s,"sym:symtab"));
 
1131
  while (s && Strcmp(nodeType(s),k_using) == 0) {
 
1132
    Node *ss = Swig_symbol_clookup_local(Getattr(s,k_uname), Getattr(s,k_symsymtab));
1008
1133
    if (!ss) {
1009
 
      Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s,"uname"));
 
1134
      Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s,k_uname));
1010
1135
    }
1011
1136
    s = ss;
1012
1137
  }
1026
1151
    hsym = current_symtab;
1027
1152
    h = ccurrent;
1028
1153
  } else {
1029
 
    if (Strcmp(nodeType(n),"symboltable")) {
1030
 
      n = Getattr(n,"sym:symtab");
 
1154
    if (Strcmp(nodeType(n),k_symboltable)) {
 
1155
      n = Getattr(n,k_symsymtab);
1031
1156
    }
1032
1157
    assert(n);
1033
1158
    hsym = n;
1034
 
    h = Getattr(n,"csymtab");
 
1159
    h = Getattr(n,k_csymtab);
1035
1160
  }
1036
1161
 
1037
1162
  if (Swig_scopename_check(name)) {
1038
 
    if (Strncmp(name,"::",2) == 0) {
1039
 
      s = symbol_lookup_qualified(Char(name)+2,global_scope,0,0,checkfunc);
 
1163
    if (Strncmp(name,k_coloncolon,2) == 0) {
 
1164
      String *nname = NewString(Char(name)+2);
 
1165
      if (Swig_scopename_check(nname)) {
 
1166
        s = symbol_lookup_qualified(nname,global_scope,0,0,checkfunc);
 
1167
      }
 
1168
      Delete(nname);
1040
1169
    } else {
1041
1170
      s = symbol_lookup_qualified(name,hsym,0,0,checkfunc);
1042
1171
    }
1046
1175
  }
1047
1176
  if (!s) return 0;
1048
1177
  /* Check if s is a 'using' node */
1049
 
  while (s && Strcmp(nodeType(s),"using") == 0) {
1050
 
    Node *ss = Swig_symbol_clookup_local_check(Getattr(s,"uname"), Getattr(s,"sym:symtab"),checkfunc);
 
1178
  while (s && Strcmp(nodeType(s),k_using) == 0) {
 
1179
    Node *ss = Swig_symbol_clookup_local_check(Getattr(s,k_uname), Getattr(s,k_symsymtab),checkfunc);
1051
1180
    if (!ss && !checkfunc) {
1052
 
      Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s,"uname"));
 
1181
      Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s,k_uname));
1053
1182
    }
1054
1183
    s = ss;
1055
1184
  }
1065
1194
 
1066
1195
Symtab *
1067
1196
Swig_symbol_cscope(String_or_char *name, Symtab *symtab) {
1068
 
  if (Strncmp(name,"::",2) == 0) return symbol_lookup_qualified(0, global_scope, name, 0,0);
 
1197
  if (Strncmp(name,k_coloncolon,2) == 0) return symbol_lookup_qualified(0, global_scope, name, 0,0);
1069
1198
  return symbol_lookup_qualified(0,symtab,name,0,0);
1070
1199
}
1071
1200
 
1081
1210
Swig_symbol_remove(Node *n) {
1082
1211
  Symtab  *symtab; 
1083
1212
  String  *symname;
 
1213
  String  *overname;
1084
1214
  Node    *symprev;
1085
1215
  Node    *symnext;
1086
1216
  Node    *fixovername = 0;
1087
 
  symtab  = Getattr(n,"sym:symtab");        /* Get symbol table object */
1088
 
  symtab  = Getattr(symtab,"symtab");       /* Get actual hash table of symbols */
1089
 
  symname = Getattr(n,"sym:name");
1090
 
  symprev = Getattr(n,"sym:previousSibling");
1091
 
  symnext = Getattr(n,"sym:nextSibling");
 
1217
  symtab  = Getattr(n,k_symsymtab);        /* Get symbol table object */
 
1218
  symtab  = Getattr(symtab,k_symtab);       /* Get actual hash table of symbols */
 
1219
  symname = Getattr(n,k_symname);
 
1220
  symprev = Getattr(n,k_sympreviousSibling);
 
1221
  symnext = Getattr(n,k_symnextSibling);
1092
1222
 
1093
1223
  /* If previous symbol, just fix the links */
1094
1224
  if (symprev) {
1095
1225
    if (symnext) {
1096
 
      Setattr(symprev,"sym:nextSibling",symnext);
 
1226
      Setattr(symprev,k_symnextSibling,symnext);
1097
1227
      fixovername = symprev; /* fix as symbol to remove is somewhere in the middle of the linked list */
1098
1228
    } else {
1099
 
      Delattr(symprev,"sym:nextSibling");
 
1229
      Delattr(symprev,k_symnextSibling);
1100
1230
    }
1101
1231
  } else {
1102
1232
    /* If no previous symbol, see if there is a next symbol */
1109
1239
  }
1110
1240
  if (symnext) {
1111
1241
    if (symprev) {
1112
 
      Setattr(symnext,"sym:previousSibling",symprev);
 
1242
      Setattr(symnext,k_sympreviousSibling,symprev);
1113
1243
    } else {
1114
 
      Delattr(symnext,"sym:previousSibling");
 
1244
      Delattr(symnext,k_sympreviousSibling);
1115
1245
    }
1116
1246
  }
1117
 
  Delattr(n,"sym:symtab");
1118
 
  Delattr(n,"sym:previousSibling");
1119
 
  Delattr(n,"sym:nextSibling");
1120
 
  Delattr(n,"csym:nextSibling");
1121
 
  Delattr(n,"sym:overname");
1122
 
  Delattr(n,"csym:previousSibling");
1123
 
  Delattr(n,"sym:overloaded");
 
1247
  Delattr(n,k_symsymtab);
 
1248
  Delattr(n,k_sympreviousSibling);
 
1249
  Delattr(n,k_symnextSibling);
 
1250
  Delattr(n,k_csymnextSibling);
 
1251
  Delattr(n,k_symovername);
 
1252
  Delattr(n,k_csympreviousSibling);
 
1253
  Delattr(n,k_symoverloaded);
1124
1254
  n = 0;
1125
1255
 
1126
1256
  if (fixovername) {
1131
1261
    /* find head of linked list */
1132
1262
    while (nn) {
1133
1263
      head = nn;
1134
 
      nn = Getattr(nn, "sym:previousSibling");
 
1264
      nn = Getattr(nn, k_sympreviousSibling);
1135
1265
    }
1136
1266
 
1137
1267
    /* adjust all the sym:overname strings to start from 0 and increment by one */
1138
1268
    nn = head;
1139
1269
    while (nn) {
1140
 
      assert(Getattr(nn,"sym:overname"));
1141
 
      Delattr(nn,"sym:overname");
1142
 
      Setattr(nn,"sym:overname", NewStringf("__SWIG_%d", pn));
 
1270
      assert(Getattr(nn,k_symovername));
 
1271
      Delattr(nn,k_symovername);
 
1272
      overname = NewStringf("__SWIG_%d", pn);
 
1273
      Setattr(nn,k_symovername, overname);
 
1274
      Delete(overname);
1143
1275
      pn++;
1144
 
      nn = Getattr(nn,"sym:nextSibling");
 
1276
      nn = Getattr(nn,k_symnextSibling);
1145
1277
    }
1146
1278
  }
1147
1279
}
1155
1287
String *
1156
1288
Swig_symbol_qualified(Node *n) {
1157
1289
  Hash *symtab;
1158
 
  if (Strcmp(nodeType(n),"symboltable") == 0) {
 
1290
  if (Strcmp(nodeType(n),k_symboltable) == 0) {
1159
1291
    symtab = n;
1160
1292
  } else {
1161
 
    symtab = Getattr(n,"sym:symtab");
 
1293
    symtab = Getattr(n,k_symsymtab);
1162
1294
  }
1163
1295
  if (!symtab) return NewString("");
 
1296
#ifdef SWIG_DEBUG
 
1297
  Printf(stderr,"symbol_qscope %s %x %s\n", Getattr(n,k_name), symtab,Getattr(symtab,k_name));
 
1298
#endif
1164
1299
  return Swig_symbol_qualifiedscopename(symtab);
1165
1300
}
1166
1301
 
1172
1307
 
1173
1308
Node *
1174
1309
Swig_symbol_isoverloaded(Node *n) {
1175
 
  return Getattr(n,"sym:overloaded");
 
1310
  return Getattr(n,k_symoverloaded);
1176
1311
}
1177
1312
 
1178
1313
/* -----------------------------------------------------------------------------
1181
1316
 * Create a fully qualified type name
1182
1317
 * ----------------------------------------------------------------------------- */
1183
1318
 
 
1319
static int no_constructor(Node *n) {
 
1320
  SwigType *type = nodeType(n);
 
1321
#ifdef SWIG_DEBUG
 
1322
  Printf(stderr,"node type %s\n", Getattr(n,k_name), type);
 
1323
#endif
 
1324
  return type ? (Strcmp(type,"constructor") != 0): 1;
 
1325
}
 
1326
 
 
1327
static SwigType *
 
1328
Swig_symbol_template_qualify(const SwigType *e, Symtab *st) {
 
1329
  String *tprefix, *tsuffix;
 
1330
  SwigType *qprefix;
 
1331
  List   *targs;
 
1332
  Node *tempn;
 
1333
  Symtab *tscope;
 
1334
  Iterator ti;
 
1335
  tprefix = SwigType_templateprefix(e);
 
1336
  tsuffix = SwigType_templatesuffix(e);
 
1337
  qprefix = Swig_symbol_type_qualify(tprefix,st);
 
1338
  targs = SwigType_parmlist(e);
 
1339
  tempn = Swig_symbol_clookup_local(tprefix,st);
 
1340
  tscope = tempn ? Getattr(tempn,"sym:symtab") : 0;
 
1341
  Printf(qprefix,"<(");
 
1342
  for (ti = First(targs); ti.item;) {
 
1343
    String *vparm;
 
1344
    String *qparm = Swig_symbol_type_qualify(ti.item,st);
 
1345
    if (tscope && (tscope != st)) {
 
1346
      String *ty = Swig_symbol_type_qualify(qparm,tscope);
 
1347
      Delete(qparm);      
 
1348
      qparm = ty;
 
1349
    }
 
1350
 
 
1351
    vparm = Swig_symbol_template_param_eval(qparm, st);
 
1352
    Append(qprefix,vparm);
 
1353
    ti = Next(ti);
 
1354
    if (ti.item) {
 
1355
      Putc(',',qprefix);
 
1356
    }
 
1357
    Delete(qparm);
 
1358
    Delete(vparm);
 
1359
  }
 
1360
  Append(qprefix,")>");
 
1361
  Append(qprefix,tsuffix);
 
1362
  Delete(tprefix);
 
1363
  Delete(tsuffix);
 
1364
  Delete(targs);
 
1365
#ifdef SWIG_DEBUG
 
1366
  Printf(stderr,"symbol_temp_qual %s %s\n", e, qprefix);
 
1367
#endif
 
1368
  return qprefix;
 
1369
}
 
1370
 
1184
1371
SwigType *
1185
 
Swig_symbol_type_qualify(SwigType *t, Symtab *st) {
 
1372
Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
1186
1373
  List   *elements;
1187
1374
  String *result;
1188
1375
  int     i,len;
1194
1381
  for (i = 0; i < len; i++) {
1195
1382
    String *e = Getitem(elements,i);
1196
1383
    if (SwigType_issimple(e)) {
1197
 
      Node *n = Swig_symbol_clookup(e,st);
 
1384
      Node *n = Swig_symbol_clookup_check(e,st,no_constructor);
1198
1385
      if (n) {
1199
 
        String *name = Getattr(n,"name");
 
1386
        String *name = Getattr(n,k_name);
1200
1387
        Clear(e);
1201
1388
        Append(e,name);
 
1389
#ifdef SWIG_DEBUG
 
1390
        Printf(stderr,"symbol_qual_ei %d %s %s %x\n", i, name, e, st);
 
1391
#endif
1202
1392
        if (!Swig_scopename_check(name)) {
1203
1393
          String *qname = Swig_symbol_qualified(n);
1204
1394
          if (Len(qname)) {
1205
 
            Insert(e,0,"::");
 
1395
            Insert(e,0,k_coloncolon);
1206
1396
            Insert(e,0,qname);
1207
1397
          }
 
1398
#ifdef SWIG_DEBUG
 
1399
          Printf(stderr,"symbol_qual_sc %d %s %s %x\n", i, qname, e, st);
 
1400
#endif
1208
1401
          Delete(qname);
1209
1402
        }
1210
1403
      } else if (SwigType_istemplate(e)) {
1211
 
        String *tprefix, *tsuffix;
1212
 
        SwigType *qprefix;
1213
 
        List   *targs;
1214
 
        Iterator ti;
1215
 
        tprefix = SwigType_templateprefix(e);
1216
 
        tsuffix = SwigType_templatesuffix(e);
1217
 
        qprefix = Swig_symbol_type_qualify(tprefix,st);
1218
 
        targs = SwigType_parmlist(e);
1219
 
        Printf(qprefix,"<(");
1220
 
        for (ti = First(targs); ti.item;) {
1221
 
          String *qparm = Swig_symbol_type_qualify(ti.item,st);
1222
 
          while (1) {
1223
 
            /* It is possible for an integer to show up here.  If so, we need to evaluate it */
1224
 
            Node *nn = Swig_symbol_clookup(qparm,st);
1225
 
            if (nn) {
1226
 
              SwigType *nt = nodeType(nn);
1227
 
              if (Strcmp(nt,"cdecl") == 0) {
1228
 
                String *nv = Getattr(nn,"value");
1229
 
                if (nv) {
1230
 
                  Clear(qparm);
1231
 
                  Append(qparm,nv);
1232
 
                } else {
1233
 
                  break;
1234
 
                }
1235
 
              } else if (Strcmp(nt,"enumitem") == 0) {
1236
 
                String *qn = Swig_symbol_qualified(nn);
1237
 
                if (Len(qn)) {
1238
 
                  Append(qn,"::");
1239
 
                  Append(qn,Getattr(nn,"name"));
1240
 
                  Clear(qparm);
1241
 
                  Append(qparm,qn);
1242
 
                }
1243
 
                Delete(qn);
1244
 
                break;
1245
 
              } else {
1246
 
                break;
1247
 
              }
1248
 
            } else {
1249
 
              break;
1250
 
            }
1251
 
          }
1252
 
          Append(qprefix,qparm);
1253
 
          ti = Next(ti);
1254
 
          if (ti.item) {
1255
 
            Putc(',',qprefix);
1256
 
          }
1257
 
          Delete(qparm);
1258
 
        }
1259
 
        Append(qprefix,")>");
1260
 
        Append(qprefix,tsuffix);
 
1404
        SwigType *ty = Swig_symbol_template_qualify(e,st);
1261
1405
        Clear(e);
1262
 
        Append(e,qprefix);
1263
 
        Delete(tprefix);
1264
 
        Delete(tsuffix);
1265
 
        Delete(qprefix);
 
1406
        Append(e,ty);
 
1407
        Delete(ty);     
1266
1408
      }
1267
 
      if (Strncmp(e,"::",2) == 0) {
 
1409
      if (Strncmp(e,k_coloncolon,2) == 0) {
1268
1410
        Delitem(e,0);
1269
1411
        Delitem(e,0);
1270
1412
      }
1271
1413
      Append(result,e);
1272
1414
    } else if (SwigType_isfunction(e)) {
1273
 
      Iterator pi;
1274
1415
      List *parms = SwigType_parmlist(e);
1275
1416
      String *s = NewString("f(");
1276
 
      pi = First(parms);
 
1417
      Iterator pi = First(parms);
1277
1418
      while (pi.item) {
1278
 
        Append(s,Swig_symbol_type_qualify(pi.item,st));
 
1419
        String *pf = Swig_symbol_type_qualify(pi.item,st);
 
1420
        Append(s,pf);
1279
1421
        pi = Next(pi);
1280
1422
        if (pi.item) {
1281
1423
          Append(s,",");
1282
1424
        }
 
1425
        Delete(pf);
1283
1426
      }
1284
1427
      Append(s,").");
1285
1428
      Append(result,s);
 
1429
      Delete(parms);
1286
1430
      Delete(s);
1287
1431
    } else {
1288
1432
      Append(result,e);
1289
1433
    }
1290
1434
  }
1291
1435
  Delete(elements);
 
1436
#ifdef SWIG_DEBUG
 
1437
  Printf(stderr,"symbol_qualify %s %s %x %s\n", t, result, st, st ?Getattr(st,k_name): 0);
 
1438
#endif
1292
1439
  return result;
1293
1440
}
1294
1441
 
1298
1445
 * Chase a typedef through symbol tables looking for a match.
1299
1446
 * ----------------------------------------------------------------------------- */
1300
1447
 
 
1448
static 
 
1449
SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab)
 
1450
{
 
1451
  Iterator pi;
 
1452
  Parm *p;
 
1453
  List *parms = SwigType_parmlist(qt);
 
1454
  String *tprefix = SwigType_templateprefix(qt);
 
1455
  String *tsuffix = SwigType_templatesuffix(qt);
 
1456
  String *qprefix = SwigType_typedef_qualified(tprefix);
 
1457
  Printv(qprefix,"<(",NIL);
 
1458
  pi = First(parms);
 
1459
  while ((p = pi.item)) {
 
1460
    String *np;
 
1461
    String *tp = Swig_symbol_typedef_reduce(p, ntab);
 
1462
    String *qp = Swig_symbol_type_qualify(tp, ntab);
 
1463
    Node *n = Swig_symbol_clookup(qp,ntab);
 
1464
    if (n) {
 
1465
      String *qual = Swig_symbol_qualified(n);
 
1466
      np = Copy(Getattr(n,k_name));
 
1467
      tp = np;
 
1468
      if (Len(qual)) {
 
1469
        Insert(np,0,k_coloncolon);
 
1470
        Insert(np,0,qual);
 
1471
      }
 
1472
      Delete(qual);
 
1473
    } else {
 
1474
      np = qp;
 
1475
    }
 
1476
    Append(qprefix,np);
 
1477
    pi= Next(pi);
 
1478
    if (pi.item) {
 
1479
      Append(qprefix,",");
 
1480
    }
 
1481
    Delete(qp);
 
1482
    Delete(tp);
 
1483
  }
 
1484
  Append(qprefix,")>");
 
1485
  Insert(tsuffix, 0, qprefix);
 
1486
  Delete(parms);  
 
1487
  Delete(tprefix);  
 
1488
  Delete(qprefix);  
 
1489
  return tsuffix;
 
1490
}
 
1491
 
 
1492
 
1301
1493
SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) {
1302
1494
  SwigType *prefix, *base;
1303
1495
  Node *n;
1309
1501
  n = Swig_symbol_clookup(base,tab);
1310
1502
  if (!n) {
1311
1503
    Delete(base);
1312
 
    Delete(prefix);
1313
 
    return Copy(ty);
 
1504
    if (SwigType_istemplate(ty)) {
 
1505
      SwigType *qt = Swig_symbol_template_reduce(ty,tab);
 
1506
      Append(prefix,qt);
 
1507
      Delete(qt);
 
1508
#ifdef SWIG_DEBUG
 
1509
      Printf(stderr,"symbol_reduce %s %s\n", ty, prefix);
 
1510
#endif
 
1511
      return prefix;
 
1512
    } else {
 
1513
      Delete(prefix);
 
1514
#ifdef SWIG_DEBUG
 
1515
      Printf(stderr,"symbol_reduce %s %s\n", ty, ty);
 
1516
#endif
 
1517
      return Copy(ty);
 
1518
    }
1314
1519
  }
1315
 
  if (Strcmp(nodeType(n),"using") == 0) {
1316
 
    String *uname = Getattr(n,"uname");
 
1520
  if (Strcmp(nodeType(n),k_using) == 0) {
 
1521
    String *uname = Getattr(n,k_uname);
1317
1522
    if (uname) {
1318
 
      n = Swig_symbol_clookup(base,Getattr(n,"sym:symtab"));
 
1523
      n = Swig_symbol_clookup(base,Getattr(n,k_symsymtab));
1319
1524
      if (!n) {
1320
1525
        Delete(base);
1321
1526
        Delete(prefix);
 
1527
#ifdef SWIG_DEBUG
 
1528
        Printf(stderr,"symbol_reduce %s %s\n", ty, ty);
 
1529
#endif
1322
1530
        return Copy(ty);
1323
1531
      }
1324
1532
    } 
1325
1533
  }
1326
 
  if (Strcmp(nodeType(n),"cdecl") == 0) {
1327
 
    String *storage = Getattr(n,"storage");
1328
 
    if (storage && (Strcmp(storage,"typedef") == 0)) {
 
1534
  if (Strcmp(nodeType(n),k_cdecl) == 0) {
 
1535
    String *storage = Getattr(n,k_storage);
 
1536
    if (storage && (Strcmp(storage,k_typedef) == 0)) {
1329
1537
      SwigType *decl;
1330
1538
      SwigType *rt;
1331
1539
      SwigType *qt;
1332
1540
      Symtab *ntab;
1333
 
      SwigType *nt = Copy(Getattr(n,"type"));
 
1541
      SwigType *nt = Copy(Getattr(n,k_type));
1334
1542
      
1335
1543
      /* Fix for case 'typedef struct Hello hello;' */
1336
1544
      { 
1337
1545
        const char* dclass[3] = {"struct ", "union ", "class "};
1338
1546
        int i;
 
1547
        char * c = Char(nt);
1339
1548
        for (i=0; i<3; i++) {
1340
 
          char * c = Char(nt);
1341
1549
          if (strstr(c, dclass[i]) == c) {
1342
 
            Replace(nt,dclass[i],"", DOH_REPLACE_FIRST);
 
1550
            Replace(nt,dclass[i],"", DOH_REPLACE_FIRST); 
1343
1551
          }
1344
1552
        }
1345
1553
      }
1346
 
      decl = Getattr(n,"decl");
 
1554
      decl = Getattr(n,k_decl);
1347
1555
      if (decl) {
1348
1556
        SwigType_push(nt,decl);
1349
1557
      }
1350
1558
      SwigType_push(nt,prefix);
1351
1559
      Delete(base);
1352
1560
      Delete(prefix);
1353
 
      ntab = Getattr(n,"sym:symtab");
 
1561
      ntab = Getattr(n,k_symsymtab);
1354
1562
      rt = Swig_symbol_typedef_reduce(nt, ntab);
1355
1563
      qt = Swig_symbol_type_qualify(rt, ntab);
1356
1564
      if (SwigType_istemplate(qt)) {
1357
 
        Iterator pi;
1358
 
        Parm *p;
1359
 
        List *parms = SwigType_parmlist(qt);
1360
 
        String *tprefix = SwigType_templateprefix(qt);
1361
 
        String *tsuffix = SwigType_templatesuffix(qt);
1362
 
        String *qprefix = SwigType_typedef_qualified(tprefix);
1363
 
        Printv(qprefix,"<(",NIL);
1364
 
        pi = First(parms);
1365
 
        while ((p = pi.item)) {
1366
 
          String *np;
1367
 
          String *tp = 0;
1368
 
          String *qp = Swig_symbol_type_qualify(p, ntab);
1369
 
          Node *n = Swig_symbol_clookup(qp,ntab);
1370
 
          if (n) {
1371
 
            String *qual = Swig_symbol_qualified(n);
1372
 
            np = Copy(Getattr(n,"name"));
1373
 
            tp = np;
1374
 
            if (qual) {
1375
 
              Insert(np,0,"::");
1376
 
              Insert(np,0,qual);
1377
 
              Delete(qual);
1378
 
            }
1379
 
          } else {
1380
 
            np = qp;
1381
 
          }
1382
 
          Append(qprefix,np);
1383
 
          pi= Next(pi);
1384
 
          if (pi.item) {
1385
 
            Append(qprefix,",");
1386
 
          }
1387
 
          Delete(qp);
1388
 
          Delete(tp);
1389
 
        }
1390
 
        Append(qprefix,")>");
1391
 
        Insert(tsuffix, 0, qprefix);
 
1565
        SwigType *qtr = Swig_symbol_template_reduce(qt,ntab);
1392
1566
        Delete(qt);
1393
 
        qt = tsuffix;
 
1567
        qt = qtr;
1394
1568
      }      
1395
1569
      Delete(nt);
1396
1570
      Delete(rt);
1397
 
      /* Printf(stderr,"reduce  %s %s\n", ty, qt); */
 
1571
#ifdef SWIG_DEBUG
 
1572
      Printf(stderr,"symbol_reduce %s %s\n", qt, ty);
 
1573
#endif
1398
1574
      return qt;
1399
1575
    }
1400
1576
  }
1401
1577
  Delete(base);
1402
1578
  Delete(prefix);
 
1579
#ifdef SWIG_DEBUG
 
1580
      Printf(stderr,"symbol_reduce %s %s\n", ty, ty);
 
1581
#endif
1403
1582
  return Copy(ty);
1404
1583
}
1405
1584
 
1446
1625
  return r;
1447
1626
}
1448
1627
 
 
1628
 
 
1629
/* -----------------------------------------------------------------------------
 
1630
 * Swig_symbol_template_defargs()
 
1631
 *
 
1632
 * Apply default arg from generic template default args 
 
1633
 * ----------------------------------------------------------------------------- */
 
1634
 
 
1635
 
 
1636
void
 
1637
Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl) {
 
1638
  if (Len(parms) < Len(targs)) {
 
1639
    Parm *lp = parms;
 
1640
    Parm *p = lp;
 
1641
    Parm *tp = targs;
 
1642
    while(p && tp) {
 
1643
      p = nextSibling(p);
 
1644
      tp = nextSibling(tp);
 
1645
      if (p) lp = p;
 
1646
    }
 
1647
    while (tp) {
 
1648
      String *value = Getattr(tp,k_value);
 
1649
      if (value) {
 
1650
        Parm *cp;
 
1651
        Parm *ta = targs;
 
1652
        Parm *p = parms;
 
1653
        SwigType *nt = Swig_symbol_string_qualify(value,tsdecl);
 
1654
        SwigType *ntq = 0;
 
1655
#ifdef SWIG_DEBUG
 
1656
        Printf(stderr,"value %s %s %s\n",value, nt,tsdecl ? Getattr(tsdecl,k_name) : tsdecl);
 
1657
#endif
 
1658
        while(p && ta) {
 
1659
          String *name = Getattr(ta,k_name);
 
1660
          String *pvalue = Getattr(p,k_value);
 
1661
          String *value = pvalue ? pvalue : Getattr(p,k_type);
 
1662
          String *ttq = Swig_symbol_type_qualify(value,tscope);
 
1663
          /* value = SwigType_typedef_resolve_all(value);*/
 
1664
          Replaceid(nt, name, ttq);
 
1665
          p = nextSibling(p);
 
1666
          ta = nextSibling(ta);
 
1667
          Delete(ttq);
 
1668
        }
 
1669
        ntq = Swig_symbol_type_qualify(nt,tsdecl);
 
1670
        if (SwigType_istemplate(ntq)) {
 
1671
          String *ty = Swig_symbol_template_deftype(ntq, tscope);
 
1672
          Delete(ntq);
 
1673
          ntq = ty;
 
1674
        }
 
1675
        /* Printf(stderr,"value %s %s %s\n",value,ntr,ntq);*/
 
1676
        cp = NewParm(ntq,0);
 
1677
        set_nextSibling(lp,cp);
 
1678
        lp = cp;
 
1679
        tp = nextSibling(tp);
 
1680
        Delete(cp);
 
1681
        Delete(nt);
 
1682
        Delete(ntq);
 
1683
      } else {
 
1684
        tp = 0;
 
1685
      }
 
1686
    }
 
1687
  }
 
1688
}
 
1689
 
 
1690
/* -----------------------------------------------------------------------------
 
1691
 * Swig_symbol_template_deftype()
 
1692
 *
 
1693
 * Apply default args to generic template type
 
1694
 * ----------------------------------------------------------------------------- */
 
1695
SwigType*
 
1696
Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope) {
 
1697
  String *result   = NewString("");
 
1698
  List   *elements = SwigType_split(type);
 
1699
  int     len = Len(elements);
 
1700
  int     i;
 
1701
#ifdef SWIG_DEBUG
 
1702
  Printf(stderr,"finding deftype %s\n", type);
 
1703
#endif
 
1704
 
 
1705
  for (i = 0; i < len; i++) {
 
1706
    String *e = Getitem(elements,i);
 
1707
    if (SwigType_isfunction(e)) {
 
1708
      String *s = NewString("f(");
 
1709
      List *parms = SwigType_parmlist(e);
 
1710
      Iterator pi = First(parms);
 
1711
      while (pi.item) {
 
1712
        String *pf = SwigType_istemplate(e) ? 
 
1713
          Swig_symbol_template_deftype(pi.item,tscope)
 
1714
          : Swig_symbol_type_qualify(pi.item,tscope);
 
1715
        Append(s,pf);
 
1716
        pi = Next(pi);
 
1717
        if (pi.item) {
 
1718
          Append(s,",");
 
1719
        }
 
1720
        Delete(pf);
 
1721
      }
 
1722
      Append(s,").");
 
1723
      Append(result,s);
 
1724
      Delete(s);
 
1725
      Delete(parms);
 
1726
    } else if (SwigType_istemplate(e)) {
 
1727
      String *prefix   = SwigType_prefix(e);
 
1728
      String *base     = SwigType_base(e);
 
1729
      String *tprefix  = SwigType_templateprefix(base);
 
1730
      String *targs    = SwigType_templateargs(base);
 
1731
      String *tsuffix  = SwigType_templatesuffix(base);
 
1732
      ParmList *tparms = SwigType_function_parms(targs);
 
1733
      Node *tempn = Swig_symbol_clookup_local(tprefix,tscope);
 
1734
#ifdef SWIG_DEBUG
 
1735
      Printf(stderr,"deftype type %s \n", e);
 
1736
#endif
 
1737
      if (tempn) {
 
1738
        ParmList *tnargs = Getattr(tempn,k_templateparms);
 
1739
        Parm *p;
 
1740
        Symtab *tsdecl = Getattr(tempn,k_symsymtab);
 
1741
        
 
1742
#ifdef SWIG_DEBUG
 
1743
        Printf(stderr,"deftype type %s %s %s\n", tprefix, targs,
 
1744
        tsuffix);
 
1745
#endif
 
1746
        Append(tprefix,"<(");
 
1747
        Swig_symbol_template_defargs(tparms, tnargs,tscope,tsdecl);
 
1748
        p = tparms;
 
1749
        tscope = Getattr(tempn,"sym:symtab");
 
1750
        while (p) {
 
1751
          SwigType *ptype = Getattr(p,k_type);
 
1752
          SwigType *ttr = ptype ? ptype : Getattr(p,k_value);
 
1753
          SwigType *ttf = Swig_symbol_type_qualify(ttr,tscope);
 
1754
          SwigType *ttq = Swig_symbol_template_param_eval(ttf,tscope);
 
1755
#ifdef SWIG_DEBUG
 
1756
          Printf(stderr,"arg type %s\n", ttq);
 
1757
#endif
 
1758
          if (SwigType_istemplate(ttq)) {
 
1759
            SwigType *ttd = Swig_symbol_template_deftype(ttq, tscope);
 
1760
            Delete(ttq);
 
1761
            ttq = ttd;
 
1762
#ifdef SWIG_DEBUG
 
1763
            Printf(stderr,"arg deftype %s\n", ttq);
 
1764
#endif
 
1765
          }     
 
1766
          Append(tprefix,ttq);
 
1767
          p = nextSibling(p);
 
1768
          if (p) Putc(',',tprefix);
 
1769
          Delete(ttf);
 
1770
          Delete(ttq);
 
1771
        }
 
1772
        Append(tprefix,")>");
 
1773
        Append(tprefix,tsuffix);
 
1774
        Append(prefix,tprefix);
 
1775
#ifdef SWIG_DEBUG
 
1776
        Printf(stderr,"deftype %s %s \n", type, tprefix); 
 
1777
#endif
 
1778
        Append(result,prefix);
 
1779
      } else {
 
1780
        Append(result,e);
 
1781
      }
 
1782
      Delete(prefix);
 
1783
      Delete(base);
 
1784
      Delete(tprefix);
 
1785
      Delete(tsuffix);
 
1786
      Delete(targs);
 
1787
      Delete(tparms);
 
1788
    } else {
 
1789
      Append(result,e);
 
1790
    }
 
1791
  }
 
1792
  Delete(elements);
 
1793
  return result;
 
1794
}
 
1795
 
 
1796
SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab)
 
1797
{
 
1798
  String *value = Copy(p);
 
1799
  Node *lastnode = 0;
 
1800
  while (1) {
 
1801
    Node *n = Swig_symbol_clookup(value,symtab);
 
1802
    if (n == lastnode) break;
 
1803
    lastnode = n;
 
1804
    if (n) {
 
1805
      if (Strcmp(nodeType(n),k_enumitem) == 0) {
 
1806
        /* An enum item.   Generate a fully qualified name */
 
1807
        String *qn = Swig_symbol_qualified(n);
 
1808
        if (Len(qn)) {
 
1809
          Append(qn,k_coloncolon);
 
1810
          Append(qn,Getattr(n,k_name));
 
1811
          Delete(value);
 
1812
          value = qn;
 
1813
          continue;
 
1814
        } else {
 
1815
          Delete(qn);
 
1816
          break;
 
1817
        }
 
1818
      } else if ((Strcmp(nodeType(n),k_cdecl) == 0) && (Getattr(n,k_value))) {
 
1819
        Delete(value);
 
1820
        value = Copy(Getattr(n,k_value));
 
1821
        continue;
 
1822
      }
 
1823
    }
 
1824
    break;
 
1825
  }
 
1826
  return value;
 
1827
}