Fix wrapping of const array typedefs which were generating uncompileable code

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12616 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2011-04-08 07:02:31 +00:00
commit 93c1939370
3 changed files with 57 additions and 13 deletions

View file

@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.4 (in progress) Version 2.0.4 (in progress)
=========================== ===========================
2011-04-07: wsfulton
Fix wrapping of const array typedefs which were generating uncompileable code as
reported by Karl Wette.
2011-04-01: wsfulton 2011-04-01: wsfulton
Add in missing wrappers for friend functions for some target languages, mostly Add in missing wrappers for friend functions for some target languages, mostly
the non-scripting languages like Java and C#. the non-scripting languages like Java and C#.

View file

@ -1,12 +1,38 @@
%module array_typedef_memberin %module array_typedef_memberin
%inline %{ %inline %{
typedef short arr_short8[8]; typedef short Eight[8];
typedef const short ConstEight[8];
namespace ArrayExample namespace ArrayExample
{ {
class ExampleDetail class ExampleDetail
{ {
public: public:
arr_short8 node_list; Eight node_list;
const Eight node_list2;
ConstEight node_list3;
void fn1(Eight a) {}
void fn2(const Eight a) {}
void fn3(ConstEight a) {}
void fn4(Eight* a) {}
void fn5(ConstEight* a) {}
void fn6(const ConstEight* a) {}
void fn7(Eight*& a) {}
void fn8(ConstEight*& a) {}
void fn9(const ConstEight*& a) {}
}; };
} }
typedef int Four[4];
typedef const int ConstFour[4];
void test_1(int (*v)[4]) {}
void test_2(Four *v) {}
void test_3(const Four *v) {}
void test_4(ConstFour *v) {}
void test_5(const int (*v)[4]) {}
void test_3r(const Four *&v) {}
void test_4r(ConstFour *&v) {}
%} %}

View file

@ -513,7 +513,9 @@ String *SwigType_namestr(const SwigType *t) {
String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) { String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
String *result; String *result;
String *element = 0, *nextelement; String *element = 0;
String *nextelement;
String *forwardelement;
List *elements; List *elements;
int nelements, i; int nelements, i;
@ -536,8 +538,14 @@ String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
for (i = 0; i < nelements; i++) { for (i = 0; i < nelements; i++) {
if (i < (nelements - 1)) { if (i < (nelements - 1)) {
nextelement = Getitem(elements, i + 1); nextelement = Getitem(elements, i + 1);
forwardelement = nextelement;
if (SwigType_isqualifier(nextelement)) {
if (i < (nelements - 2))
forwardelement = Getitem(elements, i + 2);
}
} else { } else {
nextelement = 0; nextelement = 0;
forwardelement = 0;
} }
if (SwigType_isqualifier(element)) { if (SwigType_isqualifier(element)) {
DOH *q = 0; DOH *q = 0;
@ -547,7 +555,7 @@ String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
Delete(q); Delete(q);
} else if (SwigType_ispointer(element)) { } else if (SwigType_ispointer(element)) {
Insert(result, 0, "*"); Insert(result, 0, "*");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "("); Insert(result, 0, "(");
Append(result, ")"); Append(result, ")");
} }
@ -556,14 +564,14 @@ String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
q = SwigType_parm(element); q = SwigType_parm(element);
Insert(result, 0, "::*"); Insert(result, 0, "::*");
Insert(result, 0, q); Insert(result, 0, q);
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "("); Insert(result, 0, "(");
Append(result, ")"); Append(result, ")");
} }
Delete(q); Delete(q);
} else if (SwigType_isreference(element)) { } else if (SwigType_isreference(element)) {
Insert(result, 0, "&"); Insert(result, 0, "&");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "("); Insert(result, 0, "(");
Append(result, ")"); Append(result, ")");
} }
@ -728,7 +736,9 @@ String *SwigType_lstr(const SwigType *s, const_String_or_char_ptr id) {
String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) { String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
String *result, *cast; String *result, *cast;
String *element = 0, *nextelement; String *element = 0;
String *nextelement;
String *forwardelement;
SwigType *td, *tc = 0; SwigType *td, *tc = 0;
const SwigType *rs; const SwigType *rs;
List *elements; List *elements;
@ -773,8 +783,14 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
for (i = 0; i < nelements; i++) { for (i = 0; i < nelements; i++) {
if (i < (nelements - 1)) { if (i < (nelements - 1)) {
nextelement = Getitem(elements, i + 1); nextelement = Getitem(elements, i + 1);
forwardelement = nextelement;
if (SwigType_isqualifier(nextelement)) {
if (i < (nelements - 2))
forwardelement = Getitem(elements, i + 2);
}
} else { } else {
nextelement = 0; nextelement = 0;
forwardelement = 0;
} }
if (SwigType_isqualifier(element)) { if (SwigType_isqualifier(element)) {
DOH *q = 0; DOH *q = 0;
@ -785,7 +801,7 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
clear = 0; clear = 0;
} else if (SwigType_ispointer(element)) { } else if (SwigType_ispointer(element)) {
Insert(result, 0, "*"); Insert(result, 0, "*");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "("); Insert(result, 0, "(");
Append(result, ")"); Append(result, ")");
} }
@ -796,14 +812,14 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
q = SwigType_parm(element); q = SwigType_parm(element);
Insert(result, 0, q); Insert(result, 0, q);
Delete(q); Delete(q);
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "("); Insert(result, 0, "(");
Append(result, ")"); Append(result, ")");
} }
firstarray = 0; firstarray = 0;
} else if (SwigType_isreference(element)) { } else if (SwigType_isreference(element)) {
Insert(result, 0, "&"); Insert(result, 0, "&");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "("); Insert(result, 0, "(");
Append(result, ")"); Append(result, ")");
} }
@ -855,8 +871,6 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
if (name) { if (name) {
if (!isfunction) { if (!isfunction) {
if (isreference) { if (isreference) {
if (isarray)
Clear(cast);
Append(cast, "*"); Append(cast, "*");
} }
} }