diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-05-10 12:16:26 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-05-10 12:21:11 +0100 |
commit | 4fa08ea79cd30a7d8dd9c781a6247806a0dfe581 (patch) | |
tree | 73f6069397b7c6e1f303946ff8acd007c0419cfa | |
parent | 4fd7b3c089191b720d9bc0cf6634fbc8c54450a4 (diff) | |
download | gcc-4fa08ea79cd30a7d8dd9c781a6247806a0dfe581.zip gcc-4fa08ea79cd30a7d8dd9c781a6247806a0dfe581.tar.gz gcc-4fa08ea79cd30a7d8dd9c781a6247806a0dfe581.tar.bz2 |
Add is method flag for FnTypes
This is a building block to support generic impl blocks with a generic
method. We need to adjust the Self type parameters to the turbo fish for
the method call expr.
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-implitem.h | 4 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-toplevel.h | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 6 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.h | 26 |
4 files changed, 28 insertions, 10 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h index 2a3e9f9..f961bba 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h @@ -112,7 +112,7 @@ public: } auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (), - std::move (params), ret_type, + false, std::move (params), ret_type, std::move (substitutions)); context->insert_type (function.get_mappings (), fnType); } @@ -189,7 +189,7 @@ public: context->insert_type (param.get_mappings (), param_tyty); } - auto fnType = new TyTy::FnType (method.get_mappings ().get_hirid (), + auto fnType = new TyTy::FnType (method.get_mappings ().get_hirid (), true, std::move (params), ret_type, std::move (substitutions)); context->insert_type (method.get_mappings (), fnType); diff --git a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h index 6be1552..ef940c1 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h +++ b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h @@ -229,7 +229,7 @@ public: } auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (), - std::move (params), ret_type, + false, std::move (params), ret_type, std::move (substitutions)); context->insert_type (function.get_mappings (), fnType); } diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index dcf9203..8c45573 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -687,9 +687,9 @@ FnType::clone () cloned_params.push_back ( std::pair<HIR::Pattern *, BaseType *> (p.first, p.second->clone ())); - return new FnType (get_ref (), get_ty_ref (), std::move (cloned_params), - get_return_type ()->clone (), clone_substs (), - get_combined_refs ()); + return new FnType (get_ref (), get_ty_ref (), is_method_flag, + std::move (cloned_params), get_return_type ()->clone (), + clone_substs (), get_combined_refs ()); } FnType * diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 442b23b..84f2a80 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -819,23 +819,24 @@ private: class FnType : public BaseType, public SubstitutionRef { public: - FnType (HirId ref, std::vector<std::pair<HIR::Pattern *, BaseType *> > params, + FnType (HirId ref, bool is_method, + std::vector<std::pair<HIR::Pattern *, BaseType *> > params, BaseType *type, std::vector<SubstitutionParamMapping> subst_refs, std::set<HirId> refs = std::set<HirId> ()) : BaseType (ref, ref, TypeKind::FNDEF, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), - params (std::move (params)), type (type) + params (std::move (params)), type (type), is_method_flag (is_method) {} - FnType (HirId ref, HirId ty_ref, + FnType (HirId ref, HirId ty_ref, bool is_method, std::vector<std::pair<HIR::Pattern *, BaseType *> > params, BaseType *type, std::vector<SubstitutionParamMapping> subst_refs, std::set<HirId> refs = std::set<HirId> ()) : BaseType (ref, ty_ref, TypeKind::FNDEF, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), - params (params), type (type) + params (params), type (type), is_method_flag (is_method) {} void accept_vis (TyVisitor &vis) override; @@ -851,6 +852,22 @@ public: size_t num_params () const { return params.size (); } + bool is_method () const + { + if (num_params () == 0) + return false; + + return is_method_flag; + } + + // get the Self type for the method + BaseType *get_self_type () const + { + rust_assert (is_method ()); + // FIXME this will need updated when we support coercion for & mut self etc + return get_params ().at (0).second; + } + std::vector<std::pair<HIR::Pattern *, BaseType *> > &get_params () { return params; @@ -893,6 +910,7 @@ public: private: std::vector<std::pair<HIR::Pattern *, BaseType *> > params; BaseType *type; + bool is_method_flag; }; class FnPtr : public BaseType |