From 5ba2b985f23e715f368aeaee2059b035c234774b Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 2 Aug 2023 10:43:36 +0200 Subject: [PATCH 1/4] Extend support for struct inheritance, C++ inheritance and constructors are now generated, swap and other support methods not added yet * tests/idl4/illegal_idl/struct_circular_inheritance.idl: * tests/idl4/illegal_idl/struct_inherit_interface.idl: Added. * ridlbe/c++11/templates/cli/hdr/struct_post.erb: * ridlbe/c++11/templates/cli/hdr/struct_pre.erb: * ridlbe/c++11/templates/cli/inl/struct_inl.erb: * ridlbe/c++11/visitors/struct.rb: * tests/idl4/struct_inheritance/test.idl: --- .../c++11/templates/cli/hdr/struct_post.erb | 4 +++- ridlbe/c++11/templates/cli/hdr/struct_pre.erb | 2 +- ridlbe/c++11/templates/cli/inl/struct_inl.erb | 8 ++++++- ridlbe/c++11/visitors/struct.rb | 5 +++++ .../struct_circular_inheritance.idl | 15 +++++++++++++ .../illegal_idl/struct_inherit_interface.idl | 17 ++++++++++++++ tests/idl4/struct_inheritance/test.idl | 22 +++++++++++++++++++ 7 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/idl4/illegal_idl/struct_circular_inheritance.idl create mode 100644 tests/idl4/illegal_idl/struct_inherit_interface.idl diff --git a/ridlbe/c++11/templates/cli/hdr/struct_post.erb b/ridlbe/c++11/templates/cli/hdr/struct_post.erb index 7448bcc7..afea4173 100644 --- a/ridlbe/c++11/templates/cli/hdr/struct_post.erb +++ b/ridlbe/c++11/templates/cli/hdr/struct_post.erb @@ -1,12 +1,14 @@ // 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..6d29cfed 100644 --- a/ridlbe/c++11/templates/cli/inl/struct_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/struct_inl.erb @@ -4,9 +4,10 @@ %# 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 +19,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 +33,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/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..73f181bb --- /dev/null +++ b/tests/idl4/illegal_idl/struct_inherit_interface.idl @@ -0,0 +1,17 @@ +/** + * @file struct_circular_inheritance.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/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 +{ +}; From 3a2063a6f9050be756194d4c2bba029903c9dff7 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 2 Aug 2023 10:46:28 +0200 Subject: [PATCH 2/4] Small change to get rid of empty lines when no base is used * ridlbe/c++11/templates/cli/hdr/struct_post.erb: * ridlbe/c++11/templates/cli/inl/struct_inl.erb: --- ridlbe/c++11/templates/cli/hdr/struct_post.erb | 8 ++++++-- ridlbe/c++11/templates/cli/inl/struct_inl.erb | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ridlbe/c++11/templates/cli/hdr/struct_post.erb b/ridlbe/c++11/templates/cli/hdr/struct_post.erb index afea4173..601fbd47 100644 --- a/ridlbe/c++11/templates/cli/hdr/struct_post.erb +++ b/ridlbe/c++11/templates/cli/hdr/struct_post.erb @@ -1,14 +1,18 @@ // generated from <%= ridl_template_path %> <%= cxxname %> () = default; ~<%= cxxname %> () = default; - <% unless base.nil? %> using <%= base.cxxname %>::<%= base.cxxname %>;<% end %> +% unless base.nil? + using <%= base.cxxname %>::<%= base.cxxname %>; +% end <%= cxxname %> (<%= cxx_in_type %>) = default; <%= cxxname %> (<%= cxx_move_type %>) = default; % 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 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/inl/struct_inl.erb b/ridlbe/c++11/templates/cli/inl/struct_inl.erb index 6d29cfed..c2c5f6da 100644 --- a/ridlbe/c++11/templates/cli/inl/struct_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/struct_inl.erb @@ -7,7 +7,9 @@ % if member_count > 0 || !base.nil? % _ms = members.dup inline <%= scoped_cxxtype %>::<%= cxxname %> ( - <% unless base.nil? %><%= base.cxxname %> _base<%= _ms.empty? ? ')' : ',' %><% end %> +% unless base.nil? + <%= base.cxxname %> _base<%= _ms.empty? ? ')' : ',' %> +% end % unless _ms.empty? % while !_ms.empty? % _m = _ms.shift From 64d4b6f029787b55cd6da9d2d9357d52517cfe82 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 2 Aug 2023 12:33:21 +0200 Subject: [PATCH 3/4] Add test :: * tests/idl4/illegal_idl/struct_multiple_inheritance.idl: Added. * tests/idl4/illegal_idl/struct_inherit_interface.idl: --- .../illegal_idl/struct_inherit_interface.idl | 2 +- .../struct_multiple_inheritance.idl | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/idl4/illegal_idl/struct_multiple_inheritance.idl diff --git a/tests/idl4/illegal_idl/struct_inherit_interface.idl b/tests/idl4/illegal_idl/struct_inherit_interface.idl index 73f181bb..0731afc8 100644 --- a/tests/idl4/illegal_idl/struct_inherit_interface.idl +++ b/tests/idl4/illegal_idl/struct_inherit_interface.idl @@ -1,5 +1,5 @@ /** - * @file struct_circular_inheritance.idl + * @file struct_inherit_interface.idl * @author Johnny Willemsen * * ridlc shall reject the inheritance of a non struct type 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; +}; From 55fcfd82db13efba3e8cba8eaccc2116743a85bd Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 2 Aug 2023 12:45:05 +0200 Subject: [PATCH 4/4] Fixed script * tests/idl4/illegal_idl/run_test.pl: --- tests/idl4/illegal_idl/run_test.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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");