Skip to content

Commit

Permalink
Merge pull request #342 from jwillemsen/jwi-uniondefault
Browse files Browse the repository at this point in the history
Support and test for using @default for a union member
  • Loading branch information
jwillemsen authored Jan 16, 2024
2 parents 7b3f82e + fa1875f commit 00a2f88
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ridlbe/c++11/visitors/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ def is_array?
def has_multiple_discriminators?
labels.size > 1 || is_default?
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
8 changes: 8 additions & 0 deletions tests/idl4/default/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,13 @@ int main (int /*argc*/, char* /*argv*/[])
++retval;
}

TestUnion_Octet tuo;
if (tuo.FirstCase() != 5)
{
TAOX11_TEST_ERROR << "tuo.FirstCase() not 5 but: " << tuo.FirstCase() << std::endl;
++retval;
}


return retval;
}
7 changes: 7 additions & 0 deletions tests/idl4/default/test.idl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ exception foo
@default(9) typedef_short_type_8 typedef_short_9;
@default(5) unsigned short ushort_5;
};

union TestUnion_Octet switch(octet) {
case 1:
@default(5) short FirstCase;
case 2:
long SecondCase;
};

0 comments on commit 00a2f88

Please sign in to comment.