Skip to content

Commit

Permalink
Merge pull request #349 from jwillemsen/jwi-defaultliteralarray
Browse files Browse the repository at this point in the history
Implement and test default_literal on a enum which we use after that in an array
  • Loading branch information
jwillemsen authored Jan 23, 2024
2 parents ff5f14b + c776347 commit 582f46a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 18 deletions.
39 changes: 25 additions & 14 deletions ridlbe/c++11/config/cxx_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,13 @@ def os_fmt
'%s'
end

# Construct for triggering zero initialization
def zero_initializer
# Construct for value initialization
def value_initializer
'{}'
end

# Construct for value initialization
def value_initializer
zero_initializer
def default_value
nil
end

# define cxxtype methods for 'primitive' types
Expand Down Expand Up @@ -746,10 +745,6 @@ def cxx_member_type_name
is_reference? ? resolved_type.cxx_member_type_name : super
end

def zero_initializer
resolved_type.zero_initializer
end

def cxx_return_type(scope = nil)
is_reference? ? resolved_type.cxx_member_type(scope, self) : super
end
Expand Down Expand Up @@ -802,6 +797,14 @@ def cdr_to_fmt
def cdr_from_fmt
resolved_type.cdr_from_fmt
end

def value_initializer
resolved_type.value_initializer
end

def default_value
resolved_type.default_value
end
end

class Interface
Expand Down Expand Up @@ -862,13 +865,16 @@ def is_pod?
end

def value_initializer
res = '{}'
'{' + default_value.to_s + '}'
end

def default_value
node.enumerators.each do |e|
unless e.annotations[:default_literal].first.nil?
res = '{' + cxx_type + '::' + e.scoped_cxxname + '}'
return cxx_type + '::' + e.scoped_cxxname
end
end
return res
nil
end
end

Expand Down Expand Up @@ -1000,8 +1006,13 @@ def cxx_anyop_arg_typename(scope = nil)
resolved_cxx_type(scope)
end

def zero_initializer
'{}'
def value_initializer
df = basetype.default_value
if df == nil
return '{}'
else
'{' + (basetype.default_value + ', ') * sizes.first + '}'
end
end
end
end # Type
Expand Down
4 changes: 0 additions & 4 deletions ridlbe/c++11/visitorbase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,6 @@ def scoped_cxx_anyop_arg_typename
self._resolved_idltype.cxx_anyop_arg_typename
end

def zero_initializer
self._idltype.zero_initializer
end

def value_initializer
self._idltype.value_initializer
end
Expand Down
21 changes: 21 additions & 0 deletions tests/idl4/default/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ int main (int /*argc*/, char* /*argv*/[])
TAOX11_TEST_ERROR << "shape.color_red() not RED but: " << shape.color_red() << std::endl;
++retval;
}
for (const auto& arrayi : shape.color_red_array())
{
if (arrayi != Color::RED)
{
TAOX11_TEST_ERROR << "shape.color_red_array() not RED but: " << arrayi << std::endl;
++retval;
}
}
if (shape.color_no_default_literal() != ColorNoDefaultLiteral::BLACK)
{
TAOX11_TEST_ERROR << "shape.color_no_default_literal() not BLACK but: " << shape.color_no_default_literal() << std::endl;
++retval;
}
for (const auto& arrayi : shape.color_no_default_literal_array())
{
if (arrayi != ColorNoDefaultLiteral::BLACK)
{
TAOX11_TEST_ERROR << "shape.color_no_default_literal_array() not BLACK but: " << arrayi << std::endl;
++retval;
}
}

return retval;
}
12 changes: 12 additions & 0 deletions tests/idl4/default/test.idl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ enum Color {
BLUE
};

typedef Color ColorArray[5];

enum ColorNoDefaultLiteral {
BLACK,
WHITE,
YELLOW
};
typedef ColorNoDefaultLiteral ColorNoDefaultLiteralArray[5];

struct Shape {
Color color_red;
ColorArray color_red_array;
ColorNoDefaultLiteral color_no_default_literal;
ColorNoDefaultLiteralArray color_no_default_literal_array;
};

0 comments on commit 582f46a

Please sign in to comment.