diff options
author | Vladimir Kalinin <vkalinin@opendesign.com> | 2013-12-04 01:53:42 +0400 |
---|---|---|
committer | Vladimir Kalinin <vkalinin@opendesign.com> | 2013-12-04 01:53:42 +0400 |
commit | e1a4e11beaaea4ebe9991ec47be8b559bf48e39f (patch) | |
tree | dcc6aea3b1c3262855cc27b00b6a2dbc58779f3e | |
parent | df679071681242ec2619c82693f261f1f1c34b80 (diff) | |
download | swig-e1a4e11beaaea4ebe9991ec47be8b559bf48e39f.tar.gz |
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#
-rw-r--r-- | Examples/test-suite/common.mk | 3 | ||||
-rw-r--r-- | Examples/test-suite/java/nested_structs_runme.java | 7 | ||||
-rw-r--r-- | Examples/test-suite/nested_scope.i | 14 | ||||
-rw-r--r-- | Source/CParse/parser.y | 19 | ||||
-rw-r--r-- | Source/Modules/csharp.cxx | 2 | ||||
-rw-r--r-- | Source/Modules/java.cxx | 2 |
6 files changed, 39 insertions, 8 deletions
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5c2aea787..e444f869d 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -84,7 +84,6 @@ CPP_TEST_BROKEN += \ extend_variable \ li_std_vector_ptr \ li_boost_shared_ptr_template \ - nested_private \ overload_complicated \ template_default_pointer \ template_expr \ @@ -279,6 +278,8 @@ CPP_TEST_CASES += \ naturalvar_more \ nested_class \ nested_comment \ + nested_private \ + nested_scope \ nested_workaround \ newobject1 \ null_pointer \ diff --git a/Examples/test-suite/java/nested_structs_runme.java b/Examples/test-suite/java/nested_structs_runme.java index 4b713395a..43c5e2897 100644 --- a/Examples/test-suite/java/nested_structs_runme.java +++ b/Examples/test-suite/java/nested_structs_runme.java @@ -33,5 +33,12 @@ public class nested_structs_runme { if (inside2.getVal() != 200) throw new RuntimeException("failed inside2"); if (inside3.getVal() != 200) throw new RuntimeException("failed inside3"); 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"); } } diff --git a/Examples/test-suite/nested_scope.i b/Examples/test-suite/nested_scope.i new file mode 100644 index 000000000..358dbbb61 --- /dev/null +++ b/Examples/test-suite/nested_scope.i @@ -0,0 +1,14 @@ +%module nested_scope + +%inline %{ +namespace ns { + struct Global { + struct Outer { + struct Nested; + }; + struct Outer::Nested { + int data; + } instance; + }; +} +%}
\ No newline at end of file diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index a97ac8fd5..7a3fc1a29 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -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 */ 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); Setline(scope,cparse_line); $3 = scope; @@ -3462,6 +3464,10 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { (void) $<node>6; $$ = currentOuterClass; 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) inclass = 0; cscope = Getattr($$, "prev_symtab"); @@ -3490,14 +3496,16 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { if (am) append_previous_extension($$,am); p = $9; - if (p) { + if (p && !nscope_inner) { if (!cparse_cplusplus && currentOuterClass) appendChild(currentOuterClass, p); else 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); } else { ty = NewStringf("%s %s", $2,$3); @@ -3505,7 +3513,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { while (p) { Setattr(p,"storage",$1); Setattr(p,"type",ty); - if (!cparse_cplusplus) { + if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) { SetFlag(p,"hasconsttype"); SetFlag(p,"feature:immutable"); } @@ -3539,12 +3547,13 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); add_symbols($$); - if (nscope) $$ = nscope; /* but the variable definition in the current scope */ Swig_symbol_setscope(cscope); Delete(Namespaceprefix); Namespaceprefix = Swig_symbol_qualifiedscopename(0); add_symbols($9); + nscope_inner = 0; + $$ = $9; } else { Delete(yyrename); yyrename = 0; @@ -3657,7 +3666,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE { while (n) { Setattr(n,"storage",$1); Setattr(n, "type", ty); - if (!cparse_cplusplus) { + if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) { SetFlag(n,"hasconsttype"); SetFlag(n,"feature:immutable"); } diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 7d3a0ac07..88dbfbad7 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -182,7 +182,7 @@ public: if (!proxyname) { String *nspace = Getattr(n, "sym:nspace"); 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")) { Push(symname, "."); Push(symname, Getattr(outer_class, "sym:name")); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 15199af9e..f781f0c39 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -209,7 +209,7 @@ public: if (!proxyname || jnidescriptor) { String *nspace = Getattr(n, "sym:nspace"); 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")) { Push(symname, "."); Push(symname, Getattr(outer_class, "sym:name")); |