aboutsummaryrefslogtreecommitdiff
path: root/src/index
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-03-04 12:17:00 +0100
committerDaniel Gavin <danielgavin5@hotmail.com>2022-03-04 12:17:00 +0100
commit58287455d64ab16091522bf8a358b079ef05daad (patch)
tree7b6655d6d34b5ad6d719523e4938b8002c43d8ab /src/index
parent63d0bd412a8817445d6dc18e79d5d54c94caf401 (diff)
strip colons and update ast to use unions
Diffstat (limited to 'src/index')
-rw-r--r--src/index/build.odin122
-rw-r--r--src/index/clone.odin378
-rw-r--r--src/index/collector.odin577
-rw-r--r--src/index/indexer.odin50
-rw-r--r--src/index/memory_index.odin28
-rw-r--r--src/index/symbol.odin46
6 files changed, 597 insertions, 604 deletions
diff --git a/src/index/build.odin b/src/index/build.odin
index c8b1996..a7944f0 100644
--- a/src/index/build.odin
+++ b/src/index/build.odin
@@ -10,13 +10,14 @@ import "core:log"
import "core:odin/tokenizer"
import "core:strings"
import "core:mem"
+import "core:runtime"
import "shared:common"
-symbol_collection: SymbolCollection;
+symbol_collection: SymbolCollection
-files: [dynamic]string;
+files: [dynamic]string
platform_os: map[string]bool = {
"windows" = true,
@@ -26,135 +27,144 @@ platform_os: map[string]bool = {
"freebsd" = true,
"darwin" = true,
"wasm32" = true,
-};
+}
+
+
+os_enum_to_string: map[runtime.Odin_OS_Type]string = {
+ .Windows = "windows",
+ .Darwin = "dawrin",
+ .Linux = "linux",
+ .Essence = "essence",
+ .FreeBSD = "freebsd",
+ .WASI = "wasi",
+ .JS = "js",
+ .Freestanding = "freestanding",
+}
-walk_static_index_build :: proc(info: os.File_Info, in_err: os.Errno) -> (err: os.Errno, skip_dir: bool) {
+walk_static_index_build :: proc(info: os.File_Info, in_err: os.Errno) -> (err: os.Errno, skip_dir: bool) {
if info.is_dir {
- return 0, false;
+ return 0, false
}
if filepath.ext(info.name) != ".odin" {
- return 0, false;
+ return 0, false
}
- last_underscore_index := strings.last_index(info.name, "_");
- last_dot_index := strings.last_index(info.name, ".");
+ last_underscore_index := strings.last_index(info.name, "_")
+ last_dot_index := strings.last_index(info.name, ".")
if last_underscore_index + 1 < last_dot_index {
-
- name_between := info.name[last_underscore_index + 1:last_dot_index];
+ name_between := info.name[last_underscore_index + 1:last_dot_index]
if _, ok := platform_os[name_between]; ok {
- if name_between != ODIN_OS {
- return 0, false;
+ if name_between != os_enum_to_string[ODIN_OS] {
+ return 0, false
}
}
}
- forward, _ := filepath.to_slash(info.fullpath, context.temp_allocator);
+ forward, _ := filepath.to_slash(info.fullpath, context.temp_allocator)
- append(&files, strings.clone(forward, context.allocator));
+ append(&files, strings.clone(forward, context.allocator))
- return 0, false;
+ return 0, false
}
build_static_index :: proc(allocator := context.allocator, config: ^common.Config) {
+ symbol_collection = make_symbol_collection(allocator, config)
- symbol_collection = make_symbol_collection(allocator, config);
-
- files = make([dynamic]string, context.allocator);
+ files = make([dynamic]string, context.allocator)
for k, v in config.collections {
- filepath.walk(v, walk_static_index_build);
+ filepath.walk(v, walk_static_index_build)
}
- when ODIN_OS == "windows" {
- slashed, _ := filepath.to_slash(os.get_current_directory(context.temp_allocator), context.temp_allocator);
+ when ODIN_OS == .Windows {
+ slashed, _ := filepath.to_slash(os.get_current_directory(context.temp_allocator), context.temp_allocator)
} else {
- slashed, _ := filepath.to_slash(os.get_current_directory(), context.temp_allocator);
+ slashed, _ := filepath.to_slash(os.get_current_directory(), context.temp_allocator)
}
- when ODIN_OS == "windows" {
- builtin_package := path.join(elems = {slashed, "builtin"}, allocator = context.temp_allocator);
- append(&indexer.builtin_packages, strings.to_lower(builtin_package));
+ when ODIN_OS == .Windows {
+ builtin_package := path.join(elems = {slashed, "builtin"}, allocator = context.temp_allocator)
+ append(&indexer.builtin_packages, strings.to_lower(builtin_package))
} else {
- builtin_package := path.join(elems = {slashed, "builtin"}, allocator = context.allocator);
- append(&indexer.builtin_packages, builtin_package);
+ builtin_package := path.join(elems = {slashed, "builtin"}, allocator = context.allocator)
+ append(&indexer.builtin_packages, builtin_package)
}
- filepath.walk(builtin_package, walk_static_index_build);
+ filepath.walk(builtin_package, walk_static_index_build)
- temp_arena: mem.Arena;
+ temp_arena: mem.Arena
- mem.init_arena(&temp_arena, make([]byte, mem.megabytes(100)));
+ mem.init_arena(&temp_arena, make([]byte, mem.megabytes(100)))
- context.allocator = mem.arena_allocator(&temp_arena);
+ context.allocator = mem.arena_allocator(&temp_arena)
for fullpath in files {
-
- data, ok := os.read_entire_file(fullpath, context.allocator);
+ data, ok := os.read_entire_file(fullpath, context.allocator)
if !ok {
- log.errorf("failed to read entire file for indexing %v", fullpath);
- continue;
+ log.errorf("failed to read entire file for indexing %v", fullpath)
+ continue
}
p := parser.Parser {
err = log_error_handler,
warn = log_warning_handler,
- };
+ }
//have to cheat the parser since it really wants to parse an entire package with the new changes...
- dir := filepath.base(filepath.dir(fullpath, context.allocator));
+ dir := filepath.base(filepath.dir(fullpath, context.allocator))
- pkg := new(ast.Package);
- pkg.kind = .Normal;
- pkg.fullpath = fullpath;
- pkg.name = dir;
+ pkg := new(ast.Package)
+ pkg.kind = .Normal
+ pkg.fullpath = fullpath
+ pkg.name = dir
if dir == "runtime" {
- pkg.kind = .Runtime;
+ pkg.kind = .Runtime
}
file := ast.File {
fullpath = fullpath,
src = string(data),
pkg = pkg,
- };
+ }
- ok = parser.parse_file(&p, &file);
+ ok = parser.parse_file(&p, &file)
if !ok {
- log.info(pkg);
- log.errorf("error in parse file for indexing %v", fullpath);
+ log.info(pkg)
+ log.errorf("error in parse file for indexing %v", fullpath)
}
- uri := common.create_uri(fullpath, context.allocator);
+ uri := common.create_uri(fullpath, context.allocator)
//ERROR hover on uri does not show string
- collect_symbols(&symbol_collection, file, uri.uri);
+ collect_symbols(&symbol_collection, file, uri.uri)
- free_all(context.allocator);
+ free_all(context.allocator)
- delete(fullpath, allocator);
+ delete(fullpath, allocator)
}
- delete(files);
- delete(temp_arena.data);
+ delete(files)
+ delete(temp_arena.data)
- indexer.static_index = make_memory_index(symbol_collection);
+ indexer.static_index = make_memory_index(symbol_collection)
}
free_static_index :: proc() {
- delete_symbol_collection(symbol_collection);
+ delete_symbol_collection(symbol_collection)
}
log_error_handler :: proc(pos: tokenizer.Pos, msg: string, args: ..any) {
- log.warnf("%v %v %v", pos, msg, args);
+ log.warnf("%v %v %v", pos, msg, args)
}
log_warning_handler :: proc(pos: tokenizer.Pos, msg: string, args: ..any) {
- log.warnf("%v %v %v", pos, msg, args);
+ log.warnf("%v %v %v", pos, msg, args)
}
diff --git a/src/index/clone.odin b/src/index/clone.odin
index a9b6f33..24a1138 100644
--- a/src/index/clone.odin
+++ b/src/index/clone.odin
@@ -6,15 +6,24 @@ import "core:odin/tokenizer"
import "core:odin/ast"
import "core:strings"
import "core:log"
+import "core:intrinsics"
+import "core:reflect"
+_ :: intrinsics
new_type :: proc($T: typeid, pos, end: tokenizer.Pos, allocator: mem.Allocator) -> ^T {
- n, _ := mem.new(T, allocator);
- n.pos = pos;
- n.end = end;
- n.derived = n^;
- base: ^ast.Node = n; // dummy check
- _ = base; // "Use" type to make -vet happy
- return n;
+ n, _ := mem.new(T, allocator)
+ n.pos = pos
+ n.end = end
+ n.derived = n
+ base: ^ast.Node = n // dummy check
+ _ = base // "Use" type to make -vet happy
+ when intrinsics.type_has_field(T, "derived_expr") {
+ n.derived_expr = n
+ }
+ when intrinsics.type_has_field(T, "derived_stmt") {
+ n.derived_stmt = n
+ }
+ return n
}
clone_type :: proc {
@@ -22,242 +31,223 @@ clone_type :: proc {
clone_expr,
clone_array,
clone_dynamic_array,
-};
+}
clone_array :: proc(array: $A/[]^$T, allocator: mem.Allocator, unique_strings: ^map[string]string) -> A {
if len(array) == 0 {
- return nil;
+ return nil
}
- res := make(A, len(array), allocator);
+ res := make(A, len(array), allocator)
for elem, i in array {
- res[i] = cast(^T)clone_type(elem, allocator, unique_strings);
+ res[i] = cast(^T)clone_type(elem, allocator, unique_strings)
}
- return res;
+ return res
}
clone_dynamic_array :: proc(array: $A/[dynamic]^$T, allocator: mem.Allocator, unique_strings: ^map[string]string) -> A {
if len(array) == 0 {
- return nil;
+ return nil
}
- res := make(A, len(array), allocator);
+ res := make(A, len(array), allocator)
for elem, i in array {
- res[i] = auto_cast clone_type(elem, allocator, unique_strings);
+ res[i] = auto_cast clone_type(elem, allocator, unique_strings)
}
- return res;
+ return res
}
clone_expr :: proc(node: ^ast.Expr, allocator: mem.Allocator, unique_strings: ^map[string]string) -> ^ast.Expr {
- return cast(^ast.Expr)clone_node(node, allocator, unique_strings);
+ return cast(^ast.Expr)clone_node(node, allocator, unique_strings)
}
clone_node :: proc(node: ^ast.Node, allocator: mem.Allocator, unique_strings: ^map[string]string) -> ^ast.Node {
-
- using ast;
-
+ using ast
if node == nil {
- return nil;
+ return nil
}
- size := size_of(Node);
- align := align_of(Node);
- ti := type_info_of(node.derived.id);
+ size := size_of(Node)
+ align := align_of(Node)
+ ti := reflect.union_variant_type_info(node.derived)
if ti != nil {
- size = ti.size;
- align = ti.align;
+ elem := ti.variant.(reflect.Type_Info_Pointer).elem
+ size = elem.size
+ align = elem.align
+ }
+
+ #partial switch in node.derived {
+ case ^Package, ^File:
+ panic("Cannot clone this node type")
}
- res := cast(^Node)mem.alloc(size, align, allocator);
- src: rawptr = node;
+ res := cast(^Node)mem.alloc(size, align, allocator)
+ src: rawptr = node
if node.derived != nil {
- src = node.derived.data;
+ src = (^rawptr)(&node.derived)^
}
- mem.copy(res, src, size);
- res.derived.data = rawptr(res);
+ mem.copy(res, src, size)
+ res_ptr_any: any
+ res_ptr_any.data = &res
+ res_ptr_any.id = ti.id
if unique_strings != nil && node.pos.file != "" {
- res.pos.file = get_index_unique_string(unique_strings, allocator, node.pos.file);
+ res.pos.file = get_index_unique_string(unique_strings, allocator, node.pos.file)
} else {
- res.pos.file = node.pos.file;
+ res.pos.file = node.pos.file
}
if unique_strings != nil && node.end.file != "" {
- res.end.file = get_index_unique_string(unique_strings, allocator, node.end.file);
+ res.end.file = get_index_unique_string(unique_strings, allocator, node.end.file)
} else {
- res.end.file = node.end.file;
+ res.end.file = node.end.file
}
- switch n in node.derived {
- case Bad_Expr:
- case Ident:
- r := cast(^Ident)res;
+ reflect.set_union_value(res.derived, res_ptr_any)
+
+ res_ptr := reflect.deref(res_ptr_any)
+
+ if de := reflect.struct_field_value_by_name(res_ptr, "derived_expr", true); de != nil {
+ reflect.set_union_value(de, res_ptr_any)
+ }
+ if ds := reflect.struct_field_value_by_name(res_ptr, "derived_stmt", true); ds != nil {
+ reflect.set_union_value(ds, res_ptr_any)
+ }
+
+ if res.derived != nil do #partial switch r in res.derived {
+ case ^Ident:
+ n := node.derived.(^Ident)
+
if unique_strings == nil {
- r.name = strings.clone(n.name, allocator);
+ r.name = strings.clone(n.name, allocator)
} else {
- r.name = get_index_unique_string(unique_strings, allocator, n.name);
+ r.name = get_index_unique_string(unique_strings, allocator, n.name)
}
- case Implicit:
- r := cast(^Implicit)res;
+ case ^Implicit:
+ n := node.derived.(^Implicit)
if unique_strings == nil {
- r.tok.text = strings.clone(n.tok.text, allocator);
+ r.tok.text = strings.clone(n.tok.text, allocator)
} else {
- r.tok.text = get_index_unique_string(unique_strings, allocator, n.tok.text);
+ r.tok.text = get_index_unique_string(unique_strings, allocator, n.tok.text)
}
- case Undef:
- case Basic_Lit:
- r := cast(^Basic_Lit)res;
+ case ^Undef:
+ case ^Basic_Lit:
+ n := node.derived.(^Basic_Lit)
if unique_strings == nil {
- r.tok.text = strings.clone(n.tok.text, allocator);
+ r.tok.text = strings.clone(n.tok.text, allocator)
} else {
- r.tok.text = get_index_unique_string(unique_strings, allocator, n.tok.text);
+ r.tok.text = get_index_unique_string(unique_strings, allocator, n.tok.text)
}
- case Basic_Directive:
- r := cast(^Basic_Directive)res;
+ case ^Basic_Directive:
+ n := node.derived.(^Basic_Directive)
if unique_strings == nil {
- r.name = strings.clone(n.name, allocator);
+ r.name = strings.clone(n.name, allocator)
} else {
- r.name = get_index_unique_string(unique_strings, allocator, n.name);
+ r.name = get_index_unique_string(unique_strings, allocator, n.name)
}
- case Ellipsis:
- r := cast(^Ellipsis)res;
- r.expr = clone_type(r.expr, allocator, unique_strings);
- case Tag_Expr:
- r := cast(^Tag_Expr)res;
- r.expr = clone_type(r.expr, allocator, unique_strings);
- case Unary_Expr:
- r := cast(^Unary_Expr)res;
- r.expr = clone_type(r.expr, allocator, unique_strings);
- case Binary_Expr:
- r := cast(^Binary_Expr)res;
- r.left = clone_type(r.left, allocator, unique_strings);
- r.right = clone_type(r.right, allocator, unique_strings);
- case Paren_Expr:
- r := cast(^Paren_Expr)res;
- r.expr = clone_type(r.expr, allocator, unique_strings);
- case Selector_Expr:
- r := cast(^Selector_Expr)res;
- r.expr = clone_type(r.expr, allocator, unique_strings);
- r.field = auto_cast clone_type(r.field, allocator, unique_strings);
- case Implicit_Selector_Expr:
- r := cast(^Implicit_Selector_Expr)res;
- r.field = auto_cast clone_type(r.field, allocator, unique_strings);
- case Slice_Expr:
- r := cast(^Slice_Expr)res;
- r.expr = clone_type(r.expr, allocator, unique_strings);
- r.low = clone_type(r.low, allocator, unique_strings);
- r.high = clone_type(r.high, allocator, unique_strings);
- case Attribute:
- r := cast(^Attribute)res;
- r.elems = clone_type(r.elems, allocator, unique_strings);
- case Distinct_Type:
- r := cast(^Distinct_Type)res;
- r.type = clone_type(r.type, allocator, unique_strings);
- case Proc_Type:
- r := cast(^Proc_Type)res;
- r.params = auto_cast clone_type(r.params, allocator, unique_strings);
- r.results = auto_cast clone_type(r.results, allocator, unique_strings);
- case Pointer_Type:
- r := cast(^Pointer_Type)res;
- r.elem = clone_type(r.elem, allocator, unique_strings);
- case Array_Type:
- r := cast(^Array_Type)res;
- r.len = clone_type(r.len, allocator, unique_strings);
- r.elem = clone_type(r.elem, allocator, unique_strings);
- r.tag = clone_type(r.tag, allocator, unique_strings);
- case Dynamic_Array_Type:
- r := cast(^Dynamic_Array_Type)res;
- r.elem = clone_type(r.elem, allocator, unique_strings);
- r.tag = clone_type(r.tag, allocator, unique_strings);
- case Struct_Type:
- r := cast(^Struct_Type)res;
- r.poly_params = auto_cast clone_type(r.poly_params, allocator, unique_strings);
- r.align = clone_type(r.align, allocator, unique_strings);
- r.fields = auto_cast clone_type(r.fields, allocator, unique_strings);
- r.where_clauses = clone_type(r.where_clauses, allocator, unique_strings);
- case Field:
- r := cast(^Field)res;
- r.names = clone_type(r.names, allocator, unique_strings);
- r.type = clone_type(r.type, allocator, unique_strings);
- r.default_value = clone_type(r.default_value, allocator, unique_strings);
- case Field_List:
- r := cast(^Field_List)res;
- r.list = clone_type(r.list, allocator, unique_strings);
- case Field_Value:
- r := cast(^Field_Value)res;
- r.field = clone_type(r.field, allocator, unique_strings);
- r.value = clone_type(r.value, allocator, unique_strings);
- case Union_Type:
- r := cast(^Union_Type)res;
- r.poly_params = auto_cast clone_type(r.poly_params, allocator, unique_strings);
- r.align = clone_type(r.align, allocator, unique_strings);
- r.variants = clone_type(r.variants, allocator, unique_strings);
- r.where_clauses = clone_type(r.where_clauses, allocator, unique_strings);
- case Enum_Type:
- r := cast(^Enum_Type)res;
- r.base_type = clone_type(r.base_type, allocator, unique_strings);
- r.fields = clone_type(r.fields, allocator, unique_strings);
- case Bit_Set_Type:
- r := cast(^Bit_Set_Type)res;
- r.elem = clone_type(r.elem, allocator, unique_strings);
- r.underlying = clone_type(r.underlying, allocator, unique_strings);
- case Map_Type:
- r := cast(^Map_Type)res;
- r.key = clone_type(r.key, allocator, unique_strings);
- r.value = clone_type(r.value, allocator, unique_strings);
- case Call_Expr:
- r := cast(^Call_Expr)res;
- r.expr = clone_type(r.expr, allocator, unique_strings);
- r.args = clone_type(r.args, allocator, unique_strings);
- case Typeid_Type:
- r := cast(^Typeid_Type)res;
- r.specialization = clone_type(r.specialization, allocator, unique_strings);
- case Ternary_When_Expr:
- r := cast(^Ternary_When_Expr)res;
- r.x = clone_type(r.x, allocator, unique_strings);
- r.cond = clone_type(r.cond, allocator, unique_strings);
- r.y = clone_type(r.y, allocator, unique_strings);
- case Poly_Type:
- r := cast(^Poly_Type)res;
- r.type = auto_cast clone_type(r.type, allocator, unique_strings);
- r.specialization = clone_type(r.specialization, allocator, unique_strings);
- case Proc_Group:
- r := cast(^Proc_Group)res;
- r.args = clone_type(r.args, allocator, unique_strings);
- case Comp_Lit:
- r := cast(^Comp_Lit)res;
- r.type = clone_type(r.type, allocator, unique_strings);
- r.elems = clone_type(r.elems, allocator, unique_strings);
- case Proc_Lit:
- r := cast(^Proc_Lit)res;
- r.type = cast(^Proc_Type)clone_type(cast(^Node)r.type, allocator, unique_strings);
- r.body = nil;
- r.where_clauses = nil;
- case Helper_Type:
- r := cast(^Helper_Type)res;
- r.type = clone_type(r.type, allocator, unique_strings);
- case Type_Cast:
- r := cast(^Type_Cast)res;
- r.type = clone_type(r.type, allocator, unique_strings);
- r.expr = clone_type(r.expr, allocator, unique_strings);
- case Deref_Expr:
- r := cast(^Deref_Expr)res;
- r.expr = clone_type(r.expr, allocator, unique_strings);
- case Index_Expr:
- r := cast(^Index_Expr)res;
- r.expr = clone_type(r.expr, allocator, unique_strings);
- r.index = clone_type(r.index, allocator, unique_strings);
- case Multi_Pointer_Type:
- r := cast(^Multi_Pointer_Type)res;
- r.elem = clone_type(r.elem, allocator, unique_strings);
- case Matrix_Type:
- r := cast(^Matrix_Type)res;
- r.elem = clone_type(r.elem, allocator, unique_strings);
- case Type_Assertion:
- r := cast(^Type_Assertion)res;
- r.expr = clone_type(r.expr, allocator, unique_strings);
- r.type = clone_type(r.type, allocator, unique_strings);
+ case ^Ellipsis:
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ case ^Tag_Expr:
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ case ^Unary_Expr:
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ case ^Binary_Expr:
+ r.left = clone_type(r.left, allocator, unique_strings)
+ r.right = clone_type(r.right, allocator, unique_strings)
+ case ^Paren_Expr:
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ case ^Selector_Expr:
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ r.field = auto_cast clone_type(r.field, allocator, unique_strings)
+ case ^Implicit_Selector_Expr:
+ r.field = auto_cast clone_type(r.field, allocator, unique_strings)
+ case ^Slice_Expr:
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ r.low = clone_type(r.low, allocator, unique_strings)
+ r.high = clone_type(r.high, allocator, unique_strings)
+ case ^Attribute:
+ r.elems = clone_type(r.elems, allocator, unique_strings)
+ case ^Distinct_Type:
+ r.type = clone_type(r.type, allocator, unique_strings)
+ case ^Proc_Type:
+ r.params = auto_cast clone_type(r.params, allocator, unique_strings)
+ r.results = auto_cast clone_type(r.results, allocator, unique_strings)
+ case ^Pointer_Type:
+ r.elem = clone_type(r.elem, allocator, unique_strings)
+ case ^Array_Type:
+ r.len = clone_type(r.len, allocator, unique_strings)
+ r.elem = clone_type(r.elem, allocator, unique_strings)
+ r.tag = clone_type(r.tag, allocator, unique_strings)
+ case ^Dynamic_Array_Type:
+ r.elem = clone_type(r.elem, allocator, unique_strings)
+ r.tag = clone_type(r.tag, allocator, unique_strings)
+ case ^Struct_Type:
+ r.poly_params = auto_cast clone_type(r.poly_params, allocator, unique_strings)
+ r.align = clone_type(r.align, allocator, unique_strings)
+ r.fields = auto_cast clone_type(r.fields, allocator, unique_strings)
+ r.where_clauses = clone_type(r.where_clauses, allocator, unique_strings)
+ case ^Field:
+ r.names = clone_type(r.names, allocator, unique_strings)
+ r.type = clone_type(r.type, allocator, unique_strings)
+ r.default_value = clone_type(r.default_value, allocator, unique_strings)
+ case ^Field_List:
+ r.list = clone_type(r.list, allocator, unique_strings)
+ case ^Field_Value:
+ r.field = clone_type(r.field, allocator, unique_strings)
+ r.value = clone_type(r.value, allocator, unique_strings)
+ case ^Union_Type:
+ r.poly_params = auto_cast clone_type(r.poly_params, allocator, unique_strings)
+ r.align = clone_type(r.align, allocator, unique_strings)
+ r.variants = clone_type(r.variants, allocator, unique_strings)
+ r.where_clauses = clone_type(r.where_clauses, allocator, unique_strings)
+ case ^Enum_Type:
+ r.base_type = clone_type(r.base_type, allocator, unique_strings)
+ r.fields = clone_type(r.fields, allocator, unique_strings)
+ case ^Bit_Set_Type:
+ r.elem = clone_type(r.elem, allocator, unique_strings)
+ r.underlying = clone_type(r.underlying, allocator, unique_strings)
+ case ^Map_Type:
+ r.key = clone_type(r.key, allocator, unique_strings)
+ r.value = clone_type(r.value, allocator, unique_strings)
+ case ^Call_Expr:
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ r.args = clone_type(r.args, allocator, unique_strings)
+ case ^Typeid_Type:
+ r.specialization = clone_type(r.specialization, allocator, unique_strings)
+ case ^Ternary_When_Expr:
+ r.x = clone_type(r.x, allocator, unique_strings)
+ r.cond = clone_type(r.cond, allocator, unique_strings)
+ r.y = clone_type(r.y, allocator, unique_strings)
+ case ^Poly_Type:
+ r.type = auto_cast clone_type(r.type, allocator, unique_strings)
+ r.specialization = clone_type(r.specialization, allocator, unique_strings)
+ case ^Proc_Group:
+ r.args = clone_type(r.args, allocator, unique_strings)
+ case ^Comp_Lit:
+ r.type = clone_type(r.type, allocator, unique_strings)
+ r.elems = clone_type(r.elems, allocator, unique_strings)
+ case ^Proc_Lit:
+ r.type = cast(^Proc_Type)clone_type(cast(^Node)r.type, allocator, unique_strings)
+ r.body = nil
+ r.where_clauses = nil
+ case ^Helper_Type:
+ r.type = clone_type(r.type, allocator, unique_strings)
+ case ^Type_Cast:
+ r.type = clone_type(r.type, allocator, unique_strings)
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ case ^Deref_Expr:
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ case ^Index_Expr:
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ r.index = clone_type(r.index, allocator, unique_strings)
+ case ^Multi_Pointer_Type:
+ r.elem = clone_type(r.elem, allocator, unique_strings)
+ case ^Matrix_Type:
+ r.elem = clone_type(r.elem, allocator, unique_strings)
+ case ^Type_Assertion:
+ r.expr = clone_type(r.expr, allocator, unique_strings)
+ r.type = clone_type(r.type, allocator, unique_strings)
case:
- panic(fmt.aprintf("Clone type Unhandled node kind: %T", node.derived));
+ //fmt.logf("Unhandled node kind: %T", r)
}
- return res;
+ return res
}
diff --git a/src/index/collector.odin b/src/index/collector.odin
index 49df1e6..495e2a3 100644
--- a/src/index/collector.odin
+++ b/src/index/collector.odin
@@ -22,20 +22,19 @@ SymbolCollection :: struct {
get_index_unique_string :: proc {
get_index_unique_string_collection,
get_index_unique_string_collection_raw,
-};
+}
get_index_unique_string_collection :: proc(collection: ^SymbolCollection, s: string) -> string {
- return get_index_unique_string_collection_raw(&collection.unique_strings, collection.allocator, s);
+ return get_index_unique_string_collection_raw(&collection.unique_strings, collection.allocator, s)
}
get_index_unique_string_collection_raw :: proc(unique_strings: ^map[string]string, allocator: mem.Allocator, s: string) -> string {
- //i'm hashing this string way to much
if _, ok := unique_strings[s]; !ok {
- str := strings.clone(s, allocator);
- unique_strings[str] = str; //yeah maybe I have to use some integer and hash it, tried that before but got name collisions.
+ str := strings.clone(s, allocator)
+ unique_strings[str] = str
}
- return unique_strings[s];
+ return unique_strings[s]
}
make_symbol_collection :: proc(allocator := context.allocator, config: ^common.Config) -> SymbolCollection {
@@ -44,42 +43,39 @@ make_symbol_collection :: proc(allocator := context.allocator, config: ^common.C
config = config,
symbols = make(map[uint]Symbol, 16, allocator),
unique_strings = make(map[string]string, 16, allocator),
- };
+ }
}
delete_symbol_collection :: proc(collection: SymbolCollection) {
-
for k, v in collection.symbols {
- free_symbol(v, collection.allocator);
+ free_symbol(v, collection.allocator)
}
for k, v in collection.unique_strings {
- delete(v, collection.allocator);
+ delete(v, collection.allocator)
}
- delete(collection.symbols);
- delete(collection.unique_strings);
+ delete(collection.symbols)
+ delete(collection.unique_strings)
}
collect_procedure_fields :: proc(collection: ^SymbolCollection, proc_type: ^ast.Proc_Type, arg_list: ^ast.Field_List, return_list: ^ast.Field_List, package_map: map[string]string) -> SymbolProcedureValue {
- returns := make([dynamic]^ast.Field, 0, collection.allocator);
- args := make([dynamic]^ast.Field, 0, collection.allocator);
+ returns := make([dynamic]^ast.Field, 0, collection.allocator)
+ args := make([dynamic]^ast.Field, 0, collection.allocator)
if return_list != nil {
-
for ret in return_list.list {
- cloned := cast(^ast.Field)clone_type(ret, collection.allocator, &collection.unique_strings);
- replace_package_alias(cloned, package_map, collection);
- append(&returns, cloned);
+ cloned := cast(^ast.Field)clone_type(ret, collection.allocator, &collection.unique_strings)
+ replace_package_alias(cloned, package_map, collection)
+ append(&returns, cloned)
}
}
if arg_list != nil {
-
for arg in arg_list.list {
- cloned := cast(^ast.Field)clone_type(arg, collection.allocator, &collection.unique_strings);
- replace_package_alias(cloned, package_map, collection);
- append(&args, cloned);
+ cloned := cast(^ast.Field)clone_type(arg, collection.allocator, &collection.unique_strings)
+ replace_package_alias(cloned, package_map, collection)
+ append(&args, cloned)
}
}
@@ -87,27 +83,26 @@ collect_procedure_fields :: proc(collection: ^SymbolCollection, proc_type: ^ast.
return_types = returns[:],
arg_types = args[:],
generic = proc_type.generic,
- };
- return value;
+ }
+ return value
}
collect_struct_fields :: proc(collection: ^SymbolCollection, struct_type: ast.Struct_Type, package_map: map[string]string) -> SymbolStructValue {
- names := make([dynamic]string, 0, collection.allocator);
- types := make([dynamic]^ast.Expr, 0, collection.allocator);
- usings := make(map[string]bool, 0, collection.allocator);
+ names := make([dynamic]string, 0, collection.allocator)
+ types := make([dynamic]^ast.Expr, 0, collection.allocator)
+ usings := make(map[string]bool, 0, collection.allocator)
for field in struct_type.fields.list {
-
for n in field.names {
- ident := n.derived.(ast.Ident);
- append(&names, get_index_unique_string(collection, ident.name));
+ ident := n.derived.(^ast.Ident)
+ append(&names, get_index_unique_string(collection, ident.name))
- cloned := clone_type(field.type, collection.allocator, &collection.unique_strings);
- replace_package_alias(cloned, package_map, collection);
- append(&types, cloned);
+ cloned := clone_type(field.type, collection.allocator, &collection.unique_strings)
+ replace_package_alias(cloned, package_map, collection)
+ append(&types, cloned)
if .Using in field.flags {
- usings[names[len(names) - 1]] = true;
+ usings[names[len(names) - 1]] = true
}
}
}
@@ -117,345 +112,345 @@ collect_struct_fields :: proc(collection: ^SymbolCollection, struct_type: ast.St
types = types[:],
usings = usings,
poly = cast(^ast.Field_List)clone_type(struct_type.poly_params, collection.allocator, &collection.unique_strings),
- };
+ }
- return value;
+ return value
}
collect_enum_fields :: proc(collection: ^SymbolCollection, fields: []^ast.Expr, package_map: map[string]string) -> SymbolEnumValue {
- names := make([dynamic]string, 0, collection.allocator);
+ names := make([dynamic]string, 0, collection.allocator)
//ERROR no hover on n in the for, but elsewhere is fine
for n in fields {
- if ident, ok := n.derived.(ast.Ident); ok {
- append(&names, get_index_unique_string(collection, ident.name));
- } else if field, ok := n.derived.(ast.Field_Value); ok {
- if ident, ok := field.field.derived.(ast.Ident); ok {
- append(&names, get_index_unique_string(collection, ident.name));
- } else if binary, ok := field.field.derived.(ast.Binary_Expr); ok {
- append(&names, get_index_unique_string(collection, binary.left.derived.(ast.Ident).name));
+ if ident, ok := n.derived.(^ast.Ident); ok {
+ append(&names, get_index_unique_string(collection, ident.name))
+ } else if field, ok := n.derived.(^ast.Field_Value); ok {
+ if ident, ok := field.field.derived.(^ast.Ident); ok {
+ append(&names, get_index_unique_string(collection, ident.name))
+ } else if binary, ok := field.field.derived.(^ast.Binary_Expr); ok {
+ append(&names, get_index_unique_string(collection, binary.left.derived.(^ast.Ident).name))
}
}
}
value := SymbolEnumValue {
names = names[:],
- };
+ }
- return value;
+ return value
}
collect_union_fields :: proc(collection: ^SymbolCollection, union_type: ast.Union_Type, package_map: map[string]string) -> SymbolUnionValue {
- types := make([dynamic]^ast.Expr, 0, collection.allocator);
+ types := make([dynamic]^ast.Expr, 0, collection.allocator)
for variant in union_type.variants {
- cloned := clone_type(variant, collection.allocator, &collection.unique_strings);
- replace_package_alias(cloned, package_map, collection);
- append(&types, cloned);
+ cloned := clone_type(variant, collection.allocator, &collection.unique_strings)
+ replace_package_alias(cloned, package_map, collection)
+ append(&types, cloned)
}
value := SymbolUnionValue {
types = types[:],
poly = cast(^ast.Field_List)clone_type(union_type.poly_params, collection.allocator, &collection.unique_strings),
- };
+ }
- return value;
+ return value
}
collect_bitset_field :: proc(collection: ^SymbolCollection, bitset_type: ast.Bit_Set_Type, package_map: map[string]string) -> SymbolBitSetValue {
- cloned := clone_type(bitset_type.elem, collection.allocator, &collection.unique_strings);
- replace_package_alias(cloned, package_map, collection);
+ cloned := clone_type(bitset_type.elem, collection.allocator, &collection.unique_strings)
+ replace_package_alias(cloned, package_map, collection)
return SymbolBitSetValue {
expr = cloned,
- };
+ }
}
collect_slice :: proc(collection: ^SymbolCollection, array: ast.Array_Type, package_map: map[string]string) -> SymbolFixedArrayValue {
- elem := clone_type(array.elem, collection.allocator, &collection.unique_strings);
- len := clone_type(array.len, collection.allocator, &collection.unique_strings);
+ elem := clone_type(array.elem, collection.allocator, &collection.unique_strings)
+ len := clone_type(array.len, collection.allocator, &collection.unique_strings)
- replace_package_alias(elem, package_map, collection);
- replace_package_alias(len, package_map, collection);
+ replace_package_alias(elem, package_map, collection)
+ replace_package_alias(len, package_map, collection)
return SymbolFixedArrayValue {
expr = elem,
len = len,
- };
+ }
}
collect_array :: proc(collection: ^SymbolCollection, array: ast.Array_Type, package_map: map[string]string) -> SymbolSliceValue {
- elem := clone_type(array.elem, collection.allocator, &collection.unique_strings);
+ elem := clone_type(array.elem, collection.allocator, &collection.unique_strings)
- replace_package_alias(elem, package_map, collection);
+ replace_package_alias(elem, package_map, collection)
return SymbolSliceValue {
expr = elem,
- };
+ }
}
collect_map :: proc(collection: ^SymbolCollection, m: ast.Map_Type, package_map: map[string]string) -> SymbolMapValue {
- key := clone_type(m.key, collection.allocator, &collection.unique_strings);
- value := clone_type(m.value, collection.allocator, &collection.unique_strings);
+ key := clone_type(m.key, collection.allocator, &collection.unique_strings)
+ value := clone_type(m.value, collection.allocator, &collection.unique_strings)
- replace_package_alias(key, package_map, collection);
- replace_package_alias(value, package_map, collection);
+ replace_package_alias(key, package_map, collection)
+ replace_package_alias(value, package_map, collection)
return SymbolMapValue {
key = key,
value = value,
- };
+ }
}
collect_dynamic_array :: proc(collection: ^SymbolCollection, array: ast.Dynamic_Array_Type, package_map: map[string]string) -> SymbolDynamicArrayValue {
- elem := clone_type(array.elem, collection.allocator, &collection.unique_strings);
+ elem := clone_type(array.elem, collection.allocator, &collection.unique_strings)
- replace_package_alias(elem, package_map, collection);
+ replace_package_alias(elem, package_map, collection)
return SymbolDynamicArrayValue {
expr = elem,
- };
+ }
}
collect_generic :: proc(collection: ^SymbolCollection, expr: ^ast.Expr, package_map: map[string]string, uri: string) -> SymbolGenericValue {
//Bit hacky right now, but it's hopefully a temporary solution.
//In the c package code it uses a documentation package(builtin).
- if selector, ok := expr.derived.(ast.Selector_Expr); ok {
- if ident, ok := selector.expr.derived.(ast.Ident); ok {
+ if selector, ok := expr.derived.(^ast.Selector_Expr); ok {
+ if ident, ok := selector.expr.derived.(^ast.Ident); ok {
if ident.name == "builtin" && strings.contains(uri, "Odin/core/c/c.odin") {
- cloned := clone_type(selector.field, collection.allocator, &collection.unique_strings);
- replace_package_alias(cloned, package_map, collection);
+ cloned := clone_type(selector.field, collection.allocator, &collection.unique_strings)
+ replace_package_alias(cloned, package_map, collection)
value := SymbolGenericValue {
expr = cloned,
- };
- return value;
+ }
+ return value
}
}
}
- cloned := clone_type(expr, collection.allocator, &collection.unique_strings);
- replace_package_alias(cloned, package_map, collection);
+ cloned := clone_type(expr, collection.allocator, &collection.unique_strings)
+ replace_package_alias(cloned, package_map, collection)
value := SymbolGenericValue {
expr = cloned,
- };
+ }
- return value;
+ return value
}
collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: string) -> common.Error {
- forward, _ := filepath.to_slash(file.fullpath, context.temp_allocator);
+ forward, _ := filepath.to_slash(file.fullpath, context.temp_allocator)
- when ODIN_OS == "windows" {
- directory := strings.to_lower(path.dir(forward, context.temp_allocator), context.temp_allocator);
+ when ODIN_OS == .Windows {
+ directory := strings.to_lower(path.dir(forward, context.temp_allocator), context.temp_allocator)
} else {
- directory := path.dir(forward, context.temp_allocator);
+ directory := path.dir(forward, context.temp_allocator)
}
- package_map := get_package_mapping(file, collection.config, directory);
+ package_map := get_package_mapping(file, collection.config, directory)
- exprs := common.collect_globals(file, true);
+ exprs := common.collect_globals(file, true)
for expr in exprs {
- symbol: Symbol;
+ symbol: Symbol
- token: ast.Node;
- token_type: SymbolType;
+ token: ast.Node
+ token_type: SymbolType
- name := expr.name;
+ name := expr.name
- col_expr := expr.expr;
+ col_expr := expr.expr
- if helper, ok := col_expr.derived.(ast.Helper_Type); ok {
+ if helper, ok := col_expr.derived.(^ast.Helper_Type); ok {
if helper.type != nil {
- col_expr = helper.type;
+ col_expr = helper.type
}
}
- if dist, ok := col_expr.derived.(ast.Distinct_Type); ok {
+ if dist, ok := col_expr.derived.(^ast.Distinct_Type); ok {
if dist.type != nil {
- col_expr = dist.type;
+ col_expr = dist.type
}
}
- switch v in col_expr.derived {
- case ast.Proc_Lit:
- token = v;
- token_type = .Function;
+ #partial switch v in col_expr.derived {
+ case ^ast.Proc_Lit:
+ token = v^
+ token_type = .Function
if v.type != nil {
- symbol.value = collect_procedure_fields(collection, v.type, v.type.params, v.type.results, package_map);
+ symbol.value = collect_procedure_fields(collection, v.type, v.type.params, v.type.results, package_map)
}
- case ast.Proc_Type:
- token = v;
- token_type = .Function;
- symbol.value = collect_procedure_fields(collection, cast(^ast.Proc_Type)col_expr, v.params, v.results, package_map);
- case ast.Proc_Group:
- token = v;
- token_type = .Function;
+ case ^ast.Proc_Type:
+ token = v^
+ token_type = .Function
+ symbol.value = collect_procedure_fields(collection, cast(^ast.Proc_Type)col_expr, v.params, v.results, package_map)
+ case ^ast.Proc_Group:
+ token = v^
+ token_type = .Function
symbol.value = SymbolProcedureGroupValue {
group = clone_type(col_expr, collection.allocator, &collection.unique_strings),
- };
- case ast.Struct_Type:
- token = v;
- token_type = .Struct;
- symbol.value = collect_struct_fields(collection, v, package_map);
- symbol.signature = "struct";
- case ast.Enum_Type:
- token = v;
- token_type = .Enum;
- symbol.value = collect_enum_fields(collection, v.fields, package_map);
- symbol.signature = "enum";
- case ast.Union_Type:
- token = v;
- token_type = .Union;
- symbol.value = collect_union_fields(collection, v, package_map);
- symbol.signature = "union";
- case ast.Bit_Set_Type:
- token = v;
- token_type = .Enum;
- symbol.value = collect_bitset_field(collection, v, package_map);
- symbol.signature = "bitset";
- case ast.Map_Type:
- token = v;
- token_type = .Variable;
- symbol.value = collect_map(collection, v, package_map);
- case ast.Array_Type:
- token = v;
- token_type = .Variable;
+ }
+ case ^ast.Struct_Type:
+ token = v^
+ token_type = .Struct
+ symbol.value = collect_struct_fields(collection, v^, package_map)
+ symbol.signature = "struct"
+ case ^ast.Enum_Type:
+ token = v^
+ token_type = .Enum
+ symbol.value = collect_enum_fields(collection, v.fields, package_map)
+ symbol.signature = "enum"
+ case ^ast.Union_Type:
+ token = v^
+ token_type = .Union
+ symbol.value = collect_union_fields(collection, v^, package_map)
+ symbol.signature = "union"
+ case ^ast.Bit_Set_Type:
+ token = v^
+ token_type = .Enum
+ symbol.value = collect_bitset_field(collection, v^, package_map)
+ symbol.signature = "bitset"
+ case ^ast.Map_Type:
+ token = v^
+ token_type = .Variable
+ symbol.value = collect_map(collection, v^, package_map)
+ case ^ast.Array_Type:
+ token = v^
+ token_type = .Variable
if v.len == nil {
- symbol.value = collect_slice(collection, v, package_map);
+ symbol.value = collect_slice(collection, v^, package_map)
} else {
- symbol.value = collect_array(collection, v, package_map);
+ symbol.value = collect_array(collection, v^, package_map)
}
- case ast.Dynamic_Array_Type:
- token = v;
- token_type = .Variable;
- symbol.value = collect_dynamic_array(collection, v, package_map);
- case ast.Basic_Lit:
- token = v;
- symbol.value = collect_generic(collection, col_expr, package_map, uri);
+ case ^ast.Dynamic_Array_Type:
+ token = v^
+ token_type = .Variable
+ symbol.value = collect_dynamic_array(collection, v^, package_map)
+ case ^ast.Basic_Lit:
+ token = v^
+ symbol.value = collect_generic(collection, col_expr, package_map, uri)
if expr.mutable {
- token_type = .Variable;
+ token_type = .Variable
} else {
- token_type = .Constant;
+ token_type = .Constant
}
- case ast.Ident:
- token = v;
- symbol.value = collect_generic(collection, col_expr, package_map, uri);
+ case ^ast.Ident:
+ token = v^
+ symbol.value = collect_generic(collection, col_expr, package_map, uri)
if expr.mutable {
- token_type = .Variable;
+ token_type = .Variable
} else {
- token_type = .Unresolved;
+ token_type = .Unresolved
}
case: // default
- symbol.value = collect_generic(collection, col_expr, package_map, uri);
+ symbol.value = collect_generic(collection, col_expr, package_map, uri)
if expr.mutable {
- token_type = .Variable;
+ token_type = .Variable
} else {
- token_type = .Unresolved;
+ token_type = .Unresolved
}
- token = expr.expr;
+ token = expr.expr
}
- symbol.range = common.get_token_range(token, file.src);
- 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);
+ symbol.range = common.get_token_range(token, file.src)
+ 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)
if expr.deprecated {
- symbol.flags |= {.Deprecated};
+ symbol.flags |= {.Deprecated}
}
if expr.file_private {
- symbol.flags |= {.PrivateFile};
+ symbol.flags |= {.PrivateFile}
}
if expr.package_private {
- symbol.flags |= {.PrivatePackage};
+ symbol.flags |= {.PrivatePackage}
}
- when ODIN_OS == "windows" {
- symbol.uri = get_index_unique_string(collection, strings.to_lower(uri, context.temp_allocator));
+ when ODIN_OS == .Windows {
+ symbol.uri = get_index_unique_string(collection, strings.to_lower(uri, context.temp_allocator))
} else {
- symbol.uri = get_index_unique_string(collection, uri);
+ symbol.uri = get_index_unique_string(collection, uri)
}
- cat := strings.concatenate({symbol.pkg, name}, context.temp_allocator);
+ cat := strings.concatenate({symbol.pkg, name}, context.temp_allocator)
- id := get_symbol_id(cat);
+ id := get_symbol_id(cat)
if v, ok := collection.symbols[id]; !ok || v.name == "" {
- collection.symbols[id] = symbol;
+ collection.symbols[id] = symbol
} else {
- free_symbol(symbol, collection.allocator);
+ free_symbol(symbol, collection.allocator)
}
}
- return .None;
+ return .None
}
/*
Gets the map from import alias to absolute package directory
*/
get_package_mapping :: proc(file: ast.File, config: ^common.Config, directory: string) -> map[string]string {
- package_map := make(map[string]string, 0, context.temp_allocator);
+ package_map := make(map[string]string, 0, context.temp_allocator)
for imp, index in file.imports {
//collection specified
if i := strings.index(imp.fullpath, ":"); i != -1 {
//ERROR hover on collection should show string
- collection := imp.fullpath[1:i];
- p := imp.fullpath[i + 1:len(imp.fullpath) - 1];
+ collection := imp.fullpath[1:i]
+ p := imp.fullpath[i + 1:len(imp.fullpath) - 1]
- dir, ok := config.collections[collection];
+ dir, ok := config.collections[collection]
if !ok {
- continue;
+ continue
}
- name: string;
+ name: string
- when ODIN_OS == "windows" {
- full := path.join(elems = {strings.to_lower(dir, context.temp_allocator), p}, allocator = context.temp_allocator);
+ when ODIN_OS == .Windows {
+ full := path.join(elems = {strings.to_lower(dir, context.temp_allocator), p}, allocator = context.temp_allocator)
} else {
- full := path.join(elems = {dir, p}, allocator = context.temp_allocator);
+ full := path.join(elems = {dir, p}, allocator = context.temp_allocator)
}
if imp.name.text != "" {
- name = imp.name.text;
+ name = imp.name.text
} else {
- name = path.base(full, false, context.temp_allocator);
+ name = path.base(full, false, context.temp_allocator)
}
- when ODIN_OS == "windows" {
- package_map[name] = strings.to_lower(full, context.temp_allocator);
+ when ODIN_OS == .Windows {
+ package_map[name] = strings.to_lower(full, context.temp_allocator)
} else {
- package_map[name] = full;
+ package_map[name] = full
}
} else {
- name: string;
+ name: string
- full := path.join(elems = {directory, imp.fullpath[1:len(imp.fullpath) - 1]}, allocator = context.temp_allocator);
+ full := path.join(elems = {directory, imp.fullpath[1:len(imp.fullpath) - 1]}, allocator = context.temp_allocator)
- full = path.clean(full, context.temp_allocator);
+ full = path.clean(full, context.temp_allocator)
if imp.name.text != "" {
- name = imp.name.text;
+ name = imp.name.text
} else {
- name = path.base(full, false, context.temp_allocator);
+ name = path.base(full, false, context.temp_allocator)
}
- when ODIN_OS == "windows" {
- package_map[name] = strings.to_lower(full, context.temp_allocator);
+ when ODIN_OS == .Windows {
+ package_map[name] = strings.to_lower(full, context.temp_allocator)
} else {
- package_map[name] = full;
+ package_map[name] = full
}
}
}
- return package_map;
+ return package_map
}
/*
@@ -468,127 +463,125 @@ replace_package_alias :: proc {
replace_package_alias_expr,
replace_package_alias_array,
replace_package_alias_dynamic_array,
-};
+}
replace_package_alias_array :: proc(array: $A/[]^$T, package_map: map[string]string, collection: ^SymbolCollection) {
for elem, i in array {
- replace_package_alias(elem, package_map, collection);
+ replace_package_alias(elem, package_map, collection)
}
}
replace_package_alias_dynamic_array :: proc(array: $A/[dynamic]^$T, package_map: map[string]string, collection: ^SymbolCollection) {
for elem, i in array {
- replace_package_alias(elem, package_map, collection);
+ replace_package_alias(elem, package_map, collection)
}
}
replace_package_alias_expr :: proc(node: ^ast.Expr, package_map: map[string]string, collection: ^SymbolCollection) {
- replace_package_alias_node(node, package_map, collection);
+ replace_package_alias_node(node, package_map, collection)
}
replace_package_alias_node :: proc(node: ^ast.Node, package_map: map[string]string, collection: ^SymbolCollection) {
- using ast;
+ using ast
if node == nil {
- return;
+ return
}
- switch n in node.derived {
- case Bad_Expr:
- case Ident:
- case Implicit:
- case Undef:
- case Basic_Lit:
- case Basic_Directive:
- case Ellipsis:
- replace_package_alias(n.expr, package_map, collection);
- case Tag_Expr:
- replace_package_alias(n.expr, package_map, collection);
- case Unary_Expr:
- replace_package_alias(n.expr, package_map, collection);
- case Binary_Expr:
- replace_package_alias(n.left, package_map, collection);
- replace_package_alias(n.right, package_map, collection);
- case Paren_Expr:
- replace_package_alias(n.expr, package_map, collection);
- case Selector_Expr:
-
- if _, ok := n.expr.derived.(Ident); ok {
-
- ident := &n.expr.derived.(Ident);
+ #partial switch n in node.derived {
+ case ^Bad_Expr:
+ case ^Ident:
+ case ^Implicit:
+ case ^Undef:
+ case ^Basic_Lit:
+ case ^Basic_Directive:
+ case ^Ellipsis:
+ replace_package_alias(n.expr, package_map, collection)
+ case ^Tag_Expr:
+ replace_package_alias(n.expr, package_map, collection)
+ case ^Unary_Expr:
+ replace_package_alias(n.expr, package_map, collection)
+ case ^Binary_Expr:
+ replace_package_alias(n.left, package_map, collection)
+ replace_package_alias(n.right, package_map, collection)
+ case ^Paren_Expr:
+ replace_package_alias(n.expr, package_map, collection)
+ case ^Selector_Expr:
+ if _, ok := n.expr.derived.(^Ident); ok {
+ ident := n.expr.derived.(^Ident)
if package_name, ok := package_map[ident.name]; ok {
- ident.name = get_index_unique_string(collection, package_name);
+ ident.name = get_index_unique_string(collection, package_name)
}
} else {
- replace_package_alias(n.expr, package_map, collection);
- replace_package_alias(n.field, package_map, collection);
+ replace_package_alias(n.expr, package_map, collection)
+ replace_package_alias(n.field, package_map, collection)
}
- case Implicit_Selector_Expr:
- replace_package_alias(n.field, package_map, collection);
- case Slice_Expr:
- replace_package_alias(n.expr, package_map, collection);
- replace_package_alias(n.low, package_map, collection);
- replace_package_alias(n.high, package_map, collection);
- case Attribute:
- replace_package_alias(n.elems, package_map, collection);
- case Distinct_Type:
- replace_package_alias(n.type, package_map, collection);
- case Proc_Type:
- replace_package_alias(n.params, package_map, collection);
- replace_package_alias(n.results, package_map, collection);
- case Pointer_Type:
- replace_package_alias(n.elem, package_map, collection);
- case Array_Type:
- replace_package_alias(n.len, package_map, collection);
- replace_package_alias(n.elem, package_map, collection);
- case Dynamic_Array_Type:
- replace_package_alias(n.elem, package_map, collection);
- case Struct_Type:
- replace_package_alias(n.poly_params, package_map, collection);
- replace_package_alias(n.align, package_map, collection);
- replace_package_alias(n.fields, package_map, collection);
- case Field:
- replace_package_alias(n.names, package_map, collection);
- replace_package_alias(n.type, package_map, collection);
- replace_package_alias(n.default_value, package_map, collection);
- case Field_List:
- replace_package_alias(n.list, package_map, collection);
- case Field_Value:
- replace_package_alias(n.field, package_map, collection);
- replace_package_alias(n.value, package_map, collection);
- case Union_Type:
- replace_package_alias(n.poly_params, package_map, collection);
- replace_package_alias(n.align, package_map, collection);
- replace_package_alias(n.variants, package_map, collection);
- case Enum_Type:
- replace_package_alias(n.base_type, package_map, collection);
- replace_package_alias(n.fields, package_map, collection);
- case Bit_Set_Type:
- replace_package_alias(n.elem, package_map, collection);
- replace_package_alias(n.underlying, package_map, collection);
- case Map_Type:
- replace_package_alias(n.key, package_map, collection);
- replace_package_alias(n.value, package_map, collection);
- case Call_Expr:
- replace_package_alias(n.expr, package_map, collection);
- replace_package_alias(n.args, package_map, collection);
- case Typeid_Type:
- replace_package_alias(n.specialization, package_map, collection);
- case Poly_Type:
- replace_package_alias(n.type, package_map, collection);
- replace_package_alias(n.specialization, package_map, collection);
- case Proc_Group:
- replace_package_alias(n.args, package_map, collection);
- case Comp_Lit:
- replace_package_alias(n.type, package_map, collection);
- replace_package_alias(n.elems, package_map, collection);
- case Helper_Type:
- replace_package_alias(n.type, package_map, collection);
- case Proc_Lit:
- case Multi_Pointer_Type:
- replace_package_alias(n.elem, package_map, collection);
+ case ^Implicit_Selector_Expr:
+ replace_package_alias(n.field, package_map, collection)
+ case ^Slice_Expr:
+ replace_package_alias(n.expr, package_map, collection)
+ replace_package_alias(n.low, package_map, collection)
+ replace_package_alias(n.high, package_map, collection)
+ case ^Attribute:
+ replace_package_alias(n.elems, package_map, collection)
+ case ^Distinct_Type:
+ replace_package_alias(n.type, package_map, collection)
+ case ^Proc_Type:
+ replace_package_alias(n.params, package_map, collection)
+ replace_package_alias(n.results, package_map, collection)
+ case ^Pointer_Type:
+ replace_package_alias(n.elem, package_map, collection)
+ case ^Array_Type:
+ replace_package_alias(n.len, package_map, collection)
+ replace_package_alias(n.elem, package_map, collection)
+ case ^Dynamic_Array_Type:
+ replace_package_alias(n.elem, package_map, collection)
+ case ^Struct_Type:
+ replace_package_alias(n.poly_params, package_map, collection)
+ replace_package_alias(n.align, package_map, collection)
+ replace_package_alias(n.fields, package_map, collection)
+ case ^Field:
+ replace_package_alias(n.names, package_map, collection)
+ replace_package_alias(n.type, package_map, collection)
+ replace_package_alias(n.default_value, package_map, collection)
+ case ^Field_List:
+ replace_package_alias(n.list, package_map, collection)
+ case ^Field_Value:
+ replace_package_alias(n.field, package_map, collection)
+ replace_package_alias(n.value, package_map, collection)
+ case ^Union_Type:
+ replace_package_alias(n.poly_params, package_map, collection)
+ replace_package_alias(n.align, package_map, collection)
+ replace_package_alias(n.variants, package_map, collection)
+ case ^Enum_Type:
+ replace_package_alias(n.base_type, package_map, collection)
+ replace_package_alias(n.fields, package_map, collection)
+ case ^Bit_Set_Type:
+ replace_package_alias(n.elem, package_map, collection)
+ replace_package_alias(n.underlying, package_map, collection)
+ case ^Map_Type:
+ replace_package_alias(n.key, package_map, collection)
+ replace_package_alias(n.value, package_map, collection)
+ case ^Call_Expr:
+ replace_package_alias(n.expr, package_map, collection)
+ replace_package_alias(n.args, package_map, collection)
+ case ^Typeid_Type:
+ replace_package_alias(n.specialization, package_map, collection)
+ case ^Poly_Type:
+ replace_package_alias(n.type, package_map, collection)
+ replace_package_alias(n.specialization, package_map, collection)
+ case ^Proc_Group:
+ replace_package_alias(n.args, package_map, collection)
+ case ^Comp_Lit:
+ replace_package_alias(n.type, package_map, collection)
+ replace_package_alias(n.elems, package_map, collection)
+ case ^Helper_Type:
+ replace_package_alias(n.type, package_map, collection)
+ case ^Proc_Lit:
+ case ^Multi_Pointer_Type:
+ replace_package_alias(n.elem, package_map, collection)
case:
- log.warnf("Replace Unhandled node kind: %T", n);
+ log.warnf("Replace Unhandled node kind: %T", n)
}
}
diff --git a/src/index/indexer.odin b/src/index/indexer.odin
index 42b111c..a67c147 100644
--- a/src/index/indexer.odin
+++ b/src/index/indexer.odin
@@ -41,7 +41,7 @@ Indexer :: struct {
dynamic_index: MemoryIndex,
}
-indexer: Indexer;
+indexer: Indexer
FuzzyResult :: struct {
symbol: Symbol,
@@ -50,62 +50,62 @@ FuzzyResult :: struct {
lookup :: proc(name: string, pkg: string, loc := #caller_location) -> (Symbol, bool) {
if symbol, ok := memory_index_lookup(&indexer.dynamic_index, name, pkg); ok {
- log.infof("lookup dynamic name: %v pkg: %v, symbol %v location %v", name, pkg, symbol, loc);
- return symbol, true;
+ log.infof("lookup dynamic name: %v pkg: %v, symbol %v location %v", name, pkg, symbol, loc)
+ return symbol, true
}
if symbol, ok := memory_index_lookup(&indexer.static_index, name, pkg); ok {
- log.infof("lookup name: %v pkg: %v, symbol %v location %v", name, pkg, symbol, loc);
- return symbol, true;
+ log.infof("lookup name: %v pkg: %v, symbol %v location %v", name, pkg, symbol, loc)
+ return symbol, true
}
- log.infof("lookup failed name: %v pkg: %v location %v", name, pkg, loc);
- return {}, false;
+ log.infof("lookup failed name: %v pkg: %v location %v", name, pkg, loc)
+ return {}, false
}
fuzzy_search :: proc(name: string, pkgs: []string) -> ([]FuzzyResult, bool) {
- dynamic_results, dynamic_ok := memory_index_fuzzy_search(&indexer.dynamic_index, name, pkgs);
- static_results, static_ok := memory_index_fuzzy_search(&indexer.static_index, name, pkgs);
- result := make([dynamic]FuzzyResult, context.temp_allocator);
- files := make(map[string]bool, 0, context.temp_allocator);
+ dynamic_results, dynamic_ok := memory_index_fuzzy_search(&indexer.dynamic_index, name, pkgs)
+ static_results, static_ok := memory_index_fuzzy_search(&indexer.static_index, name, pkgs)
+ result := make([dynamic]FuzzyResult, context.temp_allocator)
+ files := make(map[string]bool, 0, context.temp_allocator)
if !dynamic_ok || !static_ok {
- return {}, false;
+ return {}, false
}
for r in dynamic_results {
- files[r.symbol.uri] = true;
- append(&result, r);
+ files[r.symbol.uri] = true
+ append(&result, r)
}
for r in static_results {
if r.symbol.uri in files {
- continue;
+ continue
}
- append(&result, r);
+ append(&result, r)
}
- sort.sort(fuzzy_sort_interface(&result));
+ sort.sort(fuzzy_sort_interface(&result))
- return result[:], true;
+ return result[:], true
}
fuzzy_sort_interface :: proc(s: ^[dynamic]FuzzyResult) -> sort.Interface {
return sort.Interface {
collection = rawptr(s),
len = proc(it: sort.Interface) -> int {
- s := (^[dynamic]FuzzyResult)(it.collection);
- return len(s^);
+ s := (^[dynamic]FuzzyResult)(it.collection)
+ return len(s^)
},
less = proc(it: sort.Interface, i, j: int) -> bool {
- s := (^[dynamic]FuzzyResult)(it.collection);
- return s[i].score > s[j].score;
+ s := (^[dynamic]FuzzyResult)(it.collection)
+ return s[i].score > s[j].score
},
swap = proc(it: sort.Interface, i, j: int) {
- s := (^[dynamic]FuzzyResult)(it.collection);
- s[i], s[j] = s[j], s[i];
+ s := (^[dynamic]FuzzyResult)(it.collection)
+ s[i], s[j] = s[j], s[i]
},
- };
+ }
}
diff --git a/src/index/memory_index.odin b/src/index/memory_index.odin
index e946811..d4e7e6e 100644
--- a/src/index/memory_index.odin
+++ b/src/index/memory_index.odin
@@ -22,44 +22,44 @@ make_memory_index :: proc(collection: SymbolCollection) -> MemoryIndex {
return MemoryIndex {
collection = collection,
- };
+ }
}
memory_index_lookup :: proc(index: ^MemoryIndex, name: string, pkg: string) -> (Symbol, bool) {
- id := get_symbol_id(strings.concatenate({pkg, name}, context.temp_allocator));
- return index.collection.symbols[id];
+ id := get_symbol_id(strings.concatenate({pkg, name}, context.temp_allocator))
+ return index.collection.symbols[id]
}
memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, pkgs: []string) -> ([]FuzzyResult, bool) {
- symbols := make([dynamic]FuzzyResult, 0, context.temp_allocator);
+ symbols := make([dynamic]FuzzyResult, 0, context.temp_allocator)
- fuzzy_matcher := common.make_fuzzy_matcher(name);
+ fuzzy_matcher := common.make_fuzzy_matcher(name)
- top := 20;
+ top := 20
for _, symbol in index.collection.symbols {
if !exists_in_scope(symbol.pkg, pkgs) {
- continue;
+ continue
}
if score, ok := common.fuzzy_match(fuzzy_matcher, symbol.name); ok == 1 {
result := FuzzyResult {
symbol = symbol,
score = score,
- };
+ }
- append(&symbols, result);
+ append(&symbols, result)
}
}
- sort.sort(fuzzy_sort_interface(&symbols));
+ sort.sort(fuzzy_sort_interface(&symbols))
if name == "" {
- return symbols[:], true;
+ return symbols[:], true
} else {
- return symbols[:min(top, len(symbols))], true;
+ return symbols[:min(top, len(symbols))], true
}
}
@@ -67,9 +67,9 @@ exists_in_scope :: proc(symbol_scope: string, scope: []string) -> bool {
for s in scope {
if strings.compare(symbol_scope, s) == 0 {
- return true;
+ return true
}
}
- return false;
+ return false
}
diff --git a/src/index/symbol.odin b/src/index/symbol.odin
index 3ee808f..c00c08e 100644
--- a/src/index/symbol.odin
+++ b/src/index/symbol.odin
@@ -138,54 +138,54 @@ SymbolType :: enum {
}
new_clone_symbol :: proc(data: Symbol, allocator := context.allocator) -> (^Symbol) {
- new_symbol := new(Symbol, allocator);
- new_symbol^ = data;
- new_symbol.value = data.value;
- return new_symbol;
+ new_symbol := new(Symbol, allocator)
+ new_symbol^ = data
+ new_symbol.value = data.value
+ return new_symbol
}
free_symbol :: proc(symbol: Symbol, allocator: mem.Allocator) {
if symbol.signature != "" && symbol.signature != "struct" &&
symbol.signature != "union" && symbol.signature != "enum" &&
symbol.signature != "bitset" {
- delete(symbol.signature, allocator);
+ delete(symbol.signature, allocator)
}
if symbol.doc != "" {
- delete(symbol.doc, allocator);
+ delete(symbol.doc, allocator)
}
#partial switch v in symbol.value {
case SymbolProcedureValue:
- common.free_ast(v.return_types, allocator);
- common.free_ast(v.arg_types, allocator);
+ common.free_ast(v.return_types, allocator)
+ common.free_ast(v.arg_types, allocator)
case SymbolStructValue:
- delete(v.names, allocator);
- common.free_ast(v.types, allocator);
+ delete(v.names, allocator)
+ common.free_ast(v.types, allocator)
case SymbolGenericValue:
- common.free_ast(v.expr, allocator);
+ common.free_ast(v.expr, allocator)
case SymbolProcedureGroupValue:
- common.free_ast(v.group, allocator);
+ common.free_ast(v.group, allocator)
case SymbolEnumValue:
- delete(v.names, allocator);
+ delete(v.names, allocator)
case SymbolUnionValue:
- common.free_ast(v.types, allocator);
+ common.free_ast(v.types, allocator)
case SymbolBitSetValue:
- common.free_ast(v.expr, allocator);
+ common.free_ast(v.expr, allocator)
case SymbolDynamicArrayValue:
- common.free_ast(v.expr, allocator);
+ common.free_ast(v.expr, allocator)
case SymbolFixedArrayValue:
- common.free_ast(v.expr, allocator);
- common.free_ast(v.len, allocator);
+ common.free_ast(v.expr, allocator)
+ common.free_ast(v.len, allocator)
case SymbolSliceValue:
- common.free_ast(v.expr, allocator);
+ common.free_ast(v.expr, allocator)
case SymbolBasicValue:
- common.free_ast(v.ident, allocator);
+ common.free_ast(v.ident, allocator)
}
}
get_symbol_id :: proc(str: string) -> uint {
- ret := common.sha1_hash(transmute([]byte)str);
- r := cast(^uint)slice.first_ptr(ret[:]);
- return r^;
+ ret := common.sha1_hash(transmute([]byte)str)
+ r := cast(^uint)slice.first_ptr(ret[:])
+ return r^
}