From 3ca9d2c45cbebe6b828c3724a96b89c4ca2d82f2 Mon Sep 17 00:00:00 2001 From: ell1e Date: Sat, 24 Aug 2024 01:27:20 +0200 Subject: [PATCH] compiler: Fix type evaluation of the expression: "std.size_of(self)" DCO-1.1-Signed-off-by: Ellie --- src/compiler/moose64/ast/analyze/analyze.h64 | 47 +++++++++++++++++++- src/compiler/storage/scope/scope.h64 | 3 +- src/compiler/typeinfo/typeinfo.h64 | 4 +- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/compiler/moose64/ast/analyze/analyze.h64 b/src/compiler/moose64/ast/analyze/analyze.h64 index f0d16dc..4b1dbaa 100644 --- a/src/compiler/moose64/ast/analyze/analyze.h64 +++ b/src/compiler/moose64/ast/analyze/analyze.h64 @@ -90,6 +90,7 @@ func get_c_or_m64_type_of_sym_info( store_self_value_ref_for_funcs=no, msgs=none, debug=no ) { + const is_moose64 = yes var dbg_prefix = "" if debug { d_id = random.gen_id() @@ -151,6 +152,50 @@ func get_c_or_m64_type_of_sym_info( node_with_reference.ref.kind) { target_ref = node_with_reference.ref } + if target_ref == none and node_with_reference.ref != none and + node_with_reference.ref.kind == st_ref.ST_SELF and + node_with_reference_parents != none and + node_with_reference_parents.len >= 1 { + var owning_func_attr_node = none + var i = node_with_reference_parents.len + while i >= 1 { + if {ast.N_STMT_FUNC, ast.N_STMT_FUNCEXTEND}.has( + node_with_reference_parents[i].kind) { + owning_func_attr_node = + node_with_reference_parents[i] + break + } + i -= 1 + } + if debug { + var owning_func_attr_str = "none" + if owning_func_attr_node != none { + owning_func_attr_str = owning_func_attr_node.as_str() + + "..." + } + print(dbg_prefix + " Found self ref with " + "owning_func_attr_node=" + + owning_func_attr_str) + } + if owning_func_attr_node != none { + var anscope = project_file. + make_attr_names_scope_from_funcattr( + owning_func_attr_node, msgs=msg, + is_moose64=is_moose64, + def_project_file=project_file + ) + if debug { + print(dbg_prefix + " Found associated " + "anscope for self: anscope=" + + anscope.as_str()) + } + if anscope != none { + target_ref = new st_ref.StorageRef( + st_ref.ST_GLOBAL, anscope.storage_id + ) + } + } + } if target_ref != none { assert(target_ref == none or has_attr(target_ref, "kind")) assert(target_ref.kind != st_ref.ST_LOCAL) @@ -647,7 +692,7 @@ func _get_c_or_m64_type_of_node_do( return later none } var size_result = new typeinfo.TypeInfo( - TI_C_TYPE + typeinfo.TI_C_TYPE ) size_result.orig_type_name = "size" size_result.c_type_name = diff --git a/src/compiler/storage/scope/scope.h64 b/src/compiler/storage/scope/scope.h64 index e95b272..4187a98 100644 --- a/src/compiler/storage/scope/scope.h64 +++ b/src/compiler/storage/scope/scope.h64 @@ -72,7 +72,8 @@ func SymbolInfo.as_str { "storage_id=" + self.storage_id.as_str() + ", " "def_line=" + self.def_line.as_str() + ", " + - "def_col=" + self.def_col.as_str() + "}" + "def_col=" + self.def_col.as_str() + t += "}" return t } diff --git a/src/compiler/typeinfo/typeinfo.h64 b/src/compiler/typeinfo/typeinfo.h64 index 7a4fb56..155e1c8 100644 --- a/src/compiler/typeinfo/typeinfo.h64 +++ b/src/compiler/typeinfo/typeinfo.h64 @@ -46,7 +46,9 @@ extend func st_scope.SymbolInfo.as_str { var result = extended() assert(result.ends("}")) result = result.sub(1, result.len - 1) + ", " + - "typeref_expr=" + self.typeref_expr.as_str() + "typeref_expr=" + self.typeref_expr.as_str() + ", " + + "type_storage_ref=" + self.type_storage_ref.as_str() + "}" return result }