aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-04-28 14:08:49 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2021-04-28 14:08:49 +0200
commitbd4e3b3990593d10def18984101ae68f275eefea (patch)
tree75616fc8573854b4f0c518869f03bb7f7c97f001 /src
parentab77d1bf51541b745388fce1df64f62fea664906 (diff)
started on untyped proc overloading handling
Diffstat (limited to 'src')
-rw-r--r--src/common/ast.odin1
-rw-r--r--src/server/analysis.odin55
-rw-r--r--src/testing/testing.odin2
3 files changed, 49 insertions, 9 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);