From 0907a03cfeef2664f816bcf609740bce40f05ed8 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 14 Aug 2023 17:30:36 +0200 Subject: [PATCH 1/3] Generate constructors and swap * ridlbe/c++11/templates/cli/inl/bitset_inl.erb: Added. * ridlbe/c++11/templates/cli/hdr/bitset.erb: * ridlbe/c++11/templates/cli/inl/struct_inl.erb: * ridlbe/c++11/writers/stubheader.rb: --- ridlbe/c++11/templates/cli/hdr/bitset.erb | 18 +++++++++ ridlbe/c++11/templates/cli/inl/bitset_inl.erb | 40 +++++++++++++++++++ ridlbe/c++11/templates/cli/inl/struct_inl.erb | 1 - ridlbe/c++11/writers/stubheader.rb | 4 ++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 ridlbe/c++11/templates/cli/inl/bitset_inl.erb diff --git a/ridlbe/c++11/templates/cli/hdr/bitset.erb b/ridlbe/c++11/templates/cli/hdr/bitset.erb index 8123b1f4..383ac480 100644 --- a/ridlbe/c++11/templates/cli/hdr/bitset.erb +++ b/ridlbe/c++11/templates/cli/hdr/bitset.erb @@ -11,6 +11,21 @@ public: <%= cxxname %> (<%= cxxname %>&&) = default; <%= cxxname %>& operator= (const <%= cxxname %>&) = default; <%= cxxname %>& operator= (<%= cxxname %>&&) = default; +%unless base.nil? + using <%= base.cxxname %>::<%= base.cxxname %>; +%end +%_ms = bitfields.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 + <%= "#{_m.cxx_byval_type} #{_m.cxxname}" %><%= _ms.empty? ? ');' : ',' %> +% end +%end %bitfields.each do |_m| % unless _m.cxxname.empty? @@ -19,6 +34,9 @@ public: % end %end + /// Exchange the value of two bitsets in an efficient matter + inline void swap (<%= cxx_inout_type %> s); + private: struct { diff --git a/ridlbe/c++11/templates/cli/inl/bitset_inl.erb b/ridlbe/c++11/templates/cli/inl/bitset_inl.erb new file mode 100644 index 00000000..e023530f --- /dev/null +++ b/ridlbe/c++11/templates/cli/inl/bitset_inl.erb @@ -0,0 +1,40 @@ + +// generated from <%= ridl_template_path %> +%# +%# Constructor inlines +%# +%# Initializer CTOR +% _ms = bitfields.dup +inline <%= scoped_cxxtype %>::<%= cxxname %> ( +% unless base.nil? + <%= base.cxxname %> _base<%= _ms.empty? ? ')' : ',' %> +% end +% unless _ms.empty? +% while !_ms.empty? +% _m = _ms.shift + <%= "#{_m.cxx_byval_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %> +% end +% end +% _pfx = nil +% unless base.nil? + : <%= base.cxxname %> (std::move(_base))<% unless _ms.empty? %>,<% end %> +% end + <% if base.nil? %>:<% else %>,<% end %> _taox11_<%= cxxname.downcase %> { +%# Change formatting +% bitfields.each do |_m| +% unless _m.cxxname.empty? + <%= _pfx %><%= _m.cxxname %> +% end +% _pfx = ', ' unless _pfx +% end +} +{ +} + +inline void <%= scoped_cxxtype %>::swap (<%= scoped_cxx_out_type %> s) +{ +%# Add support for base +%# bitfields.each do |_m| + std::swap (this->_taox11_<%= cxxname.downcase %>, s._taox11_<%= cxxname.downcase %>); +%# end +} diff --git a/ridlbe/c++11/templates/cli/inl/struct_inl.erb b/ridlbe/c++11/templates/cli/inl/struct_inl.erb index c2c5f6da..8eab1845 100644 --- a/ridlbe/c++11/templates/cli/inl/struct_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/struct_inl.erb @@ -4,7 +4,6 @@ %# Constructor inlines %# %# Initializer CTOR -% if member_count > 0 || !base.nil? % _ms = members.dup inline <%= scoped_cxxtype %>::<%= cxxname %> ( % unless base.nil? diff --git a/ridlbe/c++11/writers/stubheader.rb b/ridlbe/c++11/writers/stubheader.rb index 945e393e..6d89b1fb 100644 --- a/ridlbe/c++11/writers/stubheader.rb +++ b/ridlbe/c++11/writers/stubheader.rb @@ -714,6 +714,10 @@ def enter_struct(node) visitor(StructVisitor).visit_inl(node) end + def visit_bitset(node) + visitor(BitsetVisitor).visit_inl(node) + end + def enter_union(node) visitor(UnionVisitor).visit_inl(node) end From 79540d82546ee5798a8cba814004d28bd3f0c30b Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 14 Aug 2023 17:31:19 +0200 Subject: [PATCH 2/3] Revert change * ridlbe/c++11/templates/cli/inl/struct_inl.erb: --- ridlbe/c++11/templates/cli/inl/struct_inl.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/ridlbe/c++11/templates/cli/inl/struct_inl.erb b/ridlbe/c++11/templates/cli/inl/struct_inl.erb index 8eab1845..c2c5f6da 100644 --- a/ridlbe/c++11/templates/cli/inl/struct_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/struct_inl.erb @@ -4,6 +4,7 @@ %# Constructor inlines %# %# Initializer CTOR +% if member_count > 0 || !base.nil? % _ms = members.dup inline <%= scoped_cxxtype %>::<%= cxxname %> ( % unless base.nil? From 99dff6134de7a54260beef819644c6c332c7b26c Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 14 Aug 2023 19:54:45 +0200 Subject: [PATCH 3/3] Layout changes * ridlbe/c++11/templates/cli/hdr/bitset.erb: * ridlbe/c++11/templates/cli/inl/bitset_inl.erb: --- ridlbe/c++11/templates/cli/hdr/bitset.erb | 8 ++--- ridlbe/c++11/templates/cli/inl/bitset_inl.erb | 35 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/ridlbe/c++11/templates/cli/hdr/bitset.erb b/ridlbe/c++11/templates/cli/hdr/bitset.erb index 383ac480..78bfb691 100644 --- a/ridlbe/c++11/templates/cli/hdr/bitset.erb +++ b/ridlbe/c++11/templates/cli/hdr/bitset.erb @@ -14,7 +14,7 @@ public: %unless base.nil? using <%= base.cxxname %>::<%= base.cxxname %>; %end -%_ms = bitfields.dup +%_ms = bitfields.dup.find_all {|bitf| !bitf.cxxname.empty? } /// Constructor which accepts value for all members explicit inline <%= cxxname %> ( %unless base.nil? @@ -27,11 +27,9 @@ public: % end %end -%bitfields.each do |_m| -% unless _m.cxxname.empty? +%bitfields.find_all {|bitf| !bitf.cxxname.empty? }.each do |_m| inline void <%= _m.cxxname %> (<%= _m.cxx_in_type %> _x11_<%= _m.cxxname %>) { this->_taox11_<%= cxxname.downcase %>.<%= _m.cxxname %> = _x11_<%= _m.cxxname %>; } inline <%= _m.cxx_in_type %> <%= _m.cxxname %> () const { return this->_taox11_<%= cxxname.downcase %>.<%= _m.cxxname %>; } -% end %end /// Exchange the value of two bitsets in an efficient matter @@ -47,4 +45,6 @@ private: } _taox11_<%= cxxname.downcase %>; }; // <%= cxxname %> +inline void swap (<%= scoped_cxx_out_type %> m1, <%= scoped_cxx_out_type %> m2) { m1.swap (m2); } + % visit_template('typecode') if generate_typecode_support? diff --git a/ridlbe/c++11/templates/cli/inl/bitset_inl.erb b/ridlbe/c++11/templates/cli/inl/bitset_inl.erb index e023530f..1487377d 100644 --- a/ridlbe/c++11/templates/cli/inl/bitset_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/bitset_inl.erb @@ -4,30 +4,27 @@ %# Constructor inlines %# %# Initializer CTOR -% _ms = bitfields.dup +%_ms = bitfields.dup.find_all {|bitf| !bitf.cxxname.empty? } inline <%= scoped_cxxtype %>::<%= cxxname %> ( -% unless base.nil? +% unless base.nil? <%= base.cxxname %> _base<%= _ms.empty? ? ')' : ',' %> -% end -% unless _ms.empty? -% while !_ms.empty? -% _m = _ms.shift +% end +% unless _ms.empty? +% while !_ms.empty? +% _m = _ms.shift <%= "#{_m.cxx_byval_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %> -% end -% end -% _pfx = nil -% unless base.nil? +% end +% end +% _pfx = nil +% unless base.nil? : <%= base.cxxname %> (std::move(_base))<% unless _ms.empty? %>,<% end %> -% end - <% if base.nil? %>:<% else %>,<% end %> _taox11_<%= cxxname.downcase %> { -%# Change formatting -% bitfields.each do |_m| -% unless _m.cxxname.empty? - <%= _pfx %><%= _m.cxxname %> +% end +% str = "" +% bitfields.find_all {|bitf| !bitf.cxxname.empty? }.each do |_m| +% str = "#{str}#{_pfx}#{_m.cxxname}" +% _pfx = ', ' unless _pfx % end -% _pfx = ', ' unless _pfx -% end -} + <% if base.nil? %>:<% else %>,<% end %> _taox11_<%= cxxname.downcase %> { <%= str %> } { }