Fix bug with finding function calls
Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
parent
a966ff45a3
commit
a372c4420a
@ -15,16 +15,20 @@ StructType :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Type :: struct {
|
Type :: struct {
|
||||||
kind: TypeKind,
|
kind: TypeKind,
|
||||||
bit_size: u8,
|
bit_size: u8,
|
||||||
is_signed: bool,
|
is_signed: bool,
|
||||||
pointer_to: ^Type,
|
pointer_to: ^Type,
|
||||||
array_of: ^Type,
|
array_of: ^Type,
|
||||||
array_size: u64,
|
array_size: u64,
|
||||||
struct_type: ^StructType,
|
struct_index: u64,
|
||||||
|
struct_type: ^StructType,
|
||||||
}
|
}
|
||||||
|
|
||||||
type_to_string :: proc(type: ^Type) -> string {
|
type_to_string :: proc(type: ^Type) -> string {
|
||||||
|
if type == nil {
|
||||||
|
return "nil (shouldnt happen lol)"
|
||||||
|
}
|
||||||
if type.kind == .Integer {
|
if type.kind == .Integer {
|
||||||
if type.is_signed {
|
if type.is_signed {
|
||||||
return fmt.aprintf("i{}", type.bit_size)
|
return fmt.aprintf("i{}", type.bit_size)
|
||||||
|
@ -278,10 +278,12 @@ type_check :: proc(ast: ^Node, parent_ast: ^Node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
found_field := false
|
found_field := false
|
||||||
for &field in struct_.fields {
|
struct_index: u64 = 0
|
||||||
|
for &field, i in struct_.fields {
|
||||||
if compare_dyn_arrs(&field.name, &rhs.value.([dynamic]u8)) {
|
if compare_dyn_arrs(&field.name, &rhs.value.([dynamic]u8)) {
|
||||||
ast.return_type = field.type
|
ast.return_type = field.type
|
||||||
found_field = true
|
found_field = true
|
||||||
|
struct_index = u64(i)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,6 +300,8 @@ type_check :: proc(ast: ^Node, parent_ast: ^Node) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ast.return_type.struct_index = struct_index
|
||||||
|
|
||||||
case .FunctionCall:
|
case .FunctionCall:
|
||||||
if ast.children[0].kind == .FieldAccess {
|
if ast.children[0].kind == .FieldAccess {
|
||||||
// FIXME: This is some temporary shitfuckery, check if a function is part
|
// FIXME: This is some temporary shitfuckery, check if a function is part
|
||||||
@ -389,11 +393,12 @@ type_check :: proc(ast: ^Node, parent_ast: ^Node) {
|
|||||||
} else {
|
} else {
|
||||||
ast.kind = .FunctionCall
|
ast.kind = .FunctionCall
|
||||||
append(&ast.children, node_create_value(.Identifier, ast.range, ast.value))
|
append(&ast.children, node_create_value(.Identifier, ast.range, ast.value))
|
||||||
ast.value = nil
|
|
||||||
ast.return_type = fn.return_type
|
ast.return_type = fn.return_type
|
||||||
|
ast.value = nil
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ast.return_type = type
|
||||||
}
|
}
|
||||||
ast.return_type = type
|
|
||||||
case .BinaryExpression:
|
case .BinaryExpression:
|
||||||
type_check(ast.children[0], ast)
|
type_check(ast.children[0], ast)
|
||||||
type_check(ast.children[1], ast)
|
type_check(ast.children[1], ast)
|
||||||
@ -446,6 +451,15 @@ type_check :: proc(ast: ^Node, parent_ast: ^Node) {
|
|||||||
case .UnaryExpression:
|
case .UnaryExpression:
|
||||||
// FIXME: Verify that the operation is possible
|
// FIXME: Verify that the operation is possible
|
||||||
type_check(ast.children[0], ast)
|
type_check(ast.children[0], ast)
|
||||||
|
append(
|
||||||
|
&g_message_list,
|
||||||
|
message_create(
|
||||||
|
.FIXME,
|
||||||
|
fmt.aprintf("Check type before setting return type in unary expression"),
|
||||||
|
ast.range,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
ast.return_type = ast.children[0].return_type
|
||||||
case .Ret:
|
case .Ret:
|
||||||
function_return_type := scope_function_return_type_lookup()
|
function_return_type := scope_function_return_type_lookup()
|
||||||
if function_return_type == nil {
|
if function_return_type == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user