static String *manglestr_default(const SwigType *s) { String *mangled = NewString("_"); SwigType *sr = SwigType_typedef_resolve_all(s); SwigType *sq = SwigType_typedef_qualified(sr); SwigType *ss = SwigType_remove_global_scope_prefix(sq); SwigType *type = ss; SwigType *lt; if (SwigType_istemplate(ss)) { SwigType *ty = Swig_symbol_template_deftype(ss, 0); Delete(ss); ss = ty; type = ss; } lt = SwigType_ltype(type); Replace(lt, "struct ", "", DOH_REPLACE_ANY); Replace(lt, "class ", "", DOH_REPLACE_ANY); Replace(lt, "union ", "", DOH_REPLACE_ANY); Replace(lt, "enum ", "", DOH_REPLACE_ANY); mangle_subtype(mangled, lt); Delete(ss); Delete(sq); Delete(sr); return mangled; }
String *Swig_string_mangle(const String *s) { #if 0 /* old mangling, not suitable for using in macros */ String *t = Copy(s); char *c = Char(t); while (*c) { if (!isalnum(*c)) *c = '_'; c++; } return t; #else String *result = NewStringEmpty(); int space = 0; int state = 0; char *pc, *cb; String *b = Copy(s); if (SwigType_istemplate(b)) { String *st = Swig_symbol_template_deftype(b, 0); String *sq = Swig_symbol_type_qualify(st, 0); String *t = SwigType_namestr(sq); Delete(st); Delete(sq); Delete(b); b = t; } pc = cb = Char(b); while (*pc) { char c = *pc; if (isalnum((int) c) || (c == '_')) { state = 1; if (space && (space == state)) { Append(result, "_SS_"); } space = 0; Printf(result, "%c", (int) c); } else { if (isspace((int) c)) { space = state; ++pc; continue; } else { state = 3; space = 0; } switch (c) { case '.': if ((cb != pc) && (*(pc - 1) == 'p')) { Append(result, "_"); ++pc; continue; } else { c = 'f'; } break; case ':': if (*(pc + 1) == ':') { Append(result, "_"); ++pc; ++pc; continue; } break; case '*': c = 'm'; break; case '&': c = 'A'; break; case '<': c = 'l'; break; case '>': c = 'g'; break; case '=': c = 'e'; break; case ',': c = 'c'; break; case '(': c = 'p'; break; case ')': c = 'P'; break; case '[': c = 'b'; break; case ']': c = 'B'; break; case '^': c = 'x'; break; case '|': c = 'o'; break; case '~': c = 'n'; break; case '!': c = 'N'; break; case '%': c = 'M'; break; case '?': c = 'q'; break; case '+': c = 'a'; break; case '-': c = 's'; break; case '/': c = 'd'; break; default: break; } if (isalpha((int) c)) { Printf(result, "_S%c_", (int) c); } else { Printf(result, "_S%02X_", (int) c); } } ++pc; } Delete(b); return result; #endif }
int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope) { List *patchlist, *cpatchlist, *typelist; String *templateargs; String *tname; String *iname; String *tbase; patchlist = NewList(); cpatchlist = NewList(); typelist = NewList(); { String *tmp = NewStringEmpty(); if (tparms) { SwigType_add_template(tmp, tparms); } templateargs = Copy(tmp); Delete(tmp); } tname = Copy(Getattr(n, "name")); tbase = Swig_scopename_last(tname); /* Look for partial specialization matching */ if (Getattr(n, "partialargs")) { Parm *p, *tp; ParmList *ptargs = SwigType_function_parms(Getattr(n, "partialargs")); p = ptargs; tp = tparms; while (p && tp) { SwigType *ptype; SwigType *tptype; SwigType *partial_type; ptype = Getattr(p, "type"); tptype = Getattr(tp, "type"); if (ptype && tptype) { partial_type = partial_arg(tptype, ptype); /* Printf(stdout,"partial '%s' '%s' ---> '%s'\n", tptype, ptype, partial_type); */ Setattr(tp, "type", partial_type); Delete(partial_type); } p = nextSibling(p); tp = nextSibling(tp); } assert(ParmList_len(ptargs) == ParmList_len(tparms)); Delete(ptargs); } /* Parm *p = tparms; while (p) { Printf(stdout, "tparm: '%s' '%s' '%s'\n", Getattr(p, "name"), Getattr(p, "type"), Getattr(p, "value")); p = nextSibling(p); } */ /* Printf(stdout,"targs = '%s'\n", templateargs); Printf(stdout,"rname = '%s'\n", rname); Printf(stdout,"tname = '%s'\n", tname); */ cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist); /* Set the name */ { String *name = Getattr(n, "name"); if (name) { Append(name, templateargs); } iname = name; } /* Patch all of the types */ { Parm *tp = Getattr(n, "templateparms"); Parm *p = tparms; /* Printf(stdout,"%s\n", ParmList_str_defaultargs(tp)); */ if (tp) { Symtab *tsdecl = Getattr(n, "sym:symtab"); while (p && tp) { String *name, *value, *valuestr, *tydef, *tmp, *tmpr; int sz, i; String *dvalue = 0; String *qvalue = 0; name = Getattr(tp, "name"); value = Getattr(p, "value"); tydef = Getattr(p, "typedef"); if (name) { if (!value) value = Getattr(p, "type"); qvalue = Swig_symbol_typedef_reduce(value, tsdecl); dvalue = Swig_symbol_type_qualify(qvalue, tsdecl); if (SwigType_istemplate(dvalue)) { String *ty = Swig_symbol_template_deftype(dvalue, tscope); Delete(dvalue); dvalue = ty; } assert(dvalue); valuestr = SwigType_str(dvalue, 0); /* Need to patch default arguments */ { Parm *rp = nextSibling(p); while (rp) { String *rvalue = Getattr(rp, "value"); if (rvalue) { Replace(rvalue, name, dvalue, DOH_REPLACE_ID); } rp = nextSibling(rp); } } sz = Len(patchlist); for (i = 0; i < sz; i++) { String *s = Getitem(patchlist, i); Replace(s, name, dvalue, DOH_REPLACE_ID); } sz = Len(typelist); for (i = 0; i < sz; i++) { String *s = Getitem(typelist, i); /* Replace(s,name,value, DOH_REPLACE_ID); */ /* Printf(stdout,"name = '%s', value = '%s', tbase = '%s', iname='%s' s = '%s' --> ", name, dvalue, tbase, iname, s); */ SwigType_typename_replace(s, name, dvalue); SwigType_typename_replace(s, tbase, iname); /* Printf(stdout,"'%s'\n", s); */ } if (!tydef) { tydef = dvalue; } tmp = NewStringf("#%s", name); tmpr = NewStringf("\"%s\"", valuestr); sz = Len(cpatchlist); for (i = 0; i < sz; i++) { String *s = Getitem(cpatchlist, i); Replace(s, tmp, tmpr, DOH_REPLACE_ID); /* Replace(s,name,tydef, DOH_REPLACE_ID); */ Replace(s, name, valuestr, DOH_REPLACE_ID); } Delete(tmp); Delete(tmpr); Delete(valuestr); Delete(dvalue); Delete(qvalue); } p = nextSibling(p); tp = nextSibling(tp); if (!p) p = tp; } } else { /* No template parameters at all. This could be a specialization */ int i, sz; sz = Len(typelist); for (i = 0; i < sz; i++) { String *s = Getitem(typelist, i); SwigType_typename_replace(s, tbase, iname); } } } /* Patch bases */ { List *bases = Getattr(n, "baselist"); if (bases) { Iterator b; for (b = First(bases); b.item; b = Next(b)) { String *qn = Swig_symbol_type_qualify(b.item, tscope); Clear(b.item); Append(b.item, qn); Delete(qn); } } } Delete(patchlist); Delete(cpatchlist); Delete(typelist); Delete(tbase); Delete(tname); Delete(templateargs); /* set_nodeType(n,"template"); */ return 0; }
static String *manglestr_default(const SwigType *s) { char *c; String *result = 0; String *base = 0; SwigType *lt; SwigType *sr = SwigType_typedef_resolve_all(s); SwigType *sq = SwigType_typedef_qualified(sr); SwigType *ss = SwigType_remove_global_scope_prefix(sq); SwigType *type = ss; if (SwigType_istemplate(ss)) { SwigType *ty = Swig_symbol_template_deftype(ss, 0); Delete(ss); ss = ty; type = ss; } lt = SwigType_ltype(type); result = SwigType_prefix(lt); base = SwigType_base(lt); c = Char(result); while (*c) { if (!isalnum((int) *c)) *c = '_'; c++; } if (SwigType_istemplate(base)) { String *b = SwigType_namestr(base); Delete(base); base = b; } Replace(base, "struct ", "", DOH_REPLACE_ANY); /* This might be problematic */ Replace(base, "class ", "", DOH_REPLACE_ANY); Replace(base, "union ", "", DOH_REPLACE_ANY); Replace(base, "enum ", "", DOH_REPLACE_ANY); c = Char(base); while (*c) { if (*c == '<') *c = 'T'; else if (*c == '>') *c = 't'; else if (*c == '*') *c = 'p'; else if (*c == '[') *c = 'a'; else if (*c == ']') *c = 'A'; else if (*c == '&') *c = 'R'; else if (*c == '(') *c = 'f'; else if (*c == ')') *c = 'F'; else if (!isalnum((int) *c)) *c = '_'; c++; } Append(result, base); Insert(result, 0, "_"); Delete(lt); Delete(base); Delete(ss); Delete(sq); Delete(sr); return result; }
void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *decl, const_String_or_char_ptr featurename, String *value, Hash *featureattribs) { Hash *n; Hash *fhash; #ifdef SWIG_DEBUG Printf(stdout, "Swig_feature_set: '%s' '%s' '%s' '%s'\n", name, decl, featurename, value); #endif n = Getattr(features, name); if (!n) { n = NewHash(); Setattr(features, name, n); Delete(n); } if (!decl) { fhash = Getattr(n, "start"); if (!fhash) { fhash = NewHash(); Setattr(n, "start", fhash); Delete(fhash); } } else { fhash = Getattr(n, decl); if (!fhash) { String *cdecl_ = Copy(decl); fhash = NewHash(); Setattr(n, cdecl_, fhash); Delete(cdecl_); Delete(fhash); } } if (value) { Setattr(fhash, featurename, value); } else { Delattr(fhash, featurename); } { /* Add in the optional feature attributes */ Hash *attribs = featureattribs; while (attribs) { String *attribname = Getattr(attribs, "name"); String *featureattribname = NewStringf("%s:%s", featurename, attribname); if (value) { String *attribvalue = Getattr(attribs, "value"); Setattr(fhash, featureattribname, attribvalue); } else { Delattr(fhash, featureattribname); } attribs = nextSibling(attribs); Delete(featureattribname); } } if (name && SwigType_istemplate(name)) { String *dname = Swig_symbol_template_deftype(name, 0); if (Strcmp(dname, name)) { Swig_feature_set(features, dname, decl, featurename, value, featureattribs); } Delete(dname); } }
void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, Node *node) { char *ncdecl = 0; String *rdecl = 0; String *rname = 0; if (!features) return; /* MM: This removed to more tightly control feature/name matching */ /* if ((decl) && (SwigType_isqualifier(decl))) { ncdecl = strchr(Char(decl),'.'); ncdecl++; } */ /* very specific hack for template constructors/destructors */ if (name && SwigType_istemplate(name)) { String *nodetype = nodeType(node); if (nodetype && (Equal(nodetype, "constructor") || Equal(nodetype, "destructor"))) { String *nprefix = NewStringEmpty(); String *nlast = NewStringEmpty(); String *tprefix; Swig_scopename_split(name, &nprefix, &nlast); tprefix = SwigType_templateprefix(nlast); Delete(nlast); if (Len(nprefix)) { Append(nprefix, "::"); Append(nprefix, tprefix); Delete(tprefix); rname = nprefix; } else { rname = tprefix; Delete(nprefix); } rdecl = Copy(decl); Replaceall(rdecl, name, rname); decl = rdecl; name = rname; } } #ifdef SWIG_DEBUG Printf(stdout, "Swig_features_get: '%s' '%s' '%s'\n", prefix, name, decl); #endif /* Global features */ features_get(features, "", 0, 0, node); if (name) { String *tname = NewStringEmpty(); /* add features for 'root' template */ String *dname = SwigType_istemplate_templateprefix(name); if (dname) { features_get(features, dname, decl, ncdecl, node); } /* Catch-all */ features_get(features, name, decl, ncdecl, node); /* Perform a class-based lookup (if class prefix supplied) */ if (prefix) { /* A class-generic feature */ if (Len(prefix)) { Printf(tname, "%s::", prefix); features_get(features, tname, decl, ncdecl, node); } /* A wildcard-based class lookup */ Clear(tname); Printf(tname, "*::%s", name); features_get(features, tname, decl, ncdecl, node); /* A specific class lookup */ if (Len(prefix)) { /* A template-based class lookup */ String *tprefix = SwigType_istemplate_templateprefix(prefix); if (tprefix) { Clear(tname); Printf(tname, "%s::%s", tprefix, name); features_get(features, tname, decl, ncdecl, node); } Clear(tname); Printf(tname, "%s::%s", prefix, name); features_get(features, tname, decl, ncdecl, node); Delete(tprefix); } } else { /* Lookup in the global namespace only */ Clear(tname); Printf(tname, "::%s", name); features_get(features, tname, decl, ncdecl, node); } Delete(tname); Delete(dname); } if (name && SwigType_istemplate(name)) { /* add features for complete template type */ String *dname = Swig_symbol_template_deftype(name, 0); if (!Equal(dname, name)) { Swig_features_get(features, prefix, dname, decl, node); } Delete(dname); } if (rname) Delete(rname); if (rdecl) Delete(rdecl); }