Merge branch 'master' into doxygen

The way Python docstrings are indented has changed on master, so use the
standard inspect module in Python autodoc unit test to ignore the differences
in their indentation level between -builtin and non-builtin cases to make the
test still pass with the branch version, which avoids the use of different
(but almost identical) values in the test itself.
This commit is contained in:
Vadim Zeitlin 2016-12-05 02:14:51 +01:00
commit e668c47b70
1094 changed files with 39390 additions and 11483 deletions

View file

@ -291,6 +291,7 @@ int Swig_insert_file(const_String_or_char_ptr filename, File *outfile) {
while ((nbytes = Read(f, buffer, 4096)) > 0) {
Write(outfile, buffer, nbytes);
}
fclose(f);
return 0;
}

View file

@ -309,6 +309,7 @@ int Swig_storage_isstatic(Node *n) {
* Swig_string_escape()
*
* Takes a string object and produces a string with escape codes added to it.
* Octal escaping is used.
* ----------------------------------------------------------------------------- */
String *Swig_string_escape(String *s) {
@ -342,6 +343,43 @@ String *Swig_string_escape(String *s) {
return ns;
}
/* -----------------------------------------------------------------------------
* Swig_string_hexescape()
*
* Takes a string object and produces a string with escape codes added to it.
* Hex escaping is used.
* ----------------------------------------------------------------------------- */
String *Swig_string_hexescape(String *s) {
String *ns;
int c;
ns = NewStringEmpty();
while ((c = Getc(s)) != EOF) {
if (c == '\n') {
Printf(ns, "\\n");
} else if (c == '\r') {
Printf(ns, "\\r");
} else if (c == '\t') {
Printf(ns, "\\t");
} else if (c == '\\') {
Printf(ns, "\\\\");
} else if (c == '\'') {
Printf(ns, "\\'");
} else if (c == '\"') {
Printf(ns, "\\\"");
} else if (c == ' ') {
Putc(c, ns);
} else if (!isgraph(c)) {
if (c < 0)
c += UCHAR_MAX + 1;
Printf(ns, "\\x%X", c);
} else {
Putc(c, ns);
}
}
return ns;
}
/* -----------------------------------------------------------------------------
* Swig_string_upper()
@ -1147,6 +1185,39 @@ String *Swig_string_strip(String *s) {
return ns;
}
/* -----------------------------------------------------------------------------
* Swig_string_rstrip()
*
* Strip given suffix from identifiers
*
* Printf(stderr,"%(rstrip:[Cls])s","HelloCls") -> Hello
* ----------------------------------------------------------------------------- */
String *Swig_string_rstrip(String *s) {
String *ns;
int len = Len(s);
if (!len) {
ns = NewString(s);
} else {
const char *cs = Char(s);
const char *ce = Strchr(cs, ']');
if (*cs != '[' || !ce) {
ns = NewString(s);
} else {
String *fmt = NewStringf("%%.%ds", ce-cs-1);
String *suffix = NewStringf(fmt, cs+1);
int suffix_len = Len(suffix);
if (0 == Strncmp(cs+len-suffix_len, suffix, suffix_len)) {
int copy_len = len-suffix_len-(ce+1-cs);
ns = NewStringWithSize(ce+1, copy_len);
} else {
ns = NewString(ce+1);
}
}
}
return ns;
}
/* -----------------------------------------------------------------------------
* Swig_offset_string()
*
@ -1328,7 +1399,7 @@ String *replace_captures(int num_captures, const char *input, String *subst, int
*
* Executes a regular expression substitution. For example:
*
* Printf(stderr,"gsl%(regex:/GSL_.*_/\\1/)s","GSL_Hello_") -> gslHello
* Printf(stderr,"gsl%(regex:/GSL_(.*)_/\\1/)s", "GSL_Hello_") -> gslHello
* ----------------------------------------------------------------------------- */
String *Swig_string_regex(String *s) {
const int pcre_options = 0;
@ -1403,6 +1474,7 @@ int Swig_is_generated_overload(Node *n) {
void Swig_init() {
/* Set some useful string encoding methods */
DohEncoding("escape", Swig_string_escape);
DohEncoding("hexescape", Swig_string_hexescape);
DohEncoding("upper", Swig_string_upper);
DohEncoding("lower", Swig_string_lower);
DohEncoding("title", Swig_string_title);
@ -1414,6 +1486,7 @@ void Swig_init() {
DohEncoding("command", Swig_string_command);
DohEncoding("schemify", Swig_string_schemify);
DohEncoding("strip", Swig_string_strip);
DohEncoding("rstrip", Swig_string_rstrip);
DohEncoding("regex", Swig_string_regex);
/* aliases for the case encoders */

View file

@ -50,6 +50,13 @@ void Swig_name_unregister(const_String_or_char_ptr method) {
}
}
/* Return naming format for the specified method or the default format if none was explicitly registered */
static String* get_naming_format_for(const char *method, const char *def_format) {
String* f = naming_hash ? Getattr(naming_hash, method) : NULL;
return f ? Copy(f) : NewString(def_format);
}
static int name_mangle(String *r) {
char *c;
int special;
@ -172,18 +179,8 @@ String *Swig_name_mangle(const_String_or_char_ptr s) {
* ----------------------------------------------------------------------------- */
String *Swig_name_wrapper(const_String_or_char_ptr fname) {
String *r;
String *f;
String *r = get_naming_format_for("wrapper", "_wrap_%f");
r = NewStringEmpty();
if (!naming_hash)
naming_hash = NewHash();
f = Getattr(naming_hash, "wrapper");
if (!f) {
Append(r, "_wrap_%f");
} else {
Append(r, f);
}
Replace(r, "%f", fname, DOH_REPLACE_ANY);
name_mangle(r);
return r;
@ -198,20 +195,11 @@ String *Swig_name_wrapper(const_String_or_char_ptr fname) {
String *Swig_name_member(const_String_or_char_ptr nspace, const_String_or_char_ptr classname, const_String_or_char_ptr membername) {
String *r;
String *f;
String *rclassname;
char *cname;
rclassname = SwigType_namestr(classname);
r = NewStringEmpty();
if (!naming_hash)
naming_hash = NewHash();
f = Getattr(naming_hash, "member");
if (!f) {
Append(r, "%n%c_%m");
} else {
Append(r, f);
}
r = get_naming_format_for("member", "%n%c_%m");
cname = Char(rclassname);
if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) {
cname = strchr(cname, ' ') + 1;
@ -231,23 +219,12 @@ String *Swig_name_member(const_String_or_char_ptr nspace, const_String_or_char_p
* ----------------------------------------------------------------------------- */
String *Swig_name_get(const_String_or_char_ptr nspace, const_String_or_char_ptr vname) {
String *r;
String *f;
String *r = get_naming_format_for("get", "%n%v_get");
#ifdef SWIG_DEBUG
Printf(stdout, "Swig_name_get: '%s'\n", vname);
#endif
r = NewStringEmpty();
if (!naming_hash)
naming_hash = NewHash();
f = Getattr(naming_hash, "get");
if (!f) {
Append(r, "%n%v_get");
} else {
Append(r, f);
}
replace_nspace(r, nspace);
Replace(r, "%v", vname, DOH_REPLACE_ANY);
/* name_mangle(r); */
@ -261,18 +238,7 @@ String *Swig_name_get(const_String_or_char_ptr nspace, const_String_or_char_ptr
* ----------------------------------------------------------------------------- */
String *Swig_name_set(const_String_or_char_ptr nspace, const_String_or_char_ptr vname) {
String *r;
String *f;
r = NewStringEmpty();
if (!naming_hash)
naming_hash = NewHash();
f = Getattr(naming_hash, "set");
if (!f) {
Append(r, "%n%v_set");
} else {
Append(r, f);
}
String *r = get_naming_format_for("set", "%n%v_set");
replace_nspace(r, nspace);
Replace(r, "%v", vname, DOH_REPLACE_ANY);
@ -280,6 +246,26 @@ String *Swig_name_set(const_String_or_char_ptr nspace, const_String_or_char_ptr
return r;
}
/* Common implementation of all Swig_name_<special-method>() functions below. */
static String *make_full_name_for(const char *method, const char *def_format, const_String_or_char_ptr nspace, const_String_or_char_ptr classname) {
String *r;
String *rclassname;
char *cname;
rclassname = SwigType_namestr(classname);
r = get_naming_format_for(method, def_format);
cname = Char(rclassname);
if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) {
cname = strchr(cname, ' ') + 1;
}
replace_nspace(r, nspace);
Replace(r, "%c", cname, DOH_REPLACE_ANY);
Delete(rclassname);
return r;
}
/* -----------------------------------------------------------------------------
* Swig_name_construct()
*
@ -287,31 +273,7 @@ String *Swig_name_set(const_String_or_char_ptr nspace, const_String_or_char_ptr
* ----------------------------------------------------------------------------- */
String *Swig_name_construct(const_String_or_char_ptr nspace, const_String_or_char_ptr classname) {
String *r;
String *f;
String *rclassname;
char *cname;
rclassname = SwigType_namestr(classname);
r = NewStringEmpty();
if (!naming_hash)
naming_hash = NewHash();
f = Getattr(naming_hash, "construct");
if (!f) {
Append(r, "new_%n%c");
} else {
Append(r, f);
}
cname = Char(rclassname);
if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) {
cname = strchr(cname, ' ') + 1;
}
replace_nspace(r, nspace);
Replace(r, "%c", cname, DOH_REPLACE_ANY);
Delete(rclassname);
return r;
return make_full_name_for("construct", "new_%n%c", nspace, classname);
}
@ -322,31 +284,7 @@ String *Swig_name_construct(const_String_or_char_ptr nspace, const_String_or_cha
* ----------------------------------------------------------------------------- */
String *Swig_name_copyconstructor(const_String_or_char_ptr nspace, const_String_or_char_ptr classname) {
String *r;
String *f;
String *rclassname;
char *cname;
rclassname = SwigType_namestr(classname);
r = NewStringEmpty();
if (!naming_hash)
naming_hash = NewHash();
f = Getattr(naming_hash, "copy");
if (!f) {
Append(r, "copy_%n%c");
} else {
Append(r, f);
}
cname = Char(rclassname);
if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) {
cname = strchr(cname, ' ') + 1;
}
replace_nspace(r, nspace);
Replace(r, "%c", cname, DOH_REPLACE_ANY);
Delete(rclassname);
return r;
return make_full_name_for("copy", "copy_%n%c", nspace, classname);
}
/* -----------------------------------------------------------------------------
@ -356,30 +294,7 @@ String *Swig_name_copyconstructor(const_String_or_char_ptr nspace, const_String_
* ----------------------------------------------------------------------------- */
String *Swig_name_destroy(const_String_or_char_ptr nspace, const_String_or_char_ptr classname) {
String *r;
String *f;
String *rclassname;
char *cname;
rclassname = SwigType_namestr(classname);
r = NewStringEmpty();
if (!naming_hash)
naming_hash = NewHash();
f = Getattr(naming_hash, "destroy");
if (!f) {
Append(r, "delete_%n%c");
} else {
Append(r, f);
}
cname = Char(rclassname);
if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) {
cname = strchr(cname, ' ') + 1;
}
replace_nspace(r, nspace);
Replace(r, "%c", cname, DOH_REPLACE_ANY);
Delete(rclassname);
return r;
return make_full_name_for("destroy", "delete_%n%c", nspace, classname);
}
@ -390,30 +305,7 @@ String *Swig_name_destroy(const_String_or_char_ptr nspace, const_String_or_char_
* ----------------------------------------------------------------------------- */
String *Swig_name_disown(const_String_or_char_ptr nspace, const_String_or_char_ptr classname) {
String *r;
String *f;
String *rclassname;
char *cname;
rclassname = SwigType_namestr(classname);
r = NewStringEmpty();
if (!naming_hash)
naming_hash = NewHash();
f = Getattr(naming_hash, "disown");
if (!f) {
Append(r, "disown_%n%c");
} else {
Append(r, f);
}
cname = Char(rclassname);
if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) {
cname = strchr(cname, ' ') + 1;
}
replace_nspace(r, nspace);
Replace(r, "%c", cname, DOH_REPLACE_ANY);
Delete(rclassname);
return r;
return make_full_name_for("disown", "disown_%n%c", nspace, classname);
}
@ -466,8 +358,7 @@ static DOH *get_object(Hash *n, String *decl) {
return rn;
}
static
DOH *name_object_get(Hash *namehash, String *tname, SwigType *decl, SwigType *ncdecl) {
static DOH *name_object_get(Hash *namehash, String *tname, SwigType *decl, SwigType *ncdecl) {
DOH *rn = 0;
Hash *n = Getattr(namehash, tname);
if (n) {
@ -513,7 +404,17 @@ DOH *Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType
}
Delete(cls);
}
/* A template-based class lookup, check name first */
/* Lookup a name within a templated-based class */
if (!rn) {
String *t_name = SwigType_istemplate_templateprefix(prefix);
if (t_name) {
Clear(tname);
Printf(tname, "%s::%s", t_name, name);
rn = name_object_get(namehash, tname, decl, ncdecl);
Delete(t_name);
}
}
/* Lookup a template-based name within a class */
if (!rn) {
String *t_name = SwigType_istemplate_templateprefix(name);
if (t_name)
@ -646,8 +547,7 @@ static void merge_features(Hash *features, Node *n) {
* the declaration, decl.
* ----------------------------------------------------------------------------- */
static
void features_get(Hash *features, const String *tname, SwigType *decl, SwigType *ncdecl, Node *node) {
static void features_get(Hash *features, const String *tname, SwigType *decl, SwigType *ncdecl, Node *node) {
Node *n = Getattr(features, tname);
#ifdef SWIG_DEBUG
Printf(stdout, " features_get: %s\n", tname);
@ -844,41 +744,41 @@ void Swig_feature_set(Hash *features, const_String_or_char_ptr name, SwigType *d
* ----------------------------------------------------------------------------- */
static Hash *namewarn_hash = 0;
Hash *Swig_name_namewarn_hash() {
static Hash *name_namewarn_hash() {
if (!namewarn_hash)
namewarn_hash = NewHash();
return namewarn_hash;
}
static Hash *rename_hash = 0;
Hash *Swig_name_rename_hash() {
static Hash *name_rename_hash() {
if (!rename_hash)
rename_hash = NewHash();
return rename_hash;
}
static List *namewarn_list = 0;
List *Swig_name_namewarn_list() {
static List *name_namewarn_list() {
if (!namewarn_list)
namewarn_list = NewList();
return namewarn_list;
}
static List *rename_list = 0;
List *Swig_name_rename_list() {
static List *name_rename_list() {
if (!rename_list)
rename_list = NewList();
return rename_list;
}
/* -----------------------------------------------------------------------------
* int Swig_need_name_warning(Node *n)
* int need_name_warning(Node *n)
*
* Detects if a node needs name warnings
*
* ----------------------------------------------------------------------------- */
int Swig_need_name_warning(Node *n) {
static int need_name_warning(Node *n) {
int need = 1;
/*
We don't use name warnings for:
@ -1061,13 +961,13 @@ int Swig_need_protected(Node *n) {
}
/* -----------------------------------------------------------------------------
* void Swig_name_nameobj_add()
* void name_nameobj_add()
*
* Add nameobj (rename/namewarn)
*
* ----------------------------------------------------------------------------- */
static List *Swig_make_attrlist(const char *ckey) {
static List *make_attrlist(const char *ckey) {
List *list = NewList();
const char *cattr = strchr(ckey, '$');
if (cattr) {
@ -1089,7 +989,7 @@ static List *Swig_make_attrlist(const char *ckey) {
return list;
}
static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) {
static void name_object_attach_keys(const char *keys[], Hash *nameobj) {
Node *kw = nextSibling(nameobj);
List *matchlist = 0;
while (kw) {
@ -1105,7 +1005,7 @@ static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) {
|| (isregexmatch = (strncmp(ckey, "regexmatch", 10) == 0))
|| (isnotmatch = isregexmatch = (strncmp(ckey, "notregexmatch", 13) == 0))) {
Hash *mi = NewHash();
List *attrlist = Swig_make_attrlist(ckey);
List *attrlist = make_attrlist(ckey);
if (!matchlist)
matchlist = NewList();
Setattr(mi, "value", Getattr(kw, "value"));
@ -1135,7 +1035,7 @@ static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) {
}
}
void Swig_name_nameobj_add(Hash *name_hash, List *name_list, String *prefix, String *name, SwigType *decl, Hash *nameobj) {
static void name_nameobj_add(Hash *name_hash, List *name_list, String *prefix, String *name, SwigType *decl, Hash *nameobj) {
String *nname = 0;
if (name && Len(name)) {
String *target_fmt = Getattr(nameobj, "targetfmt");
@ -1164,13 +1064,13 @@ void Swig_name_nameobj_add(Hash *name_hash, List *name_list, String *prefix, Str
}
/* -----------------------------------------------------------------------------
* int Swig_name_match_nameobj()
* int name_match_nameobj()
*
* Apply and check the nameobj's math list to the node
*
* ----------------------------------------------------------------------------- */
static DOH *Swig_get_lattr(Node *n, List *lattr) {
static DOH *get_lattr(Node *n, List *lattr) {
DOH *res = 0;
int ilen = Len(lattr);
int i;
@ -1192,7 +1092,7 @@ static DOH *Swig_get_lattr(Node *n, List *lattr) {
#ifdef HAVE_PCRE
#include <pcre.h>
int Swig_name_regexmatch_value(Node *n, String *pattern, String *s) {
static int name_regexmatch_value(Node *n, String *pattern, String *s) {
pcre *compiled_pat;
const char *err;
int errpos;
@ -1224,7 +1124,7 @@ int Swig_name_regexmatch_value(Node *n, String *pattern, String *s) {
#else /* !HAVE_PCRE */
int Swig_name_regexmatch_value(Node *n, String *pattern, String *s) {
static int name_regexmatch_value(Node *n, String *pattern, String *s) {
(void)pattern;
(void)s;
Swig_error("SWIG", Getline(n),
@ -1234,7 +1134,7 @@ int Swig_name_regexmatch_value(Node *n, String *pattern, String *s) {
#endif /* HAVE_PCRE/!HAVE_PCRE */
int Swig_name_match_value(String *mvalue, String *value) {
static int name_match_value(String *mvalue, String *value) {
#if defined(SWIG_USE_SIMPLE_MATCHOR)
int match = 0;
char *cvalue = Char(value);
@ -1260,12 +1160,11 @@ int Swig_name_match_value(String *mvalue, String *value) {
#endif
}
int Swig_name_match_nameobj(Hash *rn, Node *n) {
static int name_match_nameobj(Hash *rn, Node *n) {
int match = 1;
List *matchlist = Getattr(rn, "matchlist");
#ifdef SWIG_DEBUG
Printf(stdout, "Swig_name_match_nameobj: %s\n", Getattr(n, "name"));
Printf(stdout, "name_match_nameobj: %s\n", Getattr(n, "name"));
#endif
if (matchlist) {
int ilen = Len(matchlist);
@ -1273,14 +1172,14 @@ int Swig_name_match_nameobj(Hash *rn, Node *n) {
for (i = 0; match && (i < ilen); ++i) {
Node *mi = Getitem(matchlist, i);
List *lattr = Getattr(mi, "attrlist");
String *nval = Swig_get_lattr(n, lattr);
String *nval = get_lattr(n, lattr);
int notmatch = GetFlag(mi, "notmatch");
int regexmatch = GetFlag(mi, "regexmatch");
match = 0;
if (nval) {
String *kwval = Getattr(mi, "value");
match = regexmatch ? Swig_name_regexmatch_value(n, kwval, nval)
: Swig_name_match_value(kwval, nval);
match = regexmatch ? name_regexmatch_value(n, kwval, nval)
: name_match_value(kwval, nval);
#ifdef SWIG_DEBUG
Printf(stdout, "val %s %s %d %d \n", nval, kwval, match, ilen);
#endif
@ -1290,19 +1189,19 @@ int Swig_name_match_nameobj(Hash *rn, Node *n) {
}
}
#ifdef SWIG_DEBUG
Printf(stdout, "Swig_name_match_nameobj: %d\n", match);
Printf(stdout, "name_match_nameobj: %d\n", match);
#endif
return match;
}
/* -----------------------------------------------------------------------------
* Hash *Swig_name_nameobj_lget()
* Hash *name_nameobj_lget()
*
* Get a nameobj (rename/namewarn) from the list of filters
*
* ----------------------------------------------------------------------------- */
Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *name, String *decl) {
static Hash *name_nameobj_lget(List *namelist, Node *n, String *prefix, String *name, String *decl) {
Hash *res = 0;
if (namelist) {
int len = Len(namelist);
@ -1313,7 +1212,7 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na
String *rdecl = Getattr(rn, "decl");
if (rdecl && (!decl || !Equal(rdecl, decl))) {
continue;
} else if (Swig_name_match_nameobj(rn, n)) {
} else if (name_match_nameobj(rn, n)) {
String *tname = Getattr(rn, "targetname");
if (tname) {
String *sfmt = Getattr(rn, "sourcefmt");
@ -1336,8 +1235,8 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na
DohIncref(name);
}
}
match = regextarget ? Swig_name_regexmatch_value(n, tname, sname)
: Swig_name_match_value(tname, sname);
match = regextarget ? name_regexmatch_value(n, tname, sname)
: name_match_value(tname, sname);
Delete(sname);
} else {
/* Applying the renaming rule may fail if it contains a %(regex)s expression that doesn't match the given name. */
@ -1367,23 +1266,23 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na
void Swig_name_namewarn_add(String *prefix, String *name, SwigType *decl, Hash *namewrn) {
const char *namewrn_keys[] = { "rename", "error", "fullname", "sourcefmt", "targetfmt", 0 };
Swig_name_object_attach_keys(namewrn_keys, namewrn);
Swig_name_nameobj_add(Swig_name_namewarn_hash(), Swig_name_namewarn_list(), prefix, name, decl, namewrn);
name_object_attach_keys(namewrn_keys, namewrn);
name_nameobj_add(name_namewarn_hash(), name_namewarn_list(), prefix, name, decl, namewrn);
}
/* -----------------------------------------------------------------------------
* Hash *Swig_name_namewarn_get()
* Hash *name_namewarn_get()
*
* Return the namewarn object, if there is one.
*
* ----------------------------------------------------------------------------- */
Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl) {
static Hash *name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl) {
if (!namewarn_hash && !namewarn_list)
return 0;
if (n) {
/* Return in the obvious cases */
if (!name || !Swig_need_name_warning(n)) {
if (!name || !need_name_warning(n)) {
return 0;
} else {
String *access = Getattr(n, "access");
@ -1395,11 +1294,11 @@ Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *de
}
if (name) {
/* Check to see if the name is in the hash */
Hash *wrn = Swig_name_object_get(Swig_name_namewarn_hash(), prefix, name, decl);
if (wrn && !Swig_name_match_nameobj(wrn, n))
Hash *wrn = Swig_name_object_get(name_namewarn_hash(), prefix, name, decl);
if (wrn && !name_match_nameobj(wrn, n))
wrn = 0;
if (!wrn) {
wrn = Swig_name_nameobj_lget(Swig_name_namewarn_list(), n, prefix, name, decl);
wrn = name_nameobj_lget(name_namewarn_list(), n, prefix, name, decl);
}
if (wrn && Getattr(wrn, "error")) {
if (n) {
@ -1422,7 +1321,7 @@ Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *de
* ----------------------------------------------------------------------------- */
String *Swig_name_warning(Node *n, String *prefix, String *name, SwigType *decl) {
Hash *wrn = Swig_name_namewarn_get(n, prefix, name, decl);
Hash *wrn = name_namewarn_get(n, prefix, name, decl);
return (name && wrn) ? Getattr(wrn, "name") : 0;
}
@ -1434,7 +1333,7 @@ String *Swig_name_warning(Node *n, String *prefix, String *name, SwigType *decl)
* ----------------------------------------------------------------------------- */
static void single_rename_add(String *prefix, String *name, SwigType *decl, Hash *newname) {
Swig_name_nameobj_add(Swig_name_rename_hash(), Swig_name_rename_list(), prefix, name, decl, newname);
name_nameobj_add(name_rename_hash(), name_rename_list(), prefix, name, decl, newname);
}
/* Add a new rename. Works much like new_feature including default argument handling. */
@ -1443,7 +1342,7 @@ void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *ne
ParmList *declparms = declaratorparms;
const char *rename_keys[] = { "fullname", "sourcefmt", "targetfmt", "continue", "regextarget", 0 };
Swig_name_object_attach_keys(rename_keys, newname);
name_object_attach_keys(rename_keys, newname);
/* Add the name */
single_rename_add(prefix, name, decl, newname);
@ -1556,11 +1455,10 @@ String *Swig_name_make(Node *n, String *prefix, const_String_or_char_ptr cname,
}
}
if (rename_hash || rename_list || namewarn_hash || namewarn_list) {
Hash *rn = Swig_name_object_get(Swig_name_rename_hash(), prefix, name, decl);
if (!rn || !Swig_name_match_nameobj(rn, n)) {
rn = Swig_name_nameobj_lget(Swig_name_rename_list(), n, prefix, name, decl);
Hash *rn = Swig_name_object_get(name_rename_hash(), prefix, name, decl);
if (!rn || !name_match_nameobj(rn, n)) {
rn = name_nameobj_lget(name_rename_list(), n, prefix, name, decl);
if (rn) {
String *sfmt = Getattr(rn, "sourcefmt");
int fullname = GetFlag(rn, "fullname");
@ -1596,7 +1494,7 @@ String *Swig_name_make(Node *n, String *prefix, const_String_or_char_ptr cname,
}
}
nname = result ? result : name;
wrn = Swig_name_namewarn_get(n, prefix, nname, decl);
wrn = name_namewarn_get(n, prefix, nname, decl);
if (wrn) {
String *rename = Getattr(wrn, "rename");
if (rename) {
@ -1641,14 +1539,14 @@ String *Swig_name_make(Node *n, String *prefix, const_String_or_char_ptr cname,
/* -----------------------------------------------------------------------------
* void Swig_name_inherit()
*
* Inherit namewarn,rename, and feature objects
* Inherit namewarn, rename, and feature objects
*
* ----------------------------------------------------------------------------- */
void Swig_name_inherit(String *base, String *derived) {
/* Printf(stdout,"base = '%s', derived = '%s'\n", base, derived); */
Swig_name_object_inherit(Swig_name_rename_hash(), base, derived);
Swig_name_object_inherit(Swig_name_namewarn_hash(), base, derived);
Swig_name_object_inherit(name_rename_hash(), base, derived);
Swig_name_object_inherit(name_namewarn_hash(), base, derived);
Swig_name_object_inherit(Swig_cparse_features(), base, derived);
}

View file

@ -283,13 +283,11 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Swig_naming_init(void);
extern void Swig_name_namewarn_add(String *prefix, String *name, SwigType *decl, Hash *namewrn);
extern Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl);
extern void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *namewrn, ParmList *declaratorparms);
extern void Swig_name_inherit(String *base, String *derived);
extern List *Swig_make_inherit_list(String *clsname, List *names, String *Namespaceprefix);
extern void Swig_inherit_base_symbols(List *bases);
extern int Swig_need_protected(Node *n);
extern int Swig_need_name_warning(Node *n);
extern int Swig_need_redefined_warn(Node *a, Node *b, int InClass);
extern String *Swig_name_make(Node *n, String *prefix, const_String_or_char_ptr cname, SwigType *decl, String *oldname);
@ -411,8 +409,6 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern String *Swig_typemap_lookup(const_String_or_char_ptr tmap_method, Node *n, const_String_or_char_ptr lname, Wrapper *f);
extern String *Swig_typemap_lookup_out(const_String_or_char_ptr tmap_method, Node *n, const_String_or_char_ptr lname, Wrapper *f, String *actioncode);
extern void Swig_typemap_new_scope(void);
extern Hash *Swig_typemap_pop_scope(void);
extern void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *parms, Wrapper *f);

View file

@ -68,7 +68,7 @@ void Swig_print_node(Node *obj) {
Node *cobj;
print_indent(0);
Printf(stdout, "+++ %s ----------------------------------------\n", nodeType(obj));
Printf(stdout, "+++ %s - %p ----------------------------------------\n", nodeType(obj), obj);
ki = First(obj);
while (ki.key) {
String *k = ki.key;

View file

@ -59,13 +59,9 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper
*
* ----------------------------------------------------------------------------- */
#define MAX_SCOPE 32
static Hash *typemaps;
static Hash *typemaps[MAX_SCOPE];
static int tm_scope = 0;
static Hash *get_typemap(int tm_scope, const SwigType *type) {
static Hash *get_typemap(const SwigType *type) {
Hash *tm = 0;
SwigType *dtype = 0;
SwigType *hashtype;
@ -79,7 +75,7 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) {
/* remove unary scope operator (::) prefix indicating global scope for looking up in the hashmap */
hashtype = SwigType_remove_global_scope_prefix(type);
tm = Getattr(typemaps[tm_scope], hashtype);
tm = Getattr(typemaps, hashtype);
Delete(dtype);
Delete(hashtype);
@ -87,7 +83,7 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) {
return tm;
}
static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) {
static void set_typemap(const SwigType *type, Hash **tmhash) {
SwigType *hashtype = 0;
Hash *new_tm = 0;
assert(*tmhash == 0);
@ -96,7 +92,7 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) {
String *ty = Swig_symbol_template_deftype(rty, 0);
String *tyq = Swig_symbol_type_qualify(ty, 0);
hashtype = SwigType_remove_global_scope_prefix(tyq);
*tmhash = Getattr(typemaps[tm_scope], hashtype);
*tmhash = Getattr(typemaps, hashtype);
Delete(rty);
Delete(tyq);
Delete(ty);
@ -111,7 +107,7 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) {
}
/* note that the unary scope operator (::) prefix indicating global scope has been removed from the type */
Setattr(typemaps[tm_scope], hashtype, *tmhash);
Setattr(typemaps, hashtype, *tmhash);
Delete(hashtype);
Delete(new_tm);
@ -125,12 +121,7 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash **tmhash) {
* ----------------------------------------------------------------------------- */
void Swig_typemap_init() {
int i;
for (i = 0; i < MAX_SCOPE; i++) {
typemaps[i] = 0;
}
typemaps[0] = NewHash();
tm_scope = 0;
typemaps = NewHash();
}
static String *typemap_method_name(const_String_or_char_ptr tmap_method) {
@ -160,32 +151,6 @@ static String *typemap_method_name(const_String_or_char_ptr tmap_method) {
return s;
}
#if 0
/* -----------------------------------------------------------------------------
* Swig_typemap_new_scope()
*
* Create a new typemap scope
* ----------------------------------------------------------------------------- */
void Swig_typemap_new_scope() {
tm_scope++;
typemaps[tm_scope] = NewHash();
}
/* -----------------------------------------------------------------------------
* Swig_typemap_pop_scope()
*
* Pop the last typemap scope off
* ----------------------------------------------------------------------------- */
Hash *Swig_typemap_pop_scope() {
if (tm_scope > 0) {
return typemaps[tm_scope--];
}
return 0;
}
#endif
/* -----------------------------------------------------------------------------
* typemap_register()
*
@ -216,9 +181,9 @@ static void typemap_register(const_String_or_char_ptr tmap_method, ParmList *par
pname = Getattr(parms, "name");
/* See if this type has been seen before */
tm = get_typemap(tm_scope, type);
tm = get_typemap(type);
if (!tm) {
set_typemap(tm_scope, type, &tm);
set_typemap(type, &tm);
}
if (pname) {
/* See if parameter has been seen before */
@ -311,15 +276,12 @@ void Swig_typemap_register(const_String_or_char_ptr tmap_method, ParmList *parms
/* -----------------------------------------------------------------------------
* typemap_get()
*
* Retrieve typemap information from current scope.
* Retrieve typemap information.
* ----------------------------------------------------------------------------- */
static Hash *typemap_get(SwigType *type, const_String_or_char_ptr name, int scope) {
static Hash *typemap_get(SwigType *type, const_String_or_char_ptr name) {
Hash *tm, *tm1;
/* See if this type has been seen before */
if ((scope < 0) || (scope > tm_scope))
return 0;
tm = get_typemap(scope, type);
tm = get_typemap(type);
if (!tm) {
return 0;
}
@ -342,51 +304,48 @@ int Swig_typemap_copy(const_String_or_char_ptr tmap_method, ParmList *srcparms,
Parm *p;
String *pname;
SwigType *ptype;
int ts = tm_scope;
String *tm_methods, *multi_tmap_method;
if (ParmList_len(parms) != ParmList_len(srcparms))
return -1;
tm_method = typemap_method_name(tmap_method);
while (ts >= 0) {
p = srcparms;
tm_methods = NewString(tm_method);
while (p) {
ptype = Getattr(p, "type");
pname = Getattr(p, "name");
p = srcparms;
tm_methods = NewString(tm_method);
while (p) {
ptype = Getattr(p, "type");
pname = Getattr(p, "name");
/* Lookup the type */
tm = typemap_get(ptype, pname, ts);
if (!tm)
break;
/* Lookup the type */
tm = typemap_get(ptype, pname);
if (!tm)
break;
tm = Getattr(tm, tm_methods);
if (!tm)
break;
tm = Getattr(tm, tm_methods);
if (!tm)
break;
/* Got a match. Look for next typemap */
multi_tmap_method = NewStringf("%s-%s+%s:", tm_methods, ptype, pname);
Delete(tm_methods);
tm_methods = multi_tmap_method;
p = nextSibling(p);
}
/* Got a match. Look for next typemap */
multi_tmap_method = NewStringf("%s-%s+%s:", tm_methods, ptype, pname);
Delete(tm_methods);
if (!p && tm) {
/* Got some kind of match */
String *parms_str = ParmList_str_multibrackets(parms);
String *srcparms_str = ParmList_str_multibrackets(srcparms);
String *source_directive = NewStringf("typemap(%s) %s = %s", tmap_method, parms_str, srcparms_str);
typemap_register(tmap_method, parms, Getattr(tm, "code"), Getattr(tm, "locals"), Getattr(tm, "kwargs"), source_directive);
Delete(source_directive);
Delete(srcparms_str);
Delete(parms_str);
return 0;
}
ts--;
tm_methods = multi_tmap_method;
p = nextSibling(p);
}
Delete(tm_methods);
if (!p && tm) {
/* Got some kind of match */
String *parms_str = ParmList_str_multibrackets(parms);
String *srcparms_str = ParmList_str_multibrackets(srcparms);
String *source_directive = NewStringf("typemap(%s) %s = %s", tmap_method, parms_str, srcparms_str);
typemap_register(tmap_method, parms, Getattr(tm, "code"), Getattr(tm, "locals"), Getattr(tm, "kwargs"), source_directive);
Delete(source_directive);
Delete(srcparms_str);
Delete(parms_str);
return 0;
}
/* Not found */
return -1;
@ -411,7 +370,7 @@ void Swig_typemap_clear(const_String_or_char_ptr tmap_method, ParmList *parms) {
while (p) {
type = Getattr(p, "type");
name = Getattr(p, "name");
tm = typemap_get(type, name, tm_scope);
tm = typemap_get(type, name);
if (!tm)
return;
p = nextSibling(p);
@ -452,7 +411,6 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
String *ssig, *dsig;
Parm *p, *np, *lastp, *dp, *lastdp = 0;
int narg = 0;
int ts = tm_scope;
SwigType *type = 0, *name;
Hash *tm, *sm;
int match = 0;
@ -480,9 +438,9 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
/* make sure a typemap node exists for the last destination node */
type = Getattr(lastdp, "type");
tm = get_typemap(tm_scope, type);
tm = get_typemap(type);
if (!tm) {
set_typemap(tm_scope, type, &tm);
set_typemap(type, &tm);
}
name = Getattr(lastdp, "name");
if (name) {
@ -501,69 +459,65 @@ int Swig_typemap_apply(ParmList *src, ParmList *dest) {
type = Getattr(lastp, "type");
name = Getattr(lastp, "name");
while (ts >= 0) {
/* See if there is a matching typemap in this scope */
sm = typemap_get(type, name);
/* See if there is a matching typemap in this scope */
sm = typemap_get(type, name, ts);
/* if there is not matching, look for a typemap in the
original typedef, if any, like in:
/* if there is not matching, look for a typemap in the
original typedef, if any, like in:
typedef unsigned long size_t;
...
%apply(size_t) {my_size}; ==> %apply(unsigned long) {my_size};
*/
if (!sm) {
SwigType *ntype = SwigType_typedef_resolve(type);
if (ntype && (Cmp(ntype, type) != 0)) {
sm = typemap_get(ntype, name, ts);
}
Delete(ntype);
typedef unsigned long size_t;
...
%apply(size_t) {my_size}; ==> %apply(unsigned long) {my_size};
*/
if (!sm) {
SwigType *ntype = SwigType_typedef_resolve(type);
if (ntype && (Cmp(ntype, type) != 0)) {
sm = typemap_get(ntype, name);
}
Delete(ntype);
}
if (sm) {
/* Got a typemap. Need to only merge attributes for methods that match our signature */
Iterator ki;
match = 1;
for (ki = First(sm); ki.key; ki = Next(ki)) {
/* Check for a signature match with the source signature */
if ((count_args(ki.key) == narg) && (Strstr(ki.key, ssig))) {
String *oldm;
/* A typemap we have to copy */
String *nkey = Copy(ki.key);
Replace(nkey, ssig, dsig, DOH_REPLACE_ANY);
if (sm) {
/* Got a typemap. Need to only merge attributes for methods that match our signature */
Iterator ki;
match = 1;
for (ki = First(sm); ki.key; ki = Next(ki)) {
/* Check for a signature match with the source signature */
if ((count_args(ki.key) == narg) && (Strstr(ki.key, ssig))) {
String *oldm;
/* A typemap we have to copy */
String *nkey = Copy(ki.key);
Replace(nkey, ssig, dsig, DOH_REPLACE_ANY);
/* Make sure the typemap doesn't already exist in the target map */
/* Make sure the typemap doesn't already exist in the target map */
oldm = Getattr(tm, nkey);
if (!oldm || (!Getattr(tm, "code"))) {
String *code;
ParmList *locals;
ParmList *kwargs;
Hash *sm1 = ki.item;
oldm = Getattr(tm, nkey);
if (!oldm || (!Getattr(tm, "code"))) {
String *code;
ParmList *locals;
ParmList *kwargs;
Hash *sm1 = ki.item;
code = Getattr(sm1, "code");
locals = Getattr(sm1, "locals");
kwargs = Getattr(sm1, "kwargs");
if (code) {
String *src_str = ParmList_str_multibrackets(src);
String *dest_str = ParmList_str_multibrackets(dest);
String *source_directive = NewStringf("apply %s { %s }", src_str, dest_str);
code = Getattr(sm1, "code");
locals = Getattr(sm1, "locals");
kwargs = Getattr(sm1, "kwargs");
if (code) {
String *src_str = ParmList_str_multibrackets(src);
String *dest_str = ParmList_str_multibrackets(dest);
String *source_directive = NewStringf("apply %s { %s }", src_str, dest_str);
Replace(nkey, dsig, "", DOH_REPLACE_ANY);
Replace(nkey, "tmap:", "", DOH_REPLACE_ANY);
typemap_register(nkey, dest, code, locals, kwargs, source_directive);
Replace(nkey, dsig, "", DOH_REPLACE_ANY);
Replace(nkey, "tmap:", "", DOH_REPLACE_ANY);
typemap_register(nkey, dest, code, locals, kwargs, source_directive);
Delete(source_directive);
Delete(dest_str);
Delete(src_str);
}
Delete(source_directive);
Delete(dest_str);
Delete(src_str);
}
Delete(nkey);
}
Delete(nkey);
}
}
ts--;
}
Delete(ssig);
Delete(dsig);
@ -597,7 +551,7 @@ void Swig_typemap_clear_apply(Parm *parms) {
}
p = np;
}
tm = get_typemap(tm_scope, Getattr(lastp, "type"));
tm = get_typemap(Getattr(lastp, "type"));
if (!tm) {
Delete(tsig);
return;
@ -711,7 +665,6 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
SwigType *primitive = 0;
SwigType *ctype = 0;
SwigType *ctype_unstripped = 0;
int ts;
int isarray;
const String *cname = 0;
const String *cqualifiedname = 0;
@ -722,90 +675,86 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
cname = name;
if ((qualifiedname) && Len(qualifiedname))
cqualifiedname = qualifiedname;
ts = tm_scope;
if (debug_display) {
String *typestr = SwigType_str(type, cqualifiedname ? cqualifiedname : cname);
Swig_diagnostic(Getfile(node), Getline(node), "Searching for a suitable '%s' typemap for: %s\n", tmap_method, typestr);
Delete(typestr);
}
while (ts >= 0) {
ctype = Copy(type);
ctype_unstripped = Copy(ctype);
while (ctype) {
/* Try to get an exact type-match */
tm = get_typemap(ts, ctype);
result = typemap_search_helper(debug_display, tm, tm_method, ctype, cqualifiedname, cname, &backup);
if (result && Getattr(result, "code"))
goto ret_result;
ctype = Copy(type);
ctype_unstripped = Copy(ctype);
while (ctype) {
/* Try to get an exact type-match */
tm = get_typemap(ctype);
result = typemap_search_helper(debug_display, tm, tm_method, ctype, cqualifiedname, cname, &backup);
if (result && Getattr(result, "code"))
goto ret_result;
{
/* Look for the type reduced to just the template prefix - for templated types without the template parameter list being specified */
SwigType *template_prefix = SwigType_istemplate_only_templateprefix(ctype);
if (template_prefix) {
tm = get_typemap(ts, template_prefix);
result = typemap_search_helper(debug_display, tm, tm_method, template_prefix, cqualifiedname, cname, &backup);
Delete(template_prefix);
if (result && Getattr(result, "code"))
goto ret_result;
}
}
/* look for [ANY] arrays */
isarray = SwigType_isarray(ctype);
if (isarray) {
/* If working with arrays, strip away all of the dimensions and replace with "ANY".
See if that generates a match */
SwigType *noarrays = strip_arrays(ctype);
tm = get_typemap(ts, noarrays);
result = typemap_search_helper(debug_display, tm, tm_method, noarrays, cqualifiedname, cname, &backup);
Delete(noarrays);
{
/* Look for the type reduced to just the template prefix - for templated types without the template parameter list being specified */
SwigType *template_prefix = SwigType_istemplate_only_templateprefix(ctype);
if (template_prefix) {
tm = get_typemap(template_prefix);
result = typemap_search_helper(debug_display, tm, tm_method, template_prefix, cqualifiedname, cname, &backup);
Delete(template_prefix);
if (result && Getattr(result, "code"))
goto ret_result;
}
/* No match so far - try with a qualifier stripped (strip one qualifier at a time until none remain)
* The order of stripping in SwigType_strip_single_qualifier is used to provide some sort of consistency
* with the default (SWIGTYPE) typemap matching rules for the first qualifier to be stripped. */
{
SwigType *oldctype = ctype;
ctype = SwigType_strip_single_qualifier(oldctype);
if (!Equal(ctype, oldctype)) {
Delete(oldctype);
continue;
}
Delete(oldctype);
}
/* Once all qualifiers are stripped try resolve a typedef */
{
SwigType *oldctype = ctype;
ctype = SwigType_typedef_resolve(ctype_unstripped);
Delete(oldctype);
ctype_unstripped = Copy(ctype);
}
}
/* Hmmm. Well, no match seems to be found at all. See if there is some kind of default (SWIGTYPE) mapping */
primitive = SwigType_default_create(type);
while (primitive) {
tm = get_typemap(ts, primitive);
result = typemap_search_helper(debug_display, tm, tm_method, primitive, cqualifiedname, cname, &backup);
/* look for [ANY] arrays */
isarray = SwigType_isarray(ctype);
if (isarray) {
/* If working with arrays, strip away all of the dimensions and replace with "ANY".
See if that generates a match */
SwigType *noarrays = strip_arrays(ctype);
tm = get_typemap(noarrays);
result = typemap_search_helper(debug_display, tm, tm_method, noarrays, cqualifiedname, cname, &backup);
Delete(noarrays);
if (result && Getattr(result, "code"))
goto ret_result;
}
{
SwigType *nprim = SwigType_default_deduce(primitive);
Delete(primitive);
primitive = nprim;
/* No match so far - try with a qualifier stripped (strip one qualifier at a time until none remain)
* The order of stripping in SwigType_strip_single_qualifier is used to provide some sort of consistency
* with the default (SWIGTYPE) typemap matching rules for the first qualifier to be stripped. */
{
SwigType *oldctype = ctype;
ctype = SwigType_strip_single_qualifier(oldctype);
if (!Equal(ctype, oldctype)) {
Delete(oldctype);
continue;
}
Delete(oldctype);
}
if (ctype != type) {
Delete(ctype);
ctype = 0;
/* Once all qualifiers are stripped try resolve a typedef */
{
SwigType *oldctype = ctype;
ctype = SwigType_typedef_resolve(ctype_unstripped);
Delete(oldctype);
ctype_unstripped = Copy(ctype);
}
ts--; /* Hmmm. Nothing found in this scope. Guess we'll go try another scope */
}
/* Hmmm. Well, no match seems to be found at all. See if there is some kind of default (SWIGTYPE) mapping */
primitive = SwigType_default_create(type);
while (primitive) {
tm = get_typemap(primitive);
result = typemap_search_helper(debug_display, tm, tm_method, primitive, cqualifiedname, cname, &backup);
if (result && Getattr(result, "code"))
goto ret_result;
{
SwigType *nprim = SwigType_default_deduce(primitive);
Delete(primitive);
primitive = nprim;
}
}
if (ctype != type) {
Delete(ctype);
ctype = 0;
}
result = backup;
@ -1318,6 +1267,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
char *cmethod = Char(tmap_method);
int optimal_attribute = 0;
int optimal_substitution = 0;
int delete_optimal_attribute = 0;
int num_substitutions = 0;
SwigType *matchtype = 0;
@ -1372,7 +1322,6 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
Delete(typestr);
}
Delete(qpname);
qpname = 0;
Delete(noscope_pname);
@ -1391,23 +1340,16 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
s = Copy(s); /* Make a local copy of the typemap code */
/* Attach kwargs - ie the typemap attributes */
kw = Getattr(tm, "kwargs");
while (kw) {
String *value = Copy(Getattr(kw, "value"));
String *kwtype = Getattr(kw, "type");
char *ckwname = Char(Getattr(kw, "name"));
if (kwtype) {
String *mangle = Swig_string_mangle(kwtype);
Append(value, mangle);
Delete(mangle);
/* Look in the "out" typemap for the "optimal" attribute */
if (Cmp(cmethod, "out") == 0) {
kw = Getattr(tm, "kwargs");
while (kw) {
if (Cmp(Getattr(kw, "name"), "optimal") == 0) {
optimal_attribute = GetFlag(kw, "value");
break;
}
kw = nextSibling(kw);
}
sprintf(temp, "%s:%s", cmethod, ckwname);
Setattr(node, typemap_method_name(temp), value);
if (Cmp(temp, "out:optimal") == 0)
optimal_attribute = (Cmp(value, "0") != 0) ? 1 : 0;
Delete(value);
kw = nextSibling(kw);
}
if (optimal_attribute) {
@ -1438,14 +1380,15 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
}
}
if (!optimal_substitution) {
Swig_warning(WARN_TYPEMAP_OUT_OPTIMAL_IGNORED, Getfile(node), Getline(node), "Method %s usage of the optimal attribute ignored\n", Swig_name_decl(node));
Swig_warning(WARN_TYPEMAP_OUT_OPTIMAL_IGNORED, Getfile(s), Getline(s), "in the out typemap as the following cannot be used to generate optimal code: %s\n", clname);
Delattr(node, "tmap:out:optimal");
Swig_warning(WARN_TYPEMAP_OUT_OPTIMAL_IGNORED, Getfile(node), Getline(node), "Method %s usage of the optimal attribute ignored\n", Swig_name_decl(node));
Swig_warning(WARN_TYPEMAP_OUT_OPTIMAL_IGNORED, Getfile(s), Getline(s), "in the out typemap as the following cannot be used to generate optimal code: %s\n", clname);
delete_optimal_attribute = 1;
}
} else {
assert(!f);
}
}
if (actioncode) {
assert(f);
Append(f->code, actioncode);
@ -1486,6 +1429,41 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
Delete(parm_sublist);
}
/* Attach kwargs - ie the typemap attributes */
kw = Getattr(tm, "kwargs");
while (kw) {
String *value = Copy(Getattr(kw, "value"));
String *kwtype = Getattr(kw, "type");
char *ckwname = Char(Getattr(kw, "name"));
{
/* Expand special variables in typemap attributes. */
SwigType *ptype = Getattr(node, "type");
String *pname = Getattr(node, "name");
SwigType *mtype = Getattr(node, "tmap:match");
SwigType *matchtype = mtype ? mtype : ptype;
ParmList *parm_sublist;
typemap_replace_vars(value, NULL, matchtype, ptype, pname, (char *)lname, 1);
/* Expand special variable macros (embedded typemaps) in typemap attributes. */
parm_sublist = NewParmWithoutFileLineInfo(ptype, pname);
Setattr(parm_sublist, "lname", lname);
replace_embedded_typemap(value, parm_sublist, NULL, tm);
Delete(parm_sublist);
}
if (kwtype) {
String *mangle = Swig_string_mangle(kwtype);
Append(value, mangle);
Delete(mangle);
}
sprintf(temp, "%s:%s", cmethod, ckwname);
Setattr(node, typemap_method_name(temp), value);
Delete(value);
kw = nextSibling(kw);
}
if (delete_optimal_attribute)
Delattr(node, "tmap:out:optimal");
Replace(s, "$name", pname, DOH_REPLACE_ANY);
symname = Getattr(node, "sym:name");
@ -1558,17 +1536,44 @@ String *Swig_typemap_lookup(const_String_or_char_ptr tmap_method, Node *node, co
* If this hash (tm) contains a linked list of parameters under its "kwargs"
* attribute, add keys for each of those named keyword arguments to this
* parameter for later use.
* For example, attach the typemap attributes to p:
* For example, attach the typemap attributes to firstp (first parameter in parameter list):
* %typemap(in, foo="xyz") ...
* A new attribute called "tmap:in:foo" with value "xyz" is attached to p.
* A new attribute called "tmap:in:foo" with value "xyz" is attached to firstp.
* Also expands special variables and special variable macros in the typemap attributes.
* ----------------------------------------------------------------------------- */
static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method, Parm *p) {
static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method, Parm *firstp, int nmatch) {
String *temp = NewStringEmpty();
Parm *kw = Getattr(tm, "kwargs");
while (kw) {
String *value = Copy(Getattr(kw, "value"));
String *type = Getattr(kw, "type");
int i;
Parm *p = firstp;
/* Expand special variables */
for (i = 0; i < nmatch; i++) {
SwigType *type = Getattr(p, "type");
String *pname = Getattr(p, "name");
String *lname = Getattr(p, "lname");
SwigType *mtype = Getattr(p, "tmap:match");
SwigType *matchtype = mtype ? mtype : type;
typemap_replace_vars(value, NULL, matchtype, type, pname, lname, i + 1);
p = nextSibling(p);
}
/* Expand special variable macros (embedded typemaps).
* Special variable are expanded first above as they might be used in the special variable macros.
* For example: $typemap(imtype, $2_type). */
p = firstp;
for (i = 0; i < nmatch; i++) {
SwigType *type = Getattr(p, "type");
String *pname = Getattr(p, "name");
String *lname = Getattr(p, "lname");
ParmList *parm_sublist = NewParmWithoutFileLineInfo(type, pname);
Setattr(parm_sublist, "lname", lname);
replace_embedded_typemap(value, parm_sublist, NULL, tm);
p = nextSibling(p);
}
if (type) {
Hash *v = NewHash();
Setattr(v, "type", type);
@ -1578,13 +1583,13 @@ static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method
}
Clear(temp);
Printf(temp, "%s:%s", tmap_method, Getattr(kw, "name"));
Setattr(p, typemap_method_name(temp), value);
Setattr(firstp, typemap_method_name(temp), value);
Delete(value);
kw = nextSibling(kw);
}
Clear(temp);
Printf(temp, "%s:match_type", tmap_method);
Setattr(p, typemap_method_name(temp), Getattr(tm, "type"));
Setattr(firstp, typemap_method_name(temp), Getattr(tm, "type"));
Delete(temp);
}
@ -1779,7 +1784,7 @@ void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *p
Setattr(firstp, typemap_method_name(temp), p);
/* Attach kwargs */
typemap_attach_kwargs(tm, tmap_method, firstp);
typemap_attach_kwargs(tm, tmap_method, firstp, nmatch);
/* Replace the argument number */
sprintf(temp, "%d", argnum);
@ -2054,16 +2059,9 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper
* ----------------------------------------------------------------------------- */
void Swig_typemap_debug() {
int ts;
int nesting_level = 2;
Printf(stdout, "---[ typemaps ]--------------------------------------------------------------\n");
ts = tm_scope;
while (ts >= 0) {
Printf(stdout, "::: scope %d\n\n", ts);
Swig_print(typemaps[ts], nesting_level);
ts--;
}
Swig_print(typemaps, nesting_level);
Printf(stdout, "-----------------------------------------------------------------------------\n");
}