Skip to content

Commit

Permalink
compiler: Fix type evaluation of the expression: "std.size_of(self)"
Browse files Browse the repository at this point in the history
DCO-1.1-Signed-off-by: Ellie <[email protected]>
  • Loading branch information
ell1e committed Aug 23, 2024
1 parent 8b3cecd commit 3ca9d2c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
47 changes: 46 additions & 1 deletion src/compiler/moose64/ast/analyze/analyze.h64
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 =
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/storage/scope/scope.h64
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion src/compiler/typeinfo/typeinfo.h64
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 3ca9d2c

Please sign in to comment.