Changed enum handling to try and fix C++ enum handling bugs.

Any enum type is now explicitly reduced to an 'int' by SwigType_lstr() and
SwigType_ltype().

Also made a few modifications to the handling of 'const' keywords which
reduces the amount of casting.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@856 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-09-19 03:42:03 +00:00
commit 8c1045407b

View file

@ -283,7 +283,7 @@ List *SwigType_split(SwigType *t) {
/* -----------------------------------------------------------------------------
* SwigType_pop()
*
* Pop off the first type-constructor object and update the type
* Pop off the first type-constructor object and updates the type
* ----------------------------------------------------------------------------- */
String *SwigType_pop(SwigType *t)
@ -462,6 +462,14 @@ int SwigType_isconst(SwigType *t) {
return 0;
}
int SwigType_isenum(SwigType *t) {
char *c = Char(t);
if (strncmp(c,"enum ",5) == 0) {
return 1;
}
return 0;
}
/* -----------------------------------------------------------------------------
* SwigType_base()
*
@ -727,19 +735,26 @@ SwigType_lstr(SwigType *s, const String_or_char *id)
List *elements;
int nelements, i;
int firstarray = 1;
SwigType *td;
SwigType *td, *rs, *tc = 0;
if (id) {
result = NewString(Char(id));
} else {
result = NewString("");
}
td = SwigType_typedef_resolve(s);
if (SwigType_isconst(s)) {
tc = Copy(s);
Delete(SwigType_pop(tc));
rs = tc;
} else {
rs = s;
}
td = SwigType_typedef_resolve(rs);
if ((td) && (SwigType_isconst(td) || SwigType_isarray(td))) {
elements = SwigType_split(td);
} else if (td && SwigType_isenum(td)) {
elements = SwigType_split("int");
} else {
elements = SwigType_split(s);
elements = SwigType_split(rs);
}
if (td) Delete(td);
nelements = Len(elements);
@ -804,6 +819,7 @@ SwigType_lstr(SwigType *s, const String_or_char *id)
element = nextelement;
}
Delete(elements);
if (tc) Delete(tc);
return Swig_temp_result(result);
}
@ -818,17 +834,28 @@ SwigType *
SwigType_ltype(SwigType *s) {
String *result;
String *element, *nextelement;
SwigType *td;
SwigType *td, *rs, *tc = 0;
List *elements;
int nelements, i;
int firstarray = 1;
result = NewString("");
td = SwigType_typedef_resolve(s);
if (SwigType_isconst(s)) {
tc = Copy(s);
Delete(SwigType_pop(tc));
rs = tc;
} else {
rs = s;
}
td = SwigType_typedef_resolve(rs);
if ((td) && (SwigType_isconst(td) || SwigType_isarray(td))) {
elements = SwigType_split(td);
} else if (td && SwigType_isenum(td)) {
elements = SwigType_split("int");
} else {
elements = SwigType_split(s);
elements = SwigType_split(rs);
}
if (td) Delete(td);
nelements = Len(elements);
@ -861,6 +888,7 @@ SwigType_ltype(SwigType *s) {
element = nextelement;
}
Delete(elements);
if (tc) Delete(tc);
return result;
}
@ -874,18 +902,30 @@ SwigType_ltype(SwigType *s) {
String *SwigType_rcaststr(SwigType *s, const String_or_char *name) {
String *result, *cast;
String *element = 0, *nextelement;
SwigType *td;
SwigType *td, *rs, *tc = 0;
List *elements;
int nelements, i;
int clear = 1;
int firstarray = 1;
result = NewString("");
td = SwigType_typedef_resolve(s);
if ((td) && (SwigType_isconst(td) || SwigType_isarray(td))) {
elements = SwigType_split(td);
if (SwigType_isconst(s)) {
tc = Copy(s);
Delete(SwigType_pop(tc));
rs = tc;
} else {
elements = SwigType_split(s);
rs = s;
}
td = SwigType_typedef_resolve(rs);
if ((td) && (SwigType_isconst(td) || SwigType_isarray(td))) {
elements = SwigType_split(td);
} else if (td && SwigType_isenum(td)) {
elements = SwigType_split(rs);
clear = 0;
} else {
elements = SwigType_split(rs);
}
if (td) Delete(td);
nelements = Len(elements);
@ -961,6 +1001,7 @@ String *SwigType_rcaststr(SwigType *s, const String_or_char *name) {
Append(cast,name);
}
Delete(result);
Delete(tc);
return Swig_temp_result(cast);
}