summaryrefslogtreecommitdiff
path: root/src/ast/expr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast/expr.cpp')
-rw-r--r--src/ast/expr.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/ast/expr.cpp b/src/ast/expr.cpp
index 7d6983f6..8c239092 100644
--- a/src/ast/expr.cpp
+++ b/src/ast/expr.cpp
@@ -69,6 +69,7 @@ SERIALISE_TYPE(Expr::, "Expr", {
else _(ExprNode_Cast)
else _(ExprNode_CallPath)
else _(ExprNode_BinOp)
+ else _(ExprNode_UniOp)
else
throw ::std::runtime_error("Unknown node type " + tag);
#undef _
@@ -278,6 +279,44 @@ NODE(ExprNode_BinOp, {
os << " " << *m_right << ")";
})
+void operator%(::Serialiser& s, const ExprNode_UniOp::Type t) {
+ switch(t)
+ {
+ #define _(v) case ExprNode_UniOp::v: s << #v; return;
+ _(NEGATE)
+ _(INVERT)
+ _(BOX)
+ _(REF)
+ #undef _
+ }
+}
+void operator%(::Deserialiser& s, enum ExprNode_UniOp::Type& t) {
+ ::std::string n;
+ s.item(n);
+ if(1) ;
+ #define _(v) else if(n == #v) t = ExprNode_UniOp::v;
+ _(NEGATE)
+ _(INVERT)
+ _(BOX)
+ _(REF)
+ else
+ throw ::std::runtime_error( FMT("No uniop type for '" << n << "'") );
+ #undef _
+}
+NODE(ExprNode_UniOp, {
+ s % m_type;
+ s.item(m_value);
+},{
+ switch(m_type)
+ {
+ case NEGATE: os << "(-"; break;
+ case INVERT: os << "(!"; break;
+ case BOX: os << "(box "; break;
+ case REF: os << "(&"; break;
+ }
+ os << *m_value << ")";
+})
+
#define NV(type, actions)\
void NodeVisitorDef::visit(type& node) { DEBUG("DEF - "#type); actions }
@@ -386,6 +425,10 @@ NV(ExprNode_BinOp,
visit(node.m_left);
visit(node.m_right);
})
+NV(ExprNode_UniOp,
+{
+ visit(node.m_value);
+})
#undef NV