mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix some bugs, satisfy more compilers.
This commit is contained in:
@@ -528,11 +528,11 @@ void fprint_expr_recursive(FILE *file, Expr *expr, int indent)
|
||||
case CONST_INT:
|
||||
if (expr->type->type_kind >= TYPE_U8 && expr->type->type_kind <= TYPE_UXX)
|
||||
{
|
||||
fprintf(file, "%llu\n", expr->const_expr.i);
|
||||
fprintf(file, "%llu\n", (unsigned long long)expr->const_expr.i);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(file, "%lld\n", (int64_t)expr->const_expr.i);
|
||||
fprintf(file, "%lld\n", (long long)expr->const_expr.i);
|
||||
}
|
||||
break;
|
||||
case CONST_FLOAT:
|
||||
|
||||
@@ -30,7 +30,7 @@ static void print_error(SourceRange source_range, const char *message, PrintType
|
||||
{
|
||||
SourcePosition position = source_file_find_position(source_range.loc);
|
||||
|
||||
const static int LINES_SHOWN = 4;
|
||||
static const int LINES_SHOWN = 4;
|
||||
|
||||
unsigned max_line_length = (int)round(log10(position.line)) + 1;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ static bool expr_is_ltype(Expr *expr)
|
||||
|| expr->identifier_expr.decl->var.kind == VARDECL_GLOBAL
|
||||
|| expr->identifier_expr.decl->var.kind == VARDECL_PARAM);
|
||||
case EXPR_UNARY:
|
||||
return expr->unary_expr.operator == TOKEN_STAR;
|
||||
return expr->unary_expr.operator == UNARYOP_DEREF;
|
||||
case EXPR_ACCESS:
|
||||
return expr_is_ltype(expr->access_expr.parent);
|
||||
case EXPR_SUBSCRIPT:
|
||||
@@ -413,7 +413,7 @@ static inline Decl *decl_find_by_name(Decl** decls, const char *name)
|
||||
static inline bool expr_may_be_struct_field_decl(Expr *maybe_binary)
|
||||
{
|
||||
if (maybe_binary->expr_kind != EXPR_BINARY) return false;
|
||||
if (maybe_binary->binary_expr.operator != TOKEN_EQ) return false;
|
||||
if (maybe_binary->binary_expr.operator != BINARYOP_EQ) return false;
|
||||
Expr *expr = maybe_binary->binary_expr.left;
|
||||
while (1)
|
||||
{
|
||||
|
||||
@@ -221,6 +221,7 @@ void skip_whitespace(Lexer *lexer)
|
||||
{
|
||||
case '\n':
|
||||
lexer_store_line_end(lexer);
|
||||
// fallthrough
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\r':
|
||||
|
||||
@@ -240,6 +240,7 @@ LLVMValueRef gencontext_emit_unary_expr(GenContext *context, Expr *expr)
|
||||
case UNARYOP_DEC:
|
||||
return gencontext_emit_pre_inc_dec(context, expr->unary_expr.expr, -1, false);
|
||||
}
|
||||
UNREACHABLE
|
||||
}
|
||||
|
||||
|
||||
@@ -430,6 +431,7 @@ static LLVMValueRef gencontext_emit_binary(GenContext *context, Expr *expr, LLVM
|
||||
case BINARYOP_SHL_ASSIGN:
|
||||
UNREACHABLE
|
||||
}
|
||||
UNREACHABLE
|
||||
}
|
||||
|
||||
LLVMValueRef gencontext_emit_post_unary_expr(GenContext *context, Expr *expr)
|
||||
|
||||
@@ -201,7 +201,7 @@ void gencontext_emit_for_stmt(GenContext *context, Ast *ast)
|
||||
// A loop must either have a body or an inc.
|
||||
// This type of for loop is forbidden:
|
||||
// for (;;);
|
||||
assert(cond_block || inc_block || body_block && "For has no body, no inc and no cond.");
|
||||
assert((cond_block || inc_block || body_block) && "For has no body, no inc and no cond.");
|
||||
|
||||
// Break is simple it always jumps out.
|
||||
// For continue:
|
||||
|
||||
@@ -1598,6 +1598,7 @@ static Ast *parse_stmt(Context *context)
|
||||
sema_error_at(context->tok.span.loc - 1, "Reached the end of the file when expecting a statement.");
|
||||
return &poisoned_ast;
|
||||
}
|
||||
UNREACHABLE
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -89,8 +89,8 @@ const char *type_to_error_string(Type *type)
|
||||
return buffer;
|
||||
case TYPE_ERROR_UNION:
|
||||
TODO
|
||||
|
||||
}
|
||||
UNREACHABLE
|
||||
}
|
||||
|
||||
static void type_append_signature_name_user_defined(Decl *decl, char *dst, size_t *offset)
|
||||
@@ -593,8 +593,11 @@ Type *type_find_max_type(Type *type, Type *other)
|
||||
case TYPE_SUBARRAY:
|
||||
TODO
|
||||
}
|
||||
UNREACHABLE
|
||||
}
|
||||
|
||||
#define MAX_SEARCH_DEPTH 512
|
||||
|
||||
Type *type_find_common_ancestor(Type *left, Type *right)
|
||||
{
|
||||
if (left == right) return left;
|
||||
@@ -609,7 +612,6 @@ Type *type_find_common_ancestor(Type *left, Type *right)
|
||||
}
|
||||
if (left->type_kind != TYPE_STRUCT) return NULL;
|
||||
|
||||
static const int MAX_SEARCH_DEPTH = 512;
|
||||
static Type *left_types[MAX_SEARCH_DEPTH];
|
||||
int depth = 0;
|
||||
while (depth < MAX_SEARCH_DEPTH)
|
||||
|
||||
@@ -150,23 +150,24 @@ void file_add_wildcard_files(const char ***files, const char *path, bool recursi
|
||||
struct dirent *ent;
|
||||
while ((ent = readdir(dir)))
|
||||
{
|
||||
if (ent->d_namlen < 4) continue;
|
||||
size_t namelen = strlen(ent->d_name);
|
||||
if (namelen < 4) continue;
|
||||
|
||||
// Doesn't end with .c3
|
||||
if (strncmp(&ent->d_name[ent->d_namlen - 3], ".c3", 3) != 0)
|
||||
if (strncmp(&ent->d_name[namelen - 3], ".c3", 3) != 0)
|
||||
{
|
||||
if (ent->d_type == DT_DIR && ent->d_name[0] != '.' && recursive)
|
||||
{
|
||||
char *new_path = strndup(ent->d_name, ent->d_namlen);
|
||||
char *new_path = strndup(ent->d_name, namelen);
|
||||
file_add_wildcard_files(files, new_path, recursive);
|
||||
free(new_path);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
char *name = malloc_arena(ent->d_namlen + 1);
|
||||
memcpy(name, ent->d_name, ent->d_namlen);
|
||||
name[ent->d_namlen] = '\0';
|
||||
char *name = malloc_arena(namelen + 1);
|
||||
memcpy(name, ent->d_name, namelen);
|
||||
name[namelen] = '\0';
|
||||
vec_add(*files, name);
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
@@ -38,11 +38,9 @@ char *toml_strndup(TOML_CONST char *str, size_t n)
|
||||
|
||||
int toml_vasprintf(char **str, TOML_CONST char *format, va_list args)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
size = vsnprintf(NULL, size, format, args_copy);
|
||||
int size = vsnprintf(NULL, 0, format, args_copy);
|
||||
va_end(args_copy);
|
||||
|
||||
if (size < 0)
|
||||
|
||||
Reference in New Issue
Block a user