From eb072a063d3aa873087f08a47f01162753b559a6 Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Wed, 10 Dec 2014 19:50:51 +0100 Subject: [PATCH] Do not wrap simple expressions in braces. --- Nodes.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Nodes.cpp b/Nodes.cpp index 2ebf93d..9cc0b63 100644 --- a/Nodes.cpp +++ b/Nodes.cpp @@ -161,9 +161,19 @@ void Assignment::emit(std::ostream &stream, int indent) { } void Print::emit(std::ostream &stream, int indent) { - stream << "std::cout << ("; + bool simpleExpression = (dynamic_cast(expression.get()) != nullptr); + + stream << "std::cout << "; + if (!simpleExpression) { + stream << '('; + } + expression->emit(stream); - stream << ") << std::endl"; + + if (!simpleExpression) { + stream << ')'; + } + stream << " << std::endl"; } void Input::emit(std::ostream &stream, int indent) {