Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement and test default_literal annotation for enum #347

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ridlbe/c++11/config/cxx_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,16 @@ def value_to_s(v, scope = nil)
def is_pod?
true
end

def value_initializer
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

class Bitmask
Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/visitors/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def value_initializer
end
res_idl_type = res_idl_type.node.idltype
end
_resolved_idltype.zero_initializer
_resolved_idltype.value_initializer
end
end

Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/visitors/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def bitbound
def bitbound_bits
node.bitbound_bits
end
# template mapping

# template mapping
map_template :enum, :enum
map_template :typecode, :typecode
map_template :tao_typecode, :enum_typecode
Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/visitors/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def value_initializer
end
res_idl_type = res_idl_type.node.idltype
end
_resolved_idltype.zero_initializer
_resolved_idltype.value_initializer
end
end

Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/visitors/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def value_initializer
end
res_idl_type = res_idl_type.node.idltype
end
_resolved_idltype.zero_initializer
_resolved_idltype.value_initializer
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions tests/idl4/default/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,13 @@
++retval;
}

Shape shape;
TAOX11_TEST_INFO << "shape: " << shape << std::endl;
if (shape.color_red() != Color::RED)
{
TAOX11_TEST_ERROR << "shape.color_red() not RED but: " << shape.color_red() << std::endl;
++retval;

Check warning on line 96 in tests/idl4/default/client.cpp

View check run for this annotation

Codecov / codecov/patch

tests/idl4/default/client.cpp#L95-L96

Added lines #L95 - L96 were not covered by tests
}

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 @@ -34,3 +34,13 @@ union TestUnion_Octet switch(short) {
case 1:
long SecondCase;
};

enum Color {
GREEN,
@default_literal RED,
BLUE
};

struct Shape {
Color color_red;
};
Loading