diff --git a/ridlbe/c++11/templates/cli/hdr/struct_post.erb b/ridlbe/c++11/templates/cli/hdr/struct_post.erb index 7448bcc7..601fbd47 100644 --- a/ridlbe/c++11/templates/cli/hdr/struct_post.erb +++ b/ridlbe/c++11/templates/cli/hdr/struct_post.erb @@ -1,12 +1,18 @@ // generated from <%= ridl_template_path %> <%= cxxname %> () = default; ~<%= cxxname %> () = default; +% unless base.nil? + using <%= base.cxxname %>::<%= base.cxxname %>; +% end <%= cxxname %> (<%= cxx_in_type %>) = default; <%= cxxname %> (<%= cxx_move_type %>) = default; -% if member_count > 0 +% if member_count > 0 || !base.nil? % _ms = members.dup /// Constructor which accepts value for all members explicit inline <%= cxxname %> ( +% unless base.nil? + <%= base.cxxname %> _base<%= _ms.empty? ? ');' : ',' %> +% end % unless _ms.empty? % while !_ms.empty? % _m = _ms.shift diff --git a/ridlbe/c++11/templates/cli/hdr/struct_pre.erb b/ridlbe/c++11/templates/cli/hdr/struct_pre.erb index b76c25ce..c318d4f0 100644 --- a/ridlbe/c++11/templates/cli/hdr/struct_pre.erb +++ b/ridlbe/c++11/templates/cli/hdr/struct_pre.erb @@ -1,6 +1,6 @@ // generated from <%= ridl_template_path %> /// @copydoc <%= doc_scoped_name %> -class <%= stub_export_macro %><%= cxxname %> +class <%= stub_export_macro %><%= cxxname %><% unless base.nil? %> : public <%= base.cxxname %><% end %> { public: diff --git a/ridlbe/c++11/templates/cli/inl/struct_inl.erb b/ridlbe/c++11/templates/cli/inl/struct_inl.erb index b8989896..c2c5f6da 100644 --- a/ridlbe/c++11/templates/cli/inl/struct_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/struct_inl.erb @@ -4,9 +4,12 @@ %# Constructor inlines %# %# Initializer CTOR -% if member_count > 0 +% if member_count > 0 || !base.nil? % _ms = members.dup inline <%= scoped_cxxtype %>::<%= cxxname %> ( +% unless base.nil? + <%= base.cxxname %> _base<%= _ms.empty? ? ')' : ',' %> +% end % unless _ms.empty? % while !_ms.empty? % _m = _ms.shift @@ -18,6 +21,10 @@ inline <%= scoped_cxxtype %>::<%= cxxname %> ( % end % end % _pfx = nil +% unless base.nil? + : <%= base.cxxname %> (std::move(_base))<% unless _ms.empty? %>,<% end %> +% _pfx = ', ' unless _pfx +% end % members.each do |_m| <%= _pfx || ': ' %><%= _m.cxxname %>_ (std::move (<%= _m.cxxname %>)) % _pfx = ', ' unless _pfx @@ -28,6 +35,7 @@ inline <%= scoped_cxxtype %>::<%= cxxname %> ( % end inline void <%= scoped_cxxtype %>::swap (<%= scoped_cxx_out_type %><% if member_count > 0 %> s<% end %>) { +%# Add support for base % members.each do |_m| std::swap (this-><%= _m.cxxname %>_, s.<%= _m.cxxname %>_); % end diff --git a/ridlbe/c++11/visitors/struct.rb b/ridlbe/c++11/visitors/struct.rb index e5636e2f..5afb2993 100644 --- a/ridlbe/c++11/visitors/struct.rb +++ b/ridlbe/c++11/visitors/struct.rb @@ -29,6 +29,11 @@ def is_exception? false end + # Return the base of this struct, nil in case of no base struct + def base + node.base + end + # template mapping map_template :typecode, :typecode diff --git a/tests/idl4/illegal_idl/run_test.pl b/tests/idl4/illegal_idl/run_test.pl index 632277d1..e11ae914 100755 --- a/tests/idl4/illegal_idl/run_test.pl +++ b/tests/idl4/illegal_idl/run_test.pl @@ -38,7 +38,7 @@ open (STDERR, ">&STDOUT"); # Compile the IDL - system ("$ridl", "--idl-version 4 $input_file"); + system ("$ridl", "--idl-version=4", "$input_file"); #Redirect the null device output back to the screen open (STDOUT, ">&OLDOUT"); diff --git a/tests/idl4/illegal_idl/struct_circular_inheritance.idl b/tests/idl4/illegal_idl/struct_circular_inheritance.idl new file mode 100644 index 00000000..3985abd2 --- /dev/null +++ b/tests/idl4/illegal_idl/struct_circular_inheritance.idl @@ -0,0 +1,15 @@ +/** + * @file struct_circular_inheritance.idl + * @author Johnny Willemsen + * + * ridlc shall reject the use of circular inheritance + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ + +struct Foo; + +struct Foo : Foo +{ + long x; +}; diff --git a/tests/idl4/illegal_idl/struct_inherit_interface.idl b/tests/idl4/illegal_idl/struct_inherit_interface.idl new file mode 100644 index 00000000..0731afc8 --- /dev/null +++ b/tests/idl4/illegal_idl/struct_inherit_interface.idl @@ -0,0 +1,17 @@ +/** + * @file struct_inherit_interface.idl + * @author Johnny Willemsen + * + * ridlc shall reject the inheritance of a non struct type + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ + +interface Foo +{ +}; + +struct Bar : Foo +{ + long x; +}; diff --git a/tests/idl4/illegal_idl/struct_multiple_inheritance.idl b/tests/idl4/illegal_idl/struct_multiple_inheritance.idl new file mode 100644 index 00000000..52026fc1 --- /dev/null +++ b/tests/idl4/illegal_idl/struct_multiple_inheritance.idl @@ -0,0 +1,23 @@ +/** + * @file struct_multiple_inheritance.idl + * @author Johnny Willemsen + * + * ridlc shall reject the use of multiple inheritance + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ + +struct Base1 +{ + long a; +}; + +struct Base2 +{ + long b; +}; + +struct Foo : Base1, Base2 +{ + long x; +}; diff --git a/tests/idl4/struct_inheritance/test.idl b/tests/idl4/struct_inheritance/test.idl index e16bc9bb..72f9f0bd 100644 --- a/tests/idl4/struct_inheritance/test.idl +++ b/tests/idl4/struct_inheritance/test.idl @@ -16,6 +16,28 @@ struct Point3D : Point2D long z; }; +struct Point4D : Point3D +{ + long super; +}; + struct EmptyStruct { }; + +struct DeriveEmpty : EmptyStruct +{ +}; + +struct DeriveEmptyWithMember : EmptyStruct +{ + long x; +}; + +struct EmptyFromDerived : Point2D +{ +}; + +struct EmptyFromDerivedDerived : Point3D +{ +};