From 03abe7eb95c17494149829cf16f2f28965ddeb74 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 24 Jan 2025 02:48:05 +0200 Subject: [PATCH] Store called function signature to AstCall --- compiler/ast.jou | 1 + compiler/build_cf_graph.jou | 13 +------------ .../typecheck/step3_function_and_method_bodies.jou | 2 ++ 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/compiler/ast.jou b/compiler/ast.jou index b3360896..b198f2cd 100644 --- a/compiler/ast.jou +++ b/compiler/ast.jou @@ -419,6 +419,7 @@ class AstCall: uses_arrow_operator: bool # distinguishes foo->bar() and foo.bar() nargs: int args: AstExpression* + called_signature: Signature* # populated in typecheck, NULL before typecheck runs, not owned def print(self) -> None: self->print_with_tree_printer(TreePrinter{}) diff --git a/compiler/build_cf_graph.jou b/compiler/build_cf_graph.jou index 6f79dd7c..16e3f7e0 100644 --- a/compiler/build_cf_graph.jou +++ b/compiler/build_cf_graph.jou @@ -483,18 +483,7 @@ class CfBuilder: location: Location, call: AstCall*, ) -> LocalVariable*: - sig: Signature* = NULL - - if call->method_call_self != NULL: - selfclass = call->method_call_self->types.orig_type - if call->uses_arrow_operator: - assert selfclass->kind == TypeKind.Pointer - selfclass = selfclass->value_type - assert selfclass->kind == TypeKind.Class - sig = selfclass->find_method(call->name) - else: - sig = self->filetypes->find_function(call->name) - + sig = call->called_signature assert sig != NULL ins = CfInstruction{ diff --git a/compiler/typecheck/step3_function_and_method_bodies.jou b/compiler/typecheck/step3_function_and_method_bodies.jou index eaa76712..890e6e51 100644 --- a/compiler/typecheck/step3_function_and_method_bodies.jou +++ b/compiler/typecheck/step3_function_and_method_bodies.jou @@ -596,6 +596,8 @@ def typecheck_function_or_method_call(state: State*, call: AstCall*, self_type: "class %s does not have a method named '%s'", self_type->name, call->name) fail(location, msg) + call->called_signature = sig + if self_type == NULL: function_or_method = "function" else: