From 04054c97aa01d438a43ecc5322b52fd8cdb66a3e Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 22 Jan 2024 11:38:06 +0100 Subject: [PATCH] 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