Skip to content

Commit

Permalink
Merge pull request #347 from jwillemsen/jwi-defaultliteral
Browse files Browse the repository at this point in the history
Implement and test default_literal annotation for enum
  • Loading branch information
jwillemsen authored Jan 22, 2024
2 parents 84973e5 + 04054c9 commit 80bdd14
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
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 @@ int main (int /*argc*/, char* /*argv*/[])
++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;
}

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;
};

0 comments on commit 80bdd14

Please sign in to comment.