Commit 2be850ba authored by Tom Niget's avatar Tom Niget

Add generic JSON-like default __repr__ to user types

parent 14b4ddee
...@@ -24,6 +24,21 @@ class ClassVisitor(NodeVisitor): ...@@ -24,6 +24,21 @@ class ClassVisitor(NodeVisitor):
yield "type() {}" yield "type() {}"
yield "type(const type&) = delete;" yield "type(const type&) = delete;"
yield "type(type&&) = delete;" yield "type(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 "}"
yield "void py_print(std::ostream &s) const {"
yield "py_repr(s);"
yield "}"
yield "};" yield "};"
yield "template<typename... T> auto operator()(T&&... args) {" yield "template<typename... T> auto operator()(T&&... args) {"
......
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