From eec7f046ecd96f807e81481383e1e5521fd28011 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 17 Jan 2024 09:57:22 +0100 Subject: [PATCH 1/3] Add first test case for default_literal * tests/idl4/default/client.cpp: * tests/idl4/default/test.idl: --- tests/idl4/default/client.cpp | 8 ++++++++ tests/idl4/default/test.idl | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/idl4/default/client.cpp b/tests/idl4/default/client.cpp index c5ee6511..ac342b42 100644 --- a/tests/idl4/default/client.cpp +++ b/tests/idl4/default/client.cpp @@ -88,5 +88,13 @@ int main (int /*argc*/, char* /*argv*/[]) ++retval; } + Shape shape; + TAOX11_TEST_INFO << "shape: " << shape << std::endl; + if (shape.color_red() != Color::RED) + { + TAOX11_TEST_ERROR << "shape.color_red() not RED but: " << shape.color_red() << std::endl; + ++retval; + } + return retval; } diff --git a/tests/idl4/default/test.idl b/tests/idl4/default/test.idl index e15d0457..8360bc83 100644 --- a/tests/idl4/default/test.idl +++ b/tests/idl4/default/test.idl @@ -34,3 +34,13 @@ union TestUnion_Octet switch(short) { case 1: long SecondCase; }; + +enum Color { + GREEN, + @default_literal RED, + BLUE +}; + +struct Shape { + Color color_red; +}; From e3272d8ad713c3cd7100d96277b4e239750b1a50 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 17 Jan 2024 12:37:21 +0100 Subject: [PATCH 2/3] store test code * ridlbe/c++11/config/cxx_type.rb: * ridlbe/c++11/visitors/attribute.rb: * ridlbe/c++11/visitors/enum.rb: * ridlbe/c++11/visitors/struct.rb: * ridlbe/c++11/visitors/union.rb: --- ridlbe/c++11/config/cxx_type.rb | 18 ++++++++++++++++++ ridlbe/c++11/visitors/attribute.rb | 2 +- ridlbe/c++11/visitors/enum.rb | 20 +++++++++++++++++++- ridlbe/c++11/visitors/struct.rb | 2 +- ridlbe/c++11/visitors/union.rb | 2 +- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ridlbe/c++11/config/cxx_type.rb b/ridlbe/c++11/config/cxx_type.rb index a4c8163d..f7a5c6de 100644 --- a/ridlbe/c++11/config/cxx_type.rb +++ b/ridlbe/c++11/config/cxx_type.rb @@ -860,6 +860,24 @@ def value_to_s(v, scope = nil) def is_pod? true end + + def value_initializer + # When we have an annotation directly applied to this node we are using it + # unless node.annotations[:default].first.nil? + # "{#{node.annotations[:default].first.fields[:value]}}" + # else + # # Check whether it is a typedef, if so, we need to see if there is an annotation applied to the typedef (or its typedef) + # res_idl_type = _idltype + # while res_idl_type.is_a?(IDL::Type::ScopedName) + # unless res_idl_type.node.annotations[:default].first.nil? + # return "{#{res_idl_type.node.annotations[:default].first.fields[:value]}}" + # end + # res_idl_type = res_idl_type.node.idltype + # end + # _resolved_idltype.zero_initializer + # end + return "FOO" + end end class Bitmask diff --git a/ridlbe/c++11/visitors/attribute.rb b/ridlbe/c++11/visitors/attribute.rb index 4b1e700e..d953b905 100644 --- a/ridlbe/c++11/visitors/attribute.rb +++ b/ridlbe/c++11/visitors/attribute.rb @@ -133,7 +133,7 @@ def value_initializer end res_idl_type = res_idl_type.node.idltype end - _resolved_idltype.zero_initializer + _resolved_idltype.value_initializer end end diff --git a/ridlbe/c++11/visitors/enum.rb b/ridlbe/c++11/visitors/enum.rb index fe62fb5c..e734a557 100644 --- a/ridlbe/c++11/visitors/enum.rb +++ b/ridlbe/c++11/visitors/enum.rb @@ -24,8 +24,26 @@ def bitbound def bitbound_bits node.bitbound_bits end - # template mapping + def value_initializer + # # When we have an annotation directly applied to this node we are using it + # unless node.annotations[:default].first.nil? + # "{#{node.annotations[:default].first.fields[:value]}}" + # else + # # Check whether it is a typedef, if so, we need to see if there is an annotation applied to the typedef (or its typedef) + # res_idl_type = _idltype + # while res_idl_type.is_a?(IDL::Type::ScopedName) + # unless res_idl_type.node.annotations[:default].first.nil? + # return "{#{res_idl_type.node.annotations[:default].first.fields[:value]}}" + # end + # res_idl_type = res_idl_type.node.idltype + # end + # _resolved_idltype.zero_initializer + # end + return "FOO" + end + + # template mapping map_template :enum, :enum map_template :typecode, :typecode map_template :tao_typecode, :enum_typecode diff --git a/ridlbe/c++11/visitors/struct.rb b/ridlbe/c++11/visitors/struct.rb index 984bfdf5..202686df 100644 --- a/ridlbe/c++11/visitors/struct.rb +++ b/ridlbe/c++11/visitors/struct.rb @@ -70,7 +70,7 @@ def value_initializer end res_idl_type = res_idl_type.node.idltype end - _resolved_idltype.zero_initializer + _resolved_idltype.value_initializer end end diff --git a/ridlbe/c++11/visitors/union.rb b/ridlbe/c++11/visitors/union.rb index 7983a9d2..2c77b0f4 100644 --- a/ridlbe/c++11/visitors/union.rb +++ b/ridlbe/c++11/visitors/union.rb @@ -171,7 +171,7 @@ def value_initializer end res_idl_type = res_idl_type.node.idltype end - _resolved_idltype.zero_initializer + _resolved_idltype.value_initializer end end end From 04054c97aa01d438a43ecc5322b52fd8cdb66a3e Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 22 Jan 2024 11:38:06 +0100 Subject: [PATCH 3/3] Implement default_literal for enum * ridlbe/c++11/config/cxx_type.rb: * ridlbe/c++11/visitors/enum.rb: --- ridlbe/c++11/config/cxx_type.rb | 22 +++++++--------------- ridlbe/c++11/visitors/enum.rb | 18 ------------------ 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/ridlbe/c++11/config/cxx_type.rb b/ridlbe/c++11/config/cxx_type.rb index f7a5c6de..85e5df7b 100644 --- a/ridlbe/c++11/config/cxx_type.rb +++ b/ridlbe/c++11/config/cxx_type.rb @@ -862,21 +862,13 @@ def is_pod? end def value_initializer - # When we have an annotation directly applied to this node we are using it - # unless node.annotations[:default].first.nil? - # "{#{node.annotations[:default].first.fields[:value]}}" - # else - # # Check whether it is a typedef, if so, we need to see if there is an annotation applied to the typedef (or its typedef) - # res_idl_type = _idltype - # while res_idl_type.is_a?(IDL::Type::ScopedName) - # unless res_idl_type.node.annotations[:default].first.nil? - # return "{#{res_idl_type.node.annotations[:default].first.fields[:value]}}" - # end - # res_idl_type = res_idl_type.node.idltype - # end - # _resolved_idltype.zero_initializer - # end - return "FOO" + res = '{}' + node.enumerators.each do |e| + unless e.annotations[:default_literal].first.nil? + res = '{' + cxx_type + '::' + e.scoped_cxxname + '}' + end + end + return res end end diff --git a/ridlbe/c++11/visitors/enum.rb b/ridlbe/c++11/visitors/enum.rb index e734a557..3261ed17 100644 --- a/ridlbe/c++11/visitors/enum.rb +++ b/ridlbe/c++11/visitors/enum.rb @@ -25,24 +25,6 @@ def bitbound_bits node.bitbound_bits end - def value_initializer - # # When we have an annotation directly applied to this node we are using it - # unless node.annotations[:default].first.nil? - # "{#{node.annotations[:default].first.fields[:value]}}" - # else - # # Check whether it is a typedef, if so, we need to see if there is an annotation applied to the typedef (or its typedef) - # res_idl_type = _idltype - # while res_idl_type.is_a?(IDL::Type::ScopedName) - # unless res_idl_type.node.annotations[:default].first.nil? - # return "{#{res_idl_type.node.annotations[:default].first.fields[:value]}}" - # end - # res_idl_type = res_idl_type.node.idltype - # end - # _resolved_idltype.zero_initializer - # end - return "FOO" - end - # template mapping map_template :enum, :enum map_template :typecode, :typecode