aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-07-26 22:16:21 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-07-27 12:32:25 +0100
commitb176f389161bbe30237ff29063697f8e0ccaa513 (patch)
treeb8d6da12bb614669c11d0b3a6b91bfb7c518ab1d /gcc
parentdefe97ea4dfd5d0e77ec2a8401c987772d96884f (diff)
downloadgcc-b176f389161bbe30237ff29063697f8e0ccaa513.zip
gcc-b176f389161bbe30237ff29063697f8e0ccaa513.tar.gz
gcc-b176f389161bbe30237ff29063697f8e0ccaa513.tar.bz2
Add flags for FnType FNTYPE_IS_METHOD_FLAG FNTYPE_IS_EXTERN_FLAG
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-implitem.h105
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-toplevel.h14
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc2
-rw-r--r--gcc/rust/typecheck/rust-tyty.h20
4 files changed, 125 insertions, 16 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h
index 5f6fcd9..02e5ef1 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h
@@ -28,6 +28,101 @@
namespace Rust {
namespace Resolver {
+class TypeCheckTopLevelExternItem : public TypeCheckBase
+{
+ using Rust::Resolver::TypeCheckBase::visit;
+
+public:
+ static void Resolve (HIR::ExternalItem *item)
+ {
+ TypeCheckTopLevelExternItem resolver;
+ item->accept_vis (resolver);
+ }
+
+ void visit (HIR::ExternalStaticItem &item) override
+ {
+ TyTy::BaseType *actual_type
+ = TypeCheckType::Resolve (item.get_item_type ().get ());
+
+ context->insert_type (item.get_mappings (), actual_type);
+ }
+
+ void visit (HIR::ExternalFunctionItem &function) override
+ {
+ std::vector<TyTy::SubstitutionParamMapping> substitutions;
+ if (function.has_generics ())
+ {
+ for (auto &generic_param : function.get_generic_params ())
+ {
+ switch (generic_param.get ()->get_kind ())
+ {
+ case HIR::GenericParam::GenericKind::LIFETIME:
+ // Skipping Lifetime completely until better handling.
+ break;
+
+ case HIR::GenericParam::GenericKind::TYPE: {
+ auto param_type
+ = TypeResolveGenericParam::Resolve (generic_param.get ());
+ context->insert_type (generic_param->get_mappings (),
+ param_type);
+
+ substitutions.push_back (TyTy::SubstitutionParamMapping (
+ static_cast<HIR::TypeParam &> (*generic_param),
+ param_type));
+ }
+ break;
+ }
+ }
+ }
+
+ TyTy::BaseType *ret_type = nullptr;
+ if (!function.has_return_type ())
+ ret_type = new TyTy::TupleType (function.get_mappings ().get_hirid ());
+ else
+ {
+ auto resolved
+ = TypeCheckType::Resolve (function.get_return_type ().get ());
+ if (resolved == nullptr)
+ {
+ rust_error_at (function.get_locus (),
+ "failed to resolve return type");
+ return;
+ }
+
+ ret_type = resolved->clone ();
+ ret_type->set_ref (
+ function.get_return_type ()->get_mappings ().get_hirid ());
+ }
+
+ std::vector<std::pair<HIR::Pattern *, TyTy::BaseType *> > params;
+ for (auto &param : function.get_function_params ())
+ {
+ // get the name as well required for later on
+ auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ());
+
+ HIR::IdentifierPattern *param_pattern = new HIR::IdentifierPattern (
+ param.get_param_name (), Location (), false, false,
+ std::unique_ptr<HIR::Pattern> (nullptr));
+
+ params.push_back (
+ std::pair<HIR::Pattern *, TyTy::BaseType *> (param_pattern,
+ param_tyty));
+
+ context->insert_type (param.get_mappings (), param_tyty);
+ }
+
+ auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (),
+ function.get_mappings ().get_defid (),
+ function.get_item_name (),
+ FNTYPE_IS_EXTERN_FLAG, std::move (params),
+ ret_type, std::move (substitutions));
+ context->insert_type (function.get_mappings (), fnType);
+ }
+
+private:
+ TypeCheckTopLevelExternItem () : TypeCheckBase () {}
+};
+
class TypeCheckTopLevelImplItem : public TypeCheckBase
{
using Rust::Resolver::TypeCheckBase::visit;
@@ -134,11 +229,11 @@ public:
context->insert_type (param.get_mappings (), param_tyty);
}
- auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (),
- function.get_mappings ().get_defid (),
- function.get_function_name (),
- function.is_method (), std::move (params),
- ret_type, std::move (substitutions));
+ auto fnType = new TyTy::FnType (
+ function.get_mappings ().get_hirid (),
+ function.get_mappings ().get_defid (), function.get_function_name (),
+ function.is_method () ? FNTYPE_IS_METHOD_FLAG : FNTYPE_DEFAULT_FLAGS,
+ std::move (params), ret_type, std::move (substitutions));
context->insert_type (function.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 dd3dd75..18f3e72 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h
@@ -230,9 +230,9 @@ public:
auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (),
function.get_mappings ().get_defid (),
- function.get_function_name (), false,
- std::move (params), ret_type,
- std::move (substitutions));
+ function.get_function_name (),
+ FNTYPE_DEFAULT_FLAGS, std::move (params),
+ ret_type, std::move (substitutions));
context->insert_type (function.get_mappings (), fnType);
}
@@ -274,6 +274,14 @@ public:
substitutions);
}
+ void visit (HIR::ExternBlock &extern_block) override
+ {
+ for (auto &item : extern_block.get_extern_items ())
+ {
+ TypeCheckTopLevelExternItem::Resolve (item.get ());
+ }
+ }
+
private:
TypeCheckTopLevel () : TypeCheckBase () {}
};
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index bb5d6c0..64587da 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -816,7 +816,7 @@ FnType::clone ()
std::pair<HIR::Pattern *, BaseType *> (p.first, p.second->clone ()));
return new FnType (get_ref (), get_ty_ref (), get_id (), get_identifier (),
- is_method_flag, std::move (cloned_params),
+ flags, std::move (cloned_params),
get_return_type ()->clone (), clone_substs (),
get_combined_refs ());
}
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index cecf69a..0a087df 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -970,14 +970,18 @@ private:
class FnType : public BaseType, public SubstitutionRef
{
public:
- FnType (HirId ref, DefId id, std::string identifier, bool is_method,
+#define FNTYPE_DEFAULT_FLAGS 0x00
+#define FNTYPE_IS_METHOD_FLAG 0x01
+#define FNTYPE_IS_EXTERN_FLAG 0x02
+
+ FnType (HirId ref, DefId id, std::string identifier, uint8_t flags,
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), is_method_flag (is_method),
+ params (std::move (params)), type (type), flags (flags),
identifier (identifier), id (id)
{
LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK;
@@ -985,15 +989,15 @@ public:
}
FnType (HirId ref, HirId ty_ref, DefId id, std::string identifier,
- bool is_method,
+ uint8_t flags,
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), is_method_flag (is_method),
- identifier (identifier), id (id)
+ params (params), type (type), flags (flags), identifier (identifier),
+ id (id)
{
LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK;
rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
@@ -1022,9 +1026,11 @@ public:
if (num_params () == 0)
return false;
- return is_method_flag;
+ return (flags & FNTYPE_IS_METHOD_FLAG) != 0;
}
+ bool is_extern () const { return (flags & FNTYPE_IS_EXTERN_FLAG) != 0; }
+
DefId get_id () const { return id; }
// get the Self type for the method
@@ -1077,7 +1083,7 @@ public:
private:
std::vector<std::pair<HIR::Pattern *, BaseType *> > params;
BaseType *type;
- bool is_method_flag;
+ uint8_t flags;
std::string identifier;
DefId id;
};