diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-02-16 15:40:28 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-03-01 10:35:07 +0000 |
commit | 9af2ae0ff91535da104db0d3828d863770439fad (patch) | |
tree | 57b375ba818f22c70066c87a4d9c2a1c1b78f69e /gcc/rust/resolve/rust-ast-resolve.cc | |
parent | 06bb1d6542a9d07f4d866613a5b039be7bcb5f95 (diff) | |
download | gcc-9af2ae0ff91535da104db0d3828d863770439fad.zip gcc-9af2ae0ff91535da104db0d3828d863770439fad.tar.gz gcc-9af2ae0ff91535da104db0d3828d863770439fad.tar.bz2 |
Support Generic arguments to Structs
This removes StructFieldType from the TyTy base as it is not a type that
can be unified against.
It adds in a substition mapper implementation which will likely change
over time when this this support is extended over to Functions and
TupleStructs.
Note generic argument binding is not supported as part of this yet.
Fixes #235
Diffstat (limited to 'gcc/rust/resolve/rust-ast-resolve.cc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve.cc | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index ddba7f2..6bc356a 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -368,5 +368,103 @@ ResolveStructExprField::visit (AST::StructExprFieldIdentifier &field) ResolveExpr::go (&expr, field.get_node_id ()); } +// rust-ast-resolve-type.h + +void +ResolveTypePath::visit (AST::TypePathSegmentGeneric &seg) +{ + AST::GenericArgs &generics = seg.get_generic_args (); + for (auto > : generics.get_type_args ()) + ResolveType::go (gt.get (), UNKNOWN_NODEID); + + if (seg.is_error ()) + { + type_seg_failed_flag = true; + rust_error_at (Location (), "segment has error: %s", + seg.as_string ().c_str ()); + return; + } + + if (seg.get_separating_scope_resolution ()) + path_buffer += "::"; + + path_buffer += seg.get_ident_segment ().as_string (); +} + +void +ResolveTypePath::visit (AST::TypePathSegment &seg) +{ + if (seg.is_error ()) + { + type_seg_failed_flag = true; + rust_error_at (Location (), "segment has error: %s", + seg.as_string ().c_str ()); + return; + } + + if (seg.get_separating_scope_resolution ()) + path_buffer += "::"; + + path_buffer += seg.get_ident_segment ().as_string (); +} + +// rust-ast-resolve-expr.h + +void +ResolvePath::resolve_path (AST::PathInExpression *expr) +{ + // this needs extended similar to the TypePath to lookup each segment + // in turn then look its rib for the next segment and so forth until we + // resolve to a final NodeId generic args can be ignored + std::string path_buf; + for (auto &seg : expr->get_segments ()) + { + auto s = seg.get_ident_segment (); + if (s.is_error () && !seg.has_generic_args ()) + { + rust_error_at (expr->get_locus (), "malformed path"); + return; + } + + if (seg.has_generic_args ()) + { + AST::GenericArgs &args = seg.get_generic_args (); + for (auto > : args.get_type_args ()) + ResolveType::go (gt.get (), UNKNOWN_NODEID); + } + + if (!s.is_error ()) + { + bool needs_sep = !path_buf.empty (); + if (needs_sep) + path_buf += "::"; + + path_buf += s.as_string (); + } + } + + // name scope first + if (resolver->get_name_scope ().lookup (path_buf, &resolved_node)) + { + resolver->insert_resolved_name (expr->get_node_id (), resolved_node); + resolver->insert_new_definition (expr->get_node_id (), + Definition{expr->get_node_id (), + parent}); + } + // check the type scope + else if (resolver->get_type_scope ().lookup (path_buf, &resolved_node)) + { + resolver->insert_resolved_type (expr->get_node_id (), resolved_node); + resolver->insert_new_definition (expr->get_node_id (), + Definition{expr->get_node_id (), + parent}); + } + else + { + rust_error_at (expr->get_locus (), "unknown path %s", + expr->as_string ().c_str (), path_buf.c_str ()); + } +} + } // namespace Resolver } // namespace Rust |