aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-01-24 18:38:58 +0000
committerPhilip Herron <philip.herron@embecosm.com>2022-01-24 18:42:24 +0000
commitc8a0c6eb4b9ea3779f01418cfc97a6761ca4a957 (patch)
tree5c10c91f085cbe16316fd5dff0a611bbd40a0610 /gcc/rust/backend/rust-compile-expr.h
parent3de87e620f8714278c273ec91dc6ec22347c188c (diff)
downloadgcc-c8a0c6eb4b9ea3779f01418cfc97a6761ca4a957.zip
gcc-c8a0c6eb4b9ea3779f01418cfc97a6761ca4a957.tar.gz
gcc-c8a0c6eb4b9ea3779f01418cfc97a6761ca4a957.tar.bz2
Remove hack to handle forward declared items
We used to use a compile_fns flag as a method to handle the case of code such as: ```rust fn foo() { bar() } fn bar() { } ``` The compile_fns flag when set to false would allow us to do a toplevel scan to compile the initial fndecl prototype of the functions as a method of handling the case of the call to bar() within the body of foo. The backend is setup now that we can 'query_compile' by compiling the item as required with a cache if we have already done so.
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h105
1 files changed, 1 insertions, 104 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 5464c88..4cc4dfc 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -127,110 +127,7 @@ public:
void visit (HIR::MethodCallExpr &expr) override;
- void visit (HIR::IdentifierExpr &expr) override
- {
- NodeId ast_node_id = expr.get_mappings ().get_nodeid ();
-
- bool is_value = false;
- NodeId ref_node_id = UNKNOWN_NODEID;
- if (ctx->get_resolver ()->lookup_resolved_name (ast_node_id, &ref_node_id))
- {
- // these ref_node_ids will resolve to a pattern declaration but we are
- // interested in the definition that this refers to get the parent id
- 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;
- is_value = true;
- }
- else if (!ctx->get_resolver ()->lookup_resolved_type (ast_node_id,
- &ref_node_id))
- {
- rust_error_at (expr.get_locus (),
- "Failed to lookup type reference for node: %s",
- expr.as_string ().c_str ());
- return;
- }
-
- if (ref_node_id == UNKNOWN_NODEID)
- {
- rust_fatal_error (expr.get_locus (), "unresolved IdentifierExpr: %s",
- expr.as_string ().c_str ());
- return;
- }
-
- // node back to HIR
- 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");
- return;
- }
-
- TyTy::BaseType *lookup = nullptr;
- if (!ctx->get_tyctx ()->lookup_type (ref, &lookup))
- {
- rust_fatal_error (expr.get_locus (),
- "failed to find type relevant to this context: %s",
- expr.get_mappings ().as_string ().c_str ());
- return;
- }
-
- bool is_type_ref = !is_value;
- if (is_type_ref)
- {
- // this might be a case for
- //
- // struct S;
- //
- // fn main() {
- // let s = S;
- // }
-
- if (lookup->is_unit ())
- {
- translated = ctx->get_backend ()->unit_expression ();
- return;
- }
-
- // rust actually treats like this an fn call or structs with fields but
- // unit structs are just the struct name lets catch it with an is-unit
- // check
- gcc_unreachable ();
- }
-
- tree fn = NULL_TREE;
- Bvariable *var = nullptr;
- if (ctx->lookup_const_decl (ref, &translated))
- {
- return;
- }
- else if (ctx->lookup_function_decl (ref, &fn))
- {
- translated
- = ctx->get_backend ()->function_code_expression (fn,
- expr.get_locus ());
- }
- else if (ctx->lookup_var_decl (ref, &var))
- {
- translated
- = ctx->get_backend ()->var_expression (var, expr.get_locus ());
- }
- else if (ctx->lookup_pattern_binding (ref, &translated))
- {
- return;
- }
- else
- {
- rust_fatal_error (expr.get_locus (),
- "failed to lookup compiled reference");
- }
- }
+ void visit (HIR::IdentifierExpr &expr) override;
void visit (HIR::LiteralExpr &expr) override
{