diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-30 21:40:20 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-30 21:40:20 +0800 |
commit | 1d8bd9bf1c4ebe98e6bea954c939c97f0d7c3a93 (patch) | |
tree | 15d021b4919992606a270d913b115c34971da872 | |
parent | 667912cb8de8cecd066505970d669565544eb431 (diff) | |
download | mrust-1d8bd9bf1c4ebe98e6bea954c939c97f0d7c3a93.tar.gz |
AST - Remove copy construction of TypeRef
-rw-r--r-- | src/ast/ast.cpp | 17 | ||||
-rw-r--r-- | src/ast/ast.hpp | 2 | ||||
-rw-r--r-- | src/ast/crate.hpp | 4 | ||||
-rw-r--r-- | src/ast/expr.cpp | 10 | ||||
-rw-r--r-- | src/ast/generics.hpp | 20 | ||||
-rw-r--r-- | src/ast/path.cpp | 68 | ||||
-rw-r--r-- | src/ast/path.hpp | 23 | ||||
-rw-r--r-- | src/ast/types.cpp | 31 | ||||
-rw-r--r-- | src/ast/types.hpp | 19 | ||||
-rw-r--r-- | src/expand/derive.cpp | 31 | ||||
-rw-r--r-- | src/parse/expr.cpp | 2 | ||||
-rw-r--r-- | src/parse/paths.cpp | 10 | ||||
-rw-r--r-- | src/parse/root.cpp | 16 | ||||
-rw-r--r-- | src/parse/token.cpp | 4 | ||||
-rw-r--r-- | src/parse/types.cpp | 8 | ||||
-rw-r--r-- | src/resolve/absolute.cpp | 14 |
16 files changed, 135 insertions, 144 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 144842db..a5085501 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -67,21 +67,21 @@ MetaItem MetaItem::clone() const StructItem StructItem::clone() const
{
- return StructItem(m_attrs.clone(), m_is_public, m_name, m_type);
+ return StructItem(m_attrs.clone(), m_is_public, m_name, m_type.clone());
}
TupleItem TupleItem::clone() const
{
- return TupleItem(m_attrs.clone(), m_is_public, m_type);
+ return TupleItem(m_attrs.clone(), m_is_public, m_type.clone());
}
TypeAlias TypeAlias::clone() const
{
- return TypeAlias( m_params.clone(), m_type );
+ return TypeAlias( m_params.clone(), m_type.clone() );
}
Static Static::clone() const
{
- return Static( m_class, m_type, m_value.is_valid() ? AST::Expr( m_value.node().clone() ) : AST::Expr() );
+ return Static( m_class, m_type.clone(), m_value.is_valid() ? AST::Expr( m_value.node().clone() ) : AST::Expr() );
}
Function::Function(Span sp, GenericParams params, ::std::string abi, bool is_unsafe, bool is_const, bool is_variadic, TypeRef ret_type, Arglist args):
@@ -99,9 +99,9 @@ Function Function::clone() const {
decltype(m_args) new_args;
for(const auto& arg : m_args)
- new_args.push_back( ::std::make_pair( arg.first.clone(), arg.second ) );
+ new_args.push_back( ::std::make_pair( arg.first.clone(), arg.second.clone() ) );
- auto rv = Function( m_span, m_params.clone(), m_abi, m_is_unsafe, m_is_const, m_is_variadic, m_rettype, mv$(new_args) );
+ auto rv = Function( m_span, m_params.clone(), m_abi, m_is_unsafe, m_is_const, m_is_variadic, m_rettype.clone(), mv$(new_args) );
if( m_code.is_valid() )
{
rv.m_code = AST::Expr( m_code.node().clone() );
@@ -157,7 +157,10 @@ Enum Enum::clone() const new_variants.push_back( EnumVariant(var.m_attrs.clone(), var.m_name, e.m_value.clone()) );
),
(Tuple,
- new_variants.push_back( EnumVariant(var.m_attrs.clone(), var.m_name, e.m_sub_types) );
+ decltype(e.m_sub_types) new_st;
+ for(const auto& f : e.m_sub_types)
+ new_st.push_back( f.clone() );
+ new_variants.push_back( EnumVariant(var.m_attrs.clone(), var.m_name, mv$(new_st)) );
),
(Struct,
decltype(e.m_fields) new_fields;
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index 7f34e30b..63a8b751 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -596,7 +596,7 @@ struct ImplRef ImplRef(const Impl& impl, ::std::vector<TypeRef> params):
impl(impl),
- params(params)
+ params( mv$(params) )
{}
::rust::option<char> find_named_item(const ::std::string& name) const;
diff --git a/src/ast/crate.hpp b/src/ast/crate.hpp index 146c05f6..31076c02 100644 --- a/src/ast/crate.hpp +++ b/src/ast/crate.hpp @@ -13,10 +13,6 @@ class ExternCrate; class Crate { public: - ::std::map< TypeRef, ::std::vector<Impl*> > m_impl_map; - ::std::vector<Impl*> m_impl_index; - ::std::vector<const ImplDef*> m_neg_impl_index; - ::AST::MetaItems m_attrs; ::std::map< ::std::string, ::AST::Path> m_lang_items; diff --git a/src/ast/expr.cpp b/src/ast/expr.cpp index 00c8f5e2..e6374f25 100644 --- a/src/ast/expr.cpp +++ b/src/ast/expr.cpp @@ -121,7 +121,7 @@ NODE(ExprNode_Flow, { NODE(ExprNode_LetBinding, { os << "let " << m_pat << ": " << m_type << " = " << *m_value; },{ - return NEWNODE(ExprNode_LetBinding, m_pat.clone(), TypeRef(m_type), OPT_CLONE(m_value)); + return NEWNODE(ExprNode_LetBinding, m_pat.clone(), m_type.clone(), OPT_CLONE(m_value)); }) NODE(ExprNode_Assign, { @@ -244,9 +244,9 @@ NODE(ExprNode_Closure, { },{ ExprNode_Closure::args_t args; for(const auto& a : m_args) { - args.push_back( ::std::make_pair(a.first.clone(), TypeRef(a.second)) ); + args.push_back( ::std::make_pair(a.first.clone(), a.second.clone()) ); } - return NEWNODE(ExprNode_Closure, mv$(args), TypeRef(m_return), m_code->clone()); + return NEWNODE(ExprNode_Closure, mv$(args), m_return.clone(), m_code->clone()); }); NODE(ExprNode_StructLiteral, { @@ -323,12 +323,12 @@ NODE(ExprNode_Deref, { NODE(ExprNode_Cast, { os << "(" << *m_value << " as " << m_type << ")"; },{ - return NEWNODE(ExprNode_Cast, m_value->clone(), TypeRef(m_type)); + return NEWNODE(ExprNode_Cast, m_value->clone(), m_type.clone()); }) NODE(ExprNode_TypeAnnotation, { os << "(" << *m_value << ": " << m_type << ")"; },{ - return NEWNODE(ExprNode_TypeAnnotation, m_value->clone(), TypeRef(m_type)); + return NEWNODE(ExprNode_TypeAnnotation, m_value->clone(), m_type.clone()); }) NODE(ExprNode_BinOp, { diff --git a/src/ast/generics.hpp b/src/ast/generics.hpp index f02de958..7f8858a8 100644 --- a/src/ast/generics.hpp +++ b/src/ast/generics.hpp @@ -11,6 +11,12 @@ class TypeParam ::std::string m_name; TypeRef m_default; public: + TypeParam(TypeParam&& x) = default; + TypeParam& operator=(TypeParam&& x) = default; + TypeParam(const TypeParam& x): + m_name(x.m_name), + m_default(x.m_default.clone()) + {} //TypeParam(): m_name("") {} TypeParam(::std::string name): m_name( ::std::move(name) ), @@ -73,11 +79,11 @@ TAGGED_UNION_EX( GenericBound, (), Lifetime, GenericBound clone() const { TU_MATCH(GenericBound, ( (*this) ), (ent), (Lifetime, return make_Lifetime({ent.test, ent.bound}); ), - (TypeLifetime, return make_TypeLifetime({ent.type, ent.bound}); ), - (IsTrait, return make_IsTrait({ent.type, ent.hrls, ent.trait}); ), - (MaybeTrait, return make_MaybeTrait({ent.type, ent.trait}); ), - (NotTrait, return make_NotTrait({ent.type, ent.trait}); ), - (Equality, return make_Equality({ent.type, ent.replacement}); ) + (TypeLifetime, return make_TypeLifetime({ent.type.clone(), ent.bound}); ), + (IsTrait, return make_IsTrait({ent.type.clone(), ent.hrls, ent.trait}); ), + (MaybeTrait, return make_MaybeTrait({ent.type.clone(), ent.trait}); ), + (NotTrait, return make_NotTrait({ent.type.clone(), ent.trait}); ), + (Equality, return make_Equality({ent.type.clone(), ent.replacement.clone()}); ) ) return GenericBound(); } @@ -93,13 +99,13 @@ class GenericParams ::std::vector<GenericBound> m_bounds; public: GenericParams() {} - GenericParams(GenericParams&& x) noexcept = default; + GenericParams(GenericParams&& x) = default; GenericParams& operator=(GenericParams&& x) = default; GenericParams(const GenericParams& x) = delete; GenericParams clone() const { GenericParams rv; - rv.m_type_params = m_type_params; // Copy-constructable + rv.m_type_params = ::std::vector<TypeParam>( m_type_params ); // Copy-constructable rv.m_lifetime_params = m_lifetime_params; rv.m_bounds.reserve( m_bounds.size() ); for(auto& e: m_bounds) diff --git a/src/ast/path.cpp b/src/ast/path.cpp index 132f0bb8..7574f707 100644 --- a/src/ast/path.cpp +++ b/src/ast/path.cpp @@ -76,6 +76,17 @@ PathBinding PathBinding::clone() const os << ">"; return os; } +PathParams::PathParams(const PathParams& x): + m_lifetimes( x.m_lifetimes ) +{ + m_types.reserve( x.m_types.size() ); + for(const auto& t : x.m_types) + m_types.push_back(t.clone()); + + m_assoc.reserve( x.m_assoc.size() ); + for(const auto& t : x.m_assoc) + m_assoc.push_back( ::std::make_pair(t.first, t.second.clone()) ); +} Ordering PathParams::ord(const PathParams& x) const { Ordering rv; @@ -162,52 +173,15 @@ AST::Path::Path(const Path& x): ), (UFCS, if( ent.trait ) - m_class = Class::make_UFCS({ box$(TypeRef(*ent.type)), ::std::unique_ptr<Path>(new Path(*ent.trait)), ent.nodes }); + m_class = Class::make_UFCS({ box$(ent.type->clone()), ::std::unique_ptr<Path>(new Path(*ent.trait)), ent.nodes }); else - m_class = Class::make_UFCS({ box$(TypeRef(*ent.type)), nullptr, ent.nodes }); + m_class = Class::make_UFCS({ box$(ent.type->clone()), nullptr, ent.nodes }); ) ) memcpy(&m_binding, &x.m_binding, sizeof(PathBinding)); - //DEBUG("clone, x = " << x << ", this = " << *this ); } -/* -void Path::check_param_counts(const GenericParams& params, bool expect_params, PathNode& node) -{ - if( !expect_params ) - { - if( node.args().size() ) - throw CompileError::BugCheck(FMT("Unexpected parameters in path " << *this)); - } - else if( node.args().size() != params.ty_params().size() ) - { - DEBUG("Count mismatch"); - if( node.args().size() > params.ty_params().size() ) - { - // Too many, definitely an error - throw CompileError::Generic(FMT("Too many type parameters passed in path " << *this)); - } - else - { - // Too few, allow defaulting - while( node.args().size() < params.ty_params().size() ) - { - unsigned int i = node.args().size(); - const auto& p = params.ty_params()[i]; - DEBUG("Extra #" << i << ", p = " << p); - // XXX: Currently, the default is just inserted (_ where not specified) - // - Erroring failed on transmute, and other omitted for inferrence instnaces - if( true || p.get_default() != TypeRef() ) - node.args().push_back( p.get_default() ); - else - throw CompileError::Generic(FMT("Not enough type parameters passed in path " << *this)); - } - } - } -} -*/ - void Path::bind_variable(unsigned int slot) { m_binding = PathBinding::make_Variable({slot}); @@ -232,27 +206,11 @@ void Path::bind_enum_var(const Enum& ent, const ::std::string& name, const ::std if( idx == ent.variants().size() ) throw ParseError::Generic("Enum variant not found"); - //if( args.size() > 0 ) - //{ - // if( args.size() != ent.params().size() ) - // throw ParseError::Generic("Parameter count mismatch"); - // throw ParseError::Todo("Bind enum variant with params passed"); - //} - DEBUG("Bound to enum variant '" << name << "' (#" << idx << ")"); m_binding = PathBinding::make_EnumVar({&ent, idx}); } void Path::bind_struct(const Struct& ent, const ::std::vector<TypeRef>& /*args*/) { - //if( args.size() > 0 ) - //{ - // if( args.size() != ent.params().n_params() ) - // throw ParseError::Generic("Parameter count mismatch"); - // // TODO: Is it the role of this section of code to ensure that the passed args are valid? - // // - Probably not, it should instead be the type checker that does it - // // - Count validation is OK here though - //} - DEBUG("Bound to struct"); m_binding = PathBinding::make_Struct({&ent}); } diff --git a/src/ast/path.hpp b/src/ast/path.hpp index edc874bb..3a00cdfd 100644 --- a/src/ast/path.hpp +++ b/src/ast/path.hpp @@ -106,6 +106,18 @@ struct PathParams ::std::vector< TypeRef > m_types; ::std::vector< ::std::pair< ::std::string, TypeRef> > m_assoc; + PathParams(PathParams&& x) = default; + PathParams(const PathParams& x); + PathParams() {} + PathParams(::std::vector<::std::string> lfts, ::std::vector<TypeRef> tys, ::std::vector<::std::pair<::std::string,TypeRef>> a): + m_lifetimes(mv$(lfts)), + m_types(mv$(tys)), + m_assoc(mv$(a)) + {} + + PathParams& operator=(PathParams&& x) = default; + PathParams& operator=(const PathParams& x) = delete; + bool is_empty() const { return m_lifetimes.empty() && m_types.empty() && m_assoc.empty(); } @@ -174,7 +186,7 @@ public: Path(): m_class() {} - Path(Path&&) noexcept = default; + Path(Path&&) = default; Path& operator=(AST::Path&& x) { m_class = mv$(x.m_class); m_binding = mv$(x.m_binding); @@ -183,6 +195,7 @@ public: } Path(const Path& x); + Path& operator=(const AST::Path&) = delete; // ABSOLUTE Path(::std::string crate, ::std::vector<PathNode> nodes): @@ -211,7 +224,7 @@ public: // SELF struct TagSelf {}; Path(TagSelf, ::std::vector<PathNode> nodes): - m_class( Class::make_Self({ nodes }) ) + m_class( Class::make_Self({ mv$(nodes) }) ) {} // SUPER struct TagSuper {}; @@ -231,9 +244,9 @@ public: return m_class.tag(); } - Path operator+(PathNode&& pn) const { + Path operator+(PathNode pn) const { Path tmp = Path(*this); - tmp.nodes().push_back( pn ); + tmp.nodes().push_back( mv$(pn) ); return tmp; } Path operator+(const ::std::string& s) const { @@ -249,7 +262,7 @@ public: void append(PathNode node) { if( m_class.is_Invalid() ) m_class = Class::make_Relative({}); - nodes().push_back(node); + nodes().push_back( mv$(node) ); m_binding = PathBinding(); } diff --git a/src/ast/types.cpp b/src/ast/types.cpp index d95c172f..c8f373e5 100644 --- a/src/ast/types.cpp +++ b/src/ast/types.cpp @@ -78,9 +78,10 @@ const char* coretype_name(const eCoreType ct ) { Type_Function::Type_Function(const Type_Function& other): is_unsafe(other.is_unsafe), m_abi(other.m_abi), - m_rettype( box$( TypeRef(*other.m_rettype) ) ), - m_arg_types(other.m_arg_types) + m_rettype( box$( other.m_rettype->clone() ) ) { + for( const auto& at : other.m_arg_types ) + m_arg_types.push_back( at.clone() ); } Ordering Type_Function::ord(const Type_Function& x) const @@ -98,13 +99,22 @@ TypeRef::~TypeRef() { } -TypeRef::TypeRef(const TypeRef& other) +TypeRef TypeRef::clone() const { - switch( other.m_data.tag() ) + struct H { + static ::std::vector< ::TypeRef> clone_ty_vec(const ::std::vector<TypeRef>& x) { + ::std::vector<TypeRef> rv; + rv.reserve(x.size()); + for(const auto& t : x) + rv.push_back( t.clone() ); + return rv; + } + }; + switch( m_data.tag() ) { case TypeData::TAGDEAD: assert(!"Copying a destructed type"); - #define _COPY(VAR) case TypeData::TAG_##VAR: m_data = TypeData::make_##VAR(other.m_data.as_##VAR()); break; - #define _CLONE(VAR, code...) case TypeData::TAG_##VAR: { auto& old = other.m_data.as_##VAR(); m_data = TypeData::make_##VAR(code); } break; + #define _COPY(VAR) case TypeData::TAG_##VAR: return TypeRef(m_span, TypeData::make_##VAR(m_data.as_##VAR()) ); break; + #define _CLONE(VAR, code...) case TypeData::TAG_##VAR: { auto& old = m_data.as_##VAR(); return TypeRef(m_span, TypeData::make_##VAR(code) ); } break; _COPY(None) _COPY(Any) _COPY(Bang) @@ -112,10 +122,10 @@ TypeRef::TypeRef(const TypeRef& other) _COPY(Unit) _COPY(Primitive) _COPY(Function) - _COPY(Tuple) - _CLONE(Borrow, { old.is_mut, box$(TypeRef(*old.inner)) }) - _CLONE(Pointer, { old.is_mut, box$(TypeRef(*old.inner)) }) - _CLONE(Array, { box$(TypeRef(*old.inner)), old.size }) + _CLONE(Tuple, { H::clone_ty_vec(old.inner_types) }) + _CLONE(Borrow, { old.is_mut, box$(old.inner->clone()) }) + _CLONE(Pointer, { old.is_mut, box$(old.inner->clone()) }) + _CLONE(Array, { box$(old.inner->clone()), old.size }) _COPY(Generic) _COPY(Path) _COPY(TraitObject) @@ -123,6 +133,7 @@ TypeRef::TypeRef(const TypeRef& other) #undef _COPY #undef _CLONE } + throw ""; } Ordering TypeRef::ord(const TypeRef& x) const diff --git a/src/ast/types.hpp b/src/ast/types.hpp index 66f5797c..04c1517f 100644 --- a/src/ast/types.hpp +++ b/src/ast/types.hpp @@ -110,16 +110,23 @@ class TypeRef public:
TypeData m_data;
- virtual ~TypeRef();
+ ~TypeRef();
- TypeRef(TypeRef&& other) noexcept = default;
+ TypeRef(TypeRef&& other) = default;
TypeRef& operator=(TypeRef&& other) = default;
- TypeRef(const TypeRef& other);
+ #if 1
+ TypeRef(const TypeRef& other) = delete;
+ TypeRef& operator=(const TypeRef& other) = delete;
+ #else
+ TypeRef(const TypeRef& other): m_span(other.m_span) {
+ *this = other.clone();
+ }
TypeRef& operator=(const TypeRef& other) {
- m_data = TypeRef(other).m_data;
+ m_data = mv$(other.clone().m_data);
return *this;
}
+ #endif
TypeRef(Span sp):
m_span( mv$(sp) ),
@@ -235,9 +242,7 @@ public: bool is_pointer() const { return m_data.is_Pointer(); }
bool is_tuple() const { return m_data.is_Tuple(); }
- TypeRef clone() const {
- return TypeRef(*this);
- }
+ TypeRef clone() const;
const TypeRef& inner_type() const {
TU_MATCH_DEF(TypeData, (m_data), (e),
diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp index 84539318..fc3210b5 100644 --- a/src/expand/derive.cpp +++ b/src/expand/derive.cpp @@ -244,7 +244,7 @@ struct Deriver } } - out_list.push_back(type); + out_list.push_back(type.clone()); } }; @@ -268,8 +268,7 @@ class Deriver_Debug: AST::Impl make_ret(Span sp, const ::std::string& core_name, const AST::GenericParams& p, const TypeRef& type, ::std::vector<TypeRef> types_to_bound, AST::ExprNodeP node) const { const AST::Path debug_trait = AST::Path(core_name, { AST::PathNode("fmt", {}), AST::PathNode("Debug", {}) }); - const TypeRef ret_type(sp, AST::Path(core_name, {AST::PathNode("fmt",{}), AST::PathNode("Result",{})}) ); - const TypeRef f_type(TypeRef::TagReference(), sp, true, + TypeRef f_type(TypeRef::TagReference(), sp, true, TypeRef(sp, AST::Path(core_name, {AST::PathNode("fmt",{}), AST::PathNode("Formatter", {})})) ); @@ -279,17 +278,17 @@ class Deriver_Debug: sp, AST::GenericParams(), ABI_RUST, false, false, false, - ret_type, + TypeRef(sp, AST::Path(core_name, {AST::PathNode("fmt",{}), AST::PathNode("Result",{})}) ), vec$( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), sp, false, TypeRef(sp, "Self", 0xFFFF)) ), - ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "f"), f_type ) + ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "f"), mv$(f_type) ) ) ); fcn.set_code( NEWNODE(Block, vec$(mv$(node))) ); AST::GenericParams params = get_params_with_bounds(sp, p, debug_trait, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, debug_trait), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, debug_trait), type.clone() ) ); rv.add_function(false, false, "fmt", mv$(fcn)); return mv$(rv); } @@ -452,7 +451,7 @@ class Deriver_PartialEq: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); rv.add_function(false, false, "eq", mv$(fcn)); return mv$(rv); } @@ -628,7 +627,7 @@ class Deriver_PartialOrd: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); rv.add_function(false, false, "partial_cmp", mv$(fcn)); return mv$(rv); } @@ -865,7 +864,7 @@ class Deriver_Eq: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); rv.add_function(false, false, "assert_receiver_is_total_eq", mv$(fcn)); return mv$(rv); } @@ -1000,7 +999,7 @@ class Deriver_Ord: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); rv.add_function(false, false, "cmp", mv$(fcn)); return mv$(rv); } @@ -1228,7 +1227,7 @@ class Deriver_Clone: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); rv.add_function(false, false, "clone", mv$(fcn)); return mv$(rv); } @@ -1359,7 +1358,7 @@ class Deriver_Copy: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); return mv$(rv); } @@ -1400,7 +1399,7 @@ class Deriver_Default: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); rv.add_function(false, false, "default", mv$(fcn)); return mv$(rv); } @@ -1489,7 +1488,7 @@ class Deriver_Hash: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); rv.add_function(false, false, "hash", mv$(fcn)); return mv$(rv); } @@ -1639,7 +1638,7 @@ class Deriver_RustcEncodable: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); rv.add_function(false, false, "encode", mv$(fcn)); return mv$(rv); } @@ -1866,7 +1865,7 @@ class Deriver_RustcDecodable: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); - AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type ) ); + AST::Impl rv( AST::ImplDef( sp, AST::MetaItems(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); rv.add_function(false, false, "decode", mv$(fcn)); return mv$(rv); } 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<ExprNodeP> 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: <Foo>::BAR is actually `<Foo as _>::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(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<AST::Item> { mv$(name), mv$(i), is_public } );
@@ -1464,7 +1464,7 @@ void Parse_Use(TokenStream& lex, ::std::function<void(AST::UseStmt, ::std::strin GET_CHECK_TOK(tok, lex, TOK_EQUAL);
AST::Expr val = Parse_Expr(lex);
GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);
- item_data = ::AST::Item( ::AST::Static(AST::Static::CONST, type, val) );
+ item_data = ::AST::Item( ::AST::Static(AST::Static::CONST, mv$(type), mv$(val)) );
break; }
case TOK_RWORD_UNSAFE:
GET_CHECK_TOK(tok, lex, TOK_RWORD_FN);
@@ -1501,7 +1501,7 @@ void Parse_Use(TokenStream& lex, ::std::function<void(AST::UseStmt, ::std::strin AST::Expr val = Parse_Expr(lex);
GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);
- item_data = ::AST::Item( ::AST::Static( (is_mut ? AST::Static::MUT : AST::Static::STATIC), type, val) );
+ item_data = ::AST::Item( ::AST::Static( (is_mut ? AST::Static::MUT : AST::Static::STATIC), mv$(type), mv$(val)) );
break; }
// `unsafe fn`
diff --git a/src/parse/token.cpp b/src/parse/token.cpp index 37515a2e..05ded69f 100644 --- a/src/parse/token.cpp +++ b/src/parse/token.cpp @@ -71,7 +71,7 @@ Token::Token(const InterpolatedFragment& frag) case InterpolatedFragment::TT: throw ""; case InterpolatedFragment::TYPE: m_type = TOK_INTERPOLATED_TYPE; - m_data = new TypeRef( *reinterpret_cast<const TypeRef*>(frag.m_ptr) ); + m_data = new TypeRef( reinterpret_cast<const TypeRef*>(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<TypeRef*>(e) ); + rv.m_data = new TypeRef( reinterpret_cast<TypeRef*>(e)->clone() ); break; case TOK_INTERPOLATED_PATTERN: rv.m_data = new AST::Pattern( reinterpret_cast<AST::Pattern*>(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))); } } } diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index 7fe7d6c6..34f217a8 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -379,7 +379,7 @@ struct Context (ConcreteSelf, DEBUG("- ConcreteSelf"); if( ( mode == LookupMode::Type || mode == LookupMode::Namespace ) && name == "Self" ) { - return ::AST::Path( ::AST::Path::TagUfcs(), *e, ::AST::Path(), ::std::vector< ::AST::PathNode>() ); + return ::AST::Path( ::AST::Path::TagUfcs(), e->clone(), ::AST::Path(), ::std::vector< ::AST::PathNode>() ); } ), (VarBlock, @@ -657,8 +657,8 @@ namespace { } AST::Path split_replace_into_ufcs_path(const Span& sp, AST::Path path, unsigned int i, const AST::Path& ty_path_tpl) { - const auto& path_abs = path.m_class.as_Absolute(); - const auto& n = path_abs.nodes[i]; + auto& path_abs = path.m_class.as_Absolute(); + auto& n = path_abs.nodes[i]; auto type_path = ::AST::Path(ty_path_tpl); if( ! n.args().is_empty() ) { @@ -785,12 +785,12 @@ namespace { void Resolve_Absolute_Path_BindAbsolute__hir_from(Context& context, const Span& sp, Context::LookupMode& mode, ::AST::Path& path, const AST::ExternCrate& crate, unsigned int start) { TRACE_FUNCTION_FR(path << " start=" << start, path); - const auto& path_abs = path.m_class.as_Absolute(); + auto& path_abs = path.m_class.as_Absolute(); const ::HIR::Module* hmod = &crate.m_hir->m_root_module; for(unsigned int i = start; i < path_abs.nodes.size() - 1; i ++ ) { - const auto& n = path_abs.nodes[i]; + auto& n = path_abs.nodes[i]; auto it = hmod->m_mod_items.find(n.name()); if( it == hmod->m_mod_items.end() ) ERROR(sp, E0000, "Couldn't find path component '" << n.name() << "' of " << path); @@ -1016,7 +1016,7 @@ namespace { void Resolve_Absolute_Path_BindAbsolute(Context& context, const Span& sp, Context::LookupMode& mode, ::AST::Path& path) { TRACE_FUNCTION_FR("path = " << path, path); - const auto& path_abs = path.m_class.as_Absolute(); + auto& path_abs = path.m_class.as_Absolute(); if( path_abs.crate != "" ) { // TODO: Handle items from other crates (back-converting HIR paths) @@ -1028,7 +1028,7 @@ void Resolve_Absolute_Path_BindAbsolute(Context& context, const Span& sp, Contex const ::AST::Module* mod = &context.m_crate.m_root_module; for(unsigned int i = 0; i < path_abs.nodes.size() - 1; i ++ ) { - const auto& n = path_abs.nodes[i]; + auto& n = path_abs.nodes[i]; if( n.name()[0] == '#' ) { if( ! n.args().is_empty() ) { |