Fix parsing of struct declaration and initialization
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11750 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
0286f6d43e
commit
7fd36f5bd6
6 changed files with 70 additions and 5 deletions
|
|
@ -1,6 +1,13 @@
|
||||||
Version 1.3.41 (in progress)
|
Version 1.3.41 (in progress)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
2009-11-17: wsfulton
|
||||||
|
Fix parsing of struct declaration and initialization, for example:
|
||||||
|
|
||||||
|
struct S {
|
||||||
|
int x;
|
||||||
|
} instance = { 10 };
|
||||||
|
|
||||||
2009-11-15: wsfulton
|
2009-11-15: wsfulton
|
||||||
Fix #1960977 - Syntax error parsing derived nested class declaration and member
|
Fix #1960977 - Syntax error parsing derived nested class declaration and member
|
||||||
variable instance.
|
variable instance.
|
||||||
|
|
|
||||||
|
|
@ -303,6 +303,7 @@ CPP_TEST_CASES += \
|
||||||
static_array_member \
|
static_array_member \
|
||||||
static_const_member \
|
static_const_member \
|
||||||
static_const_member_2 \
|
static_const_member_2 \
|
||||||
|
struct_initialization_cpp \
|
||||||
struct_value \
|
struct_value \
|
||||||
template \
|
template \
|
||||||
template_arg_replace \
|
template_arg_replace \
|
||||||
|
|
@ -470,6 +471,7 @@ C_TEST_CASES += \
|
||||||
sizeof_pointer \
|
sizeof_pointer \
|
||||||
sneaky1 \
|
sneaky1 \
|
||||||
struct_rename \
|
struct_rename \
|
||||||
|
struct_initialization \
|
||||||
typedef_struct \
|
typedef_struct \
|
||||||
typemap_subst \
|
typemap_subst \
|
||||||
union_parameter \
|
union_parameter \
|
||||||
|
|
|
||||||
20
Examples/test-suite/python/struct_initialization_runme.py
Normal file
20
Examples/test-suite/python/struct_initialization_runme.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
from struct_initialization import *
|
||||||
|
|
||||||
|
if cvar.instanceC1.x != 10:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if cvar.instanceD1.x != 10:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if cvar.instanceD2.x != 20:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if cvar.instanceD3.x != 30:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if cvar.instanceE1.x != 1:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if cvar.instanceF1.x != 1:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
31
Examples/test-suite/struct_initialization.i
Normal file
31
Examples/test-suite/struct_initialization.i
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Test declaration and initialization of structs (C code)
|
||||||
|
%module struct_initialization
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
// Named types
|
||||||
|
struct StructA {
|
||||||
|
int x;
|
||||||
|
} instanceA1;
|
||||||
|
|
||||||
|
struct StructB {
|
||||||
|
int x;
|
||||||
|
} instanceB1, instanceB2, instanceB3;
|
||||||
|
|
||||||
|
struct StructC {
|
||||||
|
int x;
|
||||||
|
} instanceC1 = { 10 };
|
||||||
|
|
||||||
|
struct StructD {
|
||||||
|
int x;
|
||||||
|
} instanceD1 = { 10 }, instanceD2 = { 20 }, instanceD3 = { 30 };
|
||||||
|
|
||||||
|
struct StructE {
|
||||||
|
int x;
|
||||||
|
} instanceE1[3] = { { 1 }, { 2 }, { 3} };
|
||||||
|
|
||||||
|
struct StructF {
|
||||||
|
int x;
|
||||||
|
} instanceF1[3] = { { 1 }, { 2 } }, instanceF2[2] = { { -1 }, { -2 } }, instanceF3[2] = { { 11 }, { 22 } };
|
||||||
|
|
||||||
|
%}
|
||||||
5
Examples/test-suite/struct_initialization_cpp.i
Normal file
5
Examples/test-suite/struct_initialization_cpp.i
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
// Test declaration and initialization of structs (C++ code)
|
||||||
|
%module struct_initialization_cpp
|
||||||
|
|
||||||
|
%include "struct_initialization.i" // C code
|
||||||
|
|
||||||
|
|
@ -3546,7 +3546,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
Classprefix = NewStringEmpty();
|
Classprefix = NewStringEmpty();
|
||||||
Delete(Namespaceprefix);
|
Delete(Namespaceprefix);
|
||||||
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||||
} cpp_members RBRACE declarator c_decl_tail {
|
} cpp_members RBRACE declarator initializer c_decl_tail {
|
||||||
String *unnamed;
|
String *unnamed;
|
||||||
Node *n;
|
Node *n;
|
||||||
Classprefix = 0;
|
Classprefix = 0;
|
||||||
|
|
@ -3564,8 +3564,8 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
Setattr(n,"decl",$7.type);
|
Setattr(n,"decl",$7.type);
|
||||||
Setattr(n,"parms",$7.parms);
|
Setattr(n,"parms",$7.parms);
|
||||||
Setattr(n,"storage",$1);
|
Setattr(n,"storage",$1);
|
||||||
if ($8) {
|
if ($9) {
|
||||||
Node *p = $8;
|
Node *p = $9;
|
||||||
set_nextSibling(n,p);
|
set_nextSibling(n,p);
|
||||||
while (p) {
|
while (p) {
|
||||||
String *type = Copy(unnamed);
|
String *type = Copy(unnamed);
|
||||||
|
|
@ -3635,12 +3635,12 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
;
|
;
|
||||||
|
|
||||||
cpp_opt_declarators : SEMI { $$ = 0; }
|
cpp_opt_declarators : SEMI { $$ = 0; }
|
||||||
| declarator c_decl_tail {
|
| declarator initializer c_decl_tail {
|
||||||
$$ = new_node("cdecl");
|
$$ = new_node("cdecl");
|
||||||
Setattr($$,"name",$1.id);
|
Setattr($$,"name",$1.id);
|
||||||
Setattr($$,"decl",$1.type);
|
Setattr($$,"decl",$1.type);
|
||||||
Setattr($$,"parms",$1.parms);
|
Setattr($$,"parms",$1.parms);
|
||||||
set_nextSibling($$,$2);
|
set_nextSibling($$,$3);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue