aboutsummaryrefslogtreecommitdiff
path: root/Source/Swig/typesys.c
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Swig/typesys.c')
-rw-r--r--Source/Swig/typesys.c151
1 files changed, 77 insertions, 74 deletions
diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c
index 7564db1a6..dacc12540 100644
--- a/Source/Swig/typesys.c
+++ b/Source/Swig/typesys.c
@@ -4,7 +4,7 @@
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
- * and at http://www.swig.org/legal.html.
+ * and at https://www.swig.org/legal.html.
*
* typesys.c
*
@@ -180,7 +180,7 @@ int Swig_value_wrapper_mode(int mode) {
}
-static void flush_cache() {
+static void flush_cache(void) {
typedef_resolve_cache = 0;
typedef_all_cache = 0;
typedef_qualified_cache = 0;
@@ -188,7 +188,7 @@ static void flush_cache() {
/* Initialize the scoping system */
-void SwigType_typesystem_init() {
+void SwigType_typesystem_init(void) {
if (global_scope)
Delete(global_scope);
if (scopes)
@@ -407,7 +407,7 @@ void SwigType_using_scope(Typetab *scope) {
* table for the scope that was popped off.
* ----------------------------------------------------------------------------- */
-Typetab *SwigType_pop_scope() {
+Typetab *SwigType_pop_scope(void) {
Typetab *t, *old = current_scope;
t = Getattr(current_scope, "parent");
if (!t)
@@ -1148,6 +1148,7 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) {
Append(qprefix, "<(");
pi = First(parms);
while ((p = pi.item)) {
+ /* TODO: the logic here should be synchronised with that in symbol_template_qualify() in symbol.c */
String *qt = SwigType_typedef_qualified(p);
if (Equal(qt, p)) { /* && (!Swig_scopename_check(qt))) */
/* No change in value. It is entirely possible that the parameter is an integer value.
@@ -1419,7 +1420,8 @@ int SwigType_type(const SwigType *t) {
c++;
if (*c)
return SwigType_type(c + 1);
- return T_ERROR;
+ Printf(stderr, "*** Internal error: Invalid type string '%s'\n", t);
+ Exit(EXIT_FAILURE);
}
if (strncmp(c, "f(", 2) == 0)
return T_FUNCTION;
@@ -1453,11 +1455,11 @@ int SwigType_type(const SwigType *t) {
return T_DOUBLE;
if (strcmp(c, "long double") == 0)
return T_LONGDOUBLE;
- if (!cparse_cplusplus && (strcmp(c, "float complex") == 0))
+ if (!cparse_cplusplus && (strcmp(c, "float _Complex") == 0))
return T_FLTCPLX;
- if (!cparse_cplusplus && (strcmp(c, "double complex") == 0))
+ if (!cparse_cplusplus && (strcmp(c, "double _Complex") == 0))
return T_DBLCPLX;
- if (!cparse_cplusplus && (strcmp(c, "complex") == 0))
+ if (!cparse_cplusplus && (strcmp(c, "_Complex") == 0))
return T_COMPLEX;
if (strcmp(c, "void") == 0)
return T_VOID;
@@ -1491,11 +1493,11 @@ int SwigType_type(const SwigType *t) {
* Returns the alternative value type needed in C++ for class value
* types. When swig is not sure about using a plain $ltype value,
* since the class doesn't have a default constructor, or it can't be
- * assigned, you will get back 'SwigValueWrapper<type >'.
+ * assigned, you will get back 'SwigValueWrapper<(type)>'.
*
* This is the default behavior unless:
*
- * 1.- swig detects a default_constructor and 'setallocate:default_constructor'
+ * 1.- swig detects a default_constructor and 'allocate:default_constructor'
* attribute.
*
* 2.- swig doesn't mark 'type' as non-assignable.
@@ -1564,11 +1566,7 @@ SwigType *SwigType_alttype(const SwigType *t, int local_tmap) {
}
if (use_wrapper) {
- /* Need a space before the type in case it starts "::" (since the <:
- * token is a digraph for [ in C++. Also need a space after the
- * type in case it ends with ">" since then we form the token ">>".
- */
- w = NewStringf("SwigValueWrapper< %s >", td);
+ w = NewStringf("SwigValueWrapper<(%s)>", td);
}
Delete(td);
return w;
@@ -1700,14 +1698,6 @@ void SwigType_remember_clientdata(const SwigType *t, const_String_or_char_ptr cl
/*Printf(stdout,"t = '%s'\n", t);
Printf(stdout,"fr= '%s'\n\n", fr); */
- if (t) {
- char *ct = Char(t);
- if (strchr(ct, '<') && !(strstr(ct, "<("))) {
- Printf(stdout, "Bad template type passed to SwigType_remember: %s\n", t);
- assert(0);
- }
- }
-
h = Getattr(r_mangled, mt);
if (!h) {
h = NewHash();
@@ -1974,6 +1964,7 @@ void SwigType_inherit_equiv(File *out) {
Hash *sub;
Hash *rh;
List *rlist;
+ List *r_resolved_sorted_keys;
Iterator rk, bk, ck;
if (!conversions)
@@ -1981,10 +1972,12 @@ void SwigType_inherit_equiv(File *out) {
if (!subclass)
subclass = NewHash();
- rk = First(r_resolved);
- while (rk.key) {
+ r_resolved_sorted_keys = SortedKeys(r_resolved, Strcmp);
+ rk = First(r_resolved_sorted_keys);
+ while (rk.item) {
+ List *sub_sorted_keys;
/* rkey is a fully qualified type. We strip all of the type constructors off of it just to get the base */
- base = SwigType_base(rk.key);
+ base = SwigType_base(rk.item);
/* Check to see whether the base is recorded in the subclass table */
sub = Getattr(subclass, base);
Delete(base);
@@ -1995,28 +1988,29 @@ void SwigType_inherit_equiv(File *out) {
/* This type has subclasses. We now need to walk through these subtypes and generate pointer conversion functions */
- rh = Getattr(r_resolved, rk.key);
+ rh = Getattr(r_resolved, rk.item);
rlist = NewList();
for (ck = First(rh); ck.key; ck = Next(ck)) {
Append(rlist, ck.key);
}
- /* Printf(stdout,"rk.key = '%s'\n", rk.key);
+ /* Printf(stdout,"rk.item = '%s'\n", rk.item);
Printf(stdout,"rh = %p '%s'\n", rh,rh); */
- bk = First(sub);
- while (bk.key) {
- prefix = SwigType_prefix(rk.key);
- Append(prefix, bk.key);
+ sub_sorted_keys = SortedKeys(sub, Strcmp);
+ bk = First(sub_sorted_keys);
+ while (bk.item) {
+ prefix = SwigType_prefix(rk.item);
+ Append(prefix, bk.item);
/* Printf(stdout,"set %p = '%s' : '%s'\n", rh, SwigType_manglestr(prefix),prefix); */
mprefix = SwigType_manglestr(prefix);
Setattr(rh, mprefix, prefix);
- mkey = SwigType_manglestr(rk.key);
+ mkey = SwigType_manglestr(rk.item);
ckey = NewStringf("%s+%s", mprefix, mkey);
if (!Getattr(conversions, ckey)) {
String *convname = NewStringf("%sTo%s", mprefix, mkey);
- String *lkey = SwigType_lstr(rk.key, 0);
+ String *lkey = SwigType_lstr(rk.item, 0);
String *lprefix = SwigType_lstr(prefix, 0);
- Hash *subhash = Getattr(sub, bk.key);
+ Hash *subhash = Getattr(sub, bk.item);
String *convcode = Getattr(subhash, "convcode");
if (convcode) {
char *newmemoryused = Strstr(convcode, "newmemory"); /* see if newmemory parameter is used in order to avoid unused parameter warnings */
@@ -2077,29 +2071,13 @@ void SwigType_inherit_equiv(File *out) {
Delete(mkey);
bk = Next(bk);
}
+ Delete(sub_sorted_keys);
rk = Next(rk);
Delete(rlist);
}
+ Delete(r_resolved_sorted_keys);
}
-/* Helper function to sort the mangled list */
-static int SwigType_compare_mangled(const DOH *a, const DOH *b) {
- return strcmp((char *) Data(a), (char *) Data(b));
-}
-
-/* -----------------------------------------------------------------------------
- * SwigType_get_sorted_mangled_list()
- *
- * Returns the sorted list of mangled type names that should be exported into the
- * wrapper file.
- * ----------------------------------------------------------------------------- */
-List *SwigType_get_sorted_mangled_list() {
- List *l = Keys(r_mangled);
- SortList(l, SwigType_compare_mangled);
- return l;
-}
-
-
/* -----------------------------------------------------------------------------
* SwigType_type_table()
*
@@ -2126,22 +2104,22 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
/*#define DEBUG 1*/
#ifdef DEBUG
Printf(stdout, "---r_mangled---\n");
- Printf(stdout, "%s\n", r_mangled);
+ Swig_print(r_mangled, 2);
Printf(stdout, "---r_resolved---\n");
- Printf(stdout, "%s\n", r_resolved);
+ Swig_print(r_resolved, 2);
Printf(stdout, "---r_ltype---\n");
- Printf(stdout, "%s\n", r_ltype);
+ Swig_print(r_ltype, 2);
Printf(stdout, "---subclass---\n");
- Printf(stdout, "%s\n", subclass);
+ Swig_print(subclass, 2);
Printf(stdout, "---conversions---\n");
- Printf(stdout, "%s\n", conversions);
+ Swig_print(conversions, 2);
Printf(stdout, "---r_clientdata---\n");
- Printf(stdout, "%s\n", r_clientdata);
+ Swig_print(r_clientdata, 2);
#endif
table = NewStringEmpty();
@@ -2155,12 +2133,10 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
Printf(f_forward, "\n/* -------- TYPES TABLE (BEGIN) -------- */\n\n");
- mangled_list = SwigType_get_sorted_mangled_list();
+ mangled_list = SortedKeys(r_mangled, Strcmp);
for (ki = First(mangled_list); ki.item; ki = Next(ki)) {
List *el;
Iterator ei;
- SwigType *lt;
- SwigType *rt = 0;
String *nt;
String *ln;
String *rn;
@@ -2168,8 +2144,12 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
Hash *lthash;
Iterator ltiter;
Hash *nthash;
+ String *cast_temp_conv;
+ String *resolved_lstr = 0;
+ List *ntlist;
cast_temp = NewStringEmpty();
+ cast_temp_conv = NewStringEmpty();
Printv(types, "static swig_type_info _swigt_", ki.item, " = {", NIL);
Append(table_list, ki.item);
@@ -2185,8 +2165,8 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
nthash = NewHash();
ltiter = First(lthash);
while (ltiter.key) {
- lt = ltiter.key;
- rt = SwigType_typedef_resolve_all(lt);
+ SwigType *lt = ltiter.key;
+ SwigType *rt = SwigType_typedef_resolve_all(lt);
/* we save the original type and the fully resolved version */
ln = SwigType_lstr(lt, 0);
rn = SwigType_lstr(rt, 0);
@@ -2196,6 +2176,12 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
Setattr(nthash, rn, "1");
Setattr(nthash, ln, "1");
}
+ if (!resolved_lstr) {
+ resolved_lstr = Copy(rn);
+ } else if (Len(rn) < Len(resolved_lstr)) {
+ Delete(resolved_lstr);
+ resolved_lstr = Copy(rn);
+ }
if (SwigType_istemplate(rt)) {
String *dt = Swig_symbol_template_deftype(rt, 0);
String *dn = SwigType_lstr(dt, 0);
@@ -2205,33 +2191,50 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
Delete(dt);
Delete(dn);
}
+ Delete(rt);
+ Delete(rn);
+ Delete(ln);
ltiter = Next(ltiter);
}
/* now build nt */
- ltiter = First(nthash);
+ ntlist = SortedKeys(nthash, Strcmp);
+ ltiter = First(ntlist);
nt = 0;
- while (ltiter.key) {
- if (nt) {
- Printf(nt, "|%s", ltiter.key);
- } else {
- nt = NewString(ltiter.key);
+ while (ltiter.item) {
+ if (!Equal(resolved_lstr, ltiter.item)) {
+ if (nt) {
+ Printf(nt, "|%s", ltiter.item);
+ } else {
+ nt = NewString(ltiter.item);
+ }
}
ltiter = Next(ltiter);
}
+ /* Last in list is a resolved type used by SWIG_TypePrettyName.
+ * There can be more than one resolved type and the chosen one is simply the
+ * shortest in length, arguably the most user friendly/readable. */
+ if (nt) {
+ Printf(nt, "|%s", resolved_lstr);
+ } else {
+ nt = NewString(resolved_lstr);
+ }
+ Delete(ntlist);
Delete(nthash);
+ Delete(resolved_lstr);
Printf(types, "\"%s\", \"%s\", 0, 0, (void*)%s, 0};\n", ki.item, nt, cd);
el = SwigType_equivalent_mangle(ki.item, 0, 0);
+ SortList(el, Strcmp);
for (ei = First(el); ei.item; ei = Next(ei)) {
String *ckey;
String *conv;
ckey = NewStringf("%s+%s", ei.item, ki.item);
conv = Getattr(conversions, ckey);
if (conv) {
- Printf(cast_temp, " {&_swigt_%s, %s, 0, 0},", ei.item, conv);
+ Printf(cast_temp_conv, " {&_swigt_%s, %s, 0, 0},", ei.item, conv);
} else {
Printf(cast_temp, " {&_swigt_%s, 0, 0, 0},", ei.item);
}
@@ -2248,13 +2251,13 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
}
}
Delete(el);
- Printf(cast, "%s{0, 0, 0, 0}};\n", cast_temp);
+ Printf(cast, "%s%s{0, 0, 0, 0}};\n", cast_temp, cast_temp_conv);
+ Delete(cast_temp_conv);
Delete(cast_temp);
Delete(nt);
- Delete(rt);
}
/* print the tables in the proper order */
- SortList(table_list, SwigType_compare_mangled);
+ SortList(table_list, Strcmp);
i = 0;
for (ki = First(table_list); ki.item; ki = Next(ki)) {
Printf(f_forward, "#define SWIGTYPE%s swig_types[%d]\n", ki.item, i++);