support of typemaps + template + template def args
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6808 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
47ae5abfab
commit
9b963f9763
4 changed files with 92 additions and 27 deletions
|
|
@ -58,6 +58,7 @@ extern int need_redefined_warn(Node* a, Node* b, int InClass);
|
||||||
|
|
||||||
/* templ.c */
|
/* templ.c */
|
||||||
extern void Swig_cparse_template_defargs(Parm *parms, Parm *targs, Symtab *tscope);
|
extern void Swig_cparse_template_defargs(Parm *parms, Parm *targs, Symtab *tscope);
|
||||||
|
extern String* Swig_cparse_template_deftype(SwigType *type, Symtab *tscope);
|
||||||
extern int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope);
|
extern int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope);
|
||||||
extern Node *Swig_cparse_template_locate(String *name, ParmList *tparms, Symtab *tscope);
|
extern Node *Swig_cparse_template_locate(String *name, ParmList *tparms, Symtab *tscope);
|
||||||
extern void Swig_cparse_debug_templates(int);
|
extern void Swig_cparse_debug_templates(int);
|
||||||
|
|
|
||||||
|
|
@ -3301,25 +3301,8 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { template_para
|
||||||
Delete(targs);
|
Delete(targs);
|
||||||
} else {
|
} else {
|
||||||
/* Need to resolve exact specialization name */
|
/* Need to resolve exact specialization name */
|
||||||
/* This needs to be rewritten */
|
|
||||||
ParmList *tparms;
|
|
||||||
String *fname;
|
|
||||||
Parm *p;
|
|
||||||
fname = SwigType_templateprefix(tname);
|
|
||||||
tparms = SwigType_function_parms(tname);
|
|
||||||
/* add default args from generic template */
|
/* add default args from generic template */
|
||||||
Swig_cparse_template_defargs(tparms, Getattr(tempn,"templateparms"),0);
|
String *fname = Swig_cparse_template_deftype(tname,0);
|
||||||
Append(fname,"<(");
|
|
||||||
p = tparms;
|
|
||||||
while (p){
|
|
||||||
SwigType *type = Getattr(p,"type");
|
|
||||||
SwigType *ttr = Swig_symbol_typedef_reduce(type ? type : Getattr(p,"value") ,0);
|
|
||||||
ttr = Swig_symbol_type_qualify(ttr,0);
|
|
||||||
Append(fname,ttr);
|
|
||||||
p = nextSibling(p);
|
|
||||||
if (p) Putc(',',fname);
|
|
||||||
}
|
|
||||||
Append(fname,")>");
|
|
||||||
Swig_symbol_cadd(fname,$$);
|
Swig_symbol_cadd(fname,$$);
|
||||||
}
|
}
|
||||||
} else if ($$) {
|
} else if ($$) {
|
||||||
|
|
|
||||||
|
|
@ -428,6 +428,59 @@ Swig_cparse_template_defargs(Parm *parms, Parm *targs, Symtab *tscope) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* Swig_cparse_template_deftype()
|
||||||
|
*
|
||||||
|
* Apply default args to generic template type
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
String*
|
||||||
|
Swig_cparse_template_deftype(SwigType *type, Symtab *tscope) {
|
||||||
|
String *prefix = SwigType_prefix(type);
|
||||||
|
String *base = SwigType_base(type);
|
||||||
|
String *tprefix = SwigType_templateprefix(base);
|
||||||
|
String *targs = SwigType_templateargs(base);
|
||||||
|
String *tsuffix = SwigType_templatesuffix(base);
|
||||||
|
ParmList *tparms = SwigType_function_parms(targs);
|
||||||
|
Node *tempn = Swig_symbol_clookup_local(tprefix,tscope);
|
||||||
|
if (tempn) {
|
||||||
|
ParmList *tnargs = Getattr(tempn,"templateparms");
|
||||||
|
Parm *p;
|
||||||
|
/* Printf(stderr,"deftype type %s %s %s\n", tprefix, targs, tsuffix);*/
|
||||||
|
Append(tprefix,"<(");
|
||||||
|
Swig_cparse_template_defargs(tparms, tnargs,tscope);
|
||||||
|
p = tparms;
|
||||||
|
while (p) {
|
||||||
|
SwigType *ptype = Getattr(p,"type");
|
||||||
|
SwigType *ttr = Swig_symbol_typedef_reduce(ptype ? ptype : Getattr(p,"value") ,tscope);
|
||||||
|
SwigType *ttq = Swig_symbol_type_qualify(ttr,tscope);
|
||||||
|
if (SwigType_istemplate(ttq)) {
|
||||||
|
SwigType *t = Swig_cparse_template_deftype(ttq, tscope);
|
||||||
|
Delete(ttq);
|
||||||
|
ttq = t;
|
||||||
|
}
|
||||||
|
Append(tprefix,ttq);
|
||||||
|
p = nextSibling(p);
|
||||||
|
if (p) Putc(',',tprefix);
|
||||||
|
Delete(ttr);
|
||||||
|
Delete(ttq);
|
||||||
|
}
|
||||||
|
Append(tprefix,")>");
|
||||||
|
Append(tprefix,tsuffix);
|
||||||
|
Append(prefix,tprefix);
|
||||||
|
/* Printf(stderr,"deftype default %s \n", tprefix); */
|
||||||
|
type = Copy(prefix);
|
||||||
|
} else {
|
||||||
|
type = Copy(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
Delete(prefix);
|
||||||
|
Delete(base);
|
||||||
|
Delete(tprefix);
|
||||||
|
Delete(tsuffix);
|
||||||
|
Delete(targs);
|
||||||
|
Delete(tparms);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* template_locate()
|
* template_locate()
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,33 @@ static void replace_embedded_typemap(String *s);
|
||||||
static Hash *typemaps[MAX_SCOPE];
|
static Hash *typemaps[MAX_SCOPE];
|
||||||
static int tm_scope = 0;
|
static int tm_scope = 0;
|
||||||
|
|
||||||
|
static Hash* get_typemap(int tm_scope, SwigType* type)
|
||||||
|
{
|
||||||
|
Hash *tm = 0;
|
||||||
|
SwigType* dtype = 0;
|
||||||
|
if (SwigType_istemplate(type)) {
|
||||||
|
dtype = Swig_cparse_template_deftype(type,0);
|
||||||
|
/* Printf(stderr,"gettm %s %s\n", type, dtype);*/
|
||||||
|
type = dtype;
|
||||||
|
}
|
||||||
|
tm = Getattr(typemaps[tm_scope],type);
|
||||||
|
if (dtype) Delete(dtype);
|
||||||
|
return tm;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_typemap(int tm_scope, SwigType* type, Hash* tm)
|
||||||
|
{
|
||||||
|
SwigType* dtype = 0;
|
||||||
|
if (SwigType_istemplate(type)) {
|
||||||
|
dtype = Swig_cparse_template_deftype(type,0);
|
||||||
|
/* Printf(stderr,"settm %s %s\n", type, dtype);*/
|
||||||
|
type = dtype;
|
||||||
|
}
|
||||||
|
Setattr(typemaps[tm_scope],Copy(type),tm);
|
||||||
|
if (dtype) Delete(dtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Swig_typemap_init()
|
* Swig_typemap_init()
|
||||||
*
|
*
|
||||||
|
|
@ -135,10 +162,10 @@ Swig_typemap_register(const String_or_char *op, ParmList *parms, String_or_char
|
||||||
pname = Getattr(parms,"name");
|
pname = Getattr(parms,"name");
|
||||||
|
|
||||||
/* See if this type has been seen before */
|
/* See if this type has been seen before */
|
||||||
tm = Getattr(typemaps[tm_scope],type);
|
tm = get_typemap(tm_scope,type);
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
tm = NewHash();
|
tm = NewHash();
|
||||||
Setattr(typemaps[tm_scope],Copy(type),tm);
|
set_typemap(tm_scope,type,tm);
|
||||||
Delete(tm);
|
Delete(tm);
|
||||||
}
|
}
|
||||||
if (pname) {
|
if (pname) {
|
||||||
|
|
@ -216,7 +243,7 @@ Swig_typemap_get(SwigType *type, String_or_char *name, int scope) {
|
||||||
Hash *tm, *tm1;
|
Hash *tm, *tm1;
|
||||||
/* See if this type has been seen before */
|
/* See if this type has been seen before */
|
||||||
if ((scope < 0) || (scope > tm_scope)) return 0;
|
if ((scope < 0) || (scope > tm_scope)) return 0;
|
||||||
tm = Getattr(typemaps[scope],type);
|
tm = get_typemap(scope,type);
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -368,10 +395,11 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make sure a typemap node exists for the last destination node */
|
/* make sure a typemap node exists for the last destination node */
|
||||||
tm = Getattr(typemaps[tm_scope],Getattr(lastdp,"type"));
|
type = Getattr(lastdp,"type");
|
||||||
|
tm = get_typemap(tm_scope,type);
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
tm = NewHash();
|
tm = NewHash();
|
||||||
Setattr(typemaps[tm_scope],Getattr(lastdp,"type"),tm);
|
set_typemap(tm_scope,type,tm);
|
||||||
Delete(tm);
|
Delete(tm);
|
||||||
}
|
}
|
||||||
name = Getattr(lastdp,"name");
|
name = Getattr(lastdp,"name");
|
||||||
|
|
@ -478,7 +506,7 @@ Swig_typemap_clear_apply(Parm *parms) {
|
||||||
}
|
}
|
||||||
p = np;
|
p = np;
|
||||||
}
|
}
|
||||||
tm = Getattr(typemaps[tm_scope],Getattr(lastp,"type"));
|
tm = get_typemap(tm_scope,Getattr(lastp,"type"));
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
Delete(tsig);
|
Delete(tsig);
|
||||||
return;
|
return;
|
||||||
|
|
@ -546,7 +574,7 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch
|
||||||
ctype = type;
|
ctype = type;
|
||||||
while (ctype) {
|
while (ctype) {
|
||||||
/* Try to get an exact type-match */
|
/* Try to get an exact type-match */
|
||||||
tm = Getattr(typemaps[ts],ctype);
|
tm = get_typemap(ts,ctype);
|
||||||
if (tm && cname) {
|
if (tm && cname) {
|
||||||
tm1 = Getattr(tm,cname);
|
tm1 = Getattr(tm,cname);
|
||||||
if (tm1) {
|
if (tm1) {
|
||||||
|
|
@ -567,7 +595,7 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch
|
||||||
if (!noarrays) {
|
if (!noarrays) {
|
||||||
noarrays = strip_arrays(ctype);
|
noarrays = strip_arrays(ctype);
|
||||||
}
|
}
|
||||||
tma = Getattr(typemaps[ts],noarrays);
|
tma = get_typemap(ts,noarrays);
|
||||||
if (tma && cname) {
|
if (tma && cname) {
|
||||||
tm1 = Getattr(tma,cname);
|
tm1 = Getattr(tma,cname);
|
||||||
if (tm1) {
|
if (tm1) {
|
||||||
|
|
@ -613,7 +641,7 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch
|
||||||
|
|
||||||
primitive = SwigType_default(type);
|
primitive = SwigType_default(type);
|
||||||
while (primitive) {
|
while (primitive) {
|
||||||
tm = Getattr(typemaps[ts],primitive);
|
tm = get_typemap(ts,primitive);
|
||||||
if (tm && cname) {
|
if (tm && cname) {
|
||||||
tm1 = Getattr(tm,cname);
|
tm1 = Getattr(tm,cname);
|
||||||
if (tm1) {
|
if (tm1) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue