diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-02-26 18:10:38 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-02-26 18:10:38 +0800 |
commit | aa99de423034435cf765b9dc104f69fc20f84bd6 (patch) | |
tree | 2d03f44379c6f80c6c4e0a22baed8c8e8a44cba4 /src | |
parent | 177040dd129bccdc275831e3423af2efab6e948e (diff) | |
download | mrust-aa99de423034435cf765b9dc104f69fc20f84bd6.tar.gz |
Expand derive - Debug for enums
Diffstat (limited to 'src')
-rw-r--r-- | src/expand/derive.cpp | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp index 58eb1f96..c363b689 100644 --- a/src/expand/derive.cpp +++ b/src/expand/derive.cpp @@ -369,43 +369,56 @@ public: pat_a = AST::Pattern(AST::Pattern::TagValue(), AST::Pattern::Value::make_Named(base_path + v.m_name)); ), (Tuple, - // TODO: Complete this. ::std::vector<AST::Pattern> pats_a; - //::std::vector<AST::ExprNodeP> nodes; + AST::ExprNodeP node; + + node = NEWNODE(NamedValue, AST::Path("f")); + node = NEWNODE(CallMethod, + mv$(node), AST::PathNode("debug_tuple",{}), + vec$( NEWNODE(String, v.m_name) ) + ); for( unsigned int idx = 0; idx < e.m_sub_types.size(); idx ++ ) { auto name_a = FMT("a" << idx); pats_a.push_back( ::AST::Pattern(::AST::Pattern::TagBind(), name_a, ::AST::PatternBinding::Type::REF) ); - //nodes.push_back( this->assert_is_eq(assert_method_path, NEWNODE(NamedValue, AST::Path(name_a))) ); - } - //code = NEWNODE(Block, mv$(nodes)); - code = NEWNODE(CallMethod, - NEWNODE(NamedValue, AST::Path("f")), - AST::PathNode("write_str",{}), - vec$( NEWNODE(String, v.m_name + "(...)") ) - ); + node = NEWNODE(CallMethod, + mv$(node), AST::PathNode("field",{}), + vec$( + NEWNODE(NamedValue, AST::Path(name_a)) + ) + ); + } + code = NEWNODE(CallMethod, mv$(node), AST::PathNode("finish",{}), {}); pat_a = AST::Pattern(AST::Pattern::TagNamedTuple(), base_path + v.m_name, mv$(pats_a)); ), (Struct, ::std::vector< ::std::pair<std::string, AST::Pattern> > pats_a; - //::std::vector<AST::ExprNodeP> nodes; + AST::ExprNodeP node; + + node = NEWNODE(NamedValue, AST::Path("f")); + node = NEWNODE(CallMethod, + mv$(node), AST::PathNode("debug_struct",{}), + vec$( NEWNODE(String, v.m_name) ) + ); for( const auto& fld : e.m_fields ) { auto name_a = FMT("a" << fld.m_name); pats_a.push_back( ::std::make_pair(fld.m_name, ::AST::Pattern(::AST::Pattern::TagBind(), name_a, ::AST::PatternBinding::Type::REF)) ); - //nodes.push_back( this->assert_is_eq(assert_method_path, NEWNODE(NamedValue, AST::Path(name_a))) ); + + node = NEWNODE(CallMethod, + mv$(node), AST::PathNode("field",{}), + vec$( + NEWNODE(String, fld.m_name), + NEWNODE(NamedValue, AST::Path(name_a)) + ) + ); } - //code = NEWNODE(Block, mv$(nodes) ); - code = NEWNODE(CallMethod, - NEWNODE(NamedValue, AST::Path("f")), - AST::PathNode("write_str",{}), - vec$( NEWNODE(String, v.m_name + "{...}") ) - ); + code = NEWNODE(CallMethod, mv$(node), AST::PathNode("finish",{}), {}); pat_a = AST::Pattern(AST::Pattern::TagStruct(), base_path + v.m_name, mv$(pats_a), true); ) ) |