Commit 6ecfe8a2 authored by Tom Niget's avatar Tom Niget

Add specific repr implementation for enums

parent 8e1f1ddf
......@@ -25,15 +25,22 @@ class ClassVisitor(NodeVisitor):
yield "py_type(const py_type&) = delete;"
yield "py_type(py_type&&) = delete;"
yield "void py_repr(std::ostream &s) const {"
yield "s << '{';"
for i, (name, memb) in enumerate(node.type.members.items()):
if i != 0:
yield 's << ", ";'
yield f's << "\\"{name}\\": ";'
yield f"repr_to({name}, s);"
yield "s << '}';"
yield "}"
if getattr(node.type, "is_enum", False):
yield "int value;"
yield "operator int() const { return value; }"
yield "void py_repr(std::ostream &s) const {"
yield f's << "{node.name}." << value;'
yield "}"
else:
yield "void py_repr(std::ostream &s) const {"
yield "s << '{';"
for i, (name, memb) in enumerate(node.type.members.items()):
if i != 0:
yield 's << ", ";'
yield f's << "\\"{name}\\": ";'
yield f"repr_to({name}, s);"
yield "s << '}';"
yield "}"
yield "void py_print(std::ostream &s) const {"
yield "py_repr(s);"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment