diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2021-04-28 14:08:49 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2021-04-28 14:08:49 +0200 |
| commit | bd4e3b3990593d10def18984101ae68f275eefea (patch) | |
| tree | 75616fc8573854b4f0c518869f03bb7f7c97f001 | |
| parent | ab77d1bf51541b745388fce1df64f62fea664906 (diff) | |
started on untyped proc overloading handling
| -rw-r--r-- | src/common/ast.odin | 1 | ||||
| -rw-r--r-- | src/server/analysis.odin | 55 | ||||
| -rw-r--r-- | src/testing/testing.odin | 2 | ||||
| -rw-r--r-- | tests/signatures_test.odin | 30 |
4 files changed, 78 insertions, 10 deletions
diff --git a/src/common/ast.odin b/src/common/ast.odin index 92a5769..8a68783 100644 --- a/src/common/ast.odin +++ b/src/common/ast.odin @@ -10,6 +10,7 @@ keyword_map: map[string]bool = { "int" = true, "uint" = true, "string" = true, + "cstring" = true, "u64" = true, "f32" = true, "f64" = true, diff --git a/src/server/analysis.odin b/src/server/analysis.odin index c29b816..397d31f 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -451,8 +451,33 @@ resolve_generic_function_ast :: proc(ast_context: ^AstContext, proc_lit: ast.Pro is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol) -> bool { - a_id := reflect.union_variant_typeid(a); - b_id := reflect.union_variant_typeid(b); + //relying on the fact that a is the call argument to avoid checking both sides for untyped. + if untyped, ok := a.value.(index.SymbolUntypedValue); ok { + if basic, ok := b.value.(index.SymbolBasicValue); ok { + switch untyped.type { + case .Integer: + switch basic.ident.name { + case "int", "uint", "u32", "i32", "u8", "i8", "u64": return true; + case: return false; + } + case .Bool: + switch basic.ident.name { + case "bool": return true; + case: return false; + } + case .String: + switch basic.ident.name { + case "string", "cstring": return true; + case: return false; + } + case .Float: + } + } + } + + + a_id := reflect.union_variant_typeid(a.value); + b_id := reflect.union_variant_typeid(b.value); if a_id != b_id { return false; @@ -462,7 +487,7 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol) -> bo return false; } - /* + /* switch s in a.value { case index.SymbolBasicValue: @@ -851,14 +876,30 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i ident := index.new_type(Ident, node.pos, node.end, context.temp_allocator); ident.name = node.name; - symbol := index.Symbol { + symbol: index.Symbol; + + switch ident.name { + case "true", "false": + symbol = index.Symbol { + type = .Keyword, + signature = node.name, + pkg = ast_context.current_package, + value = index.SymbolUntypedValue { + type = .Bool, + }, + }; + case: + symbol = index.Symbol { type = .Keyword, signature = node.name, pkg = ast_context.current_package, value = index.SymbolBasicValue { ident = ident, - }, - }; + }, + }; + } + + return symbol, true; } else { //right now we replace the package ident with the absolute directory name, so it should have '/' which is not a valid ident character @@ -1402,14 +1443,12 @@ make_symbol_struct_from_ast :: proc(ast_context: ^AstContext, v: ast.Struct_Type resolve_poly_struct :: proc(ast_context: ^AstContext, v: ast.Struct_Type, symbol: ^index.Symbol) { if ast_context.call == nil { - log.infof("no call"); return; } symbol_value := &symbol.value.(index.SymbolStructValue); if symbol_value == nil { - log.infof("no value"); return; } diff --git a/src/testing/testing.odin b/src/testing/testing.odin index 9562bc4..001b8cf 100644 --- a/src/testing/testing.odin +++ b/src/testing/testing.odin @@ -35,7 +35,7 @@ setup :: proc(src: ^Source) { src.document.allocator = new(common.Scratch_Allocator); src.document.package_name = "test"; - common.scratch_allocator_init(src.document.allocator, mem.kilobytes(5), context.temp_allocator); + common.scratch_allocator_init(src.document.allocator, mem.kilobytes(20), context.temp_allocator); server.document_refresh(src.document, &src.config, nil); diff --git a/tests/signatures_test.odin b/tests/signatures_test.odin index 4d673fc..ccefc35 100644 --- a/tests/signatures_test.odin +++ b/tests/signatures_test.odin @@ -39,7 +39,7 @@ ast_simple_proc_signature :: proc(t: ^testing.T) { } @(test) -ast_proc_group_signature :: proc(t: ^testing.T) { +ast_proc_group_signature_empty_call :: proc(t: ^testing.T) { source := test.Source { main = `package test @@ -64,4 +64,32 @@ ast_proc_group_signature :: proc(t: ^testing.T) { }; test.expect_signature_labels(t, &source, {"test.int_function: proc(a: int)", "test.bool_function: proc(a: bool)"}); +} + +@(test) +ast_proc_group_signature_basic_types :: proc(t: ^testing.T) { + + source := test.Source { + main = `package test + int_function :: proc(a: int, b: bool, c: int) { + + } + + bool_function :: proc(a: bool, b: bool, c: bool) { + + } + + group_function :: proc { + int_function, + bool_function, + }; + + main :: proc() { + group_function(2, true, *) + } + `, + source_packages = {}, + }; + + test.expect_signature_labels(t, &source, {"test.int_function: proc(a: int, b: bool, c: int)"}); }
\ No newline at end of file |