diff --git a/bin/taox11_tests.lst b/bin/taox11_tests.lst index 44ec4592..36f296a3 100644 --- a/bin/taox11_tests.lst +++ b/bin/taox11_tests.lst @@ -78,6 +78,7 @@ tests/idl4/bitset/run_test.pl: tests/idl4/bitset/run_illegal_idl3_test.pl: tests/idl4/bitmask/run_test.pl: tests/idl4/bitmask/run_illegal_idl3_test.pl: +tests/idl4/default/run_test.pl: tests/idl4/enum/run_test.pl: tests/idl4/explicit_ints/run_test.pl: tests/idl4/explicit_ints/run_illegal_idl3_test.pl: diff --git a/ridlbe/c++11/visitors/struct.rb b/ridlbe/c++11/visitors/struct.rb index 5afb2993..4c44efca 100644 --- a/ridlbe/c++11/visitors/struct.rb +++ b/ridlbe/c++11/visitors/struct.rb @@ -56,6 +56,23 @@ def is_abstractbase? def is_array? _resolved_idltype.is_a?(IDL::Type::Array) 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 + end end end end diff --git a/tests/idl4/default/client.cpp b/tests/idl4/default/client.cpp index 473a3a4a..db907607 100644 --- a/tests/idl4/default/client.cpp +++ b/tests/idl4/default/client.cpp @@ -14,9 +14,10 @@ int main (int /*argc*/, char* /*argv*/[]) { int retval {}; bar mybar; + foo myfoo; - // Just compilation test TAOX11_TEST_INFO << "mybar: " << mybar << std::endl; + TAOX11_TEST_INFO << "myfoo: " << myfoo << std::endl; if (mybar.short_no_default() != 0) { @@ -43,6 +44,41 @@ int main (int /*argc*/, char* /*argv*/[]) TAOX11_TEST_ERROR << "mybar.typedef_short_9() not 9 but: " << mybar.typedef_short_9() << std::endl; ++retval; } + if (mybar.ushort_5() != 5) + { + TAOX11_TEST_ERROR << "mybar.ushort_5() not 5 but: " << mybar.ushort_5() << std::endl; + ++retval; + } + if (myfoo.short_no_default() != 0) + { + TAOX11_TEST_ERROR << "myfoo.short_no_default() not 0 but: " << myfoo.short_no_default() << std::endl; + ++retval; + } + if (myfoo.short_5() != 5) + { + TAOX11_TEST_ERROR << "myfoo.short_5() not 5 but: " << myfoo.short_5() << std::endl; + ++retval; + } + if (myfoo.short_8() != 8) + { + TAOX11_TEST_ERROR << "myfoo.short_8() not 8 but: " << myfoo.short_8() << std::endl; + ++retval; + } + if (myfoo.typedef_short_8() != 8) + { + TAOX11_TEST_ERROR << "myfoo.typedef_short_8() not 8 but: " << myfoo.typedef_short_8() << std::endl; + ++retval; + } + if (myfoo.typedef_short_9() != 9) + { + TAOX11_TEST_ERROR << "myfoo.typedef_short_9() not 9 but: " << myfoo.typedef_short_9() << std::endl; + ++retval; + } + if (myfoo.ushort_5() != 5) + { + TAOX11_TEST_ERROR << "myfoo.ushort_5() not 5 but: " << myfoo.ushort_5() << std::endl; + ++retval; + } return retval; } diff --git a/tests/idl4/default/test.idl b/tests/idl4/default/test.idl index 1fd86657..f64cbcbf 100644 --- a/tests/idl4/default/test.idl +++ b/tests/idl4/default/test.idl @@ -15,5 +15,15 @@ struct bar short_type_8 short_8; typedef_short_type_8 typedef_short_8; @default(9) typedef_short_type_8 typedef_short_9; + @default(5) unsigned short ushort_5; }; +exception foo +{ + short short_no_default; + @default(5) short short_5; + short_type_8 short_8; + typedef_short_type_8 typedef_short_8; + @default(9) typedef_short_type_8 typedef_short_9; + @default(5) unsigned short ushort_5; +};