diff options
author | John Hodge <tpg@mutabah.net> | 2016-05-20 22:38:34 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-05-20 22:38:34 +0800 |
commit | cca20d66c1f0933b12b4bfd82817aa2cf40b1730 (patch) | |
tree | 26ffdeb83d3b9e3f93f71adb44cf4d0dc50ecc5b /src/expand | |
parent | d2fcab19c6d8441f1b0610cb2147a43292893764 (diff) | |
download | mrust-cca20d66c1f0933b12b4bfd82817aa2cf40b1730.tar.gz |
Expand+HIR - `?` desugar, closures
Diffstat (limited to 'src/expand')
-rw-r--r-- | src/expand/mod.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index 7474ce21..f0508698 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -482,6 +482,32 @@ struct CExpandExpr: } void visit(::AST::ExprNode_UniOp& node) override { this->visit_nodelete(node, node.m_value); + if( node.m_type == ::AST::ExprNode_UniOp::QMARK ) { + auto path_Ok = ::AST::Path("", {::AST::PathNode("result"), ::AST::PathNode("Result"), ::AST::PathNode("Ok")}); + auto path_Err = ::AST::Path("", {::AST::PathNode("result"), ::AST::PathNode("Result"), ::AST::PathNode("Err")}); + auto path_From = ::AST::Path("", {::AST::PathNode("convert"), ::AST::PathNode("From")}); + + ::std::vector< ::AST::ExprNode_Match_Arm> arms; + arms.push_back(::AST::ExprNode_Match_Arm( + ::make_vec1( ::AST::Pattern(::AST::Pattern::TagEnumVariant(), path_Ok, ::make_vec1( ::AST::Pattern(::AST::Pattern::TagBind(), "v") )) ), + nullptr, + ::AST::ExprNodeP( new ::AST::ExprNode_NamedValue( ::AST::Path(::AST::Path::TagLocal(), "v") ) ) + )); + arms.push_back(::AST::ExprNode_Match_Arm( + ::make_vec1( ::AST::Pattern(::AST::Pattern::TagEnumVariant(), path_Err, ::make_vec1( ::AST::Pattern(::AST::Pattern::TagBind(), "e") )) ), + nullptr, + ::AST::ExprNodeP(new ::AST::ExprNode_Flow( + ::AST::ExprNode_Flow::RETURN, + "", + ::AST::ExprNodeP(new ::AST::ExprNode_CallPath( + ::AST::Path(::AST::Path::TagUfcs(), ::TypeRef(), mv$(path_From), { ::AST::PathNode("from") }), + ::make_vec1( ::AST::ExprNodeP( new ::AST::ExprNode_NamedValue( ::AST::Path(::AST::Path::TagLocal(), "e") ) ) ) + )) + )) + )); + + replacement.reset(new ::AST::ExprNode_Match( mv$(node.m_value), mv$(arms) )); + } } }; |