diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-07-28 21:06:54 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-08-05 18:19:26 +0100 |
commit | 874b783748d06cdcd199df3b68777a928a8f2158 (patch) | |
tree | cbc69e94c889c031bfedbbb39ffbadbf34af4c5a /gcc | |
parent | 443d4d1f7cf6aa1570670e728b0cb59aada0e10f (diff) | |
download | gcc-874b783748d06cdcd199df3b68777a928a8f2158.zip gcc-874b783748d06cdcd199df3b68777a928a8f2158.tar.gz gcc-874b783748d06cdcd199df3b68777a928a8f2158.tar.bz2 |
Add type bound name resolution
Resolve the type-bound to the trait.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h index d826d68..46ebdc4 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -297,6 +297,42 @@ private: bool ok; }; +class ResolveTypeBound : public ResolverBase +{ + using Rust::Resolver::ResolverBase::visit; + +public: + static NodeId go (AST::TypeParamBound *type, NodeId parent, + bool canonicalize_type_with_generics = false) + { + ResolveTypeBound resolver (parent, canonicalize_type_with_generics); + type->accept_vis (resolver); + if (!resolver.ok) + rust_error_at (type->get_locus_slow (), "unresolved type bound"); + + return resolver.resolved_node; + }; + + void visit (AST::TraitBound &bound) override + { + resolved_node = ResolveType::go (&bound.get_type_path (), parent, + canonicalize_type_with_generics); + ok = resolved_node != UNKNOWN_NODEID; + } + + void visit (AST::Lifetime &bound) override { ok = true; } + +private: + ResolveTypeBound (NodeId parent, bool canonicalize_type_with_generics) + : ResolverBase (parent), + canonicalize_type_with_generics (canonicalize_type_with_generics), + ok (false) + {} + + bool canonicalize_type_with_generics; + bool ok; +}; + class ResolveGenericParam : public ResolverBase { using Rust::Resolver::ResolverBase::visit; @@ -326,6 +362,14 @@ public: if (param.has_type ()) ResolveType::go (param.get_type ().get (), param.get_node_id ()); + if (param.has_type_param_bounds ()) + { + for (auto &bound : param.get_type_param_bounds ()) + { + ResolveTypeBound::go (bound.get (), param.get_node_id ()); + } + } + // for now lets focus on handling the basics: like struct<T> { a:T, ....} resolver->get_type_scope ().insert ( CanonicalPath::new_seg (param.get_node_id (), |