diff --git a/CMakeLists.txt b/CMakeLists.txt index 7edd98501..cb546c6f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,6 @@ add_executable(c3c src/compiler/diagnostics.c src/compiler/ast.c src/compiler/bigint.c - src/compiler/bigint.h src/compiler/context.c src/compiler/sema_expr.c src/compiler/enums.h @@ -144,18 +143,9 @@ add_executable(c3c src/compiler/llvm_codegen_c_abi_riscv.c src/compiler/llvm_codegen_c_abi_wasm.c) -target_compile_options(c3c PRIVATE -Wno-unknown-warning-option - -Wsign-compare -Wimplicit-int -Werror -Wall - -Wempty-body -Wuninitialized -Wcast-function-type -Wclobbered - -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wmisleading-indentation - -Wold-style-declaration -Woverride-init - -Wtype-limits -Wshift-negative-value - -Wnested-externs -Wvla -Wno-stringop-overread - -Wpointer-arith -Wpacked - -Walloc-zero -Wduplicated-cond -Wshadow - -Wmissing-field-initializers -Wmissing-parameter-type - -Wno-unused-result -Wno-maybe-uninitialized - -Wno-unknown-pragmas -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter) +target_compile_options(c3c PRIVATE -Wall -Werror -Wno-unknown-pragmas -Wno-unused-result + -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter) + target_include_directories(c3c PRIVATE "${CMAKE_SOURCE_DIR}/src/") diff --git a/src/build/project_creation.c b/src/build/project_creation.c index 7c81f8b37..5e2664849 100644 --- a/src/build/project_creation.c +++ b/src/build/project_creation.c @@ -59,16 +59,16 @@ void create_project(BuildOptions *build_options) FILE *file = fopen("LICENCE", "a"); if (!file) goto ERROR; - fclose(file); + if (fclose(file)) goto ERROR; file = fopen("README.md", "a"); if (!file) goto ERROR; - fclose(file); + if (fclose(file)) goto ERROR; file = fopen("project.toml", "a"); if (!file) goto ERROR; - fprintf(file, TOML, build_options->project_name); - fclose(file); + (void) fprintf(file, TOML, build_options->project_name); + if (fclose(file)) goto ERROR; if (mkdir("lib", 0755)) goto ERROR; @@ -78,52 +78,54 @@ void create_project(BuildOptions *build_options) if (mkdir("test", 0755)) goto ERROR; - chdir("test"); + if (chdir("test")) goto ERROR; if (mkdir(build_options->project_name, 0755)) goto ERROR; - chdir(".."); + if (chdir("..")) goto ERROR; if (mkdir("directives", 0755)) goto ERROR; - chdir("directives"); + if (chdir("directives") == -1) goto ERROR; file = fopen("about.md", "a"); if (!file) goto ERROR; - fclose(file); + if (fclose(file)) goto ERROR; if (mkdir("src", 0755)) goto ERROR; - chdir("src"); + if (chdir("src")) goto ERROR; file = fopen("index.html", "a"); if (!file) goto ERROR; - fclose(file); + if (fclose(file)) goto ERROR; - chdir("../.."); + if (chdir("../..")) goto ERROR; if (mkdir("src", 0755)) goto ERROR; - chdir("src"); + if (chdir("src")) goto ERROR; if (mkdir(build_options->project_name, 0755)) goto ERROR; - chdir(build_options->project_name); + if (chdir(build_options->project_name)) goto ERROR; file = fopen("main.c3", "a"); if (!file) goto ERROR; - fclose(file); + if (fclose(file)) goto ERROR; - chdir("../.."); + if (chdir("../..")) goto ERROR; - printf("Project '%s' created.\n", build_options->project_name); + (void) printf("Project '%s' created.\n", build_options->project_name); exit(EXIT_SUCCESS); ERROR: fprintf(stderr, "Err: %s\n", strerror(errno)); printf("Something went wrong creating the project."); - chdir(build_options->path); - rmdir(build_options->project_name); + if (!chdir(build_options->path)) + { + (void)rmdir(build_options->project_name); + } exit(EXIT_FAILURE); } diff --git a/src/compiler/bigint.c b/src/compiler/bigint.c index ea7b4ef50..20c627388 100644 --- a/src/compiler/bigint.c +++ b/src/compiler/bigint.c @@ -2,8 +2,7 @@ // Use of this source code is governed by the GNU LGPLv3.0 license // a copy of which can be found in the LICENSE file. -#include "bigint.h" -#include "../utils/lib.h" +#include "compiler_internal.h" #include static inline uint32_t u32_min(uint32_t a, uint32_t b) @@ -27,7 +26,7 @@ static inline const uint64_t *bigint_ptr(const BigInt *big_int) } -#define alloc_digits(_digits) ((_digits) ? malloc_arena(sizeof(uint64_t) * (_digits)) : NULL) +#define ALLOC_DIGITS(_digits) ((_digits) ? malloc_arena(sizeof(uint64_t) * (_digits)) : NULL) static void normalize(BigInt *big_int) { @@ -81,14 +80,8 @@ static bool bit_at_index(const BigInt *big_int, size_t index) uint32_t bigint_hash(BigInt x) { - if (x.digit_count == 0) - { - return 0; - } - else - { - return (uint32_t) bigint_ptr(&x)[0]; - } + if (x.digit_count == 0) return 0; + return (uint32_t) bigint_ptr(&x)[0]; } static size_t bigint_bits_needed(const BigInt *big_int) @@ -138,7 +131,7 @@ void bigint_init_bigint(BigInt *dest, const BigInt *src) } dest->is_negative = src->is_negative; dest->digit_count = src->digit_count; - dest->digits = alloc_digits(dest->digit_count); + dest->digits = ALLOC_DIGITS(dest->digit_count); memcpy(dest->digits, src->digits, sizeof(uint64_t) * dest->digit_count); } @@ -268,11 +261,9 @@ static void from_twos_complement(BigInt *dest, const BigInt *src, size_t bit_cou void bigint_init_data(BigInt *dest, const uint64_t *digits, unsigned int digit_count, bool is_negative) { - if (digit_count == 0) - { - return bigint_init_unsigned(dest, 0); - } - else if (digit_count == 1) + if (digit_count == 0) return bigint_init_unsigned(dest, 0); + + if (digit_count == 1) { dest->digit_count = 1; dest->digit = digits[0]; @@ -283,7 +274,7 @@ void bigint_init_data(BigInt *dest, const uint64_t *digits, unsigned int digit_c dest->digit_count = digit_count; dest->is_negative = is_negative; - dest->digits = alloc_digits(digit_count); + dest->digits = ALLOC_DIGITS(digit_count); memcpy(dest->digits, digits, sizeof(uint64_t) * digit_count); normalize(dest); @@ -472,7 +463,7 @@ void bigint_read_twos_complement(BigInt *dest, const uint8_t *buf, size_t bit_co } else { - digits = alloc_digits(dest->digit_count); + digits = ALLOC_DIGITS(dest->digit_count); dest->digits = digits; } @@ -612,7 +603,7 @@ void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2) } unsigned i = 1; uint64_t first_digit = dest->digit; - dest->digits = alloc_digits(unsigned_max(op1->digit_count, op2->digit_count) + 1); + dest->digits = ALLOC_DIGITS(unsigned_max(op1->digit_count, op2->digit_count) + 1); dest->digits[0] = first_digit; for (;;) @@ -691,7 +682,7 @@ void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2) return; } uint64_t first_digit = dest->digit; - dest->digits = alloc_digits(bigger_op->digit_count); + dest->digits = ALLOC_DIGITS(bigger_op->digit_count); dest->digits[0] = first_digit; unsigned i = 1; @@ -862,7 +853,7 @@ void bigint_mul_wrap(BigInt *dest, const BigInt *op1, const BigInt *op2, size_t bigint_truncate(dest, &unwrapped, bit_count, is_signed); } -unsigned countLeadingZeros(uint32_t val) +unsigned count_leading_zeros(uint32_t val) { if (val == 0) return 32; @@ -897,7 +888,7 @@ static inline uint32_t lo_32(uint64_t val) /// from "Art of Computer Programming, Volume 2", section 4.3.1, p. 272. The /// variables here have the same names as in the algorithm. Comments explain /// the algorithm and any deviation from it. -static void KnuthDiv(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t *r, unsigned m, unsigned n) +static void knuth_div(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t *r, unsigned m, unsigned n) { assert(u && "Must provide dividend"); assert(v && "Must provide divisor"); @@ -916,7 +907,7 @@ static void KnuthDiv(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t *r, unsigne // and v so that its high bits are shifted to the top of v's range without // overflow. Note that this can require an extra word in u so that u must // be of length m+n+1. - unsigned shift = countLeadingZeros(v[n - 1]); + unsigned shift = count_leading_zeros(v[n - 1]); uint32_t v_carry = 0; uint32_t u_carry = 0; if (shift) @@ -1060,8 +1051,8 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn return; } - const uint64_t *LHS = bigint_ptr(op1); - const uint64_t *RHS = bigint_ptr(op2); + const uint64_t *lhs = bigint_ptr(op1); + const uint64_t *rhs = bigint_ptr(op2); unsigned lhsWords = op1->digit_count; unsigned rhsWords = op2->digit_count; @@ -1077,19 +1068,19 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn // Allocate space for the temporary values we need either on the stack, if // it will fit, or on the heap if it won't. - uint32_t SPACE[128]; + uint32_t space[128]; uint32_t *U = NULL; uint32_t *V = NULL; uint32_t *Q = NULL; uint32_t *R = NULL; if ((Remainder ? 4 : 3) * n + 2 * m + 1 <= 128) { - U = &SPACE[0]; - V = &SPACE[m + n + 1]; - Q = &SPACE[(m + n + 1) + n]; + U = &space[0]; + V = &space[m + n + 1]; + Q = &space[(m + n + 1) + n]; if (Remainder) { - R = &SPACE[(m + n + 1) + n + (m + n)]; + R = &space[(m + n + 1) + n + (m + n)]; } } else @@ -1107,7 +1098,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn memset(U, 0, (m + n + 1) * sizeof(uint32_t)); for (unsigned i = 0; i < lhsWords; ++i) { - uint64_t tmp = LHS[i]; + uint64_t tmp = lhs[i]; U[i * 2] = lo_32(tmp); U[i * 2 + 1] = hi_32(tmp); } @@ -1117,7 +1108,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn memset(V, 0, (n) * sizeof(uint32_t)); for (unsigned i = 0; i < rhsWords; ++i) { - uint64_t tmp = RHS[i]; + uint64_t tmp = rhs[i]; V[i * 2] = lo_32(tmp); V[i * 2 + 1] = hi_32(tmp); } @@ -1184,7 +1175,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn { // Now we're ready to invoke the Knuth classical divide algorithm. In this // case n > 1. - KnuthDiv(U, V, Q, R, m, n); + knuth_div(U, V, Q, R, m, n); } // If the caller wants the quotient @@ -1198,7 +1189,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn } else { - Quotient->digits = alloc_digits(lhsWords); + Quotient->digits = ALLOC_DIGITS(lhsWords); for (size_t i = 0; i < lhsWords; i += 1) { Quotient->digits[i] = make_64(Q[i * 2 + 1], Q[i * 2]); @@ -1217,7 +1208,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn } else { - Remainder->digits = alloc_digits(rhsWords); + Remainder->digits = ALLOC_DIGITS(rhsWords); for (size_t i = 0; i < rhsWords; i += 1) { Remainder->digits[i] = make_64(R[i * 2 + 1], R[i * 2]); @@ -1428,7 +1419,7 @@ void bigint_or(BigInt *dest, const BigInt *op1, const BigInt *op2) return; } dest->digit_count = unsigned_max(op1->digit_count, op2->digit_count); - dest->digits = alloc_digits(dest->digit_count); + dest->digits = ALLOC_DIGITS(dest->digit_count); for (size_t i = 0; i < dest->digit_count; i += 1) { uint64_t digit = 0; @@ -1481,7 +1472,7 @@ void bigint_and(BigInt *dest, const BigInt *op1, const BigInt *op2) } dest->digit_count = unsigned_max(op1->digit_count, op2->digit_count); - dest->digits = alloc_digits(dest->digit_count); + dest->digits = ALLOC_DIGITS(dest->digit_count); size_t i = 0; for (; i < op1->digit_count && i < op2->digit_count; i += 1) @@ -1536,7 +1527,7 @@ void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2) return; } dest->digit_count = unsigned_max(op1->digit_count, op2->digit_count); - dest->digits = alloc_digits(dest->digit_count); + dest->digits = ALLOC_DIGITS(dest->digit_count); size_t i = 0; for (; i < op1->digit_count && i < op2->digit_count; i += 1) { @@ -1602,7 +1593,7 @@ void bigint_shl_int(BigInt *dest, const BigInt *op1, uint64_t shift) uint64_t digit_shift_count = shift / 64; uint64_t leftover_shift_count = shift % 64; - dest->digits = alloc_digits(op1->digit_count + digit_shift_count + 1); + dest->digits = ALLOC_DIGITS(op1->digit_count + digit_shift_count + 1); dest->digit_count = digit_shift_count; uint64_t carry = 0; for (size_t i = 0; i < op1->digit_count; i += 1) @@ -1679,7 +1670,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) } else { - digits = alloc_digits(dest->digit_count); + digits = ALLOC_DIGITS(dest->digit_count); dest->digits = digits; } @@ -1759,7 +1750,7 @@ void bigint_not(BigInt *dest, const BigInt *op, size_t bit_count, bool is_signed } dest->digit_count = (unsigned int) ((bit_count + 63) / 64); assert(dest->digit_count >= op->digit_count); - dest->digits = alloc_digits(dest->digit_count); + dest->digits = ALLOC_DIGITS(dest->digit_count); size_t i = 0; for (; i < op->digit_count; i += 1) { @@ -1789,26 +1780,12 @@ void bigint_truncate(BigInt *dst, const BigInt *op, size_t bit_count, bool is_si CmpRes bigint_cmp(const BigInt *op1, const BigInt *op2) { - if (op1->is_negative && !op2->is_negative) - { - return CMP_LT; - } - else if (!op1->is_negative && op2->is_negative) - { - return CMP_GT; - } - else if (op1->digit_count > op2->digit_count) - { - return op1->is_negative ? CMP_LT : CMP_GT; - } - else if (op2->digit_count > op1->digit_count) - { - return op1->is_negative ? CMP_GT : CMP_LT; - } - else if (op1->digit_count == 0) - { - return CMP_EQ; - } + if (op1->is_negative && !op2->is_negative) return CMP_LT; + if (!op1->is_negative && op2->is_negative) return CMP_GT; + if (op1->digit_count > op2->digit_count) return op1->is_negative ? CMP_LT : CMP_GT; + if (op2->digit_count > op1->digit_count) return op1->is_negative ? CMP_GT : CMP_LT; + if (op1->digit_count == 0) return CMP_EQ; + const uint64_t *op1_digits = bigint_ptr(op1); const uint64_t *op2_digits = bigint_ptr(op2); for (unsigned i = op1->digit_count - 1;; i--) @@ -2095,12 +2072,9 @@ int64_t bigint_as_signed(const BigInt *bigint) { return (-((int64_t) (bigint->digit - 1))) - 1; } - else - { - FATAL_ERROR("BigInt does not fit in i64"); - } + FATAL_ERROR("BigInt does not fit in i64"); } - return bigint->digit; + return (int64_t)bigint->digit; } CmpRes bigint_cmp_zero(const BigInt *op) @@ -2128,7 +2102,7 @@ void bigint_incr(BigInt *x) x->digit -= 1; return; } - else if (!x->is_negative && x->digit != UINT64_MAX) + if (!x->is_negative && x->digit != UINT64_MAX) { x->digit += 1; return; diff --git a/src/compiler/bigint.h b/src/compiler/bigint.h deleted file mode 100644 index 3ce7a403c..000000000 --- a/src/compiler/bigint.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -// Copyright (c) 2019 Christoffer Lerno. All rights reserved. -// Use of this source code is governed by the GNU LGPLv3.0 license -// a copy of which can be found in the LICENSE file. - -#include "compiler_internal.h" - -typedef enum _CmpRes -{ - CMP_LT, - CMP_GT, - CMP_EQ, -} CmpRes; - -void bigint_init_unsigned(BigInt *big_int, uint64_t value); -void bigint_init_signed(BigInt *big_int, int64_t value); -void bigint_init_bigint(BigInt *dest, const BigInt *src); -void bigint_init_data(BigInt *dest, const uint64_t *digits, unsigned int digit_count, bool is_negative); -void bigint_negate(BigInt *dest, const BigInt *source); -size_t bigint_clz(const BigInt *big_int, size_t bit_count); -size_t bigint_ctz(const BigInt *big_int, size_t bit_count); -bool bigint_fits_in_bits(const BigInt *big_int, size_t bit_count, bool is_signed); -void bigint_write_twos_complement(const BigInt *big_int, uint8_t *buf, size_t bit_count, bool is_big_endian); -void bigint_read_twos_complement(BigInt *dest, const uint8_t *buf, size_t bit_count, bool is_big_endian, bool is_signed); -void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_add_wrap(BigInt *dest, const BigInt *op1, const BigInt *op2, size_t bit_count, bool is_signed); -void bigint_sub(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_sub_wrap(BigInt *dest, const BigInt *op1, const BigInt *op2, size_t bit_count, bool is_signed); -void bigint_mul(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_mul_wrap(BigInt *dest, const BigInt *op1, const BigInt *op2, size_t bit_count, bool is_signed); -void bigint_rem(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_mod(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_shl(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_shl_int(BigInt *dest, const BigInt *op1, uint64_t shift); -void bigint_shl_trunc(BigInt *dest, const BigInt *op1, const BigInt *op2, size_t bit_count, bool is_signed); -void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_div_floor(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_or(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_and(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2); -void bigint_negate_wrap(BigInt *dest, const BigInt *op, size_t bit_count); -void bigint_not(BigInt *dest, const BigInt *op, size_t bit_count, bool is_signed); -bool bigint_eql(BigInt a, BigInt b); -CmpRes bigint_cmp(const BigInt *op1, const BigInt *op2); -CmpRes bigint_cmp_zero(const BigInt *op); -uint32_t bigint_hash(BigInt x); -const char *bigint_to_error_string(const BigInt *bigint, uint64_t base); -void bigint_print(BigInt *bigint, uint64_t base); -void bigint_fprint(FILE *file, BigInt *bigint, uint64_t base); -uint64_t bigint_as_unsigned(const BigInt *bigint); -int64_t bigint_as_signed(const BigInt *bigint); -long double bigint_as_float(const BigInt *bigint); -void bigint_truncate(BigInt *dst, const BigInt *op, size_t bit_count, bool is_signed); -void bigint_incr(BigInt *x); -size_t bigint_popcount_signed(const BigInt *bi, size_t bit_count); -size_t bigint_popcount_unsigned(const BigInt *big_int); diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index a3174482c..e550f832d 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -1,7 +1,3 @@ -#pragma once -#pragma clang diagnostic push -#pragma ide diagnostic ignored "bugprone-reserved-identifier" - // Copyright (c) 2019 Christoffer Lerno. All rights reserved. // Use of this source code is governed by the GNU LGPLv3.0 license // a copy of which can be found in the LICENSE file. @@ -50,16 +46,16 @@ typedef struct #define MAX_ALIGNMENT ((ArrayIndex)(((uint64_t)2) << 28)) #define MAX_OFFSET ((ArrayIndex)(((uint64_t)2) << 60)) -typedef struct _Ast Ast; -typedef struct _Decl Decl; -typedef struct _TypeInfo TypeInfo; -typedef struct _Expr Expr; -typedef struct _Module Module; -typedef struct _Type Type; +typedef struct Ast_ Ast; +typedef struct Decl_ Decl; +typedef struct TypeInfo_ TypeInfo; +typedef struct Expr_ Expr; +typedef struct Module_ Module; +typedef struct Type_ Type; typedef unsigned AstId; -typedef struct _BigInt +typedef struct BigInt_ { unsigned digit_count; bool is_negative; @@ -162,7 +158,7 @@ typedef struct -typedef struct _Path +typedef struct Path_ { SourceSpan span; const char *module; @@ -198,11 +194,11 @@ typedef struct typedef struct { - struct _FunctionSignature *signature; + struct FunctionSignature_ *signature; const char *mangled_function_signature; } TypeFunc; -struct _Type +struct Type_ { TypeKind type_kind : 8; Type *canonical; @@ -230,7 +226,7 @@ struct _Type }; }; -struct _TypeInfo +struct TypeInfo_ { ResolveStatus resolve_status : 2; bool virtual_type : 1; @@ -278,7 +274,7 @@ typedef struct } StructDecl; -typedef struct _VarDecl +typedef struct VarDecl_ { VarDeclKind kind : 4; bool constant : 1; @@ -339,7 +335,7 @@ typedef struct TypeInfo *type_info; } EnumDecl; -typedef struct _FunctionSignature +typedef struct FunctionSignature_ { CallConvention convention : 4; bool variadic : 1; @@ -418,12 +414,12 @@ typedef struct bool failable : 1; Decl **parameters; TypeInfo *rtype; // May be null! - struct _Ast *body; + struct Ast_ *body; } MacroDecl; typedef struct { - struct _Ast **cases; + struct Ast_ **cases; Decl **parameters; TypeInfo *rtype; // May be null! Path *path; // For redefinition @@ -466,7 +462,7 @@ typedef struct } LabelDecl; -typedef struct _Decl +typedef struct Decl_ { const char *name; TokenId name_token; @@ -734,11 +730,6 @@ typedef struct Decl **params; } ExprMacroBlock; -typedef struct -{ - Expr *left; - Expr *right; -} ExprRange; typedef enum { @@ -782,7 +773,7 @@ typedef struct } ExprLen; -struct _Expr +struct Expr_ { ExprKind expr_kind : 8; ResolveStatus resolve_status : 3; @@ -799,7 +790,6 @@ struct _Expr Expr *typeof_expr; TypeInfo *type_expr; ExprConst const_expr; - ExprRange range_expr; ExprStructValue struct_value_expr; ExprGuard guard_expr; Expr *trycatch_expr; @@ -835,7 +825,7 @@ struct _Expr typedef struct { - struct _Ast **stmts; + struct Ast_ **stmts; DeferList defer_list; } AstCompoundStmt; @@ -984,11 +974,11 @@ typedef struct } AstCatchStmt; -typedef struct _AstCtIfStmt +typedef struct AstCtIfStmt_ { Expr *expr; - struct _Ast *then; - struct _Ast *elif; + struct Ast_ *then; + struct Ast_ *elif; } AstCtIfStmt; @@ -1112,7 +1102,7 @@ typedef struct }; } AstDocDirective; -typedef struct _Ast +typedef struct Ast_ { SourceSpan span; AstKind ast_kind : 8; @@ -1154,7 +1144,7 @@ typedef struct _Ast -typedef struct _Module +typedef struct Module_ { Path *name; TokenId *parameters; @@ -1170,12 +1160,12 @@ typedef struct _Module Decl** functions; STable symbols; STable public_symbols; - struct _Context **contexts; + struct Context_ **contexts; } Module; -typedef struct _DynamicScope +typedef struct DynamicScope_ { ScopeId scope_id; bool allow_dead_code : 1; @@ -1222,7 +1212,7 @@ typedef struct } Lexer; -typedef struct _Context +typedef struct Context_ { Path *module_name; File* file; @@ -1439,7 +1429,7 @@ extern const char *kw___round; extern const char *kw___sqrt; extern const char *kw___trunc; -#define AST_NEW_TOKEN(_kind, _token) new_ast(_kind, source_span_from_token_id(_token.id)) +#define AST_NEW_TOKEN(_kind, _token) new_ast(_kind, source_span_from_token_id((_token).id)) #define AST_NEW(_kind, _loc) new_ast(_kind, _loc) ARENA_DEF(ast, Ast) @@ -1470,6 +1460,55 @@ static inline Ast *extend_ast_with_prev_token(Context *context, Ast *ast) } +typedef enum CmpRes_ +{ + CMP_LT, + CMP_GT, + CMP_EQ, +} CmpRes; + +void bigint_init_unsigned(BigInt *big_int, uint64_t value); +void bigint_init_signed(BigInt *big_int, int64_t value); +void bigint_init_bigint(BigInt *dest, const BigInt *src); +void bigint_init_data(BigInt *dest, const uint64_t *digits, unsigned int digit_count, bool is_negative); +void bigint_negate(BigInt *dest, const BigInt *source); +size_t bigint_clz(const BigInt *big_int, size_t bit_count); +size_t bigint_ctz(const BigInt *big_int, size_t bit_count); +bool bigint_fits_in_bits(const BigInt *big_int, size_t bit_count, bool is_signed); +void bigint_write_twos_complement(const BigInt *big_int, uint8_t *buf, size_t bit_count, bool is_big_endian); +void bigint_read_twos_complement(BigInt *dest, const uint8_t *buf, size_t bit_count, bool is_big_endian, bool is_signed); +void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_add_wrap(BigInt *dest, const BigInt *op1, const BigInt *op2, size_t bit_count, bool is_signed); +void bigint_sub(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_sub_wrap(BigInt *dest, const BigInt *op1, const BigInt *op2, size_t bit_count, bool is_signed); +void bigint_mul(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_mul_wrap(BigInt *dest, const BigInt *op1, const BigInt *op2, size_t bit_count, bool is_signed); +void bigint_rem(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_mod(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_shl(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_shl_int(BigInt *dest, const BigInt *op1, uint64_t shift); +void bigint_shl_trunc(BigInt *dest, const BigInt *op1, const BigInt *op2, size_t bit_count, bool is_signed); +void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_div_floor(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_or(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_and(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2); +void bigint_negate_wrap(BigInt *dest, const BigInt *op, size_t bit_count); +void bigint_not(BigInt *dest, const BigInt *op, size_t bit_count, bool is_signed); +bool bigint_eql(BigInt a, BigInt b); +CmpRes bigint_cmp(const BigInt *op1, const BigInt *op2); +CmpRes bigint_cmp_zero(const BigInt *op); +uint32_t bigint_hash(BigInt x); +const char *bigint_to_error_string(const BigInt *bigint, uint64_t base); +void bigint_print(BigInt *bigint, uint64_t base); +void bigint_fprint(FILE *file, BigInt *bigint, uint64_t base); +uint64_t bigint_as_unsigned(const BigInt *bigint); +int64_t bigint_as_signed(const BigInt *bigint); +long double bigint_as_float(const BigInt *bigint); +void bigint_truncate(BigInt *dst, const BigInt *op, size_t bit_count, bool is_signed); +void bigint_incr(BigInt *x); +size_t bigint_popcount_signed(const BigInt *bi, size_t bit_count); +size_t bigint_popcount_unsigned(const BigInt *big_int); void builtin_setup(PlatformTarget *target); @@ -1548,8 +1587,8 @@ static inline Decl *decl_flatten(Decl *decl) void diag_verror_range(SourceLocation *location, const char *message, va_list args); -#define EXPR_NEW_EXPR(_kind, _expr) expr_new(_kind, _expr->span) -#define EXPR_NEW_TOKEN(_kind, _tok) expr_new(_kind, source_span_from_token_id(_tok.id)) +#define EXPR_NEW_EXPR(kind_, expr_) expr_new(kind_, (expr_)->span) +#define EXPR_NEW_TOKEN(kind_, tok_) expr_new(kind_, source_span_from_token_id((tok_).id)) Expr *expr_new(ExprKind kind, SourceSpan start); static inline bool expr_ok(Expr *expr) { return expr == NULL || expr->expr_kind != EXPR_POISONED; } static inline bool expr_poison(Expr *expr) { expr->expr_kind = EXPR_POISONED; expr->resolve_status = RESOLVE_DONE; return false; } @@ -1692,7 +1731,7 @@ void *llvm_target_machine_create(void); void target_setup(BuildTarget *build_target); int target_alloca_addr_space(); -#define TOK2VARSTR(_token) _token.span.length, _token.start + bool token_is_type(TokenType type); bool token_is_any_type(TokenType type); bool token_is_symbol(TokenType type); @@ -2079,6 +2118,4 @@ void platform_linker(const char *output_file, const char **files, unsigned file_ #define TRY_TYPE_REAL_OR(_type_stmt, _res) ({ Type* _type = (_type_stmt); if (!type_ok(_type)) return _res; _type; }) #define TRY_DECL_OR(_decl_stmt, _res) ({ Decl* _decl = (_decl_stmt); if (!decl_ok(_decl)) return _res; _decl; }) -#pragma clang diagnostic pop - diff --git a/src/compiler/context.c b/src/compiler/context.c index 5988d6308..3dcf18fbf 100644 --- a/src/compiler/context.c +++ b/src/compiler/context.c @@ -147,7 +147,6 @@ void context_register_global_decl(Context *context, Decl *decl) case DECL_LABEL: case DECL_CT_CASE: UNREACHABLE - break; case DECL_CT_IF: case DECL_CT_SWITCH: vec_add(context->ct_ifs, decl); diff --git a/src/compiler/copying.c b/src/compiler/copying.c index 1f804f2e6..7a049b486 100644 --- a/src/compiler/copying.c +++ b/src/compiler/copying.c @@ -263,7 +263,6 @@ Ast *copy_ast(Ast *source) return ast; case AST_CONTINUE_STMT: TODO - return ast; case AST_CT_ASSERT: MACRO_COPY_EXPR(ast->ct_assert_stmt.message); MACRO_COPY_EXPR(ast->ct_assert_stmt.expr); @@ -333,7 +332,6 @@ Ast *copy_ast(Ast *source) case AST_NEXT_STMT: MACRO_COPY_EXPR(ast->next_stmt.switch_expr); TODO - return ast; case AST_NOP_STMT: return ast; case AST_RETURN_STMT: diff --git a/src/compiler/lexer.c b/src/compiler/lexer.c index e924ced38..b694989d9 100644 --- a/src/compiler/lexer.c +++ b/src/compiler/lexer.c @@ -256,6 +256,8 @@ static inline bool parse_multiline_comment(Lexer *lexer) break; case '\0': return add_error_token(lexer, "Missing '*/' to end the multiline comment."); + default: + break; } next(lexer); } @@ -291,26 +293,6 @@ static void skip_whitespace(Lexer *lexer, LexMode lex_type) #pragma mark --- Identifier scanning -static inline bool scan_prefixed_ident(Lexer *lexer, TokenType type, TokenType no_ident_type, bool ends_with_bang, const char *start) -{ - uint32_t hash = FNV1a(prev(lexer), FNV1_SEED); - while (is_alphanum_(peek(lexer))) - { - hash = FNV1a(next(lexer), hash); - } - if (ends_with_bang && peek(lexer) == '!') - { - hash = FNV1a(next(lexer), hash); - } - uint32_t len = (uint32_t)(lexer->current - lexer->lexing_start); - if (len == 1) - { - return add_token(lexer, no_ident_type, start); - } - const char* interned = symtab_add(lexer->lexing_start, len, hash, &type); - return add_token(lexer, type, interned); -} - // Parses identifiers. Note that this is a bit complicated here since // we split identifiers into 2 types + find keywords. diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index 8d5064546..2665a2ed5 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -710,17 +710,6 @@ void gencontext_emit_introspection_type(GenContext *context, Decl *decl) } } -static inline uint32_t upper_power_of_two(uint32_t v) -{ - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v++; - return v; -} void llvm_value_set_bool(BEValue *value, LLVMValueRef llvm_value) { diff --git a/src/compiler/llvm_codegen_debug_info.c b/src/compiler/llvm_codegen_debug_info.c index 17c6e95ba..bde2dc0dc 100644 --- a/src/compiler/llvm_codegen_debug_info.c +++ b/src/compiler/llvm_codegen_debug_info.c @@ -3,7 +3,6 @@ // a copy of which can be found in the LICENSE file. #include "llvm_codegen_internal.h" -#include "bigint.h" #define LINE_ZERO 0 diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 7213b3805..4cfd117d6 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -3,8 +3,6 @@ // a copy of which can be found in the LICENSE file. #include "llvm_codegen_internal.h" -#include "compiler_internal.h" -#include "bigint.h" static void gencontext_emit_unary_expr(GenContext *context, BEValue *value, Expr *expr); static inline void llvm_emit_post_inc_dec(GenContext *c, BEValue *value, Expr *expr, int diff, bool use_mod); @@ -123,8 +121,6 @@ llvm_emit_sub_int(GenContext *c, Type *type, LLVMValueRef left, LLVMValueRef rig static inline void llvm_emit_subscript_addr_base(GenContext *context, BEValue *value, Expr *parent) { - LLVMValueRef parent_value; - Type *type = type_flatten(parent->type); llvm_emit_expr(context, value, parent); llvm_emit_ptr_from_array(context, value); } @@ -275,7 +271,6 @@ static void gencontext_emit_member_addr(GenContext *c, BEValue *value, Decl *par int index = find_member_index(parent, member); assert(index > -1); found = parent->strukt.members[index]; - const char *name = found->name ? found->name : "anon"; switch (parent->type->canonical->type_kind) { case TYPE_UNION: @@ -604,12 +599,12 @@ static inline void llvm_emit_initialize_reference_temporary_const(GenContext *c, LLVMValueRef value = llvm_emit_const_aggregate(c, expr, &modified); // Create a global const. - LLVMTypeRef type = modified ? LLVMTypeOf(value) : llvm_get_type(c, expr->type); + LLVMTypeRef type = modified ? LLVMTypeOf(value) : llvm_get_type(c, canonical); LLVMValueRef global_copy = LLVMAddGlobal(c->module, type, ".__const"); LLVMSetLinkage(global_copy, LLVMPrivateLinkage); // Set a nice alignment - unsigned alignment = type_alloca_alignment(expr->type); + ByteSize alignment = type_alloca_alignment(expr->type); llvm_set_alignment(global_copy, alignment); // Set the value and make it constant @@ -697,7 +692,6 @@ static void llvm_emit_inititialize_reference_const(GenContext *c, BEValue *ref, Decl *decl = const_init->type->decl; Decl **members = decl->strukt.members; MemberIndex count = vec_size(members); - LLVMValueRef *entries = NULL; for (MemberIndex i = 0; i < count; i++) { BEValue value; @@ -896,8 +890,6 @@ static inline void llvm_emit_initialize_reference_designated(GenContext *c, BEVa // Clear the memory if not union. if (real_type->type_kind != TYPE_UNION) llvm_emit_memclear(c, ref); - LLVMValueRef value = ref->value; - // Now walk through the elements. VECEACH(elements, i) { @@ -1230,7 +1222,7 @@ llvm_emit_slice_values(GenContext *c, Expr *slice, Type **parent_type_ref, LLVMV llvm_emit_expr(c, &parent_addr_x, parent_expr); llvm_value_addr(c, &parent_addr_x); LLVMValueRef parent_addr = parent_addr_x.value; - LLVMValueRef parent_load_value; + LLVMValueRef parent_load_value = NULL; LLVMValueRef parent_base; switch (parent_type->type_kind) { @@ -1260,7 +1252,7 @@ llvm_emit_slice_values(GenContext *c, Expr *slice, Type **parent_type_ref, LLVMV llvm_emit_expr(c, &start_index, start); llvm_value_rvalue(c, &start_index); - LLVMValueRef len; + LLVMValueRef len = NULL; if (!end || slice->slice_expr.start_from_back || slice->slice_expr.end_from_back || active_target.feature.safe_mode) { switch (parent_type->type_kind) @@ -1269,6 +1261,7 @@ llvm_emit_slice_values(GenContext *c, Expr *slice, Type **parent_type_ref, LLVMV len = NULL; break; case TYPE_SUBARRAY: + assert(parent_load_value); len = LLVMBuildExtractValue(c->builder, parent_load_value, 1, ""); break; case TYPE_ARRAY: @@ -1292,6 +1285,7 @@ llvm_emit_slice_values(GenContext *c, Expr *slice, Type **parent_type_ref, LLVMV if (parent_type->type_kind != TYPE_POINTER && active_target.feature.safe_mode) { + assert(len); LLVMValueRef exceeds_size = llvm_emit_int_comparison(c, type_usize, start_type, @@ -1755,7 +1749,7 @@ static void gencontext_emit_binary(GenContext *c, BEValue *be_value, Expr *expr, return; } bool is_float = type_is_float(lhs_type); - LLVMValueRef val; + LLVMValueRef val = NULL; switch (binary_op) { case BINARYOP_ERROR: @@ -1885,6 +1879,7 @@ static void gencontext_emit_binary(GenContext *c, BEValue *be_value, Expr *expr, case BINARYOP_SHL_ASSIGN: UNREACHABLE } + assert(val); llvm_value_set(be_value, val, expr->type); } diff --git a/src/compiler/llvm_codegen_function.c b/src/compiler/llvm_codegen_function.c index 720abc7a9..77299f6eb 100644 --- a/src/compiler/llvm_codegen_function.c +++ b/src/compiler/llvm_codegen_function.c @@ -4,7 +4,6 @@ #include "llvm_codegen_internal.h" -#include "bigint.h" static void llvm_emit_param_attributes(GenContext *context, LLVMValueRef function, ABIArgInfo *info, bool is_return, int index, int last_index); static inline void llvm_emit_return_value(GenContext *context, LLVMValueRef value); diff --git a/src/compiler/number.c b/src/compiler/number.c index 1a2db1369..25f942900 100644 --- a/src/compiler/number.c +++ b/src/compiler/number.c @@ -3,7 +3,6 @@ // a copy of which can be found in the LICENSE file. #include "compiler_internal.h" -#include "bigint.h" #define CHECK_SI_KIND(_kind) assert(_kind >= TYPE_I8 && _kind <= TYPE_I64) #define CHECK_IXX_KIND(_kind) assert(_kind == TYPE_IXX) diff --git a/src/compiler/parse_expr.c b/src/compiler/parse_expr.c index 3f2b02d8f..3a24d85b6 100644 --- a/src/compiler/parse_expr.c +++ b/src/compiler/parse_expr.c @@ -4,7 +4,6 @@ #include "compiler_internal.h" #include "parser_internal.h" -#include "bigint.h" #define BINOP_PREC_REQ_LEN 40 int BINOP_PREC_REQ[BINOP_PREC_REQ_LEN] = { @@ -203,11 +202,6 @@ static Expr *parse_macro_ident(Context *context, Expr *left) } -static inline Expr* parse_non_assign_expr(Context *context) -{ - return parse_precedence(context, PREC_ASSIGNMENT + 1); -} - /** * expression_list * : expression @@ -784,8 +778,8 @@ static Expr *parse_double(Context *context, Expr *left) static int append_esc_string_token(char *restrict dest, const char *restrict src, size_t *pos) { - int scanned = 0; - uint64_t unicode_char = 0; + int scanned; + uint64_t unicode_char; switch (src[0]) { case 'a': diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 53a7f97d2..ec9fdf2a0 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -247,8 +247,6 @@ static inline Path *parse_module_path(Context *context) { assert(TOKEN_IS(TOKEN_IDENT)); scratch_buffer_clear(); - char *scratch_ptr = global_context.scratch_buffer; - size_t offset = 0; SourceSpan span = source_span_from_token_id(context->tok.id); scratch_buffer_append_len(TOKSTR(context->tok), TOKLEN(context->tok)); TokenId last_token; diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index b05338535..46c9e0864 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -1170,7 +1170,6 @@ Ast *parse_stmt(Context *context) SEMA_TOKEN_ERROR(context->tok, "Unexpected '%s' found when expecting a statement.", token_type_to_string(context->tok.type)); advance(context); return poisoned_ast; - break; case TOKEN_RPAREN: case TOKEN_RBRACE: case TOKEN_RBRACKET: diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index 172e134d8..ed21de707 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -3,7 +3,6 @@ // a copy of which can be found in the LICENSE file. #include "compiler_internal.h" -#include "bigint.h" #define FLOAT32_LIMIT 340282346638528859811704183484516925440.0000000000000000 #define FLOAT64_LIMIT 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0000000000000000 @@ -28,50 +27,6 @@ static inline bool insert_runtime_cast_unless_const(Expr *expr, CastKind kind, T return insert_cast(expr, kind, type); } -static bool sema_type_mismatch(Expr *expr, Type *type, CastType cast_type) -{ - Type *expr_type = expr->type; - if (expr_type == type_typeinfo) - { - SEMA_ERROR(expr, "A raw type cannot be used in an expression. Add the suffix '.typeid' to use it as a value."); - return false; - } - const char *action = ""; - switch (cast_type) - { - case CAST_TYPE_EXPLICIT: - action = "cast"; - break; - case CAST_TYPE_IMPLICIT: - action = "implicitly cast"; - break; - case CAST_TYPE_OPTIONAL_IMPLICIT: - UNREACHABLE - } - if (expr_type == expr_type->canonical) - { - if (type->canonical == type) - { - SEMA_ERROR(expr, "Cannot %s '%s' to '%s'.", action, type_to_error_string(expr_type), type_to_error_string(type)); - } - else - { - SEMA_ERROR(expr, "Cannot %s '%s' to '%s' ('%s').", action, type_to_error_string(expr_type), type_to_error_string(type), type_to_error_string(type->canonical)); - } - } - else - { - if (type->canonical == type) - { - SEMA_ERROR(expr, "Cannot %s '%s' (%s) to '%s'.", action, type_to_error_string(expr_type), type_to_error_string(expr_type->canonical), type_to_error_string(type)); - } - else - { - SEMA_ERROR(expr, "Cannot %s '%s' (%s) to '%s' ('%s').", action, type_to_error_string(expr_type), type_to_error_string(expr_type->canonical), type_to_error_string(type), type_to_error_string(type->canonical)); - } - } - return false; -} bool pointer_to_integer(Expr *expr, Type *type) { @@ -93,25 +48,6 @@ bool pointer_to_bool(Expr *expr, Type *type) return true; } -static inline bool may_implicitly_cast_ptr_to_ptr(Type *current_type, Type *target_type) -{ - assert(current_type->canonical == current_type); - assert(target_type->canonical == target_type); - - // void* converts freely to and from: - if (target_type->pointer == type_void || current_type->pointer == type_void) return true; - - // Pointee is same? Fine! - if (target_type->pointer == current_type->pointer) return true; - - // Special case, does it point to an array, then it's okay if the element is the same. - if (current_type->pointer->type_kind == TYPE_ARRAY && - target_type->pointer == current_type->pointer->array.base) return true; - - // IMPROVE Vector - - return false; -} bool pointer_to_pointer(Expr* expr, Type *type) { diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index af031ffb5..0a4d4d3ed 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -3,10 +3,6 @@ // a copy of which can be found in the LICENSE file. #include "sema_internal.h" -#include "bigint.h" - - - static AttributeType sema_analyse_attribute(Context *context, Attr *attr, AttributeDomain domain); @@ -1025,16 +1021,6 @@ static inline bool sema_analyse_generic(Context *context, Decl *decl) } -static bool sema_analyse_plain_define(Context *c, Decl *decl, Decl *symbol) -{ - unsigned parameter_count = vec_size(symbol->module->parameters); - if (parameter_count > 0) - { - SEMA_ERROR(decl, "Using 'define' with parameterized modules, requires parameters - did you forget them?"); - return false; - } - TODO -} static Context *copy_context(Module *module, Context *c) { @@ -1073,16 +1059,6 @@ static Module *sema_instantiate_module(Context *context, Module *module, Path *p static Decl *sema_analyse_parameterized_define(Context *c, Decl *decl) { - TokenId define_ident;; - TypeInfo *define_type; - if (decl->define_decl.define_kind == DEFINE_TYPE_ALIAS) - { - define_type = decl->define_decl.type_info; - } - else - { - define_ident = decl->define_decl.identifier; - } Path *decl_path; bool mismatch = false; const char *name; @@ -1091,14 +1067,17 @@ static Decl *sema_analyse_parameterized_define(Context *c, Decl *decl) { case DEFINE_IDENT_ALIAS: decl_path = decl->define_decl.path; - name = TOKSTR(define_ident); + name = TOKSTR(decl->define_decl.identifier); break; case DEFINE_TYPE_ALIAS: + { + TypeInfo *define_type = decl->define_decl.type_info; mismatch_span = define_type->span; decl_path = define_type->unresolved.path; name = TOKSTR(define_type->unresolved.name_loc); mismatch = define_type->kind != TYPE_INFO_IDENTIFIER; break; + } default: UNREACHABLE } diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index ec31b4cdb..617424d76 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -3,7 +3,6 @@ // a copy of which can be found in the LICENSE file. #include "sema_internal.h" -#include "bigint.h" /* * TODOs @@ -1416,40 +1415,6 @@ static inline bool sema_expr_analyse_call(Context *context, Type *to, Expr *expr return false; } -static inline bool sema_expr_analyse_range(Context *context, Type *to, Expr *expr) -{ - Expr *left = expr->range_expr.left; - Expr *right = expr->range_expr.right; - bool success = sema_analyse_expr(context, to, left) & (!right || sema_analyse_expr(context, to, right)); - if (!success) return expr_poison(expr); - Type *left_canonical = left->type->canonical; - Type *right_canonical = right ? right->type->canonical : left_canonical; - if (!type_is_any_integer(left_canonical)) - { - SEMA_ERROR(left, "Expected an integer value in the range expression."); - return false; - } - if (!type_is_any_integer(right_canonical)) - { - SEMA_ERROR(right, "Expected an integer value in the range expression."); - return false; - } - if (left_canonical != right_canonical) - { - Type *type = type_find_max_type(left_canonical, right_canonical); - if (!cast_implicit(left, type) || !cast_implicit(right, type)) return expr_poison(expr); - } - if (left->expr_kind == EXPR_CONST && right && right->expr_kind == EXPR_CONST) - { - if (expr_const_compare(&left->const_expr, &right->const_expr, BINARYOP_GT)) - { - SEMA_ERROR(expr, "Left side of the range is smaller than the right."); - return false; - } - } - expr_copy_types(expr, left); - return true; -} static bool expr_check_index_in_range(Context *context, Type *type, Expr *index_expr, bool end_index, bool from_end) { @@ -2278,7 +2243,6 @@ static Type *sema_find_type_of_element(Context *context, Type *type, DesignatorE static Type *sema_expr_analyse_designator(Context *context, Type *current, Expr *expr, ArrayIndex *max_index) { DesignatorElement **path = expr->designator_expr.path; - Expr *value = expr->designator_expr.value; // Walk down into this path bool is_constant = true; diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index 8d0118b29..4e6c8b882 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -3,7 +3,6 @@ // a copy of which can be found in the LICENSE file. #include "sema_internal.h" -#include "bigint.h" #pragma mark --- Context help functions @@ -259,8 +258,6 @@ static inline bool sema_analyse_cond(Context *context, Expr *expr, bool cast_to_ { assert(expr->expr_kind == EXPR_DECL_LIST && "Conditional expressions should always be of type EXPR_DECL_LIST"); - size_t size = vec_size(expr->dexpr_list_expr); - // 1. Analyse the declaration list. if (!sema_analyse_decl_expr_list(context, expr)) return false; diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index fa32a417f..eeeb85354 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -3,9 +3,6 @@ // a copy of which can be found in the LICENSE file. #include "sema_internal.h" -#include "compiler_internal.h" -#include "bigint.h" - static inline bool sema_resolve_ptr_type(Context *context, TypeInfo *type_info) { @@ -24,7 +21,7 @@ static inline bool sema_resolve_array_type(Context *context, TypeInfo *type) { return type_info_poison(type); } - uint64_t len = 0; + uint64_t len; switch (type->kind) { case TYPE_INFO_VARARRAY: diff --git a/src/compiler/target.c b/src/compiler/target.c index 13bb756d5..ebdf9014a 100644 --- a/src/compiler/target.c +++ b/src/compiler/target.c @@ -20,7 +20,6 @@ static unsigned os_target_supports_float128(OsType os, ArchType arch); static unsigned os_target_supports_vec(OsType os, ArchType arch, int bits, bool is_int); static bool os_requires_libc(OsType os); - PlatformTarget platform_target = {}; int target_alloca_addr_space() diff --git a/src/compiler/types.c b/src/compiler/types.c index 9479a40bd..c4132f095 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -457,6 +457,8 @@ bool type_is_homogenous_base_type(Type *type) case 8: case 16: return true; + default: + break; } FALLTHROUGH; default: diff --git a/src/utils/file_utils.c b/src/utils/file_utils.c index c1fe683b2..87a3203a5 100644 --- a/src/utils/file_utils.c +++ b/src/utils/file_utils.c @@ -13,6 +13,7 @@ #include #include "whereami.h" + const char* expand_path(const char* path) { if (path[0] == '~' && path[1] == '/') diff --git a/src/utils/whereami.c b/src/utils/whereami.c index f3ca6fec3..af007a312 100644 --- a/src/utils/whereami.c +++ b/src/utils/whereami.c @@ -424,6 +424,8 @@ const char *find_executable_path(void) case '\\': path[i + 1] = '\0'; return path; + default: + break; } } path[len] = '\0';