aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-04-28 01:04:58 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2021-04-28 01:04:58 +0200
commitab77d1bf51541b745388fce1df64f62fea664906 (patch)
treef4db5cf948c7c09c913ea149b20f4f0f30be468b /src
parent4a7b6a78eb3f3cdec003dfd6d0495c313eb4d925 (diff)
start working on the procedure overloading
Diffstat (limited to 'src')
-rw-r--r--src/common/ast.odin19
-rw-r--r--src/index/collector.odin15
-rw-r--r--src/server/analysis.odin92
3 files changed, 86 insertions, 40 deletions
diff --git a/src/common/ast.odin b/src/common/ast.odin
index 27484c7..92a5769 100644
--- a/src/common/ast.odin
+++ b/src/common/ast.odin
@@ -4,6 +4,7 @@ import "core:odin/ast"
import "core:log"
import "core:mem"
import "core:fmt"
+import "core:strings"
keyword_map: map[string]bool = {
"int" = true,
@@ -143,6 +144,24 @@ get_ast_node_string :: proc(node: ^ast.Node, src: []byte) -> string {
return string(src[node.pos.offset:node.end.offset]);
}
+get_doc :: proc(comment: ^ast.Comment_Group, allocator: mem.Allocator) -> string {
+
+ if comment != nil {
+ tmp: string;
+
+ for doc in comment.list {
+ tmp = strings.concatenate({tmp, "\n", doc.text}, context.temp_allocator);
+ }
+
+ if tmp != "" {
+ replaced, allocated := strings.replace_all(tmp, "//", "", context.temp_allocator);
+ return strings.clone(replaced, allocator);
+ }
+ }
+
+ return "";
+}
+
free_ast :: proc{
free_ast_node,
free_ast_array,
diff --git a/src/index/collector.odin b/src/index/collector.odin
index 65876fc..44c439b 100644
--- a/src/index/collector.odin
+++ b/src/index/collector.odin
@@ -384,6 +384,7 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
symbol.name = get_index_unique_string(collection, name);
symbol.pkg = get_index_unique_string(collection, directory);
symbol.type = token_type;
+ symbol.doc = common.get_doc(expr.docs, collection.allocator);
when ODIN_OS == "windows" {
symbol.uri = get_index_unique_string(collection, strings.to_lower(uri, context.temp_allocator));
@@ -391,20 +392,6 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
symbol.uri = get_index_unique_string(collection, uri);
}
- if expr.docs != nil {
-
- tmp: string;
-
- for doc in expr.docs.list {
- tmp = strings.concatenate({tmp, "\n", doc.text}, context.temp_allocator);
- }
-
- if tmp != "" {
- replaced, allocated := strings.replace_all(tmp, "//", "", context.temp_allocator);
- symbol.doc = strings.clone(replaced, collection.allocator);
- }
- }
-
cat := strings.concatenate({symbol.pkg, name}, context.temp_allocator);
id := get_symbol_id(cat);
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 27c4882..c29b816 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -13,6 +13,7 @@ import "core:path/filepath"
import "core:sort"
import "core:slice"
import "core:unicode/utf8"
+import "core:reflect"
import "shared:common"
import "shared:index"
@@ -82,7 +83,6 @@ AstContext :: struct {
value_decl: ^ast.Value_Decl,
field_name: string,
uri: string,
-
}
make_ast_context :: proc(file: ast.File, imports: []Package, package_name: string, uri: string, allocator := context.temp_allocator) -> AstContext {
@@ -449,6 +449,29 @@ resolve_generic_function_ast :: proc(ast_context: ^AstContext, proc_lit: ast.Pro
return resolve_generic_function_symbol(ast_context, proc_lit.type.params.list, proc_lit.type.results.list);
}
+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);
+
+ if a_id != b_id {
+ return false;
+ }
+
+ if a.pointers != b.pointers {
+ return false;
+ }
+
+ /*
+ switch s in a.value {
+ case index.SymbolBasicValue:
+
+ }
+ */
+
+ return true;
+}
+
/*
Figure out which function the call expression is using out of the list from proc group
*/
@@ -476,26 +499,35 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou
for arg, i in call_expr.args {
- if eval_call_expr, ok := resolve_type_expression(ast_context, arg); ok {
+ call_symbol: index.Symbol;
+ arg_symbol: index.Symbol;
+ ok: bool;
- #partial switch v in eval_call_expr.value {
- case index.SymbolProcedureValue:
- /*
- case index.SymbolGenericValue:
- if !common.node_equal(v.expr, procedure.arg_types[i].type) {
- break next_fn;
- }
- */
- case index.SymbolStructValue:
- }
- } else {
- return index.Symbol {}, false;
+ if _, ok = arg.derived.(ast.Bad_Expr); ok {
+ continue;
}
+
+ call_symbol, ok = resolve_type_expression(ast_context, arg);
+
+ if !ok {
+ fmt.println("call_symbol failed");
+ break next_fn;
+ }
+
+ arg_symbol, ok = resolve_type_expression(ast_context, procedure.arg_types[i].type);
+
+ if !ok {
+ fmt.println("arg_symbol failed");
+ break next_fn;
+ }
+
+ if !is_symbol_same_typed(ast_context, call_symbol, arg_symbol) {
+ break next_fn;
+ }
+
}
append(&candidates, f);
-
- return f, true;
}
}
}
@@ -772,7 +804,6 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i
case Call_Expr:
return resolve_type_expression(ast_context, local);
case:
- log.warnf("default type node kind: %T", v);
return resolve_type_expression(ast_context, local);
}
} else if global, ok := ast_context.globals[node.name]; ast_context.use_globals && ok {
@@ -2060,17 +2091,26 @@ get_signature_information :: proc(document: ^Document, position: common.Position
call: index.Symbol;
call, ok = resolve_type_expression(&ast_context, position_context.call);
- if symbol, ok := call.value.(index.SymbolProcedureValue); !ok {
- return signature_help, true;
- }
+ signature_information := make([dynamic]SignatureInformation, 1, context.temp_allocator);
- signature_information := make([]SignatureInformation, 1, context.temp_allocator);
-
- signature_information[0].label = concatenate_symbols_information(&ast_context, call, false);
- signature_information[0].documentation = call.doc;
+ if _, ok := call.value.(index.SymbolProcedureValue); ok {
+ info := SignatureInformation {
+ label = concatenate_symbols_information(&ast_context, call, false),
+ documentation = call.doc,
+ };
+ append(&signature_information, info);
+ } else if value, ok := call.value.(index.SymbolAggregateValue); ok {
+ for symbol in value.symbols {
+ info := SignatureInformation {
+ label = concatenate_symbols_information(&ast_context, symbol, false),
+ documentation = symbol.doc,
+ };
+ append(&signature_information, info);
+ }
+ }
- signature_help.signatures = signature_information;
- signature_help.activeSignature = 0;
+ signature_help.signatures = signature_information[:];
+ signature_help.activeSignature = len(signature_information);
signature_help.activeParameter = 0;
return signature_help, true;