From 1d8bd9bf1c4ebe98e6bea954c939c97f0d7c3a93 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 30 Oct 2016 21:40:20 +0800 Subject: AST - Remove copy construction of TypeRef --- src/parse/expr.cpp | 2 +- src/parse/paths.cpp | 10 +++++----- src/parse/root.cpp | 16 ++++++++-------- src/parse/token.cpp | 4 ++-- src/parse/types.cpp | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src/parse') diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index 749ffc9f..a45e4384 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -532,7 +532,7 @@ ExprNodeP Parse_Stmt_Let(TokenStream& lex) else { PUTBACK(tok, lex); } - return NEWNODE( AST::ExprNode_LetBinding, ::std::move(pat), ::std::move(type), ::std::move(val) ); + return NEWNODE( AST::ExprNode_LetBinding, ::std::move(pat), mv$(type), ::std::move(val) ); } ::std::vector Parse_ParenList(TokenStream& lex) diff --git a/src/parse/paths.cpp b/src/parse/paths.cpp index c952d977..e7fe1b0b 100644 --- a/src/parse/paths.cpp +++ b/src/parse/paths.cpp @@ -57,7 +57,7 @@ AST::Path Parse_Path(TokenStream& lex, eParsePathGenericMode generic_mode) } GET_CHECK_TOK(tok, lex, TOK_GT); GET_CHECK_TOK(tok, lex, TOK_DOUBLE_COLON); - return AST::Path(AST::Path::TagUfcs(), ty, trait, Parse_PathNodes(lex, generic_mode)); + return AST::Path(AST::Path::TagUfcs(), mv$(ty), mv$(trait), Parse_PathNodes(lex, generic_mode)); } else { PUTBACK(tok, lex); @@ -65,8 +65,8 @@ AST::Path Parse_Path(TokenStream& lex, eParsePathGenericMode generic_mode) // TODO: Terminating the "path" here is sometimes valid? GET_CHECK_TOK(tok, lex, TOK_DOUBLE_COLON); // NOTE: ::BAR is actually `::BAR` (in mrustc parleance) - //return AST::Path(AST::Path::TagUfcs(), ty, Parse_PathNodes(lex, generic_mode)); - return AST::Path(AST::Path::TagUfcs(), ty, AST::Path(), Parse_PathNodes(lex, generic_mode)); + //return AST::Path(AST::Path::TagUfcs(), mv$(ty), Parse_PathNodes(lex, generic_mode)); + return AST::Path(AST::Path::TagUfcs(), mv$(ty), AST::Path(), Parse_PathNodes(lex, generic_mode)); } throw ""; } @@ -161,8 +161,8 @@ AST::Path Parse_Path(TokenStream& lex, bool is_abs, eParsePathGenericMode generi // Encode into path, by converting Fn(A,B)->C into Fn<(A,B),Ret=C> params = ::AST::PathParams { {}, - ::std::vector { TypeRef(TypeRef::TagTuple(), lex.end_span(ps), ::std::move(args)) }, - { ::std::make_pair( ::std::string("Output"), mv$(ret_type) ) } + ::make_vec1( TypeRef(TypeRef::TagTuple(), lex.end_span(ps), mv$(args)) ), + ::make_vec1( ::std::make_pair( ::std::string("Output"), mv$(ret_type) ) ) }; GET_TOK(tok, lex); diff --git a/src/parse/root.cpp b/src/parse/root.cpp index ce3cb5fb..1ea9ea93 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -138,7 +138,7 @@ AST::GenericParams Parse_GenericParams(TokenStream& lex) auto param_ty = TypeRef(lex.getPosition(), param_name); if( GET_TOK(tok, lex) == TOK_COLON ) { - Parse_TypeBound(lex, ret, param_ty); + Parse_TypeBound(lex, ret, mv$(param_ty)); GET_TOK(tok, lex); } @@ -200,14 +200,14 @@ void Parse_WhereClause(TokenStream& lex, AST::GenericParams& params) TypeRef type = Parse_Type(lex); GET_CHECK_TOK(tok, lex, TOK_COLON); - Parse_TypeBound(lex, params, type, lifetimes); + Parse_TypeBound(lex,params, mv$(type), mv$(lifetimes)); } else { PUTBACK(tok, lex); TypeRef type = Parse_Type(lex); GET_CHECK_TOK(tok, lex, TOK_COLON); - Parse_TypeBound(lex, params, type); + Parse_TypeBound(lex, params, mv$(type)); } } while( GET_TOK(tok, lex) == TOK_COMMA ); PUTBACK(tok, lex); @@ -328,7 +328,7 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, bool allow_ else { PUTBACK(tok, lex); } - args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), ty) ); + args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), mv$(ty)) ); GET_TOK(tok, lex); } } @@ -345,7 +345,7 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, bool allow_ else { PUTBACK(tok, lex); } - args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), ty) ); + args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), mv$(ty)) ); GET_TOK(tok, lex); } else @@ -1149,7 +1149,7 @@ AST::ExternBlock Parse_ExternBlock(TokenStream& lex, ::std::string abi, ::AST::M auto type = Parse_Type(lex); GET_CHECK_TOK(tok, lex, TOK_SEMICOLON); - auto i = ::AST::Item(::AST::Static( (is_mut ? ::AST::Static::MUT : ::AST::Static::STATIC), type, ::AST::Expr() )); + auto i = ::AST::Item(::AST::Static( (is_mut ? ::AST::Static::MUT : ::AST::Static::STATIC), mv$(type), ::AST::Expr() )); i.attrs = mv$(meta_items); i.span = lex.end_span(ps); rv.add_item( AST::Named { mv$(name), mv$(i), is_public } ); @@ -1464,7 +1464,7 @@ void Parse_Use(TokenStream& lex, ::std::function(frag.m_ptr) ); + m_data = new TypeRef( reinterpret_cast(frag.m_ptr)->clone() ); break; case InterpolatedFragment::PAT: m_type = TOK_INTERPOLATED_PATTERN; @@ -179,7 +179,7 @@ Token Token::clone() const switch(m_type) { case TOK_INTERPOLATED_TYPE: - rv.m_data = new TypeRef( *reinterpret_cast(e) ); + rv.m_data = new TypeRef( reinterpret_cast(e)->clone() ); break; case TOK_INTERPOLATED_PATTERN: rv.m_data = new AST::Pattern( reinterpret_cast(e)->clone() ); diff --git a/src/parse/types.cpp b/src/parse/types.cpp index fabb13bc..1cbcc306 100644 --- a/src/parse/types.cpp +++ b/src/parse/types.cpp @@ -146,11 +146,11 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) // Sized array AST::Expr array_size = Parse_Expr(lex); GET_CHECK_TOK(tok, lex, TOK_SQUARE_CLOSE); - return TypeRef(TypeRef::TagSizedArray(), lex.end_span(ps), inner, array_size.take_node()); + return TypeRef(TypeRef::TagSizedArray(), lex.end_span(ps), mv$(inner), array_size.take_node()); } else if( tok.type() == TOK_SQUARE_CLOSE ) { - return TypeRef(TypeRef::TagUnsizedArray(), lex.end_span(ps), inner); + return TypeRef(TypeRef::TagUnsizedArray(), lex.end_span(ps), mv$(inner)); } else { throw ParseError::Unexpected(lex, tok/*, "; or ]"*/); @@ -181,7 +181,7 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) break; else PUTBACK(tok, lex); - types.push_back(Parse_Type(lex)); + types.push_back( Parse_Type(lex) ); } CHECK_TOK(tok, TOK_PAREN_CLOSE); return TypeRef(TypeRef::TagTuple(), lex.end_span(ps), mv$(types)); } @@ -287,7 +287,7 @@ TypeRef Parse_Type_Path(TokenStream& lex, ::std::vector<::std::string> hrls, boo return TypeRef(lex.end_span(ps), mv$(hrls), ::std::move(traits)); } else { - return TypeRef(TypeRef::TagPath(), lex.end_span(ps), traits.at(0)); + return TypeRef(TypeRef::TagPath(), lex.end_span(ps), mv$(traits.at(0))); } } } -- cgit v1.2.3