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/exact_value.cpp | 90 ++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'src/exact_value.cpp') 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); } -- cgit v1.2.3 From 056ba1ed13b36c8a85d7415f5a288a4780cb55f8 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 21:24:45 +0000 Subject: Even more `gb_internal` everywhere --- src/checker.hpp | 84 +++++------ src/entity.cpp | 52 +++---- src/exact_value.cpp | 8 +- src/types.cpp | 428 ++++++++++++++++++++++++++-------------------------- 4 files changed, 286 insertions(+), 286 deletions(-) (limited to 'src/exact_value.cpp') diff --git a/src/checker.hpp b/src/checker.hpp index 37232ea95..e1efd5b89 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -20,7 +20,7 @@ struct ExprInfo { ExactValue value; }; -gb_inline ExprInfo *make_expr_info(AddressingMode mode, Type *type, ExactValue const &value, bool is_lhs) { +gb_internal gb_inline ExprInfo *make_expr_info(AddressingMode mode, Type *type, ExactValue const &value, bool is_lhs) { ExprInfo *ei = gb_alloc_item(permanent_allocator(), ExprInfo); ei->mode = mode; ei->type = type; @@ -130,7 +130,7 @@ struct AttributeContext { String enable_target_feature; // will be enabled for the procedure only }; -AttributeContext make_attribute_context(String link_prefix) { +gb_internal gb_inline AttributeContext make_attribute_context(String link_prefix) { AttributeContext ac = {}; ac.link_prefix = link_prefix; return ac; @@ -139,7 +139,7 @@ AttributeContext make_attribute_context(String link_prefix) { #define DECL_ATTRIBUTE_PROC(_name) bool _name(CheckerContext *c, Ast *elem, String name, Ast *value, AttributeContext *ac) typedef DECL_ATTRIBUTE_PROC(DeclAttributeProc); -void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac); +gb_internal void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac); // DeclInfo is used to store information of certain declarations to allow for "any order" usage @@ -443,59 +443,59 @@ gb_global AstPackage *config_pkg = nullptr; // CheckerInfo API -TypeAndValue type_and_value_of_expr (Ast *expr); -Type * type_of_expr (Ast *expr); -Entity * implicit_entity_of_node(Ast *clause); -DeclInfo * decl_info_of_ident (Ast *ident); -DeclInfo * decl_info_of_entity (Entity * e); -AstFile * ast_file_of_filename (CheckerInfo *i, String filename); +gb_internal TypeAndValue type_and_value_of_expr (Ast *expr); +gb_internal Type * type_of_expr (Ast *expr); +gb_internal Entity * implicit_entity_of_node(Ast *clause); +gb_internal DeclInfo * decl_info_of_ident (Ast *ident); +gb_internal DeclInfo * decl_info_of_entity (Entity * e); +gb_internal AstFile * ast_file_of_filename (CheckerInfo *i, String filename); // IMPORTANT: Only to use once checking is done -isize type_info_index (CheckerInfo *i, Type *type, bool error_on_failure); +gb_internal isize type_info_index (CheckerInfo *i, Type *type, bool error_on_failure); // Will return nullptr if not found -Entity *entity_of_node(Ast *expr); +gb_internal Entity *entity_of_node(Ast *expr); -Entity *scope_lookup_current(Scope *s, String const &name); -Entity *scope_lookup (Scope *s, String const &name); -void scope_lookup_parent (Scope *s, String const &name, Scope **scope_, Entity **entity_); -Entity *scope_insert (Scope *s, Entity *entity, bool use_mutex=true); +gb_internal Entity *scope_lookup_current(Scope *s, String const &name); +gb_internal Entity *scope_lookup (Scope *s, String const &name); +gb_internal void scope_lookup_parent (Scope *s, String const &name, Scope **scope_, Entity **entity_); +gb_internal Entity *scope_insert (Scope *s, Entity *entity, bool use_mutex=true); -void add_type_and_value (CheckerInfo *i, Ast *expression, AddressingMode mode, Type *type, ExactValue value); -ExprInfo *check_get_expr_info (CheckerContext *c, Ast *expr); -void add_untyped (CheckerContext *c, Ast *expression, AddressingMode mode, Type *basic_type, ExactValue value); -void add_entity_use (CheckerContext *c, Ast *identifier, Entity *entity); -void add_implicit_entity (CheckerContext *c, Ast *node, Entity *e); -void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, DeclInfo *d, bool is_exported=true); -void add_type_info_type (CheckerContext *c, Type *t); +gb_internal void add_type_and_value (CheckerInfo *i, Ast *expression, AddressingMode mode, Type *type, ExactValue value); +gb_internal ExprInfo *check_get_expr_info (CheckerContext *c, Ast *expr); +gb_internal void add_untyped (CheckerContext *c, Ast *expression, AddressingMode mode, Type *basic_type, ExactValue value); +gb_internal void add_entity_use (CheckerContext *c, Ast *identifier, Entity *entity); +gb_internal void add_implicit_entity (CheckerContext *c, Ast *node, Entity *e); +gb_internal void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, DeclInfo *d, bool is_exported=true); +gb_internal void add_type_info_type (CheckerContext *c, Type *t); -void check_add_import_decl(CheckerContext *c, Ast *decl); -void check_add_foreign_import_decl(CheckerContext *c, Ast *decl); +gb_internal void check_add_import_decl(CheckerContext *c, Ast *decl); +gb_internal void check_add_foreign_import_decl(CheckerContext *c, Ast *decl); -void check_entity_decl(CheckerContext *c, Entity *e, DeclInfo *d, Type *named_type); -void check_const_decl(CheckerContext *c, Entity *e, Ast *type_expr, Ast *init_expr, Type *named_type); -void check_type_decl(CheckerContext *c, Entity *e, Ast *type_expr, Type *def); +gb_internal void check_entity_decl(CheckerContext *c, Entity *e, DeclInfo *d, Type *named_type); +gb_internal void check_const_decl(CheckerContext *c, Entity *e, Ast *type_expr, Ast *init_expr, Type *named_type); +gb_internal void check_type_decl(CheckerContext *c, Entity *e, Ast *type_expr, Type *def); -bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global = false); -void check_collect_entities(CheckerContext *c, Slice const &nodes); -void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws); -void check_delayed_file_import_entity(CheckerContext *c, Ast *decl); +gb_internal bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global = false); +gb_internal void check_collect_entities(CheckerContext *c, Slice const &nodes); +gb_internal void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws); +gb_internal void check_delayed_file_import_entity(CheckerContext *c, Ast *decl); -CheckerTypePath *new_checker_type_path(); -void destroy_checker_type_path(CheckerTypePath *tp); +gb_internal CheckerTypePath *new_checker_type_path(); +gb_internal void destroy_checker_type_path(CheckerTypePath *tp); -void check_type_path_push(CheckerContext *c, Entity *e); -Entity *check_type_path_pop (CheckerContext *c); +gb_internal void check_type_path_push(CheckerContext *c, Entity *e); +gb_internal Entity *check_type_path_pop (CheckerContext *c); -CheckerPolyPath *new_checker_poly_path(); -void destroy_checker_poly_path(CheckerPolyPath *); +gb_internal CheckerPolyPath *new_checker_poly_path(); +gb_internal void destroy_checker_poly_path(CheckerPolyPath *); -void check_poly_path_push(CheckerContext *c, Type *t); -Type *check_poly_path_pop (CheckerContext *c); +gb_internal void check_poly_path_push(CheckerContext *c, Type *t); +gb_internal Type *check_poly_path_pop (CheckerContext *c); -void init_core_context(Checker *c); -void init_mem_allocator(Checker *c); +gb_internal void init_core_context(Checker *c); +gb_internal void init_mem_allocator(Checker *c); -void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped); +gb_internal void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped); diff --git a/src/entity.cpp b/src/entity.cpp index 3d3712328..6a3a69950 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -26,7 +26,7 @@ enum EntityKind { Entity_Count, }; -String const entity_strings[] = { +gb_global String const entity_strings[] = { #define ENTITY_KIND(k) {cast(u8 *)#k, gb_size_of(#k)-1}, ENTITY_KINDS #undef ENTITY_KIND @@ -116,7 +116,7 @@ struct ParameterValue { }; }; -bool has_parameter_value(ParameterValue const ¶m_value) { +gb_internal gb_inline bool has_parameter_value(ParameterValue const ¶m_value) { if (param_value.kind != ParameterValue_Invalid) { return true; } @@ -151,7 +151,7 @@ struct TypeNameObjCMetadata { Array value_entries; }; -TypeNameObjCMetadata *create_type_name_obj_c_metadata() { +gb_internal TypeNameObjCMetadata *create_type_name_obj_c_metadata() { TypeNameObjCMetadata *md = gb_alloc_item(permanent_allocator(), TypeNameObjCMetadata); md->mutex = gb_alloc_item(permanent_allocator(), BlockingMutex); mutex_init(md->mutex); @@ -266,7 +266,7 @@ struct Entity { }; }; -bool is_entity_kind_exported(EntityKind kind, bool allow_builtin = false) { +gb_internal bool is_entity_kind_exported(EntityKind kind, bool allow_builtin = false) { switch (kind) { case Entity_Builtin: return allow_builtin; @@ -278,7 +278,7 @@ bool is_entity_kind_exported(EntityKind kind, bool allow_builtin = false) { return true; } -bool is_entity_exported(Entity *e, bool allow_builtin = false) { +gb_internal bool is_entity_exported(Entity *e, bool allow_builtin = false) { // TODO(bill): Determine the actual exportation rules for imports of entities GB_ASSERT(e != nullptr); if (!is_entity_kind_exported(e->kind, allow_builtin)) { @@ -300,7 +300,7 @@ bool is_entity_exported(Entity *e, bool allow_builtin = false) { return true; } -bool entity_has_deferred_procedure(Entity *e) { +gb_internal bool entity_has_deferred_procedure(Entity *e) { GB_ASSERT(e != nullptr); if (e->kind == Entity_Procedure) { return e->Procedure.deferred_procedure.entity != nullptr; @@ -311,7 +311,7 @@ bool entity_has_deferred_procedure(Entity *e) { gb_global std::atomic global_entity_id; -Entity *alloc_entity(EntityKind kind, Scope *scope, Token token, Type *type) { +gb_internal Entity *alloc_entity(EntityKind kind, Scope *scope, Token token, Type *type) { gbAllocator a = permanent_allocator(); Entity *entity = gb_alloc_item(a, Entity); entity->kind = kind; @@ -323,13 +323,13 @@ Entity *alloc_entity(EntityKind kind, Scope *scope, Token token, Type *type) { return entity; } -Entity *alloc_entity_variable(Scope *scope, Token token, Type *type, EntityState state = EntityState_Unresolved) { +gb_internal Entity *alloc_entity_variable(Scope *scope, Token token, Type *type, EntityState state = EntityState_Unresolved) { Entity *entity = alloc_entity(Entity_Variable, scope, token, type); entity->state = state; return entity; } -Entity *alloc_entity_using_variable(Entity *parent, Token token, Type *type, Ast *using_expr) { +gb_internal Entity *alloc_entity_using_variable(Entity *parent, Token token, Type *type, Ast *using_expr) { GB_ASSERT(parent != nullptr); token.pos = parent->token.pos; Entity *entity = alloc_entity(Entity_Variable, parent->scope, token, type); @@ -343,19 +343,19 @@ Entity *alloc_entity_using_variable(Entity *parent, Token token, Type *type, Ast } -Entity *alloc_entity_constant(Scope *scope, Token token, Type *type, ExactValue value) { +gb_internal Entity *alloc_entity_constant(Scope *scope, Token token, Type *type, ExactValue value) { Entity *entity = alloc_entity(Entity_Constant, scope, token, type); entity->Constant.value = value; return entity; } -Entity *alloc_entity_type_name(Scope *scope, Token token, Type *type, EntityState state = EntityState_Unresolved) { +gb_internal Entity *alloc_entity_type_name(Scope *scope, Token token, Type *type, EntityState state = EntityState_Unresolved) { Entity *entity = alloc_entity(Entity_TypeName, scope, token, type); entity->state = state; return entity; } -Entity *alloc_entity_param(Scope *scope, Token token, Type *type, bool is_using, bool is_value) { +gb_internal Entity *alloc_entity_param(Scope *scope, Token token, Type *type, bool is_using, bool is_value) { Entity *entity = alloc_entity_variable(scope, token, type); entity->flags |= EntityFlag_Used; entity->flags |= EntityFlag_Param; @@ -366,7 +366,7 @@ Entity *alloc_entity_param(Scope *scope, Token token, Type *type, bool is_using, } -Entity *alloc_entity_const_param(Scope *scope, Token token, Type *type, ExactValue value, bool poly_const) { +gb_internal Entity *alloc_entity_const_param(Scope *scope, Token token, Type *type, ExactValue value, bool poly_const) { Entity *entity = alloc_entity_constant(scope, token, type, value); entity->flags |= EntityFlag_Used; if (poly_const) entity->flags |= EntityFlag_PolyConst; @@ -375,7 +375,7 @@ Entity *alloc_entity_const_param(Scope *scope, Token token, Type *type, ExactVal } -Entity *alloc_entity_field(Scope *scope, Token token, Type *type, bool is_using, i32 field_index, EntityState state = EntityState_Unresolved) { +gb_internal Entity *alloc_entity_field(Scope *scope, Token token, Type *type, bool is_using, i32 field_index, EntityState state = EntityState_Unresolved) { Entity *entity = alloc_entity_variable(scope, token, type); entity->Variable.field_index = field_index; if (is_using) entity->flags |= EntityFlag_Using; @@ -384,7 +384,7 @@ Entity *alloc_entity_field(Scope *scope, Token token, Type *type, bool is_using, return entity; } -Entity *alloc_entity_array_elem(Scope *scope, Token token, Type *type, i32 field_index) { +gb_internal Entity *alloc_entity_array_elem(Scope *scope, Token token, Type *type, i32 field_index) { Entity *entity = alloc_entity_variable(scope, token, type); entity->Variable.field_index = field_index; entity->flags |= EntityFlag_Field; @@ -393,26 +393,26 @@ Entity *alloc_entity_array_elem(Scope *scope, Token token, Type *type, i32 field return entity; } -Entity *alloc_entity_procedure(Scope *scope, Token token, Type *signature_type, u64 tags) { +gb_internal Entity *alloc_entity_procedure(Scope *scope, Token token, Type *signature_type, u64 tags) { Entity *entity = alloc_entity(Entity_Procedure, scope, token, signature_type); entity->Procedure.tags = tags; return entity; } -Entity *alloc_entity_proc_group(Scope *scope, Token token, Type *type) { +gb_internal Entity *alloc_entity_proc_group(Scope *scope, Token token, Type *type) { Entity *entity = alloc_entity(Entity_ProcGroup, scope, token, type); return entity; } -Entity *alloc_entity_builtin(Scope *scope, Token token, Type *type, i32 id) { +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; } -Entity *alloc_entity_import_name(Scope *scope, Token token, Type *type, +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); entity->ImportName.path = path; @@ -422,7 +422,7 @@ Entity *alloc_entity_import_name(Scope *scope, Token token, Type *type, return entity; } -Entity *alloc_entity_library_name(Scope *scope, Token token, Type *type, +gb_internal Entity *alloc_entity_library_name(Scope *scope, Token token, Type *type, Slice paths, String name) { Entity *entity = alloc_entity(Entity_LibraryName, scope, token, type); entity->LibraryName.paths = paths; @@ -435,12 +435,12 @@ Entity *alloc_entity_library_name(Scope *scope, Token token, Type *type, -Entity *alloc_entity_nil(String name, Type *type) { +gb_internal Entity *alloc_entity_nil(String name, Type *type) { Entity *entity = alloc_entity(Entity_Nil, nullptr, make_token_ident(name), type); return entity; } -Entity *alloc_entity_label(Scope *scope, Token token, Type *type, Ast *node, Ast *parent) { +gb_internal Entity *alloc_entity_label(Scope *scope, Token token, Type *type, Ast *node, Ast *parent) { Entity *entity = alloc_entity(Entity_Label, scope, token, type); entity->Label.node = node; entity->Label.parent = parent; @@ -448,15 +448,15 @@ Entity *alloc_entity_label(Scope *scope, Token token, Type *type, Ast *node, Ast return entity; } -Entity *alloc_entity_dummy_variable(Scope *scope, Token token) { +gb_internal Entity *alloc_entity_dummy_variable(Scope *scope, Token token) { token.string = str_lit("_"); return alloc_entity_variable(scope, token, nullptr); } -Entity *entity_from_expr(Ast *expr); +gb_internal Entity *entity_from_expr(Ast *expr); -Entity *strip_entity_wrapping(Entity *e) { +gb_internal Entity *strip_entity_wrapping(Entity *e) { if (e == nullptr) { return nullptr; } @@ -469,7 +469,7 @@ Entity *strip_entity_wrapping(Entity *e) { return e; } -Entity *strip_entity_wrapping(Ast *expr) { +gb_internal Entity *strip_entity_wrapping(Ast *expr) { Entity *e = entity_from_expr(expr); return strip_entity_wrapping(e); } diff --git a/src/exact_value.cpp b/src/exact_value.cpp index d3ea4be68..453909a15 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -6,7 +6,7 @@ struct Ast; struct HashKey; struct Type; struct Entity; -bool are_types_identical(Type *x, Type *y); +gb_internal bool are_types_identical(Type *x, Type *y); struct Complex128 { f64 real, imag; @@ -969,10 +969,10 @@ gb_internal bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) return false; } -Entity *strip_entity_wrapping(Ast *expr); -Entity *strip_entity_wrapping(Entity *e); +gb_internal Entity *strip_entity_wrapping(Ast *expr); +gb_internal Entity *strip_entity_wrapping(Entity *e); -gbString write_expr_to_string(gbString str, Ast *node, bool shorthand); +gb_internal gbString write_expr_to_string(gbString str, Ast *node, bool shorthand); gb_internal gbString write_exact_value_to_string(gbString str, ExactValue const &v, isize string_limit=36) { switch (v.kind) { diff --git a/src/types.cpp b/src/types.cpp index 7b6942525..2ab7374c2 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -287,7 +287,7 @@ enum TypeKind { Type_Count, }; -String const type_strings[] = { +gb_global String const type_strings[] = { {cast(u8 *)"Invalid", gb_size_of("Invalid")}, #define TYPE_KIND(k, ...) {cast(u8 *)#k, gb_size_of(#k)-1}, TYPE_KINDS @@ -368,10 +368,10 @@ enum : int { }; -bool is_type_comparable(Type *t); -bool is_type_simple_compare(Type *t); +gb_internal bool is_type_comparable(Type *t); +gb_internal bool is_type_simple_compare(Type *t); -u32 type_info_flags_of_type(Type *type) { +gb_internal u32 type_info_flags_of_type(Type *type) { if (type == nullptr) { return 0; } @@ -396,14 +396,14 @@ struct Selection { u8 swizzle_indices; // 2 bits per component, representing which swizzle index bool pseudo_field; }; -Selection empty_selection = {0}; +gb_global Selection const empty_selection = {0}; -Selection make_selection(Entity *entity, Array index, bool indirect) { +gb_internal Selection make_selection(Entity *entity, Array index, bool indirect) { Selection s = {entity, index, indirect}; return s; } -void selection_add_index(Selection *s, isize index) { +gb_internal void selection_add_index(Selection *s, isize index) { // IMPORTANT NOTE(bill): this requires a stretchy buffer/dynamic array so it requires some form // of heap allocation // TODO(bill): Find a way to use a backing buffer for initial use as the general case is probably .count<3 @@ -413,7 +413,7 @@ void selection_add_index(Selection *s, isize index) { array_add(&s->index, cast(i32)index); } -Selection selection_combine(Selection const &lhs, Selection const &rhs) { +gb_internal Selection selection_combine(Selection const &lhs, Selection const &rhs) { Selection new_sel = lhs; new_sel.indirect = lhs.indirect || rhs.indirect; new_sel.index = array_make(heap_allocator(), lhs.index.count+rhs.index.count); @@ -422,7 +422,7 @@ Selection selection_combine(Selection const &lhs, Selection const &rhs) { return new_sel; } -Selection sub_selection(Selection const &sel, isize offset) { +gb_internal Selection sub_selection(Selection const &sel, isize offset) { Selection res = {}; res.index.data = sel.index.data + offset; res.index.count = gb_max(sel.index.count - offset, 0); @@ -430,7 +430,7 @@ Selection sub_selection(Selection const &sel, isize offset) { return res; } -Selection sub_selection_with_length(Selection const &sel, isize offset, isize len) { +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)); @@ -732,26 +732,26 @@ gb_global RecursiveMutex g_type_mutex; struct TypePath; -i64 type_size_of (Type *t); -i64 type_align_of (Type *t); -i64 type_offset_of (Type *t, i32 index); -gbString type_to_string (Type *type, bool shorthand=true); -gbString type_to_string (Type *type, gbAllocator allocator, bool shorthand=true); -i64 type_size_of_internal(Type *t, TypePath *path); -void init_map_internal_types(Type *type); -Type * bit_set_to_int(Type *t); -bool are_types_identical(Type *x, Type *y); +gb_internal i64 type_size_of (Type *t); +gb_internal i64 type_align_of (Type *t); +gb_internal i64 type_offset_of (Type *t, i32 index); +gb_internal gbString type_to_string (Type *type, bool shorthand=true); +gb_internal gbString type_to_string (Type *type, gbAllocator allocator, bool shorthand=true); +gb_internal i64 type_size_of_internal(Type *t, TypePath *path); +gb_internal void init_map_internal_types(Type *type); +gb_internal Type * bit_set_to_int(Type *t); +gb_internal bool are_types_identical(Type *x, Type *y); -bool is_type_pointer(Type *t); -bool is_type_soa_pointer(Type *t); -bool is_type_proc(Type *t); -bool is_type_slice(Type *t); -bool is_type_integer(Type *t); -bool type_set_offsets(Type *t); -Type *base_type(Type *t); +gb_internal bool is_type_pointer(Type *t); +gb_internal bool is_type_soa_pointer(Type *t); +gb_internal bool is_type_proc(Type *t); +gb_internal bool is_type_slice(Type *t); +gb_internal bool is_type_integer(Type *t); +gb_internal bool type_set_offsets(Type *t); +gb_internal Type *base_type(Type *t); -i64 type_size_of_internal(Type *t, TypePath *path); -i64 type_align_of_internal(Type *t, TypePath *path); +gb_internal i64 type_size_of_internal(Type *t, TypePath *path); +gb_internal i64 type_align_of_internal(Type *t, TypePath *path); // IMPORTANT TODO(bill): SHould this TypePath code be removed since type cycle checking is handled much earlier on? @@ -762,15 +762,15 @@ struct TypePath { }; -void type_path_init(TypePath *tp) { +gb_internal void type_path_init(TypePath *tp) { tp->path.allocator = heap_allocator(); } -void type_path_free(TypePath *tp) { +gb_internal void type_path_free(TypePath *tp) { array_free(&tp->path); } -void type_path_print_illegal_cycle(TypePath *tp, isize start_index) { +gb_internal void type_path_print_illegal_cycle(TypePath *tp, isize start_index) { GB_ASSERT(tp != nullptr); GB_ASSERT(start_index < tp->path.count); @@ -789,7 +789,7 @@ void type_path_print_illegal_cycle(TypePath *tp, isize start_index) { base_type(e->type)->failure = true; } -bool type_path_push(TypePath *tp, Type *t) { +gb_internal bool type_path_push(TypePath *tp, Type *t) { GB_ASSERT(tp != nullptr); if (t->kind != Type_Named) { return false; @@ -807,7 +807,7 @@ bool type_path_push(TypePath *tp, Type *t) { return true; } -void type_path_pop(TypePath *tp) { +gb_internal void type_path_pop(TypePath *tp) { if (tp != nullptr && tp->path.count > 0) { array_pop(&tp->path); } @@ -817,11 +817,11 @@ void type_path_pop(TypePath *tp) { #define FAILURE_SIZE 0 #define FAILURE_ALIGNMENT 0 -void init_type_mutex(void) { +gb_internal void init_type_mutex(void) { mutex_init(&g_type_mutex); } -bool type_ptr_set_exists(PtrSet *s, Type *t) { +gb_internal bool type_ptr_set_exists(PtrSet *s, Type *t) { if (ptr_set_exists(s, t)) { return true; } @@ -839,7 +839,7 @@ bool type_ptr_set_exists(PtrSet *s, Type *t) { return false; } -Type *base_type(Type *t) { +gb_internal Type *base_type(Type *t) { for (;;) { if (t == nullptr) { break; @@ -855,7 +855,7 @@ Type *base_type(Type *t) { return t; } -Type *base_enum_type(Type *t) { +gb_internal Type *base_enum_type(Type *t) { Type *bt = base_type(t); if (bt != nullptr && bt->kind == Type_Enum) { @@ -864,7 +864,7 @@ Type *base_enum_type(Type *t) { return t; } -Type *core_type(Type *t) { +gb_internal Type *core_type(Type *t) { for (;;) { if (t == nullptr) { break; @@ -886,14 +886,14 @@ Type *core_type(Type *t) { return t; } -void set_base_type(Type *t, Type *base) { +gb_internal void set_base_type(Type *t, Type *base) { if (t && t->kind == Type_Named) { t->Named.base = base; } } -Type *alloc_type(TypeKind kind) { +gb_internal Type *alloc_type(TypeKind kind) { // gbAllocator a = heap_allocator(); gbAllocator a = permanent_allocator(); Type *t = gb_alloc_item(a, Type); @@ -905,7 +905,7 @@ Type *alloc_type(TypeKind kind) { } -Type *alloc_type_generic(Scope *scope, i64 id, String name, Type *specialized) { +gb_internal Type *alloc_type_generic(Scope *scope, i64 id, String name, Type *specialized) { Type *t = alloc_type(Type_Generic); t->Generic.id = id; t->Generic.name = name; @@ -914,26 +914,26 @@ Type *alloc_type_generic(Scope *scope, i64 id, String name, Type *specialized) { return t; } -Type *alloc_type_pointer(Type *elem) { +gb_internal Type *alloc_type_pointer(Type *elem) { Type *t = alloc_type(Type_Pointer); t->Pointer.elem = elem; return t; } -Type *alloc_type_multi_pointer(Type *elem) { +gb_internal Type *alloc_type_multi_pointer(Type *elem) { Type *t = alloc_type(Type_MultiPointer); t->MultiPointer.elem = elem; return t; } -Type *alloc_type_soa_pointer(Type *elem) { +gb_internal Type *alloc_type_soa_pointer(Type *elem) { Type *t = alloc_type(Type_SoaPointer); t->SoaPointer.elem = elem; return t; } -Type *alloc_type_array(Type *elem, i64 count, Type *generic_count = nullptr) { +gb_internal Type *alloc_type_array(Type *elem, i64 count, Type *generic_count = nullptr) { if (generic_count != nullptr) { Type *t = alloc_type(Type_Array); t->Array.elem = elem; @@ -947,7 +947,7 @@ Type *alloc_type_array(Type *elem, i64 count, Type *generic_count = nullptr) { return t; } -Type *alloc_type_matrix(Type *elem, i64 row_count, i64 column_count, Type *generic_row_count = nullptr, Type *generic_column_count = nullptr) { +gb_internal Type *alloc_type_matrix(Type *elem, i64 row_count, i64 column_count, Type *generic_row_count = nullptr, Type *generic_column_count = nullptr) { if (generic_row_count != nullptr || generic_column_count != nullptr) { Type *t = alloc_type(Type_Matrix); t->Matrix.elem = elem; @@ -965,7 +965,7 @@ Type *alloc_type_matrix(Type *elem, i64 row_count, i64 column_count, Type *gener } -Type *alloc_type_enumerated_array(Type *elem, Type *index, ExactValue const *min_value, ExactValue const *max_value, TokenKind op) { +gb_internal Type *alloc_type_enumerated_array(Type *elem, Type *index, ExactValue const *min_value, ExactValue const *max_value, TokenKind op) { Type *t = alloc_type(Type_EnumeratedArray); t->EnumeratedArray.elem = elem; t->EnumeratedArray.index = index; @@ -980,37 +980,37 @@ Type *alloc_type_enumerated_array(Type *elem, Type *index, ExactValue const *min } -Type *alloc_type_slice(Type *elem) { +gb_internal Type *alloc_type_slice(Type *elem) { Type *t = alloc_type(Type_Slice); t->Array.elem = elem; return t; } -Type *alloc_type_dynamic_array(Type *elem) { +gb_internal Type *alloc_type_dynamic_array(Type *elem) { Type *t = alloc_type(Type_DynamicArray); t->DynamicArray.elem = elem; return t; } -Type *alloc_type_struct() { +gb_internal Type *alloc_type_struct() { Type *t = alloc_type(Type_Struct); return t; } -Type *alloc_type_union() { +gb_internal Type *alloc_type_union() { Type *t = alloc_type(Type_Union); return t; } -Type *alloc_type_enum() { +gb_internal Type *alloc_type_enum() { Type *t = alloc_type(Type_Enum); t->Enum.min_value = gb_alloc_item(permanent_allocator(), ExactValue); t->Enum.max_value = gb_alloc_item(permanent_allocator(), ExactValue); return t; } -Type *alloc_type_relative_pointer(Type *pointer_type, Type *base_integer) { +gb_internal Type *alloc_type_relative_pointer(Type *pointer_type, Type *base_integer) { GB_ASSERT(is_type_pointer(pointer_type)); GB_ASSERT(is_type_integer(base_integer)); Type *t = alloc_type(Type_RelativePointer); @@ -1019,7 +1019,7 @@ Type *alloc_type_relative_pointer(Type *pointer_type, Type *base_integer) { return t; } -Type *alloc_type_relative_slice(Type *slice_type, Type *base_integer) { +gb_internal Type *alloc_type_relative_slice(Type *slice_type, Type *base_integer) { GB_ASSERT(is_type_slice(slice_type)); GB_ASSERT(is_type_integer(base_integer)); Type *t = alloc_type(Type_RelativeSlice); @@ -1028,7 +1028,7 @@ Type *alloc_type_relative_slice(Type *slice_type, Type *base_integer) { return t; } -Type *alloc_type_named(String name, Type *base, Entity *type_name) { +gb_internal Type *alloc_type_named(String name, Type *base, Entity *type_name) { Type *t = alloc_type(Type_Named); t->Named.name = name; t->Named.base = base; @@ -1039,7 +1039,7 @@ Type *alloc_type_named(String name, Type *base, Entity *type_name) { return t; } -bool is_calling_convention_none(ProcCallingConvention calling_convention) { +gb_internal bool is_calling_convention_none(ProcCallingConvention calling_convention) { switch (calling_convention) { case ProcCC_None: case ProcCC_InlineAsm: @@ -1048,7 +1048,7 @@ bool is_calling_convention_none(ProcCallingConvention calling_convention) { return false; } -bool is_calling_convention_odin(ProcCallingConvention calling_convention) { +gb_internal bool is_calling_convention_odin(ProcCallingConvention calling_convention) { switch (calling_convention) { case ProcCC_Odin: case ProcCC_Contextless: @@ -1057,12 +1057,12 @@ bool is_calling_convention_odin(ProcCallingConvention calling_convention) { return false; } -Type *alloc_type_tuple() { +gb_internal Type *alloc_type_tuple() { Type *t = alloc_type(Type_Tuple); return t; } -Type *alloc_type_proc(Scope *scope, Type *params, isize param_count, Type *results, isize result_count, bool variadic, ProcCallingConvention calling_convention) { +gb_internal Type *alloc_type_proc(Scope *scope, Type *params, isize param_count, Type *results, isize result_count, bool variadic, ProcCallingConvention calling_convention) { Type *t = alloc_type(Type_Proc); if (variadic) { @@ -1087,9 +1087,9 @@ Type *alloc_type_proc(Scope *scope, Type *params, isize param_count, Type *resul return t; } -bool is_type_valid_for_keys(Type *t); +gb_internal bool is_type_valid_for_keys(Type *t); -Type *alloc_type_map(i64 count, Type *key, Type *value) { +gb_internal Type *alloc_type_map(i64 count, Type *key, Type *value) { if (key != nullptr) { GB_ASSERT(value != nullptr); } @@ -1099,14 +1099,14 @@ Type *alloc_type_map(i64 count, Type *key, Type *value) { return t; } -Type *alloc_type_bit_set() { +gb_internal Type *alloc_type_bit_set() { Type *t = alloc_type(Type_BitSet); return t; } -Type *alloc_type_simd_vector(i64 count, Type *elem, Type *generic_count=nullptr) { +gb_internal Type *alloc_type_simd_vector(i64 count, Type *elem, Type *generic_count=nullptr) { Type *t = alloc_type(Type_SimdVector); t->SimdVector.count = count; t->SimdVector.elem = elem; @@ -1119,7 +1119,7 @@ Type *alloc_type_simd_vector(i64 count, Type *elem, Type *generic_count=nullptr) //////////////////////////////////////////////////////////////// -Type *type_deref(Type *t, bool allow_multi_pointer=false) { +gb_internal Type *type_deref(Type *t, bool allow_multi_pointer=false) { if (t != nullptr) { Type *bt = base_type(t); if (bt == nullptr) { @@ -1146,13 +1146,13 @@ Type *type_deref(Type *t, bool allow_multi_pointer=false) { return t; } -bool is_type_named(Type *t) { +gb_internal bool is_type_named(Type *t) { if (t->kind == Type_Basic) { return true; } return t->kind == Type_Named; } -bool is_type_named_alias(Type *t) { +gb_internal bool is_type_named_alias(Type *t) { if (!is_type_named(t)) { return false; } @@ -1166,7 +1166,7 @@ bool is_type_named_alias(Type *t) { return e->TypeName.is_type_alias; } -bool is_type_boolean(Type *t) { +gb_internal bool is_type_boolean(Type *t) { // t = core_type(t); t = base_type(t); if (t->kind == Type_Basic) { @@ -1174,7 +1174,7 @@ bool is_type_boolean(Type *t) { } return false; } -bool is_type_integer(Type *t) { +gb_internal bool is_type_integer(Type *t) { // t = core_type(t); t = base_type(t); if (t->kind == Type_Basic) { @@ -1182,7 +1182,7 @@ bool is_type_integer(Type *t) { } return false; } -bool is_type_integer_like(Type *t) { +gb_internal bool is_type_integer_like(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & (BasicFlag_Integer|BasicFlag_Boolean)) != 0; @@ -1196,7 +1196,7 @@ bool is_type_integer_like(Type *t) { return false; } -bool is_type_unsigned(Type *t) { +gb_internal bool is_type_unsigned(Type *t) { t = base_type(t); // t = core_type(t); if (t->kind == Type_Basic) { @@ -1204,7 +1204,7 @@ bool is_type_unsigned(Type *t) { } return false; } -bool is_type_integer_128bit(Type *t) { +gb_internal bool is_type_integer_128bit(Type *t) { // t = core_type(t); t = base_type(t); if (t->kind == Type_Basic) { @@ -1212,7 +1212,7 @@ bool is_type_integer_128bit(Type *t) { } return false; } -bool is_type_rune(Type *t) { +gb_internal bool is_type_rune(Type *t) { // t = core_type(t); t = base_type(t); if (t->kind == Type_Basic) { @@ -1220,7 +1220,7 @@ bool is_type_rune(Type *t) { } return false; } -bool is_type_numeric(Type *t) { +gb_internal bool is_type_numeric(Type *t) { // t = core_type(t); t = base_type(t); if (t->kind == Type_Basic) { @@ -1234,21 +1234,21 @@ bool is_type_numeric(Type *t) { } return false; } -bool is_type_string(Type *t) { +gb_internal bool is_type_string(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_String) != 0; } return false; } -bool is_type_cstring(Type *t) { +gb_internal bool is_type_cstring(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return t->Basic.kind == Basic_cstring; } return false; } -bool is_type_typed(Type *t) { +gb_internal bool is_type_typed(Type *t) { t = base_type(t); if (t == nullptr) { return false; @@ -1258,7 +1258,7 @@ bool is_type_typed(Type *t) { } return true; } -bool is_type_untyped(Type *t) { +gb_internal bool is_type_untyped(Type *t) { t = base_type(t); if (t == nullptr) { return false; @@ -1268,7 +1268,7 @@ bool is_type_untyped(Type *t) { } return false; } -bool is_type_ordered(Type *t) { +gb_internal bool is_type_ordered(Type *t) { t = core_type(t); switch (t->kind) { case Type_Basic: @@ -1280,7 +1280,7 @@ bool is_type_ordered(Type *t) { } return false; } -bool is_type_ordered_numeric(Type *t) { +gb_internal bool is_type_ordered_numeric(Type *t) { t = core_type(t); switch (t->kind) { case Type_Basic: @@ -1288,7 +1288,7 @@ bool is_type_ordered_numeric(Type *t) { } return false; } -bool is_type_constant_type(Type *t) { +gb_internal bool is_type_constant_type(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_ConstantType) != 0; @@ -1301,110 +1301,110 @@ bool is_type_constant_type(Type *t) { } return false; } -bool is_type_float(Type *t) { +gb_internal bool is_type_float(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Float) != 0; } return false; } -bool is_type_complex(Type *t) { +gb_internal bool is_type_complex(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Complex) != 0; } return false; } -bool is_type_quaternion(Type *t) { +gb_internal bool is_type_quaternion(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Quaternion) != 0; } return false; } -bool is_type_complex_or_quaternion(Type *t) { +gb_internal bool is_type_complex_or_quaternion(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & (BasicFlag_Complex|BasicFlag_Quaternion)) != 0; } return false; } -bool is_type_f16(Type *t) { +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; } -bool is_type_f32(Type *t) { +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; } -bool is_type_f64(Type *t) { +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; } -bool is_type_pointer(Type *t) { +gb_internal bool is_type_pointer(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Pointer) != 0; } return t->kind == Type_Pointer; } -bool is_type_soa_pointer(Type *t) { +gb_internal bool is_type_soa_pointer(Type *t) { t = base_type(t); return t->kind == Type_SoaPointer; } -bool is_type_multi_pointer(Type *t) { +gb_internal bool is_type_multi_pointer(Type *t) { t = base_type(t); return t->kind == Type_MultiPointer; } -bool is_type_internally_pointer_like(Type *t) { +gb_internal bool is_type_internally_pointer_like(Type *t) { return is_type_pointer(t) || is_type_multi_pointer(t) || is_type_cstring(t) || is_type_proc(t); } -bool is_type_tuple(Type *t) { +gb_internal bool is_type_tuple(Type *t) { t = base_type(t); return t->kind == Type_Tuple; } -bool is_type_uintptr(Type *t) { +gb_internal bool is_type_uintptr(Type *t) { if (t->kind == Type_Basic) { return (t->Basic.kind == Basic_uintptr); } return false; } -bool is_type_rawptr(Type *t) { +gb_internal bool is_type_rawptr(Type *t) { if (t->kind == Type_Basic) { return t->Basic.kind == Basic_rawptr; } return false; } -bool is_type_u8(Type *t) { +gb_internal bool is_type_u8(Type *t) { if (t->kind == Type_Basic) { return t->Basic.kind == Basic_u8; } return false; } -bool is_type_array(Type *t) { +gb_internal bool is_type_array(Type *t) { t = base_type(t); return t->kind == Type_Array; } -bool is_type_enumerated_array(Type *t) { +gb_internal bool is_type_enumerated_array(Type *t) { t = base_type(t); return t->kind == Type_EnumeratedArray; } -bool is_type_matrix(Type *t) { +gb_internal bool is_type_matrix(Type *t) { t = base_type(t); return t->kind == Type_Matrix; } -i64 matrix_align_of(Type *t, struct TypePath *tp) { +gb_internal i64 matrix_align_of(Type *t, struct TypePath *tp) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); @@ -1440,7 +1440,7 @@ i64 matrix_align_of(Type *t, struct TypePath *tp) { } -i64 matrix_type_stride_in_bytes(Type *t, struct TypePath *tp) { +gb_internal i64 matrix_type_stride_in_bytes(Type *t, struct TypePath *tp) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); if (t->Matrix.stride_in_bytes != 0) { @@ -1469,7 +1469,7 @@ i64 matrix_type_stride_in_bytes(Type *t, struct TypePath *tp) { return stride_in_bytes; } -i64 matrix_type_stride_in_elems(Type *t) { +gb_internal i64 matrix_type_stride_in_elems(Type *t) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); i64 stride = matrix_type_stride_in_bytes(t, nullptr); @@ -1477,7 +1477,7 @@ i64 matrix_type_stride_in_elems(Type *t) { } -i64 matrix_type_total_internal_elems(Type *t) { +gb_internal i64 matrix_type_total_internal_elems(Type *t) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); i64 size = type_size_of(t); @@ -1485,7 +1485,7 @@ i64 matrix_type_total_internal_elems(Type *t) { return size/gb_max(elem_size, 1); } -i64 matrix_indices_to_offset(Type *t, i64 row_index, i64 column_index) { +gb_internal i64 matrix_indices_to_offset(Type *t, i64 row_index, i64 column_index) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); GB_ASSERT(0 <= row_index && row_index < t->Matrix.row_count); @@ -1495,7 +1495,7 @@ i64 matrix_indices_to_offset(Type *t, i64 row_index, i64 column_index) { return row_index + stride_elems*column_index; } -i64 matrix_row_major_index_to_offset(Type *t, i64 index) { +gb_internal i64 matrix_row_major_index_to_offset(Type *t, i64 index) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); @@ -1503,7 +1503,7 @@ i64 matrix_row_major_index_to_offset(Type *t, i64 index) { i64 column_index = index%t->Matrix.column_count; return matrix_indices_to_offset(t, row_index, column_index); } -i64 matrix_column_major_index_to_offset(Type *t, i64 index) { +gb_internal i64 matrix_column_major_index_to_offset(Type *t, i64 index) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); @@ -1513,13 +1513,13 @@ i64 matrix_column_major_index_to_offset(Type *t, i64 index) { } -bool is_matrix_square(Type *t) { +gb_internal bool is_matrix_square(Type *t) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); return t->Matrix.row_count == t->Matrix.column_count; } -bool is_type_valid_for_matrix_elems(Type *t) { +gb_internal bool is_type_valid_for_matrix_elems(Type *t) { t = base_type(t); if (is_type_integer(t)) { return true; @@ -1534,32 +1534,32 @@ bool is_type_valid_for_matrix_elems(Type *t) { return false; } -bool is_type_dynamic_array(Type *t) { +gb_internal bool is_type_dynamic_array(Type *t) { t = base_type(t); return t->kind == Type_DynamicArray; } -bool is_type_slice(Type *t) { +gb_internal bool is_type_slice(Type *t) { t = base_type(t); return t->kind == Type_Slice; } -bool is_type_proc(Type *t) { +gb_internal bool is_type_proc(Type *t) { t = base_type(t); return t->kind == Type_Proc; } -bool is_type_asm_proc(Type *t) { +gb_internal bool is_type_asm_proc(Type *t) { t = base_type(t); return t->kind == Type_Proc && t->Proc.calling_convention == ProcCC_InlineAsm; } -bool is_type_poly_proc(Type *t) { +gb_internal bool is_type_poly_proc(Type *t) { t = base_type(t); return t->kind == Type_Proc && t->Proc.is_polymorphic; } -bool is_type_simd_vector(Type *t) { +gb_internal bool is_type_simd_vector(Type *t) { t = base_type(t); return t->kind == Type_SimdVector; } -Type *base_array_type(Type *t) { +gb_internal Type *base_array_type(Type *t) { Type *bt = base_type(t); if (is_type_array(bt)) { return bt->Array.elem; @@ -1573,49 +1573,49 @@ Type *base_array_type(Type *t) { return t; } -bool is_type_generic(Type *t) { +gb_internal bool is_type_generic(Type *t) { t = base_type(t); return t->kind == Type_Generic; } -bool is_type_relative_pointer(Type *t) { +gb_internal bool is_type_relative_pointer(Type *t) { t = base_type(t); return t->kind == Type_RelativePointer; } -bool is_type_relative_slice(Type *t) { +gb_internal bool is_type_relative_slice(Type *t) { t = base_type(t); return t->kind == Type_RelativeSlice; } -bool is_type_u8_slice(Type *t) { +gb_internal bool is_type_u8_slice(Type *t) { t = base_type(t); if (t->kind == Type_Slice) { return is_type_u8(t->Slice.elem); } return false; } -bool is_type_u8_array(Type *t) { +gb_internal bool is_type_u8_array(Type *t) { t = base_type(t); if (t->kind == Type_Array) { return is_type_u8(t->Array.elem); } return false; } -bool is_type_u8_ptr(Type *t) { +gb_internal bool is_type_u8_ptr(Type *t) { t = base_type(t); if (t->kind == Type_Pointer) { return is_type_u8(t->Slice.elem); } return false; } -bool is_type_u8_multi_ptr(Type *t) { +gb_internal bool is_type_u8_multi_ptr(Type *t) { t = base_type(t); if (t->kind == Type_MultiPointer) { return is_type_u8(t->Slice.elem); } return false; } -bool is_type_rune_array(Type *t) { +gb_internal bool is_type_rune_array(Type *t) { t = base_type(t); if (t->kind == Type_Array) { return is_type_rune(t->Array.elem); @@ -1624,10 +1624,10 @@ bool is_type_rune_array(Type *t) { } -bool is_type_array_like(Type *t) { +gb_internal bool is_type_array_like(Type *t) { return is_type_array(t) || is_type_enumerated_array(t); } -i64 get_array_type_count(Type *t) { +gb_internal i64 get_array_type_count(Type *t) { Type *bt = base_type(t); if (bt->kind == Type_Array) { return bt->Array.count; @@ -1642,7 +1642,7 @@ i64 get_array_type_count(Type *t) { -Type *core_array_type(Type *t) { +gb_internal Type *core_array_type(Type *t) { for (;;) { t = base_array_type(t); switch (t->kind) { @@ -1657,7 +1657,7 @@ Type *core_array_type(Type *t) { } } -i32 type_math_rank(Type *t) { +gb_internal i32 type_math_rank(Type *t) { i32 rank = 0; for (;;) { t = base_type(t); @@ -1677,7 +1677,7 @@ i32 type_math_rank(Type *t) { } -Type *base_complex_elem_type(Type *t) { +gb_internal Type *base_complex_elem_type(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { switch (t->Basic.kind) { @@ -1695,37 +1695,37 @@ Type *base_complex_elem_type(Type *t) { return t_invalid; } -bool is_type_struct(Type *t) { +gb_internal bool is_type_struct(Type *t) { t = base_type(t); return t->kind == Type_Struct; } -bool is_type_union(Type *t) { +gb_internal bool is_type_union(Type *t) { t = base_type(t); return t->kind == Type_Union; } -bool is_type_soa_struct(Type *t) { +gb_internal bool is_type_soa_struct(Type *t) { t = base_type(t); return t->kind == Type_Struct && t->Struct.soa_kind != StructSoa_None; } -bool is_type_raw_union(Type *t) { +gb_internal bool is_type_raw_union(Type *t) { t = base_type(t); return (t->kind == Type_Struct && t->Struct.is_raw_union); } -bool is_type_enum(Type *t) { +gb_internal bool is_type_enum(Type *t) { t = base_type(t); return (t->kind == Type_Enum); } -bool is_type_bit_set(Type *t) { +gb_internal bool is_type_bit_set(Type *t) { t = base_type(t); return (t->kind == Type_BitSet); } -bool is_type_map(Type *t) { +gb_internal bool is_type_map(Type *t) { t = base_type(t); return t->kind == Type_Map; } -bool is_type_union_maybe_pointer(Type *t) { +gb_internal bool is_type_union_maybe_pointer(Type *t) { t = base_type(t); if (t->kind == Type_Union && t->Union.variants.count == 1) { Type *v = t->Union.variants[0]; @@ -1735,7 +1735,7 @@ bool is_type_union_maybe_pointer(Type *t) { } -bool is_type_union_maybe_pointer_original_alignment(Type *t) { +gb_internal bool is_type_union_maybe_pointer_original_alignment(Type *t) { t = base_type(t); if (t->kind == Type_Union && t->Union.variants.count == 1) { Type *v = t->Union.variants[0]; @@ -1748,7 +1748,7 @@ bool is_type_union_maybe_pointer_original_alignment(Type *t) { -bool is_type_endian_big(Type *t) { +gb_internal bool is_type_endian_big(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { if (t->Basic.flags & BasicFlag_EndianBig) { @@ -1764,7 +1764,7 @@ bool is_type_endian_big(Type *t) { } return build_context.endian_kind == TargetEndian_Big; } -bool is_type_endian_little(Type *t) { +gb_internal bool is_type_endian_little(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { if (t->Basic.flags & BasicFlag_EndianLittle) { @@ -1781,7 +1781,7 @@ bool is_type_endian_little(Type *t) { return build_context.endian_kind == TargetEndian_Little; } -bool is_type_endian_platform(Type *t) { +gb_internal bool is_type_endian_platform(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & (BasicFlag_EndianLittle|BasicFlag_EndianBig)) == 0; @@ -1793,10 +1793,10 @@ bool is_type_endian_platform(Type *t) { return false; } -bool types_have_same_internal_endian(Type *a, Type *b) { +gb_internal bool types_have_same_internal_endian(Type *a, Type *b) { return is_type_endian_little(a) == is_type_endian_little(b); } -bool is_type_endian_specific(Type *t) { +gb_internal bool is_type_endian_specific(Type *t) { t = core_type(t); if (t->kind == Type_BitSet) { t = bit_set_to_int(t); @@ -1834,7 +1834,7 @@ bool is_type_endian_specific(Type *t) { return false; } -bool is_type_dereferenceable(Type *t) { +gb_internal bool is_type_dereferenceable(Type *t) { if (is_type_rawptr(t)) { return false; } @@ -1843,7 +1843,7 @@ bool is_type_dereferenceable(Type *t) { -bool is_type_different_to_arch_endianness(Type *t) { +gb_internal bool is_type_different_to_arch_endianness(Type *t) { switch (build_context.endian_kind) { case TargetEndian_Little: return !is_type_endian_little(t); @@ -1853,7 +1853,7 @@ bool is_type_different_to_arch_endianness(Type *t) { return false; } -Type *integer_endian_type_to_platform_type(Type *t) { +gb_internal Type *integer_endian_type_to_platform_type(Type *t) { t = core_type(t); if (t->kind == Type_BitSet) { t = bit_set_to_int(t); @@ -1893,35 +1893,35 @@ Type *integer_endian_type_to_platform_type(Type *t) { -bool is_type_any(Type *t) { +gb_internal bool is_type_any(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_any); } -bool is_type_typeid(Type *t) { +gb_internal bool is_type_typeid(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_typeid); } -bool is_type_untyped_nil(Type *t) { +gb_internal bool is_type_untyped_nil(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_UntypedNil); } -bool is_type_untyped_undef(Type *t) { +gb_internal bool is_type_untyped_undef(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_UntypedUndef); } -bool is_type_empty_union(Type *t) { +gb_internal bool is_type_empty_union(Type *t) { t = base_type(t); return t->kind == Type_Union && t->Union.variants.count == 0; } -bool is_type_empty_struct(Type *t) { +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; } -bool is_type_valid_for_keys(Type *t) { +gb_internal bool is_type_valid_for_keys(Type *t) { t = core_type(t); if (t->kind == Type_Generic) { return true; @@ -1932,7 +1932,7 @@ bool is_type_valid_for_keys(Type *t) { return type_size_of(t) > 0 && is_type_comparable(t); } -bool is_type_valid_bit_set_elem(Type *t) { +gb_internal bool is_type_valid_bit_set_elem(Type *t) { if (is_type_enum(t)) { return true; } @@ -1943,7 +1943,7 @@ bool is_type_valid_bit_set_elem(Type *t) { return false; } -Type *bit_set_to_int(Type *t) { +gb_internal Type *bit_set_to_int(Type *t) { GB_ASSERT(is_type_bit_set(t)); Type *bt = base_type(t); Type *underlying = bt->BitSet.underlying; @@ -1964,7 +1964,7 @@ Type *bit_set_to_int(Type *t) { return nullptr; } -bool is_type_valid_vector_elem(Type *t) { +gb_internal bool is_type_valid_vector_elem(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { if (t->Basic.flags & BasicFlag_EndianLittle) { @@ -1987,7 +1987,7 @@ bool is_type_valid_vector_elem(Type *t) { } -bool is_type_indexable(Type *t) { +gb_internal bool is_type_indexable(Type *t) { Type *bt = base_type(t); switch (bt->kind) { case Type_Basic: @@ -2009,7 +2009,7 @@ bool is_type_indexable(Type *t) { return false; } -bool is_type_sliceable(Type *t) { +gb_internal bool is_type_sliceable(Type *t) { Type *bt = base_type(t); switch (bt->kind) { case Type_Basic: @@ -2029,7 +2029,7 @@ bool is_type_sliceable(Type *t) { } -bool is_type_polymorphic_record(Type *t) { +gb_internal bool is_type_polymorphic_record(Type *t) { t = base_type(t); if (t->kind == Type_Struct) { return t->Struct.is_polymorphic; @@ -2039,7 +2039,7 @@ bool is_type_polymorphic_record(Type *t) { return false; } -Scope *polymorphic_record_parent_scope(Type *t) { +gb_internal Scope *polymorphic_record_parent_scope(Type *t) { t = base_type(t); if (is_type_polymorphic_record(t)) { if (t->kind == Type_Struct) { @@ -2051,7 +2051,7 @@ Scope *polymorphic_record_parent_scope(Type *t) { return nullptr; } -bool is_type_polymorphic_record_specialized(Type *t) { +gb_internal bool is_type_polymorphic_record_specialized(Type *t) { t = base_type(t); if (t->kind == Type_Struct) { return t->Struct.is_poly_specialized; @@ -2061,7 +2061,7 @@ bool is_type_polymorphic_record_specialized(Type *t) { return false; } -bool is_type_polymorphic_record_unspecialized(Type *t) { +gb_internal bool is_type_polymorphic_record_unspecialized(Type *t) { t = base_type(t); if (t->kind == Type_Struct) { return t->Struct.is_polymorphic && !t->Struct.is_poly_specialized; @@ -2071,7 +2071,7 @@ bool is_type_polymorphic_record_unspecialized(Type *t) { return false; } -TypeTuple *get_record_polymorphic_params(Type *t) { +gb_internal TypeTuple *get_record_polymorphic_params(Type *t) { t = base_type(t); switch (t->kind) { case Type_Struct: @@ -2089,7 +2089,7 @@ TypeTuple *get_record_polymorphic_params(Type *t) { } -bool is_type_polymorphic(Type *t, bool or_specialized=false) { +gb_internal bool is_type_polymorphic(Type *t, bool or_specialized=false) { if (t == nullptr) { return false; } @@ -2248,11 +2248,11 @@ bool is_type_polymorphic(Type *t, bool or_specialized=false) { } -bool type_has_undef(Type *t) { +gb_internal gb_inline bool type_has_undef(Type *t) { return true; } -bool type_has_nil(Type *t) { +gb_internal bool type_has_nil(Type *t) { t = base_type(t); switch (t->kind) { case Type_Basic: { @@ -2297,7 +2297,7 @@ bool type_has_nil(Type *t) { return false; } -bool elem_type_can_be_constant(Type *t) { +gb_internal bool elem_type_can_be_constant(Type *t) { t = base_type(t); if (t == t_invalid) { return false; @@ -2308,7 +2308,7 @@ bool elem_type_can_be_constant(Type *t) { return true; } -bool is_type_lock_free(Type *t) { +gb_internal bool is_type_lock_free(Type *t) { t = core_type(t); if (t == t_invalid) { return false; @@ -2320,7 +2320,7 @@ bool is_type_lock_free(Type *t) { -bool is_type_comparable(Type *t) { +gb_internal bool is_type_comparable(Type *t) { t = base_type(t); switch (t->kind) { case Type_Basic: @@ -2395,7 +2395,7 @@ bool is_type_comparable(Type *t) { } // NOTE(bill): type can be easily compared using memcmp -bool is_type_simple_compare(Type *t) { +gb_internal bool is_type_simple_compare(Type *t) { t = core_type(t); switch (t->kind) { case Type_Array: @@ -2450,7 +2450,7 @@ bool is_type_simple_compare(Type *t) { return false; } -bool is_type_load_safe(Type *type) { +gb_internal bool is_type_load_safe(Type *type) { GB_ASSERT(type != nullptr); type = core_type(core_array_type(type)); switch (type->kind) { @@ -2501,7 +2501,7 @@ bool is_type_load_safe(Type *type) { return false; } -String lookup_subtype_polymorphic_field(Type *dst, Type *src) { +gb_internal String lookup_subtype_polymorphic_field(Type *dst, Type *src) { Type *prev_src = src; // Type *prev_dst = dst; src = base_type(type_deref(src)); @@ -2532,7 +2532,7 @@ String lookup_subtype_polymorphic_field(Type *dst, Type *src) { return str_lit(""); } -bool lookup_subtype_polymorphic_selection(Type *dst, Type *src, Selection *sel) { +gb_internal bool lookup_subtype_polymorphic_selection(Type *dst, Type *src, Selection *sel) { Type *prev_src = src; // Type *prev_dst = dst; src = base_type(type_deref(src)); @@ -2571,17 +2571,17 @@ bool lookup_subtype_polymorphic_selection(Type *dst, Type *src, Selection *sel) -bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names); +gb_internal bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names); -bool are_types_identical(Type *x, Type *y) { +gb_internal bool are_types_identical(Type *x, Type *y) { return are_types_identical_internal(x, y, false); } -bool are_types_identical_unique_tuples(Type *x, Type *y) { +gb_internal bool are_types_identical_unique_tuples(Type *x, Type *y) { return are_types_identical_internal(x, y, true); } -bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names) { +gb_internal bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names) { if (x == y) { return true; } @@ -2748,7 +2748,7 @@ bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names) { return false; } -Type *default_type(Type *type) { +gb_internal Type *default_type(Type *type) { if (type == nullptr) { return t_invalid; } @@ -2766,7 +2766,7 @@ Type *default_type(Type *type) { return type; } -i64 union_variant_index(Type *u, Type *v) { +gb_internal i64 union_variant_index(Type *u, Type *v) { u = base_type(u); GB_ASSERT(u->kind == Type_Union); @@ -2783,7 +2783,7 @@ i64 union_variant_index(Type *u, Type *v) { return 0; } -i64 union_tag_size(Type *u) { +gb_internal i64 union_tag_size(Type *u) { u = base_type(u); GB_ASSERT(u->kind == Type_Union); if (u->Union.tag_size > 0) { @@ -2820,7 +2820,7 @@ i64 union_tag_size(Type *u) { return u->Union.tag_size; } -Type *union_tag_type(Type *u) { +gb_internal Type *union_tag_type(Type *u) { i64 s = union_tag_size(u); switch (s) { case 0: return t_u8; @@ -2850,7 +2850,7 @@ enum ProcTypeOverloadKind { }; -ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) { +gb_internal ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) { if (x == nullptr && y == nullptr) return ProcOverload_NotProcedure; if (x == nullptr && y != nullptr) return ProcOverload_NotProcedure; if (x != nullptr && y == nullptr) return ProcOverload_NotProcedure; @@ -2917,13 +2917,13 @@ ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) { -Selection lookup_field_with_selection(Type *type_, String field_name, bool is_type, Selection sel, bool allow_blank_ident=false); +gb_internal Selection lookup_field_with_selection(Type *type_, String field_name, bool is_type, Selection sel, bool allow_blank_ident=false); -Selection lookup_field(Type *type_, String field_name, bool is_type, bool allow_blank_ident=false) { +gb_internal Selection lookup_field(Type *type_, String field_name, bool is_type, bool allow_blank_ident=false) { return lookup_field_with_selection(type_, field_name, is_type, empty_selection, allow_blank_ident); } -Selection lookup_field_from_index(Type *type, i64 index) { +gb_internal Selection lookup_field_from_index(Type *type, i64 index) { GB_ASSERT(is_type_struct(type) || is_type_union(type) || is_type_tuple(type)); type = base_type(type); @@ -2967,10 +2967,10 @@ Selection lookup_field_from_index(Type *type, i64 index) { return empty_selection; } -Entity *scope_lookup_current(Scope *s, String const &name); -bool has_type_got_objc_class_attribute(Type *t); +gb_internal Entity *scope_lookup_current(Scope *s, String const &name); +gb_internal bool has_type_got_objc_class_attribute(Type *t); -Selection lookup_field_with_selection(Type *type_, String field_name, bool is_type, Selection sel, bool allow_blank_ident) { +gb_internal Selection lookup_field_with_selection(Type *type_, String field_name, bool is_type, Selection sel, bool allow_blank_ident) { GB_ASSERT(type_ != nullptr); if (!allow_blank_ident && is_blank_ident(field_name)) { @@ -3312,7 +3312,7 @@ Selection lookup_field_with_selection(Type *type_, String field_name, bool is_ty return sel; } -bool are_struct_fields_reordered(Type *type) { +gb_internal bool are_struct_fields_reordered(Type *type) { type = base_type(type); GB_ASSERT(type->kind == Type_Struct); type_set_offsets(type); @@ -3330,7 +3330,7 @@ bool are_struct_fields_reordered(Type *type) { return false; } -Slice struct_fields_index_by_increasing_offset(gbAllocator allocator, Type *type) { +gb_internal Slice struct_fields_index_by_increasing_offset(gbAllocator allocator, Type *type) { type = base_type(type); GB_ASSERT(type->kind == Type_Struct); type_set_offsets(type); @@ -3365,12 +3365,12 @@ Slice struct_fields_index_by_increasing_offset(gbAllocator allocator, Type -i64 type_size_of_internal (Type *t, TypePath *path); -i64 type_align_of_internal(Type *t, TypePath *path); -i64 type_size_of(Type *t); -i64 type_align_of(Type *t); +gb_internal i64 type_size_of_internal (Type *t, TypePath *path); +gb_internal i64 type_align_of_internal(Type *t, TypePath *path); +gb_internal i64 type_size_of(Type *t); +gb_internal i64 type_align_of(Type *t); -i64 type_size_of_struct_pretend_is_packed(Type *ot) { +gb_internal i64 type_size_of_struct_pretend_is_packed(Type *ot) { if (ot == nullptr) { return 0; } @@ -3399,7 +3399,7 @@ i64 type_size_of_struct_pretend_is_packed(Type *ot) { } -i64 type_size_of(Type *t) { +gb_internal i64 type_size_of(Type *t) { if (t == nullptr) { return 0; } @@ -3416,7 +3416,7 @@ i64 type_size_of(Type *t) { return t->cached_size; } -i64 type_align_of(Type *t) { +gb_internal i64 type_align_of(Type *t) { if (t == nullptr) { return 1; } @@ -3435,7 +3435,7 @@ i64 type_align_of(Type *t) { } -i64 type_align_of_internal(Type *t, TypePath *path) { +gb_internal i64 type_align_of_internal(Type *t, TypePath *path) { GB_ASSERT(path != nullptr); if (t->failure) { return FAILURE_ALIGNMENT; @@ -3608,7 +3608,7 @@ i64 type_align_of_internal(Type *t, TypePath *path) { return gb_clamp(next_pow2(type_size_of_internal(t, path)), 1, build_context.max_align); } -i64 *type_set_offsets_of(Slice const &fields, bool is_packed, bool is_raw_union) { +gb_internal i64 *type_set_offsets_of(Slice const &fields, bool is_packed, bool is_raw_union) { gbAllocator a = permanent_allocator(); auto offsets = gb_alloc_array(a, i64, fields.count); i64 curr_offset = 0; @@ -3635,7 +3635,7 @@ i64 *type_set_offsets_of(Slice const &fields, bool is_packed, bool is_ return offsets; } -bool type_set_offsets(Type *t) { +gb_internal bool type_set_offsets(Type *t) { mutex_lock(&g_type_mutex); defer (mutex_unlock(&g_type_mutex)); @@ -3662,7 +3662,7 @@ bool type_set_offsets(Type *t) { return false; } -i64 type_size_of_internal(Type *t, TypePath *path) { +gb_internal i64 type_size_of_internal(Type *t, TypePath *path) { if (t->failure) { return FAILURE_SIZE; } @@ -3882,7 +3882,7 @@ i64 type_size_of_internal(Type *t, TypePath *path) { return build_context.word_size; } -i64 type_offset_of(Type *t, i32 index) { +gb_internal i64 type_offset_of(Type *t, i32 index) { t = base_type(t); if (t->kind == Type_Struct) { type_set_offsets(t); @@ -3931,7 +3931,7 @@ i64 type_offset_of(Type *t, i32 index) { } -i64 type_offset_of_from_selection(Type *type, Selection sel) { +gb_internal i64 type_offset_of_from_selection(Type *type, Selection sel) { GB_ASSERT(sel.indirect == false); Type *t = type; @@ -3979,7 +3979,7 @@ i64 type_offset_of_from_selection(Type *type, Selection sel) { return offset; } -isize check_is_assignable_to_using_subtype(Type *src, Type *dst, isize level = 0, bool src_is_ptr = false) { +gb_internal isize check_is_assignable_to_using_subtype(Type *src, Type *dst, isize level = 0, bool src_is_ptr = false) { Type *prev_src = src; src = type_deref(src); if (!src_is_ptr) { @@ -4014,7 +4014,7 @@ isize check_is_assignable_to_using_subtype(Type *src, Type *dst, isize level = 0 return 0; } -bool is_type_subtype_of(Type *src, Type *dst) { +gb_internal bool is_type_subtype_of(Type *src, Type *dst) { if (are_types_identical(src, dst)) { return true; } @@ -4023,26 +4023,26 @@ bool is_type_subtype_of(Type *src, Type *dst) { } -bool has_type_got_objc_class_attribute(Type *t) { +gb_internal bool has_type_got_objc_class_attribute(Type *t) { return t->kind == Type_Named && t->Named.type_name != nullptr && t->Named.type_name->TypeName.objc_class_name != ""; } -bool is_type_objc_object(Type *t) { +gb_internal bool is_type_objc_object(Type *t) { bool internal_check_is_assignable_to(Type *src, Type *dst); return internal_check_is_assignable_to(t, t_objc_object); } -Type *get_struct_field_type(Type *t, isize index) { +gb_internal Type *get_struct_field_type(Type *t, isize index) { t = base_type(type_deref(t)); GB_ASSERT(t->kind == Type_Struct); return t->Struct.fields[index]->type; } -Type *reduce_tuple_to_single_type(Type *original_type) { +gb_internal Type *reduce_tuple_to_single_type(Type *original_type) { if (original_type != nullptr) { Type *t = core_type(original_type); if (t->kind == Type_Tuple && t->Tuple.variables.count == 1) { @@ -4053,7 +4053,7 @@ Type *reduce_tuple_to_single_type(Type *original_type) { } -Type *alloc_type_struct_from_field_types(Type **field_types, isize field_count, bool is_packed) { +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); @@ -4066,7 +4066,7 @@ Type *alloc_type_struct_from_field_types(Type **field_types, isize field_count, return t; } -Type *alloc_type_tuple_from_field_types(Type **field_types, isize field_count, bool is_packed, bool must_be_tuple) { +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; } @@ -4086,7 +4086,7 @@ Type *alloc_type_tuple_from_field_types(Type **field_types, isize field_count, b return t; } -Type *alloc_type_proc_from_types(Type **param_types, unsigned param_count, Type *results, bool is_c_vararg, ProcCallingConvention calling_convention) { +gb_internal Type *alloc_type_proc_from_types(Type **param_types, unsigned param_count, Type *results, bool is_c_vararg, ProcCallingConvention calling_convention) { Type *params = alloc_type_tuple_from_field_types(param_types, param_count, false, true); isize results_count = 0; @@ -4105,7 +4105,7 @@ Type *alloc_type_proc_from_types(Type **param_types, unsigned param_count, Type -gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) { +gb_internal gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) { if (type == nullptr) { return gb_string_appendc(str, ""); } @@ -4416,14 +4416,14 @@ gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) { } -gbString type_to_string(Type *type, gbAllocator allocator, bool shorthand) { +gb_internal gbString type_to_string(Type *type, gbAllocator allocator, bool shorthand) { return write_type_to_string(gb_string_make(allocator, ""), type, shorthand); } -gbString type_to_string(Type *type, bool shorthand) { +gb_internal gbString type_to_string(Type *type, bool shorthand) { return write_type_to_string(gb_string_make(heap_allocator(), ""), type, shorthand); } -gbString type_to_string_shorthand(Type *type) { +gb_internal gbString type_to_string_shorthand(Type *type) { return type_to_string(type, true); } -- 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/exact_value.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