Apply patch from Kalyanov Dmitry which fixes parsing of nested structs containing comments
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10981 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
cf527173cd
commit
4b79eb9219
5 changed files with 107 additions and 18 deletions
|
|
@ -1,6 +1,14 @@
|
||||||
Version 1.3.37 (in progress)
|
Version 1.3.37 (in progress)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
2008-12-12: wsfulton
|
||||||
|
Apply patch from Kalyanov Dmitry which fixes parsing of nested structs
|
||||||
|
containing comments.
|
||||||
|
|
||||||
|
2008-12-12: wsfulton
|
||||||
|
Fix error message in some nested struct and %inline parsing error situations
|
||||||
|
such as unterminated strings and comments.
|
||||||
|
|
||||||
2008-12-07: olly
|
2008-12-07: olly
|
||||||
[PHP] Fix warnings when compiling generated wrapper with GCC 4.3.
|
[PHP] Fix warnings when compiling generated wrapper with GCC 4.3.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ CPP_TEST_BROKEN += \
|
||||||
extend_variable \
|
extend_variable \
|
||||||
li_std_vector_ptr \
|
li_std_vector_ptr \
|
||||||
namespace_union \
|
namespace_union \
|
||||||
nested_comment \
|
nested_struct \
|
||||||
overload_complicated \
|
overload_complicated \
|
||||||
template_default_pointer \
|
template_default_pointer \
|
||||||
template_expr
|
template_expr
|
||||||
|
|
@ -235,6 +235,7 @@ CPP_TEST_CASES += \
|
||||||
namespace_typemap \
|
namespace_typemap \
|
||||||
namespace_virtual_method \
|
namespace_virtual_method \
|
||||||
naturalvar \
|
naturalvar \
|
||||||
|
nested_comment \
|
||||||
newobject1 \
|
newobject1 \
|
||||||
null_pointer \
|
null_pointer \
|
||||||
operator_overload \
|
operator_overload \
|
||||||
|
|
|
||||||
|
|
@ -18,24 +18,17 @@ in rlgc models */
|
||||||
char *name;
|
char *name;
|
||||||
} n ;
|
} n ;
|
||||||
} s2;
|
} s2;
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
// bug #491476
|
// comment in nested struct
|
||||||
%inline %{
|
%inline %{
|
||||||
struct {
|
struct a
|
||||||
struct {
|
{
|
||||||
int a;
|
struct {
|
||||||
} a, b;
|
/*struct*/
|
||||||
} a;
|
struct {
|
||||||
|
int b;
|
||||||
%}
|
} c;
|
||||||
|
} d;
|
||||||
// bug #909387
|
|
||||||
%inline %{
|
|
||||||
struct foo {
|
|
||||||
struct happy; // no warning
|
|
||||||
struct sad { int x; }; // warning
|
|
||||||
happy *good(); // produces good code
|
|
||||||
sad *bad(); // produces bad code
|
|
||||||
};
|
};
|
||||||
|
%}
|
||||||
|
|
|
||||||
22
Examples/test-suite/nested_structs.i
Normal file
22
Examples/test-suite/nested_structs.i
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
%module nested_structs
|
||||||
|
|
||||||
|
// bug #491476
|
||||||
|
%inline %{
|
||||||
|
struct {
|
||||||
|
struct {
|
||||||
|
int a;
|
||||||
|
} a, b;
|
||||||
|
} a;
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
// bug #909387
|
||||||
|
%inline %{
|
||||||
|
struct foo {
|
||||||
|
struct happy; // no warning
|
||||||
|
struct sad { int x; }; // warning
|
||||||
|
happy *good(); // produces good code
|
||||||
|
sad *bad(); // produces bad code
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
@ -1002,6 +1002,68 @@ static void add_nested(Nested *n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Strips C-style and C++-style comments from string in-place. */
|
||||||
|
static void strip_comments(char *string) {
|
||||||
|
int state = 0; /*
|
||||||
|
* 0 - not in comment
|
||||||
|
* 1 - in c-style comment
|
||||||
|
* 2 - in c++-style comment
|
||||||
|
* 3 - in string
|
||||||
|
* 4 - after reading / not in comments
|
||||||
|
* 5 - after reading * in c-style comments
|
||||||
|
* 6 - after reading \ in strings
|
||||||
|
*/
|
||||||
|
char * c = string;
|
||||||
|
while (*c) {
|
||||||
|
switch (state) {
|
||||||
|
case 0:
|
||||||
|
if (*c == '\"')
|
||||||
|
state = 3;
|
||||||
|
else if (*c == '/')
|
||||||
|
state = 4;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (*c == '*')
|
||||||
|
state = 5;
|
||||||
|
*c = ' ';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (*c == '\n')
|
||||||
|
state = 0;
|
||||||
|
else
|
||||||
|
*c = ' ';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (*c == '\"')
|
||||||
|
state = 0;
|
||||||
|
else if (*c == '\\')
|
||||||
|
state = 6;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if (*c == '/') {
|
||||||
|
*(c-1) = ' ';
|
||||||
|
*c = ' ';
|
||||||
|
state = 2;
|
||||||
|
} else if (*c == '*') {
|
||||||
|
*(c-1) = ' ';
|
||||||
|
*c = ' ';
|
||||||
|
state = 1;
|
||||||
|
} else
|
||||||
|
state = 0;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
if (*c == '/')
|
||||||
|
state = 0;
|
||||||
|
*c = ' ';
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
state = 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Dump all of the nested class declarations to the inline processor
|
/* Dump all of the nested class declarations to the inline processor
|
||||||
* However. We need to do a few name replacements and other munging
|
* However. We need to do a few name replacements and other munging
|
||||||
* first. This function must be called before closing a class! */
|
* first. This function must be called before closing a class! */
|
||||||
|
|
@ -1053,6 +1115,9 @@ static Node *dump_nested(const char *parent) {
|
||||||
ret = retx;
|
ret = retx;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Strip comments - further code may break in presence of comments. */
|
||||||
|
strip_comments(Char(n->code));
|
||||||
|
|
||||||
/* Make all SWIG created typedef structs/unions/classes unnamed else
|
/* Make all SWIG created typedef structs/unions/classes unnamed else
|
||||||
redefinition errors occur - nasty hack alert.*/
|
redefinition errors occur - nasty hack alert.*/
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue