From 34a048f7daaf93b16ae4121bf5238f9008f3465b Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 9 Dec 2022 11:29:28 +0000 Subject: Replace compiler for loops for the hash-table types to simplify code usage --- src/string_map.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/string_map.cpp') diff --git a/src/string_map.cpp b/src/string_map.cpp index 218a45482..e2a4d5f65 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -30,6 +30,8 @@ struct StringMapEntry { template struct StringMap { + using K = String; + using V = T; Slice hashes; Array > entries; }; @@ -270,3 +272,24 @@ gb_inline void string_map_clear(StringMap *h) { } } + + +template +StringMapEntry *begin(StringMap &m) { + return m.entries.data; +} +template +StringMapEntry const *begin(StringMap const &m) { + return m.entries.data; +} + + +template +StringMapEntry *end(StringMap &m) { + return m.entries.data + m.entries.count; +} + +template +StringMapEntry const *end(StringMap const &m) { + return m.entries.data + m.entries.count; +} \ No newline at end of file -- cgit v1.2.3 From ac5f5a33e94054396de66a37043e226349b6c91c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 21:17:07 +0000 Subject: `gb_internal` a lot --- src/array.cpp | 150 +++++++-------- src/big_int.cpp | 158 ++++++++-------- src/build_settings.cpp | 83 ++++----- src/common.cpp | 90 ++++----- src/common_memory.cpp | 74 ++++---- src/error.cpp | 62 +++---- src/exact_value.cpp | 90 ++++----- src/main.cpp | 42 ++--- src/microsoft_craziness.h | 40 ++-- src/parser.cpp | 460 +++++++++++++++++++++++----------------------- src/parser.hpp | 30 +-- src/parser_pos.cpp | 4 +- src/priority_queue.cpp | 14 +- src/ptr_map.cpp | 84 ++++----- src/ptr_set.cpp | 54 +++--- src/queue.cpp | 12 +- src/range_cache.cpp | 10 +- src/string.cpp | 124 ++++++------- src/string_map.cpp | 82 ++++----- src/thread_pool.cpp | 20 +- src/threading.cpp | 192 +++++++++---------- src/timings.cpp | 36 ++-- src/tokenizer.cpp | 70 +++---- src/types.cpp | 241 ++++++++++-------------- src/unicode.cpp | 10 +- 25 files changed, 1091 insertions(+), 1141 deletions(-) (limited to 'src/string_map.cpp') diff --git a/src/array.cpp b/src/array.cpp index d08bd647f..c633078f6 100644 --- a/src/array.cpp +++ b/src/array.cpp @@ -23,32 +23,32 @@ struct Array { } }; -template void array_init (Array *array, gbAllocator const &a); -template void array_init (Array *array, gbAllocator const &a, isize count); -template void array_init (Array *array, gbAllocator const &a, isize count, isize capacity); -template Array array_make (gbAllocator const &a); -template Array array_make (gbAllocator const &a, isize count); -template Array array_make (gbAllocator const &a, isize count, isize capacity); -template Array array_make_from_ptr (T *data, isize count, isize capacity); -template void array_free (Array *array); -template void array_add (Array *array, T const &t); -template T * array_add_and_get (Array *array); -template void array_add_elems (Array *array, T const *elems, isize elem_count); -template T array_pop (Array *array); -template void array_clear (Array *array); -template void array_reserve (Array *array, isize capacity); -template void array_resize (Array *array, isize count); -template void array_set_capacity (Array *array, isize capacity); -template Array array_slice (Array const &array, isize lo, isize hi); -template Array array_clone (gbAllocator const &a, Array const &array); - -template void array_ordered_remove (Array *array, isize index); -template void array_unordered_remove(Array *array, isize index); - -template void array_copy(Array *array, Array const &data, isize offset); -template void array_copy(Array *array, Array const &data, isize offset, isize count); - -template T *array_end_ptr(Array *array); +template gb_internal void array_init (Array *array, gbAllocator const &a); +template gb_internal void array_init (Array *array, gbAllocator const &a, isize count); +template gb_internal void array_init (Array *array, gbAllocator const &a, isize count, isize capacity); +template gb_internal Array array_make (gbAllocator const &a); +template gb_internal Array array_make (gbAllocator const &a, isize count); +template gb_internal Array array_make (gbAllocator const &a, isize count, isize capacity); +template gb_internal Array array_make_from_ptr (T *data, isize count, isize capacity); +template gb_internal void array_free (Array *array); +template gb_internal void array_add (Array *array, T const &t); +template gb_internal T * array_add_and_get (Array *array); +template gb_internal void array_add_elems (Array *array, T const *elems, isize elem_count); +template gb_internal T array_pop (Array *array); +template gb_internal void array_clear (Array *array); +template gb_internal void array_reserve (Array *array, isize capacity); +template gb_internal void array_resize (Array *array, isize count); +template gb_internal void array_set_capacity (Array *array, isize capacity); +template gb_internal Array array_slice (Array const &array, isize lo, isize hi); +template gb_internal Array array_clone (gbAllocator const &a, Array const &array); + +template gb_internal void array_ordered_remove (Array *array, isize index); +template gb_internal void array_unordered_remove(Array *array, isize index); + +template gb_internal void array_copy(Array *array, Array const &data, isize offset); +template gb_internal void array_copy(Array *array, Array const &data, isize offset, isize count); + +template gb_internal T *array_end_ptr(Array *array); template @@ -56,14 +56,14 @@ struct Slice { T *data; isize count; - T &operator[](isize index) { + gb_inline T &operator[](isize index) { #if !defined(NO_ARRAY_BOUNDS_CHECK) GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count); #endif return data[index]; } - T const &operator[](isize index) const { + gb_inline T const &operator[](isize index) const { #if !defined(NO_ARRAY_BOUNDS_CHECK) GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count); #endif @@ -71,12 +71,12 @@ struct Slice { } }; -template Slice slice_from_array(Array const &a); +template gb_internal Slice slice_from_array(Array const &a); template -Slice slice_make(gbAllocator const &allocator, isize count) { +gb_internal Slice slice_make(gbAllocator const &allocator, isize count) { GB_ASSERT(count >= 0); Slice s = {}; s.data = gb_alloc_array(allocator, T, count); @@ -86,7 +86,7 @@ Slice slice_make(gbAllocator const &allocator, isize count) { } template -void slice_init(Slice *s, gbAllocator const &allocator, isize count) { +gb_internal void slice_init(Slice *s, gbAllocator const &allocator, isize count) { GB_ASSERT(count >= 0); s->data = gb_alloc_array(allocator, T, count); if (count > 0) { @@ -96,23 +96,23 @@ void slice_init(Slice *s, gbAllocator const &allocator, isize count) { } template -void slice_free(Slice *s, gbAllocator const &allocator) { +gb_internal void slice_free(Slice *s, gbAllocator const &allocator) { gb_free(allocator, s->data); } template -void slice_resize(Slice *s, gbAllocator const &allocator, isize new_count) { +gb_internal void slice_resize(Slice *s, gbAllocator const &allocator, isize new_count) { resize_array_raw(&s->data, allocator, s->count, new_count); s->count = new_count; } template -Slice slice_from_array(Array const &a) { +gb_internal Slice slice_from_array(Array const &a) { return {a.data, a.count}; } template -Slice slice_array(Array const &array, isize lo, isize hi) { +gb_internal Slice slice_array(Array const &array, isize lo, isize hi) { GB_ASSERT(0 <= lo && lo <= hi && hi <= array.count); Slice out = {}; isize len = hi-lo; @@ -125,30 +125,30 @@ Slice slice_array(Array const &array, isize lo, isize hi) { template -Slice slice_clone(gbAllocator const &allocator, Slice const &a) { +gb_internal Slice slice_clone(gbAllocator const &allocator, Slice const &a) { T *data = cast(T *)gb_alloc_copy_align(allocator, a.data, a.count*gb_size_of(T), gb_align_of(T)); return {data, a.count}; } template -Slice slice_clone_from_array(gbAllocator const &allocator, Array const &a) { +gb_internal Slice slice_clone_from_array(gbAllocator const &allocator, Array const &a) { auto c = array_clone(allocator, a); return {c.data, c.count}; } template -void slice_copy(Slice *slice, Slice const &data) { +gb_internal void slice_copy(Slice *slice, Slice const &data) { isize n = gb_min(slice->count, data.count); gb_memmove(slice->data, data.data, gb_size_of(T)*n); } template -void slice_copy(Slice *slice, Slice const &data, isize offset) { +gb_internal void slice_copy(Slice *slice, Slice const &data, isize offset) { isize n = gb_clamp(slice->count-offset, 0, data.count); gb_memmove(slice->data+offset, data.data, gb_size_of(T)*n); } template -void slice_copy(Slice *slice, Slice const &data, isize offset, isize count) { +gb_internal void slice_copy(Slice *slice, Slice const &data, isize offset, isize count) { isize n = gb_clamp(slice->count-offset, 0, gb_min(data.count, count)); gb_memmove(slice->data+offset, data.data, gb_size_of(T)*n); } @@ -156,7 +156,7 @@ void slice_copy(Slice *slice, Slice const &data, isize offset, isize count template -gb_inline Slice slice(Slice const &array, isize lo, isize hi) { +gb_internal gb_inline Slice slice(Slice const &array, isize lo, isize hi) { GB_ASSERT(0 <= lo && lo <= hi && hi <= array.count); Slice out = {}; isize len = hi-lo; @@ -169,7 +169,7 @@ gb_inline Slice slice(Slice const &array, isize lo, isize hi) { template -void slice_ordered_remove(Slice *array, isize index) { +gb_internal void slice_ordered_remove(Slice *array, isize index) { GB_ASSERT(0 <= index && index < array->count); isize bytes = gb_size_of(T) * (array->count-(index+1)); @@ -178,7 +178,7 @@ void slice_ordered_remove(Slice *array, isize index) { } template -void slice_unordered_remove(Slice *array, isize index) { +gb_internal void slice_unordered_remove(Slice *array, isize index) { GB_ASSERT(0 <= index && index < array->count); isize n = array->count-1; @@ -190,18 +190,18 @@ void slice_unordered_remove(Slice *array, isize index) { template -void array_copy(Array *array, Array const &data, isize offset) { +gb_internal void array_copy(Array *array, Array const &data, isize offset) { gb_memmove(array->data+offset, data.data, gb_size_of(T)*data.count); } template -void array_copy(Array *array, Array const &data, isize offset, isize count) { +gb_internal void array_copy(Array *array, Array const &data, isize offset, isize count) { gb_memmove(array->data+offset, data.data, gb_size_of(T)*gb_min(data.count, count)); } template -T *array_end_ptr(Array *array) { +gb_internal T *array_end_ptr(Array *array) { if (array->count > 0) { return &array->data[array->count-1]; } @@ -210,18 +210,18 @@ T *array_end_ptr(Array *array) { template -gb_inline void array_init(Array *array, gbAllocator const &a) { +gb_internal gb_inline void array_init(Array *array, gbAllocator const &a) { isize cap = ARRAY_GROW_FORMULA(0); array_init(array, a, 0, cap); } template -gb_inline void array_init(Array *array, gbAllocator const &a, isize count) { +gb_internal gb_inline void array_init(Array *array, gbAllocator const &a, isize count) { array_init(array, a, count, count); } template -gb_inline void array_init(Array *array, gbAllocator const &a, isize count, isize capacity) { +gb_internal gb_inline void array_init(Array *array, gbAllocator const &a, isize count, isize capacity) { array->allocator = a; array->data = nullptr; if (capacity > 0) { @@ -234,7 +234,7 @@ gb_inline void array_init(Array *array, gbAllocator const &a, isize count, is template -gb_inline Array array_make_from_ptr(T *data, isize count, isize capacity) { +gb_internal gb_inline Array array_make_from_ptr(T *data, isize count, isize capacity) { Array a = {0}; a.data = data; a.count = count; @@ -244,7 +244,7 @@ gb_inline Array array_make_from_ptr(T *data, isize count, isize capacity) { template -gb_inline Array array_make(gbAllocator const &a) { +gb_internal gb_inline Array array_make(gbAllocator const &a) { isize capacity = ARRAY_GROW_FORMULA(0); Array array = {}; array.allocator = a; @@ -254,7 +254,7 @@ gb_inline Array array_make(gbAllocator const &a) { return array; } template -gb_inline Array array_make(gbAllocator const &a, isize count) { +gb_internal gb_inline Array array_make(gbAllocator const &a, isize count) { Array array = {}; array.allocator = a; array.data = gb_alloc_array(a, T, count); @@ -263,7 +263,7 @@ gb_inline Array array_make(gbAllocator const &a, isize count) { return array; } template -gb_inline Array array_make(gbAllocator const &a, isize count, isize capacity) { +gb_internal gb_inline Array array_make(gbAllocator const &a, isize count, isize capacity) { Array array = {}; array.allocator = a; array.data = gb_alloc_array(a, T, capacity); @@ -275,7 +275,7 @@ gb_inline Array array_make(gbAllocator const &a, isize count, isize capacity) template -gb_inline void array_free(Array *array) { +gb_internal gb_inline void array_free(Array *array) { if (array->allocator.proc != nullptr) { gb_free(array->allocator, array->data); } @@ -284,7 +284,7 @@ gb_inline void array_free(Array *array) { } template -void array__grow(Array *array, isize min_capacity) { +gb_internal void array__grow(Array *array, isize min_capacity) { isize new_capacity = ARRAY_GROW_FORMULA(array->capacity); if (new_capacity < min_capacity) { new_capacity = min_capacity; @@ -293,7 +293,7 @@ void array__grow(Array *array, isize min_capacity) { } template -void array_add(Array *array, T const &t) { +gb_internal void array_add(Array *array, T const &t) { if (array->capacity < array->count+1) { array__grow(array, 0); } @@ -302,7 +302,7 @@ void array_add(Array *array, T const &t) { } template -T *array_add_and_get(Array *array) { +gb_internal T *array_add_and_get(Array *array) { if (array->count < array->capacity) { return &array->data[array->count++]; } @@ -314,7 +314,7 @@ T *array_add_and_get(Array *array) { template -void array_add_elems(Array *array, T const *elems, isize elem_count) { +gb_internal void array_add_elems(Array *array, T const *elems, isize elem_count) { GB_ASSERT(elem_count >= 0); if (array->capacity < array->count+elem_count) { array__grow(array, array->count+elem_count); @@ -325,26 +325,26 @@ void array_add_elems(Array *array, T const *elems, isize elem_count) { template -gb_inline T array_pop(Array *array) { +gb_internal gb_inline T array_pop(Array *array) { GB_ASSERT(array->count > 0); array->count--; return array->data[array->count]; } template -void array_clear(Array *array) { +gb_internal void array_clear(Array *array) { array->count = 0; } template -void array_reserve(Array *array, isize capacity) { +gb_internal void array_reserve(Array *array, isize capacity) { if (array->capacity < capacity) { array_set_capacity(array, capacity); } } template -void array_resize(Array *array, isize count) { +gb_internal void array_resize(Array *array, isize count) { if (array->capacity < count) { array__grow(array, count); } @@ -352,7 +352,7 @@ void array_resize(Array *array, isize count) { } template -void array_set_capacity(Array *array, isize capacity) { +gb_internal void array_set_capacity(Array *array, isize capacity) { if (capacity == array->capacity) { return; } @@ -381,7 +381,7 @@ void array_set_capacity(Array *array, isize capacity) { template -gb_inline Array array_slice(Array const &array, isize lo, isize hi) { +gb_internal gb_inline Array array_slice(Array const &array, isize lo, isize hi) { GB_ASSERT(0 <= lo && lo <= hi && hi <= array.count); Array out = {}; isize len = hi-lo; @@ -394,7 +394,7 @@ gb_inline Array array_slice(Array const &array, isize lo, isize hi) { } template -Array array_clone(gbAllocator const &allocator, Array const &array) { +gb_internal Array array_clone(gbAllocator const &allocator, Array const &array) { auto clone = array_make(allocator, array.count, array.count); array_copy(&clone, array, 0); return clone; @@ -402,7 +402,7 @@ Array array_clone(gbAllocator const &allocator, Array const &array) { template -void array_ordered_remove(Array *array, isize index) { +gb_internal void array_ordered_remove(Array *array, isize index) { GB_ASSERT(0 <= index && index < array->count); isize bytes = gb_size_of(T) * (array->count-(index+1)); @@ -411,7 +411,7 @@ void array_ordered_remove(Array *array, isize index) { } template -void array_unordered_remove(Array *array, isize index) { +gb_internal void array_unordered_remove(Array *array, isize index) { GB_ASSERT(0 <= index && index < array->count); isize n = array->count-1; @@ -424,35 +424,35 @@ void array_unordered_remove(Array *array, isize index) { template -T *begin(Array &array) { +gb_internal T *begin(Array &array) { return array.data; } template -T const *begin(Array const &array) { +gb_internal T const *begin(Array const &array) { return array.data; } template -T *end(Array &array) { +gb_internal T *end(Array &array) { return array.data + array.count; } template -T const *end(Array const &array) { +gb_internal T const *end(Array const &array) { return array.data + array.count; } template -T *begin(Slice &array) { +gb_internal T *begin(Slice &array) { return array.data; } template -T const *begin(Slice const &array) { +gb_internal T const *begin(Slice const &array) { return array.data; } template -T *end(Slice &array) { +gb_internal T *end(Slice &array) { return array.data + array.count; } template -T const *end(Slice const &array) { +gb_internal T const *end(Slice const &array) { return array.data + array.count; } diff --git a/src/big_int.cpp b/src/big_int.cpp index d8b3e63a7..0f6b921b2 100644 --- a/src/big_int.cpp +++ b/src/big_int.cpp @@ -37,86 +37,86 @@ void MP_FREE(void *mem, size_t size) { typedef mp_int BigInt; -void big_int_from_u64(BigInt *dst, u64 x); -void big_int_from_i64(BigInt *dst, i64 x); -void big_int_init (BigInt *dst, BigInt const *src); -void big_int_from_string(BigInt *dst, String const &s, bool *success); +gb_internal void big_int_from_u64(BigInt *dst, u64 x); +gb_internal void big_int_from_i64(BigInt *dst, i64 x); +gb_internal void big_int_init (BigInt *dst, BigInt const *src); +gb_internal void big_int_from_string(BigInt *dst, String const &s, bool *success); -void big_int_dealloc(BigInt *dst) { +gb_internal void big_int_dealloc(BigInt *dst) { mp_clear(dst); } -BigInt big_int_make(BigInt const *b, bool abs=false); -BigInt big_int_make_abs(BigInt const *b); -BigInt big_int_make_u64(u64 x); -BigInt big_int_make_i64(i64 x); +gb_internal BigInt big_int_make(BigInt const *b, bool abs=false); +gb_internal BigInt big_int_make_abs(BigInt const *b); +gb_internal BigInt big_int_make_u64(u64 x); +gb_internal BigInt big_int_make_i64(i64 x); -u64 big_int_to_u64 (BigInt const *x); -i64 big_int_to_i64 (BigInt const *x); -f64 big_int_to_f64 (BigInt const *x); -String big_int_to_string(gbAllocator allocator, BigInt const *x, u64 base = 10); +gb_internal u64 big_int_to_u64 (BigInt const *x); +gb_internal i64 big_int_to_i64 (BigInt const *x); +gb_internal f64 big_int_to_f64 (BigInt const *x); +gb_internal String big_int_to_string(gbAllocator allocator, BigInt const *x, u64 base = 10); -void big_int_add (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_sub (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_shl (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_shr (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_mul (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y); +gb_internal void big_int_add (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_sub (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_shl (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_shr (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_mul (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y); -void big_int_quo_rem(BigInt const *x, BigInt const *y, BigInt *q, BigInt *r); -void big_int_quo (BigInt *z, BigInt const *x, BigInt const *y); -void big_int_rem (BigInt *z, BigInt const *x, BigInt const *y); +gb_internal void big_int_quo_rem(BigInt const *x, BigInt const *y, BigInt *q, BigInt *r); +gb_internal void big_int_quo (BigInt *z, BigInt const *x, BigInt const *y); +gb_internal void big_int_rem (BigInt *z, BigInt const *x, BigInt const *y); -void big_int_and (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_and_not(BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_xor (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_or (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_not (BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed); +gb_internal void big_int_and (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_and_not(BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_xor (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_or (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_not (BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed); -void big_int_add_eq(BigInt *dst, BigInt const *x); -void big_int_sub_eq(BigInt *dst, BigInt const *x); -void big_int_shl_eq(BigInt *dst, BigInt const *x); -void big_int_shr_eq(BigInt *dst, BigInt const *x); -void big_int_mul_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_add_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_sub_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_shl_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_shr_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_mul_eq(BigInt *dst, BigInt const *x); -void big_int_quo_eq(BigInt *dst, BigInt const *x); -void big_int_rem_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_quo_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_rem_eq(BigInt *dst, BigInt const *x); -bool big_int_is_neg(BigInt const *x); -void big_int_neg(BigInt *dst, BigInt const *x); +gb_internal bool big_int_is_neg(BigInt const *x); +gb_internal void big_int_neg(BigInt *dst, BigInt const *x); -void big_int_add_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_add_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_add(dst, &res, x); } -void big_int_sub_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_sub_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_sub(dst, &res, x); } -void big_int_shl_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_shl_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_shl(dst, &res, x); } -void big_int_shr_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_shr_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_shr(dst, &res, x); } -void big_int_mul_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_mul_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_mul(dst, &res, x); } -void big_int_quo_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_quo_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_quo(dst, &res, x); } -void big_int_rem_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_rem_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_rem(dst, &res, x); @@ -124,7 +124,7 @@ void big_int_rem_eq(BigInt *dst, BigInt const *x) { -i64 big_int_sign(BigInt const *x) { +gb_internal i64 big_int_sign(BigInt const *x) { if (mp_iszero(x)) { return 0; } @@ -132,44 +132,44 @@ i64 big_int_sign(BigInt const *x) { } -void big_int_from_u64(BigInt *dst, u64 x) { +gb_internal void big_int_from_u64(BigInt *dst, u64 x) { mp_init_u64(dst, x); } -void big_int_from_i64(BigInt *dst, i64 x) { +gb_internal void big_int_from_i64(BigInt *dst, i64 x) { mp_init_i64(dst, x); } -void big_int_init(BigInt *dst, BigInt const *src) { +gb_internal void big_int_init(BigInt *dst, BigInt const *src) { if (dst == src) { return; } mp_init_copy(dst, src); } -BigInt big_int_make(BigInt const *b, bool abs) { +gb_internal BigInt big_int_make(BigInt const *b, bool abs) { BigInt i = {}; big_int_init(&i, b); if (abs) mp_abs(&i, &i); return i; } -BigInt big_int_make_abs(BigInt const *b) { +gb_internal BigInt big_int_make_abs(BigInt const *b) { return big_int_make(b, true); } -BigInt big_int_make_u64(u64 x) { +gb_internal BigInt big_int_make_u64(u64 x) { BigInt i = {}; big_int_from_u64(&i, x); return i; } -BigInt big_int_make_i64(i64 x) { +gb_internal BigInt big_int_make_i64(i64 x) { BigInt i = {}; big_int_from_i64(&i, x); return i; } -void big_int_from_string(BigInt *dst, String const &s, bool *success) { +gb_internal void big_int_from_string(BigInt *dst, String const &s, bool *success) { *success = true; bool is_negative = false; @@ -262,66 +262,66 @@ void big_int_from_string(BigInt *dst, String const &s, bool *success) { -u64 big_int_to_u64(BigInt const *x) { +gb_internal u64 big_int_to_u64(BigInt const *x) { GB_ASSERT(x->sign == 0); return mp_get_u64(x); } -i64 big_int_to_i64(BigInt const *x) { +gb_internal i64 big_int_to_i64(BigInt const *x) { return mp_get_i64(x); } -f64 big_int_to_f64(BigInt const *x) { +gb_internal f64 big_int_to_f64(BigInt const *x) { return mp_get_double(x); } -void big_int_neg(BigInt *dst, BigInt const *x) { +gb_internal void big_int_neg(BigInt *dst, BigInt const *x) { mp_neg(x, dst); } -int big_int_cmp(BigInt const *x, BigInt const *y) { +gb_internal int big_int_cmp(BigInt const *x, BigInt const *y) { return mp_cmp(x, y); } -int big_int_cmp_zero(BigInt const *x) { +gb_internal int big_int_cmp_zero(BigInt const *x) { if (mp_iszero(x)) { return 0; } return x->sign ? -1 : +1; } -bool big_int_is_zero(BigInt const *x) { +gb_internal bool big_int_is_zero(BigInt const *x) { return mp_iszero(x); } -void big_int_add(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_add(BigInt *dst, BigInt const *x, BigInt const *y) { mp_add(x, y, dst); } -void big_int_sub(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_sub(BigInt *dst, BigInt const *x, BigInt const *y) { mp_sub(x, y, dst); } -void big_int_shl(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_shl(BigInt *dst, BigInt const *x, BigInt const *y) { u32 yy = mp_get_u32(y); mp_mul_2d(x, yy, dst); } -void big_int_shr(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_shr(BigInt *dst, BigInt const *x, BigInt const *y) { u32 yy = mp_get_u32(y); BigInt d = {}; mp_div_2d(x, yy, dst, &d); big_int_dealloc(&d); } -void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y) { +gb_internal void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y) { BigInt d = {}; big_int_from_u64(&d, y); mp_mul(x, &d, dst); @@ -329,12 +329,12 @@ void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y) { } -void big_int_mul(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_mul(BigInt *dst, BigInt const *x, BigInt const *y) { mp_mul(x, y, dst); } -u64 leading_zeros_u64(u64 x) { +gb_internal u64 leading_zeros_u64(u64 x) { #if defined(GB_COMPILER_MSVC) #if defined(GB_ARCH_64_BIT) return __lzcnt64(x); @@ -367,23 +367,23 @@ u64 leading_zeros_u64(u64 x) { // // q = x/y with the result truncated to zero // r = x - y*q -void big_int_quo_rem(BigInt const *x, BigInt const *y, BigInt *q_, BigInt *r_) { +gb_internal void big_int_quo_rem(BigInt const *x, BigInt const *y, BigInt *q_, BigInt *r_) { mp_div(x, y, q_, r_); } -void big_int_quo(BigInt *z, BigInt const *x, BigInt const *y) { +gb_internal void big_int_quo(BigInt *z, BigInt const *x, BigInt const *y) { BigInt r = {}; big_int_quo_rem(x, y, z, &r); big_int_dealloc(&r); } -void big_int_rem(BigInt *z, BigInt const *x, BigInt const *y) { +gb_internal void big_int_rem(BigInt *z, BigInt const *x, BigInt const *y) { BigInt q = {}; big_int_quo_rem(x, y, &q, z); big_int_dealloc(&q); } -void big_int_euclidean_mod(BigInt *z, BigInt const *x, BigInt const *y) { +gb_internal void big_int_euclidean_mod(BigInt *z, BigInt const *x, BigInt const *y) { BigInt y0 = {}; big_int_init(&y0, y); @@ -400,11 +400,11 @@ void big_int_euclidean_mod(BigInt *z, BigInt const *x, BigInt const *y) { -void big_int_and(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_and(BigInt *dst, BigInt const *x, BigInt const *y) { mp_and(x, y, dst); } -void big_int_and_not(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_and_not(BigInt *dst, BigInt const *x, BigInt const *y) { if (mp_iszero(x)) { big_int_init(dst, y); return; @@ -467,22 +467,22 @@ void big_int_and_not(BigInt *dst, BigInt const *x, BigInt const *y) { return; } -void big_int_xor(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_xor(BigInt *dst, BigInt const *x, BigInt const *y) { mp_xor(x, y, dst); } -void big_int_or(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_or(BigInt *dst, BigInt const *x, BigInt const *y) { mp_or(x, y, dst); } -void debug_print_big_int(BigInt const *x) { +gb_internal void debug_print_big_int(BigInt const *x) { String s = big_int_to_string(temporary_allocator(), x, 10); gb_printf_err("[DEBUG] %.*s\n", LIT(s)); } -void big_int_not(BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed) { +gb_internal void big_int_not(BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed) { GB_ASSERT(bit_count >= 0); if (bit_count == 0) { big_int_from_u64(dst, 0); @@ -530,7 +530,7 @@ void big_int_not(BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed) { big_int_dealloc(&v); } -bool big_int_is_neg(BigInt const *x) { +gb_internal bool big_int_is_neg(BigInt const *x) { if (x == nullptr) { return false; } @@ -538,7 +538,7 @@ bool big_int_is_neg(BigInt const *x) { } -char digit_to_char(u8 digit) { +gb_internal char digit_to_char(u8 digit) { GB_ASSERT(digit < 16); if (digit <= 9) { return digit + '0'; @@ -548,7 +548,7 @@ char digit_to_char(u8 digit) { return '0'; } -String big_int_to_string(gbAllocator allocator, BigInt const *x, u64 base) { +gb_internal String big_int_to_string(gbAllocator allocator, BigInt const *x, u64 base) { GB_ASSERT(base <= 16); if (mp_iszero(x)) { diff --git a/src/build_settings.cpp b/src/build_settings.cpp index ba68e388b..d66db8099 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -57,7 +57,7 @@ enum TargetABIKind : u16 { }; -String target_os_names[TargetOs_COUNT] = { +gb_global String target_os_names[TargetOs_COUNT] = { str_lit(""), str_lit("windows"), str_lit("darwin"), @@ -72,7 +72,7 @@ String target_os_names[TargetOs_COUNT] = { str_lit("freestanding"), }; -String target_arch_names[TargetArch_COUNT] = { +gb_global String target_arch_names[TargetArch_COUNT] = { str_lit(""), str_lit("amd64"), str_lit("i386"), @@ -82,19 +82,19 @@ String target_arch_names[TargetArch_COUNT] = { str_lit("wasm64"), }; -String target_endian_names[TargetEndian_COUNT] = { +gb_global String target_endian_names[TargetEndian_COUNT] = { str_lit(""), str_lit("little"), str_lit("big"), }; -String target_abi_names[TargetABI_COUNT] = { +gb_global String target_abi_names[TargetABI_COUNT] = { str_lit(""), str_lit("win64"), str_lit("sysv"), }; -TargetEndianKind target_endians[TargetArch_COUNT] = { +gb_global TargetEndianKind target_endians[TargetArch_COUNT] = { TargetEndian_Invalid, TargetEndian_Little, TargetEndian_Little, @@ -107,7 +107,7 @@ TargetEndianKind target_endians[TargetArch_COUNT] = { #define ODIN_VERSION_RAW "dev-unknown-unknown" #endif -String const ODIN_VERSION = str_lit(ODIN_VERSION_RAW); +gb_global String const ODIN_VERSION = str_lit(ODIN_VERSION_RAW); @@ -162,7 +162,7 @@ enum CommandKind : u32 { Command_all = ~(u32)0, }; -char const *odin_command_strings[32] = { +gb_global char const *odin_command_strings[32] = { "run", "build", "check", @@ -333,10 +333,10 @@ struct BuildContext { gb_global BuildContext build_context = {0}; -bool global_warnings_as_errors(void) { +gb_internal bool global_warnings_as_errors(void) { return build_context.warnings_as_errors; } -bool global_ignore_warnings(void) { +gb_internal bool global_ignore_warnings(void) { return build_context.ignore_warnings; } @@ -502,9 +502,9 @@ gb_global NamedTargetMetrics named_targets[] = { { str_lit("freestanding_amd64_sysv"), &target_freestanding_amd64_sysv }, }; -NamedTargetMetrics *selected_target_metrics; +gb_global NamedTargetMetrics *selected_target_metrics; -TargetOsKind get_target_os_from_string(String str) { +gb_internal TargetOsKind get_target_os_from_string(String str) { for (isize i = 0; i < TargetOs_COUNT; i++) { if (str_eq_ignore_case(target_os_names[i], str)) { return cast(TargetOsKind)i; @@ -513,7 +513,7 @@ TargetOsKind get_target_os_from_string(String str) { return TargetOs_Invalid; } -TargetArchKind get_target_arch_from_string(String str) { +gb_internal TargetArchKind get_target_arch_from_string(String str) { for (isize i = 0; i < TargetArch_COUNT; i++) { if (str_eq_ignore_case(target_arch_names[i], str)) { return cast(TargetArchKind)i; @@ -523,7 +523,7 @@ TargetArchKind get_target_arch_from_string(String str) { } -bool is_excluded_target_filename(String name) { +gb_internal bool is_excluded_target_filename(String name) { String original_name = name; name = remove_extension_from_path(name); @@ -588,13 +588,13 @@ struct LibraryCollections { gb_global Array library_collections = {0}; -void add_library_collection(String name, String path) { +gb_internal void add_library_collection(String name, String path) { // TODO(bill): Check the path is valid and a directory LibraryCollections lc = {name, string_trim_whitespace(path)}; array_add(&library_collections, lc); } -bool find_library_collection_path(String name, String *path) { +gb_internal bool find_library_collection_path(String name, String *path) { for_array(i, library_collections) { if (library_collections[i].name == name) { if (path) *path = library_collections[i].path; @@ -604,7 +604,7 @@ bool find_library_collection_path(String name, String *path) { return false; } -bool is_arch_wasm(void) { +gb_internal bool is_arch_wasm(void) { switch (build_context.metrics.arch) { case TargetArch_wasm32: case TargetArch_wasm64: @@ -613,7 +613,7 @@ bool is_arch_wasm(void) { return false; } -bool is_arch_x86(void) { +gb_internal bool is_arch_x86(void) { switch (build_context.metrics.arch) { case TargetArch_i386: case TargetArch_amd64: @@ -622,7 +622,7 @@ bool is_arch_x86(void) { return false; } -bool allow_check_foreign_filepath(void) { +gb_internal bool allow_check_foreign_filepath(void) { switch (build_context.metrics.arch) { case TargetArch_wasm32: case TargetArch_wasm64: @@ -638,13 +638,14 @@ bool allow_check_foreign_filepath(void) { // is_abs_path // has_subdir -String const WIN32_SEPARATOR_STRING = {cast(u8 *)"\\", 1}; -String const NIX_SEPARATOR_STRING = {cast(u8 *)"/", 1}; +gb_global String const WIN32_SEPARATOR_STRING = {cast(u8 *)"\\", 1}; +gb_global String const NIX_SEPARATOR_STRING = {cast(u8 *)"/", 1}; -String const WASM_MODULE_NAME_SEPARATOR = str_lit(".."); +gb_global String const WASM_MODULE_NAME_SEPARATOR = str_lit(".."); -String internal_odin_root_dir(void); -String odin_root_dir(void) { +gb_internal String internal_odin_root_dir(void); + +gb_internal String odin_root_dir(void) { if (global_module_path_set) { return global_module_path; } @@ -670,7 +671,7 @@ String odin_root_dir(void) { #if defined(GB_SYSTEM_WINDOWS) -String internal_odin_root_dir(void) { +gb_internal String internal_odin_root_dir(void) { String path = global_module_path; isize len, i; wchar_t *text; @@ -725,7 +726,7 @@ String internal_odin_root_dir(void) { String path_to_fullpath(gbAllocator a, String s); -String internal_odin_root_dir(void) { +gb_internal String internal_odin_root_dir(void) { String path = global_module_path; isize len, i; u8 *text; @@ -777,9 +778,9 @@ String internal_odin_root_dir(void) { // NOTE: Linux / Unix is unfinished and not tested very well. #include -String path_to_fullpath(gbAllocator a, String s); +gb_internal String path_to_fullpath(gbAllocator a, String s); -String internal_odin_root_dir(void) { +gb_internal String internal_odin_root_dir(void) { String path = global_module_path; isize len, i; u8 *text; @@ -938,7 +939,7 @@ String internal_odin_root_dir(void) { gb_global BlockingMutex fullpath_mutex; #if defined(GB_SYSTEM_WINDOWS) -String path_to_fullpath(gbAllocator a, String s) { +gb_internal String path_to_fullpath(gbAllocator a, String s) { String result = {}; mutex_lock(&fullpath_mutex); defer (mutex_unlock(&fullpath_mutex)); @@ -965,7 +966,7 @@ String path_to_fullpath(gbAllocator a, String s) { return result; } #elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX) -String path_to_fullpath(gbAllocator a, String s) { +gb_internal String path_to_fullpath(gbAllocator a, String s) { char *p; mutex_lock(&fullpath_mutex); p = realpath(cast(char *)s.text, 0); @@ -978,7 +979,7 @@ String path_to_fullpath(gbAllocator a, String s) { #endif -String get_fullpath_relative(gbAllocator a, String base_dir, String path) { +gb_internal String get_fullpath_relative(gbAllocator a, String base_dir, String path) { u8 *str = gb_alloc_array(heap_allocator(), u8, base_dir.len+1+path.len+1); defer (gb_free(heap_allocator(), str)); @@ -1004,7 +1005,7 @@ String get_fullpath_relative(gbAllocator a, String base_dir, String path) { } -String get_fullpath_core(gbAllocator a, String path) { +gb_internal String get_fullpath_core(gbAllocator a, String path) { String module_dir = odin_root_dir(); String core = str_lit("core/"); @@ -1024,11 +1025,11 @@ String get_fullpath_core(gbAllocator a, String path) { return path_to_fullpath(a, res); } -bool show_error_line(void) { +gb_internal bool show_error_line(void) { return build_context.show_error_line; } -bool has_asm_extension(String const &path) { +gb_internal bool has_asm_extension(String const &path) { String ext = path_extension(path); if (ext == ".asm") { return true; @@ -1041,7 +1042,7 @@ bool has_asm_extension(String const &path) { } // temporary -char *token_pos_to_string(TokenPos const &pos) { +gb_internal char *token_pos_to_string(TokenPos const &pos) { gbString s = gb_string_make_reserve(temporary_allocator(), 128); String file = get_file_path_string(pos.file_id); switch (build_context.ODIN_ERROR_POS_STYLE) { @@ -1056,7 +1057,7 @@ char *token_pos_to_string(TokenPos const &pos) { return s; } -void init_build_context(TargetMetrics *cross_target) { +gb_internal void init_build_context(TargetMetrics *cross_target) { BuildContext *bc = &build_context; gb_affinity_init(&bc->affinity); @@ -1258,7 +1259,7 @@ void init_build_context(TargetMetrics *cross_target) { #endif -Array split_by_comma(String const &list) { +gb_internal Array split_by_comma(String const &list) { isize n = 1; for (isize i = 0; i < list.len; i++) { if (list.text[i] == ',') { @@ -1280,12 +1281,12 @@ Array split_by_comma(String const &list) { return res; } -bool check_target_feature_is_valid(TokenPos pos, String const &feature) { +gb_internal bool check_target_feature_is_valid(TokenPos pos, String const &feature) { // TODO(bill): check_target_feature_is_valid return true; } -bool check_target_feature_is_enabled(TokenPos pos, String const &target_feature_list) { +gb_internal bool check_target_feature_is_enabled(TokenPos pos, String const &target_feature_list) { BuildContext *bc = &build_context; mutex_lock(&bc->target_features_mutex); defer (mutex_unlock(&bc->target_features_mutex)); @@ -1307,7 +1308,7 @@ bool check_target_feature_is_enabled(TokenPos pos, String const &target_feature_ return true; } -void enable_target_feature(TokenPos pos, String const &target_feature_list) { +gb_internal void enable_target_feature(TokenPos pos, String const &target_feature_list) { BuildContext *bc = &build_context; mutex_lock(&bc->target_features_mutex); defer (mutex_unlock(&bc->target_features_mutex)); @@ -1326,7 +1327,7 @@ void enable_target_feature(TokenPos pos, String const &target_feature_list) { } -char const *target_features_set_to_cstring(gbAllocator allocator, bool with_quotes) { +gb_internal char const *target_features_set_to_cstring(gbAllocator allocator, bool with_quotes) { isize len = 0; isize i = 0; for (auto const &entry : build_context.target_features_set) { @@ -1359,7 +1360,7 @@ char const *target_features_set_to_cstring(gbAllocator allocator, bool with_quot // NOTE(Jeroen): Set/create the output and other paths and report an error as appropriate. // We've previously called `parse_build_flags`, so `out_filepath` should be set. -bool init_build_paths(String init_filename) { +gb_internal bool init_build_paths(String init_filename) { gbAllocator ha = heap_allocator(); BuildContext *bc = &build_context; diff --git a/src/common.cpp b/src/common.cpp index bc421b5fd..09203e633 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -29,14 +29,14 @@ #include #include // Because I wanted the C++11 memory order semantics, of which gb.h does not offer (because it was a C89 library) -gbAllocator heap_allocator(void); +gb_internal gbAllocator heap_allocator(void); #define for_array(index_, array_) for (isize index_ = 0; index_ < (array_).count; index_++) -i32 next_pow2(i32 n); -i64 next_pow2(i64 n); -isize next_pow2_isize(isize n); -void debugf(char const *fmt, ...); +gb_internal i32 next_pow2(i32 n); +gb_internal i64 next_pow2(i64 n); +gb_internal isize next_pow2_isize(isize n); +gb_internal void debugf(char const *fmt, ...); #if defined(GB_SYSTEM_WINDOWS) && defined(GB_ARCH_32_BIT) #error Odin on Windows requires a 64-bit build-system. The 'Developer Command Prompt' for VS still defaults to 32-bit shell. The 64-bit shell can be found under the name 'x64 Native Tools Command Prompt' for VS. For more information, please see https://odin-lang.org/docs/install/#for-windows @@ -51,14 +51,14 @@ void debugf(char const *fmt, ...); #include "range_cache.cpp" -bool is_power_of_two(i64 x) { +gb_internal gb_inline bool is_power_of_two(i64 x) { if (x <= 0) { return false; } return !(x & (x-1)); } -int isize_cmp(isize x, isize y) { +gb_internal int isize_cmp(isize x, isize y) { if (x < y) { return -1; } else if (x > y) { @@ -66,7 +66,7 @@ int isize_cmp(isize x, isize y) { } return 0; } -int u64_cmp(u64 x, u64 y) { +gb_internal int u64_cmp(u64 x, u64 y) { if (x < y) { return -1; } else if (x > y) { @@ -74,7 +74,7 @@ int u64_cmp(u64 x, u64 y) { } return 0; } -int i64_cmp(i64 x, i64 y) { +gb_internal int i64_cmp(i64 x, i64 y) { if (x < y) { return -1; } else if (x > y) { @@ -82,7 +82,7 @@ int i64_cmp(i64 x, i64 y) { } return 0; } -int i32_cmp(i32 x, i32 y) { +gb_internal int i32_cmp(i32 x, i32 y) { if (x < y) { return -1; } else if (x > y) { @@ -91,7 +91,7 @@ int i32_cmp(i32 x, i32 y) { return 0; } -u32 fnv32a(void const *data, isize len) { +gb_internal u32 fnv32a(void const *data, isize len) { u8 const *bytes = cast(u8 const *)data; u32 h = 0x811c9dc5; @@ -112,7 +112,7 @@ u32 fnv32a(void const *data, isize len) { return h; } -u64 fnv64a(void const *data, isize len) { +gb_internal u64 fnv64a(void const *data, isize len) { u8 const *bytes = cast(u8 const *)data; u64 h = 0xcbf29ce484222325ull; @@ -133,7 +133,7 @@ u64 fnv64a(void const *data, isize len) { return h; } -u64 u64_digit_value(Rune r) { +gb_internal u64 u64_digit_value(Rune r) { switch (r) { case '0': return 0; case '1': return 1; @@ -162,7 +162,7 @@ u64 u64_digit_value(Rune r) { } -u64 u64_from_string(String string) { +gb_internal u64 u64_from_string(String string) { u64 base = 10; bool has_prefix = false; if (string.len > 2 && string[0] == '0') { @@ -205,7 +205,7 @@ gb_global char const global_num_to_char_table[] = "abcdefghijklmnopqrstuvwxyz" "@$"; -String u64_to_string(u64 v, char *out_buf, isize out_buf_len) { +gb_internal String u64_to_string(u64 v, char *out_buf, isize out_buf_len) { char buf[32] = {0}; isize i = gb_size_of(buf); @@ -220,7 +220,7 @@ String u64_to_string(u64 v, char *out_buf, isize out_buf_len) { gb_memmove(out_buf, &buf[i], len); return make_string(cast(u8 *)out_buf, len); } -String i64_to_string(i64 a, char *out_buf, isize out_buf_len) { +gb_internal String i64_to_string(i64 a, char *out_buf, isize out_buf_len) { char buf[32] = {0}; isize i = gb_size_of(buf); bool negative = false; @@ -282,17 +282,17 @@ gb_global u64 const unsigned_integer_maxs[] = { }; -bool add_overflow_u64(u64 x, u64 y, u64 *result) { +gb_internal bool add_overflow_u64(u64 x, u64 y, u64 *result) { *result = x + y; return *result < x || *result < y; } -bool sub_overflow_u64(u64 x, u64 y, u64 *result) { +gb_internal bool sub_overflow_u64(u64 x, u64 y, u64 *result) { *result = x - y; return *result > x; } -void mul_overflow_u64(u64 x, u64 y, u64 *lo, u64 *hi) { +gb_internal void mul_overflow_u64(u64 x, u64 y, u64 *lo, u64 *hi) { #if defined(GB_COMPILER_MSVC) && defined(GB_ARCH_64_BIT) *lo = _umul128(x, y, hi); #else @@ -342,7 +342,7 @@ struct StringIntern { PtrMap string_intern_map = {}; // Key: u64 gb_global Arena string_intern_arena = {}; -char const *string_intern(char const *text, isize len) { +gb_internal char const *string_intern(char const *text, isize len) { u64 hash = gb_fnv64a(text, len); uintptr key = cast(uintptr)(hash ? hash : 1); StringIntern **found = map_get(&string_intern_map, key); @@ -363,18 +363,18 @@ char const *string_intern(char const *text, isize len) { return new_intern->str; } -char const *string_intern(String const &string) { +gb_internal char const *string_intern(String const &string) { return string_intern(cast(char const *)string.text, string.len); } -void init_string_interner(void) { +gb_internal void init_string_interner(void) { map_init(&string_intern_map, heap_allocator()); } -i32 next_pow2(i32 n) { +gb_internal i32 next_pow2(i32 n) { if (n <= 0) { return 0; } @@ -387,7 +387,7 @@ i32 next_pow2(i32 n) { n++; return n; } -i64 next_pow2(i64 n) { +gb_internal i64 next_pow2(i64 n) { if (n <= 0) { return 0; } @@ -401,7 +401,7 @@ i64 next_pow2(i64 n) { n++; return n; } -isize next_pow2_isize(isize n) { +gb_internal isize next_pow2_isize(isize n) { if (n <= 0) { return 0; } @@ -417,7 +417,7 @@ isize next_pow2_isize(isize n) { n++; return n; } -u32 next_pow2_u32(u32 n) { +gb_internal u32 next_pow2_u32(u32 n) { if (n == 0) { return 0; } @@ -432,7 +432,7 @@ u32 next_pow2_u32(u32 n) { } -i32 bit_set_count(u32 x) { +gb_internal i32 bit_set_count(u32 x) { x -= ((x >> 1) & 0x55555555); x = (((x >> 2) & 0x33333333) + (x & 0x33333333)); x = (((x >> 4) + x) & 0x0f0f0f0f); @@ -442,13 +442,13 @@ i32 bit_set_count(u32 x) { return cast(i32)(x & 0x0000003f); } -i64 bit_set_count(u64 x) { +gb_internal i64 bit_set_count(u64 x) { u32 a = *(cast(u32 *)&x); u32 b = *(cast(u32 *)&x + 1); return bit_set_count(a) + bit_set_count(b); } -u32 floor_log2(u32 x) { +gb_internal u32 floor_log2(u32 x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; @@ -457,7 +457,7 @@ u32 floor_log2(u32 x) { return cast(u32)(bit_set_count(x) - 1); } -u64 floor_log2(u64 x) { +gb_internal u64 floor_log2(u64 x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; @@ -468,7 +468,7 @@ u64 floor_log2(u64 x) { } -u32 ceil_log2(u32 x) { +gb_internal u32 ceil_log2(u32 x) { i32 y = cast(i32)(x & (x-1)); y |= -y; y >>= 32-1; @@ -480,7 +480,7 @@ u32 ceil_log2(u32 x) { return cast(u32)(bit_set_count(x) - 1 - y); } -u64 ceil_log2(u64 x) { +gb_internal u64 ceil_log2(u64 x) { i64 y = cast(i64)(x & (x-1)); y |= -y; y >>= 64-1; @@ -493,7 +493,7 @@ u64 ceil_log2(u64 x) { return cast(u64)(bit_set_count(x) - 1 - y); } -u32 prev_pow2(u32 n) { +gb_internal u32 prev_pow2(u32 n) { if (n == 0) { return 0; } @@ -504,7 +504,7 @@ u32 prev_pow2(u32 n) { n |= n >> 16; return n - (n >> 1); } -i32 prev_pow2(i32 n) { +gb_internal i32 prev_pow2(i32 n) { if (n <= 0) { return 0; } @@ -515,7 +515,7 @@ i32 prev_pow2(i32 n) { n |= n >> 16; return n - (n >> 1); } -i64 prev_pow2(i64 n) { +gb_internal i64 prev_pow2(i64 n) { if (n <= 0) { return 0; } @@ -528,7 +528,7 @@ i64 prev_pow2(i64 n) { return n - (n >> 1); } -u16 f32_to_f16(f32 value) { +gb_internal u16 f32_to_f16(f32 value) { union { u32 i; f32 f; } v; i32 i, s, e, m; @@ -579,7 +579,7 @@ u16 f32_to_f16(f32 value) { } } -f32 f16_to_f32(u16 value) { +gb_internal f32 f16_to_f32(u16 value) { typedef union { u32 u; f32 f; } fp32; fp32 v; @@ -595,7 +595,7 @@ f32 f16_to_f32(u16 value) { return v.f; } -f64 gb_sqrt(f64 x) { +gb_internal gb_inline f64 gb_sqrt(f64 x) { return sqrt(x); } @@ -623,7 +623,7 @@ f64 gb_sqrt(f64 x) { #if defined(GB_SYSTEM_WINDOWS) -wchar_t **command_line_to_wargv(wchar_t *cmd_line, int *_argc) { +gb_internal wchar_t **command_line_to_wargv(wchar_t *cmd_line, int *_argc) { u32 i, j; u32 len = cast(u32)string16_len(cmd_line); @@ -706,7 +706,7 @@ enum LoadedFileError { LoadedFile_COUNT, }; -LoadedFileError load_file_32(char const *fullpath, LoadedFile *memory_mapped_file, bool copy_file_contents) { +gb_internal LoadedFileError load_file_32(char const *fullpath, LoadedFile *memory_mapped_file, bool copy_file_contents) { LoadedFileError err = LoadedFile_None; if (!copy_file_contents) { @@ -811,7 +811,7 @@ LoadedFileError load_file_32(char const *fullpath, LoadedFile *memory_mapped_fil #define USE_DAMERAU_LEVENSHTEIN 1 -isize levenstein_distance_case_insensitive(String const &a, String const &b) { +gb_internal isize levenstein_distance_case_insensitive(String const &a, String const &b) { isize w = b.len+1; isize h = a.len+1; isize *matrix = gb_alloc_array(temporary_allocator(), isize, w*h); @@ -870,16 +870,16 @@ struct DidYouMeanAnswers { enum {MAX_SMALLEST_DID_YOU_MEAN_DISTANCE = 3-USE_DAMERAU_LEVENSHTEIN}; -DidYouMeanAnswers did_you_mean_make(gbAllocator allocator, isize cap, String const &key) { +gb_internal DidYouMeanAnswers did_you_mean_make(gbAllocator allocator, isize cap, String const &key) { DidYouMeanAnswers d = {}; array_init(&d.distances, allocator, 0, cap); d.key = key; return d; } -void did_you_mean_destroy(DidYouMeanAnswers *d) { +gb_internal void did_you_mean_destroy(DidYouMeanAnswers *d) { array_free(&d->distances); } -void did_you_mean_append(DidYouMeanAnswers *d, String const &target) { +gb_internal void did_you_mean_append(DidYouMeanAnswers *d, String const &target) { if (target.len == 0 || target == "_") { return; } @@ -888,7 +888,7 @@ void did_you_mean_append(DidYouMeanAnswers *d, String const &target) { dat.distance = levenstein_distance_case_insensitive(d->key, target); array_add(&d->distances, dat); } -Slice did_you_mean_results(DidYouMeanAnswers *d) { +gb_internal Slice did_you_mean_results(DidYouMeanAnswers *d) { gb_sort_array(d->distances.data, d->distances.count, gb_isize_cmp(gb_offset_of(DistanceAndTarget, distance))); isize count = 0; for (isize i = 0; i < d->distances.count; i++) { diff --git a/src/common_memory.cpp b/src/common_memory.cpp index 953462077..63b7c24ef 100644 --- a/src/common_memory.cpp +++ b/src/common_memory.cpp @@ -1,5 +1,5 @@ -gb_inline void zero_size(void *ptr, isize len) { +gb_internal gb_inline void zero_size(void *ptr, isize len) { memset(ptr, 0, len); } @@ -7,27 +7,27 @@ gb_inline void zero_size(void *ptr, isize len) { template -gb_inline U bit_cast(V &v) { return reinterpret_cast(v); } +gb_internal gb_inline U bit_cast(V &v) { return reinterpret_cast(v); } template -gb_inline U const &bit_cast(V const &v) { return reinterpret_cast(v); } +gb_internal gb_inline U const &bit_cast(V const &v) { return reinterpret_cast(v); } -gb_inline i64 align_formula(i64 size, i64 align) { +gb_internal gb_inline i64 align_formula(i64 size, i64 align) { if (align > 0) { i64 result = size + align-1; return result - result%align; } return size; } -gb_inline isize align_formula_isize(isize size, isize align) { +gb_internal gb_inline isize align_formula_isize(isize size, isize align) { if (align > 0) { isize result = size + align-1; return result - result%align; } return size; } -gb_inline void *align_formula_ptr(void *ptr, isize align) { +gb_internal gb_inline void *align_formula_ptr(void *ptr, isize align) { if (align > 0) { uintptr result = (cast(uintptr)ptr) + align-1; return (void *)(result - result%align); @@ -39,9 +39,9 @@ gb_inline void *align_formula_ptr(void *ptr, isize align) { gb_global BlockingMutex global_memory_block_mutex; gb_global BlockingMutex global_memory_allocator_mutex; -void platform_virtual_memory_init(void); +gb_internal void platform_virtual_memory_init(void); -void virtual_memory_init(void) { +gb_internal void virtual_memory_init(void) { mutex_init(&global_memory_block_mutex); mutex_init(&global_memory_allocator_mutex); platform_virtual_memory_init(); @@ -66,13 +66,13 @@ enum { DEFAULT_MINIMUM_BLOCK_SIZE = 8ll*1024ll*1024ll }; gb_global isize DEFAULT_PAGE_SIZE = 4096; -MemoryBlock *virtual_memory_alloc(isize size); -void virtual_memory_dealloc(MemoryBlock *block); -void *arena_alloc(Arena *arena, isize min_size, isize alignment); -void arena_free_all(Arena *arena); +gb_internal MemoryBlock *virtual_memory_alloc(isize size); +gb_internal void virtual_memory_dealloc(MemoryBlock *block); +gb_internal void *arena_alloc(Arena *arena, isize min_size, isize alignment); +gb_internal void arena_free_all(Arena *arena); -isize arena_align_forward_offset(Arena *arena, isize alignment) { +gb_internal isize arena_align_forward_offset(Arena *arena, isize alignment) { isize alignment_offset = 0; isize ptr = cast(isize)(arena->curr_block->base + arena->curr_block->used); isize mask = alignment-1; @@ -82,7 +82,7 @@ isize arena_align_forward_offset(Arena *arena, isize alignment) { return alignment_offset; } -void *arena_alloc(Arena *arena, isize min_size, isize alignment) { +gb_internal void *arena_alloc(Arena *arena, isize min_size, isize alignment) { GB_ASSERT(gb_is_power_of_two(alignment)); BlockingMutex *mutex = &global_memory_allocator_mutex; @@ -123,7 +123,7 @@ void *arena_alloc(Arena *arena, isize min_size, isize alignment) { return ptr; } -void arena_free_all(Arena *arena) { +gb_internal void arena_free_all(Arena *arena) { while (arena->curr_block != nullptr) { MemoryBlock *free_block = arena->curr_block; arena->curr_block = free_block->prev; @@ -142,12 +142,12 @@ struct PlatformMemoryBlock { gb_global std::atomic global_platform_memory_total_usage; gb_global PlatformMemoryBlock global_platform_memory_block_sentinel; -PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size); -void platform_virtual_memory_free(PlatformMemoryBlock *block); -void platform_virtual_memory_protect(void *memory, isize size); +gb_internal PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size); +gb_internal void platform_virtual_memory_free(PlatformMemoryBlock *block); +gb_internal void platform_virtual_memory_protect(void *memory, isize size); #if defined(GB_SYSTEM_WINDOWS) - void platform_virtual_memory_init(void) { + gb_internal void platform_virtual_memory_init(void) { global_platform_memory_block_sentinel.prev = &global_platform_memory_block_sentinel; global_platform_memory_block_sentinel.next = &global_platform_memory_block_sentinel; @@ -157,7 +157,7 @@ void platform_virtual_memory_protect(void *memory, isize size); GB_ASSERT(gb_is_power_of_two(DEFAULT_PAGE_SIZE)); } - PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size) { + gb_internal PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size) { PlatformMemoryBlock *pmblock = (PlatformMemoryBlock *)VirtualAlloc(0, total_size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); if (pmblock == nullptr) { gb_printf_err("Out of Virtual memory, oh no...\n"); @@ -168,17 +168,17 @@ void platform_virtual_memory_protect(void *memory, isize size); global_platform_memory_total_usage += total_size; return pmblock; } - void platform_virtual_memory_free(PlatformMemoryBlock *block) { + gb_internal void platform_virtual_memory_free(PlatformMemoryBlock *block) { global_platform_memory_total_usage -= block->total_size; GB_ASSERT(VirtualFree(block, 0, MEM_RELEASE)); } - void platform_virtual_memory_protect(void *memory, isize size) { + gb_internal void platform_virtual_memory_protect(void *memory, isize size) { DWORD old_protect = 0; BOOL is_protected = VirtualProtect(memory, size, PAGE_NOACCESS, &old_protect); GB_ASSERT(is_protected); } #else - void platform_virtual_memory_init(void) { + gb_internal void platform_virtual_memory_init(void) { global_platform_memory_block_sentinel.prev = &global_platform_memory_block_sentinel; global_platform_memory_block_sentinel.next = &global_platform_memory_block_sentinel; @@ -186,7 +186,7 @@ void platform_virtual_memory_protect(void *memory, isize size); GB_ASSERT(gb_is_power_of_two(DEFAULT_PAGE_SIZE)); } - PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size) { + gb_internal PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size) { PlatformMemoryBlock *pmblock = (PlatformMemoryBlock *)mmap(nullptr, total_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (pmblock == nullptr) { gb_printf_err("Out of Virtual memory, oh no...\n"); @@ -197,18 +197,18 @@ void platform_virtual_memory_protect(void *memory, isize size); global_platform_memory_total_usage += total_size; return pmblock; } - void platform_virtual_memory_free(PlatformMemoryBlock *block) { + gb_internal void platform_virtual_memory_free(PlatformMemoryBlock *block) { isize size = block->total_size; global_platform_memory_total_usage -= size; munmap(block, size); } - void platform_virtual_memory_protect(void *memory, isize size) { + gb_internal void platform_virtual_memory_protect(void *memory, isize size) { int err = mprotect(memory, size, PROT_NONE); GB_ASSERT(err == 0); } #endif -MemoryBlock *virtual_memory_alloc(isize size) { +gb_internal MemoryBlock *virtual_memory_alloc(isize size) { isize const page_size = DEFAULT_PAGE_SIZE; isize total_size = size + gb_size_of(PlatformMemoryBlock); @@ -250,7 +250,7 @@ MemoryBlock *virtual_memory_alloc(isize size) { return &pmblock->block; } -void virtual_memory_dealloc(MemoryBlock *block_to_free) { +gb_internal void virtual_memory_dealloc(MemoryBlock *block_to_free) { PlatformMemoryBlock *block = cast(PlatformMemoryBlock *)block_to_free; if (block != nullptr) { mutex_lock(&global_memory_block_mutex); @@ -265,9 +265,9 @@ void virtual_memory_dealloc(MemoryBlock *block_to_free) { -GB_ALLOCATOR_PROC(arena_allocator_proc); +gb_internal GB_ALLOCATOR_PROC(arena_allocator_proc); -gbAllocator arena_allocator(Arena *arena) { +gb_internal gbAllocator arena_allocator(Arena *arena) { gbAllocator a; a.proc = arena_allocator_proc; a.data = arena; @@ -275,7 +275,7 @@ gbAllocator arena_allocator(Arena *arena) { } -GB_ALLOCATOR_PROC(arena_allocator_proc) { +gb_internal GB_ALLOCATOR_PROC(arena_allocator_proc) { void *ptr = nullptr; Arena *arena = cast(Arena *)allocator_data; GB_ASSERT_NOT_NULL(arena); @@ -307,11 +307,11 @@ GB_ALLOCATOR_PROC(arena_allocator_proc) { gb_global gb_thread_local Arena permanent_arena = {nullptr, DEFAULT_MINIMUM_BLOCK_SIZE, true}; -gbAllocator permanent_allocator() { +gb_internal gbAllocator permanent_allocator() { return arena_allocator(&permanent_arena); } -gbAllocator temporary_allocator() { +gb_internal gbAllocator temporary_allocator() { return permanent_allocator(); } @@ -320,9 +320,9 @@ gbAllocator temporary_allocator() { -GB_ALLOCATOR_PROC(heap_allocator_proc); +gb_internal GB_ALLOCATOR_PROC(heap_allocator_proc); -gbAllocator heap_allocator(void) { +gb_internal gbAllocator heap_allocator(void) { gbAllocator a; a.proc = heap_allocator_proc; a.data = nullptr; @@ -330,7 +330,7 @@ gbAllocator heap_allocator(void) { } -GB_ALLOCATOR_PROC(heap_allocator_proc) { +gb_internal GB_ALLOCATOR_PROC(heap_allocator_proc) { void *ptr = nullptr; gb_unused(allocator_data); gb_unused(old_size); @@ -460,7 +460,7 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) { template -void resize_array_raw(T **array, gbAllocator const &a, isize old_count, isize new_count) { +gb_internal void resize_array_raw(T **array, gbAllocator const &a, isize old_count, isize new_count) { GB_ASSERT(new_count >= 0); if (new_count == 0) { gb_free(a, *array); diff --git a/src/error.cpp b/src/error.cpp index faf4d11fb..085e1a8dd 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -17,11 +17,11 @@ gb_global ErrorCollector global_error_collector; #define MAX_ERROR_COLLECTOR_COUNT (36) -bool any_errors(void) { +gb_internal bool any_errors(void) { return global_error_collector.count.load() != 0; } -void init_global_error_collector(void) { +gb_internal void init_global_error_collector(void) { mutex_init(&global_error_collector.mutex); mutex_init(&global_error_collector.block_mutex); mutex_init(&global_error_collector.error_out_mutex); @@ -35,9 +35,9 @@ void init_global_error_collector(void) { // temporary // defined in build_settings.cpp -char *token_pos_to_string(TokenPos const &pos); +gb_internal char *token_pos_to_string(TokenPos const &pos); -bool set_file_path_string(i32 index, String const &path) { +gb_internal bool set_file_path_string(i32 index, String const &path) { bool ok = false; GB_ASSERT(index >= 0); mutex_lock(&global_error_collector.string_mutex); @@ -55,7 +55,7 @@ bool set_file_path_string(i32 index, String const &path) { return ok; } -bool thread_safe_set_ast_file_from_id(i32 index, AstFile *file) { +gb_internal bool thread_safe_set_ast_file_from_id(i32 index, AstFile *file) { bool ok = false; GB_ASSERT(index >= 0); mutex_lock(&global_error_collector.string_mutex); @@ -73,7 +73,7 @@ bool thread_safe_set_ast_file_from_id(i32 index, AstFile *file) { return ok; } -String get_file_path_string(i32 index) { +gb_internal String get_file_path_string(i32 index) { GB_ASSERT(index >= 0); mutex_lock(&global_error_collector.string_mutex); @@ -86,7 +86,7 @@ String get_file_path_string(i32 index) { return path; } -AstFile *thread_safe_get_ast_file_from_id(i32 index) { +gb_internal AstFile *thread_safe_get_ast_file_from_id(i32 index) { GB_ASSERT(index >= 0); mutex_lock(&global_error_collector.string_mutex); @@ -101,12 +101,12 @@ AstFile *thread_safe_get_ast_file_from_id(i32 index) { -void begin_error_block(void) { +gb_internal void begin_error_block(void) { mutex_lock(&global_error_collector.block_mutex); global_error_collector.in_block.store(true); } -void end_error_block(void) { +gb_internal void end_error_block(void) { if (global_error_collector.error_buffer.count > 0) { isize n = global_error_collector.error_buffer.count; u8 *text = gb_alloc_array(permanent_allocator(), u8, n+1); @@ -127,7 +127,7 @@ void end_error_block(void) { #define ERROR_OUT_PROC(name) void name(char const *fmt, va_list va) typedef ERROR_OUT_PROC(ErrorOutProc); -ERROR_OUT_PROC(default_error_out_va) { +gb_internal ERROR_OUT_PROC(default_error_out_va) { gbFile *f = gb_file_get_standard(gbFileStandard_Error); char buf[4096] = {}; @@ -154,15 +154,15 @@ ERROR_OUT_PROC(default_error_out_va) { } -ErrorOutProc *error_out_va = default_error_out_va; +gb_global ErrorOutProc *error_out_va = default_error_out_va; // NOTE: defined in build_settings.cpp -bool global_warnings_as_errors(void); -bool global_ignore_warnings(void); -bool show_error_line(void); -gbString get_file_line_as_string(TokenPos const &pos, i32 *offset); +gb_internal bool global_warnings_as_errors(void); +gb_internal bool global_ignore_warnings(void); +gb_internal bool show_error_line(void); +gb_internal gbString get_file_line_as_string(TokenPos const &pos, i32 *offset); -void error_out(char const *fmt, ...) { +gb_internal void error_out(char const *fmt, ...) { va_list va; va_start(va, fmt); error_out_va(fmt, va); @@ -170,7 +170,7 @@ void error_out(char const *fmt, ...) { } -bool show_error_on_line(TokenPos const &pos, TokenPos end) { +gb_internal bool show_error_on_line(TokenPos const &pos, TokenPos end) { if (!show_error_line()) { return false; } @@ -237,7 +237,7 @@ bool show_error_on_line(TokenPos const &pos, TokenPos end) { return false; } -void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { +gb_internal void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { global_error_collector.count.fetch_add(1); mutex_lock(&global_error_collector.mutex); @@ -257,7 +257,7 @@ void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { } } -void warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { +gb_internal void warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { if (global_warnings_as_errors()) { error_va(pos, end, fmt, va); return; @@ -280,11 +280,11 @@ void warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) } -void error_line_va(char const *fmt, va_list va) { +gb_internal void error_line_va(char const *fmt, va_list va) { error_out_va(fmt, va); } -void error_no_newline_va(TokenPos const &pos, char const *fmt, va_list va) { +gb_internal void error_no_newline_va(TokenPos const &pos, char const *fmt, va_list va) { mutex_lock(&global_error_collector.mutex); global_error_collector.count++; // NOTE(bill): Duplicate error, skip it @@ -303,7 +303,7 @@ void error_no_newline_va(TokenPos const &pos, char const *fmt, va_list va) { } -void syntax_error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { +gb_internal void syntax_error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { mutex_lock(&global_error_collector.mutex); global_error_collector.count++; // NOTE(bill): Duplicate error, skip it @@ -323,7 +323,7 @@ void syntax_error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list } } -void syntax_warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { +gb_internal void syntax_warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { if (global_warnings_as_errors()) { syntax_error_va(pos, end, fmt, va); return; @@ -347,21 +347,21 @@ void syntax_warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_li -void warning(Token const &token, char const *fmt, ...) { +gb_internal void warning(Token const &token, char const *fmt, ...) { va_list va; va_start(va, fmt); warning_va(token.pos, {}, fmt, va); va_end(va); } -void error(Token const &token, char const *fmt, ...) { +gb_internal void error(Token const &token, char const *fmt, ...) { va_list va; va_start(va, fmt); error_va(token.pos, {}, fmt, va); va_end(va); } -void error(TokenPos pos, char const *fmt, ...) { +gb_internal void error(TokenPos pos, char const *fmt, ...) { va_list va; va_start(va, fmt); Token token = {}; @@ -370,7 +370,7 @@ void error(TokenPos pos, char const *fmt, ...) { va_end(va); } -void error_line(char const *fmt, ...) { +gb_internal void error_line(char const *fmt, ...) { va_list va; va_start(va, fmt); error_line_va(fmt, va); @@ -378,21 +378,21 @@ void error_line(char const *fmt, ...) { } -void syntax_error(Token const &token, char const *fmt, ...) { +gb_internal void syntax_error(Token const &token, char const *fmt, ...) { va_list va; va_start(va, fmt); syntax_error_va(token.pos, {}, fmt, va); va_end(va); } -void syntax_error(TokenPos pos, char const *fmt, ...) { +gb_internal void syntax_error(TokenPos pos, char const *fmt, ...) { va_list va; va_start(va, fmt); syntax_error_va(pos, {}, fmt, va); va_end(va); } -void syntax_warning(Token const &token, char const *fmt, ...) { +gb_internal void syntax_warning(Token const &token, char const *fmt, ...) { va_list va; va_start(va, fmt); syntax_warning_va(token.pos, {}, fmt, va); @@ -400,7 +400,7 @@ void syntax_warning(Token const &token, char const *fmt, ...) { } -void compiler_error(char const *fmt, ...) { +gb_internal void compiler_error(char const *fmt, ...) { va_list va; va_start(va, fmt); diff --git a/src/exact_value.cpp b/src/exact_value.cpp index 25ff08a82..d3ea4be68 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -15,7 +15,7 @@ struct Quaternion256 { f64 imag, jmag, kmag, real; }; -Quaternion256 quaternion256_inverse(Quaternion256 x) { +gb_internal Quaternion256 quaternion256_inverse(Quaternion256 x) { f64 invmag2 = 1.0 / (x.real*x.real + x.imag*x.imag + x.jmag*x.jmag + x.kmag*x.kmag); x.real = +x.real * invmag2; x.imag = -x.imag * invmag2; @@ -60,7 +60,7 @@ struct ExactValue { gb_global ExactValue const empty_exact_value = {}; -uintptr hash_exact_value(ExactValue v) { +gb_internal uintptr hash_exact_value(ExactValue v) { mutex_lock(&hash_exact_value_mutex); defer (mutex_unlock(&hash_exact_value_mutex)); @@ -97,44 +97,44 @@ uintptr hash_exact_value(ExactValue v) { } -ExactValue exact_value_compound(Ast *node) { +gb_internal ExactValue exact_value_compound(Ast *node) { ExactValue result = {ExactValue_Compound}; result.value_compound = node; return result; } -ExactValue exact_value_bool(bool b) { +gb_internal ExactValue exact_value_bool(bool b) { ExactValue result = {ExactValue_Bool}; result.value_bool = (b != 0); return result; } -ExactValue exact_value_string(String string) { +gb_internal ExactValue exact_value_string(String string) { // TODO(bill): Allow for numbers with underscores in them ExactValue result = {ExactValue_String}; result.value_string = string; return result; } -ExactValue exact_value_i64(i64 i) { +gb_internal ExactValue exact_value_i64(i64 i) { ExactValue result = {ExactValue_Integer}; big_int_from_i64(&result.value_integer, i); return result; } -ExactValue exact_value_u64(u64 i) { +gb_internal ExactValue exact_value_u64(u64 i) { ExactValue result = {ExactValue_Integer}; big_int_from_u64(&result.value_integer, i); return result; } -ExactValue exact_value_float(f64 f) { +gb_internal ExactValue exact_value_float(f64 f) { ExactValue result = {ExactValue_Float}; result.value_float = f; return result; } -ExactValue exact_value_complex(f64 real, f64 imag) { +gb_internal ExactValue exact_value_complex(f64 real, f64 imag) { ExactValue result = {ExactValue_Complex}; result.value_complex = gb_alloc_item(permanent_allocator(), Complex128); result.value_complex->real = real; @@ -142,7 +142,7 @@ ExactValue exact_value_complex(f64 real, f64 imag) { return result; } -ExactValue exact_value_quaternion(f64 real, f64 imag, f64 jmag, f64 kmag) { +gb_internal ExactValue exact_value_quaternion(f64 real, f64 imag, f64 jmag, f64 kmag) { ExactValue result = {ExactValue_Quaternion}; result.value_quaternion = gb_alloc_item(permanent_allocator(), Quaternion256); result.value_quaternion->real = real; @@ -152,27 +152,27 @@ ExactValue exact_value_quaternion(f64 real, f64 imag, f64 jmag, f64 kmag) { return result; } -ExactValue exact_value_pointer(i64 ptr) { +gb_internal ExactValue exact_value_pointer(i64 ptr) { ExactValue result = {ExactValue_Pointer}; result.value_pointer = ptr; return result; } -ExactValue exact_value_procedure(Ast *node) { +gb_internal ExactValue exact_value_procedure(Ast *node) { ExactValue result = {ExactValue_Procedure}; result.value_procedure = node; return result; } -ExactValue exact_value_typeid(Type *type) { +gb_internal ExactValue exact_value_typeid(Type *type) { ExactValue result = {ExactValue_Typeid}; result.value_typeid = type; return result; } -ExactValue exact_value_integer_from_string(String const &string) { +gb_internal ExactValue exact_value_integer_from_string(String const &string) { ExactValue result = {ExactValue_Integer}; bool success; big_int_from_string(&result.value_integer, string, &success); @@ -184,7 +184,7 @@ ExactValue exact_value_integer_from_string(String const &string) { -f64 float_from_string(String string) { +gb_internal f64 float_from_string(String string) { isize i = 0; u8 *str = string.text; isize len = string.len; @@ -262,7 +262,7 @@ f64 float_from_string(String string) { return sign * (frac ? (value / scale) : (value * scale)); } -ExactValue exact_value_float_from_string(String string) { +gb_internal ExactValue exact_value_float_from_string(String string) { if (string.len > 2 && string[0] == '0' && string[1] == 'h') { isize digit_count = 0; @@ -298,7 +298,7 @@ ExactValue exact_value_float_from_string(String string) { } -ExactValue exact_value_from_basic_literal(TokenKind kind, String const &string) { +gb_internal ExactValue exact_value_from_basic_literal(TokenKind kind, String const &string) { switch (kind) { case Token_String: return exact_value_string(string); case Token_Integer: return exact_value_integer_from_string(string); @@ -330,7 +330,7 @@ ExactValue exact_value_from_basic_literal(TokenKind kind, String const &string) return result; } -ExactValue exact_value_to_integer(ExactValue v) { +gb_internal ExactValue exact_value_to_integer(ExactValue v) { switch (v.kind) { case ExactValue_Bool: { i64 i = 0; @@ -357,7 +357,7 @@ ExactValue exact_value_to_integer(ExactValue v) { return r; } -ExactValue exact_value_to_float(ExactValue v) { +gb_internal ExactValue exact_value_to_float(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_float(big_int_to_f64(&v.value_integer)); @@ -368,7 +368,7 @@ ExactValue exact_value_to_float(ExactValue v) { return r; } -ExactValue exact_value_to_complex(ExactValue v) { +gb_internal ExactValue exact_value_to_complex(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_complex(big_int_to_f64(&v.value_integer), 0); @@ -383,7 +383,7 @@ ExactValue exact_value_to_complex(ExactValue v) { v.value_complex = gb_alloc_item(permanent_allocator(), Complex128); return r; } -ExactValue exact_value_to_quaternion(ExactValue v) { +gb_internal ExactValue exact_value_to_quaternion(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_quaternion(big_int_to_f64(&v.value_integer), 0, 0, 0); @@ -399,7 +399,7 @@ ExactValue exact_value_to_quaternion(ExactValue v) { return r; } -ExactValue exact_value_real(ExactValue v) { +gb_internal ExactValue exact_value_real(ExactValue v) { switch (v.kind) { case ExactValue_Integer: case ExactValue_Float: @@ -413,7 +413,7 @@ ExactValue exact_value_real(ExactValue v) { return r; } -ExactValue exact_value_imag(ExactValue v) { +gb_internal ExactValue exact_value_imag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: case ExactValue_Float: @@ -427,7 +427,7 @@ ExactValue exact_value_imag(ExactValue v) { return r; } -ExactValue exact_value_jmag(ExactValue v) { +gb_internal ExactValue exact_value_jmag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: case ExactValue_Float: @@ -440,7 +440,7 @@ ExactValue exact_value_jmag(ExactValue v) { return r; } -ExactValue exact_value_kmag(ExactValue v) { +gb_internal ExactValue exact_value_kmag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: case ExactValue_Float: @@ -453,7 +453,7 @@ ExactValue exact_value_kmag(ExactValue v) { return r; } -ExactValue exact_value_make_imag(ExactValue v) { +gb_internal ExactValue exact_value_make_imag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_complex(0, exact_value_to_float(v).value_float); @@ -466,7 +466,7 @@ ExactValue exact_value_make_imag(ExactValue v) { return r; } -ExactValue exact_value_make_jmag(ExactValue v) { +gb_internal ExactValue exact_value_make_jmag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_quaternion(0, 0, exact_value_to_float(v).value_float, 0); @@ -479,7 +479,7 @@ ExactValue exact_value_make_jmag(ExactValue v) { return r; } -ExactValue exact_value_make_kmag(ExactValue v) { +gb_internal ExactValue exact_value_make_kmag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_quaternion(0, 0, 0, exact_value_to_float(v).value_float); @@ -492,21 +492,21 @@ ExactValue exact_value_make_kmag(ExactValue v) { return r; } -i64 exact_value_to_i64(ExactValue v) { +gb_internal i64 exact_value_to_i64(ExactValue v) { v = exact_value_to_integer(v); if (v.kind == ExactValue_Integer) { return big_int_to_i64(&v.value_integer); } return 0; } -u64 exact_value_to_u64(ExactValue v) { +gb_internal u64 exact_value_to_u64(ExactValue v) { v = exact_value_to_integer(v); if (v.kind == ExactValue_Integer) { return big_int_to_u64(&v.value_integer); } return 0; } -f64 exact_value_to_f64(ExactValue v) { +gb_internal f64 exact_value_to_f64(ExactValue v) { v = exact_value_to_float(v); if (v.kind == ExactValue_Float) { return v.value_float; @@ -519,7 +519,7 @@ f64 exact_value_to_f64(ExactValue v) { -ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision, bool is_unsigned) { +gb_internal ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision, bool is_unsigned) { switch (op) { case Token_Add: { switch (v.kind) { @@ -596,7 +596,7 @@ failure: } // NOTE(bill): Make sure things are evaluated in correct order -i32 exact_value_order(ExactValue const &v) { +gb_internal i32 exact_value_order(ExactValue const &v) { switch (v.kind) { case ExactValue_Invalid: case ExactValue_Compound: @@ -623,7 +623,7 @@ i32 exact_value_order(ExactValue const &v) { } } -void match_exact_values(ExactValue *x, ExactValue *y) { +gb_internal void match_exact_values(ExactValue *x, ExactValue *y) { if (exact_value_order(*y) < exact_value_order(*x)) { match_exact_values(y, x); return; @@ -687,7 +687,7 @@ void match_exact_values(ExactValue *x, ExactValue *y) { } // TODO(bill): Allow for pointer arithmetic? Or are pointer slices good enough? -ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y) { +gb_internal ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y) { match_exact_values(&x, &y); switch (x.kind) { @@ -846,32 +846,32 @@ error:; // NOTE(bill): MSVC accepts this??? apparently you cannot declare variab return empty_exact_value; } -gb_inline ExactValue exact_value_add(ExactValue const &x, ExactValue const &y) { +gb_internal gb_inline ExactValue exact_value_add(ExactValue const &x, ExactValue const &y) { return exact_binary_operator_value(Token_Add, x, y); } -gb_inline ExactValue exact_value_sub(ExactValue const &x, ExactValue const &y) { +gb_internal gb_inline ExactValue exact_value_sub(ExactValue const &x, ExactValue const &y) { return exact_binary_operator_value(Token_Sub, x, y); } -gb_inline ExactValue exact_value_mul(ExactValue const &x, ExactValue const &y) { +gb_internal gb_inline ExactValue exact_value_mul(ExactValue const &x, ExactValue const &y) { return exact_binary_operator_value(Token_Mul, x, y); } -gb_inline ExactValue exact_value_quo(ExactValue const &x, ExactValue const &y) { +gb_internal gb_inline ExactValue exact_value_quo(ExactValue const &x, ExactValue const &y) { return exact_binary_operator_value(Token_Quo, x, y); } -gb_inline ExactValue exact_value_shift(TokenKind op, ExactValue const &x, ExactValue const &y) { +gb_internal gb_inline ExactValue exact_value_shift(TokenKind op, ExactValue const &x, ExactValue const &y) { return exact_binary_operator_value(op, x, y); } -gb_inline ExactValue exact_value_increment_one(ExactValue const &x) { +gb_internal gb_inline ExactValue exact_value_increment_one(ExactValue const &x) { return exact_binary_operator_value(Token_Add, x, exact_value_i64(1)); } -i32 cmp_f64(f64 a, f64 b) { +gb_internal gb_inline i32 cmp_f64(f64 a, f64 b) { return (a > b) - (a < b); } -bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) { +gb_internal bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) { match_exact_values(&x, &y); switch (x.kind) { @@ -974,7 +974,7 @@ Entity *strip_entity_wrapping(Entity *e); gbString write_expr_to_string(gbString str, Ast *node, bool shorthand); -gbString write_exact_value_to_string(gbString str, ExactValue const &v, isize string_limit=36) { +gb_internal gbString write_exact_value_to_string(gbString str, ExactValue const &v, isize string_limit=36) { switch (v.kind) { case ExactValue_Invalid: return str; @@ -1017,6 +1017,6 @@ gbString write_exact_value_to_string(gbString str, ExactValue const &v, isize st return str; }; -gbString exact_value_to_string(ExactValue const &v, isize string_limit=36) { +gb_internal gbString exact_value_to_string(ExactValue const &v, isize string_limit=36) { return write_exact_value_to_string(gb_string_make(heap_allocator(), ""), v, string_limit); } diff --git a/src/main.cpp b/src/main.cpp index 3b0a599db..614130bb6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,20 +8,20 @@ #include "build_settings.cpp" gb_global ThreadPool global_thread_pool; -void init_global_thread_pool(void) { +gb_internal void init_global_thread_pool(void) { isize thread_count = gb_max(build_context.thread_count, 1); isize worker_count = thread_count-1; // NOTE(bill): The main thread will also be used for work thread_pool_init(&global_thread_pool, permanent_allocator(), worker_count, "ThreadPoolWorker"); } -bool global_thread_pool_add_task(WorkerTaskProc *proc, void *data) { +gb_internal bool global_thread_pool_add_task(WorkerTaskProc *proc, void *data) { return thread_pool_add_task(&global_thread_pool, proc, data); } -void global_thread_pool_wait(void) { +gb_internal void global_thread_pool_wait(void) { thread_pool_wait(&global_thread_pool); } -void debugf(char const *fmt, ...) { +gb_internal void debugf(char const *fmt, ...) { if (build_context.show_debug_messages) { gb_printf_err("[DEBUG] "); va_list va; @@ -62,7 +62,7 @@ gb_global Timings global_timings = {0}; #include "bug_report.cpp" // NOTE(bill): 'name' is used in debugging and profiling modes -i32 system_exec_command_line_app(char const *name, char const *fmt, ...) { +gb_internal i32 system_exec_command_line_app(char const *name, char const *fmt, ...) { isize const cmd_cap = 64<<20; // 64 MiB should be more than enough char *cmd_line = gb_alloc_array(gb_heap_allocator(), char, cmd_cap); isize cmd_len = 0; @@ -124,7 +124,7 @@ i32 system_exec_command_line_app(char const *name, char const *fmt, ...) { } -i32 linker_stage(lbGenerator *gen) { +gb_internal i32 linker_stage(lbGenerator *gen) { i32 result = 0; Timings *timings = &global_timings; @@ -524,7 +524,7 @@ i32 linker_stage(lbGenerator *gen) { return result; } -Array setup_args(int argc, char const **argv) { +gb_internal Array setup_args(int argc, char const **argv) { gbAllocator a = heap_allocator(); #if defined(GB_SYSTEM_WINDOWS) @@ -553,7 +553,7 @@ Array setup_args(int argc, char const **argv) { #endif } -void print_usage_line(i32 indent, char const *fmt, ...) { +gb_internal void print_usage_line(i32 indent, char const *fmt, ...) { while (indent --> 0) { gb_printf_err("\t"); } @@ -564,7 +564,7 @@ void print_usage_line(i32 indent, char const *fmt, ...) { gb_printf_err("\n"); } -void usage(String argv0) { +gb_internal void usage(String argv0) { print_usage_line(0, "%.*s is a tool for managing Odin source code", LIT(argv0)); print_usage_line(0, "Usage:"); print_usage_line(1, "%.*s command [arguments]", LIT(argv0)); @@ -687,12 +687,12 @@ struct BuildFlag { }; -void add_flag(Array *build_flags, BuildFlagKind kind, String name, BuildFlagParamKind param_kind, u32 command_support, bool allow_mulitple=false) { +gb_internal void add_flag(Array *build_flags, BuildFlagKind kind, String name, BuildFlagParamKind param_kind, u32 command_support, bool allow_mulitple=false) { BuildFlag flag = {kind, name, param_kind, command_support, allow_mulitple}; array_add(build_flags, flag); } -ExactValue build_param_to_exact_value(String name, String param) { +gb_internal ExactValue build_param_to_exact_value(String name, String param) { ExactValue value = {}; /* @@ -747,7 +747,7 @@ ExactValue build_param_to_exact_value(String name, String param) { } // Writes a did-you-mean message for formerly deprecated flags. -void did_you_mean_flag(String flag) { +gb_internal void did_you_mean_flag(String flag) { gbAllocator a = heap_allocator(); String name = copy_string(a, flag); defer (gb_free(a, name.text)); @@ -760,7 +760,7 @@ void did_you_mean_flag(String flag) { gb_printf_err("Unknown flag: '%.*s'\n", LIT(flag)); } -bool parse_build_flags(Array args) { +gb_internal bool parse_build_flags(Array args) { auto build_flags = array_make(heap_allocator(), 0, BuildFlag_COUNT); add_flag(&build_flags, BuildFlag_Help, str_lit("help"), BuildFlagParam_None, Command_all); add_flag(&build_flags, BuildFlag_SingleFile, str_lit("file"), BuildFlagParam_None, Command__does_build | Command__does_check); @@ -1651,7 +1651,7 @@ bool parse_build_flags(Array args) { return !bad_flags; } -void timings_export_all(Timings *t, Checker *c, bool timings_are_finalized = false) { +gb_internal void timings_export_all(Timings *t, Checker *c, bool timings_are_finalized = false) { GB_ASSERT((!(build_context.export_timings_format == TimingsExportUnspecified) && build_context.export_timings_file.len > 0)); /* @@ -1749,7 +1749,7 @@ void timings_export_all(Timings *t, Checker *c, bool timings_are_finalized = fal gb_printf("Done.\n"); } -void show_timings(Checker *c, Timings *t) { +gb_internal void show_timings(Checker *c, Timings *t) { Parser *p = c->parser; isize lines = p->total_line_count; isize tokens = p->total_token_count; @@ -1878,7 +1878,7 @@ void show_timings(Checker *c, Timings *t) { } } -void remove_temp_files(lbGenerator *gen) { +gb_internal void remove_temp_files(lbGenerator *gen) { if (build_context.keep_temp_files) return; TIME_SECTION("remove keep temp files"); @@ -1902,7 +1902,7 @@ void remove_temp_files(lbGenerator *gen) { } -void print_show_help(String const arg0, String const &command) { +gb_internal void print_show_help(String const arg0, String const &command) { print_usage_line(0, "%.*s is a tool for managing Odin source code", LIT(arg0)); print_usage_line(0, "Usage:"); print_usage_line(1, "%.*s %.*s [arguments]", LIT(arg0), LIT(command)); @@ -2248,7 +2248,7 @@ void print_show_help(String const arg0, String const &command) { } } -void print_show_unused(Checker *c) { +gb_internal void print_show_unused(Checker *c) { CheckerInfo *info = &c->info; auto unused = array_make(permanent_allocator(), 0, info->entities.count); @@ -2322,7 +2322,7 @@ void print_show_unused(Checker *c) { print_usage_line(0, ""); } -bool check_env(void) { +gb_internal bool check_env(void) { gbAllocator a = heap_allocator(); char const *odin_root = gb_get_env("ODIN_ROOT", a); defer (gb_free(a, cast(void *)odin_root)); @@ -2348,7 +2348,7 @@ struct StripSemicolonFile { i64 written; }; -gbFileError write_file_with_stripped_tokens(gbFile *f, AstFile *file, i64 *written_) { +gb_internal gbFileError write_file_with_stripped_tokens(gbFile *f, AstFile *file, i64 *written_) { i64 written = 0; gbFileError err = gbFileError_None; u8 const *file_data = file->tokenizer.start; @@ -2388,7 +2388,7 @@ gbFileError write_file_with_stripped_tokens(gbFile *f, AstFile *file, i64 *writt return err; } -int strip_semicolons(Parser *parser) { +gb_internal int strip_semicolons(Parser *parser) { isize file_count = 0; for_array(i, parser->packages) { AstPackage *pkg = parser->packages[i]; diff --git a/src/microsoft_craziness.h b/src/microsoft_craziness.h index fc5f09904..4e6182e07 100644 --- a/src/microsoft_craziness.h +++ b/src/microsoft_craziness.h @@ -58,40 +58,40 @@ struct Find_Result { String vs_library_path; }; -String mc_wstring_to_string(wchar_t const *str) { +gb_internal String mc_wstring_to_string(wchar_t const *str) { return string16_to_string(mc_allocator, make_string16_c(str)); } -String16 mc_string_to_wstring(String str) { +gb_internal String16 mc_string_to_wstring(String str) { return string_to_string16(mc_allocator, str); } -String mc_concat(String a, String b) { +gb_internal String mc_concat(String a, String b) { return concatenate_strings(mc_allocator, a, b); } -String mc_concat(String a, String b, String c) { +gb_internal String mc_concat(String a, String b, String c) { return concatenate3_strings(mc_allocator, a, b, c); } -String mc_concat(String a, String b, String c, String d) { +gb_internal String mc_concat(String a, String b, String c, String d) { return concatenate4_strings(mc_allocator, a, b, c, d); } -String mc_get_env(String key) { +gb_internal String mc_get_env(String key) { char const * value = gb_get_env((char const *)key.text, mc_allocator); return make_string_c(value); } -void mc_free(String str) { +gb_internal void mc_free(String str) { if (str.len) gb_free(mc_allocator, str.text); } -void mc_free(String16 str) { +gb_internal void mc_free(String16 str) { if (str.len) gb_free(mc_allocator, str.text); } -void mc_free_all() { +gb_internal void mc_free_all() { gb_free_all(mc_allocator); } @@ -101,7 +101,7 @@ typedef struct _MC_Find_Data { } MC_Find_Data; -HANDLE mc_find_first(String wildcard, MC_Find_Data *find_data) { +gb_internal HANDLE mc_find_first(String wildcard, MC_Find_Data *find_data) { WIN32_FIND_DATAW _find_data; String16 wildcard_wide = mc_string_to_wstring(wildcard); @@ -115,7 +115,7 @@ HANDLE mc_find_first(String wildcard, MC_Find_Data *find_data) { return handle; } -bool mc_find_next(HANDLE handle, MC_Find_Data *find_data) { +gb_internal bool mc_find_next(HANDLE handle, MC_Find_Data *find_data) { WIN32_FIND_DATAW _find_data; bool success = !!FindNextFileW(handle, &_find_data); @@ -124,7 +124,7 @@ bool mc_find_next(HANDLE handle, MC_Find_Data *find_data) { return success; } -void mc_find_close(HANDLE handle) { +gb_internal void mc_find_close(HANDLE handle) { FindClose(handle); } @@ -216,7 +216,7 @@ struct Version_Data { }; typedef void (*MC_Visit_Proc)(String short_name, String full_name, Version_Data *data); -bool mc_visit_files(String dir_name, Version_Data *data, MC_Visit_Proc proc) { +gb_internal bool mc_visit_files(String dir_name, Version_Data *data, MC_Visit_Proc proc) { // Visit everything in one folder (non-recursively). If it's a directory // that doesn't start with ".", call the visit proc on it. The visit proc @@ -246,7 +246,7 @@ bool mc_visit_files(String dir_name, Version_Data *data, MC_Visit_Proc proc) { return true; } -String find_windows_kit_root(HKEY key, String const version) { +gb_internal String find_windows_kit_root(HKEY key, String const version) { // Given a key to an already opened registry entry, // get the value stored under the 'version' subkey. // If that's not the right terminology, hey, I never do registry stuff. @@ -275,7 +275,7 @@ String find_windows_kit_root(HKEY key, String const version) { return value; } -void win10_best(String short_name, String full_name, Version_Data *data) { +gb_internal void win10_best(String short_name, String full_name, Version_Data *data) { // Find the Windows 10 subdirectory with the highest version number. int i0, i1, i2, i3; @@ -307,7 +307,7 @@ void win10_best(String short_name, String full_name, Version_Data *data) { } } -void find_windows_kit_paths(Find_Result *result) { +gb_internal void find_windows_kit_paths(Find_Result *result) { bool sdk_found = false; HKEY main_key; @@ -355,7 +355,7 @@ void find_windows_kit_paths(Find_Result *result) { } } -bool find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *result) { +gb_internal bool find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *result) { // The name of this procedure is kind of cryptic. Its purpose is // to fight through Microsoft craziness. The things that the fine // Visual Studio team want you to do, JUST TO FIND A SINGLE FOLDER @@ -519,7 +519,7 @@ bool find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res // NOTE(WalterPlinge): Environment variables can help to find Visual C++ and WinSDK paths for both // official and portable installations (like mmozeiko's portable msvc script). -void find_windows_kit_paths_from_env_vars(Find_Result *result) { +gb_internal void find_windows_kit_paths_from_env_vars(Find_Result *result) { if (build_context.metrics.arch != TargetArch_amd64 && build_context.metrics.arch != TargetArch_i386) { return; } @@ -669,7 +669,7 @@ void find_windows_kit_paths_from_env_vars(Find_Result *result) { // NOTE(WalterPlinge): Environment variables can help to find Visual C++ and WinSDK paths for both // official and portable installations (like mmozeiko's portable msvc script). This will only use // the first paths it finds, and won't overwrite any values that `result` already has. -void find_visual_studio_paths_from_env_vars(Find_Result *result) { +gb_internal void find_visual_studio_paths_from_env_vars(Find_Result *result) { if (build_context.metrics.arch != TargetArch_amd64 && build_context.metrics.arch != TargetArch_i386) { return; } @@ -756,7 +756,7 @@ void find_visual_studio_paths_from_env_vars(Find_Result *result) { } } -Find_Result find_visual_studio_and_windows_sdk() { +gb_internal Find_Result find_visual_studio_and_windows_sdk() { Find_Result r = {}; find_windows_kit_paths(&r); find_visual_studio_by_fighting_through_microsoft_craziness(&r); diff --git a/src/parser.cpp b/src/parser.cpp index 884ddefa2..1606f5b47 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -3,7 +3,7 @@ // #undef at the bottom of this file #define ALLOW_NEWLINE (!build_context.strict_style) -Token token_end_of_line(AstFile *f, Token tok) { +gb_internal Token token_end_of_line(AstFile *f, Token tok) { u8 const *start = f->tokenizer.start + tok.pos.offset; u8 const *s = start; while (*s && *s != '\n' && s < f->tokenizer.end) { @@ -13,7 +13,7 @@ Token token_end_of_line(AstFile *f, Token tok) { return tok; } -gbString get_file_line_as_string(TokenPos const &pos, i32 *offset_) { +gb_internal gbString get_file_line_as_string(TokenPos const &pos, i32 *offset_) { AstFile *file = thread_safe_get_ast_file_from_id(pos.file_id); if (file == nullptr) { return nullptr; @@ -55,7 +55,7 @@ gbString get_file_line_as_string(TokenPos const &pos, i32 *offset_) { -isize ast_node_size(AstKind kind) { +gb_internal isize ast_node_size(AstKind kind) { return align_formula_isize(gb_size_of(AstCommonStuff) + ast_variant_sizes[kind], gb_align_of(void *)); } @@ -63,7 +63,7 @@ isize ast_node_size(AstKind kind) { gb_global std::atomic global_total_node_memory_allocated; // NOTE(bill): And this below is why is I/we need a new language! Discriminated unions are a pain in C/C++ -Ast *alloc_ast_node(AstFile *f, AstKind kind) { +gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind) { gbAllocator a = ast_allocator(f); isize size = ast_node_size(kind); @@ -77,8 +77,8 @@ Ast *alloc_ast_node(AstFile *f, AstKind kind) { return node; } -Ast *clone_ast(Ast *node); -Array clone_ast_array(Array const &array) { +gb_internal Ast *clone_ast(Ast *node); +gb_internal Array clone_ast_array(Array const &array) { Array result = {}; if (array.count > 0) { result = array_make(ast_allocator(nullptr), array.count); @@ -88,7 +88,7 @@ Array clone_ast_array(Array const &array) { } return result; } -Slice clone_ast_array(Slice const &array) { +gb_internal Slice clone_ast_array(Slice const &array) { Slice result = {}; if (array.count > 0) { result = slice_clone(permanent_allocator(), array); @@ -99,7 +99,7 @@ Slice clone_ast_array(Slice const &array) { return result; } -Ast *clone_ast(Ast *node) { +gb_internal Ast *clone_ast(Ast *node) { if (node == nullptr) { return nullptr; } @@ -403,7 +403,7 @@ Ast *clone_ast(Ast *node) { } -void error(Ast *node, char const *fmt, ...) { +gb_internal void error(Ast *node, char const *fmt, ...) { Token token = {}; TokenPos end_pos = {}; if (node != nullptr) { @@ -421,7 +421,7 @@ void error(Ast *node, char const *fmt, ...) { } } -void error_no_newline(Ast *node, char const *fmt, ...) { +gb_internal void error_no_newline(Ast *node, char const *fmt, ...) { Token token = {}; if (node != nullptr) { token = ast_token(node); @@ -436,7 +436,7 @@ void error_no_newline(Ast *node, char const *fmt, ...) { } } -void warning(Ast *node, char const *fmt, ...) { +gb_internal void warning(Ast *node, char const *fmt, ...) { Token token = {}; TokenPos end_pos = {}; if (node != nullptr) { @@ -449,7 +449,7 @@ void warning(Ast *node, char const *fmt, ...) { va_end(va); } -void syntax_error(Ast *node, char const *fmt, ...) { +gb_internal void syntax_error(Ast *node, char const *fmt, ...) { Token token = {}; TokenPos end_pos = {}; if (node != nullptr) { @@ -467,14 +467,14 @@ void syntax_error(Ast *node, char const *fmt, ...) { } -bool ast_node_expect(Ast *node, AstKind kind) { +gb_internal bool ast_node_expect(Ast *node, AstKind kind) { if (node->kind != kind) { syntax_error(node, "Expected %.*s, got %.*s", LIT(ast_strings[kind]), LIT(ast_strings[node->kind])); return false; } return true; } -bool ast_node_expect2(Ast *node, AstKind kind0, AstKind kind1) { +gb_internal bool ast_node_expect2(Ast *node, AstKind kind0, AstKind kind1) { if (node->kind != kind0 && node->kind != kind1) { syntax_error(node, "Expected %.*s or %.*s, got %.*s", LIT(ast_strings[kind0]), LIT(ast_strings[kind1]), LIT(ast_strings[node->kind])); return false; @@ -482,14 +482,14 @@ bool ast_node_expect2(Ast *node, AstKind kind0, AstKind kind1) { return true; } -Ast *ast_bad_expr(AstFile *f, Token begin, Token end) { +gb_internal Ast *ast_bad_expr(AstFile *f, Token begin, Token end) { Ast *result = alloc_ast_node(f, Ast_BadExpr); result->BadExpr.begin = begin; result->BadExpr.end = end; return result; } -Ast *ast_tag_expr(AstFile *f, Token token, Token name, Ast *expr) { +gb_internal Ast *ast_tag_expr(AstFile *f, Token token, Token name, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_TagExpr); result->TagExpr.token = token; result->TagExpr.name = name; @@ -497,7 +497,7 @@ Ast *ast_tag_expr(AstFile *f, Token token, Token name, Ast *expr) { return result; } -Ast *ast_tag_stmt(AstFile *f, Token token, Token name, Ast *stmt) { +gb_internal Ast *ast_tag_stmt(AstFile *f, Token token, Token name, Ast *stmt) { Ast *result = alloc_ast_node(f, Ast_TagStmt); result->TagStmt.token = token; result->TagStmt.name = name; @@ -505,14 +505,14 @@ Ast *ast_tag_stmt(AstFile *f, Token token, Token name, Ast *stmt) { return result; } -Ast *ast_unary_expr(AstFile *f, Token op, Ast *expr) { +gb_internal Ast *ast_unary_expr(AstFile *f, Token op, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_UnaryExpr); result->UnaryExpr.op = op; result->UnaryExpr.expr = expr; return result; } -Ast *ast_binary_expr(AstFile *f, Token op, Ast *left, Ast *right) { +gb_internal Ast *ast_binary_expr(AstFile *f, Token op, Ast *left, Ast *right) { Ast *result = alloc_ast_node(f, Ast_BinaryExpr); if (left == nullptr) { @@ -531,7 +531,7 @@ Ast *ast_binary_expr(AstFile *f, Token op, Ast *left, Ast *right) { return result; } -Ast *ast_paren_expr(AstFile *f, Ast *expr, Token open, Token close) { +gb_internal Ast *ast_paren_expr(AstFile *f, Ast *expr, Token open, Token close) { Ast *result = alloc_ast_node(f, Ast_ParenExpr); result->ParenExpr.expr = expr; result->ParenExpr.open = open; @@ -539,7 +539,7 @@ Ast *ast_paren_expr(AstFile *f, Ast *expr, Token open, Token close) { return result; } -Ast *ast_call_expr(AstFile *f, Ast *proc, Array const &args, Token open, Token close, Token ellipsis) { +gb_internal Ast *ast_call_expr(AstFile *f, Ast *proc, Array const &args, Token open, Token close, Token ellipsis) { Ast *result = alloc_ast_node(f, Ast_CallExpr); result->CallExpr.proc = proc; result->CallExpr.args = slice_from_array(args); @@ -550,7 +550,7 @@ Ast *ast_call_expr(AstFile *f, Ast *proc, Array const &args, Token open, } -Ast *ast_selector_expr(AstFile *f, Token token, Ast *expr, Ast *selector) { +gb_internal Ast *ast_selector_expr(AstFile *f, Token token, Ast *expr, Ast *selector) { Ast *result = alloc_ast_node(f, Ast_SelectorExpr); result->SelectorExpr.token = token; result->SelectorExpr.expr = expr; @@ -558,14 +558,14 @@ Ast *ast_selector_expr(AstFile *f, Token token, Ast *expr, Ast *selector) { return result; } -Ast *ast_implicit_selector_expr(AstFile *f, Token token, Ast *selector) { +gb_internal Ast *ast_implicit_selector_expr(AstFile *f, Token token, Ast *selector) { Ast *result = alloc_ast_node(f, Ast_ImplicitSelectorExpr); result->ImplicitSelectorExpr.token = token; result->ImplicitSelectorExpr.selector = selector; return result; } -Ast *ast_selector_call_expr(AstFile *f, Token token, Ast *expr, Ast *call) { +gb_internal Ast *ast_selector_call_expr(AstFile *f, Token token, Ast *expr, Ast *call) { Ast *result = alloc_ast_node(f, Ast_SelectorCallExpr); result->SelectorCallExpr.token = token; result->SelectorCallExpr.expr = expr; @@ -574,7 +574,7 @@ Ast *ast_selector_call_expr(AstFile *f, Token token, Ast *expr, Ast *call) { } -Ast *ast_index_expr(AstFile *f, Ast *expr, Ast *index, Token open, Token close) { +gb_internal Ast *ast_index_expr(AstFile *f, Ast *expr, Ast *index, Token open, Token close) { Ast *result = alloc_ast_node(f, Ast_IndexExpr); result->IndexExpr.expr = expr; result->IndexExpr.index = index; @@ -584,7 +584,7 @@ Ast *ast_index_expr(AstFile *f, Ast *expr, Ast *index, Token open, Token close) } -Ast *ast_slice_expr(AstFile *f, Ast *expr, Token open, Token close, Token interval, Ast *low, Ast *high) { +gb_internal Ast *ast_slice_expr(AstFile *f, Ast *expr, Token open, Token close, Token interval, Ast *low, Ast *high) { Ast *result = alloc_ast_node(f, Ast_SliceExpr); result->SliceExpr.expr = expr; result->SliceExpr.open = open; @@ -595,7 +595,7 @@ Ast *ast_slice_expr(AstFile *f, Ast *expr, Token open, Token close, Token interv return result; } -Ast *ast_deref_expr(AstFile *f, Ast *expr, Token op) { +gb_internal Ast *ast_deref_expr(AstFile *f, Ast *expr, Token op) { Ast *result = alloc_ast_node(f, Ast_DerefExpr); result->DerefExpr.expr = expr; result->DerefExpr.op = op; @@ -603,7 +603,7 @@ Ast *ast_deref_expr(AstFile *f, Ast *expr, Token op) { } -Ast *ast_matrix_index_expr(AstFile *f, Ast *expr, Token open, Token close, Token interval, Ast *row, Ast *column) { +gb_internal Ast *ast_matrix_index_expr(AstFile *f, Ast *expr, Token open, Token close, Token interval, Ast *row, Ast *column) { Ast *result = alloc_ast_node(f, Ast_MatrixIndexExpr); result->MatrixIndexExpr.expr = expr; result->MatrixIndexExpr.row_index = row; @@ -614,24 +614,24 @@ Ast *ast_matrix_index_expr(AstFile *f, Ast *expr, Token open, Token close, Token } -Ast *ast_ident(AstFile *f, Token token) { +gb_internal Ast *ast_ident(AstFile *f, Token token) { Ast *result = alloc_ast_node(f, Ast_Ident); result->Ident.token = token; return result; } -Ast *ast_implicit(AstFile *f, Token token) { +gb_internal Ast *ast_implicit(AstFile *f, Token token) { Ast *result = alloc_ast_node(f, Ast_Implicit); result->Implicit = token; return result; } -Ast *ast_undef(AstFile *f, Token token) { +gb_internal Ast *ast_undef(AstFile *f, Token token) { Ast *result = alloc_ast_node(f, Ast_Undef); result->Undef = token; return result; } -ExactValue exact_value_from_token(AstFile *f, Token const &token) { +gb_internal ExactValue exact_value_from_token(AstFile *f, Token const &token) { String s = token.string; switch (token.kind) { case Token_Rune: @@ -648,7 +648,7 @@ ExactValue exact_value_from_token(AstFile *f, Token const &token) { return exact_value_from_basic_literal(token.kind, s); } -String string_value_from_token(AstFile *f, Token const &token) { +gb_internal String string_value_from_token(AstFile *f, Token const &token) { ExactValue value = exact_value_from_token(f, token); String str = {}; if (value.kind == ExactValue_String) { @@ -658,7 +658,7 @@ String string_value_from_token(AstFile *f, Token const &token) { } -Ast *ast_basic_lit(AstFile *f, Token basic_lit) { +gb_internal Ast *ast_basic_lit(AstFile *f, Token basic_lit) { Ast *result = alloc_ast_node(f, Ast_BasicLit); result->BasicLit.token = basic_lit; result->tav.mode = Addressing_Constant; @@ -666,14 +666,14 @@ Ast *ast_basic_lit(AstFile *f, Token basic_lit) { return result; } -Ast *ast_basic_directive(AstFile *f, Token token, Token name) { +gb_internal Ast *ast_basic_directive(AstFile *f, Token token, Token name) { Ast *result = alloc_ast_node(f, Ast_BasicDirective); result->BasicDirective.token = token; result->BasicDirective.name = name; return result; } -Ast *ast_ellipsis(AstFile *f, Token token, Ast *expr) { +gb_internal Ast *ast_ellipsis(AstFile *f, Token token, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_Ellipsis); result->Ellipsis.token = token; result->Ellipsis.expr = expr; @@ -681,7 +681,7 @@ Ast *ast_ellipsis(AstFile *f, Token token, Ast *expr) { } -Ast *ast_proc_group(AstFile *f, Token token, Token open, Token close, Array const &args) { +gb_internal Ast *ast_proc_group(AstFile *f, Token token, Token open, Token close, Array const &args) { Ast *result = alloc_ast_node(f, Ast_ProcGroup); result->ProcGroup.token = token; result->ProcGroup.open = open; @@ -690,7 +690,7 @@ Ast *ast_proc_group(AstFile *f, Token token, Token open, Token close, Array const &where_clauses) { +gb_internal Ast *ast_proc_lit(AstFile *f, Ast *type, Ast *body, u64 tags, Token where_token, Array const &where_clauses) { Ast *result = alloc_ast_node(f, Ast_ProcLit); result->ProcLit.type = type; result->ProcLit.body = body; @@ -700,7 +700,7 @@ Ast *ast_proc_lit(AstFile *f, Ast *type, Ast *body, u64 tags, Token where_token, return result; } -Ast *ast_field_value(AstFile *f, Ast *field, Ast *value, Token eq) { +gb_internal Ast *ast_field_value(AstFile *f, Ast *field, Ast *value, Token eq) { Ast *result = alloc_ast_node(f, Ast_FieldValue); result->FieldValue.field = field; result->FieldValue.value = value; @@ -709,7 +709,7 @@ Ast *ast_field_value(AstFile *f, Ast *field, Ast *value, Token eq) { } -Ast *ast_enum_field_value(AstFile *f, Ast *name, Ast *value, CommentGroup *docs, CommentGroup *comment) { +gb_internal Ast *ast_enum_field_value(AstFile *f, Ast *name, Ast *value, CommentGroup *docs, CommentGroup *comment) { Ast *result = alloc_ast_node(f, Ast_EnumFieldValue); result->EnumFieldValue.name = name; result->EnumFieldValue.value = value; @@ -718,7 +718,7 @@ Ast *ast_enum_field_value(AstFile *f, Ast *name, Ast *value, CommentGroup *docs, return result; } -Ast *ast_compound_lit(AstFile *f, Ast *type, Array const &elems, Token open, Token close) { +gb_internal Ast *ast_compound_lit(AstFile *f, Ast *type, Array const &elems, Token open, Token close) { Ast *result = alloc_ast_node(f, Ast_CompoundLit); result->CompoundLit.type = type; result->CompoundLit.elems = slice_from_array(elems); @@ -728,14 +728,14 @@ Ast *ast_compound_lit(AstFile *f, Ast *type, Array const &elems, Token op } -Ast *ast_ternary_if_expr(AstFile *f, Ast *x, Ast *cond, Ast *y) { +gb_internal Ast *ast_ternary_if_expr(AstFile *f, Ast *x, Ast *cond, Ast *y) { Ast *result = alloc_ast_node(f, Ast_TernaryIfExpr); result->TernaryIfExpr.x = x; result->TernaryIfExpr.cond = cond; result->TernaryIfExpr.y = y; return result; } -Ast *ast_ternary_when_expr(AstFile *f, Ast *x, Ast *cond, Ast *y) { +gb_internal Ast *ast_ternary_when_expr(AstFile *f, Ast *x, Ast *cond, Ast *y) { Ast *result = alloc_ast_node(f, Ast_TernaryWhenExpr); result->TernaryWhenExpr.x = x; result->TernaryWhenExpr.cond = cond; @@ -743,7 +743,7 @@ Ast *ast_ternary_when_expr(AstFile *f, Ast *x, Ast *cond, Ast *y) { return result; } -Ast *ast_or_else_expr(AstFile *f, Ast *x, Token const &token, Ast *y) { +gb_internal Ast *ast_or_else_expr(AstFile *f, Ast *x, Token const &token, Ast *y) { Ast *result = alloc_ast_node(f, Ast_OrElseExpr); result->OrElseExpr.x = x; result->OrElseExpr.token = token; @@ -751,28 +751,28 @@ Ast *ast_or_else_expr(AstFile *f, Ast *x, Token const &token, Ast *y) { return result; } -Ast *ast_or_return_expr(AstFile *f, Ast *expr, Token const &token) { +gb_internal Ast *ast_or_return_expr(AstFile *f, Ast *expr, Token const &token) { Ast *result = alloc_ast_node(f, Ast_OrReturnExpr); result->OrReturnExpr.expr = expr; result->OrReturnExpr.token = token; return result; } -Ast *ast_type_assertion(AstFile *f, Ast *expr, Token dot, Ast *type) { +gb_internal Ast *ast_type_assertion(AstFile *f, Ast *expr, Token dot, Ast *type) { Ast *result = alloc_ast_node(f, Ast_TypeAssertion); result->TypeAssertion.expr = expr; result->TypeAssertion.dot = dot; result->TypeAssertion.type = type; return result; } -Ast *ast_type_cast(AstFile *f, Token token, Ast *type, Ast *expr) { +gb_internal Ast *ast_type_cast(AstFile *f, Token token, Ast *type, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_TypeCast); result->TypeCast.token = token; result->TypeCast.type = type; result->TypeCast.expr = expr; return result; } -Ast *ast_auto_cast(AstFile *f, Token token, Ast *expr) { +gb_internal Ast *ast_auto_cast(AstFile *f, Token token, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_AutoCast); result->AutoCast.token = token; result->AutoCast.expr = expr; @@ -780,7 +780,7 @@ Ast *ast_auto_cast(AstFile *f, Token token, Ast *expr) { } -Ast *ast_inline_asm_expr(AstFile *f, Token token, Token open, Token close, +gb_internal Ast *ast_inline_asm_expr(AstFile *f, Token token, Token open, Token close, Array const ¶m_types, Ast *return_type, Ast *asm_string, @@ -806,26 +806,26 @@ Ast *ast_inline_asm_expr(AstFile *f, Token token, Token open, Token close, -Ast *ast_bad_stmt(AstFile *f, Token begin, Token end) { +gb_internal Ast *ast_bad_stmt(AstFile *f, Token begin, Token end) { Ast *result = alloc_ast_node(f, Ast_BadStmt); result->BadStmt.begin = begin; result->BadStmt.end = end; return result; } -Ast *ast_empty_stmt(AstFile *f, Token token) { +gb_internal Ast *ast_empty_stmt(AstFile *f, Token token) { Ast *result = alloc_ast_node(f, Ast_EmptyStmt); result->EmptyStmt.token = token; return result; } -Ast *ast_expr_stmt(AstFile *f, Ast *expr) { +gb_internal Ast *ast_expr_stmt(AstFile *f, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_ExprStmt); result->ExprStmt.expr = expr; return result; } -Ast *ast_assign_stmt(AstFile *f, Token op, Array const &lhs, Array const &rhs) { +gb_internal Ast *ast_assign_stmt(AstFile *f, Token op, Array const &lhs, Array const &rhs) { Ast *result = alloc_ast_node(f, Ast_AssignStmt); result->AssignStmt.op = op; result->AssignStmt.lhs = slice_from_array(lhs); @@ -834,7 +834,7 @@ Ast *ast_assign_stmt(AstFile *f, Token op, Array const &lhs, Array } -Ast *ast_block_stmt(AstFile *f, Array const &stmts, Token open, Token close) { +gb_internal Ast *ast_block_stmt(AstFile *f, Array const &stmts, Token open, Token close) { Ast *result = alloc_ast_node(f, Ast_BlockStmt); result->BlockStmt.stmts = slice_from_array(stmts); result->BlockStmt.open = open; @@ -842,7 +842,7 @@ Ast *ast_block_stmt(AstFile *f, Array const &stmts, Token open, Token clo return result; } -Ast *ast_if_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *body, Ast *else_stmt) { +gb_internal Ast *ast_if_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *body, Ast *else_stmt) { Ast *result = alloc_ast_node(f, Ast_IfStmt); result->IfStmt.token = token; result->IfStmt.init = init; @@ -852,7 +852,7 @@ Ast *ast_if_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *body, Ast * return result; } -Ast *ast_when_stmt(AstFile *f, Token token, Ast *cond, Ast *body, Ast *else_stmt) { +gb_internal Ast *ast_when_stmt(AstFile *f, Token token, Ast *cond, Ast *body, Ast *else_stmt) { Ast *result = alloc_ast_node(f, Ast_WhenStmt); result->WhenStmt.token = token; result->WhenStmt.cond = cond; @@ -862,7 +862,7 @@ Ast *ast_when_stmt(AstFile *f, Token token, Ast *cond, Ast *body, Ast *else_stmt } -Ast *ast_return_stmt(AstFile *f, Token token, Array const &results) { +gb_internal Ast *ast_return_stmt(AstFile *f, Token token, Array const &results) { Ast *result = alloc_ast_node(f, Ast_ReturnStmt); result->ReturnStmt.token = token; result->ReturnStmt.results = slice_from_array(results); @@ -870,7 +870,7 @@ Ast *ast_return_stmt(AstFile *f, Token token, Array const &results) { } -Ast *ast_for_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *post, Ast *body) { +gb_internal Ast *ast_for_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *post, Ast *body) { Ast *result = alloc_ast_node(f, Ast_ForStmt); result->ForStmt.token = token; result->ForStmt.init = init; @@ -880,7 +880,7 @@ Ast *ast_for_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *post, Ast return result; } -Ast *ast_range_stmt(AstFile *f, Token token, Slice vals, Token in_token, Ast *expr, Ast *body) { +gb_internal Ast *ast_range_stmt(AstFile *f, Token token, Slice vals, Token in_token, Ast *expr, Ast *body) { Ast *result = alloc_ast_node(f, Ast_RangeStmt); result->RangeStmt.token = token; result->RangeStmt.vals = vals; @@ -890,7 +890,7 @@ Ast *ast_range_stmt(AstFile *f, Token token, Slice vals, Token in_token, return result; } -Ast *ast_unroll_range_stmt(AstFile *f, Token unroll_token, Token for_token, Ast *val0, Ast *val1, Token in_token, Ast *expr, Ast *body) { +gb_internal Ast *ast_unroll_range_stmt(AstFile *f, Token unroll_token, Token for_token, Ast *val0, Ast *val1, Token in_token, Ast *expr, Ast *body) { Ast *result = alloc_ast_node(f, Ast_UnrollRangeStmt); result->UnrollRangeStmt.unroll_token = unroll_token; result->UnrollRangeStmt.for_token = for_token; @@ -902,7 +902,7 @@ Ast *ast_unroll_range_stmt(AstFile *f, Token unroll_token, Token for_token, Ast return result; } -Ast *ast_switch_stmt(AstFile *f, Token token, Ast *init, Ast *tag, Ast *body) { +gb_internal Ast *ast_switch_stmt(AstFile *f, Token token, Ast *init, Ast *tag, Ast *body) { Ast *result = alloc_ast_node(f, Ast_SwitchStmt); result->SwitchStmt.token = token; result->SwitchStmt.init = init; @@ -913,7 +913,7 @@ Ast *ast_switch_stmt(AstFile *f, Token token, Ast *init, Ast *tag, Ast *body) { } -Ast *ast_type_switch_stmt(AstFile *f, Token token, Ast *tag, Ast *body) { +gb_internal Ast *ast_type_switch_stmt(AstFile *f, Token token, Ast *tag, Ast *body) { Ast *result = alloc_ast_node(f, Ast_TypeSwitchStmt); result->TypeSwitchStmt.token = token; result->TypeSwitchStmt.tag = tag; @@ -922,7 +922,7 @@ Ast *ast_type_switch_stmt(AstFile *f, Token token, Ast *tag, Ast *body) { return result; } -Ast *ast_case_clause(AstFile *f, Token token, Array const &list, Array const &stmts) { +gb_internal Ast *ast_case_clause(AstFile *f, Token token, Array const &list, Array const &stmts) { Ast *result = alloc_ast_node(f, Ast_CaseClause); result->CaseClause.token = token; result->CaseClause.list = slice_from_array(list); @@ -931,21 +931,21 @@ Ast *ast_case_clause(AstFile *f, Token token, Array const &list, ArrayDeferStmt.token = token; result->DeferStmt.stmt = stmt; return result; } -Ast *ast_branch_stmt(AstFile *f, Token token, Ast *label) { +gb_internal Ast *ast_branch_stmt(AstFile *f, Token token, Ast *label) { Ast *result = alloc_ast_node(f, Ast_BranchStmt); result->BranchStmt.token = token; result->BranchStmt.label = label; return result; } -Ast *ast_using_stmt(AstFile *f, Token token, Array const &list) { +gb_internal Ast *ast_using_stmt(AstFile *f, Token token, Array const &list) { Ast *result = alloc_ast_node(f, Ast_UsingStmt); result->UsingStmt.token = token; result->UsingStmt.list = slice_from_array(list); @@ -954,14 +954,14 @@ Ast *ast_using_stmt(AstFile *f, Token token, Array const &list) { -Ast *ast_bad_decl(AstFile *f, Token begin, Token end) { +gb_internal Ast *ast_bad_decl(AstFile *f, Token begin, Token end) { Ast *result = alloc_ast_node(f, Ast_BadDecl); result->BadDecl.begin = begin; result->BadDecl.end = end; return result; } -Ast *ast_field(AstFile *f, Array const &names, Ast *type, Ast *default_value, u32 flags, Token tag, +gb_internal Ast *ast_field(AstFile *f, Array const &names, Ast *type, Ast *default_value, u32 flags, Token tag, CommentGroup *docs, CommentGroup *comment) { Ast *result = alloc_ast_node(f, Ast_Field); result->Field.names = slice_from_array(names); @@ -974,28 +974,28 @@ Ast *ast_field(AstFile *f, Array const &names, Ast *type, Ast *default_va return result; } -Ast *ast_field_list(AstFile *f, Token token, Array const &list) { +gb_internal Ast *ast_field_list(AstFile *f, Token token, Array const &list) { Ast *result = alloc_ast_node(f, Ast_FieldList); result->FieldList.token = token; result->FieldList.list = slice_from_array(list); return result; } -Ast *ast_typeid_type(AstFile *f, Token token, Ast *specialization) { +gb_internal Ast *ast_typeid_type(AstFile *f, Token token, Ast *specialization) { Ast *result = alloc_ast_node(f, Ast_TypeidType); result->TypeidType.token = token; result->TypeidType.specialization = specialization; return result; } -Ast *ast_helper_type(AstFile *f, Token token, Ast *type) { +gb_internal Ast *ast_helper_type(AstFile *f, Token token, Ast *type) { Ast *result = alloc_ast_node(f, Ast_HelperType); result->HelperType.token = token; result->HelperType.type = type; return result; } -Ast *ast_distinct_type(AstFile *f, Token token, Ast *type) { +gb_internal Ast *ast_distinct_type(AstFile *f, Token token, Ast *type) { Ast *result = alloc_ast_node(f, Ast_DistinctType); result->DistinctType.token = token; result->DistinctType.type = type; @@ -1003,7 +1003,7 @@ Ast *ast_distinct_type(AstFile *f, Token token, Ast *type) { } -Ast *ast_poly_type(AstFile *f, Token token, Ast *type, Ast *specialization) { +gb_internal Ast *ast_poly_type(AstFile *f, Token token, Ast *type, Ast *specialization) { Ast *result = alloc_ast_node(f, Ast_PolyType); result->PolyType.token = token; result->PolyType.type = type; @@ -1012,7 +1012,7 @@ Ast *ast_poly_type(AstFile *f, Token token, Ast *type, Ast *specialization) { } -Ast *ast_proc_type(AstFile *f, Token token, Ast *params, Ast *results, u64 tags, ProcCallingConvention calling_convention, bool generic, bool diverging) { +gb_internal Ast *ast_proc_type(AstFile *f, Token token, Ast *params, Ast *results, u64 tags, ProcCallingConvention calling_convention, bool generic, bool diverging) { Ast *result = alloc_ast_node(f, Ast_ProcType); result->ProcType.token = token; result->ProcType.params = params; @@ -1024,25 +1024,25 @@ Ast *ast_proc_type(AstFile *f, Token token, Ast *params, Ast *results, u64 tags, return result; } -Ast *ast_relative_type(AstFile *f, Ast *tag, Ast *type) { +gb_internal Ast *ast_relative_type(AstFile *f, Ast *tag, Ast *type) { Ast *result = alloc_ast_node(f, Ast_RelativeType); result->RelativeType.tag = tag; result->RelativeType.type = type; return result; } -Ast *ast_pointer_type(AstFile *f, Token token, Ast *type) { +gb_internal Ast *ast_pointer_type(AstFile *f, Token token, Ast *type) { Ast *result = alloc_ast_node(f, Ast_PointerType); result->PointerType.token = token; result->PointerType.type = type; return result; } -Ast *ast_multi_pointer_type(AstFile *f, Token token, Ast *type) { +gb_internal Ast *ast_multi_pointer_type(AstFile *f, Token token, Ast *type) { Ast *result = alloc_ast_node(f, Ast_MultiPointerType); result->MultiPointerType.token = token; result->MultiPointerType.type = type; return result; } -Ast *ast_array_type(AstFile *f, Token token, Ast *count, Ast *elem) { +gb_internal Ast *ast_array_type(AstFile *f, Token token, Ast *count, Ast *elem) { Ast *result = alloc_ast_node(f, Ast_ArrayType); result->ArrayType.token = token; result->ArrayType.count = count; @@ -1050,14 +1050,14 @@ Ast *ast_array_type(AstFile *f, Token token, Ast *count, Ast *elem) { return result; } -Ast *ast_dynamic_array_type(AstFile *f, Token token, Ast *elem) { +gb_internal Ast *ast_dynamic_array_type(AstFile *f, Token token, Ast *elem) { Ast *result = alloc_ast_node(f, Ast_DynamicArrayType); result->DynamicArrayType.token = token; result->DynamicArrayType.elem = elem; return result; } -Ast *ast_struct_type(AstFile *f, Token token, Slice fields, isize field_count, +gb_internal Ast *ast_struct_type(AstFile *f, Token token, Slice fields, isize field_count, Ast *polymorphic_params, bool is_packed, bool is_raw_union, Ast *align, Token where_token, Array const &where_clauses) { @@ -1075,7 +1075,7 @@ Ast *ast_struct_type(AstFile *f, Token token, Slice fields, isize field_c } -Ast *ast_union_type(AstFile *f, Token token, Array const &variants, Ast *polymorphic_params, Ast *align, UnionTypeKind kind, +gb_internal Ast *ast_union_type(AstFile *f, Token token, Array const &variants, Ast *polymorphic_params, Ast *align, UnionTypeKind kind, Token where_token, Array const &where_clauses) { Ast *result = alloc_ast_node(f, Ast_UnionType); result->UnionType.token = token; @@ -1089,7 +1089,7 @@ Ast *ast_union_type(AstFile *f, Token token, Array const &variants, Ast * } -Ast *ast_enum_type(AstFile *f, Token token, Ast *base_type, Array const &fields) { +gb_internal Ast *ast_enum_type(AstFile *f, Token token, Ast *base_type, Array const &fields) { Ast *result = alloc_ast_node(f, Ast_EnumType); result->EnumType.token = token; result->EnumType.base_type = base_type; @@ -1097,7 +1097,7 @@ Ast *ast_enum_type(AstFile *f, Token token, Ast *base_type, Array const & return result; } -Ast *ast_bit_set_type(AstFile *f, Token token, Ast *elem, Ast *underlying) { +gb_internal Ast *ast_bit_set_type(AstFile *f, Token token, Ast *elem, Ast *underlying) { Ast *result = alloc_ast_node(f, Ast_BitSetType); result->BitSetType.token = token; result->BitSetType.elem = elem; @@ -1105,7 +1105,7 @@ Ast *ast_bit_set_type(AstFile *f, Token token, Ast *elem, Ast *underlying) { return result; } -Ast *ast_map_type(AstFile *f, Token token, Ast *key, Ast *value) { +gb_internal Ast *ast_map_type(AstFile *f, Token token, Ast *key, Ast *value) { Ast *result = alloc_ast_node(f, Ast_MapType); result->MapType.token = token; result->MapType.key = key; @@ -1113,7 +1113,7 @@ Ast *ast_map_type(AstFile *f, Token token, Ast *key, Ast *value) { return result; } -Ast *ast_matrix_type(AstFile *f, Token token, Ast *row_count, Ast *column_count, Ast *elem) { +gb_internal Ast *ast_matrix_type(AstFile *f, Token token, Ast *row_count, Ast *column_count, Ast *elem) { Ast *result = alloc_ast_node(f, Ast_MatrixType); result->MatrixType.token = token; result->MatrixType.row_count = row_count; @@ -1122,7 +1122,7 @@ Ast *ast_matrix_type(AstFile *f, Token token, Ast *row_count, Ast *column_count, return result; } -Ast *ast_foreign_block_decl(AstFile *f, Token token, Ast *foreign_library, Ast *body, +gb_internal Ast *ast_foreign_block_decl(AstFile *f, Token token, Ast *foreign_library, Ast *body, CommentGroup *docs) { Ast *result = alloc_ast_node(f, Ast_ForeignBlockDecl); result->ForeignBlockDecl.token = token; @@ -1134,14 +1134,14 @@ Ast *ast_foreign_block_decl(AstFile *f, Token token, Ast *foreign_library, Ast * return result; } -Ast *ast_label_decl(AstFile *f, Token token, Ast *name) { +gb_internal Ast *ast_label_decl(AstFile *f, Token token, Ast *name) { Ast *result = alloc_ast_node(f, Ast_Label); result->Label.token = token; result->Label.name = name; return result; } -Ast *ast_value_decl(AstFile *f, Array const &names, Ast *type, Array const &values, bool is_mutable, +gb_internal Ast *ast_value_decl(AstFile *f, Array const &names, Ast *type, Array const &values, bool is_mutable, CommentGroup *docs, CommentGroup *comment) { Ast *result = alloc_ast_node(f, Ast_ValueDecl); result->ValueDecl.names = slice_from_array(names); @@ -1155,7 +1155,7 @@ Ast *ast_value_decl(AstFile *f, Array const &names, Ast *type, ArrayPackageDecl.token = token; result->PackageDecl.name = name; @@ -1164,7 +1164,7 @@ Ast *ast_package_decl(AstFile *f, Token token, Token name, CommentGroup *docs, C return result; } -Ast *ast_import_decl(AstFile *f, Token token, Token relpath, Token import_name, +gb_internal Ast *ast_import_decl(AstFile *f, Token token, Token relpath, Token import_name, CommentGroup *docs, CommentGroup *comment) { Ast *result = alloc_ast_node(f, Ast_ImportDecl); result->ImportDecl.token = token; @@ -1175,7 +1175,7 @@ Ast *ast_import_decl(AstFile *f, Token token, Token relpath, Token import_name, return result; } -Ast *ast_foreign_import_decl(AstFile *f, Token token, Array filepaths, Token library_name, +gb_internal Ast *ast_foreign_import_decl(AstFile *f, Token token, Array filepaths, Token library_name, CommentGroup *docs, CommentGroup *comment) { Ast *result = alloc_ast_node(f, Ast_ForeignImportDecl); result->ForeignImportDecl.token = token; @@ -1189,7 +1189,7 @@ Ast *ast_foreign_import_decl(AstFile *f, Token token, Array filepaths, To } -Ast *ast_attribute(AstFile *f, Token token, Token open, Token close, Array const &elems) { +gb_internal Ast *ast_attribute(AstFile *f, Token token, Token open, Token close, Array const &elems) { Ast *result = alloc_ast_node(f, Ast_Attribute); result->Attribute.token = token; result->Attribute.open = open; @@ -1199,7 +1199,7 @@ Ast *ast_attribute(AstFile *f, Token token, Token open, Token close, Arraycurr_token_index+1 < f->tokens.count) { f->curr_token = f->tokens[++f->curr_token_index]; return true; @@ -1209,7 +1209,7 @@ bool next_token0(AstFile *f) { } -Token consume_comment(AstFile *f, isize *end_line_) { +gb_internal Token consume_comment(AstFile *f, isize *end_line_) { Token tok = f->curr_token; GB_ASSERT(tok.kind == Token_Comment); isize end_line = tok.pos.line; @@ -1231,7 +1231,7 @@ Token consume_comment(AstFile *f, isize *end_line_) { } -CommentGroup *consume_comment_group(AstFile *f, isize n, isize *end_line_) { +gb_internal CommentGroup *consume_comment_group(AstFile *f, isize n, isize *end_line_) { Array list = {}; list.allocator = heap_allocator(); isize end_line = f->curr_token.pos.line; @@ -1257,7 +1257,7 @@ CommentGroup *consume_comment_group(AstFile *f, isize n, isize *end_line_) { return comments; } -void consume_comment_groups(AstFile *f, Token prev) { +gb_internal void consume_comment_groups(AstFile *f, Token prev) { if (f->curr_token.kind == Token_Comment) { CommentGroup *comment = nullptr; isize end_line = 0; @@ -1281,11 +1281,11 @@ void consume_comment_groups(AstFile *f, Token prev) { } } -gb_inline bool ignore_newlines(AstFile *f) { +gb_internal gb_inline bool ignore_newlines(AstFile *f) { return f->expr_level > 0; } -Token advance_token(AstFile *f) { +gb_internal Token advance_token(AstFile *f) { f->lead_comment = nullptr; f->line_comment = nullptr; @@ -1308,7 +1308,7 @@ Token advance_token(AstFile *f) { return prev; } -bool peek_token_kind(AstFile *f, TokenKind kind) { +gb_internal bool peek_token_kind(AstFile *f, TokenKind kind) { for (isize i = f->curr_token_index+1; i < f->tokens.count; i++) { Token tok = f->tokens[i]; if (kind != Token_Comment && tok.kind == Token_Comment) { @@ -1319,7 +1319,7 @@ bool peek_token_kind(AstFile *f, TokenKind kind) { return false; } -Token peek_token(AstFile *f) { +gb_internal Token peek_token(AstFile *f) { for (isize i = f->curr_token_index+1; i < f->tokens.count; i++) { Token tok = f->tokens[i]; if (tok.kind == Token_Comment) { @@ -1330,7 +1330,7 @@ Token peek_token(AstFile *f) { return {}; } -bool skip_possible_newline(AstFile *f) { +gb_internal bool skip_possible_newline(AstFile *f) { if (token_is_newline(f->curr_token)) { advance_token(f); return true; @@ -1338,7 +1338,7 @@ bool skip_possible_newline(AstFile *f) { return false; } -bool skip_possible_newline_for_literal(AstFile *f) { +gb_internal bool skip_possible_newline_for_literal(AstFile *f) { Token curr = f->curr_token; if (token_is_newline(curr)) { Token next = peek_token(f); @@ -1356,7 +1356,7 @@ bool skip_possible_newline_for_literal(AstFile *f) { return false; } -String token_to_string(Token const &tok) { +gb_internal String token_to_string(Token const &tok) { String p = token_strings[tok.kind]; if (token_is_newline(tok)) { p = str_lit("newline"); @@ -1365,7 +1365,7 @@ String token_to_string(Token const &tok) { } -Token expect_token(AstFile *f, TokenKind kind) { +gb_internal Token expect_token(AstFile *f, TokenKind kind) { Token prev = f->curr_token; if (prev.kind != kind) { String c = token_strings[kind]; @@ -1380,7 +1380,7 @@ Token expect_token(AstFile *f, TokenKind kind) { return prev; } -Token expect_token_after(AstFile *f, TokenKind kind, char const *msg) { +gb_internal Token expect_token_after(AstFile *f, TokenKind kind, char const *msg) { Token prev = f->curr_token; if (prev.kind != kind) { String p = token_to_string(prev); @@ -1400,7 +1400,7 @@ Token expect_token_after(AstFile *f, TokenKind kind, char const *msg) { } -bool is_token_range(TokenKind kind) { +gb_internal bool is_token_range(TokenKind kind) { switch (kind) { case Token_Ellipsis: case Token_RangeFull: @@ -1409,12 +1409,12 @@ bool is_token_range(TokenKind kind) { } return false; } -bool is_token_range(Token tok) { +gb_internal bool is_token_range(Token tok) { return is_token_range(tok.kind); } -Token expect_operator(AstFile *f) { +gb_internal Token expect_operator(AstFile *f) { Token prev = f->curr_token; if ((prev.kind == Token_in || prev.kind == Token_not_in) && (f->expr_level >= 0 || f->allow_in_expr)) { // okay @@ -1440,7 +1440,7 @@ Token expect_operator(AstFile *f) { return prev; } -Token expect_keyword(AstFile *f) { +gb_internal Token expect_keyword(AstFile *f) { Token prev = f->curr_token; if (!gb_is_between(prev.kind, Token__KeywordBegin+1, Token__KeywordEnd-1)) { String p = token_to_string(prev); @@ -1451,7 +1451,7 @@ Token expect_keyword(AstFile *f) { return prev; } -bool allow_token(AstFile *f, TokenKind kind) { +gb_internal bool allow_token(AstFile *f, TokenKind kind) { Token prev = f->curr_token; if (prev.kind == kind) { advance_token(f); @@ -1460,7 +1460,7 @@ bool allow_token(AstFile *f, TokenKind kind) { return false; } -Token expect_closing_brace_of_field_list(AstFile *f) { +gb_internal Token expect_closing_brace_of_field_list(AstFile *f) { Token token = f->curr_token; if (allow_token(f, Token_CloseBrace)) { return token; @@ -1476,19 +1476,19 @@ Token expect_closing_brace_of_field_list(AstFile *f) { return expect_token(f, Token_CloseBrace); } -bool is_blank_ident(String str) { +gb_internal bool is_blank_ident(String str) { if (str.len == 1) { return str[0] == '_'; } return false; } -bool is_blank_ident(Token token) { +gb_internal bool is_blank_ident(Token token) { if (token.kind == Token_Ident) { return is_blank_ident(token.string); } return false; } -bool is_blank_ident(Ast *node) { +gb_internal bool is_blank_ident(Ast *node) { if (node->kind == Ast_Ident) { ast_node(i, Ident, node); return is_blank_ident(i->token.string); @@ -1499,7 +1499,7 @@ bool is_blank_ident(Ast *node) { // NOTE(bill): Go to next statement to prevent numerous error messages popping up -void fix_advance_to_next_stmt(AstFile *f) { +gb_internal void fix_advance_to_next_stmt(AstFile *f) { for (;;) { Token t = f->curr_token; switch (t.kind) { @@ -1543,7 +1543,7 @@ void fix_advance_to_next_stmt(AstFile *f) { } } -Token expect_closing(AstFile *f, TokenKind kind, String const &context) { +gb_internal Token expect_closing(AstFile *f, TokenKind kind, String const &context) { if (f->curr_token.kind != kind && f->curr_token.kind == Token_Semicolon && (f->curr_token.string == "\n" || f->curr_token.kind == Token_EOF)) { @@ -1557,7 +1557,7 @@ Token expect_closing(AstFile *f, TokenKind kind, String const &context) { return expect_token(f, kind); } -void assign_removal_flag_to_semicolon(AstFile *f) { +gb_internal void assign_removal_flag_to_semicolon(AstFile *f) { // NOTE(bill): this is used for rewriting files to strip unneeded semicolons Token *prev_token = &f->tokens[f->prev_token_index]; Token *curr_token = &f->tokens[f->curr_token_index]; @@ -1587,7 +1587,7 @@ void assign_removal_flag_to_semicolon(AstFile *f) { } } -void expect_semicolon(AstFile *f) { +gb_internal void expect_semicolon(AstFile *f) { Token prev_token = {}; if (allow_token(f, Token_Semicolon)) { @@ -1626,17 +1626,17 @@ void expect_semicolon(AstFile *f) { } -Ast * parse_expr(AstFile *f, bool lhs); -Ast * parse_proc_type(AstFile *f, Token proc_token); -Array parse_stmt_list(AstFile *f); -Ast * parse_stmt(AstFile *f); -Ast * parse_body(AstFile *f); -Ast * parse_do_body(AstFile *f, Token const &token, char const *msg); -Ast * parse_block_stmt(AstFile *f, b32 is_when); +gb_internal Ast * parse_expr(AstFile *f, bool lhs); +gb_internal Ast * parse_proc_type(AstFile *f, Token proc_token); +gb_internal Array parse_stmt_list(AstFile *f); +gb_internal Ast * parse_stmt(AstFile *f); +gb_internal Ast * parse_body(AstFile *f); +gb_internal Ast * parse_do_body(AstFile *f, Token const &token, char const *msg); +gb_internal Ast * parse_block_stmt(AstFile *f, b32 is_when); -Ast *parse_ident(AstFile *f, bool allow_poly_names=false) { +gb_internal Ast *parse_ident(AstFile *f, bool allow_poly_names=false) { Token token = f->curr_token; if (token.kind == Token_Ident) { advance_token(f); @@ -1654,13 +1654,13 @@ Ast *parse_ident(AstFile *f, bool allow_poly_names=false) { return ast_ident(f, token); } -Ast *parse_tag_expr(AstFile *f, Ast *expression) { +gb_internal Ast *parse_tag_expr(AstFile *f, Ast *expression) { Token token = expect_token(f, Token_Hash); Token name = expect_token(f, Token_Ident); return ast_tag_expr(f, token, name, expression); } -Ast *unparen_expr(Ast *node) { +gb_internal Ast *unparen_expr(Ast *node) { for (;;) { if (node == nullptr) { return nullptr; @@ -1672,7 +1672,7 @@ Ast *unparen_expr(Ast *node) { } } -Ast *unselector_expr(Ast *node) { +gb_internal Ast *unselector_expr(Ast *node) { node = unparen_expr(node); if (node == nullptr) { return nullptr; @@ -1683,7 +1683,7 @@ Ast *unselector_expr(Ast *node) { return node; } -Ast *strip_or_return_expr(Ast *node) { +gb_internal Ast *strip_or_return_expr(Ast *node) { for (;;) { if (node == nullptr) { return node; @@ -1699,9 +1699,9 @@ Ast *strip_or_return_expr(Ast *node) { } -Ast *parse_value(AstFile *f); +gb_internal Ast *parse_value(AstFile *f); -Array parse_element_list(AstFile *f) { +gb_internal Array parse_element_list(AstFile *f) { auto elems = array_make(heap_allocator()); while (f->curr_token.kind != Token_CloseBrace && @@ -1722,7 +1722,7 @@ Array parse_element_list(AstFile *f) { return elems; } -CommentGroup *consume_line_comment(AstFile *f) { +gb_internal CommentGroup *consume_line_comment(AstFile *f) { CommentGroup *comment = f->line_comment; if (f->line_comment == f->lead_comment) { f->lead_comment = nullptr; @@ -1732,7 +1732,7 @@ CommentGroup *consume_line_comment(AstFile *f) { } -Array parse_enum_field_list(AstFile *f) { +gb_internal Array parse_enum_field_list(AstFile *f) { auto elems = array_make(heap_allocator()); while (f->curr_token.kind != Token_CloseBrace && @@ -1763,7 +1763,7 @@ Array parse_enum_field_list(AstFile *f) { return elems; } -Ast *parse_literal_value(AstFile *f, Ast *type) { +gb_internal Ast *parse_literal_value(AstFile *f, Ast *type) { Array elems = {}; Token open = expect_token(f, Token_OpenBrace); isize expr_level = f->expr_level; @@ -1777,7 +1777,7 @@ Ast *parse_literal_value(AstFile *f, Ast *type) { return ast_compound_lit(f, type, elems, open, close); } -Ast *parse_value(AstFile *f) { +gb_internal Ast *parse_value(AstFile *f) { if (f->curr_token.kind == Token_OpenBrace) { return parse_literal_value(f, nullptr); } @@ -1789,17 +1789,17 @@ Ast *parse_value(AstFile *f) { return value; } -Ast *parse_type_or_ident(AstFile *f); +gb_internal Ast *parse_type_or_ident(AstFile *f); -void check_proc_add_tag(AstFile *f, Ast *tag_expr, u64 *tags, ProcTag tag, String const &tag_name) { +gb_internal void check_proc_add_tag(AstFile *f, Ast *tag_expr, u64 *tags, ProcTag tag, String const &tag_name) { if (*tags & tag) { syntax_error(tag_expr, "Procedure tag already used: %.*s", LIT(tag_name)); } *tags |= tag; } -bool is_foreign_name_valid(String const &name) { +gb_internal bool is_foreign_name_valid(String const &name) { if (name.len == 0) { return false; } @@ -1847,7 +1847,7 @@ bool is_foreign_name_valid(String const &name) { return true; } -void parse_proc_tags(AstFile *f, u64 *tags) { +gb_internal void parse_proc_tags(AstFile *f, u64 *tags) { GB_ASSERT(tags != nullptr); while (f->curr_token.kind == Token_Hash) { @@ -1885,17 +1885,17 @@ void parse_proc_tags(AstFile *f, u64 *tags) { } -Array parse_lhs_expr_list (AstFile *f); -Array parse_rhs_expr_list (AstFile *f); -Ast * parse_simple_stmt (AstFile *f, u32 flags); -Ast * parse_type (AstFile *f); -Ast * parse_call_expr (AstFile *f, Ast *operand); -Ast * parse_struct_field_list(AstFile *f, isize *name_count_); -Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_typeid_token); -Ast *parse_unary_expr(AstFile *f, bool lhs); +gb_internal Array parse_lhs_expr_list (AstFile *f); +gb_internal Array parse_rhs_expr_list (AstFile *f); +gb_internal Ast * parse_simple_stmt (AstFile *f, u32 flags); +gb_internal Ast * parse_type (AstFile *f); +gb_internal Ast * parse_call_expr (AstFile *f, Ast *operand); +gb_internal Ast * parse_struct_field_list(AstFile *f, isize *name_count_); +gb_internal Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_typeid_token); +gb_internal Ast *parse_unary_expr(AstFile *f, bool lhs); -Ast *convert_stmt_to_expr(AstFile *f, Ast *statement, String const &kind) { +gb_internal Ast *convert_stmt_to_expr(AstFile *f, Ast *statement, String const &kind) { if (statement == nullptr) { return nullptr; } @@ -1912,7 +1912,7 @@ Ast *convert_stmt_to_expr(AstFile *f, Ast *statement, String const &kind) { return ast_bad_expr(f, f->curr_token, end); } -Ast *convert_stmt_to_body(AstFile *f, Ast *stmt) { +gb_internal Ast *convert_stmt_to_body(AstFile *f, Ast *stmt) { if (stmt->kind == Ast_BlockStmt) { syntax_error(stmt, "Expected a normal statement rather than a block statement"); return stmt; @@ -1929,7 +1929,7 @@ Ast *convert_stmt_to_body(AstFile *f, Ast *stmt) { } -void check_polymorphic_params_for_type(AstFile *f, Ast *polymorphic_params, Token token) { +gb_internal void check_polymorphic_params_for_type(AstFile *f, Ast *polymorphic_params, Token token) { if (polymorphic_params == nullptr) { return; } @@ -1952,16 +1952,16 @@ void check_polymorphic_params_for_type(AstFile *f, Ast *polymorphic_params, Toke } } -bool ast_on_same_line(Token const &x, Ast *yp) { +gb_internal bool ast_on_same_line(Token const &x, Ast *yp) { Token y = ast_token(yp); return x.pos.line == y.pos.line; } -bool ast_on_same_line(Ast *x, Ast *y) { +gb_internal bool ast_on_same_line(Ast *x, Ast *y) { return ast_on_same_line(ast_token(x), y); } -Ast *parse_force_inlining_operand(AstFile *f, Token token) { +gb_internal Ast *parse_force_inlining_operand(AstFile *f, Token token) { Ast *expr = parse_unary_expr(f, false); Ast *e = strip_or_return_expr(expr); if (e->kind != Ast_ProcLit && e->kind != Ast_CallExpr) { @@ -1997,7 +1997,7 @@ Ast *parse_force_inlining_operand(AstFile *f, Token token) { } -Ast *parse_check_directive_for_statement(Ast *s, Token const &tag_token, u16 state_flag) { +gb_internal Ast *parse_check_directive_for_statement(Ast *s, Token const &tag_token, u16 state_flag) { String name = tag_token.string; if (s == nullptr) { @@ -2076,7 +2076,7 @@ Ast *parse_check_directive_for_statement(Ast *s, Token const &tag_token, u16 sta return s; } -Array parse_union_variant_list(AstFile *f) { +gb_internal Array parse_union_variant_list(AstFile *f) { auto variants = array_make(heap_allocator()); while (f->curr_token.kind != Token_CloseBrace && f->curr_token.kind != Token_EOF) { @@ -2091,7 +2091,7 @@ Array parse_union_variant_list(AstFile *f) { return variants; } -Ast *parse_operand(AstFile *f, bool lhs) { +gb_internal Ast *parse_operand(AstFile *f, bool lhs) { Ast *operand = nullptr; // Operand switch (f->curr_token.kind) { case Token_Ident: @@ -2712,7 +2712,7 @@ Ast *parse_operand(AstFile *f, bool lhs) { return nullptr; } -bool is_literal_type(Ast *node) { +gb_internal bool is_literal_type(Ast *node) { node = unparen_expr(node); switch (node->kind) { case Ast_BadExpr: @@ -2735,7 +2735,7 @@ bool is_literal_type(Ast *node) { return false; } -Ast *parse_call_expr(AstFile *f, Ast *operand) { +gb_internal Ast *parse_call_expr(AstFile *f, Ast *operand) { auto args = array_make(heap_allocator()); Token open_paren, close_paren; Token ellipsis = {}; @@ -2796,7 +2796,7 @@ Ast *parse_call_expr(AstFile *f, Ast *operand) { return call; } -Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { +gb_internal Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { if (operand == nullptr) { if (f->allow_type) return nullptr; Token begin = f->curr_token; @@ -2950,7 +2950,7 @@ Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { } -Ast *parse_unary_expr(AstFile *f, bool lhs) { +gb_internal Ast *parse_unary_expr(AstFile *f, bool lhs) { switch (f->curr_token.kind) { case Token_transmute: case Token_cast: { @@ -2997,7 +2997,7 @@ Ast *parse_unary_expr(AstFile *f, bool lhs) { return parse_atom_expr(f, parse_operand(f, lhs), lhs); } -bool is_ast_range(Ast *expr) { +gb_internal bool is_ast_range(Ast *expr) { if (expr == nullptr) { return false; } @@ -3008,7 +3008,7 @@ bool is_ast_range(Ast *expr) { } // NOTE(bill): result == priority -i32 token_precedence(AstFile *f, TokenKind t) { +gb_internal i32 token_precedence(AstFile *f, TokenKind t) { switch (t) { case Token_Question: case Token_if: @@ -3058,7 +3058,7 @@ i32 token_precedence(AstFile *f, TokenKind t) { return 0; } -Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { +gb_internal Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { Ast *expr = parse_unary_expr(f, lhs); for (;;) { Token op = f->curr_token; @@ -3119,12 +3119,12 @@ Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { return expr; } -Ast *parse_expr(AstFile *f, bool lhs) { +gb_internal Ast *parse_expr(AstFile *f, bool lhs) { return parse_binary_expr(f, lhs, 0+1); } -Array parse_expr_list(AstFile *f, bool lhs) { +gb_internal Array parse_expr_list(AstFile *f, bool lhs) { bool allow_newline = f->allow_newline; f->allow_newline = ALLOW_NEWLINE; @@ -3144,15 +3144,15 @@ Array parse_expr_list(AstFile *f, bool lhs) { return list; } -Array parse_lhs_expr_list(AstFile *f) { +gb_internal Array parse_lhs_expr_list(AstFile *f) { return parse_expr_list(f, true); } -Array parse_rhs_expr_list(AstFile *f) { +gb_internal Array parse_rhs_expr_list(AstFile *f) { return parse_expr_list(f, false); } -Array parse_ident_list(AstFile *f, bool allow_poly_names) { +gb_internal Array parse_ident_list(AstFile *f, bool allow_poly_names) { auto list = array_make(heap_allocator()); for (;;) { @@ -3167,7 +3167,7 @@ Array parse_ident_list(AstFile *f, bool allow_poly_names) { return list; } -Ast *parse_type(AstFile *f) { +gb_internal Ast *parse_type(AstFile *f) { Ast *type = parse_type_or_ident(f); if (type == nullptr) { Token token = advance_token(f); @@ -3177,7 +3177,7 @@ Ast *parse_type(AstFile *f) { return type; } -void parse_foreign_block_decl(AstFile *f, Array *decls) { +gb_internal void parse_foreign_block_decl(AstFile *f, Array *decls) { Ast *decl = parse_stmt(f); switch (decl->kind) { case Ast_EmptyStmt: @@ -3196,7 +3196,7 @@ void parse_foreign_block_decl(AstFile *f, Array *decls) { } } -Ast *parse_foreign_block(AstFile *f, Token token) { +gb_internal Ast *parse_foreign_block(AstFile *f, Token token) { CommentGroup *docs = f->lead_comment; Ast *foreign_library = nullptr; if (f->curr_token.kind == Token_OpenBrace) { @@ -3229,7 +3229,7 @@ Ast *parse_foreign_block(AstFile *f, Token token) { return decl; } -Ast *parse_value_decl(AstFile *f, Array names, CommentGroup *docs) { +gb_internal Ast *parse_value_decl(AstFile *f, Array names, CommentGroup *docs) { bool is_mutable = true; Array values = {}; @@ -3293,7 +3293,7 @@ Ast *parse_value_decl(AstFile *f, Array names, CommentGroup *docs) { return ast_value_decl(f, names, type, values, is_mutable, docs, f->line_comment); } -Ast *parse_simple_stmt(AstFile *f, u32 flags) { +gb_internal Ast *parse_simple_stmt(AstFile *f, u32 flags) { Token token = f->curr_token; CommentGroup *docs = f->lead_comment; @@ -3403,7 +3403,7 @@ Ast *parse_simple_stmt(AstFile *f, u32 flags) { -Ast *parse_block_stmt(AstFile *f, b32 is_when) { +gb_internal Ast *parse_block_stmt(AstFile *f, b32 is_when) { skip_possible_newline_for_literal(f); if (!is_when && f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a block statement in the file scope"); @@ -3414,7 +3414,7 @@ Ast *parse_block_stmt(AstFile *f, b32 is_when) { -Ast *parse_results(AstFile *f, bool *diverging) { +gb_internal Ast *parse_results(AstFile *f, bool *diverging) { if (!allow_token(f, Token_ArrowRight)) { return nullptr; } @@ -3448,7 +3448,7 @@ Ast *parse_results(AstFile *f, bool *diverging) { } -ProcCallingConvention string_to_calling_convention(String const &s) { +gb_internal ProcCallingConvention string_to_calling_convention(String const &s) { if (s == "odin") return ProcCC_Odin; if (s == "contextless") return ProcCC_Contextless; if (s == "cdecl") return ProcCC_CDecl; @@ -3474,7 +3474,7 @@ ProcCallingConvention string_to_calling_convention(String const &s) { return ProcCC_Invalid; } -Ast *parse_proc_type(AstFile *f, Token proc_token) { +gb_internal Ast *parse_proc_type(AstFile *f, Token proc_token) { Ast *params = nullptr; Ast *results = nullptr; bool diverging = false; @@ -3530,7 +3530,7 @@ end: return ast_proc_type(f, proc_token, params, results, tags, cc, is_generic, diverging); } -Ast *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_typeid_token) { +gb_internal Ast *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_typeid_token) { if (allow_ellipsis && f->curr_token.kind == Token_Ellipsis) { Token tok = advance_token(f); Ast *type = parse_type_or_ident(f); @@ -3574,7 +3574,7 @@ gb_global ParseFieldPrefixMapping parse_field_prefix_mappings[] = { }; -FieldFlag is_token_field_prefix(AstFile *f) { +gb_internal FieldFlag is_token_field_prefix(AstFile *f) { switch (f->curr_token.kind) { case Token_EOF: return FieldFlag_Invalid; @@ -3604,7 +3604,7 @@ FieldFlag is_token_field_prefix(AstFile *f) { return FieldFlag_Invalid; } -u32 parse_field_prefixes(AstFile *f) { +gb_internal u32 parse_field_prefixes(AstFile *f) { i32 counts[gb_count_of(parse_field_prefix_mappings)] = {}; for (;;) { @@ -3646,7 +3646,7 @@ u32 parse_field_prefixes(AstFile *f) { return field_flags; } -u32 check_field_prefixes(AstFile *f, isize name_count, u32 allowed_flags, u32 set_flags) { +gb_internal u32 check_field_prefixes(AstFile *f, isize name_count, u32 allowed_flags, u32 set_flags) { for (i32 i = 0; i < gb_count_of(parse_field_prefix_mappings); i++) { bool err = false; auto const &m = parse_field_prefix_mappings[i]; @@ -3679,7 +3679,7 @@ struct AstAndFlags { u32 flags; }; -Array convert_to_ident_list(AstFile *f, Array list, bool ignore_flags, bool allow_poly_names) { +gb_internal Array convert_to_ident_list(AstFile *f, Array list, bool ignore_flags, bool allow_poly_names) { auto idents = array_make(heap_allocator(), 0, list.count); // Convert to ident list for_array(i, list) { @@ -3719,7 +3719,7 @@ Array convert_to_ident_list(AstFile *f, Array list, bool ign } -bool allow_field_separator(AstFile *f) { +gb_internal bool allow_field_separator(AstFile *f) { Token token = f->curr_token; if (allow_token(f, Token_Comma)) { return true; @@ -3733,7 +3733,7 @@ bool allow_field_separator(AstFile *f) { return false; } -Ast *parse_struct_field_list(AstFile *f, isize *name_count_) { +gb_internal Ast *parse_struct_field_list(AstFile *f, isize *name_count_) { Token start_token = f->curr_token; auto decls = array_make(heap_allocator()); @@ -3747,7 +3747,7 @@ Ast *parse_struct_field_list(AstFile *f, isize *name_count_) { // Returns true if any are polymorphic names -bool check_procedure_name_list(Array const &names) { +gb_internal bool check_procedure_name_list(Array const &names) { if (names.count == 0) { return false; } @@ -3775,7 +3775,7 @@ bool check_procedure_name_list(Array const &names) { return any_polymorphic_names; } -Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_typeid_token) { +gb_internal Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_typeid_token) { bool prev_allow_newline = f->allow_newline; defer (f->allow_newline = prev_allow_newline); f->allow_newline = ALLOW_NEWLINE; @@ -3976,7 +3976,7 @@ Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKi return ast_field_list(f, start_token, params); } -Ast *parse_type_or_ident(AstFile *f) { +gb_internal Ast *parse_type_or_ident(AstFile *f) { bool prev_allow_type = f->allow_type; isize prev_expr_level = f->expr_level; defer ({ @@ -3995,7 +3995,7 @@ Ast *parse_type_or_ident(AstFile *f) { -Ast *parse_body(AstFile *f) { +gb_internal Ast *parse_body(AstFile *f) { Array stmts = {}; Token open, close; isize prev_expr_level = f->expr_level; @@ -4013,7 +4013,7 @@ Ast *parse_body(AstFile *f) { return ast_block_stmt(f, stmts, open, close); } -Ast *parse_do_body(AstFile *f, Token const &token, char const *msg) { +gb_internal Ast *parse_do_body(AstFile *f, Token const &token, char const *msg) { Token open, close; isize prev_expr_level = f->expr_level; bool prev_allow_newline = f->allow_newline; @@ -4034,7 +4034,7 @@ Ast *parse_do_body(AstFile *f, Token const &token, char const *msg) { return body; } -bool parse_control_statement_semicolon_separator(AstFile *f) { +gb_internal bool parse_control_statement_semicolon_separator(AstFile *f) { Token tok = peek_token(f); if (tok.kind != Token_OpenBrace) { return allow_token(f, Token_Semicolon); @@ -4046,7 +4046,7 @@ bool parse_control_statement_semicolon_separator(AstFile *f) { } -Ast *parse_if_stmt(AstFile *f) { +gb_internal Ast *parse_if_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use an if statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -4112,7 +4112,7 @@ Ast *parse_if_stmt(AstFile *f) { return ast_if_stmt(f, token, init, cond, body, else_stmt); } -Ast *parse_when_stmt(AstFile *f) { +gb_internal Ast *parse_when_stmt(AstFile *f) { Token token = expect_token(f, Token_when); Ast *cond = nullptr; Ast *body = nullptr; @@ -4160,7 +4160,7 @@ Ast *parse_when_stmt(AstFile *f) { } -Ast *parse_return_stmt(AstFile *f) { +gb_internal Ast *parse_return_stmt(AstFile *f) { Token token = expect_token(f, Token_return); if (f->curr_proc == nullptr) { @@ -4188,7 +4188,7 @@ Ast *parse_return_stmt(AstFile *f) { return ast_return_stmt(f, token, results); } -Ast *parse_for_stmt(AstFile *f) { +gb_internal Ast *parse_for_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a for statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -4279,7 +4279,7 @@ Ast *parse_for_stmt(AstFile *f) { } -Ast *parse_case_clause(AstFile *f, bool is_type) { +gb_internal Ast *parse_case_clause(AstFile *f, bool is_type) { Token token = f->curr_token; Array list = {}; expect_token(f, Token_case); @@ -4299,7 +4299,7 @@ Ast *parse_case_clause(AstFile *f, bool is_type) { } -Ast *parse_switch_stmt(AstFile *f) { +gb_internal Ast *parse_switch_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a switch statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -4361,7 +4361,7 @@ Ast *parse_switch_stmt(AstFile *f) { return ast_switch_stmt(f, token, init, tag, body); } -Ast *parse_defer_stmt(AstFile *f) { +gb_internal Ast *parse_defer_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a defer statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -4391,7 +4391,7 @@ enum ImportDeclKind { ImportDecl_Using, }; -Ast *parse_import_decl(AstFile *f, ImportDeclKind kind) { +gb_internal Ast *parse_import_decl(AstFile *f, ImportDeclKind kind) { CommentGroup *docs = f->lead_comment; Token token = expect_token(f, Token_import); Token import_name = {}; @@ -4424,7 +4424,7 @@ Ast *parse_import_decl(AstFile *f, ImportDeclKind kind) { return s; } -Ast *parse_foreign_decl(AstFile *f) { +gb_internal Ast *parse_foreign_decl(AstFile *f) { CommentGroup *docs = f->lead_comment; Token token = expect_token(f, Token_foreign); @@ -4487,7 +4487,7 @@ Ast *parse_foreign_decl(AstFile *f) { return ast_bad_decl(f, token, f->curr_token); } -Ast *parse_attribute(AstFile *f, Token token, TokenKind open_kind, TokenKind close_kind) { +gb_internal Ast *parse_attribute(AstFile *f, Token token, TokenKind open_kind, TokenKind close_kind) { Array elems = {}; Token open = {}; Token close = {}; @@ -4542,7 +4542,7 @@ Ast *parse_attribute(AstFile *f, Token token, TokenKind open_kind, TokenKind clo } -Ast *parse_unrolled_for_loop(AstFile *f, Token unroll_token) { +gb_internal Ast *parse_unrolled_for_loop(AstFile *f, Token unroll_token) { Token for_token = expect_token(f, Token_for); Ast *val0 = nullptr; Ast *val1 = nullptr; @@ -4589,7 +4589,7 @@ Ast *parse_unrolled_for_loop(AstFile *f, Token unroll_token) { return ast_unroll_range_stmt(f, unroll_token, for_token, val0, val1, in_token, expr, body); } -Ast *parse_stmt(AstFile *f) { +gb_internal Ast *parse_stmt(AstFile *f) { Ast *s = nullptr; Token token = f->curr_token; switch (token.kind) { @@ -4781,7 +4781,7 @@ Ast *parse_stmt(AstFile *f) { return ast_bad_stmt(f, token, f->curr_token); } -Array parse_stmt_list(AstFile *f) { +gb_internal Array parse_stmt_list(AstFile *f) { auto list = array_make(heap_allocator()); while (f->curr_token.kind != Token_case && @@ -4802,7 +4802,7 @@ Array parse_stmt_list(AstFile *f) { } -ParseFileError init_ast_file(AstFile *f, String const &fullpath, TokenPos *err_pos) { +gb_internal ParseFileError init_ast_file(AstFile *f, String const &fullpath, TokenPos *err_pos) { GB_ASSERT(f != nullptr); f->fullpath = string_trim_whitespace(fullpath); // Just in case set_file_path_string(f->id, fullpath); @@ -4881,14 +4881,14 @@ ParseFileError init_ast_file(AstFile *f, String const &fullpath, TokenPos *err_p return ParseFile_None; } -void destroy_ast_file(AstFile *f) { +gb_internal void destroy_ast_file(AstFile *f) { GB_ASSERT(f != nullptr); array_free(&f->tokens); array_free(&f->comments); array_free(&f->imports); } -bool init_parser(Parser *p) { +gb_internal bool init_parser(Parser *p) { GB_ASSERT(p != nullptr); string_set_init(&p->imported_files, heap_allocator()); array_init(&p->packages, heap_allocator()); @@ -4902,7 +4902,7 @@ bool init_parser(Parser *p) { return true; } -void destroy_parser(Parser *p) { +gb_internal void destroy_parser(Parser *p) { GB_ASSERT(p != nullptr); // TODO(bill): Fix memory leak for_array(i, p->packages) { @@ -4930,16 +4930,16 @@ void destroy_parser(Parser *p) { } -void parser_add_package(Parser *p, AstPackage *pkg) { +gb_internal void parser_add_package(Parser *p, AstPackage *pkg) { mutex_lock(&p->packages_mutex); pkg->id = p->packages.count+1; array_add(&p->packages, pkg); mutex_unlock(&p->packages_mutex); } -ParseFileError process_imported_file(Parser *p, ImportedFile imported_file); +gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile imported_file); -WORKER_TASK_PROC(parser_worker_proc) { +gb_internal WORKER_TASK_PROC(parser_worker_proc) { ParserWorkerData *wd = cast(ParserWorkerData *)data; ParseFileError err = process_imported_file(wd->parser, wd->imported_file); if (err != ParseFile_None) { @@ -4949,7 +4949,7 @@ WORKER_TASK_PROC(parser_worker_proc) { } -void parser_add_file_to_process(Parser *p, AstPackage *pkg, FileInfo fi, TokenPos pos) { +gb_internal void parser_add_file_to_process(Parser *p, AstPackage *pkg, FileInfo fi, TokenPos pos) { // TODO(bill): Use a better allocator ImportedFile f = {pkg, fi, pos, p->file_to_process_count++}; auto wd = gb_alloc_item(permanent_allocator(), ParserWorkerData); @@ -4958,7 +4958,7 @@ void parser_add_file_to_process(Parser *p, AstPackage *pkg, FileInfo fi, TokenPo global_thread_pool_add_task(parser_worker_proc, wd); } -WORKER_TASK_PROC(foreign_file_worker_proc) { +gb_internal WORKER_TASK_PROC(foreign_file_worker_proc) { ForeignFileWorkerData *wd = cast(ForeignFileWorkerData *)data; Parser *p = wd->parser; ImportedFile *imp = &wd->imported_file; @@ -4987,7 +4987,7 @@ WORKER_TASK_PROC(foreign_file_worker_proc) { } -void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, AstForeignFileKind kind, FileInfo fi, TokenPos pos) { +gb_internal void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, AstForeignFileKind kind, FileInfo fi, TokenPos pos) { // TODO(bill): Use a better allocator ImportedFile f = {pkg, fi, pos, p->file_to_process_count++}; auto wd = gb_alloc_item(permanent_allocator(), ForeignFileWorkerData); @@ -4999,7 +4999,7 @@ void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, AstForeignFi // NOTE(bill): Returns true if it's added -AstPackage *try_add_import_path(Parser *p, String const &path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) { +gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) { String const FILE_EXT = str_lit(".odin"); mutex_lock(&p->import_mutex); @@ -5097,7 +5097,7 @@ gb_global Rune illegal_import_runes[] = { '|', ',', '<', '>', '?', }; -bool is_import_path_valid(String const &path) { +gb_internal bool is_import_path_valid(String const &path) { if (path.len > 0) { u8 *start = path.text; u8 *end = path.text + path.len; @@ -5129,7 +5129,7 @@ bool is_import_path_valid(String const &path) { return false; } -bool is_build_flag_path_valid(String const &path) { +gb_internal bool is_build_flag_path_valid(String const &path) { if (path.len > 0) { u8 *start = path.text; u8 *end = path.text + path.len; @@ -5171,7 +5171,7 @@ bool is_build_flag_path_valid(String const &path) { } -bool is_package_name_reserved(String const &name) { +gb_internal bool is_package_name_reserved(String const &name) { if (name == "builtin") { return true; } else if (name == "intrinsics") { @@ -5181,7 +5181,7 @@ bool is_package_name_reserved(String const &name) { } -bool determine_path_from_string(BlockingMutex *file_mutex, Ast *node, String base_dir, String const &original_string, String *path) { +gb_internal bool determine_path_from_string(BlockingMutex *file_mutex, Ast *node, String base_dir, String const &original_string, String *path) { GB_ASSERT(path != nullptr); // NOTE(bill): if file_mutex == nullptr, this means that the code is used within the semantics stage @@ -5295,9 +5295,9 @@ bool determine_path_from_string(BlockingMutex *file_mutex, Ast *node, String bas -void parse_setup_file_decls(Parser *p, AstFile *f, String const &base_dir, Slice &decls); +gb_internal void parse_setup_file_decls(Parser *p, AstFile *f, String const &base_dir, Slice &decls); -void parse_setup_file_when_stmt(Parser *p, AstFile *f, String const &base_dir, AstWhenStmt *ws) { +gb_internal void parse_setup_file_when_stmt(Parser *p, AstFile *f, String const &base_dir, AstWhenStmt *ws) { if (ws->body != nullptr) { auto stmts = ws->body->BlockStmt.stmts; parse_setup_file_decls(p, f, base_dir, stmts); @@ -5316,7 +5316,7 @@ void parse_setup_file_when_stmt(Parser *p, AstFile *f, String const &base_dir, A } } -void parse_setup_file_decls(Parser *p, AstFile *f, String const &base_dir, Slice &decls) { +gb_internal void parse_setup_file_decls(Parser *p, AstFile *f, String const &base_dir, Slice &decls) { for_array(i, decls) { Ast *node = decls[i]; if (!is_ast_decl(node) && @@ -5389,7 +5389,7 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String const &base_dir, Slice } } -String build_tag_get_token(String s, String *out) { +gb_internal String build_tag_get_token(String s, String *out) { s = string_trim_whitespace(s); isize n = 0; while (n < s.len) { @@ -5408,7 +5408,7 @@ String build_tag_get_token(String s, String *out) { return s; } -bool parse_build_tag(Token token_for_pos, String s) { +gb_internal bool parse_build_tag(Token token_for_pos, String s) { String const prefix = str_lit("+build"); GB_ASSERT(string_starts_with(s, prefix)); s = string_trim_whitespace(substring(s, prefix.len, s.len)); @@ -5473,7 +5473,7 @@ bool parse_build_tag(Token token_for_pos, String s) { return any_correct; } -String dir_from_path(String path) { +gb_internal String dir_from_path(String path) { String base_dir = path; for (isize i = path.len-1; i >= 0; i--) { if (base_dir[i] == '\\' || @@ -5485,7 +5485,7 @@ String dir_from_path(String path) { return base_dir; } -isize calc_decl_count(Ast *decl) { +gb_internal isize calc_decl_count(Ast *decl) { isize count = 0; switch (decl->kind) { case Ast_BlockStmt: @@ -5516,7 +5516,7 @@ isize calc_decl_count(Ast *decl) { return count; } -bool parse_build_project_directory_tag(Token token_for_pos, String s) { +gb_internal bool parse_build_project_directory_tag(Token token_for_pos, String s) { String const prefix = str_lit("+build-project-name"); GB_ASSERT(string_starts_with(s, prefix)); s = string_trim_whitespace(substring(s, prefix.len, s.len)); @@ -5561,7 +5561,7 @@ bool parse_build_project_directory_tag(Token token_for_pos, String s) { return any_correct; } -bool parse_file(Parser *p, AstFile *f) { +gb_internal bool parse_file(Parser *p, AstFile *f) { if (f->tokens.count == 0) { return true; } @@ -5694,7 +5694,7 @@ bool parse_file(Parser *p, AstFile *f) { } -ParseFileError process_imported_file(Parser *p, ImportedFile imported_file) { +gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile imported_file) { AstPackage *pkg = imported_file.pkg; FileInfo fi = imported_file.fi; TokenPos pos = imported_file.pos; @@ -5778,7 +5778,7 @@ ParseFileError process_imported_file(Parser *p, ImportedFile imported_file) { } -ParseFileError parse_packages(Parser *p, String init_filename) { +gb_internal ParseFileError parse_packages(Parser *p, String init_filename) { GB_ASSERT(init_filename.text[init_filename.len] == 0); String init_fullpath = path_to_full_path(heap_allocator(), init_filename); diff --git a/src/parser.hpp b/src/parser.hpp index e384f1e7e..a2d2c038e 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -258,7 +258,7 @@ enum ProcCallingConvention : i32 { ProcCC_ForeignBlockDefault = -1, }; -char const *proc_calling_convention_strings[ProcCC_MAX] = { +gb_global char const *proc_calling_convention_strings[ProcCC_MAX] = { "", "odin", "contextless", @@ -272,7 +272,7 @@ char const *proc_calling_convention_strings[ProcCC_MAX] = { "sysv", }; -ProcCallingConvention default_calling_convention(void) { +gb_internal ProcCallingConvention default_calling_convention(void) { return ProcCC_Odin; } @@ -332,7 +332,7 @@ enum InlineAsmDialectKind : u8 { InlineAsmDialect_COUNT, }; -char const *inline_asm_dialect_strings[InlineAsmDialect_COUNT] = { +gb_global char const *inline_asm_dialect_strings[InlineAsmDialect_COUNT] = { "", "att", "intel", @@ -729,7 +729,7 @@ enum AstKind : u16 { Ast_COUNT, }; -String const ast_strings[] = { +gb_global String const ast_strings[] = { {cast(u8 *)"invalid node", gb_size_of("invalid node")}, #define AST_KIND(_kind_name_, name, ...) {cast(u8 *)name, gb_size_of(name)-1}, AST_KINDS @@ -742,7 +742,7 @@ String const ast_strings[] = { #undef AST_KIND -isize const ast_variant_sizes[] = { +gb_global isize const ast_variant_sizes[] = { 0, #define AST_KIND(_kind_name_, name, ...) gb_size_of(GB_JOIN2(Ast, _kind_name_)), AST_KINDS @@ -793,33 +793,33 @@ struct Ast { #endif -gb_inline bool is_ast_expr(Ast *node) { +gb_internal gb_inline bool is_ast_expr(Ast *node) { return gb_is_between(node->kind, Ast__ExprBegin+1, Ast__ExprEnd-1); } -gb_inline bool is_ast_stmt(Ast *node) { +gb_internal gb_inline bool is_ast_stmt(Ast *node) { return gb_is_between(node->kind, Ast__StmtBegin+1, Ast__StmtEnd-1); } -gb_inline bool is_ast_complex_stmt(Ast *node) { +gb_internal gb_inline bool is_ast_complex_stmt(Ast *node) { return gb_is_between(node->kind, Ast__ComplexStmtBegin+1, Ast__ComplexStmtEnd-1); } -gb_inline bool is_ast_decl(Ast *node) { +gb_internal gb_inline bool is_ast_decl(Ast *node) { return gb_is_between(node->kind, Ast__DeclBegin+1, Ast__DeclEnd-1); } -gb_inline bool is_ast_type(Ast *node) { +gb_internal gb_inline bool is_ast_type(Ast *node) { return gb_is_between(node->kind, Ast__TypeBegin+1, Ast__TypeEnd-1); } -gb_inline bool is_ast_when_stmt(Ast *node) { +gb_internal gb_inline bool is_ast_when_stmt(Ast *node) { return node->kind == Ast_WhenStmt; } gb_global gb_thread_local Arena global_thread_local_ast_arena = {}; -gbAllocator ast_allocator(AstFile *f) { +gb_internal gbAllocator ast_allocator(AstFile *f) { Arena *arena = &global_thread_local_ast_arena; return arena_allocator(arena); } -Ast *alloc_ast_node(AstFile *f, AstKind kind); +gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind); -gbString expr_to_string(Ast *expression); -bool allow_field_separator(AstFile *f); \ No newline at end of file +gb_internal gbString expr_to_string(Ast *expression); +gb_internal bool allow_field_separator(AstFile *f); \ No newline at end of file diff --git a/src/parser_pos.cpp b/src/parser_pos.cpp index 54c3ec1f1..19a525e2e 100644 --- a/src/parser_pos.cpp +++ b/src/parser_pos.cpp @@ -1,4 +1,4 @@ -Token ast_token(Ast *node) { +gb_internal Token ast_token(Ast *node) { switch (node->kind) { case Ast_Ident: return node->Ident.token; case Ast_Implicit: return node->Implicit; @@ -360,6 +360,6 @@ Token ast_end_token(Ast *node) { return empty_token; } -TokenPos ast_end_pos(Ast *node) { +gb_internal TokenPos ast_end_pos(Ast *node) { return token_pos_end(ast_end_token(node)); } diff --git a/src/priority_queue.cpp b/src/priority_queue.cpp index aee2061b5..c0f1ddff0 100644 --- a/src/priority_queue.cpp +++ b/src/priority_queue.cpp @@ -7,7 +7,7 @@ struct PriorityQueue { }; template -bool priority_queue_shift_down(PriorityQueue *pq, isize i0, isize n) { +gb_internal bool priority_queue_shift_down(PriorityQueue *pq, isize i0, isize n) { // O(n log n) isize i = i0; isize j, j1, j2; @@ -29,7 +29,7 @@ bool priority_queue_shift_down(PriorityQueue *pq, isize i0, isize n) { } template -void priority_queue_shift_up(PriorityQueue *pq, isize j) { +gb_internal void priority_queue_shift_up(PriorityQueue *pq, isize j) { while (0 <= j && j < pq->queue.count) { isize i = (j-1)/2; if (i == j || pq->cmp(&pq->queue[0], j, i) >= 0) { @@ -43,20 +43,20 @@ void priority_queue_shift_up(PriorityQueue *pq, isize j) { // NOTE(bill): When an element at index `i0` has changed its value, this will fix the // the heap ordering. This using a basic "heapsort" with shift up and a shift down parts. template -void priority_queue_fix(PriorityQueue *pq, isize i) { +gb_internal void priority_queue_fix(PriorityQueue *pq, isize i) { if (!priority_queue_shift_down(pq, i, pq->queue.count)) { priority_queue_shift_up(pq, i); } } template -void priority_queue_push(PriorityQueue *pq, T const &value) { +gb_internal void priority_queue_push(PriorityQueue *pq, T const &value) { array_add(&pq->queue, value); priority_queue_shift_up(pq, pq->queue.count-1); } template -T priority_queue_pop(PriorityQueue *pq) { +gb_internal T priority_queue_pop(PriorityQueue *pq) { GB_ASSERT(pq->queue.count > 0); isize n = pq->queue.count - 1; @@ -67,7 +67,7 @@ T priority_queue_pop(PriorityQueue *pq) { template -T priority_queue_remove(PriorityQueue *pq, isize i) { +gb_internal T priority_queue_remove(PriorityQueue *pq, isize i) { GB_ASSERT(0 <= i && i < pq->queue.count); isize n = pq->queue.count - 1; if (n != i) { @@ -80,7 +80,7 @@ T priority_queue_remove(PriorityQueue *pq, isize i) { template -PriorityQueue priority_queue_create(Array queue, +gb_internal PriorityQueue priority_queue_create(Array queue, int (* cmp) (T *q, isize i, isize j), void (* swap)(T *q, isize i, isize j)) { PriorityQueue pq = {}; diff --git a/src/ptr_map.cpp b/src/ptr_map.cpp index ed4b20bf8..434680e91 100644 --- a/src/ptr_map.cpp +++ b/src/ptr_map.cpp @@ -26,7 +26,7 @@ struct PtrMap { }; -u32 ptr_map_hash_key(uintptr key) { +gb_internal gb_inline u32 ptr_map_hash_key(uintptr key) { #if defined(GB_ARCH_64_BIT) key = (~key) + (key << 21); key = key ^ (key >> 24); @@ -41,35 +41,35 @@ u32 ptr_map_hash_key(uintptr key) { return (word >> 22u) ^ word; #endif } -u32 ptr_map_hash_key(void const *key) { +gb_internal gb_inline u32 ptr_map_hash_key(void const *key) { return ptr_map_hash_key((uintptr)key); } -template void map_init (PtrMap *h, gbAllocator a, isize capacity = 16); -template void map_destroy (PtrMap *h); -template V * map_get (PtrMap *h, K key); -template void map_set (PtrMap *h, K key, V const &value); -template void map_remove (PtrMap *h, K key); -template void map_clear (PtrMap *h); -template void map_grow (PtrMap *h); -template void map_rehash (PtrMap *h, isize new_count); -template void map_reserve (PtrMap *h, isize cap); +template gb_internal void map_init (PtrMap *h, gbAllocator a, isize capacity = 16); +template gb_internal void map_destroy (PtrMap *h); +template gb_internal V * map_get (PtrMap *h, K key); +template gb_internal void map_set (PtrMap *h, K key, V const &value); +template gb_internal void map_remove (PtrMap *h, K key); +template gb_internal void map_clear (PtrMap *h); +template gb_internal void map_grow (PtrMap *h); +template gb_internal void map_rehash (PtrMap *h, isize new_count); +template gb_internal void map_reserve (PtrMap *h, isize cap); #if PTR_MAP_ENABLE_MULTI_MAP // Mutlivalued map procedure -template PtrMapEntry * multi_map_find_first(PtrMap *h, K key); -template PtrMapEntry * multi_map_find_next (PtrMap *h, PtrMapEntry *e); - -template isize multi_map_count (PtrMap *h, K key); -template void multi_map_get_all (PtrMap *h, K key, V *items); -template void multi_map_insert (PtrMap *h, K key, V const &value); -template void multi_map_remove (PtrMap *h, K key, PtrMapEntry *e); -template void multi_map_remove_all(PtrMap *h, K key); +template gb_internal PtrMapEntry * multi_map_find_first(PtrMap *h, K key); +template gb_internal PtrMapEntry * multi_map_find_next (PtrMap *h, PtrMapEntry *e); + +template gb_internal isize multi_map_count (PtrMap *h, K key); +template gb_internal void multi_map_get_all (PtrMap *h, K key, V *items); +template gb_internal void multi_map_insert (PtrMap *h, K key, V const &value); +template gb_internal void multi_map_remove (PtrMap *h, K key, PtrMapEntry *e); +template gb_internal void multi_map_remove_all(PtrMap *h, K key); #endif template -gb_inline void map_init(PtrMap *h, gbAllocator a, isize capacity) { +gb_internal gb_inline void map_init(PtrMap *h, gbAllocator a, isize capacity) { capacity = next_pow2_isize(capacity); slice_init(&h->hashes, a, capacity); array_init(&h->entries, a, 0, capacity); @@ -79,7 +79,7 @@ gb_inline void map_init(PtrMap *h, gbAllocator a, isize capacity) { } template -gb_inline void map_destroy(PtrMap *h) { +gb_internal gb_inline void map_destroy(PtrMap *h) { slice_free(&h->hashes, h->entries.allocator); array_free(&h->entries); } @@ -137,13 +137,13 @@ gb_internal b32 map__full(PtrMap *h) { } template -gb_inline void map_grow(PtrMap *h) { +gb_internal gb_inline void map_grow(PtrMap *h) { isize new_count = gb_max(h->hashes.count<<1, 16); map_rehash(h, new_count); } template -void map_reset_entries(PtrMap *h) { +gb_internal void map_reset_entries(PtrMap *h) { for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; } @@ -161,7 +161,7 @@ void map_reset_entries(PtrMap *h) { } template -void map_reserve(PtrMap *h, isize cap) { +gb_internal void map_reserve(PtrMap *h, isize cap) { array_reserve(&h->entries, cap); if (h->entries.count*2 < h->hashes.count) { return; @@ -172,12 +172,12 @@ void map_reserve(PtrMap *h, isize cap) { template -void map_rehash(PtrMap *h, isize new_count) { +gb_internal void map_rehash(PtrMap *h, isize new_count) { map_reserve(h, new_count); } template -V *map_get(PtrMap *h, K key) { +gb_internal V *map_get(PtrMap *h, K key) { MapIndex index = map__find(h, key).entry_index; if (index != MAP_SENTINEL) { return &h->entries.data[index].value; @@ -186,14 +186,14 @@ V *map_get(PtrMap *h, K key) { } template -V &map_must_get(PtrMap *h, K key) { +gb_internal V &map_must_get(PtrMap *h, K key) { MapIndex index = map__find(h, key).entry_index; GB_ASSERT(index != MAP_SENTINEL); return h->entries.data[index].value; } template -void map_set(PtrMap *h, K key, V const &value) { +gb_internal void map_set(PtrMap *h, K key, V const &value) { MapIndex index; MapFindResult fr; if (h->hashes.count == 0) { @@ -219,7 +219,7 @@ void map_set(PtrMap *h, K key, V const &value) { template -void map__erase(PtrMap *h, MapFindResult const &fr) { +gb_internal void map__erase(PtrMap *h, MapFindResult const &fr) { MapFindResult last; if (fr.entry_prev == MAP_SENTINEL) { h->hashes.data[fr.hash_index] = h->entries.data[fr.entry_index].next; @@ -242,7 +242,7 @@ void map__erase(PtrMap *h, MapFindResult const &fr) { } template -void map_remove(PtrMap *h, K key) { +gb_internal void map_remove(PtrMap *h, K key) { MapFindResult fr = map__find(h, key); if (fr.entry_index != MAP_SENTINEL) { map__erase(h, fr); @@ -250,7 +250,7 @@ void map_remove(PtrMap *h, K key) { } template -gb_inline void map_clear(PtrMap *h) { +gb_internal gb_inline void map_clear(PtrMap *h) { array_clear(&h->entries); for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; @@ -260,7 +260,7 @@ gb_inline void map_clear(PtrMap *h) { #if PTR_MAP_ENABLE_MULTI_MAP template -PtrMapEntry *multi_map_find_first(PtrMap *h, K key) { +gb_internal PtrMapEntry *multi_map_find_first(PtrMap *h, K key) { MapIndex i = map__find(h, key).entry_index; if (i == MAP_SENTINEL) { return nullptr; @@ -269,7 +269,7 @@ PtrMapEntry *multi_map_find_first(PtrMap *h, K key) { } template -PtrMapEntry *multi_map_find_next(PtrMap *h, PtrMapEntry *e) { +gb_internal PtrMapEntry *multi_map_find_next(PtrMap *h, PtrMapEntry *e) { MapIndex i = e->next; while (i != MAP_SENTINEL) { if (h->entries.data[i].key == e->key) { @@ -281,7 +281,7 @@ PtrMapEntry *multi_map_find_next(PtrMap *h, PtrMapEntry *e) { } template -isize multi_map_count(PtrMap *h, K key) { +gb_internal isize multi_map_count(PtrMap *h, K key) { isize count = 0; PtrMapEntry *e = multi_map_find_first(h, key); while (e != nullptr) { @@ -292,7 +292,7 @@ isize multi_map_count(PtrMap *h, K key) { } template -void multi_map_get_all(PtrMap *h, K key, V *items) { +gb_internal void multi_map_get_all(PtrMap *h, K key, V *items) { isize i = 0; PtrMapEntry *e = multi_map_find_first(h, key); while (e != nullptr) { @@ -302,7 +302,7 @@ void multi_map_get_all(PtrMap *h, K key, V *items) { } template -void multi_map_insert(PtrMap *h, K key, V const &value) { +gb_internal void multi_map_insert(PtrMap *h, K key, V const &value) { MapFindResult fr; MapIndex i; if (h->hashes.count == 0) { @@ -325,7 +325,7 @@ void multi_map_insert(PtrMap *h, K key, V const &value) { } template -void multi_map_remove(PtrMap *h, K key, PtrMapEntry *e) { +gb_internal void multi_map_remove(PtrMap *h, K key, PtrMapEntry *e) { MapFindResult fr = map__find_from_entry(h, e); if (fr.entry_index != MAP_SENTINEL) { map__erase(h, fr); @@ -333,7 +333,7 @@ void multi_map_remove(PtrMap *h, K key, PtrMapEntry *e) { } template -void multi_map_remove_all(PtrMap *h, K key) { +gb_internal void multi_map_remove_all(PtrMap *h, K key) { while (map_get(h, key) != nullptr) { map_remove(h, key); } @@ -342,21 +342,21 @@ void multi_map_remove_all(PtrMap *h, K key) { template -PtrMapEntry *begin(PtrMap &m) { +gb_internal PtrMapEntry *begin(PtrMap &m) { return m.entries.data; } template -PtrMapEntry const *begin(PtrMap const &m) { +gb_internal PtrMapEntry const *begin(PtrMap const &m) { return m.entries.data; } template -PtrMapEntry *end(PtrMap &m) { +gb_internal PtrMapEntry *end(PtrMap &m) { return m.entries.data + m.entries.count; } template -PtrMapEntry const *end(PtrMap const &m) { +gb_internal PtrMapEntry const *end(PtrMap const &m) { return m.entries.data + m.entries.count; } diff --git a/src/ptr_set.cpp b/src/ptr_set.cpp index 04ce162e2..9ecf1043e 100644 --- a/src/ptr_set.cpp +++ b/src/ptr_set.cpp @@ -10,20 +10,20 @@ struct PtrSet { Array> entries; }; -template void ptr_set_init (PtrSet *s, gbAllocator a, isize capacity = 16); -template void ptr_set_destroy(PtrSet *s); -template T ptr_set_add (PtrSet *s, T ptr); -template bool ptr_set_update (PtrSet *s, T ptr); // returns true if it previously existed -template bool ptr_set_exists (PtrSet *s, T ptr); -template void ptr_set_remove (PtrSet *s, T ptr); -template void ptr_set_clear (PtrSet *s); -template void ptr_set_grow (PtrSet *s); -template void ptr_set_rehash (PtrSet *s, isize new_count); -template void ptr_set_reserve(PtrSet *h, isize cap); +template gb_internal void ptr_set_init (PtrSet *s, gbAllocator a, isize capacity = 16); +template gb_internal void ptr_set_destroy(PtrSet *s); +template gb_internal T ptr_set_add (PtrSet *s, T ptr); +template gb_internal bool ptr_set_update (PtrSet *s, T ptr); // returns true if it previously existed +template gb_internal bool ptr_set_exists (PtrSet *s, T ptr); +template gb_internal void ptr_set_remove (PtrSet *s, T ptr); +template gb_internal void ptr_set_clear (PtrSet *s); +template gb_internal void ptr_set_grow (PtrSet *s); +template gb_internal void ptr_set_rehash (PtrSet *s, isize new_count); +template gb_internal void ptr_set_reserve(PtrSet *h, isize cap); template -void ptr_set_init(PtrSet *s, gbAllocator a, isize capacity) { +gb_internal void ptr_set_init(PtrSet *s, gbAllocator a, isize capacity) { if (capacity != 0) { capacity = next_pow2_isize(gb_max(16, capacity)); } @@ -36,7 +36,7 @@ void ptr_set_init(PtrSet *s, gbAllocator a, isize capacity) { } template -void ptr_set_destroy(PtrSet *s) { +gb_internal void ptr_set_destroy(PtrSet *s) { slice_free(&s->hashes, s->entries.allocator); array_free(&s->entries); } @@ -93,13 +93,13 @@ gb_internal bool ptr_set__full(PtrSet *s) { } template -gb_inline void ptr_set_grow(PtrSet *s) { +gb_internal gb_inline void ptr_set_grow(PtrSet *s) { isize new_count = gb_max(s->hashes.count<<1, 16); ptr_set_rehash(s, new_count); } template -void ptr_set_reset_entries(PtrSet *s) { +gb_internal void ptr_set_reset_entries(PtrSet *s) { for (isize i = 0; i < s->hashes.count; i++) { s->hashes.data[i] = MAP_SENTINEL; } @@ -117,7 +117,7 @@ void ptr_set_reset_entries(PtrSet *s) { } template -void ptr_set_reserve(PtrSet *s, isize cap) { +gb_internal void ptr_set_reserve(PtrSet *s, isize cap) { array_reserve(&s->entries, cap); if (s->entries.count*2 < s->hashes.count) { return; @@ -128,18 +128,18 @@ void ptr_set_reserve(PtrSet *s, isize cap) { template -void ptr_set_rehash(PtrSet *s, isize new_count) { +gb_internal void ptr_set_rehash(PtrSet *s, isize new_count) { ptr_set_reserve(s, new_count); } template -gb_inline bool ptr_set_exists(PtrSet *s, T ptr) { +gb_internal gb_inline bool ptr_set_exists(PtrSet *s, T ptr) { isize index = ptr_set__find(s, ptr).entry_index; return index != MAP_SENTINEL; } template -gb_inline isize ptr_entry_index(PtrSet *s, T ptr) { +gb_internal gb_inline isize ptr_entry_index(PtrSet *s, T ptr) { isize index = ptr_set__find(s, ptr).entry_index; if (index != MAP_SENTINEL) { return index; @@ -149,7 +149,7 @@ gb_inline isize ptr_entry_index(PtrSet *s, T ptr) { // Returns true if it already exists template -T ptr_set_add(PtrSet *s, T ptr) { +gb_internal T ptr_set_add(PtrSet *s, T ptr) { MapIndex index; MapFindResult fr; if (s->hashes.count == 0) { @@ -171,7 +171,7 @@ T ptr_set_add(PtrSet *s, T ptr) { } template -bool ptr_set_update(PtrSet *s, T ptr) { // returns true if it previously existsed +gb_internal bool ptr_set_update(PtrSet *s, T ptr) { // returns true if it previously existsed bool exists = false; MapIndex index; MapFindResult fr; @@ -198,7 +198,7 @@ bool ptr_set_update(PtrSet *s, T ptr) { // returns true if it previously exis template -void ptr_set__erase(PtrSet *s, MapFindResult fr) { +gb_internal void ptr_set__erase(PtrSet *s, MapFindResult fr) { MapFindResult last; if (fr.entry_prev == MAP_SENTINEL) { s->hashes.data[fr.hash_index] = s->entries.data[fr.entry_index].next; @@ -219,7 +219,7 @@ void ptr_set__erase(PtrSet *s, MapFindResult fr) { } template -void ptr_set_remove(PtrSet *s, T ptr) { +gb_internal void ptr_set_remove(PtrSet *s, T ptr) { MapFindResult fr = ptr_set__find(s, ptr); if (fr.entry_index != MAP_SENTINEL) { ptr_set__erase(s, fr); @@ -227,7 +227,7 @@ void ptr_set_remove(PtrSet *s, T ptr) { } template -gb_inline void ptr_set_clear(PtrSet *s) { +gb_internal gb_inline void ptr_set_clear(PtrSet *s) { array_clear(&s->entries); for (isize i = 0; i < s->hashes.count; i++) { s->hashes.data[i] = MAP_SENTINEL; @@ -236,21 +236,21 @@ gb_inline void ptr_set_clear(PtrSet *s) { template -PtrSetEntry *begin(PtrSet &m) { +gb_internal PtrSetEntry *begin(PtrSet &m) { return m.entries.data; } template -PtrSetEntry const *begin(PtrSet const &m) { +gb_internal PtrSetEntry const *begin(PtrSet const &m) { return m.entries.data; } template -PtrSetEntry *end(PtrSet &m) { +gb_internal PtrSetEntry *end(PtrSet &m) { return m.entries.data + m.entries.count; } template -PtrSetEntry const *end(PtrSet const &m) { +gb_internal PtrSetEntry const *end(PtrSet const &m) { return m.entries.data + m.entries.count; } \ No newline at end of file diff --git a/src/queue.cpp b/src/queue.cpp index ee8b1b086..4de5ac5e5 100644 --- a/src/queue.cpp +++ b/src/queue.cpp @@ -23,7 +23,7 @@ struct MPMCQueue { -void mpmc_internal_init_indices(MPMCQueueAtomicIdx *indices, i32 offset, i32 size) { +gb_internal void mpmc_internal_init_indices(MPMCQueueAtomicIdx *indices, i32 offset, i32 size) { GB_ASSERT(offset % 8 == 0); GB_ASSERT(size % 8 == 0); @@ -43,7 +43,7 @@ void mpmc_internal_init_indices(MPMCQueueAtomicIdx *indices, i32 offset, i32 siz template -void mpmc_init(MPMCQueue *q, gbAllocator a, isize size_i) { +gb_internal void mpmc_init(MPMCQueue *q, gbAllocator a, isize size_i) { if (size_i < 8) { size_i = 8; } @@ -64,7 +64,7 @@ void mpmc_init(MPMCQueue *q, gbAllocator a, isize size_i) { template -void mpmc_destroy(MPMCQueue *q) { +gb_internal void mpmc_destroy(MPMCQueue *q) { mutex_destroy(&q->mutex); gb_free(q->allocator, q->nodes); gb_free(q->allocator, q->indices); @@ -72,7 +72,7 @@ void mpmc_destroy(MPMCQueue *q) { template -bool mpmc_internal_grow(MPMCQueue *q) { +gb_internal bool mpmc_internal_grow(MPMCQueue *q) { mutex_lock(&q->mutex); i32 old_size = q->mask+1; i32 new_size = old_size*2; @@ -95,7 +95,7 @@ bool mpmc_internal_grow(MPMCQueue *q) { } template -i32 mpmc_enqueue(MPMCQueue *q, T const &data) { +gb_internal i32 mpmc_enqueue(MPMCQueue *q, T const &data) { GB_ASSERT(q->mask != 0); i32 head_idx = q->head_idx.load(std::memory_order_relaxed); @@ -125,7 +125,7 @@ i32 mpmc_enqueue(MPMCQueue *q, T const &data) { } template -bool mpmc_dequeue(MPMCQueue *q, T *data_) { +gb_internal bool mpmc_dequeue(MPMCQueue *q, T *data_) { if (q->mask == 0) { return false; } diff --git a/src/range_cache.cpp b/src/range_cache.cpp index 9701fb432..1f98c4b9e 100644 --- a/src/range_cache.cpp +++ b/src/range_cache.cpp @@ -10,17 +10,17 @@ struct RangeCache { }; -RangeCache range_cache_make(gbAllocator a) { +gb_internal RangeCache range_cache_make(gbAllocator a) { RangeCache cache = {}; array_init(&cache.ranges, a); return cache; } -void range_cache_destroy(RangeCache *c) { +gb_internal void range_cache_destroy(RangeCache *c) { array_free(&c->ranges); } -bool range_cache_add_index(RangeCache *c, i64 index) { +gb_internal bool range_cache_add_index(RangeCache *c, i64 index) { for_array(i, c->ranges) { RangeValue v = c->ranges[i]; if (v.lo <= index && index <= v.hi) { @@ -33,7 +33,7 @@ bool range_cache_add_index(RangeCache *c, i64 index) { } -bool range_cache_add_range(RangeCache *c, i64 lo, i64 hi) { +gb_internal bool range_cache_add_range(RangeCache *c, i64 lo, i64 hi) { GB_ASSERT(lo <= hi); for_array(i, c->ranges) { RangeValue v = c->ranges[i]; @@ -59,7 +59,7 @@ bool range_cache_add_range(RangeCache *c, i64 lo, i64 hi) { } -bool range_cache_index_exists(RangeCache *c, i64 index) { +gb_internal bool range_cache_index_exists(RangeCache *c, i64 index) { for_array(i, c->ranges) { RangeValue v = c->ranges[i]; if (v.lo <= index && index <= v.hi) { diff --git a/src/string.cpp b/src/string.cpp index bc55e370c..aeb31c7b0 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -1,6 +1,6 @@ gb_global BlockingMutex string_buffer_mutex = {}; -void init_string_buffer_memory(void) { +gb_internal void init_string_buffer_memory(void) { mutex_init(&string_buffer_mutex); } @@ -36,7 +36,7 @@ struct String16 { }; -gb_inline String make_string(u8 const *text, isize len) { +gb_internal gb_inline String make_string(u8 const *text, isize len) { String s; s.text = cast(u8 *)text; if (len < 0) { @@ -47,14 +47,14 @@ gb_inline String make_string(u8 const *text, isize len) { } -gb_inline String16 make_string16(wchar_t const *text, isize len) { +gb_internal gb_inline String16 make_string16(wchar_t const *text, isize len) { String16 s; s.text = cast(wchar_t *)text; s.len = len; return s; } -isize string16_len(wchar_t const *s) { +gb_internal isize string16_len(wchar_t const *s) { if (s == nullptr) { return 0; } @@ -66,15 +66,15 @@ isize string16_len(wchar_t const *s) { } -gb_inline String make_string_c(char const *text) { +gb_internal gb_inline String make_string_c(char const *text) { return make_string(cast(u8 *)cast(void *)text, gb_strlen(text)); } -gb_inline String16 make_string16_c(wchar_t const *text) { +gb_internal gb_inline String16 make_string16_c(wchar_t const *text) { return make_string16(text, string16_len(text)); } -String substring(String const &s, isize lo, isize hi) { +gb_internal String substring(String const &s, isize lo, isize hi) { isize max = s.len; GB_ASSERT_MSG(lo <= hi && hi <= max, "%td..%td..%td", lo, hi, max); @@ -82,14 +82,14 @@ String substring(String const &s, isize lo, isize hi) { } -char *alloc_cstring(gbAllocator a, String s) { +gb_internal char *alloc_cstring(gbAllocator a, String s) { char *c_str = gb_alloc_array(a, char, s.len+1); gb_memmove(c_str, s.text, s.len); c_str[s.len] = '\0'; return c_str; } -char *cstring_duplicate(gbAllocator a, char const *s) { +gb_internal char *cstring_duplicate(gbAllocator a, char const *s) { isize len = gb_strlen(s); char *c_str = gb_alloc_array(a, char, len+1); gb_memmove(c_str, s, len); @@ -99,7 +99,7 @@ char *cstring_duplicate(gbAllocator a, char const *s) { -gb_inline bool str_eq_ignore_case(String const &a, String const &b) { +gb_internal gb_inline bool str_eq_ignore_case(String const &a, String const &b) { if (a.len == b.len) { for (isize i = 0; i < a.len; i++) { char x = cast(char)a[i]; @@ -113,13 +113,13 @@ gb_inline bool str_eq_ignore_case(String const &a, String const &b) { return false; } -void string_to_lower(String *s) { +gb_internal void string_to_lower(String *s) { for (isize i = 0; i < s->len; i++) { s->text[i] = gb_char_to_lower(s->text[i]); } } -int string_compare(String const &x, String const &y) { +gb_internal int string_compare(String const &x, String const &y) { if (x.len != y.len || x.text != y.text) { isize n, fast, offset, curr_block; isize *la, *lb; @@ -157,7 +157,7 @@ int string_compare(String const &x, String const &y) { return 0; } -isize string_index_byte(String const &s, u8 x) { +gb_internal isize string_index_byte(String const &s, u8 x) { for (isize i = 0; i < s.len; i++) { if (s.text[i] == x) { return i; @@ -166,37 +166,37 @@ isize string_index_byte(String const &s, u8 x) { return -1; } -GB_COMPARE_PROC(string_cmp_proc) { +gb_internal GB_COMPARE_PROC(string_cmp_proc) { String x = *(String *)a; String y = *(String *)b; return string_compare(x, y); } -gb_inline bool str_eq(String const &a, String const &b) { +gb_internal gb_inline bool str_eq(String const &a, String const &b) { if (a.len != b.len) return false; return memcmp(a.text, b.text, a.len) == 0; } -gb_inline bool str_ne(String const &a, String const &b) { return !str_eq(a, b); } -gb_inline bool str_lt(String const &a, String const &b) { return string_compare(a, b) < 0; } -gb_inline bool str_gt(String const &a, String const &b) { return string_compare(a, b) > 0; } -gb_inline bool str_le(String const &a, String const &b) { return string_compare(a, b) <= 0; } -gb_inline bool str_ge(String const &a, String const &b) { return string_compare(a, b) >= 0; } - -gb_inline bool operator == (String const &a, String const &b) { return str_eq(a, b); } -gb_inline bool operator != (String const &a, String const &b) { return str_ne(a, b); } -gb_inline bool operator < (String const &a, String const &b) { return str_lt(a, b); } -gb_inline bool operator > (String const &a, String const &b) { return str_gt(a, b); } -gb_inline bool operator <= (String const &a, String const &b) { return str_le(a, b); } -gb_inline bool operator >= (String const &a, String const &b) { return str_ge(a, b); } - -template bool operator == (String const &a, char const (&b)[N]) { return str_eq(a, make_string(cast(u8 *)b, N-1)); } -template bool operator != (String const &a, char const (&b)[N]) { return str_ne(a, make_string(cast(u8 *)b, N-1)); } -template bool operator < (String const &a, char const (&b)[N]) { return str_lt(a, make_string(cast(u8 *)b, N-1)); } -template bool operator > (String const &a, char const (&b)[N]) { return str_gt(a, make_string(cast(u8 *)b, N-1)); } -template bool operator <= (String const &a, char const (&b)[N]) { return str_le(a, make_string(cast(u8 *)b, N-1)); } -template bool operator >= (String const &a, char const (&b)[N]) { return str_ge(a, make_string(cast(u8 *)b, N-1)); } - -gb_inline bool string_starts_with(String const &s, String const &prefix) { +gb_internal gb_inline bool str_ne(String const &a, String const &b) { return !str_eq(a, b); } +gb_internal gb_inline bool str_lt(String const &a, String const &b) { return string_compare(a, b) < 0; } +gb_internal gb_inline bool str_gt(String const &a, String const &b) { return string_compare(a, b) > 0; } +gb_internal gb_inline bool str_le(String const &a, String const &b) { return string_compare(a, b) <= 0; } +gb_internal gb_inline bool str_ge(String const &a, String const &b) { return string_compare(a, b) >= 0; } + +gb_internal gb_inline bool operator == (String const &a, String const &b) { return str_eq(a, b); } +gb_internal gb_inline bool operator != (String const &a, String const &b) { return str_ne(a, b); } +gb_internal gb_inline bool operator < (String const &a, String const &b) { return str_lt(a, b); } +gb_internal gb_inline bool operator > (String const &a, String const &b) { return str_gt(a, b); } +gb_internal gb_inline bool operator <= (String const &a, String const &b) { return str_le(a, b); } +gb_internal gb_inline bool operator >= (String const &a, String const &b) { return str_ge(a, b); } + +template gb_internal bool operator == (String const &a, char const (&b)[N]) { return str_eq(a, make_string(cast(u8 *)b, N-1)); } +template gb_internal bool operator != (String const &a, char const (&b)[N]) { return str_ne(a, make_string(cast(u8 *)b, N-1)); } +template gb_internal bool operator < (String const &a, char const (&b)[N]) { return str_lt(a, make_string(cast(u8 *)b, N-1)); } +template gb_internal bool operator > (String const &a, char const (&b)[N]) { return str_gt(a, make_string(cast(u8 *)b, N-1)); } +template gb_internal bool operator <= (String const &a, char const (&b)[N]) { return str_le(a, make_string(cast(u8 *)b, N-1)); } +template gb_internal bool operator >= (String const &a, char const (&b)[N]) { return str_ge(a, make_string(cast(u8 *)b, N-1)); } + +gb_internal gb_inline bool string_starts_with(String const &s, String const &prefix) { if (prefix.len > s.len) { return false; } @@ -204,7 +204,7 @@ gb_inline bool string_starts_with(String const &s, String const &prefix) { return substring(s, 0, prefix.len) == prefix; } -gb_inline bool string_ends_with(String const &s, String const &suffix) { +gb_internal gb_inline bool string_ends_with(String const &s, String const &suffix) { if (suffix.len > s.len) { return false; } @@ -212,7 +212,7 @@ gb_inline bool string_ends_with(String const &s, String const &suffix) { return substring(s, s.len-suffix.len, s.len) == suffix; } -gb_inline bool string_starts_with(String const &s, u8 prefix) { +gb_internal gb_inline bool string_starts_with(String const &s, u8 prefix) { if (1 > s.len) { return false; } @@ -221,7 +221,7 @@ gb_inline bool string_starts_with(String const &s, u8 prefix) { } -gb_inline bool string_ends_with(String const &s, u8 suffix) { +gb_internal gb_inline bool string_ends_with(String const &s, u8 suffix) { if (1 > s.len) { return false; } @@ -231,7 +231,7 @@ gb_inline bool string_ends_with(String const &s, u8 suffix) { -gb_inline String string_trim_starts_with(String const &s, String const &prefix) { +gb_internal gb_inline String string_trim_starts_with(String const &s, String const &prefix) { if (string_starts_with(s, prefix)) { return substring(s, prefix.len, s.len); } @@ -239,7 +239,7 @@ gb_inline String string_trim_starts_with(String const &s, String const &prefix) } -gb_inline isize string_extension_position(String const &str) { +gb_internal gb_inline isize string_extension_position(String const &str) { isize dot_pos = -1; isize i = str.len; while (i --> 0) { @@ -254,7 +254,7 @@ gb_inline isize string_extension_position(String const &str) { return dot_pos; } -String path_extension(String const &str, bool include_dot = true) { +gb_internal String path_extension(String const &str, bool include_dot = true) { isize pos = string_extension_position(str); if (pos < 0) { return make_string(nullptr, 0); @@ -262,7 +262,7 @@ String path_extension(String const &str, bool include_dot = true) { return substring(str, include_dot ? pos : pos + 1, str.len); } -String string_trim_whitespace(String str) { +gb_internal String string_trim_whitespace(String str) { while (str.len > 0 && rune_is_whitespace(str[str.len-1])) { str.len--; } @@ -279,7 +279,7 @@ String string_trim_whitespace(String str) { return str; } -bool string_contains_char(String const &s, u8 c) { +gb_internal bool string_contains_char(String const &s, u8 c) { isize i; for (i = 0; i < s.len; i++) { if (s[i] == c) @@ -288,7 +288,7 @@ bool string_contains_char(String const &s, u8 c) { return false; } -String filename_from_path(String s) { +gb_internal String filename_from_path(String s) { isize i = string_extension_position(s); if (i >= 0) { s = substring(s, 0, i); @@ -307,7 +307,7 @@ String filename_from_path(String s) { return make_string(nullptr, 0); } -String concatenate_strings(gbAllocator a, String const &x, String const &y) { +gb_internal String concatenate_strings(gbAllocator a, String const &x, String const &y) { isize len = x.len+y.len; u8 *data = gb_alloc_array(a, u8, len+1); gb_memmove(data, x.text, x.len); @@ -315,7 +315,7 @@ String concatenate_strings(gbAllocator a, String const &x, String const &y) { data[len] = 0; return make_string(data, len); } -String concatenate3_strings(gbAllocator a, String const &x, String const &y, String const &z) { +gb_internal String concatenate3_strings(gbAllocator a, String const &x, String const &y, String const &z) { isize len = x.len+y.len+z.len; u8 *data = gb_alloc_array(a, u8, len+1); gb_memmove(data, x.text, x.len); @@ -324,7 +324,7 @@ String concatenate3_strings(gbAllocator a, String const &x, String const &y, Str data[len] = 0; return make_string(data, len); } -String concatenate4_strings(gbAllocator a, String const &x, String const &y, String const &z, String const &w) { +gb_internal String concatenate4_strings(gbAllocator a, String const &x, String const &y, String const &z, String const &w) { isize len = x.len+y.len+z.len+w.len; u8 *data = gb_alloc_array(a, u8, len+1); gb_memmove(data, x.text, x.len); @@ -335,7 +335,7 @@ String concatenate4_strings(gbAllocator a, String const &x, String const &y, Str return make_string(data, len); } -String string_join_and_quote(gbAllocator a, Array strings) { +gb_internal String string_join_and_quote(gbAllocator a, Array strings) { if (!strings.count) { return make_string(nullptr, 0); } @@ -356,7 +356,7 @@ String string_join_and_quote(gbAllocator a, Array strings) { return make_string(cast(u8 *) s, gb_string_length(s)); } -String copy_string(gbAllocator a, String const &s) { +gb_internal String copy_string(gbAllocator a, String const &s) { u8 *data = gb_alloc_array(a, u8, s.len+1); gb_memmove(data, s.text, s.len); data[s.len] = 0; @@ -367,17 +367,17 @@ String copy_string(gbAllocator a, String const &s) { #if defined(GB_SYSTEM_WINDOWS) - int convert_multibyte_to_widechar(char const *multibyte_input, int input_length, wchar_t *output, int output_size) { + gb_internal int convert_multibyte_to_widechar(char const *multibyte_input, int input_length, wchar_t *output, int output_size) { return MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, multibyte_input, input_length, output, output_size); } - int convert_widechar_to_multibyte(wchar_t const *widechar_input, int input_length, char *output, int output_size) { + gb_internal int convert_widechar_to_multibyte(wchar_t const *widechar_input, int input_length, char *output, int output_size) { return WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, widechar_input, input_length, output, output_size, nullptr, nullptr); } #elif defined(GB_SYSTEM_UNIX) || defined(GB_SYSTEM_OSX) #include - int convert_multibyte_to_widechar(char const *multibyte_input, usize input_length, wchar_t *output, usize output_size) { + gb_internal int convert_multibyte_to_widechar(char const *multibyte_input, usize input_length, wchar_t *output, usize output_size) { iconv_t conv = iconv_open("WCHAR_T", "UTF-8"); size_t result = iconv(conv, cast(char **)&multibyte_input, &input_length, cast(char **)&output, &output_size); iconv_close(conv); @@ -385,7 +385,7 @@ String copy_string(gbAllocator a, String const &s) { return cast(int)result; } - int convert_widechar_to_multibyte(wchar_t const *widechar_input, usize input_length, char* output, usize output_size) { + gb_internal int convert_widechar_to_multibyte(wchar_t const *widechar_input, usize input_length, char* output, usize output_size) { iconv_t conv = iconv_open("UTF-8", "WCHAR_T"); size_t result = iconv(conv, cast(char**) &widechar_input, &input_length, cast(char **)&output, &output_size); iconv_close(conv); @@ -400,7 +400,7 @@ String copy_string(gbAllocator a, String const &s) { // TODO(bill): Make this non-windows specific -String16 string_to_string16(gbAllocator a, String s) { +gb_internal String16 string_to_string16(gbAllocator a, String s) { int len, len1; wchar_t *text; @@ -426,7 +426,7 @@ String16 string_to_string16(gbAllocator a, String s) { } -String string16_to_string(gbAllocator a, String16 s) { +gb_internal String string16_to_string(gbAllocator a, String16 s) { int len, len1; u8 *text; @@ -458,7 +458,7 @@ String string16_to_string(gbAllocator a, String16 s) { -bool is_printable(Rune r) { +gb_internal bool is_printable(Rune r) { if (r <= 0xff) { if (0x20 <= r && r <= 0x7e) { return true; @@ -473,7 +473,7 @@ bool is_printable(Rune r) { gb_global char const lower_hex[] = "0123456789abcdef"; -String quote_to_ascii(gbAllocator a, String str, u8 quote='"') { +gb_internal String quote_to_ascii(gbAllocator a, String str, u8 quote='"') { u8 *s = str.text; isize n = str.len; auto buf = array_make(a, 0, n); @@ -548,7 +548,7 @@ String quote_to_ascii(gbAllocator a, String str, u8 quote='"') { -bool unquote_char(String s, u8 quote, Rune *rune, bool *multiple_bytes, String *tail_string) { +gb_internal bool unquote_char(String s, u8 quote, Rune *rune, bool *multiple_bytes, String *tail_string) { u8 c; if (s[0] == quote && @@ -657,7 +657,7 @@ bool unquote_char(String s, u8 quote, Rune *rune, bool *multiple_bytes, String * } -String strip_carriage_return(gbAllocator a, String s) { +gb_internal String strip_carriage_return(gbAllocator a, String s) { isize buf_len = s.len; u8 *buf = gb_alloc_array(a, u8, buf_len); isize i = 0; @@ -675,7 +675,7 @@ String strip_carriage_return(gbAllocator a, String s) { // 0 == failure // 1 == original memory // 2 == new allocation -i32 unquote_string(gbAllocator a, String *s_, u8 quote=0, bool has_carriage_return=false) { +gb_internal i32 unquote_string(gbAllocator a, String *s_, u8 quote=0, bool has_carriage_return=false) { String s = *s_; isize n = s.len; if (quote == 0) { @@ -761,7 +761,7 @@ i32 unquote_string(gbAllocator a, String *s_, u8 quote=0, bool has_carriage_retu -bool string_is_valid_identifier(String str) { +gb_internal bool string_is_valid_identifier(String str) { if (str.len <= 0) return false; isize rune_count = 0; diff --git a/src/string_map.cpp b/src/string_map.cpp index e2a4d5f65..e289d4c9b 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -3,7 +3,7 @@ struct StringHashKey { String string; }; -gb_inline StringHashKey string_hash_string(String const &s) { +gb_internal gb_inline StringHashKey string_hash_string(String const &s) { StringHashKey hash_key = {}; hash_key.hash = fnv32a(s.text, s.len); hash_key.string = s; @@ -11,15 +11,15 @@ gb_inline StringHashKey string_hash_string(String const &s) { } -bool string_hash_key_equal(StringHashKey const &a, StringHashKey const &b) { +gb_internal gb_inline bool string_hash_key_equal(StringHashKey const &a, StringHashKey const &b) { if (a.hash == b.hash) { // NOTE(bill): If two string's hashes collide, compare the strings themselves return a.string == b.string; } return false; } -bool operator==(StringHashKey const &a, StringHashKey const &b) { return string_hash_key_equal(a, b); } -bool operator!=(StringHashKey const &a, StringHashKey const &b) { return !string_hash_key_equal(a, b); } +gb_internal bool operator==(StringHashKey const &a, StringHashKey const &b) { return string_hash_key_equal(a, b); } +gb_internal bool operator!=(StringHashKey const &a, StringHashKey const &b) { return !string_hash_key_equal(a, b); } template struct StringMapEntry { @@ -37,29 +37,29 @@ struct StringMap { }; -template void string_map_init (StringMap *h, gbAllocator a, isize capacity = 16); -template void string_map_destroy (StringMap *h); +template gb_internal void string_map_init (StringMap *h, gbAllocator a, isize capacity = 16); +template gb_internal void string_map_destroy (StringMap *h); -template T * string_map_get (StringMap *h, char const *key); -template T * string_map_get (StringMap *h, String const &key); -template T * string_map_get (StringMap *h, StringHashKey const &key); +template gb_internal T * string_map_get (StringMap *h, char const *key); +template gb_internal T * string_map_get (StringMap *h, String const &key); +template gb_internal T * string_map_get (StringMap *h, StringHashKey const &key); -template T & string_map_must_get (StringMap *h, char const *key); -template T & string_map_must_get (StringMap *h, String const &key); -template T & string_map_must_get (StringMap *h, StringHashKey const &key); +template gb_internal T & string_map_must_get (StringMap *h, char const *key); +template gb_internal T & string_map_must_get (StringMap *h, String const &key); +template gb_internal T & string_map_must_get (StringMap *h, StringHashKey const &key); -template void string_map_set (StringMap *h, StringHashKey const &key, T const &value); -template void string_map_set (StringMap *h, String const &key, T const &value); -template void string_map_set (StringMap *h, char const *key, T const &value); +template gb_internal void string_map_set (StringMap *h, StringHashKey const &key, T const &value); +template gb_internal void string_map_set (StringMap *h, String const &key, T const &value); +template gb_internal void string_map_set (StringMap *h, char const *key, T const &value); -template void string_map_remove (StringMap *h, StringHashKey const &key); -template void string_map_clear (StringMap *h); -template void string_map_grow (StringMap *h); -template void string_map_rehash (StringMap *h, isize new_count); -template void string_map_reserve (StringMap *h, isize cap); +template gb_internal void string_map_remove (StringMap *h, StringHashKey const &key); +template gb_internal void string_map_clear (StringMap *h); +template gb_internal void string_map_grow (StringMap *h); +template gb_internal void string_map_rehash (StringMap *h, isize new_count); +template gb_internal void string_map_reserve (StringMap *h, isize cap); template -gb_inline void string_map_init(StringMap *h, gbAllocator a, isize capacity) { +gb_internal gb_inline void string_map_init(StringMap *h, gbAllocator a, isize capacity) { capacity = next_pow2_isize(capacity); slice_init(&h->hashes, a, capacity); array_init(&h->entries, a, 0, capacity); @@ -69,7 +69,7 @@ gb_inline void string_map_init(StringMap *h, gbAllocator a, isize capacity) { } template -gb_inline void string_map_destroy(StringMap *h) { +gb_internal gb_inline void string_map_destroy(StringMap *h) { slice_free(&h->hashes, h->entries.allocator); array_free(&h->entries); } @@ -130,7 +130,7 @@ gb_inline void string_map_grow(StringMap *h) { template -void string_map_reset_entries(StringMap *h) { +gb_internal void string_map_reset_entries(StringMap *h) { for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; } @@ -148,7 +148,7 @@ void string_map_reset_entries(StringMap *h) { } template -void string_map_reserve(StringMap *h, isize cap) { +gb_internal void string_map_reserve(StringMap *h, isize cap) { array_reserve(&h->entries, cap); if (h->entries.count*2 < h->hashes.count) { return; @@ -159,12 +159,12 @@ void string_map_reserve(StringMap *h, isize cap) { template -void string_map_rehash(StringMap *h, isize new_count) { +gb_internal void string_map_rehash(StringMap *h, isize new_count) { string_map_reserve(h, new_count); } template -T *string_map_get(StringMap *h, StringHashKey const &key) { +gb_internal T *string_map_get(StringMap *h, StringHashKey const &key) { isize index = string_map__find(h, key).entry_index; if (index != MAP_SENTINEL) { return &h->entries.data[index].value; @@ -173,34 +173,34 @@ T *string_map_get(StringMap *h, StringHashKey const &key) { } template -gb_inline T *string_map_get(StringMap *h, String const &key) { +gb_internal gb_inline T *string_map_get(StringMap *h, String const &key) { return string_map_get(h, string_hash_string(key)); } template -gb_inline T *string_map_get(StringMap *h, char const *key) { +gb_internal gb_inline T *string_map_get(StringMap *h, char const *key) { return string_map_get(h, string_hash_string(make_string_c(key))); } template -T &string_map_must_get(StringMap *h, StringHashKey const &key) { +gb_internal T &string_map_must_get(StringMap *h, StringHashKey const &key) { isize index = string_map__find(h, key).entry_index; GB_ASSERT(index != MAP_SENTINEL); return h->entries.data[index].value; } template -gb_inline T &string_map_must_get(StringMap *h, String const &key) { +gb_internal gb_inline T &string_map_must_get(StringMap *h, String const &key) { return string_map_must_get(h, string_hash_string(key)); } template -gb_inline T &string_map_must_get(StringMap *h, char const *key) { +gb_internal gb_inline T &string_map_must_get(StringMap *h, char const *key) { return string_map_must_get(h, string_hash_string(make_string_c(key))); } template -void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { +gb_internal void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { MapIndex index; MapFindResult fr; if (h->hashes.count == 0) { @@ -225,18 +225,18 @@ void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { } template -gb_inline void string_map_set(StringMap *h, String const &key, T const &value) { +gb_internal gb_inline void string_map_set(StringMap *h, String const &key, T const &value) { string_map_set(h, string_hash_string(key), value); } template -gb_inline void string_map_set(StringMap *h, char const *key, T const &value) { +gb_internal gb_inline void string_map_set(StringMap *h, char const *key, T const &value) { string_map_set(h, string_hash_string(make_string_c(key)), value); } template -void string_map__erase(StringMap *h, MapFindResult const &fr) { +gb_internal void string_map__erase(StringMap *h, MapFindResult const &fr) { MapFindResult last; if (fr.entry_prev == MAP_SENTINEL) { h->hashes.data[fr.hash_index] = h->entries.data[fr.entry_index].next; @@ -257,7 +257,7 @@ void string_map__erase(StringMap *h, MapFindResult const &fr) { } template -void string_map_remove(StringMap *h, StringHashKey const &key) { +gb_internal void string_map_remove(StringMap *h, StringHashKey const &key) { MapFindResult fr = string_map__find(h, key); if (fr.entry_index != MAP_SENTINEL) { string_map__erase(h, fr); @@ -265,7 +265,7 @@ void string_map_remove(StringMap *h, StringHashKey const &key) { } template -gb_inline void string_map_clear(StringMap *h) { +gb_internal gb_inline void string_map_clear(StringMap *h) { array_clear(&h->entries); for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; @@ -275,21 +275,21 @@ gb_inline void string_map_clear(StringMap *h) { template -StringMapEntry *begin(StringMap &m) { +gb_internal StringMapEntry *begin(StringMap &m) { return m.entries.data; } template -StringMapEntry const *begin(StringMap const &m) { +gb_internal StringMapEntry const *begin(StringMap const &m) { return m.entries.data; } template -StringMapEntry *end(StringMap &m) { +gb_internal StringMapEntry *end(StringMap &m) { return m.entries.data + m.entries.count; } template -StringMapEntry const *end(StringMap const &m) { +gb_internal StringMapEntry const *end(StringMap const &m) { return m.entries.data + m.entries.count; } \ No newline at end of file diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index 727cdcdda..1b3e74fbe 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -23,9 +23,9 @@ struct ThreadPool { }; -THREAD_PROC(thread_pool_thread_proc); +gb_internal THREAD_PROC(thread_pool_thread_proc); -void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count, char const *worker_name) { +gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count, char const *worker_name) { pool->allocator = a; pool->stop = false; mutex_init(&pool->mutex); @@ -43,7 +43,7 @@ void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count } } -void thread_pool_destroy(ThreadPool *pool) { +gb_internal void thread_pool_destroy(ThreadPool *pool) { mutex_lock(&pool->mutex); pool->stop = true; condition_broadcast(&pool->task_cond); @@ -64,23 +64,23 @@ void thread_pool_destroy(ThreadPool *pool) { condition_destroy(&pool->task_cond); } -bool thread_pool_queue_empty(ThreadPool *pool) { +gb_internal bool thread_pool_queue_empty(ThreadPool *pool) { return pool->task_queue == nullptr; } -WorkerTask *thread_pool_queue_pop(ThreadPool *pool) { +gb_internal WorkerTask *thread_pool_queue_pop(ThreadPool *pool) { GB_ASSERT(pool->task_queue != nullptr); WorkerTask *task = pool->task_queue; pool->task_queue = task->next; return task; } -void thread_pool_queue_push(ThreadPool *pool, WorkerTask *task) { +gb_internal void thread_pool_queue_push(ThreadPool *pool, WorkerTask *task) { GB_ASSERT(task != nullptr); task->next = pool->task_queue; pool->task_queue = task; } -bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data) { +gb_internal bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data) { GB_ASSERT(proc != nullptr); mutex_lock(&pool->mutex); WorkerTask *task = gb_alloc_item(permanent_allocator(), WorkerTask); @@ -101,11 +101,11 @@ bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data) { } -void thread_pool_do_task(WorkerTask *task) { +gb_internal void thread_pool_do_task(WorkerTask *task) { task->do_work(task->data); } -void thread_pool_wait(ThreadPool *pool) { +gb_internal void thread_pool_wait(ThreadPool *pool) { if (pool->threads.count == 0) { while (!thread_pool_queue_empty(pool)) { thread_pool_do_task(thread_pool_queue_pop(pool)); @@ -138,7 +138,7 @@ void thread_pool_wait(ThreadPool *pool) { } -THREAD_PROC(thread_pool_thread_proc) { +gb_internal THREAD_PROC(thread_pool_thread_proc) { ThreadPool *pool = cast(ThreadPool *)thread->user_data; for (;;) { diff --git a/src/threading.cpp b/src/threading.cpp index 63e3415b2..511d1b477 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -29,43 +29,43 @@ struct Thread { }; -void mutex_init (BlockingMutex *m); -void mutex_destroy (BlockingMutex *m); -void mutex_lock (BlockingMutex *m); -bool mutex_try_lock(BlockingMutex *m); -void mutex_unlock (BlockingMutex *m); -void mutex_init (RecursiveMutex *m); -void mutex_destroy (RecursiveMutex *m); -void mutex_lock (RecursiveMutex *m); -bool mutex_try_lock(RecursiveMutex *m); -void mutex_unlock (RecursiveMutex *m); - -void semaphore_init (Semaphore *s); -void semaphore_destroy(Semaphore *s); -void semaphore_post (Semaphore *s, i32 count); -void semaphore_wait (Semaphore *s); -void semaphore_release(Semaphore *s) { semaphore_post(s, 1); } - - -void condition_init(Condition *c); -void condition_destroy(Condition *c); -void condition_broadcast(Condition *c); -void condition_signal(Condition *c); -void condition_wait(Condition *c, BlockingMutex *m); -void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms); - -u32 thread_current_id(void); - -void thread_init (Thread *t); -void thread_destroy (Thread *t); -void thread_start (Thread *t, ThreadProc *proc, void *data); -void thread_start_with_stack(Thread *t, ThreadProc *proc, void *data, isize stack_size); -void thread_join (Thread *t); -bool thread_is_running (Thread const *t); -void thread_set_name (Thread *t, char const *name); - -void yield_thread(void); -void yield_process(void); +gb_internal void mutex_init (BlockingMutex *m); +gb_internal void mutex_destroy (BlockingMutex *m); +gb_internal void mutex_lock (BlockingMutex *m); +gb_internal bool mutex_try_lock(BlockingMutex *m); +gb_internal void mutex_unlock (BlockingMutex *m); +gb_internal void mutex_init (RecursiveMutex *m); +gb_internal void mutex_destroy (RecursiveMutex *m); +gb_internal void mutex_lock (RecursiveMutex *m); +gb_internal bool mutex_try_lock(RecursiveMutex *m); +gb_internal void mutex_unlock (RecursiveMutex *m); + +gb_internal void semaphore_init (Semaphore *s); +gb_internal void semaphore_destroy(Semaphore *s); +gb_internal void semaphore_post (Semaphore *s, i32 count); +gb_internal void semaphore_wait (Semaphore *s); +gb_internal void semaphore_release(Semaphore *s) { semaphore_post(s, 1); } + + +gb_internal void condition_init(Condition *c); +gb_internal void condition_destroy(Condition *c); +gb_internal void condition_broadcast(Condition *c); +gb_internal void condition_signal(Condition *c); +gb_internal void condition_wait(Condition *c, BlockingMutex *m); +gb_internal void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms); + +gb_internal u32 thread_current_id(void); + +gb_internal void thread_init (Thread *t); +gb_internal void thread_destroy (Thread *t); +gb_internal void thread_start (Thread *t, ThreadProc *proc, void *data); +gb_internal void thread_start_with_stack(Thread *t, ThreadProc *proc, void *data, isize stack_size); +gb_internal void thread_join (Thread *t); +gb_internal bool thread_is_running (Thread const *t); +gb_internal void thread_set_name (Thread *t, char const *name); + +gb_internal void yield_thread(void); +gb_internal void yield_process(void); struct MutexGuard { @@ -106,36 +106,36 @@ struct MutexGuard { struct BlockingMutex { SRWLOCK srwlock; }; - void mutex_init(BlockingMutex *m) { + gb_internal void mutex_init(BlockingMutex *m) { } - void mutex_destroy(BlockingMutex *m) { + gb_internal void mutex_destroy(BlockingMutex *m) { } - void mutex_lock(BlockingMutex *m) { + gb_internal void mutex_lock(BlockingMutex *m) { AcquireSRWLockExclusive(&m->srwlock); } - bool mutex_try_lock(BlockingMutex *m) { + gb_internal bool mutex_try_lock(BlockingMutex *m) { return !!TryAcquireSRWLockExclusive(&m->srwlock); } - void mutex_unlock(BlockingMutex *m) { + gb_internal void mutex_unlock(BlockingMutex *m) { ReleaseSRWLockExclusive(&m->srwlock); } struct RecursiveMutex { CRITICAL_SECTION win32_critical_section; }; - void mutex_init(RecursiveMutex *m) { + gb_internal void mutex_init(RecursiveMutex *m) { InitializeCriticalSection(&m->win32_critical_section); } - void mutex_destroy(RecursiveMutex *m) { + gb_internal void mutex_destroy(RecursiveMutex *m) { DeleteCriticalSection(&m->win32_critical_section); } - void mutex_lock(RecursiveMutex *m) { + gb_internal void mutex_lock(RecursiveMutex *m) { EnterCriticalSection(&m->win32_critical_section); } - bool mutex_try_lock(RecursiveMutex *m) { + gb_internal bool mutex_try_lock(RecursiveMutex *m) { return TryEnterCriticalSection(&m->win32_critical_section) != 0; } - void mutex_unlock(RecursiveMutex *m) { + gb_internal void mutex_unlock(RecursiveMutex *m) { LeaveCriticalSection(&m->win32_critical_section); } @@ -143,16 +143,16 @@ struct MutexGuard { void *win32_handle; }; - void semaphore_init(Semaphore *s) { + gb_internal void semaphore_init(Semaphore *s) { s->win32_handle = CreateSemaphoreA(NULL, 0, I32_MAX, NULL); } - void semaphore_destroy(Semaphore *s) { + gb_internal void semaphore_destroy(Semaphore *s) { CloseHandle(s->win32_handle); } - void semaphore_post(Semaphore *s, i32 count) { + gb_internal void semaphore_post(Semaphore *s, i32 count) { ReleaseSemaphore(s->win32_handle, count, NULL); } - void semaphore_wait(Semaphore *s) { + gb_internal void semaphore_wait(Semaphore *s) { WaitForSingleObjectEx(s->win32_handle, INFINITE, FALSE); } @@ -160,20 +160,20 @@ struct MutexGuard { CONDITION_VARIABLE cond; }; - void condition_init(Condition *c) { + gb_internal void condition_init(Condition *c) { } - void condition_destroy(Condition *c) { + gb_internal void condition_destroy(Condition *c) { } - void condition_broadcast(Condition *c) { + gb_internal void condition_broadcast(Condition *c) { WakeAllConditionVariable(&c->cond); } - void condition_signal(Condition *c) { + gb_internal void condition_signal(Condition *c) { WakeConditionVariable(&c->cond); } - void condition_wait(Condition *c, BlockingMutex *m) { + gb_internal void condition_wait(Condition *c, BlockingMutex *m) { SleepConditionVariableSRW(&c->cond, &m->srwlock, INFINITE, 0); } - void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms) { + gb_internal void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms) { SleepConditionVariableSRW(&c->cond, &m->srwlock, timeout_in_ms, 0); } @@ -181,19 +181,19 @@ struct MutexGuard { struct BlockingMutex { pthread_mutex_t pthread_mutex; }; - void mutex_init(BlockingMutex *m) { + gb_internal void mutex_init(BlockingMutex *m) { pthread_mutex_init(&m->pthread_mutex, nullptr); } - void mutex_destroy(BlockingMutex *m) { + gb_internal void mutex_destroy(BlockingMutex *m) { pthread_mutex_destroy(&m->pthread_mutex); } - void mutex_lock(BlockingMutex *m) { + gb_internal void mutex_lock(BlockingMutex *m) { pthread_mutex_lock(&m->pthread_mutex); } - bool mutex_try_lock(BlockingMutex *m) { + gb_internal bool mutex_try_lock(BlockingMutex *m) { return pthread_mutex_trylock(&m->pthread_mutex) == 0; } - void mutex_unlock(BlockingMutex *m) { + gb_internal void mutex_unlock(BlockingMutex *m) { pthread_mutex_unlock(&m->pthread_mutex); } @@ -201,21 +201,21 @@ struct MutexGuard { pthread_mutex_t pthread_mutex; pthread_mutexattr_t pthread_mutexattr; }; - void mutex_init(RecursiveMutex *m) { + gb_internal void mutex_init(RecursiveMutex *m) { pthread_mutexattr_init(&m->pthread_mutexattr); pthread_mutexattr_settype(&m->pthread_mutexattr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&m->pthread_mutex, &m->pthread_mutexattr); } - void mutex_destroy(RecursiveMutex *m) { + gb_internal void mutex_destroy(RecursiveMutex *m) { pthread_mutex_destroy(&m->pthread_mutex); } - void mutex_lock(RecursiveMutex *m) { + gb_internal void mutex_lock(RecursiveMutex *m) { pthread_mutex_lock(&m->pthread_mutex); } - bool mutex_try_lock(RecursiveMutex *m) { + gb_internal bool mutex_try_lock(RecursiveMutex *m) { return pthread_mutex_trylock(&m->pthread_mutex) == 0; } - void mutex_unlock(RecursiveMutex *m) { + gb_internal void mutex_unlock(RecursiveMutex *m) { pthread_mutex_unlock(&m->pthread_mutex); } @@ -224,18 +224,18 @@ struct MutexGuard { semaphore_t osx_handle; }; - void semaphore_init (Semaphore *s) { semaphore_create(mach_task_self(), &s->osx_handle, SYNC_POLICY_FIFO, 0); } - void semaphore_destroy(Semaphore *s) { semaphore_destroy(mach_task_self(), s->osx_handle); } - void semaphore_post (Semaphore *s, i32 count) { while (count --> 0) semaphore_signal(s->osx_handle); } - void semaphore_wait (Semaphore *s) { semaphore_wait(s->osx_handle); } + gb_internal void semaphore_init (Semaphore *s) { semaphore_create(mach_task_self(), &s->osx_handle, SYNC_POLICY_FIFO, 0); } + gb_internal void semaphore_destroy(Semaphore *s) { semaphore_destroy(mach_task_self(), s->osx_handle); } + gb_internal void semaphore_post (Semaphore *s, i32 count) { while (count --> 0) semaphore_signal(s->osx_handle); } + gb_internal void semaphore_wait (Semaphore *s) { semaphore_wait(s->osx_handle); } #elif defined(GB_SYSTEM_UNIX) struct Semaphore { sem_t unix_handle; }; - void semaphore_init (Semaphore *s) { sem_init(&s->unix_handle, 0, 0); } - void semaphore_destroy(Semaphore *s) { sem_destroy(&s->unix_handle); } - void semaphore_post (Semaphore *s, i32 count) { while (count --> 0) sem_post(&s->unix_handle); } + gb_internal void semaphore_init (Semaphore *s) { sem_init(&s->unix_handle, 0, 0); } + gb_internal void semaphore_destroy(Semaphore *s) { sem_destroy(&s->unix_handle); } + gb_internal void semaphore_post (Semaphore *s, i32 count) { while (count --> 0) sem_post(&s->unix_handle); } void semaphore_wait (Semaphore *s) { int i; do { i = sem_wait(&s->unix_handle); } while (i == -1 && errno == EINTR); } #else #error Implement Semaphore for this platform @@ -246,22 +246,22 @@ struct MutexGuard { pthread_cond_t pthread_cond; }; - void condition_init(Condition *c) { + gb_internal void condition_init(Condition *c) { pthread_cond_init(&c->pthread_cond, NULL); } - void condition_destroy(Condition *c) { + gb_internal void condition_destroy(Condition *c) { pthread_cond_destroy(&c->pthread_cond); } - void condition_broadcast(Condition *c) { + gb_internal void condition_broadcast(Condition *c) { pthread_cond_broadcast(&c->pthread_cond); } - void condition_signal(Condition *c) { + gb_internal void condition_signal(Condition *c) { pthread_cond_signal(&c->pthread_cond); } - void condition_wait(Condition *c, BlockingMutex *m) { + gb_internal void condition_wait(Condition *c, BlockingMutex *m) { pthread_cond_wait(&c->pthread_cond, &m->pthread_mutex); } - void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms) { + gb_internal void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms) { struct timespec abstime = {}; abstime.tv_sec = timeout_in_ms/1000; abstime.tv_nsec = cast(long)(timeout_in_ms%1000)*1e6; @@ -279,7 +279,7 @@ struct Barrier { isize thread_count; }; -void barrier_init(Barrier *b, isize thread_count) { +gb_internal void barrier_init(Barrier *b, isize thread_count) { mutex_init(&b->mutex); condition_init(&b->cond); b->index = 0; @@ -287,13 +287,13 @@ void barrier_init(Barrier *b, isize thread_count) { b->thread_count = 0; } -void barrier_destroy(Barrier *b) { +gb_internal void barrier_destroy(Barrier *b) { condition_destroy(&b->cond); mutex_destroy(&b->mutex); } // Returns true if it is the leader -bool barrier_wait(Barrier *b) { +gb_internal bool barrier_wait(Barrier *b) { mutex_lock(&b->mutex); defer (mutex_unlock(&b->mutex)); isize local_gen = b->generation_id; @@ -313,7 +313,7 @@ bool barrier_wait(Barrier *b) { -u32 thread_current_id(void) { +gb_internal u32 thread_current_id(void) { u32 thread_id; #if defined(GB_SYSTEM_WINDOWS) #if defined(GB_ARCH_32_BIT) && defined(GB_CPU_X86) @@ -340,7 +340,7 @@ u32 thread_current_id(void) { } -gb_inline void yield_thread(void) { +gb_internal gb_inline void yield_thread(void) { #if defined(GB_SYSTEM_WINDOWS) _mm_pause(); #elif defined(GB_SYSTEM_OSX) @@ -358,7 +358,7 @@ gb_inline void yield_thread(void) { #endif } -gb_inline void yield(void) { +gb_internal gb_inline void yield(void) { #if defined(GB_SYSTEM_WINDOWS) YieldProcessor(); #else @@ -367,7 +367,7 @@ gb_inline void yield(void) { } -void thread_init(Thread *t) { +gb_internal void thread_init(Thread *t) { gb_zero_item(t); #if defined(GB_SYSTEM_WINDOWS) t->win32_handle = INVALID_HANDLE_VALUE; @@ -378,27 +378,27 @@ void thread_init(Thread *t) { semaphore_init(t->semaphore); } -void thread_destroy(Thread *t) { +gb_internal void thread_destroy(Thread *t) { thread_join(t); semaphore_destroy(t->semaphore); gb_free(heap_allocator(), t->semaphore); } -void gb__thread_run(Thread *t) { +gb_internal void gb__thread_run(Thread *t) { semaphore_release(t->semaphore); t->return_value = t->proc(t); } #if defined(GB_SYSTEM_WINDOWS) - DWORD __stdcall internal_thread_proc(void *arg) { + gb_internal DWORD __stdcall internal_thread_proc(void *arg) { Thread *t = cast(Thread *)arg; t->is_running.store(true); gb__thread_run(t); return 0; } #else - void *internal_thread_proc(void *arg) { + gb_internal void *internal_thread_proc(void *arg) { #if (GB_SYSTEM_LINUX) // NOTE: Don't permit any signal delivery to threads on Linux. sigset_t mask = {}; @@ -413,9 +413,9 @@ void gb__thread_run(Thread *t) { } #endif -void thread_start(Thread *t, ThreadProc *proc, void *user_data) { thread_start_with_stack(t, proc, user_data, 0); } +gb_internal void thread_start(Thread *t, ThreadProc *proc, void *user_data) { thread_start_with_stack(t, proc, user_data, 0); } -void thread_start_with_stack(Thread *t, ThreadProc *proc, void *user_data, isize stack_size) { +gb_internal void thread_start_with_stack(Thread *t, ThreadProc *proc, void *user_data, isize stack_size) { GB_ASSERT(!t->is_running.load()); GB_ASSERT(proc != NULL); t->proc = proc; @@ -441,7 +441,7 @@ void thread_start_with_stack(Thread *t, ThreadProc *proc, void *user_data, isize semaphore_wait(t->semaphore); } -void thread_join(Thread *t) { +gb_internal void thread_join(Thread *t) { if (!t->is_running.load()) { return; } @@ -457,9 +457,9 @@ void thread_join(Thread *t) { t->is_running.store(false); } -bool thread_is_running(Thread const *t) { return t->is_running.load(); } +gb_internal bool thread_is_running(Thread const *t) { return t->is_running.load(); } -void thread_set_name(Thread *t, char const *name) { +gb_internal void thread_set_name(Thread *t, char const *name) { #if defined(GB_COMPILER_MSVC) #pragma pack(push, 8) typedef struct { diff --git a/src/timings.cpp b/src/timings.cpp index 72abe7ea1..baa8b80da 100644 --- a/src/timings.cpp +++ b/src/timings.cpp @@ -13,13 +13,13 @@ struct Timings { #if defined(GB_SYSTEM_WINDOWS) -u64 win32_time_stamp_time_now(void) { +gb_internal u64 win32_time_stamp_time_now(void) { LARGE_INTEGER counter; QueryPerformanceCounter(&counter); return counter.QuadPart; } -u64 win32_time_stamp__freq(void) { +gb_internal u64 win32_time_stamp__freq(void) { gb_local_persist LARGE_INTEGER win32_perf_count_freq = {0}; if (!win32_perf_count_freq.QuadPart) { QueryPerformanceFrequency(&win32_perf_count_freq); @@ -33,11 +33,11 @@ u64 win32_time_stamp__freq(void) { #include -u64 osx_time_stamp_time_now(void) { +gb_internal u64 osx_time_stamp_time_now(void) { return mach_absolute_time(); } -u64 osx_time_stamp__freq(void) { +gb_internal u64 osx_time_stamp__freq(void) { mach_timebase_info_data_t data; data.numer = 0; data.denom = 0; @@ -55,14 +55,14 @@ u64 osx_time_stamp__freq(void) { #include -u64 unix_time_stamp_time_now(void) { +gb_internal u64 unix_time_stamp_time_now(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (ts.tv_sec * 1000000000) + ts.tv_nsec; } -u64 unix_time_stamp__freq(void) { +gb_internal u64 unix_time_stamp__freq(void) { gb_local_persist u64 freq = 0; if (freq == 0) { @@ -80,7 +80,7 @@ u64 unix_time_stamp__freq(void) { #error Implement system #endif -u64 time_stamp_time_now(void) { +gb_internal u64 time_stamp_time_now(void) { #if defined(GB_SYSTEM_WINDOWS) return win32_time_stamp_time_now(); #elif defined(GB_SYSTEM_OSX) @@ -92,7 +92,7 @@ u64 time_stamp_time_now(void) { #endif } -u64 time_stamp__freq(void) { +gb_internal u64 time_stamp__freq(void) { #if defined(GB_SYSTEM_WINDOWS) return win32_time_stamp__freq(); #elif defined(GB_SYSTEM_OSX) @@ -104,44 +104,44 @@ u64 time_stamp__freq(void) { #endif } -TimeStamp make_time_stamp(String const &label) { +gb_internal TimeStamp make_time_stamp(String const &label) { TimeStamp ts = {0}; ts.start = time_stamp_time_now(); ts.label = label; return ts; } -void timings_init(Timings *t, String const &label, isize buffer_size) { +gb_internal void timings_init(Timings *t, String const &label, isize buffer_size) { array_init(&t->sections, heap_allocator(), 0, buffer_size); t->total = make_time_stamp(label); t->freq = time_stamp__freq(); } -void timings_destroy(Timings *t) { +gb_internal void timings_destroy(Timings *t) { array_free(&t->sections); } -void timings__stop_current_section(Timings *t) { +gb_internal void timings__stop_current_section(Timings *t) { if (t->sections.count > 0) { t->sections[t->sections.count-1].finish = time_stamp_time_now(); } } -void timings_start_section(Timings *t, String const &label) { +gb_internal void timings_start_section(Timings *t, String const &label) { timings__stop_current_section(t); array_add(&t->sections, make_time_stamp(label)); } -f64 time_stamp_as_s(TimeStamp const &ts, u64 freq) { +gb_internal f64 time_stamp_as_s(TimeStamp const &ts, u64 freq) { GB_ASSERT_MSG(ts.finish >= ts.start, "time_stamp_as_ms - %.*s", LIT(ts.label)); return cast(f64)(ts.finish - ts.start) / cast(f64)freq; } -f64 time_stamp_as_ms(TimeStamp const &ts, u64 freq) { +gb_internal f64 time_stamp_as_ms(TimeStamp const &ts, u64 freq) { return 1000.0*time_stamp_as_s(ts, freq); } -f64 time_stamp_as_us(TimeStamp const &ts, u64 freq) { +gb_internal f64 time_stamp_as_us(TimeStamp const &ts, u64 freq) { return 1000000.0*time_stamp_as_s(ts, freq); } @@ -160,7 +160,7 @@ enum TimingUnit { char const *timing_unit_strings[TimingUnit_COUNT] = {"s", "ms", "us"}; -f64 time_stamp(TimeStamp const &ts, u64 freq, TimingUnit unit) { +gb_internal f64 time_stamp(TimeStamp const &ts, u64 freq, TimingUnit unit) { switch (unit) { case TimingUnit_Millisecond: return time_stamp_as_ms(ts, freq); case TimingUnit_Microsecond: return time_stamp_as_us(ts, freq); @@ -169,7 +169,7 @@ f64 time_stamp(TimeStamp const &ts, u64 freq, TimingUnit unit) { } } -void timings_print_all(Timings *t, TimingUnit unit = TimingUnit_Millisecond, bool timings_are_finalized = false) { +gb_internal void timings_print_all(Timings *t, TimingUnit unit = TimingUnit_Millisecond, bool timings_are_finalized = false) { isize const SPACES_LEN = 256; char SPACES[SPACES_LEN+1] = {0}; gb_memset(SPACES, ' ', SPACES_LEN); diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 40bc5c220..547a864fb 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -151,10 +151,10 @@ gb_global isize max_keyword_size = 11; gb_global bool keyword_indices[16] = {}; -gb_inline u32 keyword_hash(u8 const *text, isize len) { +gb_internal gb_inline u32 keyword_hash(u8 const *text, isize len) { return fnv32a(text, len); } -void add_keyword_hash_entry(String const &s, TokenKind kind) { +gb_internal void add_keyword_hash_entry(String const &s, TokenKind kind) { max_keyword_size = gb_max(max_keyword_size, s.len); keyword_indices[s.len] = true; @@ -169,7 +169,7 @@ void add_keyword_hash_entry(String const &s, TokenKind kind) { entry->kind = kind; entry->text = s; } -void init_keyword_hash_table(void) { +gb_internal void init_keyword_hash_table(void) { for (i32 kind = Token__KeywordBegin+1; kind < Token__KeywordEnd; kind++) { add_keyword_hash_entry(token_strings[kind], cast(TokenKind)kind); } @@ -191,8 +191,8 @@ void init_keyword_hash_table(void) { gb_global Array global_file_path_strings; // index is file id gb_global Array global_files; // index is file id -String get_file_path_string(i32 index); -struct AstFile *thread_safe_get_ast_file_from_id(i32 index); +gb_internal String get_file_path_string(i32 index); +gb_internal struct AstFile *thread_safe_get_ast_file_from_id(i32 index); struct TokenPos { i32 file_id; @@ -201,7 +201,7 @@ struct TokenPos { i32 column; // starting at 1 }; -i32 token_pos_cmp(TokenPos const &a, TokenPos const &b) { +gb_internal i32 token_pos_cmp(TokenPos const &a, TokenPos const &b) { if (a.offset != b.offset) { return (a.offset < b.offset) ? -1 : +1; } @@ -214,12 +214,12 @@ i32 token_pos_cmp(TokenPos const &a, TokenPos const &b) { return string_compare(get_file_path_string(a.file_id), get_file_path_string(b.file_id)); } -bool operator==(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) == 0; } -bool operator!=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) != 0; } -bool operator< (TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) < 0; } -bool operator<=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) <= 0; } -bool operator> (TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) > 0; } -bool operator>=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) >= 0; } +gb_internal gb_inline bool operator==(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) == 0; } +gb_internal gb_inline bool operator!=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) != 0; } +gb_internal gb_inline bool operator< (TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) < 0; } +gb_internal gb_inline bool operator<=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) <= 0; } +gb_internal gb_inline bool operator> (TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) > 0; } +gb_internal gb_inline bool operator>=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) >= 0; } TokenPos token_pos_add_column(TokenPos pos) { @@ -243,36 +243,36 @@ struct Token { Token empty_token = {Token_Invalid}; Token blank_token = {Token_Ident, 0, {cast(u8 *)"_", 1}}; -Token make_token_ident(String s) { +gb_internal Token make_token_ident(String s) { Token t = {Token_Ident, 0, s}; return t; } -Token make_token_ident(char const *s) { +gb_internal Token make_token_ident(char const *s) { Token t = {Token_Ident, 0, make_string_c(s)}; return t; } -bool token_is_newline(Token const &tok) { +gb_internal bool token_is_newline(Token const &tok) { return tok.kind == Token_Semicolon && tok.string == "\n"; } -gb_inline bool token_is_literal(TokenKind t) { +gb_internal gb_inline bool token_is_literal(TokenKind t) { return gb_is_between(t, Token__LiteralBegin+1, Token__LiteralEnd-1); } -gb_inline bool token_is_operator(TokenKind t) { +gb_internal gb_inline bool token_is_operator(TokenKind t) { return gb_is_between(t, Token__OperatorBegin+1, Token__OperatorEnd-1); } -gb_inline bool token_is_keyword(TokenKind t) { +gb_internal gb_inline bool token_is_keyword(TokenKind t) { return gb_is_between(t, Token__KeywordBegin+1, Token__KeywordEnd-1); } -gb_inline bool token_is_comparison(TokenKind t) { +gb_internal gb_inline bool token_is_comparison(TokenKind t) { return gb_is_between(t, Token__ComparisonBegin+1, Token__ComparisonEnd-1); } -gb_inline bool token_is_shift(TokenKind t) { +gb_internal gb_inline bool token_is_shift(TokenKind t) { return t == Token_Shl || t == Token_Shr; } -gb_inline void print_token(Token t) { gb_printf("%.*s\n", LIT(t.string)); } +gb_internal gb_inline void print_token(Token t) { gb_printf("%.*s\n", LIT(t.string)); } #include "error.cpp" @@ -309,7 +309,7 @@ struct Tokenizer { }; -void tokenizer_err(Tokenizer *t, char const *msg, ...) { +gb_internal void tokenizer_err(Tokenizer *t, char const *msg, ...) { va_list va; i32 column = t->column_minus_one+1; if (column < 1) { @@ -328,7 +328,7 @@ void tokenizer_err(Tokenizer *t, char const *msg, ...) { t->error_count++; } -void tokenizer_err(Tokenizer *t, TokenPos const &pos, char const *msg, ...) { +gb_internal void tokenizer_err(Tokenizer *t, TokenPos const &pos, char const *msg, ...) { va_list va; i32 column = t->column_minus_one+1; if (column < 1) { @@ -342,7 +342,7 @@ void tokenizer_err(Tokenizer *t, TokenPos const &pos, char const *msg, ...) { t->error_count++; } -void advance_to_next_rune(Tokenizer *t) { +gb_internal void advance_to_next_rune(Tokenizer *t) { if (t->curr_rune == '\n') { t->column_minus_one = -1; t->line_count++; @@ -372,7 +372,7 @@ void advance_to_next_rune(Tokenizer *t) { } } -void init_tokenizer_with_data(Tokenizer *t, String const &fullpath, void const *data, isize size) { +gb_internal void init_tokenizer_with_data(Tokenizer *t, String const &fullpath, void const *data, isize size) { t->fullpath = fullpath; t->line_count = 1; @@ -386,7 +386,7 @@ void init_tokenizer_with_data(Tokenizer *t, String const &fullpath, void const * } } -TokenizerInitError loaded_file_error_map_to_tokenizer[LoadedFile_COUNT] = { +gb_global TokenizerInitError loaded_file_error_map_to_tokenizer[LoadedFile_COUNT] = { TokenizerInit_None, /*LoadedFile_None*/ TokenizerInit_Empty, /*LoadedFile_Empty*/ TokenizerInit_FileTooLarge, /*LoadedFile_FileTooLarge*/ @@ -395,7 +395,7 @@ TokenizerInitError loaded_file_error_map_to_tokenizer[LoadedFile_COUNT] = { TokenizerInit_Permission, /*LoadedFile_Permission*/ }; -TokenizerInitError init_tokenizer_from_fullpath(Tokenizer *t, String const &fullpath, bool copy_file_contents) { +gb_internal TokenizerInitError init_tokenizer_from_fullpath(Tokenizer *t, String const &fullpath, bool copy_file_contents) { LoadedFileError file_err = load_file_32( alloc_cstring(temporary_allocator(), fullpath), &t->loaded_file, @@ -416,7 +416,7 @@ TokenizerInitError init_tokenizer_from_fullpath(Tokenizer *t, String const &full return err; } -gb_inline i32 digit_value(Rune r) { +gb_internal gb_inline i32 digit_value(Rune r) { switch (r) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return r - '0'; @@ -428,20 +428,20 @@ gb_inline i32 digit_value(Rune r) { return 16; // NOTE(bill): Larger than highest possible } -gb_inline void scan_mantissa(Tokenizer *t, i32 base) { +gb_internal gb_inline void scan_mantissa(Tokenizer *t, i32 base) { while (digit_value(t->curr_rune) < base || t->curr_rune == '_') { advance_to_next_rune(t); } } -u8 peek_byte(Tokenizer *t, isize offset=0) { +gb_internal u8 peek_byte(Tokenizer *t, isize offset=0) { if (t->read_curr+offset < t->end) { return t->read_curr[offset]; } return 0; } -void scan_number_to_token(Tokenizer *t, Token *token, bool seen_decimal_point) { +gb_internal void scan_number_to_token(Tokenizer *t, Token *token, bool seen_decimal_point) { token->kind = Token_Integer; token->string = {t->curr, 1}; token->pos.file_id = t->curr_file_id; @@ -566,7 +566,7 @@ end: } -bool scan_escape(Tokenizer *t) { +gb_internal bool scan_escape(Tokenizer *t) { isize len = 0; u32 base = 0, max = 0, x = 0; @@ -633,13 +633,13 @@ bool scan_escape(Tokenizer *t) { } -gb_inline void tokenizer_skip_line(Tokenizer *t) { +gb_internal gb_inline void tokenizer_skip_line(Tokenizer *t) { while (t->curr_rune != '\n' && t->curr_rune != GB_RUNE_EOF) { advance_to_next_rune(t); } } -gb_inline void tokenizer_skip_whitespace(Tokenizer *t, bool on_newline) { +gb_internal gb_inline void tokenizer_skip_whitespace(Tokenizer *t, bool on_newline) { if (on_newline) { for (;;) { switch (t->curr_rune) { @@ -666,7 +666,7 @@ gb_inline void tokenizer_skip_whitespace(Tokenizer *t, bool on_newline) { } } -void tokenizer_get_token(Tokenizer *t, Token *token, int repeat=0) { +gb_internal void tokenizer_get_token(Tokenizer *t, Token *token, int repeat=0) { tokenizer_skip_whitespace(t, t->insert_semicolon); token->kind = Token_Invalid; diff --git a/src/types.cpp b/src/types.cpp index 9bdbf8d86..7b6942525 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -2571,20 +2571,6 @@ bool lookup_subtype_polymorphic_selection(Type *dst, Type *src, Selection *sel) - -Type *strip_type_aliasing(Type *x) { - if (x == nullptr) { - return x; - } - if (x->kind == Type_Named) { - Entity *e = x->Named.type_name; - if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) { - return x->Named.base; - } - } - return x; -} - bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names); bool are_types_identical(Type *x, Type *y) { @@ -2605,193 +2591,156 @@ bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names) { return false; } - x = strip_type_aliasing(x); - y = strip_type_aliasing(y); + if (x->kind == Type_Named) { + Entity *e = x->Named.type_name; + if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) { + x = x->Named.base; + } + } + if (y->kind == Type_Named) { + Entity *e = y->Named.type_name; + if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) { + y = y->Named.base; + } + } + if (x->kind != y->kind) { + return false; + } switch (x->kind) { case Type_Generic: - if (y->kind == Type_Generic) { - return are_types_identical(x->Generic.specialized, y->Generic.specialized); - } - break; + return are_types_identical(x->Generic.specialized, y->Generic.specialized); case Type_Basic: - if (y->kind == Type_Basic) { - return x->Basic.kind == y->Basic.kind; - } - break; + return x->Basic.kind == y->Basic.kind; case Type_EnumeratedArray: - if (y->kind == Type_EnumeratedArray) { - return are_types_identical(x->EnumeratedArray.index, y->EnumeratedArray.index) && - are_types_identical(x->EnumeratedArray.elem, y->EnumeratedArray.elem); - } - break; + return are_types_identical(x->EnumeratedArray.index, y->EnumeratedArray.index) && + are_types_identical(x->EnumeratedArray.elem, y->EnumeratedArray.elem); case Type_Array: - if (y->kind == Type_Array) { - return (x->Array.count == y->Array.count) && are_types_identical(x->Array.elem, y->Array.elem); - } - break; + return (x->Array.count == y->Array.count) && are_types_identical(x->Array.elem, y->Array.elem); case Type_Matrix: - if (y->kind == Type_Matrix) { - return x->Matrix.row_count == y->Matrix.row_count && - x->Matrix.column_count == y->Matrix.column_count && - are_types_identical(x->Matrix.elem, y->Matrix.elem); - } - break; + return x->Matrix.row_count == y->Matrix.row_count && + x->Matrix.column_count == y->Matrix.column_count && + are_types_identical(x->Matrix.elem, y->Matrix.elem); case Type_DynamicArray: - if (y->kind == Type_DynamicArray) { - return are_types_identical(x->DynamicArray.elem, y->DynamicArray.elem); - } - break; + return are_types_identical(x->DynamicArray.elem, y->DynamicArray.elem); case Type_Slice: - if (y->kind == Type_Slice) { - return are_types_identical(x->Slice.elem, y->Slice.elem); - } - break; + return are_types_identical(x->Slice.elem, y->Slice.elem); case Type_BitSet: - if (y->kind == Type_BitSet) { - return are_types_identical(x->BitSet.elem, y->BitSet.elem) && - are_types_identical(x->BitSet.underlying, y->BitSet.underlying) && - x->BitSet.lower == y->BitSet.lower && - x->BitSet.upper == y->BitSet.upper; - } - break; + return are_types_identical(x->BitSet.elem, y->BitSet.elem) && + are_types_identical(x->BitSet.underlying, y->BitSet.underlying) && + x->BitSet.lower == y->BitSet.lower && + x->BitSet.upper == y->BitSet.upper; case Type_Enum: return x == y; // NOTE(bill): All enums are unique case Type_Union: - if (y->kind == Type_Union) { - if (x->Union.variants.count == y->Union.variants.count && - x->Union.custom_align == y->Union.custom_align && - x->Union.kind == y->Union.kind) { - // NOTE(bill): zeroth variant is nullptr - for_array(i, x->Union.variants) { - if (!are_types_identical(x->Union.variants[i], y->Union.variants[i])) { - return false; - } + if (x->Union.variants.count == y->Union.variants.count && + x->Union.custom_align == y->Union.custom_align && + x->Union.kind == y->Union.kind) { + // NOTE(bill): zeroth variant is nullptr + for_array(i, x->Union.variants) { + if (!are_types_identical(x->Union.variants[i], y->Union.variants[i])) { + return false; } - return true; } + return true; } break; case Type_Struct: - if (y->kind == Type_Struct) { - if (x->Struct.is_raw_union == y->Struct.is_raw_union && - x->Struct.fields.count == y->Struct.fields.count && - x->Struct.is_packed == y->Struct.is_packed && - x->Struct.custom_align == y->Struct.custom_align && - x->Struct.soa_kind == y->Struct.soa_kind && - x->Struct.soa_count == y->Struct.soa_count && - are_types_identical(x->Struct.soa_elem, y->Struct.soa_elem)) { - // TODO(bill); Fix the custom alignment rule - for_array(i, x->Struct.fields) { - Entity *xf = x->Struct.fields[i]; - Entity *yf = y->Struct.fields[i]; - if (xf->kind != yf->kind) { - return false; - } - if (!are_types_identical(xf->type, yf->type)) { - return false; - } - if (xf->token.string != yf->token.string) { - return false; - } - if (x->Struct.tags[i] != y->Struct.tags[i]) { - return false; - } - u64 xf_flags = (xf->flags&EntityFlags_IsSubtype); - u64 yf_flags = (yf->flags&EntityFlags_IsSubtype); - if (xf_flags != yf_flags) { - return false; - } + if (x->Struct.is_raw_union == y->Struct.is_raw_union && + x->Struct.fields.count == y->Struct.fields.count && + x->Struct.is_packed == y->Struct.is_packed && + x->Struct.custom_align == y->Struct.custom_align && + x->Struct.soa_kind == y->Struct.soa_kind && + x->Struct.soa_count == y->Struct.soa_count && + are_types_identical(x->Struct.soa_elem, y->Struct.soa_elem)) { + // TODO(bill); Fix the custom alignment rule + for_array(i, x->Struct.fields) { + Entity *xf = x->Struct.fields[i]; + Entity *yf = y->Struct.fields[i]; + if (xf->kind != yf->kind) { + return false; + } + if (!are_types_identical(xf->type, yf->type)) { + return false; + } + if (xf->token.string != yf->token.string) { + return false; + } + if (x->Struct.tags[i] != y->Struct.tags[i]) { + return false; + } + u64 xf_flags = (xf->flags&EntityFlags_IsSubtype); + u64 yf_flags = (yf->flags&EntityFlags_IsSubtype); + if (xf_flags != yf_flags) { + return false; } - return true; } + return true; } break; case Type_Pointer: - if (y->kind == Type_Pointer) { - return are_types_identical(x->Pointer.elem, y->Pointer.elem); - } - break; + return are_types_identical(x->Pointer.elem, y->Pointer.elem); case Type_MultiPointer: - if (y->kind == Type_MultiPointer) { - return are_types_identical(x->MultiPointer.elem, y->MultiPointer.elem); - } - break; + return are_types_identical(x->MultiPointer.elem, y->MultiPointer.elem); case Type_SoaPointer: - if (y->kind == Type_SoaPointer) { - return are_types_identical(x->SoaPointer.elem, y->SoaPointer.elem); - } - break; + return are_types_identical(x->SoaPointer.elem, y->SoaPointer.elem); case Type_Named: - if (y->kind == Type_Named) { - return x->Named.type_name == y->Named.type_name; - } - break; + return x->Named.type_name == y->Named.type_name; case Type_Tuple: - if (y->kind == Type_Tuple) { - if (x->Tuple.variables.count == y->Tuple.variables.count && - x->Tuple.is_packed == y->Tuple.is_packed) { - for_array(i, x->Tuple.variables) { - Entity *xe = x->Tuple.variables[i]; - Entity *ye = y->Tuple.variables[i]; - if (xe->kind != ye->kind || !are_types_identical(xe->type, ye->type)) { - return false; - } - if (check_tuple_names) { - if (xe->token.string != ye->token.string) { - return false; - } - } - if (xe->kind == Entity_Constant && !compare_exact_values(Token_CmpEq, xe->Constant.value, ye->Constant.value)) { - // NOTE(bill): This is needed for polymorphic procedures + if (x->Tuple.variables.count == y->Tuple.variables.count && + x->Tuple.is_packed == y->Tuple.is_packed) { + for_array(i, x->Tuple.variables) { + Entity *xe = x->Tuple.variables[i]; + Entity *ye = y->Tuple.variables[i]; + if (xe->kind != ye->kind || !are_types_identical(xe->type, ye->type)) { + return false; + } + if (check_tuple_names) { + if (xe->token.string != ye->token.string) { return false; } } - return true; + if (xe->kind == Entity_Constant && !compare_exact_values(Token_CmpEq, xe->Constant.value, ye->Constant.value)) { + // NOTE(bill): This is needed for polymorphic procedures + return false; + } } + return true; } break; case Type_Proc: - if (y->kind == Type_Proc) { - return x->Proc.calling_convention == y->Proc.calling_convention && - x->Proc.c_vararg == y->Proc.c_vararg && - x->Proc.variadic == y->Proc.variadic && - x->Proc.diverging == y->Proc.diverging && - x->Proc.optional_ok == y->Proc.optional_ok && - are_types_identical(x->Proc.params, y->Proc.params) && - are_types_identical(x->Proc.results, y->Proc.results); - } - break; + return x->Proc.calling_convention == y->Proc.calling_convention && + x->Proc.c_vararg == y->Proc.c_vararg && + x->Proc.variadic == y->Proc.variadic && + x->Proc.diverging == y->Proc.diverging && + x->Proc.optional_ok == y->Proc.optional_ok && + are_types_identical(x->Proc.params, y->Proc.params) && + are_types_identical(x->Proc.results, y->Proc.results); case Type_Map: - if (y->kind == Type_Map) { - return are_types_identical(x->Map.key, y->Map.key) && - are_types_identical(x->Map.value, y->Map.value); - } - break; + return are_types_identical(x->Map.key, y->Map.key) && + are_types_identical(x->Map.value, y->Map.value); case Type_SimdVector: - if (y->kind == Type_SimdVector) { - if (x->SimdVector.count == y->SimdVector.count) { - return are_types_identical(x->SimdVector.elem, y->SimdVector.elem); - } + if (x->SimdVector.count == y->SimdVector.count) { + return are_types_identical(x->SimdVector.elem, y->SimdVector.elem); } break; } diff --git a/src/unicode.cpp b/src/unicode.cpp index e33fb793b..c244a323c 100644 --- a/src/unicode.cpp +++ b/src/unicode.cpp @@ -7,7 +7,7 @@ extern "C" { #pragma warning(pop) -bool rune_is_letter(Rune r) { +gb_internal bool rune_is_letter(Rune r) { if (r < 0x80) { if (r == '_') { return true; @@ -25,14 +25,14 @@ bool rune_is_letter(Rune r) { return false; } -bool rune_is_digit(Rune r) { +gb_internal bool rune_is_digit(Rune r) { if (r < 0x80) { return (cast(u32)r - '0') < 10; } return utf8proc_category(r) == UTF8PROC_CATEGORY_ND; } -bool rune_is_letter_or_digit(Rune r) { +gb_internal bool rune_is_letter_or_digit(Rune r) { if (r < 0x80) { if (r == '_') { return true; @@ -55,7 +55,7 @@ bool rune_is_letter_or_digit(Rune r) { return false; } -bool rune_is_whitespace(Rune r) { +gb_internal bool rune_is_whitespace(Rune r) { switch (r) { case ' ': case '\t': @@ -99,7 +99,7 @@ gb_global Utf8AcceptRange const global__utf8_accept_ranges[] = { }; -isize utf8_decode(u8 const *str, isize str_len, Rune *codepoint_out) { +gb_internal isize utf8_decode(u8 const *str, isize str_len, Rune *codepoint_out) { isize width = 0; Rune codepoint = GB_RUNE_INVALID; -- cgit v1.2.3 From c1f5be24e28c41efbbbe6d116d533b55d48bbf82 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 22:49:10 +0000 Subject: Remove dead code in the compiler --- build.bat | 1 + src/build_settings.cpp | 6 +- src/check_decl.cpp | 10 - src/check_expr.cpp | 24 - src/check_stmt.cpp | 6 - src/checker.cpp | 140 ++---- src/checker.hpp | 8 - src/common.cpp | 9 + src/docs.cpp | 9 - src/entity.cpp | 8 - src/exact_value.cpp | 86 ++-- src/llvm_backend.cpp | 10 +- src/llvm_backend_debug.cpp | 6 - src/llvm_backend_general.cpp | 68 --- src/llvm_backend_opt.cpp | 20 +- src/llvm_backend_proc.cpp | 88 ++-- src/llvm_backend_stmt.cpp | 10 - src/llvm_backend_utility.cpp | 12 - src/main.cpp | 77 +--- src/parser.cpp | 36 -- src/parser.hpp | 5 - src/parser_pos.cpp | 2 - src/query_data.cpp | 1030 ------------------------------------------ src/range_cache.cpp | 18 +- src/string.cpp | 14 - src/string_map.cpp | 2 - src/threading.cpp | 50 +- src/types.cpp | 75 --- 28 files changed, 169 insertions(+), 1661 deletions(-) delete mode 100644 src/query_data.cpp (limited to 'src/string_map.cpp') diff --git a/build.bat b/build.bat index 7391bd95f..d7a89fe20 100644 --- a/build.bat +++ b/build.bat @@ -62,6 +62,7 @@ if %release_mode% EQU 0 ( rem Debug set compiler_warnings= ^ -W4 -WX ^ -wd4100 -wd4101 -wd4127 -wd4146 ^ + -wd4505 ^ -wd4456 -wd4457 set compiler_includes= ^ diff --git a/src/build_settings.cpp b/src/build_settings.cpp index d66db8099..7d796d775 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -149,7 +149,6 @@ enum CommandKind : u32 { Command_run = 1<<0, Command_build = 1<<1, Command_check = 1<<3, - Command_query = 1<<4, Command_doc = 1<<5, Command_version = 1<<6, Command_test = 1<<7, @@ -157,7 +156,7 @@ enum CommandKind : u32 { Command_strip_semicolon = 1<<8, Command_bug_report = 1<<9, - Command__does_check = Command_run|Command_build|Command_check|Command_query|Command_doc|Command_test|Command_strip_semicolon, + Command__does_check = Command_run|Command_build|Command_check|Command_doc|Command_test|Command_strip_semicolon, Command__does_build = Command_run|Command_build|Command_test, Command_all = ~(u32)0, }; @@ -166,7 +165,6 @@ gb_global char const *odin_command_strings[32] = { "run", "build", "check", - "query", "doc", "version", "test", @@ -316,8 +314,6 @@ struct BuildContext { u32 cmd_doc_flags; Array extra_packages; - QueryDataSetSettings query_data_set_settings; - StringSet test_names; gbAffinity affinity; diff --git a/src/check_decl.cpp b/src/check_decl.cpp index a976c1b73..d982a69fc 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -232,16 +232,6 @@ gb_internal Ast *remove_type_alias_clutter(Ast *node) { } } -gb_internal isize total_attribute_count(DeclInfo *decl) { - isize attribute_count = 0; - for_array(i, decl->attributes) { - Ast *attr = decl->attributes[i]; - if (attr->kind != Ast_Attribute) continue; - attribute_count += attr->Attribute.elems.count; - } - return attribute_count; -} - gb_internal Type *clone_enum_type(CheckerContext *ctx, Type *original_enum_type, Type *named_type) { // NOTE(bill, 2022-02-05): Stupid edge case for `distinct` declarations // diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 3003e07b6..ed1ddd1f1 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -5103,16 +5103,6 @@ gb_internal bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize return optional_ok; } - -gb_internal bool is_expr_constant_zero(Ast *expr) { - GB_ASSERT(expr != nullptr); - auto v = exact_value_to_integer(expr->tav.value); - if (v.kind == ExactValue_Integer) { - return big_int_cmp_zero(&v.value_integer) == 0; - } - return false; -} - gb_internal isize get_procedure_param_count_excluding_defaults(Type *pt, isize *param_count_) { GB_ASSERT(pt != nullptr); GB_ASSERT(pt->kind == Type_Proc); @@ -5429,20 +5419,6 @@ gb_internal isize lookup_procedure_parameter(TypeProc *pt, String parameter_name } return -1; } -gb_internal isize lookup_procedure_result(TypeProc *pt, String result_name) { - isize result_count = pt->result_count; - for (isize i = 0; i < result_count; i++) { - Entity *e = pt->results->Tuple.variables[i]; - String name = e->token.string; - if (is_blank_ident(name)) { - continue; - } - if (name == result_name) { - return i; - } - } - return -1; -} gb_internal CALL_ARGUMENT_CHECKER(check_named_call_arguments) { ast_node(ce, CallExpr, call); diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index cae9c3537..73adbed8b 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1520,12 +1520,6 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) } case_end; - case_ast_node(ts, TagStmt, node); - // TODO(bill): Tag Statements - error(node, "Tag statements are not supported yet"); - check_stmt(ctx, ts->stmt, flags); - case_end; - case_ast_node(as, AssignStmt, node); switch (as->op.kind) { case Token_Eq: { diff --git a/src/checker.cpp b/src/checker.cpp index e2c430dc2..f130a965f 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -61,18 +61,6 @@ gb_internal void scope_reserve(Scope *scope, isize capacity) { } } -gb_internal i32 is_scope_an_ancestor(Scope *parent, Scope *child) { - i32 i = 0; - while (child != nullptr) { - if (parent == child) { - return i; - } - child = child->parent; - i++; - } - return -1; -} - gb_internal void entity_graph_node_set_destroy(EntityGraphNodeSet *s) { if (s->hashes.data != nullptr) { ptr_set_destroy(s); @@ -86,9 +74,9 @@ gb_internal void entity_graph_node_set_add(EntityGraphNodeSet *s, EntityGraphNod ptr_set_add(s, n); } -gb_internal bool entity_graph_node_set_exists(EntityGraphNodeSet *s, EntityGraphNode *n) { - return ptr_set_exists(s, n); -} +// gb_internal bool entity_graph_node_set_exists(EntityGraphNodeSet *s, EntityGraphNode *n) { +// return ptr_set_exists(s, n); +// } gb_internal void entity_graph_node_set_remove(EntityGraphNodeSet *s, EntityGraphNode *n) { ptr_set_remove(s, n); @@ -139,13 +127,13 @@ gb_internal void import_graph_node_set_add(ImportGraphNodeSet *s, ImportGraphNod ptr_set_add(s, n); } -gb_internal bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) { - return ptr_set_exists(s, n); -} +// gb_internal bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) { +// return ptr_set_exists(s, n); +// } -gb_internal void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) { - ptr_set_remove(s, n); -} +// gb_internal void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) { +// ptr_set_remove(s, n); +// } gb_internal ImportGraphNode *import_graph_node_create(gbAllocator a, AstPackage *pkg) { ImportGraphNode *n = gb_alloc_item(a, ImportGraphNode); @@ -186,15 +174,6 @@ gb_internal void import_graph_node_swap(ImportGraphNode **data, isize i, isize j y->index = i; } -gb_internal GB_COMPARE_PROC(ast_node_cmp) { - Ast *x = *cast(Ast **)a; - Ast *y = *cast(Ast **)b; - Token i = ast_token(x); - Token j = ast_token(y); - return token_pos_cmp(i.pos, j.pos); -} - - @@ -213,27 +192,27 @@ gb_internal DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { return d; } -gb_internal void destroy_declaration_info(DeclInfo *d) { - ptr_set_destroy(&d->deps); - array_free(&d->labels); -} +// gb_internal void destroy_declaration_info(DeclInfo *d) { +// ptr_set_destroy(&d->deps); +// array_free(&d->labels); +// } -gb_internal bool decl_info_has_init(DeclInfo *d) { - if (d->init_expr != nullptr) { - return true; - } - if (d->proc_lit != nullptr) { - switch (d->proc_lit->kind) { - case_ast_node(pl, ProcLit, d->proc_lit); - if (pl->body != nullptr) { - return true; - } - case_end; - } - } +// gb_internal bool decl_info_has_init(DeclInfo *d) { +// if (d->init_expr != nullptr) { +// return true; +// } +// if (d->proc_lit != nullptr) { +// switch (d->proc_lit->kind) { +// case_ast_node(pl, ProcLit, d->proc_lit); +// if (pl->body != nullptr) { +// return true; +// } +// case_end; +// } +// } - return false; -} +// return false; +// } @@ -528,11 +507,6 @@ struct VettedEntity { Entity *entity; Entity *other; }; -gb_internal void init_vetted_entity(VettedEntity *ve, VettedEntityKind kind, Entity *entity, Entity *other=nullptr) { - ve->kind = kind; - ve->entity = entity; - ve->other = other; -} gb_internal GB_COMPARE_PROC(vetted_entity_variable_pos_cmp) { @@ -1144,7 +1118,7 @@ gb_internal void init_checker_info(CheckerInfo *i) { - i->allow_identifier_uses = build_context.query_data_set_settings.kind == QueryDataSet_GoToDefinitions; + i->allow_identifier_uses = false; if (i->allow_identifier_uses) { array_init(&i->identifier_uses, a); } @@ -1226,13 +1200,10 @@ gb_internal CheckerContext make_checker_context(Checker *c) { ctx.type_path = new_checker_type_path(); ctx.type_level = 0; - ctx.poly_path = new_checker_poly_path(); - ctx.poly_level = 0; return ctx; } gb_internal void destroy_checker_context(CheckerContext *ctx) { destroy_checker_type_path(ctx->type_path); - destroy_checker_poly_path(ctx->poly_path); } gb_internal void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { @@ -1348,17 +1319,17 @@ gb_internal DeclInfo *decl_info_of_entity(Entity *e) { return nullptr; } -gb_internal DeclInfo *decl_info_of_ident(Ast *ident) { - return decl_info_of_entity(entity_of_node(ident)); -} +// gb_internal DeclInfo *decl_info_of_ident(Ast *ident) { +// return decl_info_of_entity(entity_of_node(ident)); +// } -gb_internal AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { - AstFile **found = string_map_get(&i->files, filename); - if (found != nullptr) { - return *found; - } - return nullptr; -} +// gb_internal AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { +// AstFile **found = string_map_get(&i->files, filename); +// if (found != nullptr) { +// return *found; +// } +// return nullptr; +// } gb_internal ExprInfo *check_get_expr_info(CheckerContext *c, Ast *expr) { if (c->untyped != nullptr) { ExprInfo **found = map_get(c->untyped, expr); @@ -2684,32 +2655,6 @@ gb_internal Entity *check_type_path_pop(CheckerContext *c) { } -gb_internal CheckerPolyPath *new_checker_poly_path(void) { - gbAllocator a = heap_allocator(); - auto *pp = gb_alloc_item(a, CheckerPolyPath); - array_init(pp, a, 0, 16); - return pp; -} - -gb_internal void destroy_checker_poly_path(CheckerPolyPath *pp) { - array_free(pp); - gb_free(heap_allocator(), pp); -} - - -gb_internal void check_poly_path_push(CheckerContext *c, Type *t) { - GB_ASSERT(c->poly_path != nullptr); - GB_ASSERT(t != nullptr); - GB_ASSERT(is_type_polymorphic(t)); - array_add(c->poly_path, t); -} - -gb_internal Type *check_poly_path_pop(CheckerContext *c) { - GB_ASSERT(c->poly_path != nullptr); - return array_pop(c->poly_path); -} - - gb_internal Array proc_group_entities(CheckerContext *c, Operand o) { Array procs = {}; @@ -2878,13 +2823,6 @@ gb_internal ExactValue check_decl_attribute_value(CheckerContext *c, Ast *value) return ev; } -gb_internal Type *check_decl_attribute_type(CheckerContext *c, Ast *value) { - if (value != nullptr) { - return check_type(c, value); - } - return nullptr; -} - #define ATTRIBUTE_USER_TAG_NAME "tag" diff --git a/src/checker.hpp b/src/checker.hpp index e1efd5b89..58f6a027c 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -397,8 +397,6 @@ struct CheckerContext { CheckerTypePath *type_path; isize type_level; // TODO(bill): Actually handle correctly - CheckerPolyPath *poly_path; - isize poly_level; // TODO(bill): Actually handle correctly UntypedExprInfoMap *untyped; @@ -489,12 +487,6 @@ gb_internal void destroy_checker_type_path(CheckerTypePath *tp); gb_internal void check_type_path_push(CheckerContext *c, Entity *e); gb_internal Entity *check_type_path_pop (CheckerContext *c); -gb_internal CheckerPolyPath *new_checker_poly_path(); -gb_internal void destroy_checker_poly_path(CheckerPolyPath *); - -gb_internal void check_poly_path_push(CheckerContext *c, Type *t); -gb_internal Type *check_poly_path_pop (CheckerContext *c); - gb_internal void init_core_context(Checker *c); gb_internal void init_mem_allocator(Checker *c); diff --git a/src/common.cpp b/src/common.cpp index 09203e633..3624446f1 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -50,6 +50,10 @@ gb_internal void debugf(char const *fmt, ...); #include "string.cpp" #include "range_cache.cpp" +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(push) + #pragma warning(disable: 4505) +#endif gb_internal gb_inline bool is_power_of_two(i64 x) { if (x <= 0) { @@ -900,3 +904,8 @@ gb_internal Slice did_you_mean_results(DidYouMeanAnswers *d) } return slice_array(d->distances, 0, count); } + + +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(pop) +#endif \ No newline at end of file diff --git a/src/docs.cpp b/src/docs.cpp index 33b1e8361..b1efa2b46 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -85,15 +85,6 @@ gb_internal void print_doc_line(i32 indent, char const *fmt, ...) { va_end(va); gb_printf("\n"); } -gb_internal void print_doc_line_no_newline(i32 indent, char const *fmt, ...) { - while (indent --> 0) { - gb_printf("\t"); - } - va_list va; - va_start(va, fmt); - gb_printf_va(fmt, va); - va_end(va); -} gb_internal void print_doc_line_no_newline(i32 indent, String const &data) { while (indent --> 0) { gb_printf("\t"); diff --git a/src/entity.cpp b/src/entity.cpp index 6a3a69950..0605a293a 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -404,14 +404,6 @@ gb_internal Entity *alloc_entity_proc_group(Scope *scope, Token token, Type *typ return entity; } - -gb_internal Entity *alloc_entity_builtin(Scope *scope, Token token, Type *type, i32 id) { - Entity *entity = alloc_entity(Entity_Builtin, scope, token, type); - entity->Builtin.id = id; - entity->state = EntityState_Resolved; - return entity; -} - gb_internal Entity *alloc_entity_import_name(Scope *scope, Token token, Type *type, String path, String name, Scope *import_scope) { Entity *entity = alloc_entity(Entity_ImportName, scope, token, type); diff --git a/src/exact_value.cpp b/src/exact_value.cpp index 453909a15..f4c85505d 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -15,16 +15,6 @@ struct Quaternion256 { f64 imag, jmag, kmag, real; }; -gb_internal Quaternion256 quaternion256_inverse(Quaternion256 x) { - f64 invmag2 = 1.0 / (x.real*x.real + x.imag*x.imag + x.jmag*x.jmag + x.kmag*x.kmag); - x.real = +x.real * invmag2; - x.imag = -x.imag * invmag2; - x.jmag = -x.jmag * invmag2; - x.kmag = -x.kmag * invmag2; - return x; -} - - enum ExactValueKind { ExactValue_Invalid = 0, @@ -453,44 +443,44 @@ gb_internal ExactValue exact_value_kmag(ExactValue v) { return r; } -gb_internal ExactValue exact_value_make_imag(ExactValue v) { - switch (v.kind) { - case ExactValue_Integer: - return exact_value_complex(0, exact_value_to_float(v).value_float); - case ExactValue_Float: - return exact_value_complex(0, v.value_float); - default: - GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); - } - ExactValue r = {ExactValue_Invalid}; - return r; -} - -gb_internal ExactValue exact_value_make_jmag(ExactValue v) { - switch (v.kind) { - case ExactValue_Integer: - return exact_value_quaternion(0, 0, exact_value_to_float(v).value_float, 0); - case ExactValue_Float: - return exact_value_quaternion(0, 0, v.value_float, 0); - default: - GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); - } - ExactValue r = {ExactValue_Invalid}; - return r; -} - -gb_internal ExactValue exact_value_make_kmag(ExactValue v) { - switch (v.kind) { - case ExactValue_Integer: - return exact_value_quaternion(0, 0, 0, exact_value_to_float(v).value_float); - case ExactValue_Float: - return exact_value_quaternion(0, 0, 0, v.value_float); - default: - GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); - } - ExactValue r = {ExactValue_Invalid}; - return r; -} +// gb_internal ExactValue exact_value_make_imag(ExactValue v) { +// switch (v.kind) { +// case ExactValue_Integer: +// return exact_value_complex(0, exact_value_to_float(v).value_float); +// case ExactValue_Float: +// return exact_value_complex(0, v.value_float); +// default: +// GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); +// } +// ExactValue r = {ExactValue_Invalid}; +// return r; +// } + +// gb_internal ExactValue exact_value_make_jmag(ExactValue v) { +// switch (v.kind) { +// case ExactValue_Integer: +// return exact_value_quaternion(0, 0, exact_value_to_float(v).value_float, 0); +// case ExactValue_Float: +// return exact_value_quaternion(0, 0, v.value_float, 0); +// default: +// GB_PANIC("Expected an integer or float type for 'exact_value_make_jmag'"); +// } +// ExactValue r = {ExactValue_Invalid}; +// return r; +// } + +// gb_internal ExactValue exact_value_make_kmag(ExactValue v) { +// switch (v.kind) { +// case ExactValue_Integer: +// return exact_value_quaternion(0, 0, 0, exact_value_to_float(v).value_float); +// case ExactValue_Float: +// return exact_value_quaternion(0, 0, 0, v.value_float); +// default: +// GB_PANIC("Expected an integer or float type for 'exact_value_make_kmag'"); +// } +// ExactValue r = {ExactValue_Invalid}; +// return r; +// } gb_internal i64 exact_value_to_i64(ExactValue v) { v = exact_value_to_integer(v); diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index ca4b3b683..c5bc96eb9 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -605,11 +605,11 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { return {p->value, p->type}; } -gb_internal void lb_debug_print(lbProcedure *p, String const &str) { - auto args = array_make(heap_allocator(), 1); - args[0] = lb_const_string(p->module, str); - lb_emit_runtime_call(p, "print_string", args); -} +// gb_internal void lb_debug_print(lbProcedure *p, String const &str) { +// auto args = array_make(heap_allocator(), 1); +// args[0] = lb_const_string(p->module, str); +// lb_emit_runtime_call(p, "print_string", args); +// } gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { GB_ASSERT(build_context.use_static_map_calls); diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 849416579..55c4370a2 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -14,12 +14,6 @@ gb_internal void lb_set_llvm_metadata(lbModule *m, void *key, LLVMMetadataRef va } } -gb_internal LLVMMetadataRef lb_get_llvm_file_metadata_from_node(lbModule *m, Ast *node) { - if (node == nullptr) { - return nullptr; - } - return lb_get_llvm_metadata(m, node->file()); -} gb_internal LLVMMetadataRef lb_get_current_debug_scope(lbProcedure *p) { GB_ASSERT_MSG(p->debug_info != nullptr, "missing debug information for %.*s", LIT(p->name)); diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index f30038da8..e5aa95f10 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -272,12 +272,6 @@ gb_internal lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index) gb_internal LLVMValueRef llvm_zero(lbModule *m) { return LLVMConstInt(lb_type(m, t_int), 0, false); } -gb_internal LLVMValueRef llvm_zero32(lbModule *m) { - return LLVMConstInt(lb_type(m, t_i32), 0, false); -} -gb_internal LLVMValueRef llvm_one(lbModule *m) { - return LLVMConstInt(lb_type(m, t_i32), 1, false); -} gb_internal LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name) { LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block); @@ -874,14 +868,6 @@ gb_internal void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) { lb_emit_store(p, addr.addr, value); } -gb_internal void lb_const_store(lbValue ptr, lbValue value) { - GB_ASSERT(lb_is_const(ptr)); - GB_ASSERT(lb_is_const(value)); - GB_ASSERT(is_type_pointer(ptr.type)); - LLVMSetInitializer(ptr.value, value.value); -} - - gb_internal bool lb_is_type_proc_recursive(Type *t) { for (;;) { if (t == nullptr) { @@ -1327,21 +1313,6 @@ gb_internal void lb_clone_struct_type(LLVMTypeRef dst, LLVMTypeRef src) { LLVMStructSetBody(dst, fields, field_count, LLVMIsPackedStruct(src)); } -gb_internal LLVMTypeRef lb_alignment_prefix_type_hack(lbModule *m, i64 alignment) { - switch (alignment) { - case 1: - return LLVMArrayType(lb_type(m, t_u8), 0); - case 2: - return LLVMArrayType(lb_type(m, t_u16), 0); - case 4: - return LLVMArrayType(lb_type(m, t_u32), 0); - case 8: - return LLVMArrayType(lb_type(m, t_u64), 0); - default: case 16: - return LLVMArrayType(LLVMVectorType(lb_type(m, t_u32), 4), 0); - } -} - gb_internal String lb_mangle_name(lbModule *m, Entity *e) { String name = e->token.string; @@ -2202,9 +2173,6 @@ gb_internal void lb_add_member(lbModule *m, String const &name, lbValue val) { string_map_set(&m->members, name, val); } } -gb_internal void lb_add_member(lbModule *m, StringHashKey const &key, lbValue val) { - string_map_set(&m->members, key, val); -} gb_internal void lb_add_procedure_value(lbModule *m, lbProcedure *p) { if (p->entity != nullptr) { map_set(&m->procedure_values, p->value, p->entity); @@ -2493,42 +2461,6 @@ gb_internal lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) return res; } -gb_internal lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str) { - LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)}; - LLVMValueRef data = LLVMConstStringInContext(m->ctx, - cast(char const *)str.text, - cast(unsigned)str.len, - false); - - - char *name = nullptr; - { - isize max_len = 7+8+1; - name = gb_alloc_array(permanent_allocator(), char, max_len); - u32 id = m->gen->global_array_index.fetch_add(1); - isize len = gb_snprintf(name, max_len, "csbs$%x", id); - len -= 1; - } - LLVMTypeRef type = LLVMTypeOf(data); - LLVMValueRef global_data = LLVMAddGlobal(m->mod, type, name); - LLVMSetInitializer(global_data, data); - lb_make_global_private_const(global_data); - LLVMSetAlignment(global_data, 1); - - LLVMValueRef ptr = nullptr; - if (str.len != 0) { - ptr = LLVMConstInBoundsGEP2(type, global_data, indices, 2); - } else { - ptr = LLVMConstNull(lb_type(m, t_u8_ptr)); - } - LLVMValueRef len = LLVMConstInt(lb_type(m, t_int), str.len, true); - LLVMValueRef values[2] = {ptr, len}; - - lbValue res = {}; - res.value = llvm_const_named_struct(m, t_u8_slice, values, 2); - res.type = t_u8_slice; - return res; -} gb_internal lbValue lb_find_or_add_entity_string_byte_slice_with_type(lbModule *m, String const &str, Type *slice_type) { GB_ASSERT(is_type_slice(slice_type)); LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)}; diff --git a/src/llvm_backend_opt.cpp b/src/llvm_backend_opt.cpp index 533264e62..fd6d94361 100644 --- a/src/llvm_backend_opt.cpp +++ b/src/llvm_backend_opt.cpp @@ -37,16 +37,16 @@ gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i3 gb_internal void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level); gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level); -gb_internal LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) { - lbModule *m = cast(lbModule *)user_data; - if (m == nullptr) { - return false; - } - if (value == nullptr) { - return false; - } - return LLVMIsAAllocaInst(value) != nullptr; -} +// gb_internal LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) { +// lbModule *m = cast(lbModule *)user_data; +// if (m == nullptr) { +// return false; +// } +// if (value == nullptr) { +// return false; +// } +// return LLVMIsAAllocaInst(value) != nullptr; +// } #if LLVM_VERSION_MAJOR < 12 diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index 0789fb2c1..384d29ca7 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -383,46 +383,46 @@ gb_internal lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name } -gb_internal lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) { - lbParamPasskind kind = lbParamPass_Value; - - if (e != nullptr && !are_types_identical(abi_type, e->type)) { - if (is_type_pointer(abi_type)) { - GB_ASSERT(e->kind == Entity_Variable); - Type *av = core_type(type_deref(abi_type)); - if (are_types_identical(av, core_type(e->type))) { - kind = lbParamPass_Pointer; - if (e->flags&EntityFlag_Value) { - kind = lbParamPass_ConstRef; - } - } else { - kind = lbParamPass_BitCast; - } - } else if (is_type_integer(abi_type)) { - kind = lbParamPass_Integer; - } else if (abi_type == t_llvm_bool) { - kind = lbParamPass_Value; - } else if (is_type_boolean(abi_type)) { - kind = lbParamPass_Integer; - } else if (is_type_simd_vector(abi_type)) { - kind = lbParamPass_BitCast; - } else if (is_type_float(abi_type)) { - kind = lbParamPass_BitCast; - } else if (is_type_tuple(abi_type)) { - kind = lbParamPass_Tuple; - } else if (is_type_proc(abi_type)) { - kind = lbParamPass_Value; - } else { - GB_PANIC("Invalid abi type pass kind %s", type_to_string(abi_type)); - } - } - - if (kind_) *kind_ = kind; - lbValue res = {}; - res.value = LLVMGetParam(p->value, cast(unsigned)index); - res.type = abi_type; - return res; -} +// gb_internal lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) { +// lbParamPasskind kind = lbParamPass_Value; + +// if (e != nullptr && !are_types_identical(abi_type, e->type)) { +// if (is_type_pointer(abi_type)) { +// GB_ASSERT(e->kind == Entity_Variable); +// Type *av = core_type(type_deref(abi_type)); +// if (are_types_identical(av, core_type(e->type))) { +// kind = lbParamPass_Pointer; +// if (e->flags&EntityFlag_Value) { +// kind = lbParamPass_ConstRef; +// } +// } else { +// kind = lbParamPass_BitCast; +// } +// } else if (is_type_integer(abi_type)) { +// kind = lbParamPass_Integer; +// } else if (abi_type == t_llvm_bool) { +// kind = lbParamPass_Value; +// } else if (is_type_boolean(abi_type)) { +// kind = lbParamPass_Integer; +// } else if (is_type_simd_vector(abi_type)) { +// kind = lbParamPass_BitCast; +// } else if (is_type_float(abi_type)) { +// kind = lbParamPass_BitCast; +// } else if (is_type_tuple(abi_type)) { +// kind = lbParamPass_Tuple; +// } else if (is_type_proc(abi_type)) { +// kind = lbParamPass_Value; +// } else { +// GB_PANIC("Invalid abi type pass kind %s", type_to_string(abi_type)); +// } +// } + +// if (kind_) *kind_ = kind; +// lbValue res = {}; +// res.value = LLVMGetParam(p->value, cast(unsigned)index); +// res.type = abi_type; +// return res; +// } @@ -1165,14 +1165,6 @@ gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array c return result; } -gb_internal LLVMValueRef llvm_splat_float(i64 count, LLVMTypeRef type, f64 value) { - LLVMValueRef v = LLVMConstReal(type, value); - LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count); - for (i64 i = 0; i < count; i++) { - values[i] = v; - } - return LLVMConstVector(values, cast(unsigned)count); -} gb_internal LLVMValueRef llvm_splat_int(i64 count, LLVMTypeRef type, i64 value, bool is_signed=false) { LLVMValueRef v = LLVMConstInt(type, value, is_signed); LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count); diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp index 66c422071..6400a8a9d 100644 --- a/src/llvm_backend_stmt.cpp +++ b/src/llvm_backend_stmt.cpp @@ -378,16 +378,6 @@ gb_internal lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue return lb_emit_ptr_offset(p, elems_ptr, data_index); } -gb_internal void lb_map_kvh_data_static(lbProcedure *p, lbValue map_value, lbValue *ks_, lbValue *vs_, lbValue *hs_) { - lbValue capacity = lb_map_cap(p, map_value); - lbValue ks = lb_map_data_uintptr(p, map_value); - lbValue vs = {}; - lbValue hs = {}; - if (ks_) *ks_ = ks; - if (vs_) *vs_ = vs; - if (hs_) *hs_ = hs; -} - gb_internal lbValue lb_map_hash_is_valid(lbProcedure *p, lbValue hash) { // N :: size_of(uintptr)*8 - 1 // (hash != 0) & (hash>>N == 0) diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 94b900278..dbed32b82 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -599,14 +599,6 @@ gb_internal lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) } -gb_internal lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x) { - GB_ASSERT(is_type_bit_set(x.type)); - Type *underlying = bit_set_to_int(x.type); - lbValue card = lb_emit_count_ones(p, x, underlying); - return lb_emit_conv(p, card, t_int); -} - - gb_internal lbValue lb_emit_union_cast_only_ok_check(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { GB_ASSERT(is_type_tuple(type)); lbModule *m = p->module; @@ -1493,10 +1485,6 @@ gb_internal lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da) { GB_ASSERT(is_type_dynamic_array(da.type)); return lb_emit_struct_ev(p, da, 2); } -gb_internal lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da) { - GB_ASSERT(is_type_dynamic_array(da.type)); - return lb_emit_struct_ev(p, da, 3); -} gb_internal lbValue lb_map_len(lbProcedure *p, lbValue value) { GB_ASSERT_MSG(is_type_map(value.type) || are_types_identical(value.type, t_raw_map), "%s", type_to_string(value.type)); diff --git a/src/main.cpp b/src/main.cpp index 614130bb6..c7250aa8b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,14 @@ #include "common.cpp" #include "timings.cpp" #include "tokenizer.cpp" +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(push) + #pragma warning(disable: 4505) +#endif #include "big_int.cpp" +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(pop) +#endif #include "exact_value.cpp" #include "build_settings.cpp" @@ -58,7 +65,6 @@ gb_global Timings global_timings = {0}; #endif #endif -#include "query_data.cpp" #include "bug_report.cpp" // NOTE(bill): 'name' is used in debugging and profiling modes @@ -573,7 +579,6 @@ gb_internal void usage(String argv0) { print_usage_line(1, " one must contain the program's entry point, all must be in the same package."); print_usage_line(1, "run same as 'build', but also then runs the newly compiled executable."); print_usage_line(1, "check parse, and type check a directory of .odin files"); - print_usage_line(1, "query parse, type check, and output a .json file containing information about the program"); print_usage_line(1, "strip-semicolon parse, type check, and remove unneeded semicolons from the entire program"); print_usage_line(1, "test build and runs procedures with the attribute @(test) in the initial package"); print_usage_line(1, "doc generate documentation on a directory of .odin files"); @@ -817,12 +822,6 @@ gb_internal bool parse_build_flags(Array args) { add_flag(&build_flags, BuildFlag_UseStaticMapCalls, str_lit("use-static-map-calls"), BuildFlagParam_None, Command__does_check); - - add_flag(&build_flags, BuildFlag_Compact, str_lit("compact"), BuildFlagParam_None, Command_query); - add_flag(&build_flags, BuildFlag_GlobalDefinitions, str_lit("global-definitions"), BuildFlagParam_None, Command_query); - add_flag(&build_flags, BuildFlag_GoToDefinitions, str_lit("go-to-definitions"), BuildFlagParam_None, Command_query); - - add_flag(&build_flags, BuildFlag_Short, str_lit("short"), BuildFlagParam_None, Command_doc); add_flag(&build_flags, BuildFlag_AllPackages, str_lit("all-packages"), BuildFlagParam_None, Command_doc); add_flag(&build_flags, BuildFlag_DocFormat, str_lit("doc-format"), BuildFlagParam_None, Command_doc); @@ -1445,39 +1444,6 @@ gb_internal bool parse_build_flags(Array args) { build_context.strict_style_init_only = true; break; } - case BuildFlag_Compact: { - if (!build_context.query_data_set_settings.ok) { - gb_printf_err("Invalid use of -compact flag, only allowed with 'odin query'\n"); - bad_flags = true; - } else { - build_context.query_data_set_settings.compact = true; - } - break; - } - case BuildFlag_GlobalDefinitions: { - if (!build_context.query_data_set_settings.ok) { - gb_printf_err("Invalid use of -global-definitions flag, only allowed with 'odin query'\n"); - bad_flags = true; - } else if (build_context.query_data_set_settings.kind != QueryDataSet_Invalid) { - gb_printf_err("Invalid use of -global-definitions flag, a previous flag for 'odin query' was set\n"); - bad_flags = true; - } else { - build_context.query_data_set_settings.kind = QueryDataSet_GlobalDefinitions; - } - break; - } - case BuildFlag_GoToDefinitions: { - if (!build_context.query_data_set_settings.ok) { - gb_printf_err("Invalid use of -go-to-definitions flag, only allowed with 'odin query'\n"); - bad_flags = true; - } else if (build_context.query_data_set_settings.kind != QueryDataSet_Invalid) { - gb_printf_err("Invalid use of -global-definitions flag, a previous flag for 'odin query' was set\n"); - bad_flags = true; - } else { - build_context.query_data_set_settings.kind = QueryDataSet_GoToDefinitions; - } - break; - } case BuildFlag_Short: build_context.cmd_doc_flags |= CmdDocFlag_Short; break; @@ -1638,16 +1604,6 @@ gb_internal bool parse_build_flags(Array args) { gb_printf_err("`-export-timings:` requires `-show-timings` or `-show-more-timings` to be present\n"); bad_flags = true; } - - if (build_context.query_data_set_settings.ok) { - if (build_context.query_data_set_settings.kind == QueryDataSet_Invalid) { - gb_printf_err("'odin query' requires a flag determining the kind of query data set to be returned\n"); - gb_printf_err("\t-global-definitions : outputs a JSON file of global definitions\n"); - gb_printf_err("\t-go-to-definitions : outputs a OGTD binary file of go to definitions for identifiers within an Odin project\n"); - bad_flags = true; - } - } - return !bad_flags; } @@ -1931,8 +1887,6 @@ gb_internal void print_show_help(String const arg0, String const &command) { print_usage_line(3, "odin check filename.odin -file # Type check single-file package, must contain entry point."); } else if (command == "test") { print_usage_line(1, "test Build ands runs procedures with the attribute @(test) in the initial package"); - } else if (command == "query") { - print_usage_line(1, "query [experimental] Parse, type check, and output a .json file containing information about the program"); } else if (command == "doc") { print_usage_line(1, "doc generate documentation from a directory of .odin files"); print_usage_line(2, "Examples:"); @@ -2627,15 +2581,6 @@ int main(int arg_count, char const **arg_ptr) { build_context.command_kind = Command_strip_semicolon; build_context.no_output_files = true; init_filename = args[2]; - } else if (command == "query") { - if (args.count < 3) { - usage(args[0]); - return 1; - } - build_context.command_kind = Command_query; - build_context.no_output_files = true; - build_context.query_data_set_settings.ok = true; - init_filename = args[2]; } else if (command == "doc") { if (args.count < 3) { usage(args[0]); @@ -2824,12 +2769,8 @@ int main(int arg_count, char const **arg_ptr) { print_show_unused(checker); } - if (build_context.query_data_set_settings.ok) { - generate_and_print_query_data(checker, &global_timings); - } else { - if (build_context.show_timings) { - show_timings(checker, &global_timings); - } + if (build_context.show_timings) { + show_timings(checker, &global_timings); } if (global_error_collector.count != 0) { diff --git a/src/parser.cpp b/src/parser.cpp index 1606f5b47..2ccdac7fa 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -237,9 +237,6 @@ gb_internal Ast *clone_ast(Ast *node) { case Ast_ExprStmt: n->ExprStmt.expr = clone_ast(n->ExprStmt.expr); break; - case Ast_TagStmt: - n->TagStmt.stmt = clone_ast(n->TagStmt.stmt); - break; case Ast_AssignStmt: n->AssignStmt.lhs = clone_ast_array(n->AssignStmt.lhs); n->AssignStmt.rhs = clone_ast_array(n->AssignStmt.rhs); @@ -497,14 +494,6 @@ gb_internal Ast *ast_tag_expr(AstFile *f, Token token, Token name, Ast *expr) { return result; } -gb_internal Ast *ast_tag_stmt(AstFile *f, Token token, Token name, Ast *stmt) { - Ast *result = alloc_ast_node(f, Ast_TagStmt); - result->TagStmt.token = token; - result->TagStmt.name = name; - result->TagStmt.stmt = stmt; - return result; -} - gb_internal Ast *ast_unary_expr(AstFile *f, Token op, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_UnaryExpr); result->UnaryExpr.op = op; @@ -1308,16 +1297,6 @@ gb_internal Token advance_token(AstFile *f) { return prev; } -gb_internal bool peek_token_kind(AstFile *f, TokenKind kind) { - for (isize i = f->curr_token_index+1; i < f->tokens.count; i++) { - Token tok = f->tokens[i]; - if (kind != Token_Comment && tok.kind == Token_Comment) { - continue; - } - return tok.kind == kind; - } - return false; -} gb_internal Token peek_token(AstFile *f) { for (isize i = f->curr_token_index+1; i < f->tokens.count; i++) { @@ -1440,17 +1419,6 @@ gb_internal Token expect_operator(AstFile *f) { return prev; } -gb_internal Token expect_keyword(AstFile *f) { - Token prev = f->curr_token; - if (!gb_is_between(prev.kind, Token__KeywordBegin+1, Token__KeywordEnd-1)) { - String p = token_to_string(prev); - syntax_error(f->curr_token, "Expected a keyword, got '%.*s'", - LIT(p)); - } - advance_token(f); - return prev; -} - gb_internal bool allow_token(AstFile *f, TokenKind kind) { Token prev = f->curr_token; if (prev.kind == kind) { @@ -1957,10 +1925,6 @@ gb_internal bool ast_on_same_line(Token const &x, Ast *yp) { return x.pos.line == y.pos.line; } -gb_internal bool ast_on_same_line(Ast *x, Ast *y) { - return ast_on_same_line(ast_token(x), y); -} - gb_internal Ast *parse_force_inlining_operand(AstFile *f, Token token) { Ast *expr = parse_unary_expr(f, false); Ast *e = strip_or_return_expr(expr); diff --git a/src/parser.hpp b/src/parser.hpp index a2d2c038e..f7b3e51ae 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -457,11 +457,6 @@ AST_KIND(_StmtBegin, "", bool) \ AST_KIND(BadStmt, "bad statement", struct { Token begin, end; }) \ AST_KIND(EmptyStmt, "empty statement", struct { Token token; }) \ AST_KIND(ExprStmt, "expression statement", struct { Ast *expr; } ) \ - AST_KIND(TagStmt, "tag statement", struct { \ - Token token; \ - Token name; \ - Ast * stmt; \ - }) \ AST_KIND(AssignStmt, "assign statement", struct { \ Token op; \ Slice lhs, rhs; \ diff --git a/src/parser_pos.cpp b/src/parser_pos.cpp index 19a525e2e..fb7f0c9c2 100644 --- a/src/parser_pos.cpp +++ b/src/parser_pos.cpp @@ -53,7 +53,6 @@ gb_internal Token ast_token(Ast *node) { case Ast_BadStmt: return node->BadStmt.begin; case Ast_EmptyStmt: return node->EmptyStmt.token; case Ast_ExprStmt: return ast_token(node->ExprStmt.expr); - case Ast_TagStmt: return node->TagStmt.token; case Ast_AssignStmt: return node->AssignStmt.op; case Ast_BlockStmt: return node->BlockStmt.open; case Ast_IfStmt: return node->IfStmt.token; @@ -197,7 +196,6 @@ Token ast_end_token(Ast *node) { case Ast_BadStmt: return node->BadStmt.end; case Ast_EmptyStmt: return node->EmptyStmt.token; case Ast_ExprStmt: return ast_end_token(node->ExprStmt.expr); - case Ast_TagStmt: return ast_end_token(node->TagStmt.stmt); case Ast_AssignStmt: if (node->AssignStmt.rhs.count > 0) { return ast_end_token(node->AssignStmt.rhs[node->AssignStmt.rhs.count-1]); diff --git a/src/query_data.cpp b/src/query_data.cpp deleted file mode 100644 index 86487a058..000000000 --- a/src/query_data.cpp +++ /dev/null @@ -1,1030 +0,0 @@ -struct QueryValue; -struct QueryValuePair; - -gb_global gbAllocator query_value_allocator = {}; - -enum QueryKind { - Query_Invalid, - Query_String, - Query_Boolean, - Query_Integer, - Query_Float, - Query_Array, - Query_Map, -}; - -struct QueryValuePair { - String key; - QueryValue *value; -}; - - -struct QueryValue { - QueryKind kind; - bool packed; -}; - -struct QueryValueString : QueryValue { - QueryValueString(String const &v) { - kind = Query_String; - value = v; - packed = false; - } - String value; -}; - -struct QueryValueBoolean : QueryValue { - QueryValueBoolean(bool v) { - kind = Query_Boolean; - value = v; - packed = false; - } - bool value; -}; - -struct QueryValueInteger : QueryValue { - QueryValueInteger(i64 v) { - kind = Query_Integer; - value = v; - packed = false; - } - i64 value; -}; - -struct QueryValueFloat : QueryValue { - QueryValueFloat(f64 v) { - kind = Query_Float; - value = v; - packed = false; - } - f64 value; -}; - -struct QueryValueArray : QueryValue { - QueryValueArray() { - kind = Query_Array; - array_init(&value, query_value_allocator); - packed = false; - } - QueryValueArray(Array const &v) { - kind = Query_Array; - value = v; - packed = false; - } - Array value; - - void reserve(isize cap) { - array_reserve(&value, cap); - } - void add(QueryValue *v) { - array_add(&value, v); - } - void add(char const *v) { - add(make_string_c(cast(char *)v)); - } - void add(String const &v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueString); - *val = QueryValueString(v); - add(val); - } - void add(bool v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueBoolean); - *val = QueryValueBoolean(v); - add(val); - } - void add(i64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueInteger); - *val = QueryValueInteger(v); - add(val); - } - void add(f64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueFloat); - *val = QueryValueFloat(v); - add(val); - } -}; - -struct QueryValueMap : QueryValue { - QueryValueMap() { - kind = Query_Map; - array_init(&value, query_value_allocator); - packed = false; - } - QueryValueMap(Array const &v) { - kind = Query_Map; - value = v; - packed = false; - } - Array value; - - - void reserve(isize cap) { - array_reserve(&value, cap); - } - void add(char const *k, QueryValue *v) { - add(make_string_c(cast(char *)k), v); - } - void add(String const &k, QueryValue *v) { - QueryValuePair kv = {k, v}; - array_add(&value, kv); - } - - void add(char const *k, String const &v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueString); - *val = QueryValueString(v); - add(k, val); - } - void add(char const *k, char const *v) { - add(k, make_string_c(cast(char *)v)); - } - void add(char const *k, bool v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueBoolean); - *val = QueryValueBoolean(v); - add(k, val); - } - void add(char const *k, i64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueInteger); - *val = QueryValueInteger(v); - add(k, val); - } - void add(char const *k, f64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueFloat); - *val = QueryValueFloat(v); - add(k, val); - } - void add(String const &k, String const &v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueString); - *val = QueryValueString(v); - add(k, val); - } - void add(String const &k, char const *v) { - add(k, make_string_c(cast(char *)v)); - } - void add(String const &k, bool v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueBoolean); - *val = QueryValueBoolean(v); - add(k, val); - } - void add(String const &k, i64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueInteger); - *val = QueryValueInteger(v); - add(k, val); - } - void add(String const &k, f64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueFloat); - *val = QueryValueFloat(v); - add(k, val); - } -}; - - -#define DEF_QUERY_PROC(TYPE, VALUETYPE, NAME) TYPE *NAME(VALUETYPE value) { \ - auto v = gb_alloc_item(query_value_allocator, TYPE); \ - *v = TYPE(value); \ - return v; \ -} -#define DEF_QUERY_PROC0(TYPE, NAME) TYPE *NAME() { \ - auto v = gb_alloc_item(query_value_allocator, TYPE); \ - *v = TYPE(); \ - return v; \ -} - -gb_internal DEF_QUERY_PROC(QueryValueString, String const &, query_value_string); -gb_internal DEF_QUERY_PROC(QueryValueBoolean, bool, query_value_boolean); -gb_internal DEF_QUERY_PROC(QueryValueInteger, i64, query_value_integer); -gb_internal DEF_QUERY_PROC(QueryValueFloat, f64, query_value_float); -gb_internal DEF_QUERY_PROC(QueryValueArray, Array const &, query_value_array); -gb_internal DEF_QUERY_PROC(QueryValueMap, Array const &, query_value_map); -gb_internal DEF_QUERY_PROC0(QueryValueArray, query_value_array); -gb_internal DEF_QUERY_PROC0(QueryValueMap, query_value_map); - -gb_internal isize qprintf(bool format, isize indent, char const *fmt, ...) { - if (format) while (indent --> 0) { - gb_printf("\t"); - } - va_list va; - va_start(va, fmt); - isize res = gb_printf_va(fmt, va); - va_end(va); - return res; -} - -gb_internal bool qv_valid_char(u8 c) { - if (c >= 0x80) { - return false; - } - - switch (c) { - case '\"': - case '\n': - case '\r': - case '\t': - case '\v': - case '\f': - return false; - } - - return true; -} - -gb_internal void print_query_data_as_json(QueryValue *value, bool format = true, isize indent = 0) { - if (value == nullptr) { - gb_printf("null"); - return; - } - switch (value->kind) { - case Query_String: { - auto v = cast(QueryValueString *)value; - String name = v->value; - isize extra = 0; - for (isize i = 0; i < name.len; i++) { - u8 c = name[i]; - if (!qv_valid_char(c)) { - extra += 5; - } - } - - if (extra == 0) { - gb_printf("\"%.*s\"", LIT(name)); - return; - } - - char const hex_table[] = "0123456789ABCDEF"; - isize buf_len = name.len + extra + 2 + 1; - - u8 *buf = gb_alloc_array(temporary_allocator(), u8, buf_len); - - isize j = 0; - - for (isize i = 0; i < name.len; i++) { - u8 c = name[i]; - if (qv_valid_char(c)) { - buf[j+0] = c; - j += 1; - } else if (c == '"') { - buf[j+0] = '\\'; - buf[j+1] = '\"'; - j += 2; - } else { - switch (c) { - case '\n': buf[j+0] = '\\'; buf[j+1] = 'n'; j += 2; break; - case '\r': buf[j+0] = '\\'; buf[j+1] = 'r'; j += 2; break; - case '\t': buf[j+0] = '\\'; buf[j+1] = 't'; j += 2; break; - case '\v': buf[j+0] = '\\'; buf[j+1] = 'v'; j += 2; break; - case '\f': - default: - buf[j+0] = '\\'; - buf[j+1] = hex_table[0]; - buf[j+2] = hex_table[0]; - buf[j+3] = hex_table[c >> 4]; - buf[j+4] = hex_table[c & 0x0f]; - j += 5; - break; - } - } - } - - gb_printf("\"%s\"", buf); - return; - } - case Query_Boolean: { - auto v = cast(QueryValueBoolean *)value; - if (v->value) { - gb_printf("true"); - } else { - gb_printf("false"); - } - return; - } - case Query_Integer: { - auto v = cast(QueryValueInteger *)value; - gb_printf("%lld", cast(long long)v->value); - return; - } - case Query_Float: { - auto v = cast(QueryValueFloat *)value; - gb_printf("%f", v->value); - return; - } - case Query_Array: { - auto v = cast(QueryValueArray *)value; - if (v->value.count > 0) { - bool ff = format && !v->packed; - gb_printf("["); - if (ff) gb_printf("\n"); - for_array(i, v->value) { - qprintf(ff, indent+1, ""); - print_query_data_as_json(v->value[i], ff, indent+1); - if (i < v->value.count-1) { - gb_printf(","); - if (!ff && format) { - gb_printf(" "); - } - } - if (ff) gb_printf("\n"); - } - qprintf(ff, indent, "]"); - } else { - gb_printf("[]"); - } - return; - } - case Query_Map: { - auto v = cast(QueryValueMap *)value; - if (v->value.count > 0) { - bool ff = format && !v->packed; - gb_printf("{"); - if (ff) gb_printf("\n"); - for_array(i, v->value) { - auto kv = v->value[i]; - qprintf(ff, indent+1, "\"%.*s\":", LIT(kv.key)); - if (format) gb_printf(" "); - print_query_data_as_json(kv.value, ff, indent+1); - if (i < v->value.count-1) { - gb_printf(","); - if (!ff && format) { - gb_printf(" "); - } - } - if (ff) gb_printf("\n"); - } - qprintf(ff, indent, "}"); - } else { - gb_printf("{}"); - } - return; - } - } -} - - - -gb_internal int query_data_package_compare(void const *a, void const *b) { - AstPackage *x = *cast(AstPackage *const *)a; - AstPackage *y = *cast(AstPackage *const *)b; - - if (x == y) { - return 0; - } - - if (x != nullptr && y != nullptr) { - return string_compare(x->name, y->name); - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - return 0; -} - -gb_internal int query_data_definition_compare(void const *a, void const *b) { - Entity *x = *cast(Entity *const *)a; - Entity *y = *cast(Entity *const *)b; - - if (x == y) { - return 0; - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - - if (x->pkg != y->pkg) { - i32 res = query_data_package_compare(&x->pkg, &y->pkg); - if (res != 0) { - return res; - } - } - - return string_compare(x->token.string, y->token.string); -} - -gb_internal int entity_name_compare(void const *a, void const *b) { - Entity *x = *cast(Entity *const *)a; - Entity *y = *cast(Entity *const *)b; - if (x == y) { - return 0; - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - return string_compare(x->token.string, y->token.string); -} - - -gb_internal void generate_and_print_query_data_global_definitions(Checker *c, Timings *timings); -gb_internal void generate_and_print_query_data_go_to_definitions(Checker *c); - -gb_internal void generate_and_print_query_data(Checker *c, Timings *timings) { - query_value_allocator = heap_allocator(); - switch (build_context.query_data_set_settings.kind) { - case QueryDataSet_GlobalDefinitions: - generate_and_print_query_data_global_definitions(c, timings); - return; - case QueryDataSet_GoToDefinitions: - generate_and_print_query_data_go_to_definitions(c); - return; - } -} - - -gb_internal void generate_and_print_query_data_global_definitions(Checker *c, Timings *timings) { - auto *root = query_value_map(); - - if (global_error_collector.errors.count > 0) { - auto *errors = query_value_array(); - root->add("errors", errors); - for_array(i, global_error_collector.errors) { - String err = string_trim_whitespace(global_error_collector.errors[i]); - errors->add(err); - } - - } - - { // Packages - auto *packages = query_value_array(); - root->add("packages", packages); - - auto sorted_packages = array_make(query_value_allocator, 0, c->info.packages.entries.count); - defer (array_free(&sorted_packages)); - - for (auto const &entry : c->info.packages) { - AstPackage *pkg = entry.value; - if (pkg != nullptr) { - array_add(&sorted_packages, pkg); - } - } - gb_sort_array(sorted_packages.data, sorted_packages.count, query_data_package_compare); - packages->reserve(sorted_packages.count); - - for_array(i, sorted_packages) { - AstPackage *pkg = sorted_packages[i]; - String name = pkg->name; - String fullpath = pkg->fullpath; - - auto *files = query_value_array(); - files->reserve(pkg->files.count); - for_array(j, pkg->files) { - AstFile *f = pkg->files[j]; - files->add(f->fullpath); - } - - auto *package = query_value_map(); - package->reserve(3); - packages->add(package); - - package->add("name", pkg->name); - package->add("fullpath", pkg->fullpath); - package->add("files", files); - } - } - - if (c->info.definitions.count > 0) { - auto *definitions = query_value_array(); - root->add("definitions", definitions); - - auto sorted_definitions = array_make(query_value_allocator, 0, c->info.definitions.count); - defer (array_free(&sorted_definitions)); - - for_array(i, c->info.definitions) { - Entity *e = c->info.definitions[i]; - String name = e->token.string; - if (is_blank_ident(name)) { - continue; - } - if ((e->scope->flags & (ScopeFlag_Pkg|ScopeFlag_File)) == 0) { - continue; - } - if (e->parent_proc_decl != nullptr) { - continue; - } - switch (e->kind) { - case Entity_Builtin: - case Entity_Nil: - case Entity_Label: - continue; - } - if (e->pkg == nullptr) { - continue; - } - if (e->token.pos.line == 0) { - continue; - } - if (e->kind == Entity_Procedure) { - Type *t = base_type(e->type); - if (t->kind != Type_Proc) { - continue; - } - if (t->Proc.is_poly_specialized) { - continue; - } - } - if (e->kind == Entity_TypeName) { - Type *t = base_type(e->type); - if (t->kind == Type_Struct) { - if (t->Struct.is_poly_specialized) { - continue; - } - } - if (t->kind == Type_Union) { - if (t->Union.is_poly_specialized) { - continue; - } - } - } - - array_add(&sorted_definitions, e); - } - - gb_sort_array(sorted_definitions.data, sorted_definitions.count, query_data_definition_compare); - definitions->reserve(sorted_definitions.count); - - for_array(i, sorted_definitions) { - Entity *e = sorted_definitions[i]; - String name = e->token.string; - - auto *def = query_value_map(); - def->reserve(16); - definitions->add(def); - - def->add("package", e->pkg->name); - def->add("name", name); - def->add("filepath", get_file_path_string(e->token.pos.file_id)); - def->add("line", cast(i64)e->token.pos.line); - def->add("column", cast(i64)e->token.pos.column); - def->add("file_offset", cast(i64)e->token.pos.offset); - - switch (e->kind) { - case Entity_Constant: def->add("kind", str_lit("constant")); break; - case Entity_Variable: def->add("kind", str_lit("variable")); break; - case Entity_TypeName: def->add("kind", str_lit("type name")); break; - case Entity_Procedure: def->add("kind", str_lit("procedure")); break; - case Entity_ProcGroup: def->add("kind", str_lit("procedure group")); break; - case Entity_ImportName: def->add("kind", str_lit("import name")); break; - case Entity_LibraryName: def->add("kind", str_lit("library name")); break; - default: GB_PANIC("Invalid entity kind to be added"); - } - - - if (e->type != nullptr && e->type != t_invalid) { - Type *t = e->type; - Type *bt = t; - - switch (e->kind) { - case Entity_TypeName: - if (!e->TypeName.is_type_alias) { - bt = base_type(t); - } - break; - } - - { - gbString str = type_to_string(t); - String type_str = make_string(cast(u8 *)str, gb_string_length(str)); - def->add("type", type_str); - } - if (t != bt) { - gbString str = type_to_string(bt); - String type_str = make_string(cast(u8 *)str, gb_string_length(str)); - def->add("base_type", type_str); - } - { - String type_kind = {}; - Type *bt = base_type(t); - switch (bt->kind) { - case Type_Pointer: type_kind = str_lit("pointer"); break; - case Type_Array: type_kind = str_lit("array"); break; - case Type_Slice: type_kind = str_lit("slice"); break; - case Type_DynamicArray: type_kind = str_lit("dynamic array"); break; - case Type_Map: type_kind = str_lit("map"); break; - case Type_Struct: type_kind = str_lit("struct"); break; - case Type_Union: type_kind = str_lit("union"); break; - case Type_Enum: type_kind = str_lit("enum"); break; - case Type_Proc: type_kind = str_lit("procedure"); break; - case Type_BitSet: type_kind = str_lit("bit set"); break; - case Type_SimdVector: type_kind = str_lit("simd vector"); break; - - case Type_Generic: - case Type_Tuple: - GB_PANIC("Invalid definition type"); - break; - } - if (type_kind.len > 0) { - def->add("type_kind", type_kind); - } - } - } - - if (e->kind == Entity_TypeName) { - def->add("size", type_size_of(e->type)); - def->add("align", type_align_of(e->type)); - - - if (is_type_struct(e->type)) { - auto *data = query_value_map(); - data->reserve(6); - - def->add("data", data); - - Type *t = base_type(e->type); - GB_ASSERT(t->kind == Type_Struct); - - if (t->Struct.is_polymorphic) { - data->add("polymorphic", cast(bool)t->Struct.is_polymorphic); - } - if (t->Struct.is_poly_specialized) { - data->add("polymorphic_specialized", cast(bool)t->Struct.is_poly_specialized); - } - if (t->Struct.is_packed) { - data->add("packed", cast(bool)t->Struct.is_packed); - } - if (t->Struct.is_raw_union) { - data->add("raw_union", cast(bool)t->Struct.is_raw_union); - } - - auto *fields = query_value_array(); - data->add("fields", fields); - fields->reserve(t->Struct.fields.count); - fields->packed = true; - - for_array(j, t->Struct.fields) { - Entity *e = t->Struct.fields[j]; - String name = e->token.string; - if (is_blank_ident(name)) { - continue; - } - - fields->add(name); - } - } else if (is_type_union(e->type)) { - auto *data = query_value_map(); - data->reserve(4); - - def->add("data", data); - Type *t = base_type(e->type); - GB_ASSERT(t->kind == Type_Union); - - if (t->Union.is_polymorphic) { - data->add("polymorphic", cast(bool)t->Union.is_polymorphic); - } - if (t->Union.is_poly_specialized) { - data->add("polymorphic_specialized", cast(bool)t->Union.is_poly_specialized); - } - - auto *variants = query_value_array(); - variants->reserve(t->Union.variants.count); - data->add("variants", variants); - - for_array(j, t->Union.variants) { - Type *vt = t->Union.variants[j]; - - gbString str = type_to_string(vt); - String type_str = make_string(cast(u8 *)str, gb_string_length(str)); - variants->add(type_str); - } - } - } - - if (e->kind == Entity_Procedure) { - Type *t = base_type(e->type); - GB_ASSERT(t->kind == Type_Proc); - - bool is_polymorphic = t->Proc.is_polymorphic; - bool is_poly_specialized = t->Proc.is_poly_specialized; - bool ok = is_polymorphic || is_poly_specialized; - if (ok) { - auto *data = query_value_map(); - data->reserve(4); - - def->add("data", data); - if (is_polymorphic) { - data->add("polymorphic", cast(bool)is_polymorphic); - } - if (is_poly_specialized) { - data->add("polymorphic_specialized", cast(bool)is_poly_specialized); - } - } - } - - if (e->kind == Entity_ProcGroup) { - auto *procedures = query_value_array(); - procedures->reserve(e->ProcGroup.entities.count); - - for_array(j, e->ProcGroup.entities) { - Entity *p = e->ProcGroup.entities[j]; - - auto *procedure = query_value_map(); - procedure->reserve(2); - procedure->packed = true; - - procedures->add(procedure); - - procedure->add("package", p->pkg->name); - procedure->add("name", p->token.string); - } - def->add("procedures", procedures); - } - - DeclInfo *di = e->decl_info; - if (di != nullptr) { - if (di->is_using) { - def->add("using", query_value_boolean(true)); - } - } - } - } - - if (build_context.show_timings) { - Timings *t = timings; - timings__stop_current_section(t); - t->total.finish = time_stamp_time_now(); - isize max_len = gb_min(36, t->total.label.len); - for_array(i, t->sections) { - TimeStamp ts = t->sections[i]; - max_len = gb_max(max_len, ts.label.len); - } - t->total_time_seconds = time_stamp_as_s(t->total, t->freq); - - auto *tims = query_value_map(); - tims->reserve(8); - root->add("timings", tims); - tims->add("time_unit", str_lit("s")); - - tims->add(t->total.label, cast(f64)t->total_time_seconds); - - - Parser *p = c->parser; - if (p != nullptr) { - isize lines = p->total_line_count; - isize tokens = p->total_token_count; - isize files = 0; - isize packages = p->packages.count; - isize total_file_size = 0; - for_array(i, p->packages) { - files += p->packages[i]->files.count; - for_array(j, p->packages[i]->files) { - AstFile *file = p->packages[i]->files[j]; - total_file_size += file->tokenizer.end - file->tokenizer.start; - } - } - - tims->add("total_lines", cast(i64)lines); - tims->add("total_tokens", cast(i64)tokens); - tims->add("total_files", cast(i64)files); - tims->add("total_packages", cast(i64)packages); - tims->add("total_file_size", cast(i64)total_file_size); - - auto *sections = query_value_map(); - sections->reserve(t->sections.count); - tims->add("sections", sections); - for_array(i, t->sections) { - TimeStamp ts = t->sections[i]; - f64 section_time = time_stamp_as_s(ts, t->freq); - - auto *section = query_value_map(); - section->reserve(2); - sections->add(ts.label, section); - section->add("time", cast(f64)section_time); - section->add("total_fraction", cast(f64)(section_time/t->total_time_seconds)); - } - } - } - - - print_query_data_as_json(root, !build_context.query_data_set_settings.compact); - gb_printf("\n"); -} - - - -template -struct BinaryArray { - u32 offset; // Offset in bytes from the top of the file - u32 length; // Number of elements in array of type T -}; - -template -gb_internal Array binary_array_from_data(BinaryArray ba, void *data) { - Array res = {}; - res.data = cast(T *)(cast(u8 *)data + ba.offset); - res.count = ba.length; - res.capacity = ba.length; - return res; -} - -typedef BinaryArray BinaryString; - -struct GoToDefIdent { - u64 use_offset; // offset of identifier use in bytes from the start of the file that contains it - u32 len; // length in bytes of the identifier - u32 def_file_id; - u64 def_offset; // offset of entity definition in bytes from the start of the file that contains it -}; - -struct GoToDefFile { - u32 id; - BinaryString path; - BinaryArray idents; -}; - -struct GoToDefHeader { - u8 magic[4]; // ogtd (odin-go-to-definitions) - u32 version; // 1 - BinaryArray files; -}; - -struct GoToDefFileMap { - AstFile *f; - u32 id; - Array idents; -}; - - -gb_internal int go_to_def_file_map_compare(void const *a, void const *b) { - GoToDefFileMap const *x = cast(GoToDefFileMap const *)a; - GoToDefFileMap const *y = cast(GoToDefFileMap const *)b; - if (x == y) { - return 0; - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - if (x->f->id < y->f->id) { - return -1; - } else if (x->f->id > y->f->id) { - return +1; - } - return 0; -} - -gb_internal int quick_ident_compare(void const *a, void const *b) { - Ast *x = *cast(Ast **)a; - Ast *y = *cast(Ast **)b; - - // NOTE(bill): This assumes that the file is same - if (x->Ident.token.pos.offset < y->Ident.token.pos.offset) { - return -1; - } else if (x->Ident.token.pos.offset > y->Ident.token.pos.offset) { - return +1; - } - return 0; -} - - -gb_internal void generate_and_print_query_data_go_to_definitions(Checker *c) { - GB_ASSERT(c->info.allow_identifier_uses); - - gbAllocator a = query_value_allocator; - - isize file_path_memory_needed = 0; - auto files = array_make(a, 0, c->info.files.entries.count); - for (auto const &entry : c->info.files) { - AstFile *f = entry.value; - file_path_memory_needed += f->fullpath.len+1; // add NUL terminator - - - GoToDefFileMap x = {}; - x.f = f; - array_init(&x.idents, a); - array_add(&files, x); - } - gb_sort_array(files.data, files.count, go_to_def_file_map_compare); - - auto file_id_map_to_index = array_make(a, files[files.count-1].f->id + 1); - for_array(i, file_id_map_to_index) { - file_id_map_to_index[i] = -1; - } - for_array(i, files) { - file_id_map_to_index[files[i].f->id] = i; - } - - - - for_array(i, c->info.identifier_uses) { - Ast *ast = c->info.identifier_uses[i]; - GB_ASSERT(ast->kind == Ast_Ident); - TokenPos pos = ast->Ident.token.pos; - Entity *e = ast->Ident.entity; - if (e == nullptr) { - continue; - } - - - AstFile **use_file_found = string_map_get(&c->info.files, get_file_path_string(pos.file_id)); - GB_ASSERT(use_file_found != nullptr); - AstFile *use_file = *use_file_found; - GB_ASSERT(use_file != nullptr); - - if (e->scope == nullptr) { - GB_ASSERT(e->flags & EntityFlag_Field); - continue; - } - if (e->scope->flags & ScopeFlag_Global) { - continue; - } - - isize idx = file_id_map_to_index[use_file->id]; - if (idx >= 0) { - array_add(&files[idx].idents, ast); - } else { - // TODO(bill): Handle invalid map case? - } - } - - for_array(i, files) { - GoToDefFileMap *f = &files[i]; - gb_sort_array(f->idents.data, f->idents.count, quick_ident_compare); - // gb_printf_err("%lld %.*s -> %lld\n", f->f->id, LIT(f->f->fullpath), f->idents.count); - } - - - - isize data_min_size = 0; - - u32 header_offset = cast(u32)data_min_size; gb_unused(header_offset); - data_min_size += gb_size_of(GoToDefHeader); - data_min_size = align_formula_isize(data_min_size, 8); - - u32 file_offset = cast(u32)data_min_size; - data_min_size += gb_size_of(GoToDefFile) * files.count; - data_min_size = align_formula_isize(data_min_size, 8); - - u32 file_path_offset = cast(u32)data_min_size; - data_min_size += file_path_memory_needed; - data_min_size = align_formula_isize(data_min_size, 8); - - u32 idents_offset = cast(u32)data_min_size; - data_min_size += gb_size_of(GoToDefIdent) * c->info.identifier_uses.count; - - - auto data = array_make(a, 0, data_min_size); - defer (array_free(&data)); - - GoToDefHeader header = {}; - gb_memmove(header.magic, "ogtd", 4); - header.version = 1; - header.files.length = cast(u32)files.count; - header.files.offset = file_offset; - - array_add_elems(&data, cast(u8 *)&header, gb_size_of(header)); - - array_resize(&data, data_min_size); - - auto binary_files = binary_array_from_data(header.files, data.data); - - u32 file_path_offset_index = file_path_offset; - u32 idents_offset_index = idents_offset; - for_array(i, files) { - GoToDefFileMap *f_map = &files[i]; - AstFile *f = f_map->f; - binary_files[i].id = cast(u32)f->id; - - binary_files[i].path.offset = file_path_offset_index; - binary_files[i].path.length = cast(u32)f->fullpath.len; - - binary_files[i].idents.offset = idents_offset_index; - binary_files[i].idents.length = cast(u32)f_map->idents.count; - - auto path = binary_array_from_data(binary_files[i].path, data.data); - gb_memmove(path.data, f->fullpath.text, f->fullpath.len); - path.data[f->fullpath.len] = 0; - - - auto idents = binary_array_from_data(binary_files[i].idents, data.data); - for_array(j, f_map->idents) { - Ast *ast = f_map->idents[j]; - GB_ASSERT(ast->kind == Ast_Ident); - - Entity *e = ast->Ident.entity; - TokenPos def = e->token.pos; - AstFile *def_file = e->file; - - if (def_file == nullptr) { - auto *def_file_found = string_map_get(&c->info.files, get_file_path_string(e->token.pos.file_id)); - if (def_file_found == nullptr) { - continue; - } - def_file = *def_file_found; - } - - isize file_index = file_id_map_to_index[def_file->id]; - GB_ASSERT(file_index >= 0); - - idents[j].use_offset = cast(u64)ast->Ident.token.pos.offset; - idents[j].len = cast(u32)ast->Ident.token.string.len; - idents[j].def_file_id = cast(u32)def_file->id; - idents[j].def_offset = cast(u64)e->token.pos.offset; - - // gb_printf_err("%llu %llu %llu %llu\n", idents[j].len, idents[j].use_offset, idents[j].def_file_id, idents[j].def_offset); - } - - file_path_offset_index += cast(u32)(f->fullpath.len + 1); - idents_offset_index += cast(u32)(f_map->idents.count * gb_size_of(GoToDefIdent)); - } - - - gb_file_write(gb_file_get_standard(gbFileStandard_Output), data.data, data.count*gb_size_of(*data.data)); -} - diff --git a/src/range_cache.cpp b/src/range_cache.cpp index 1f98c4b9e..fc85e2a2e 100644 --- a/src/range_cache.cpp +++ b/src/range_cache.cpp @@ -59,12 +59,12 @@ gb_internal bool range_cache_add_range(RangeCache *c, i64 lo, i64 hi) { } -gb_internal bool range_cache_index_exists(RangeCache *c, i64 index) { - for_array(i, c->ranges) { - RangeValue v = c->ranges[i]; - if (v.lo <= index && index <= v.hi) { - return true; - } - } - return false; -} +// gb_internal bool range_cache_index_exists(RangeCache *c, i64 index) { +// for_array(i, c->ranges) { +// RangeValue v = c->ranges[i]; +// if (v.lo <= index && index <= v.hi) { +// return true; +// } +// } +// return false; +// } diff --git a/src/string.cpp b/src/string.cpp index aeb31c7b0..8cce0f1ef 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -89,14 +89,6 @@ gb_internal char *alloc_cstring(gbAllocator a, String s) { return c_str; } -gb_internal char *cstring_duplicate(gbAllocator a, char const *s) { - isize len = gb_strlen(s); - char *c_str = gb_alloc_array(a, char, len+1); - gb_memmove(c_str, s, len); - c_str[len] = '\0'; - return c_str; -} - gb_internal gb_inline bool str_eq_ignore_case(String const &a, String const &b) { @@ -166,12 +158,6 @@ gb_internal isize string_index_byte(String const &s, u8 x) { return -1; } -gb_internal GB_COMPARE_PROC(string_cmp_proc) { - String x = *(String *)a; - String y = *(String *)b; - return string_compare(x, y); -} - gb_internal gb_inline bool str_eq(String const &a, String const &b) { if (a.len != b.len) return false; return memcmp(a.text, b.text, a.len) == 0; diff --git a/src/string_map.cpp b/src/string_map.cpp index e289d4c9b..9f9374ece 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -18,8 +18,6 @@ gb_internal gb_inline bool string_hash_key_equal(StringHashKey const &a, StringH } return false; } -gb_internal bool operator==(StringHashKey const &a, StringHashKey const &b) { return string_hash_key_equal(a, b); } -gb_internal bool operator!=(StringHashKey const &a, StringHashKey const &b) { return !string_hash_key_equal(a, b); } template struct StringMapEntry { diff --git a/src/threading.cpp b/src/threading.cpp index 511d1b477..b74d087b4 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -1,6 +1,10 @@ #if defined(GB_SYSTEM_LINUX) #include #endif +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(push) + #pragma warning(disable: 4505) +#endif struct BlockingMutex; struct RecursiveMutex; @@ -269,48 +273,6 @@ struct MutexGuard { } #endif - - -struct Barrier { - BlockingMutex mutex; - Condition cond; - isize index; - isize generation_id; - isize thread_count; -}; - -gb_internal void barrier_init(Barrier *b, isize thread_count) { - mutex_init(&b->mutex); - condition_init(&b->cond); - b->index = 0; - b->generation_id = 0; - b->thread_count = 0; -} - -gb_internal void barrier_destroy(Barrier *b) { - condition_destroy(&b->cond); - mutex_destroy(&b->mutex); -} - -// Returns true if it is the leader -gb_internal bool barrier_wait(Barrier *b) { - mutex_lock(&b->mutex); - defer (mutex_unlock(&b->mutex)); - isize local_gen = b->generation_id; - b->index += 1; - if (b->index < b->thread_count) { - while (local_gen == b->generation_id && b->index < b->thread_count) { - condition_wait(&b->cond, &b->mutex); - } - return false; - } - b->index = 0; - b->generation_id += 1; - condition_broadcast(&b->cond); - return true; -} - - gb_internal u32 thread_current_id(void) { @@ -494,3 +456,7 @@ gb_internal void thread_set_name(Thread *t, char const *name) { #endif } + +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(pop) +#endif \ No newline at end of file diff --git a/src/types.cpp b/src/types.cpp index c8e24f01d..b1d3883c6 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -430,15 +430,6 @@ gb_internal Selection sub_selection(Selection const &sel, isize offset) { return res; } -gb_internal Selection sub_selection_with_length(Selection const &sel, isize offset, isize len) { - Selection res = {}; - res.index.data = sel.index.data + offset; - res.index.count = gb_max(len, gb_max(sel.index.count - offset, 0)); - res.index.capacity = res.index.count; - return res; -} - - gb_global Type basic_types[] = { {Type_Basic, {Basic_Invalid, 0, 0, STR_LIT("invalid type")}}, @@ -1089,15 +1080,6 @@ gb_internal Type *alloc_type_proc(Scope *scope, Type *params, isize param_count, gb_internal bool is_type_valid_for_keys(Type *t); -gb_internal Type *alloc_type_map(i64 count, Type *key, Type *value) { - if (key != nullptr) { - GB_ASSERT(value != nullptr); - } - Type *t = alloc_type(Type_Map); - t->Map.key = key; - t->Map.value = value; - return t; -} gb_internal Type *alloc_type_bit_set() { Type *t = alloc_type(Type_BitSet); @@ -1152,19 +1134,6 @@ gb_internal bool is_type_named(Type *t) { } return t->kind == Type_Named; } -gb_internal bool is_type_named_alias(Type *t) { - if (!is_type_named(t)) { - return false; - } - Entity *e = t->Named.type_name; - if (e == nullptr) { - return false; - } - if (e->kind != Entity_TypeName) { - return false; - } - return e->TypeName.is_type_alias; -} gb_internal bool is_type_boolean(Type *t) { // t = core_type(t); @@ -1329,27 +1298,6 @@ gb_internal bool is_type_complex_or_quaternion(Type *t) { } return false; } -gb_internal bool is_type_f16(Type *t) { - t = core_type(t); - if (t->kind == Type_Basic) { - return t->Basic.kind == Basic_f16; - } - return false; -} -gb_internal bool is_type_f32(Type *t) { - t = core_type(t); - if (t->kind == Type_Basic) { - return t->Basic.kind == Basic_f32; - } - return false; -} -gb_internal bool is_type_f64(Type *t) { - t = core_type(t); - if (t->kind == Type_Basic) { - return t->Basic.kind == Basic_f64; - } - return false; -} gb_internal bool is_type_pointer(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { @@ -1550,10 +1498,6 @@ gb_internal bool is_type_asm_proc(Type *t) { t = base_type(t); return t->kind == Type_Proc && t->Proc.calling_convention == ProcCC_InlineAsm; } -gb_internal bool is_type_poly_proc(Type *t) { - t = base_type(t); - return t->kind == Type_Proc && t->Proc.is_polymorphic; -} gb_internal bool is_type_simd_vector(Type *t) { t = base_type(t); return t->kind == Type_SimdVector; @@ -1915,11 +1859,6 @@ gb_internal bool is_type_empty_union(Type *t) { t = base_type(t); return t->kind == Type_Union && t->Union.variants.count == 0; } -gb_internal bool is_type_empty_struct(Type *t) { - t = base_type(t); - return t->kind == Type_Struct && !t->Struct.is_raw_union && t->Struct.fields.count == 0; -} - gb_internal bool is_type_valid_for_keys(Type *t) { t = core_type(t); @@ -4051,20 +3990,6 @@ gb_internal Type *reduce_tuple_to_single_type(Type *original_type) { return original_type; } - -gb_internal Type *alloc_type_struct_from_field_types(Type **field_types, isize field_count, bool is_packed) { - Type *t = alloc_type_struct(); - t->Struct.fields = slice_make(heap_allocator(), field_count); - - Scope *scope = nullptr; - for_array(i, t->Struct.fields) { - t->Struct.fields[i] = alloc_entity_field(scope, blank_token, field_types[i], false, cast(i32)i, EntityState_Resolved); - } - t->Struct.is_packed = is_packed; - - return t; -} - gb_internal Type *alloc_type_tuple_from_field_types(Type **field_types, isize field_count, bool is_packed, bool must_be_tuple) { if (field_count == 0) { return nullptr; -- cgit v1.2.3