aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-resolve-path.cc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-01-26 17:28:52 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-01-27 10:42:43 +0000
commit244c2d2ea1a5a69ab6f7f50902512c1a7daa29c9 (patch)
tree6e7cd01cd95637ad9606570e5ee92d549bd85594 /gcc/rust/backend/rust-compile-resolve-path.cc
parent8578c61be5061fab91fe679a15fd68ab5fad987c (diff)
downloadgcc-244c2d2ea1a5a69ab6f7f50902512c1a7daa29c9.zip
gcc-244c2d2ea1a5a69ab6f7f50902512c1a7daa29c9.tar.gz
gcc-244c2d2ea1a5a69ab6f7f50902512c1a7daa29c9.tar.bz2
Support binding functions to LetStmts.
This supports basic function pointers in rust most of the code was already there to infer this but this has now helped tidy it up and make it work. Fixes #184
Diffstat (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc')
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc32
1 files changed, 26 insertions, 6 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 37285b7..818d5cb 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -28,23 +28,43 @@ void
ResolvePathRef::visit (HIR::PathInExpression &expr)
{
// need to look up the reference for this identifier
- NodeId ref_node_id;
- if (!ctx->get_resolver ()->lookup_resolved_name (
+ NodeId ref_node_id = UNKNOWN_NODEID;
+ if (ctx->get_resolver ()->lookup_resolved_name (
expr.get_mappings ().get_nodeid (), &ref_node_id))
{
- return;
+ Resolver::Definition def;
+ if (!ctx->get_resolver ()->lookup_definition (ref_node_id, &def))
+ {
+ rust_error_at (expr.get_locus (),
+ "unknown reference for resolved name");
+ return;
+ }
+ ref_node_id = def.parent;
}
+ // this can fail because it might be a Constructor for something
+ // in that case the caller should attempt ResolvePathType::Compile
+ if (ref_node_id == UNKNOWN_NODEID)
+ return;
+
HirId ref;
if (!ctx->get_mappings ()->lookup_node_to_hir (
expr.get_mappings ().get_crate_num (), ref_node_id, &ref))
{
- rust_error_at (expr.get_locus (), "reverse lookup failure");
+ rust_error_at (expr.get_locus (), "reverse call path lookup failure");
return;
}
- // assumes paths are functions for now
- Bfunction *fn;
+ // this might be a variable reference or a function reference
+ Bvariable *var = nullptr;
+ if (ctx->lookup_var_decl (ref, &var))
+ {
+ resolved = ctx->get_backend ()->var_expression (var, expr.get_locus ());
+ return;
+ }
+
+ // must be a function call
+ Bfunction *fn = nullptr;
if (!ctx->lookup_function_decl (ref, &fn))
{
// this might fail because its a forward decl so we can attempt to