diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-08-31 15:18:57 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-08-31 15:18:57 +0800 |
commit | 894562850163a60721e23b5986869a580c7be5c7 (patch) | |
tree | 8fcc1d42e88867c47930095bb600bfc8c1feb90d /src/hir | |
parent | 1330bafaf004b5f0c42871ddc0c724e2862c115d (diff) | |
download | mrust-894562850163a60721e23b5986869a580c7be5c7.tar.gz |
HIR - Rough spport for `break value;` (no translation/typecheck yet)
Diffstat (limited to 'src/hir')
-rw-r--r-- | src/hir/expr.cpp | 6 | ||||
-rw-r--r-- | src/hir/expr.hpp | 7 | ||||
-rw-r--r-- | src/hir/from_ast_expr.cpp | 6 |
3 files changed, 12 insertions, 7 deletions
diff --git a/src/hir/expr.cpp b/src/hir/expr.cpp index 53f85c42..47f13052 100644 --- a/src/hir/expr.cpp +++ b/src/hir/expr.cpp @@ -45,7 +45,11 @@ DEF_VISIT(ExprNode_Let, node, DEF_VISIT(ExprNode_Loop, node, visit_node_ptr(node.m_code); ) -DEF_VISIT(ExprNode_LoopControl, , ) +DEF_VISIT(ExprNode_LoopControl, node, + if( node.m_value ) { + visit_node_ptr(node.m_value); + } +) DEF_VISIT(ExprNode_Match, node, visit_node_ptr(node.m_value); for(auto& arm : node.m_arms) diff --git a/src/hir/expr.hpp b/src/hir/expr.hpp index 3c37a930..3069ae1d 100644 --- a/src/hir/expr.hpp +++ b/src/hir/expr.hpp @@ -146,12 +146,13 @@ struct ExprNode_LoopControl: { ::std::string m_label; bool m_continue; - //::HIR::ExprNodeP m_value; + ::HIR::ExprNodeP m_value; - ExprNode_LoopControl(Span sp, ::std::string label, bool cont): + ExprNode_LoopControl(Span sp, ::std::string label, bool cont, ::HIR::ExprNodeP value={}): ExprNode(mv$(sp), ::HIR::TypeRef::new_diverge()), m_label( mv$(label) ), - m_continue( cont ) + m_continue( cont ), + m_value( mv$(value) ) {} NODE_METHODS(); diff --git a/src/hir/from_ast_expr.cpp b/src/hir/from_ast_expr.cpp index 545873ed..46cb03b5 100644 --- a/src/hir/from_ast_expr.cpp +++ b/src/hir/from_ast_expr.cpp @@ -71,9 +71,9 @@ struct LowerHIR_ExprNode_Visitor: break; case ::AST::ExprNode_Flow::CONTINUE: case ::AST::ExprNode_Flow::BREAK: - if( v.m_value ) - TODO(v.span(), "Handle break/continue values in HIR"); - m_rv.reset( new ::HIR::ExprNode_LoopControl( v.span(), v.m_target, (v.m_type == ::AST::ExprNode_Flow::CONTINUE) ) ); + auto val = v.m_value ? LowerHIR_ExprNode_Inner(*v.m_value) : ::HIR::ExprNodeP(); + ASSERT_BUG(v.span(), !(v.m_type == ::AST::ExprNode_Flow::CONTINUE && val), "Continue with a value isn't allowed"); + m_rv.reset( new ::HIR::ExprNode_LoopControl( v.span(), v.m_target, (v.m_type == ::AST::ExprNode_Flow::CONTINUE), mv$(val) ) ); break; } } |