fixed out-of-scope nested class definitions, added a test
enabled nested C structs assignment (still disabled for Octave), added Java runtime test fixed nested_private test case for Java & C#
This commit is contained in:
parent
df67907168
commit
e1a4e11bea
6 changed files with 39 additions and 8 deletions
|
|
@ -84,7 +84,6 @@ CPP_TEST_BROKEN += \
|
||||||
extend_variable \
|
extend_variable \
|
||||||
li_std_vector_ptr \
|
li_std_vector_ptr \
|
||||||
li_boost_shared_ptr_template \
|
li_boost_shared_ptr_template \
|
||||||
nested_private \
|
|
||||||
overload_complicated \
|
overload_complicated \
|
||||||
template_default_pointer \
|
template_default_pointer \
|
||||||
template_expr \
|
template_expr \
|
||||||
|
|
@ -279,6 +278,8 @@ CPP_TEST_CASES += \
|
||||||
naturalvar_more \
|
naturalvar_more \
|
||||||
nested_class \
|
nested_class \
|
||||||
nested_comment \
|
nested_comment \
|
||||||
|
nested_private \
|
||||||
|
nested_scope \
|
||||||
nested_workaround \
|
nested_workaround \
|
||||||
newobject1 \
|
newobject1 \
|
||||||
null_pointer \
|
null_pointer \
|
||||||
|
|
|
||||||
|
|
@ -33,5 +33,12 @@ public class nested_structs_runme {
|
||||||
if (inside2.getVal() != 200) throw new RuntimeException("failed inside2");
|
if (inside2.getVal() != 200) throw new RuntimeException("failed inside2");
|
||||||
if (inside3.getVal() != 200) throw new RuntimeException("failed inside3");
|
if (inside3.getVal() != 200) throw new RuntimeException("failed inside3");
|
||||||
if (inside4.getVal() != 400) throw new RuntimeException("failed inside4");
|
if (inside4.getVal() != 400) throw new RuntimeException("failed inside4");
|
||||||
|
|
||||||
|
outer.getInner1().setVal(11);
|
||||||
|
if (inner1.getVal() != 11) throw new RuntimeException("failed inner1 assignment");
|
||||||
|
Named named = new Named();
|
||||||
|
named.setVal(22);
|
||||||
|
outer.setInside2(named);
|
||||||
|
if (outer.getInside2().getVal() != 22) throw new RuntimeException("failed inside2 assignment");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
Examples/test-suite/nested_scope.i
Normal file
14
Examples/test-suite/nested_scope.i
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
%module nested_scope
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
namespace ns {
|
||||||
|
struct Global {
|
||||||
|
struct Outer {
|
||||||
|
struct Nested;
|
||||||
|
};
|
||||||
|
struct Outer::Nested {
|
||||||
|
int data;
|
||||||
|
} instance;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
@ -3387,6 +3387,8 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
|
|
||||||
/* If the class name is qualified. We need to create or lookup namespace/scope entries */
|
/* If the class name is qualified. We need to create or lookup namespace/scope entries */
|
||||||
scope = resolve_create_node_scope($3);
|
scope = resolve_create_node_scope($3);
|
||||||
|
/* save nscope_inner to the class - it may be overwritten in nested classes*/
|
||||||
|
Setattr($<node>$, "nested:innerscope", nscope_inner);
|
||||||
Setfile(scope,cparse_file);
|
Setfile(scope,cparse_file);
|
||||||
Setline(scope,cparse_line);
|
Setline(scope,cparse_line);
|
||||||
$3 = scope;
|
$3 = scope;
|
||||||
|
|
@ -3462,6 +3464,10 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
(void) $<node>6;
|
(void) $<node>6;
|
||||||
$$ = currentOuterClass;
|
$$ = currentOuterClass;
|
||||||
currentOuterClass = Getattr($$, "nested:outer");
|
currentOuterClass = Getattr($$, "nested:outer");
|
||||||
|
nscope_inner = Getattr($<node>$, "nested:innerscope");
|
||||||
|
Delattr($<node>$, "nested:innerscope");
|
||||||
|
if (nscope_inner) /*actual parent class for this class*/
|
||||||
|
Setattr($$, "nested:outer", nscope_inner);
|
||||||
if (!currentOuterClass)
|
if (!currentOuterClass)
|
||||||
inclass = 0;
|
inclass = 0;
|
||||||
cscope = Getattr($$, "prev_symtab");
|
cscope = Getattr($$, "prev_symtab");
|
||||||
|
|
@ -3490,14 +3496,16 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
if (am) append_previous_extension($$,am);
|
if (am) append_previous_extension($$,am);
|
||||||
|
|
||||||
p = $9;
|
p = $9;
|
||||||
if (p) {
|
if (p && !nscope_inner) {
|
||||||
if (!cparse_cplusplus && currentOuterClass)
|
if (!cparse_cplusplus && currentOuterClass)
|
||||||
appendChild(currentOuterClass, p);
|
appendChild(currentOuterClass, p);
|
||||||
else
|
else
|
||||||
appendSibling($$, p);
|
appendSibling($$, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cparse_cplusplus && !cparse_externc) {
|
if (nscope_inner) {
|
||||||
|
ty = NewString(scpname); /* if the class is declared out of scope, let the declarator use fully qualified type*/
|
||||||
|
} else if (cparse_cplusplus && !cparse_externc) {
|
||||||
ty = NewString($3);
|
ty = NewString($3);
|
||||||
} else {
|
} else {
|
||||||
ty = NewStringf("%s %s", $2,$3);
|
ty = NewStringf("%s %s", $2,$3);
|
||||||
|
|
@ -3505,7 +3513,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
while (p) {
|
while (p) {
|
||||||
Setattr(p,"storage",$1);
|
Setattr(p,"storage",$1);
|
||||||
Setattr(p,"type",ty);
|
Setattr(p,"type",ty);
|
||||||
if (!cparse_cplusplus) {
|
if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) {
|
||||||
SetFlag(p,"hasconsttype");
|
SetFlag(p,"hasconsttype");
|
||||||
SetFlag(p,"feature:immutable");
|
SetFlag(p,"feature:immutable");
|
||||||
}
|
}
|
||||||
|
|
@ -3539,12 +3547,13 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
Delete(Namespaceprefix);
|
Delete(Namespaceprefix);
|
||||||
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||||
add_symbols($$);
|
add_symbols($$);
|
||||||
if (nscope) $$ = nscope;
|
|
||||||
/* but the variable definition in the current scope */
|
/* but the variable definition in the current scope */
|
||||||
Swig_symbol_setscope(cscope);
|
Swig_symbol_setscope(cscope);
|
||||||
Delete(Namespaceprefix);
|
Delete(Namespaceprefix);
|
||||||
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||||
add_symbols($9);
|
add_symbols($9);
|
||||||
|
nscope_inner = 0;
|
||||||
|
$$ = $9;
|
||||||
} else {
|
} else {
|
||||||
Delete(yyrename);
|
Delete(yyrename);
|
||||||
yyrename = 0;
|
yyrename = 0;
|
||||||
|
|
@ -3657,7 +3666,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
||||||
while (n) {
|
while (n) {
|
||||||
Setattr(n,"storage",$1);
|
Setattr(n,"storage",$1);
|
||||||
Setattr(n, "type", ty);
|
Setattr(n, "type", ty);
|
||||||
if (!cparse_cplusplus) {
|
if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) {
|
||||||
SetFlag(n,"hasconsttype");
|
SetFlag(n,"hasconsttype");
|
||||||
SetFlag(n,"feature:immutable");
|
SetFlag(n,"feature:immutable");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ public:
|
||||||
if (!proxyname) {
|
if (!proxyname) {
|
||||||
String *nspace = Getattr(n, "sym:nspace");
|
String *nspace = Getattr(n, "sym:nspace");
|
||||||
String *symname = Copy(Getattr(n, "sym:name"));
|
String *symname = Copy(Getattr(n, "sym:name"));
|
||||||
if (!GetFlag(n, "feature:flatnested")) {
|
if (symname && !GetFlag(n, "feature:flatnested")) {
|
||||||
for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) {
|
for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) {
|
||||||
Push(symname, ".");
|
Push(symname, ".");
|
||||||
Push(symname, Getattr(outer_class, "sym:name"));
|
Push(symname, Getattr(outer_class, "sym:name"));
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ public:
|
||||||
if (!proxyname || jnidescriptor) {
|
if (!proxyname || jnidescriptor) {
|
||||||
String *nspace = Getattr(n, "sym:nspace");
|
String *nspace = Getattr(n, "sym:nspace");
|
||||||
String *symname = Copy(Getattr(n, "sym:name"));
|
String *symname = Copy(Getattr(n, "sym:name"));
|
||||||
if (!GetFlag(n, "feature:flatnested")) {
|
if (symname && !GetFlag(n, "feature:flatnested")) {
|
||||||
for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) {
|
for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) {
|
||||||
Push(symname, ".");
|
Push(symname, ".");
|
||||||
Push(symname, Getattr(outer_class, "sym:name"));
|
Push(symname, Getattr(outer_class, "sym:name"));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue