summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-10-05 19:20:20 +0800
committerJohn Hodge <tpg@mutabah.net>2016-10-05 19:20:20 +0800
commit29355c5a5de0d36cc4e24ac9fec2c697b15d0119 (patch)
tree8c641d5f4af0072e519310d3af21405f3a4bce97
parent3ee9d5c193e5177e695ae237ab2c28c225619ff2 (diff)
downloadmrust-29355c5a5de0d36cc4e24ac9fec2c697b15d0119.tar.gz
HIR Dump - Avoid parens in a few cases
-rw-r--r--src/hir/dump.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/hir/dump.cpp b/src/hir/dump.cpp
index b24d37c6..b7c2eb5f 100644
--- a/src/hir/dump.cpp
+++ b/src/hir/dump.cpp
@@ -273,6 +273,20 @@ namespace {
virtual void visit_expr(::HIR::ExprPtr& exp);
#endif
+ bool node_is_leaf(const ::HIR::ExprNode& node) {
+ if( NODE_IS(&node, _PathValue) )
+ return true;
+ if( NODE_IS(&node, _Variable) )
+ return true;
+ if( NODE_IS(&node, _Literal) )
+ return true;
+ if( NODE_IS(&node, _CallPath) )
+ return true;
+ if( NODE_IS(&node, _Deref) )
+ return true;
+ return false;
+ }
+
void visit(::HIR::ExprNode_Block& node) override
{
if( node.m_nodes.size() == 0 ) {
@@ -420,10 +434,11 @@ namespace {
case ::HIR::BorrowType::Unique: m_os << "mut "; break;
case ::HIR::BorrowType::Owned : m_os << "move "; break;
}
- // TODO: Avoid parens
- m_os << "(";
+
+ bool skip_parens = this->node_is_leaf(*node.m_value) || NODE_IS(node.m_value, _Deref);
+ if( !skip_parens ) m_os << "(";
this->visit_node_ptr(node.m_value);
- m_os << ")";
+ if( !skip_parens ) m_os << ")";
}
void visit(::HIR::ExprNode_Cast& node) override
{
@@ -448,10 +463,11 @@ namespace {
void visit(::HIR::ExprNode_Deref& node) override
{
m_os << "*";
- // TODO: Avoid parens
- m_os << "(";
+
+ bool skip_parens = this->node_is_leaf(*node.m_value);
+ if( !skip_parens ) m_os << "(";
this->visit_node_ptr(node.m_value);
- m_os << ")";
+ if( !skip_parens ) m_os << ")";
}
void visit(::HIR::ExprNode_Emplace& node) override
{