diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-07-16 22:29:44 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-07-16 22:29:44 +0800 |
commit | 9fe26bb83dcee67be874e57c439ea2e1ee984306 (patch) | |
tree | 6d720fd25f20f6bebc89df96c2a6106e79b32a54 /src/expand | |
parent | 3ae9e699d94196621f9a9ee6fc1962b2862e7438 (diff) | |
download | mrust-9fe26bb83dcee67be874e57c439ea2e1ee984306.tar.gz |
AST - Attributes on struct literal entries
Diffstat (limited to 'src/expand')
-rw-r--r-- | src/expand/derive.cpp | 24 | ||||
-rw-r--r-- | src/expand/mod.cpp | 16 | ||||
-rw-r--r-- | src/expand/test_harness.cpp | 14 |
3 files changed, 27 insertions, 27 deletions
diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp index f09e9298..30adadc1 100644 --- a/src/expand/derive.cpp +++ b/src/expand/derive.cpp @@ -1286,10 +1286,10 @@ public: nodes.push_back( NEWNODE(NamedValue, AST::Path(ty_path)) ); ), (Struct, - ::std::vector< ::std::pair< ::std::string, AST::ExprNodeP> > vals; + ::AST::ExprNode_StructLiteral::t_values vals; for( const auto& fld : e.ents ) { - vals.push_back( ::std::make_pair(fld.m_name, this->clone_val_ref(core_name, this->field(fld.m_name)) ) ); + vals.push_back({ {}, fld.m_name, this->clone_val_ref(core_name, this->field(fld.m_name)) }); } nodes.push_back( NEWNODE(StructLiteral, ty_path, nullptr, mv$(vals)) ); ), @@ -1338,13 +1338,13 @@ public: ), (Struct, ::std::vector< ::std::pair<std::string, AST::Pattern> > pats_a; - ::std::vector< ::std::pair<std::string, AST::ExprNodeP> > vals; + ::AST::ExprNode_StructLiteral::t_values vals; 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)) ); - vals.push_back( ::std::make_pair( fld.m_name, this->clone_val_direct(core_name, NEWNODE(NamedValue, AST::Path(name_a))) ) ); + vals.push_back({ {}, fld.m_name, this->clone_val_direct(core_name, NEWNODE(NamedValue, AST::Path(name_a))) }); } pat_a = AST::Pattern(AST::Pattern::TagStruct(), base_path + v.m_name, mv$(pats_a), true); @@ -1445,10 +1445,10 @@ public: nodes.push_back( NEWNODE(NamedValue, AST::Path(ty_path)) ); ), (Struct, - ::std::vector< ::std::pair< ::std::string, AST::ExprNodeP> > vals; + ::AST::ExprNode_StructLiteral::t_values vals; for( const auto& fld : e.ents ) { - vals.push_back( ::std::make_pair(fld.m_name, this->default_call(core_name)) ); + vals.push_back({ {}, fld.m_name, this->default_call(core_name) }); } nodes.push_back( NEWNODE(StructLiteral, ty_path, nullptr, mv$(vals)) ); ), @@ -1936,14 +1936,14 @@ public: (Unit, ), (Struct, - ::std::vector< ::std::pair< ::std::string, AST::ExprNodeP > > vals; + ::AST::ExprNode_StructLiteral::t_values vals; unsigned int idx = 0; for( const auto& fld : e.ents ) { - vals.push_back(::std::make_pair(fld.m_name, NEWNODE(UniOp, ::AST::ExprNode_UniOp::QMARK, NEWNODE(CallPath, + vals.push_back({ {}, fld.m_name, NEWNODE(UniOp, ::AST::ExprNode_UniOp::QMARK, NEWNODE(CallPath, this->get_trait_path_Decoder() + "read_struct_field", vec$( NEWNODE(NamedValue, AST::Path("d")), NEWNODE(String, fld.m_name), NEWNODE(Integer, idx, CORETYPE_UINT), this->dec_closure( sp, this->dec_val() ) ) - )) )); + )) }); idx ++; } node_v = NEWNODE(StructLiteral, base_path, nullptr, mv$(vals)); @@ -2021,21 +2021,21 @@ public: code = NEWNODE(CallPath, base_path + v.m_name, mv$(args)); ), (Struct, - ::std::vector< ::std::pair< ::std::string, AST::ExprNodeP > > vals; + ::AST::ExprNode_StructLiteral::t_values vals; unsigned int idx = 0; for( const auto& fld : e.m_fields ) { auto name_a = FMT("a" << fld.m_name); - vals.push_back(::std::make_pair(fld.m_name, NEWNODE(UniOp, ::AST::ExprNode_UniOp::QMARK, NEWNODE(CallPath, this->get_trait_path_Decoder() + "read_enum_struct_variant_field", + vals.push_back({ {}, fld.m_name, NEWNODE(UniOp, ::AST::ExprNode_UniOp::QMARK, NEWNODE(CallPath, this->get_trait_path_Decoder() + "read_enum_struct_variant_field", vec$( NEWNODE(NamedValue, AST::Path("d")), NEWNODE(String, fld.m_name), NEWNODE(Integer, idx, CORETYPE_UINT), this->dec_closure(sp, this->dec_val()) ) - ) ))); + ) )}); idx ++; } diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index adc53bf4..9137cc02 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -657,7 +657,7 @@ struct CExpandExpr: for(auto& val : node.m_values) { // TODO: Attributes on struct literal items (#[cfg] only?) - this->visit_nodelete(node, val.second); + this->visit_nodelete(node, val.value); } } void visit(::AST::ExprNode_Array& node) override { @@ -705,18 +705,18 @@ struct CExpandExpr: ::AST::ExprNode_StructLiteral::t_values values; if( node.m_left && node.m_right ) { - values.push_back( ::std::make_pair( ::std::string("start"), mv$(node.m_left ) ) ); - values.push_back( ::std::make_pair( ::std::string("end") , mv$(node.m_right) ) ); + values.push_back({ {}, "start", mv$(node.m_left ) }); + values.push_back({ {}, "end" , mv$(node.m_right) }); replacement.reset( new ::AST::ExprNode_StructLiteral(mv$(path_Range), nullptr, mv$(values)) ); } else if( node.m_left ) { - values.push_back( ::std::make_pair( ::std::string("start"), mv$(node.m_left ) ) ); + values.push_back({ {}, "start", mv$(node.m_left ) }); replacement.reset( new ::AST::ExprNode_StructLiteral(mv$(path_RangeFrom), nullptr, mv$(values)) ); } else if( node.m_right ) { - values.push_back( ::std::make_pair( ::std::string("end") , mv$(node.m_right) ) ); + values.push_back({ {}, "end" , mv$(node.m_right) }); replacement.reset( new ::AST::ExprNode_StructLiteral(mv$(path_RangeTo), nullptr, mv$(values)) ); } else @@ -734,14 +734,14 @@ struct CExpandExpr: if( node.m_left ) { ::AST::ExprNode_StructLiteral::t_values values; - values.push_back( ::std::make_pair( ::std::string("start"), mv$(node.m_left) ) ); - values.push_back( ::std::make_pair( ::std::string("end") , mv$(node.m_right) ) ); + values.push_back({ {}, "start", mv$(node.m_left) }); + values.push_back({ {}, "end" , mv$(node.m_right) }); replacement.reset( new ::AST::ExprNode_StructLiteral(mv$(path_RangeInclusive_NonEmpty), nullptr, mv$(values)) ); } else { ::AST::ExprNode_StructLiteral::t_values values; - values.push_back( ::std::make_pair( ::std::string("end") , mv$(node.m_right) ) ); + values.push_back({ {}, "end", mv$(node.m_right) }); replacement.reset( new ::AST::ExprNode_StructLiteral(mv$(path_RangeToInclusive), nullptr, mv$(values)) ); } replacement->set_span( node.span() ); diff --git a/src/expand/test_harness.cpp b/src/expand/test_harness.cpp index 12d32121..204ca75e 100644 --- a/src/expand/test_harness.cpp +++ b/src/expand/test_harness.cpp @@ -55,12 +55,12 @@ void Expand_TestHarness(::AST::Crate& crate) ::AST::ExprNode_StructLiteral::t_values desc_vals; // `name: "foo",` - desc_vals.push_back( ::std::make_pair("name", NEWNODE(_CallPath, + desc_vals.push_back({ {}, "name", NEWNODE(_CallPath, ::AST::Path("test", { ::AST::PathNode("StaticTestName") }), ::make_vec1( NEWNODE(_String, test.name) ) - ) )); + ) }); // `ignore: false,` - desc_vals.push_back( ::std::make_pair("ignore", NEWNODE(_Bool, test.ignore)) ); + desc_vals.push_back({ {}, "ignore", NEWNODE(_Bool, test.ignore) }); // `should_panic: ShouldPanic::No,` { ::AST::ExprNodeP should_panic_val; @@ -79,18 +79,18 @@ void Expand_TestHarness(::AST::Crate& crate) ); break; } - desc_vals.push_back( ::std::make_pair("should_panic", mv$(should_panic_val)) ); + desc_vals.push_back({ {}, "should_panic", mv$(should_panic_val) }); } auto desc_expr = NEWNODE(_StructLiteral, ::AST::Path("test", { ::AST::PathNode("TestDesc")}), nullptr, mv$(desc_vals)); ::AST::ExprNode_StructLiteral::t_values descandfn_vals; - descandfn_vals.push_back( ::std::make_pair(::std::string("desc"), mv$(desc_expr)) ); + descandfn_vals.push_back({ {}, ::std::string("desc"), mv$(desc_expr) }); auto test_type_var_name = test.is_benchmark ? "StaticBenchFn" : "StaticTestFn"; - descandfn_vals.push_back( ::std::make_pair(::std::string("testfn"), NEWNODE(_CallPath, + descandfn_vals.push_back({ {}, ::std::string("testfn"), NEWNODE(_CallPath, ::AST::Path("test", { ::AST::PathNode(test_type_var_name) }), ::make_vec1( NEWNODE(_NamedValue, AST::Path(test.path)) ) - ) ) ); + ) }); test_nodes.push_back( NEWNODE(_StructLiteral, ::AST::Path("test", { ::AST::PathNode("TestDescAndFn")}), nullptr, mv$(descandfn_vals) ) ); } |