diff --git a/CHANGES.current b/CHANGES.current index fc9e40ab5..e2dc8ba81 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,14 @@ 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 [PHP] Fix warnings when compiling generated wrapper with GCC 4.3. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 3848601bc..144e67639 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -79,7 +79,7 @@ CPP_TEST_BROKEN += \ extend_variable \ li_std_vector_ptr \ namespace_union \ - nested_comment \ + nested_struct \ overload_complicated \ template_default_pointer \ template_expr @@ -235,6 +235,7 @@ CPP_TEST_CASES += \ namespace_typemap \ namespace_virtual_method \ naturalvar \ + nested_comment \ newobject1 \ null_pointer \ operator_overload \ diff --git a/Examples/test-suite/nested_comment.i b/Examples/test-suite/nested_comment.i index 16f1b7af2..ea365a6fe 100644 --- a/Examples/test-suite/nested_comment.i +++ b/Examples/test-suite/nested_comment.i @@ -18,24 +18,17 @@ in rlgc models */ char *name; } n ; } s2; - %} -// bug #491476 +// comment in nested struct %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 +struct a +{ + struct { + /*struct*/ + struct { + int b; + } c; + } d; }; +%} diff --git a/Examples/test-suite/nested_structs.i b/Examples/test-suite/nested_structs.i new file mode 100644 index 000000000..4b13ff69d --- /dev/null +++ b/Examples/test-suite/nested_structs.i @@ -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 +}; +%} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index ccdac79d1..8ee56a246 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -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 * However. We need to do a few name replacements and other munging * first. This function must be called before closing a class! */ @@ -1053,6 +1115,9 @@ static Node *dump_nested(const char *parent) { 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 redefinition errors occur - nasty hack alert.*/