173
174
static Hash *symtabs = 0; /* Hash of all symbol tables by fully-qualified name */
174
175
static Hash *global_scope = 0; /* Global scope */
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;
178
206
Swig_symbol_dump_symtable() {
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");
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);
206
259
/* Set the global scope */
207
260
symtabs = NewHash();
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))) {
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);
571
/* Fix patetic case #1214313:
585
ie, when Foo -> FooBar -> Foo, jump one scope up when possible.
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);
504
598
if (td1 == td) break;
507
Symtab *st = Getattr(td,"symtab");
601
Symtab *st = Getattr(td,k_symtab);
509
Swig_symbol_alias(Getattr(n,"name"),st);
603
Swig_symbol_alias(Getattr(n,k_name),st);
557
651
stays in the C symbol table (so that it can be expanded using %template).
560
name = Getattr(n,"name");
654
name = Getattr(n,k_name);
655
if (name && Len(name)) {
562
656
Swig_symbol_cadd(name,n);
565
659
/* No symbol name defined. We return. */
567
Setattr(n,"sym:symtab",current_symtab);
661
Setattr(n,k_symsymtab,current_symtab);
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;
574
668
/* See if the symbol already exists in the table */
575
669
c = Getattr(current,symname);
606
cl = Getattr(cl,"sym:nextSibling");
700
cl = Getattr(cl,k_symnextSibling);
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);
614
708
if (Getattr(n,"allows_typedef")) nt = 1;
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 */
636
730
/* Hmmm. This appears to be okay. Make sure the symbol table refers to the allow_type node */
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);
646
decl = Getattr(c,"decl");
647
ndecl = Getattr(n,"decl");
740
decl = Getattr(c,k_decl);
741
ndecl = Getattr(n,k_decl);
650
744
String *nt1, *nt2;
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);
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) {
676
if (Cmp(nstorage,"typedef") == 0) {
770
if (Cmp(nstorage,k_typedef) == 0) {
680
774
/* Okay. Walk down the list of symbols and see if we get a declarator match */
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);
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 */
702
cn = Getattr(cn,"sym:nextSibling");
796
cn = Getattr(cn,k_symnextSibling);
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);
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);
823
/* Printf(stdout,"%s %s %s\n", symname, Getattr(n,k_decl), Getattr(n,k_symovername)); */
726
824
Setattr(current,symname,n);
894
1012
/* Check if s is a 'using' node */
895
while (s && Strcmp(nodeType(s),"using") == 0) {
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 */
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));
983
1104
hsym = current_symtab;
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);
991
h = Getattr(n,"csymtab");
1112
h = Getattr(n,k_csymtab);
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);
998
1123
s = symbol_lookup_qualified(name,hsym,0,0,0);
1026
1151
hsym = current_symtab;
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);
1034
h = Getattr(n,"csymtab");
1159
h = Getattr(n,k_csymtab);
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);
1041
1170
s = symbol_lookup_qualified(name,hsym,0,0,checkfunc);
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));
1081
1210
Swig_symbol_remove(Node *n) {
1082
1211
Symtab *symtab;
1083
1212
String *symname;
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);
1093
1223
/* If previous symbol, just fix the links */
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 */
1099
Delattr(symprev,"sym:nextSibling");
1229
Delattr(symprev,k_symnextSibling);
1102
1232
/* If no previous symbol, see if there is a next symbol */
1112
Setattr(symnext,"sym:previousSibling",symprev);
1242
Setattr(symnext,k_sympreviousSibling,symprev);
1114
Delattr(symnext,"sym:previousSibling");
1244
Delattr(symnext,k_sympreviousSibling);
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);
1126
1256
if (fixovername) {
1131
1261
/* find head of linked list */
1134
nn = Getattr(nn, "sym:previousSibling");
1264
nn = Getattr(nn, k_sympreviousSibling);
1137
1267
/* adjust all the sym:overname strings to start from 0 and increment by one */
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);
1144
nn = Getattr(nn,"sym:nextSibling");
1276
nn = Getattr(nn,k_symnextSibling);
1181
1316
* Create a fully qualified type name
1182
1317
* ----------------------------------------------------------------------------- */
1319
static int no_constructor(Node *n) {
1320
SwigType *type = nodeType(n);
1322
Printf(stderr,"node type %s\n", Getattr(n,k_name), type);
1324
return type ? (Strcmp(type,"constructor") != 0): 1;
1328
Swig_symbol_template_qualify(const SwigType *e, Symtab *st) {
1329
String *tprefix, *tsuffix;
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;) {
1344
String *qparm = Swig_symbol_type_qualify(ti.item,st);
1345
if (tscope && (tscope != st)) {
1346
String *ty = Swig_symbol_type_qualify(qparm,tscope);
1351
vparm = Swig_symbol_template_param_eval(qparm, st);
1352
Append(qprefix,vparm);
1360
Append(qprefix,")>");
1361
Append(qprefix,tsuffix);
1366
Printf(stderr,"symbol_temp_qual %s %s\n", e, qprefix);
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;
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);
1199
String *name = Getattr(n,"name");
1386
String *name = Getattr(n,k_name);
1201
1388
Append(e,name);
1390
Printf(stderr,"symbol_qual_ei %d %s %s %x\n", i, name, e, st);
1202
1392
if (!Swig_scopename_check(name)) {
1203
1393
String *qname = Swig_symbol_qualified(n);
1204
1394
if (Len(qname)) {
1395
Insert(e,0,k_coloncolon);
1206
1396
Insert(e,0,qname);
1399
Printf(stderr,"symbol_qual_sc %d %s %s %x\n", i, qname, e, st);
1210
1403
} else if (SwigType_istemplate(e)) {
1211
String *tprefix, *tsuffix;
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);
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);
1226
SwigType *nt = nodeType(nn);
1227
if (Strcmp(nt,"cdecl") == 0) {
1228
String *nv = Getattr(nn,"value");
1235
} else if (Strcmp(nt,"enumitem") == 0) {
1236
String *qn = Swig_symbol_qualified(nn);
1239
Append(qn,Getattr(nn,"name"));
1252
Append(qprefix,qparm);
1259
Append(qprefix,")>");
1260
Append(qprefix,tsuffix);
1404
SwigType *ty = Swig_symbol_template_qualify(e,st);
1267
if (Strncmp(e,"::",2) == 0) {
1409
if (Strncmp(e,k_coloncolon,2) == 0) {
1271
1413
Append(result,e);
1272
1414
} else if (SwigType_isfunction(e)) {
1274
1415
List *parms = SwigType_parmlist(e);
1275
1416
String *s = NewString("f(");
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);
1284
1427
Append(s,").");
1285
1428
Append(result,s);
1288
1432
Append(result,e);
1291
1435
Delete(elements);
1437
Printf(stderr,"symbol_qualify %s %s %x %s\n", t, result, st, st ?Getattr(st,k_name): 0);
1298
1445
* Chase a typedef through symbol tables looking for a match.
1299
1446
* ----------------------------------------------------------------------------- */
1449
SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab)
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);
1459
while ((p = pi.item)) {
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);
1465
String *qual = Swig_symbol_qualified(n);
1466
np = Copy(Getattr(n,k_name));
1469
Insert(np,0,k_coloncolon);
1479
Append(qprefix,",");
1484
Append(qprefix,")>");
1485
Insert(tsuffix, 0, qprefix);
1301
1493
SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) {
1302
1494
SwigType *prefix, *base;
1309
1501
n = Swig_symbol_clookup(base,tab);
1504
if (SwigType_istemplate(ty)) {
1505
SwigType *qt = Swig_symbol_template_reduce(ty,tab);
1509
Printf(stderr,"symbol_reduce %s %s\n", ty, prefix);
1515
Printf(stderr,"symbol_reduce %s %s\n", ty, ty);
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);
1318
n = Swig_symbol_clookup(base,Getattr(n,"sym:symtab"));
1523
n = Swig_symbol_clookup(base,Getattr(n,k_symsymtab));
1321
1526
Delete(prefix);
1528
Printf(stderr,"symbol_reduce %s %s\n", ty, ty);
1322
1530
return Copy(ty);
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;
1333
SwigType *nt = Copy(Getattr(n,"type"));
1541
SwigType *nt = Copy(Getattr(n,k_type));
1335
1543
/* Fix for case 'typedef struct Hello hello;' */
1337
1545
const char* dclass[3] = {"struct ", "union ", "class "};
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);
1346
decl = Getattr(n,"decl");
1554
decl = Getattr(n,k_decl);
1348
1556
SwigType_push(nt,decl);
1350
1558
SwigType_push(nt,prefix);
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)) {
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);
1365
while ((p = pi.item)) {
1368
String *qp = Swig_symbol_type_qualify(p, ntab);
1369
Node *n = Swig_symbol_clookup(qp,ntab);
1371
String *qual = Swig_symbol_qualified(n);
1372
np = Copy(Getattr(n,"name"));
1385
Append(qprefix,",");
1390
Append(qprefix,")>");
1391
Insert(tsuffix, 0, qprefix);
1565
SwigType *qtr = Swig_symbol_template_reduce(qt,ntab);
1397
/* Printf(stderr,"reduce %s %s\n", ty, qt); */
1572
Printf(stderr,"symbol_reduce %s %s\n", qt, ty);
1402
1578
Delete(prefix);
1580
Printf(stderr,"symbol_reduce %s %s\n", ty, ty);
1403
1582
return Copy(ty);
1629
/* -----------------------------------------------------------------------------
1630
* Swig_symbol_template_defargs()
1632
* Apply default arg from generic template default args
1633
* ----------------------------------------------------------------------------- */
1637
Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl) {
1638
if (Len(parms) < Len(targs)) {
1644
tp = nextSibling(tp);
1648
String *value = Getattr(tp,k_value);
1653
SwigType *nt = Swig_symbol_string_qualify(value,tsdecl);
1656
Printf(stderr,"value %s %s %s\n",value, nt,tsdecl ? Getattr(tsdecl,k_name) : tsdecl);
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);
1666
ta = nextSibling(ta);
1669
ntq = Swig_symbol_type_qualify(nt,tsdecl);
1670
if (SwigType_istemplate(ntq)) {
1671
String *ty = Swig_symbol_template_deftype(ntq, tscope);
1675
/* Printf(stderr,"value %s %s %s\n",value,ntr,ntq);*/
1676
cp = NewParm(ntq,0);
1677
set_nextSibling(lp,cp);
1679
tp = nextSibling(tp);
1690
/* -----------------------------------------------------------------------------
1691
* Swig_symbol_template_deftype()
1693
* Apply default args to generic template type
1694
* ----------------------------------------------------------------------------- */
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);
1702
Printf(stderr,"finding deftype %s\n", type);
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);
1712
String *pf = SwigType_istemplate(e) ?
1713
Swig_symbol_template_deftype(pi.item,tscope)
1714
: Swig_symbol_type_qualify(pi.item,tscope);
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);
1735
Printf(stderr,"deftype type %s \n", e);
1738
ParmList *tnargs = Getattr(tempn,k_templateparms);
1740
Symtab *tsdecl = Getattr(tempn,k_symsymtab);
1743
Printf(stderr,"deftype type %s %s %s\n", tprefix, targs,
1746
Append(tprefix,"<(");
1747
Swig_symbol_template_defargs(tparms, tnargs,tscope,tsdecl);
1749
tscope = Getattr(tempn,"sym:symtab");
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);
1756
Printf(stderr,"arg type %s\n", ttq);
1758
if (SwigType_istemplate(ttq)) {
1759
SwigType *ttd = Swig_symbol_template_deftype(ttq, tscope);
1763
Printf(stderr,"arg deftype %s\n", ttq);
1766
Append(tprefix,ttq);
1768
if (p) Putc(',',tprefix);
1772
Append(tprefix,")>");
1773
Append(tprefix,tsuffix);
1774
Append(prefix,tprefix);
1776
Printf(stderr,"deftype %s %s \n", type, tprefix);
1778
Append(result,prefix);
1796
SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab)
1798
String *value = Copy(p);
1801
Node *n = Swig_symbol_clookup(value,symtab);
1802
if (n == lastnode) break;
1805
if (Strcmp(nodeType(n),k_enumitem) == 0) {
1806
/* An enum item. Generate a fully qualified name */
1807
String *qn = Swig_symbol_qualified(n);
1809
Append(qn,k_coloncolon);
1810
Append(qn,Getattr(n,k_name));
1818
} else if ((Strcmp(nodeType(n),k_cdecl) == 0) && (Getattr(n,k_value))) {
1820
value = Copy(Getattr(n,k_value));