Skip to content

Commit

Permalink
Merge pull request #330 from jwillemsen/jwi-defaultannotation
Browse files Browse the repository at this point in the history
Add beta support for annotations on struct member declarations
  • Loading branch information
jwillemsen authored Oct 27, 2023
2 parents f8e5dcc + c7f3460 commit 1a5c5ff
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/taox11_tests.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions ridlbe/c++11/visitors/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 37 additions & 1 deletion tests/idl4/default/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
10 changes: 10 additions & 0 deletions tests/idl4/default/test.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 1a5c5ff

Please sign in to comment.