aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-08-20 13:13:26 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2022-08-20 13:13:26 +0200
commitf6f2eb760d4b11630dc0719c8893383bed20cd9a (patch)
treef3738e1fa057671d182a7161f9ff02ffa7b56020 /src/common
parent8e8360dba88feb0334a222e9f990250cf65f32bf (diff)
Finally make the move to use odinfmt in ols.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/allocator.odin73
-rw-r--r--src/common/ast.odin650
-rw-r--r--src/common/config.odin4
-rw-r--r--src/common/fuzzy.odin3
-rw-r--r--src/common/position.odin121
-rw-r--r--src/common/types.odin2
-rw-r--r--src/common/uri.odin23
-rw-r--r--src/common/util.odin41
-rw-r--r--src/common/util_windows.odin84
9 files changed, 629 insertions, 372 deletions
diff --git a/src/common/allocator.odin b/src/common/allocator.odin
index 6d2d371..c231102 100644
--- a/src/common/allocator.odin
+++ b/src/common/allocator.odin
@@ -11,15 +11,24 @@ Scratch_Allocator :: struct {
leaked_allocations: [dynamic][]byte,
}
-scratch_allocator_init :: proc (s: ^Scratch_Allocator, size: int, backup_allocator := context.allocator) {
- s.data, _ = mem.make_aligned([]byte, size, 2 * align_of(rawptr), backup_allocator)
- s.curr_offset = 0
- s.prev_allocation = nil
- s.backup_allocator = backup_allocator
+scratch_allocator_init :: proc(
+ s: ^Scratch_Allocator,
+ size: int,
+ backup_allocator := context.allocator,
+) {
+ s.data, _ = mem.make_aligned(
+ []byte,
+ size,
+ 2 * align_of(rawptr),
+ backup_allocator,
+ )
+ s.curr_offset = 0
+ s.prev_allocation = nil
+ s.backup_allocator = backup_allocator
s.leaked_allocations.allocator = backup_allocator
}
-scratch_allocator_destroy :: proc (s: ^Scratch_Allocator) {
+scratch_allocator_destroy :: proc(s: ^Scratch_Allocator) {
if s == nil {
return
}
@@ -31,14 +40,25 @@ scratch_allocator_destroy :: proc (s: ^Scratch_Allocator) {
s^ = {}
}
-scratch_allocator_proc :: proc (allocator_data: rawptr, mode: mem.Allocator_Mode, size, alignment: int, old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, mem.Allocator_Error) {
+scratch_allocator_proc :: proc(
+ allocator_data: rawptr,
+ mode: mem.Allocator_Mode,
+ size,
+ alignment: int,
+ old_memory: rawptr,
+ old_size: int,
+ loc := #caller_location,
+) -> (
+ []byte,
+ mem.Allocator_Error,
+) {
s := (^Scratch_Allocator)(allocator_data)
if s.data == nil {
DEFAULT_BACKING_SIZE :: 1 << 22
if !(context.allocator.procedure != scratch_allocator_proc &&
- context.allocator.data != allocator_data) {
+ context.allocator.data != allocator_data) {
panic("cyclic initialization of the scratch allocator with itself")
}
scratch_allocator_init(s, DEFAULT_BACKING_SIZE)
@@ -50,7 +70,7 @@ scratch_allocator_proc :: proc (allocator_data: rawptr, mode: mem.Allocator_Mode
case .Alloc:
size = mem.align_forward_int(size, alignment)
- switch {
+ switch {
case s.curr_offset + size <= len(s.data):
start := uintptr(raw_data(s.data))
ptr := start + uintptr(s.curr_offset)
@@ -80,7 +100,13 @@ scratch_allocator_proc :: proc (allocator_data: rawptr, mode: mem.Allocator_Mode
if logger := context.logger; logger.lowest_level <= .Warning {
if logger.procedure != nil {
- logger.procedure(logger.data, .Warning, "mem.Scratch_Allocator resorted to backup_allocator" , logger.options, loc)
+ logger.procedure(
+ logger.data,
+ .Warning,
+ "mem.Scratch_Allocator resorted to backup_allocator",
+ logger.options,
+ loc,
+ )
}
}
@@ -100,13 +126,29 @@ scratch_allocator_proc :: proc (allocator_data: rawptr, mode: mem.Allocator_Mode
end := begin + uintptr(len(s.data))
old_ptr := uintptr(old_memory)
- data, err := scratch_allocator_proc(allocator_data, .Alloc, size, alignment, old_memory, old_size, loc)
+ data, err := scratch_allocator_proc(
+ allocator_data,
+ .Alloc,
+ size,
+ alignment,
+ old_memory,
+ old_size,
+ loc,
+ )
if err != nil {
return data, err
}
runtime.copy(data, mem.byte_slice(old_memory, old_size))
- _, err = scratch_allocator_proc(allocator_data, .Free, 0, alignment, old_memory, old_size, loc)
+ _, err = scratch_allocator_proc(
+ allocator_data,
+ .Free,
+ 0,
+ alignment,
+ old_memory,
+ old_size,
+ loc,
+ )
return data, err
case .Query_Features:
@@ -122,9 +164,6 @@ scratch_allocator_proc :: proc (allocator_data: rawptr, mode: mem.Allocator_Mode
return nil, nil
}
-scratch_allocator :: proc (allocator: ^Scratch_Allocator) -> mem.Allocator {
- return mem.Allocator {
- procedure = scratch_allocator_proc,
- data = allocator,
- }
+scratch_allocator :: proc(allocator: ^Scratch_Allocator) -> mem.Allocator {
+ return mem.Allocator{procedure = scratch_allocator_proc, data = allocator}
}
diff --git a/src/common/ast.odin b/src/common/ast.odin
index 71f74a4..e4eb0fd 100644
--- a/src/common/ast.odin
+++ b/src/common/ast.odin
@@ -8,61 +8,61 @@ import "core:strings"
import path "core:path/slashpath"
keyword_map: map[string]bool = {
- "int" = true,
- "uint" = true,
- "string" = true,
- "cstring" = true,
- "u64" = true,
- "f32" = true,
- "f64" = true,
- "i64" = true,
- "i128" = true,
- "i32" = true,
- "i16" = true,
- "u16" = true,
- "bool" = true,
- "rawptr" = true,
- "any" = true,
- "u32" = true,
- "u128" = true,
- "b32" = true,
- "b64" = true,
- "true" = true,
- "false" = true,
- "nil" = true,
- "byte" = true,
- "u8" = true,
- "i8" = true,
- "rune" = true,
- "f16be" = true,
- "f16le" = true,
- "f32be" = true,
- "f32le" = true,
- "f64be" = true,
- "f64le" = true,
- "i16be" = true,
- "i16le" = true,
- "i32be" = true,
- "i32le" = true,
- "i64be" = true,
- "i64le" = true,
- "u16be" = true,
- "u16le" = true,
- "u32be" = true,
- "u32le" = true,
- "u64be" = true,
- "u64le" = true,
- "i128be" = true,
- "i128le" = true,
- "u128be" = true,
- "u128le" = true,
- "complex32" = true,
- "complex64" = true,
- "complex128" = true,
- "quaternion64" = true,
- "quaternion128" = true,
- "quaternion256" = true,
- "uintptr" = true,
+ "int" = true,
+ "uint" = true,
+ "string" = true,
+ "cstring" = true,
+ "u64" = true,
+ "f32" = true,
+ "f64" = true,
+ "i64" = true,
+ "i128" = true,
+ "i32" = true,
+ "i16" = true,
+ "u16" = true,
+ "bool" = true,
+ "rawptr" = true,
+ "any" = true,
+ "u32" = true,
+ "u128" = true,
+ "b32" = true,
+ "b64" = true,
+ "true" = true,
+ "false" = true,
+ "nil" = true,
+ "byte" = true,
+ "u8" = true,
+ "i8" = true,
+ "rune" = true,
+ "f16be" = true,
+ "f16le" = true,
+ "f32be" = true,
+ "f32le" = true,
+ "f64be" = true,
+ "f64le" = true,
+ "i16be" = true,
+ "i16le" = true,
+ "i32be" = true,
+ "i32le" = true,
+ "i64be" = true,
+ "i64le" = true,
+ "u16be" = true,
+ "u16le" = true,
+ "u32be" = true,
+ "u32le" = true,
+ "u64be" = true,
+ "u64le" = true,
+ "i128be" = true,
+ "i128le" = true,
+ "u128be" = true,
+ "u128le" = true,
+ "complex32" = true,
+ "complex64" = true,
+ "complex128" = true,
+ "quaternion64" = true,
+ "quaternion128" = true,
+ "quaternion256" = true,
+ "uintptr" = true,
}
GlobalExpr :: struct {
@@ -99,7 +99,12 @@ unwrap_pointer :: proc(expr: ^ast.Expr) -> (ast.Ident, bool) {
return {}, false
}
-collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^ast.Node, skip_private: bool) {
+collect_value_decl :: proc(
+ exprs: ^[dynamic]GlobalExpr,
+ file: ast.File,
+ stmt: ^ast.Node,
+ skip_private: bool,
+) {
if value_decl, ok := stmt.derived.(^ast.Value_Decl); ok {
is_deprecated := false
is_private_file := false
@@ -112,7 +117,8 @@ collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^a
if ident, ok := value.field.derived.(^ast.Ident); ok {
switch ident.name {
case "private":
- if val, ok := value.value.derived.(^ast.Basic_Lit); ok {
+ if val, ok := value.value.derived.(^ast.Basic_Lit);
+ ok {
switch val.tok.text {
case "\"file\"":
is_private_file = true
@@ -141,35 +147,44 @@ collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^a
str := get_ast_node_string(name, file.src)
if value_decl.type != nil {
- append(exprs, GlobalExpr {
- name = str,
- name_expr = name,
- expr = value_decl.type,
- mutable = value_decl.is_mutable,
- docs = value_decl.docs,
- attributes = value_decl.attributes[:],
- deprecated = is_deprecated,
- builtin = is_builtin,
- })
- } else {
- if len(value_decl.values) > i {
- append(exprs, GlobalExpr {
+ append(
+ exprs,
+ GlobalExpr{
name = str,
name_expr = name,
- expr = value_decl.values[i],
- mutable = value_decl.is_mutable,
- docs = value_decl.docs,
+ expr = value_decl.type,
+ mutable = value_decl.is_mutable,
+ docs = value_decl.docs,
attributes = value_decl.attributes[:],
deprecated = is_deprecated,
builtin = is_builtin,
- })
+ },
+ )
+ } else {
+ if len(value_decl.values) > i {
+ append(
+ exprs,
+ GlobalExpr{
+ name = str,
+ name_expr = name,
+ expr = value_decl.values[i],
+ mutable = value_decl.is_mutable,
+ docs = value_decl.docs,
+ attributes = value_decl.attributes[:],
+ deprecated = is_deprecated,
+ builtin = is_builtin,
+ },
+ )
}
}
}
}
}
-collect_globals :: proc(file: ast.File, skip_private := false) -> []GlobalExpr {
+collect_globals :: proc(
+ file: ast.File,
+ skip_private := false,
+) -> []GlobalExpr {
exprs := make([dynamic]GlobalExpr, context.temp_allocator)
for decl in file.decls {
@@ -205,16 +220,29 @@ collect_globals :: proc(file: ast.File, skip_private := false) -> []GlobalExpr {
}
if ident != nil && implicit != nil {
- if ident.name == "ODIN_OS" && implicit.tok.text == fmt.tprint(ODIN_OS) {
- if block, ok := when_decl.body.derived.(^ast.Block_Stmt); ok {
+ if ident.name == "ODIN_OS" &&
+ implicit.tok.text == fmt.tprint(ODIN_OS) {
+ if block, ok := when_decl.body.derived.(^ast.Block_Stmt);
+ ok {
for stmt in block.stmts {
- collect_value_decl(&exprs, file, stmt, skip_private)
+ collect_value_decl(
+ &exprs,
+ file,
+ stmt,
+ skip_private,
+ )
}
}
} else if ident.name != "ODIN_OS" {
- if block, ok := when_decl.body.derived.(^ast.Block_Stmt); ok {
+ if block, ok := when_decl.body.derived.(^ast.Block_Stmt);
+ ok {
for stmt in block.stmts {
- collect_value_decl(&exprs, file, stmt, skip_private)
+ collect_value_decl(
+ &exprs,
+ file,
+ stmt,
+ skip_private,
+ )
}
}
}
@@ -226,7 +254,8 @@ collect_globals :: proc(file: ast.File, skip_private := false) -> []GlobalExpr {
}
}
}
- } else if foreign_decl, ok := decl.derived.(^ast.Foreign_Block_Decl); ok {
+ } else if foreign_decl, ok := decl.derived.(^ast.Foreign_Block_Decl);
+ ok {
if foreign_decl.body == nil {
continue
}
@@ -246,18 +275,39 @@ get_ast_node_string :: proc(node: ^ast.Node, src: string) -> string {
return string(src[node.pos.offset:node.end.offset])
}
-get_doc :: proc(comment: ^ast.Comment_Group, allocator: mem.Allocator) -> string {
+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)
+ tmp = strings.concatenate(
+ {tmp, "\n", doc.text},
+ context.temp_allocator,
+ )
}
if tmp != "" {
- no_lines, _ := strings.replace_all(tmp, "//", "", context.temp_allocator)
- no_begin_comments, _ := strings.replace_all(no_lines, "/*", "", context.temp_allocator)
- no_end_comments, _ := strings.replace_all(no_begin_comments, "*/", "", context.temp_allocator)
+ no_lines, _ := strings.replace_all(
+ tmp,
+ "//",
+ "",
+ context.temp_allocator,
+ )
+ no_begin_comments, _ := strings.replace_all(
+ no_lines,
+ "/*",
+ "",
+ context.temp_allocator,
+ )
+ no_end_comments, _ := strings.replace_all(
+ no_begin_comments,
+ "*/",
+ "",
+ context.temp_allocator,
+ )
return strings.clone(no_end_comments, allocator)
}
}
@@ -265,7 +315,7 @@ get_doc :: proc(comment: ^ast.Comment_Group, allocator: mem.Allocator) -> string
return ""
}
-free_ast :: proc{
+free_ast :: proc {
free_ast_node,
free_ast_array,
free_ast_dynamic_array,
@@ -291,7 +341,10 @@ free_ast_array :: proc(array: $A/[]^$T, allocator: mem.Allocator) {
delete(array, allocator)
}
-free_ast_dynamic_array :: proc(array: $A/[dynamic]^$T, allocator: mem.Allocator) {
+free_ast_dynamic_array :: proc(
+ array: $A/[dynamic]^$T,
+ allocator: mem.Allocator,
+) {
for elem, i in array {
free_ast(elem, allocator)
}
@@ -307,195 +360,195 @@ free_ast_node :: proc(node: ^ast.Node, allocator: mem.Allocator) {
}
if node.derived != nil do #partial switch n in node.derived {
- case ^Bad_Expr:
- case ^Ident:
- case ^Implicit:
- case ^Undef:
- case ^Basic_Directive:
- case ^Basic_Lit:
- case ^Ellipsis:
- free_ast(n.expr, allocator)
- case ^Proc_Lit:
- free_ast(n.type, allocator)
- free_ast(n.body, allocator)
- free_ast(n.where_clauses, allocator)
- case ^Comp_Lit:
- free_ast(n.type, allocator)
- free_ast(n.elems, allocator)
- case ^Tag_Expr:
- free_ast(n.expr, allocator)
- case ^Unary_Expr:
- free_ast(n.expr, allocator)
- case ^Binary_Expr:
- free_ast(n.left, allocator)
- free_ast(n.right, allocator)
- case ^Paren_Expr:
- free_ast(n.expr, allocator)
- case ^Call_Expr:
- free_ast(n.expr, allocator)
- free_ast(n.args, allocator)
- case ^Selector_Expr:
- free_ast(n.expr, allocator)
- free_ast(n.field, allocator)
- case ^Implicit_Selector_Expr:
- free_ast(n.field, allocator)
- case ^Index_Expr:
- free_ast(n.expr, allocator)
- free_ast(n.index, allocator)
- case ^Deref_Expr:
- free_ast(n.expr, allocator)
- case ^Slice_Expr:
- free_ast(n.expr, allocator)
- free_ast(n.low, allocator)
- free_ast(n.high, allocator)
- case ^Field_Value:
- free_ast(n.field, allocator)
- free_ast(n.value, allocator)
- case ^Ternary_If_Expr:
- free_ast(n.x, allocator)
- free_ast(n.cond, allocator)
- free_ast(n.y, allocator)
- case ^Ternary_When_Expr:
- free_ast(n.x, allocator)
- free_ast(n.cond, allocator)
- free_ast(n.y, allocator)
- case ^Type_Assertion:
- free_ast(n.expr, allocator)
- free_ast(n.type, allocator)
- case ^Type_Cast:
- free_ast(n.type, allocator)
- free_ast(n.expr, allocator)
- case ^Auto_Cast:
- free_ast(n.expr, allocator)
- case ^Bad_Stmt:
- case ^Empty_Stmt:
- case ^Expr_Stmt:
- free_ast(n.expr, allocator)
- case ^Tag_Stmt:
- r := cast(^Expr_Stmt)node
- free_ast(r.expr, allocator)
- case ^Assign_Stmt:
- free_ast(n.lhs, allocator)
- free_ast(n.rhs, allocator)
- case ^Block_Stmt:
- free_ast(n.label, allocator)
- free_ast(n.stmts, allocator)
- case ^If_Stmt:
- free_ast(n.label, allocator)
- free_ast(n.init, allocator)
- free_ast(n.cond, allocator)
- free_ast(n.body, allocator)
- free_ast(n.else_stmt, allocator)
- case ^When_Stmt:
- free_ast(n.cond, allocator)
- free_ast(n.body, allocator)
- free_ast(n.else_stmt, allocator)
- case ^Return_Stmt:
- free_ast(n.results, allocator)
- case ^Defer_Stmt:
- free_ast(n.stmt, allocator)
- case ^For_Stmt:
- free_ast(n.label, allocator)
- free_ast(n.init, allocator)
- free_ast(n.cond, allocator)
- free_ast(n.post, allocator)
- free_ast(n.body, allocator)
- case ^Range_Stmt:
- free_ast(n.label, allocator)
- free_ast(n.vals, allocator)
- free_ast(n.expr, allocator)
- free_ast(n.body, allocator)
- case ^Case_Clause:
- free_ast(n.list, allocator)
- free_ast(n.body, allocator)
- case ^Switch_Stmt:
- free_ast(n.label, allocator)
- free_ast(n.init, allocator)
- free_ast(n.cond, allocator)
- free_ast(n.body, allocator)
- case ^Type_Switch_Stmt:
- free_ast(n.label, allocator)
- free_ast(n.tag, allocator)
- free_ast(n.expr, allocator)
- free_ast(n.body, allocator)
- case ^Branch_Stmt:
- free_ast(n.label, allocator)
- case ^Using_Stmt:
- free_ast(n.list, allocator)
- case ^Bad_Decl:
- case ^Value_Decl:
- free_ast(n.attributes, allocator)
- free_ast(n.names, allocator)
- free_ast(n.type, allocator)
- free_ast(n.values, allocator)
- case ^Package_Decl:
- case ^Import_Decl:
- case ^Foreign_Block_Decl:
- free_ast(n.attributes, allocator)
- free_ast(n.foreign_library, allocator)
- free_ast(n.body, allocator)
- case ^Foreign_Import_Decl:
- free_ast(n.name, allocator)
- free_ast(n.attributes, allocator)
- case ^Proc_Group:
- free_ast(n.args, allocator)
- case ^Attribute:
- free_ast(n.elems, allocator)
- case ^Field:
- free_ast(n.names, allocator)
- free_ast(n.type, allocator)
- free_ast(n.default_value, allocator)
- //free_ast(n.docs);
- //free_ast(n.comment);
- case ^Field_List:
- free_ast(n.list, allocator)
- case ^Typeid_Type:
- free_ast(n.specialization, allocator)
- case ^Helper_Type:
- free_ast(n.type, allocator)
- case ^Distinct_Type:
- free_ast(n.type, allocator)
- case ^Poly_Type:
- free_ast(n.type, allocator)
- free_ast(n.specialization, allocator)
- case ^Proc_Type:
- free_ast(n.params, allocator)
- free_ast(n.results, allocator)
- case ^Pointer_Type:
- free_ast(n.elem, allocator)
- case ^Array_Type:
- free_ast(n.len, allocator)
- free_ast(n.elem, allocator)
- free_ast(n.tag, allocator)
- case ^Dynamic_Array_Type:
- free_ast(n.elem, allocator)
- free_ast(n.tag, allocator)
- case ^Struct_Type:
- free_ast(n.poly_params, allocator)
- free_ast(n.align, allocator)
- free_ast(n.fields, allocator)
- free_ast(n.where_clauses, allocator)
- case ^Union_Type:
- free_ast(n.poly_params, allocator)
- free_ast(n.align, allocator)
- free_ast(n.variants, allocator)
- free_ast(n.where_clauses, allocator)
- case ^Enum_Type:
- free_ast(n.base_type, allocator)
- free_ast(n.fields, allocator)
- case ^Bit_Set_Type:
- free_ast(n.elem, allocator)
- free_ast(n.underlying, allocator)
- case ^Map_Type:
- free_ast(n.key, allocator)
- free_ast(n.value, allocator)
- case ^Multi_Pointer_Type:
- free_ast(n.elem, allocator)
- case ^Matrix_Type:
- free_ast(n.elem, allocator)
- case:
- panic(fmt.aprintf("free Unhandled node kind: %T", n))
- }
+ case ^Bad_Expr:
+ case ^Ident:
+ case ^Implicit:
+ case ^Undef:
+ case ^Basic_Directive:
+ case ^Basic_Lit:
+ case ^Ellipsis:
+ free_ast(n.expr, allocator)
+ case ^Proc_Lit:
+ free_ast(n.type, allocator)
+ free_ast(n.body, allocator)
+ free_ast(n.where_clauses, allocator)
+ case ^Comp_Lit:
+ free_ast(n.type, allocator)
+ free_ast(n.elems, allocator)
+ case ^Tag_Expr:
+ free_ast(n.expr, allocator)
+ case ^Unary_Expr:
+ free_ast(n.expr, allocator)
+ case ^Binary_Expr:
+ free_ast(n.left, allocator)
+ free_ast(n.right, allocator)
+ case ^Paren_Expr:
+ free_ast(n.expr, allocator)
+ case ^Call_Expr:
+ free_ast(n.expr, allocator)
+ free_ast(n.args, allocator)
+ case ^Selector_Expr:
+ free_ast(n.expr, allocator)
+ free_ast(n.field, allocator)
+ case ^Implicit_Selector_Expr:
+ free_ast(n.field, allocator)
+ case ^Index_Expr:
+ free_ast(n.expr, allocator)
+ free_ast(n.index, allocator)
+ case ^Deref_Expr:
+ free_ast(n.expr, allocator)
+ case ^Slice_Expr:
+ free_ast(n.expr, allocator)
+ free_ast(n.low, allocator)
+ free_ast(n.high, allocator)
+ case ^Field_Value:
+ free_ast(n.field, allocator)
+ free_ast(n.value, allocator)
+ case ^Ternary_If_Expr:
+ free_ast(n.x, allocator)
+ free_ast(n.cond, allocator)
+ free_ast(n.y, allocator)
+ case ^Ternary_When_Expr:
+ free_ast(n.x, allocator)
+ free_ast(n.cond, allocator)
+ free_ast(n.y, allocator)
+ case ^Type_Assertion:
+ free_ast(n.expr, allocator)
+ free_ast(n.type, allocator)
+ case ^Type_Cast:
+ free_ast(n.type, allocator)
+ free_ast(n.expr, allocator)
+ case ^Auto_Cast:
+ free_ast(n.expr, allocator)
+ case ^Bad_Stmt:
+ case ^Empty_Stmt:
+ case ^Expr_Stmt:
+ free_ast(n.expr, allocator)
+ case ^Tag_Stmt:
+ r := cast(^Expr_Stmt)node
+ free_ast(r.expr, allocator)
+ case ^Assign_Stmt:
+ free_ast(n.lhs, allocator)
+ free_ast(n.rhs, allocator)
+ case ^Block_Stmt:
+ free_ast(n.label, allocator)
+ free_ast(n.stmts, allocator)
+ case ^If_Stmt:
+ free_ast(n.label, allocator)
+ free_ast(n.init, allocator)
+ free_ast(n.cond, allocator)
+ free_ast(n.body, allocator)
+ free_ast(n.else_stmt, allocator)
+ case ^When_Stmt:
+ free_ast(n.cond, allocator)
+ free_ast(n.body, allocator)
+ free_ast(n.else_stmt, allocator)
+ case ^Return_Stmt:
+ free_ast(n.results, allocator)
+ case ^Defer_Stmt:
+ free_ast(n.stmt, allocator)
+ case ^For_Stmt:
+ free_ast(n.label, allocator)
+ free_ast(n.init, allocator)
+ free_ast(n.cond, allocator)
+ free_ast(n.post, allocator)
+ free_ast(n.body, allocator)
+ case ^Range_Stmt:
+ free_ast(n.label, allocator)
+ free_ast(n.vals, allocator)
+ free_ast(n.expr, allocator)
+ free_ast(n.body, allocator)
+ case ^Case_Clause:
+ free_ast(n.list, allocator)
+ free_ast(n.body, allocator)
+ case ^Switch_Stmt:
+ free_ast(n.label, allocator)
+ free_ast(n.init, allocator)
+ free_ast(n.cond, allocator)
+ free_ast(n.body, allocator)
+ case ^Type_Switch_Stmt:
+ free_ast(n.label, allocator)
+ free_ast(n.tag, allocator)
+ free_ast(n.expr, allocator)
+ free_ast(n.body, allocator)
+ case ^Branch_Stmt:
+ free_ast(n.label, allocator)
+ case ^Using_Stmt:
+ free_ast(n.list, allocator)
+ case ^Bad_Decl:
+ case ^Value_Decl:
+ free_ast(n.attributes, allocator)
+ free_ast(n.names, allocator)
+ free_ast(n.type, allocator)
+ free_ast(n.values, allocator)
+ case ^Package_Decl:
+ case ^Import_Decl:
+ case ^Foreign_Block_Decl:
+ free_ast(n.attributes, allocator)
+ free_ast(n.foreign_library, allocator)
+ free_ast(n.body, allocator)
+ case ^Foreign_Import_Decl:
+ free_ast(n.name, allocator)
+ free_ast(n.attributes, allocator)
+ case ^Proc_Group:
+ free_ast(n.args, allocator)
+ case ^Attribute:
+ free_ast(n.elems, allocator)
+ case ^Field:
+ free_ast(n.names, allocator)
+ free_ast(n.type, allocator)
+ free_ast(n.default_value, allocator)
+ //free_ast(n.docs);
+ //free_ast(n.comment);
+ case ^Field_List:
+ free_ast(n.list, allocator)
+ case ^Typeid_Type:
+ free_ast(n.specialization, allocator)
+ case ^Helper_Type:
+ free_ast(n.type, allocator)
+ case ^Distinct_Type:
+ free_ast(n.type, allocator)
+ case ^Poly_Type:
+ free_ast(n.type, allocator)
+ free_ast(n.specialization, allocator)
+ case ^Proc_Type:
+ free_ast(n.params, allocator)
+ free_ast(n.results, allocator)
+ case ^Pointer_Type:
+ free_ast(n.elem, allocator)
+ case ^Array_Type:
+ free_ast(n.len, allocator)
+ free_ast(n.elem, allocator)
+ free_ast(n.tag, allocator)
+ case ^Dynamic_Array_Type:
+ free_ast(n.elem, allocator)
+ free_ast(n.tag, allocator)
+ case ^Struct_Type:
+ free_ast(n.poly_params, allocator)
+ free_ast(n.align, allocator)
+ free_ast(n.fields, allocator)
+ free_ast(n.where_clauses, allocator)
+ case ^Union_Type:
+ free_ast(n.poly_params, allocator)
+ free_ast(n.align, allocator)
+ free_ast(n.variants, allocator)
+ free_ast(n.where_clauses, allocator)
+ case ^Enum_Type:
+ free_ast(n.base_type, allocator)
+ free_ast(n.fields, allocator)
+ case ^Bit_Set_Type:
+ free_ast(n.elem, allocator)
+ free_ast(n.underlying, allocator)
+ case ^Map_Type:
+ free_ast(n.key, allocator)
+ free_ast(n.value, allocator)
+ case ^Multi_Pointer_Type:
+ free_ast(n.elem, allocator)
+ case ^Matrix_Type:
+ free_ast(n.elem, allocator)
+ case:
+ panic(fmt.aprintf("free Unhandled node kind: %T", n))
+ }
mem.free(node, allocator)
}
@@ -516,7 +569,7 @@ free_ast_file :: proc(file: ast.File, allocator := context.allocator) {
delete(file.decls)
}
-node_equal :: proc{
+node_equal :: proc {
node_equal_node,
node_equal_array,
node_equal_dynamic_array,
@@ -722,37 +775,52 @@ node_to_string :: proc(node: ^ast.Node, remove_pointers := false) -> string {
return strings.to_string(builder)
}
-build_string :: proc{
+build_string :: proc {
build_string_ast_array,
build_string_dynamic_array,
build_string_node,
}
-build_string_dynamic_array :: proc(array: $A/[]^$T, builder: ^strings.Builder, remove_pointers: bool) {
+build_string_dynamic_array :: proc(
+ array: $A/[]^$T,
+ builder: ^strings.Builder,
+ remove_pointers: bool,
+) {
for elem, i in array {
build_string(elem, builder, remove_pointers)
}
}
-build_string_ast_array :: proc(array: $A/[dynamic]^$T, builder: ^strings.Builder, remove_pointers: bool) {
+build_string_ast_array :: proc(
+ array: $A/[dynamic]^$T,
+ builder: ^strings.Builder,
+ remove_pointers: bool,
+) {
for elem, i in array {
build_string(elem, builder, remove_pointers)
}
}
-build_string_node :: proc(node: ^ast.Node, builder: ^strings.Builder, remove_pointers: bool) {
-
+build_string_node :: proc(
+ node: ^ast.Node,
+ builder: ^strings.Builder,
+ remove_pointers: bool,
+) {
+
using ast
-
+
if node == nil {
return
}
-
+
#partial switch n in node.derived {
case ^Bad_Expr:
case ^Ident:
if strings.contains(n.name, "/") {
- strings.write_string(builder, path.base(n.name, false, context.temp_allocator))
+ strings.write_string(
+ builder,
+ path.base(n.name, false, context.temp_allocator),
+ )
} else {
strings.write_string(builder, n.name)
}
@@ -760,7 +828,7 @@ build_string_node :: proc(node: ^ast.Node, builder: ^strings.Builder, remove_poi
strings.write_string(builder, n.tok.text)
case ^Undef:
case ^Basic_Lit:
- strings.write_string(builder, n.tok.text)
+ strings.write_string(builder, n.tok.text)
case ^Basic_Directive:
strings.write_string(builder, n.name)
case ^Implicit_Selector_Expr:
@@ -850,7 +918,7 @@ build_string_node :: proc(node: ^ast.Node, builder: ^strings.Builder, remove_poi
} else {
build_string(n.type, builder, remove_pointers)
}
-
+
build_string(n.default_value, builder, remove_pointers)
case ^Field_List:
for field, i in n.list {
@@ -919,7 +987,11 @@ build_string_node :: proc(node: ^ast.Node, builder: ^strings.Builder, remove_poi
}
}
-repeat :: proc(value: string, count: int, allocator := context.allocator) -> string {
+repeat :: proc(
+ value: string,
+ count: int,
+ allocator := context.allocator,
+) -> string {
if count == 0 {
return ""
}
diff --git a/src/common/config.odin b/src/common/config.odin
index b4114c0..62e80cc 100644
--- a/src/common/config.odin
+++ b/src/common/config.odin
@@ -11,7 +11,7 @@ Config :: struct {
enable_format: bool,
enable_hover: bool,
enable_document_symbols: bool,
- enable_semantic_tokens: bool,
+ enable_semantic_tokens: bool,
enable_inlay_hints: bool,
enable_procedure_context: bool,
enable_snippets: bool,
@@ -24,4 +24,4 @@ Config :: struct {
checker_args: string,
}
-config: Config; \ No newline at end of file
+config: Config
diff --git a/src/common/fuzzy.odin b/src/common/fuzzy.odin
index 04bb0ad..c425051 100644
--- a/src/common/fuzzy.odin
+++ b/src/common/fuzzy.odin
@@ -52,6 +52,7 @@ FuzzyMatcher :: struct {
word_role: [max_word]FuzzyCharRole,
}
+//odinfmt: disable
char_roles: []u8 = {
// clang-format off
// Curr= Empty Lower Upper Separ
@@ -76,6 +77,8 @@ char_types: []u8 = {
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
}
+//odinfmt: enable
+
make_fuzzy_matcher :: proc(pattern: string, allocator := context.temp_allocator) -> ^FuzzyMatcher {
matcher := new(FuzzyMatcher, allocator)
diff --git a/src/common/position.odin b/src/common/position.odin
index e8c5ff2..5d2ae4f 100644
--- a/src/common/position.odin
+++ b/src/common/position.odin
@@ -33,7 +33,13 @@ AbsoluteRange :: struct {
AbsolutePosition :: int
-get_absolute_position :: proc(position: Position, document_text: []u8) -> (AbsolutePosition, bool) {
+get_absolute_position :: proc(
+ position: Position,
+ document_text: []u8,
+) -> (
+ AbsolutePosition,
+ bool,
+) {
absolute: AbsolutePosition
if len(document_text) == 0 {
@@ -45,16 +51,31 @@ get_absolute_position :: proc(position: Position, document_text: []u8) -> (Absol
index := 1
last := document_text[0]
- if !get_index_at_line(&index, &line_count, &last, document_text, position.line) {
+ if !get_index_at_line(
+ &index,
+ &line_count,
+ &last,
+ document_text,
+ position.line,
+ ) {
return absolute, false
}
- absolute = index + get_character_offset_u16_to_u8(position.character, document_text[index:])
+ absolute =
+ index +
+ get_character_offset_u16_to_u8(
+ position.character,
+ document_text[index:],
+ )
return absolute, true
}
-get_relative_token_position :: proc(offset: int, document_text: []u8, current_start: int) -> Position {
+get_relative_token_position :: proc(
+ offset: int,
+ document_text: []u8,
+ current_start: int,
+) -> Position {
start_index := current_start
data := document_text[start_index:]
@@ -66,10 +87,10 @@ get_relative_token_position :: proc(offset: int, document_text: []u8, current_st
for i + start_index < offset {
r, w := utf8.decode_rune(data[i:])
- if r == '\n' { //\r?
+ if r == '\n' { //\r?
position.character = 0
position.line += 1
- i += 1
+ i += 1
} else if w == 0 {
return position
} else {
@@ -95,7 +116,10 @@ get_token_range :: proc(node: ast.Node, document_text: string) -> Range {
go_backwards_to_endline :: proc(offset: int, document_text: []u8) -> int {
index := offset
- for index > 0 && document_text[index] != '\n' && document_text[index] != '\r' {
+ for
+ index > 0 &&
+ document_text[index] != '\n' &&
+ document_text[index] != '\r' {
index -= 1
}
@@ -112,34 +136,60 @@ get_token_range :: proc(node: ast.Node, document_text: string) -> Range {
offset := go_backwards_to_endline(pos_offset, transmute([]u8)document_text)
range.start.line = node.pos.line - 1
- range.start.character = get_character_offset_u8_to_u16(node.pos.column - 1, transmute([]u8)document_text[offset:])
+ range.start.character = get_character_offset_u8_to_u16(
+ node.pos.column - 1,
+ transmute([]u8)document_text[offset:],
+ )
- offset = go_backwards_to_endline(end_offset - 1, transmute([]u8)document_text)
+ offset = go_backwards_to_endline(
+ end_offset - 1,
+ transmute([]u8)document_text,
+ )
range.end.line = node.end.line - 1
- range.end.character = get_character_offset_u8_to_u16(node.end.column - 1, transmute([]u8)document_text[offset:])
+ range.end.character = get_character_offset_u8_to_u16(
+ node.end.column - 1,
+ transmute([]u8)document_text[offset:],
+ )
return range
}
-get_absolute_range :: proc(range: Range, document_text: []u8) -> (AbsoluteRange, bool) {
+get_absolute_range :: proc(
+ range: Range,
+ document_text: []u8,
+) -> (
+ AbsoluteRange,
+ bool,
+) {
absolute: AbsoluteRange
if len(document_text) == 0 {
absolute.start = 0
- absolute.end = 0
+ absolute.end = 0
return absolute, true
}
line_count := 0
- index := 1
- last := document_text[0]
+ index := 1
+ last := document_text[0]
- if !get_index_at_line(&index, &line_count, &last, document_text, range.start.line) {
+ if !get_index_at_line(
+ &index,
+ &line_count,
+ &last,
+ document_text,
+ range.start.line,
+ ) {
return absolute, false
}
- absolute.start = index + get_character_offset_u16_to_u8(range.start.character, document_text[index:])
+ absolute.start =
+ index +
+ get_character_offset_u16_to_u8(
+ range.start.character,
+ document_text[index:],
+ )
//if the last line was indexed at zero we have to move it back to index 1.
//This happens when line = 0
@@ -147,16 +197,33 @@ get_absolute_range :: proc(range: Range, document_text: []u8) -> (AbsoluteRange,
index = 1
}
- if !get_index_at_line(&index, &line_count, &last, document_text, range.end.line) {
+ if !get_index_at_line(
+ &index,
+ &line_count,
+ &last,
+ document_text,
+ range.end.line,
+ ) {
return absolute, false
}
- absolute.end = index + get_character_offset_u16_to_u8(range.end.character, document_text[index:])
+ absolute.end =
+ index +
+ get_character_offset_u16_to_u8(
+ range.end.character,
+ document_text[index:],
+ )
return absolute, true
}
-get_index_at_line :: proc(current_index: ^int, current_line: ^int, last: ^u8, document_text: []u8, end_line: int) -> bool {
+get_index_at_line :: proc(
+ current_index: ^int,
+ current_line: ^int,
+ last: ^u8,
+ document_text: []u8,
+ end_line: int,
+) -> bool {
if end_line == 0 {
current_index^ = 0
return true
@@ -193,8 +260,11 @@ get_index_at_line :: proc(current_index: ^int, current_line: ^int, last: ^u8, do
return false
}
-get_character_offset_u16_to_u8 :: proc(character_offset: int, document_text: []u8) -> int {
- utf8_idx := 0
+get_character_offset_u16_to_u8 :: proc(
+ character_offset: int,
+ document_text: []u8,
+) -> int {
+ utf8_idx := 0
utf16_idx := 0
for utf16_idx < character_offset {
@@ -216,8 +286,11 @@ get_character_offset_u16_to_u8 :: proc(character_offset: int, document_text: []u
return utf8_idx
}
-get_character_offset_u8_to_u16 :: proc(character_offset: int, document_text: []u8) -> int {
- utf8_idx := 0
+get_character_offset_u8_to_u16 :: proc(
+ character_offset: int,
+ document_text: []u8,
+) -> int {
+ utf8_idx := 0
utf16_idx := 0
for utf8_idx < character_offset {
@@ -237,4 +310,4 @@ get_character_offset_u8_to_u16 :: proc(character_offset: int, document_text: []u
}
return utf16_idx
-} \ No newline at end of file
+}
diff --git a/src/common/types.odin b/src/common/types.odin
index 8481f50..e95b86a 100644
--- a/src/common/types.odin
+++ b/src/common/types.odin
@@ -24,4 +24,4 @@ WorkspaceFolder :: struct {
}
parser_warning_handler :: proc(pos: tokenizer.Pos, msg: string, args: ..any) {
-} \ No newline at end of file
+}
diff --git a/src/common/uri.odin b/src/common/uri.odin
index 4dbed0f..0e2c705 100644
--- a/src/common/uri.odin
+++ b/src/common/uri.odin
@@ -14,7 +14,6 @@ Uri :: struct {
}
//Note(Daniel, This is an extremely incomplete uri parser and for now ignores fragment and query and only handles file schema)
-
parse_uri :: proc(value: string, allocator: mem.Allocator) -> (Uri, bool) {
uri: Uri
@@ -57,7 +56,10 @@ create_uri :: proc(path: string, allocator: mem.Allocator) -> Uri {
strings.write_string(&builder, "file://")
}
- strings.write_string(&builder, encode_percent(path_forward, context.temp_allocator))
+ strings.write_string(
+ &builder,
+ encode_percent(path_forward, context.temp_allocator),
+ )
uri: Uri
@@ -89,8 +91,13 @@ encode_percent :: proc(value: string, allocator: mem.Allocator) -> string {
if r > 127 || r == ':' {
for i := 0; i < w; i += 1 {
- strings.write_string(&builder, strings.concatenate({"%", fmt.tprintf("%X", data[index + i])},
- context.temp_allocator))
+ strings.write_string(
+ &builder,
+ strings.concatenate(
+ {"%", fmt.tprintf("%X", data[index + i])},
+ context.temp_allocator,
+ ),
+ )
}
} else {
strings.write_byte(&builder, data[index])
@@ -118,7 +125,13 @@ starts_with :: proc(value: string, starts_with: string) -> bool {
}
@(private)
-decode_percent :: proc(value: string, allocator: mem.Allocator) -> (string, bool) {
+decode_percent :: proc(
+ value: string,
+ allocator: mem.Allocator,
+) -> (
+ string,
+ bool,
+) {
builder := strings.builder_make(allocator)
for i := 0; i < len(value); i += 1 {
diff --git a/src/common/util.odin b/src/common/util.odin
index aa113ae..0466b6e 100644
--- a/src/common/util.odin
+++ b/src/common/util.odin
@@ -22,14 +22,22 @@ lookup_in_path :: proc(name: string) -> (string, bool) {
for directory in strings.split_iterator(&path, delimiter) {
when ODIN_OS == .Windows {
- name := filepath.join(elems = {directory, fmt.tprintf("%v.exe", name)}, allocator = context.temp_allocator)
+ name := filepath.join(
+ elems = {directory, fmt.tprintf("%v.exe", name)},
+ allocator = context.temp_allocator,
+ )
if os.exists(name) {
return name, true
}
} else {
- name := filepath.join(elems = {directory, name}, allocator = context.temp_allocator)
+ name := filepath.join(
+ elems = {directory, name},
+ allocator = context.temp_allocator,
+ )
if os.exists(name) {
- if info, err := os.stat(name, context.temp_allocator); err == os.ERROR_NONE && (File_Mode_User_Executable & info.mode) != 0 {
+ if info, err := os.stat(name, context.temp_allocator);
+ err == os.ERROR_NONE &&
+ (File_Mode_User_Executable & info.mode) != 0 {
return name, true
}
}
@@ -42,30 +50,39 @@ lookup_in_path :: proc(name: string) -> (string, bool) {
when ODIN_OS == .Darwin || ODIN_OS == .Linux {
FILE :: struct {}
- run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte) {
- fp := popen(strings.clone_to_cstring(command, context.temp_allocator), "r")
+ run_executable :: proc(
+ command: string,
+ stdout: ^[]byte,
+ ) -> (
+ u32,
+ bool,
+ []byte,
+ ) {
+ fp := popen(
+ strings.clone_to_cstring(command, context.temp_allocator),
+ "r",
+ )
if fp == nil {
return 0, false, stdout[0:]
}
defer pclose(fp)
-
+
read_buffer: [50]byte
index: int
-
+
for fgets(&read_buffer[0], size_of(read_buffer), fp) != nil {
read := bytes.index_byte(read_buffer[:], 0)
defer index += cast(int)read
-
+
if read > 0 && index + cast(int)read <= len(stdout) {
mem.copy(&stdout[index], &read_buffer[0], cast(int)read)
}
}
-
-
-
+
+
return 0, true, stdout[0:index]
}
-
+
foreign libc
{
popen :: proc(command: cstring, type: cstring) -> ^FILE ---
diff --git a/src/common/util_windows.odin b/src/common/util_windows.odin
index 23a58cd..59a9bcf 100644
--- a/src/common/util_windows.odin
+++ b/src/common/util_windows.odin
@@ -27,19 +27,34 @@ foreign kernel32 {
) -> u32 ---
}
-get_case_sensitive_path :: proc(path: string, allocator := context.temp_allocator) -> string {
+get_case_sensitive_path :: proc(
+ path: string,
+ allocator := context.temp_allocator,
+) -> string {
wide := win32.utf8_to_utf16(path)
- file := win32.CreateFileW(&wide[0], 0, win32.FILE_SHARE_READ, nil, win32.OPEN_EXISTING, win32.FILE_FLAG_BACKUP_SEMANTICS, nil)
-
- if(file == win32.INVALID_HANDLE)
- {
+ file := win32.CreateFileW(
+ &wide[0],
+ 0,
+ win32.FILE_SHARE_READ,
+ nil,
+ win32.OPEN_EXISTING,
+ win32.FILE_FLAG_BACKUP_SEMANTICS,
+ nil,
+ )
+
+ if (file == win32.INVALID_HANDLE) {
log_last_error()
- return "";
- }
+ return ""
+ }
buffer := make([]u16, 512, context.temp_allocator)
- ret := win32.GetFinalPathNameByHandleW(file, &buffer[0], cast(u32)len(buffer), 0)
+ ret := win32.GetFinalPathNameByHandleW(
+ file,
+ &buffer[0],
+ cast(u32)len(buffer),
+ 0,
+ )
res, _ := win32.utf16_to_utf8(buffer[4:], allocator)
@@ -56,21 +71,29 @@ log_last_error :: proc() {
error_string := cstring(&err_text[0])
if (format_message_a(
- FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- nil,
- err,
- (1 << 10) | 0,
- error_string,
- len(err_text) - 1,
- nil,
- ) != 0) {
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ nil,
+ err,
+ (1 << 10) | 0,
+ error_string,
+ len(err_text) - 1,
+ nil,
+ ) !=
+ 0) {
log.error(error_string)
}
}
-run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte) {
- stdout_read: win32.HANDLE
+run_executable :: proc(
+ command: string,
+ stdout: ^[]byte,
+) -> (
+ u32,
+ bool,
+ []byte,
+) {
+ stdout_read: win32.HANDLE
stdout_write: win32.HANDLE
attributes: win32.SECURITY_ATTRIBUTES
@@ -95,21 +118,38 @@ run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte)
startup_info.hStdOutput = stdout_write
startup_info.dwFlags |= win32.STARTF_USESTDHANDLES
- if !win32.CreateProcessW(nil, &win32.utf8_to_utf16(command)[0], nil, nil, true, 0, nil, nil, &startup_info, &process_info) {
+ if !win32.CreateProcessW(
+ nil,
+ &win32.utf8_to_utf16(command)[0],
+ nil,
+ nil,
+ true,
+ 0,
+ nil,
+ nil,
+ &startup_info,
+ &process_info,
+ ) {
return 0, false, stdout[0:]
}
win32.CloseHandle(stdout_write)
index: int
- read: u32
+ read: u32
read_buffer: [50]byte
success: win32.BOOL = true
for success {
- success = win32.ReadFile(stdout_read, &read_buffer[0], len(read_buffer), &read, nil)
+ success = win32.ReadFile(
+ stdout_read,
+ &read_buffer[0],
+ len(read_buffer),
+ &read,
+ nil,
+ )
if read > 0 && index + cast(int)read <= len(stdout) {
mem.copy(&stdout[index], &read_buffer[0], cast(int)read)
@@ -135,4 +175,4 @@ run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte)
import "core:mem/virtual"
Growing_Arena :: virtual.Growing_Arena
-growing_arena_allocator :: virtual.growing_arena_allocator \ No newline at end of file
+growing_arena_allocator :: virtual.growing_arena_allocator