use size_t for indexes

protect against incorrect copies in debug mode
This commit is contained in:
Andrew Kelley 2016-09-15 14:05:15 -04:00
parent 4c0259b107
commit 3239b3cb69
27 changed files with 556 additions and 532 deletions

View File

@ -177,7 +177,7 @@ if(MINGW)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")
endif()
set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__USE_MINGW_ANSI_STDIO -Werror=strict-prototypes -Werror=old-style-definition")
set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__USE_MINGW_ANSI_STDIO -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits")
set(EXE_LDFLAGS " ")
if(ZIG_TEST_COVERAGE)
set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage")

View File

@ -18,7 +18,6 @@
struct AstNode;
struct ImportTableEntry;
struct AsmToken;
struct FnTableEntry;
struct BlockContext;
struct TypeTableEntry;
@ -218,8 +217,8 @@ struct AstNodeFnProto {
bool skip;
Expr resolved_expr;
// computed from params field
int inline_arg_count;
int inline_or_var_type_arg_count;
size_t inline_arg_count;
size_t inline_or_var_type_arg_count;
// if this is a generic function implementation, this points to the generic node
AstNode *generic_proto_node;
};
@ -282,7 +281,7 @@ struct AstNodeDefer {
// populated by semantic analyzer:
Expr resolved_expr;
int index_in_block;
size_t index_in_block;
LLVMBasicBlockRef basic_block;
BlockContext *child_block;
};
@ -547,7 +546,7 @@ struct AstNodeSwitchExpr {
// populated by semantic analyzer
Expr resolved_expr;
int const_chosen_prong_index;
size_t const_chosen_prong_index;
};
struct AstNodeSwitchProng {
@ -599,8 +598,20 @@ struct AsmInput {
};
struct SrcPos {
int line;
int column;
size_t line;
size_t column;
};
enum AsmTokenId {
AsmTokenIdTemplate,
AsmTokenIdPercent,
AsmTokenIdVar,
};
struct AsmToken {
enum AsmTokenId id;
size_t start;
size_t end;
};
struct AstNodeAsmExpr {
@ -612,7 +623,7 @@ struct AstNodeAsmExpr {
ZigList<Buf*> clobber_list;
// populated by semantic analyzer
int return_count;
size_t return_count;
Expr resolved_expr;
};
@ -763,8 +774,8 @@ struct AstNodeVarLiteral {
struct AstNode {
enum NodeType type;
int line;
int column;
size_t line;
size_t column;
uint32_t create_index; // for determinism purposes
ImportTableEntry *owner;
AstNode **parent_field; // for AST rewriting
@ -823,18 +834,6 @@ struct AstNode {
} data;
};
enum AsmTokenId {
AsmTokenIdTemplate,
AsmTokenIdPercent,
AsmTokenIdVar,
};
struct AsmToken {
enum AsmTokenId id;
int start;
int end;
};
// this struct is allocated with allocate_nonzero
struct FnTypeParamInfo {
bool is_noalias;
@ -844,24 +843,24 @@ struct FnTypeParamInfo {
struct GenericParamValue {
TypeTableEntry *type;
AstNode *node;
int impl_index;
size_t impl_index;
};
struct GenericFnTypeId {
AstNode *decl_node; // the generic fn or container decl node
GenericParamValue *generic_params;
int generic_param_count;
size_t generic_param_count;
};
uint32_t generic_fn_type_id_hash(GenericFnTypeId *id);
bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b);
static const int fn_type_id_prealloc_param_info_count = 4;
static const size_t fn_type_id_prealloc_param_info_count = 4;
struct FnTypeId {
TypeTableEntry *return_type;
FnTypeParamInfo *param_info;
int param_count;
size_t param_count;
bool is_var_args;
bool is_naked;
bool is_cold;
@ -878,12 +877,12 @@ struct TypeTableEntryPointer {
};
struct TypeTableEntryInt {
int bit_count;
size_t bit_count;
bool is_signed;
};
struct TypeTableEntryFloat {
int bit_count;
size_t bit_count;
};
struct TypeTableEntryArray {
@ -894,8 +893,8 @@ struct TypeTableEntryArray {
struct TypeStructField {
Buf *name;
TypeTableEntry *type_entry;
int src_index;
int gen_index;
size_t src_index;
size_t gen_index;
};
struct TypeTableEntryStruct {
AstNode *decl_node;
@ -958,8 +957,8 @@ struct TypeTableEntryUnion {
};
struct FnGenParamInfo {
int src_index;
int gen_index;
size_t src_index;
size_t gen_index;
bool is_byval;
TypeTableEntry *type;
};
@ -967,7 +966,7 @@ struct FnGenParamInfo {
struct TypeTableEntryFn {
FnTypeId fn_type_id;
TypeTableEntry *gen_return_type;
int gen_param_count;
size_t gen_param_count;
FnGenParamInfo *gen_param_info;
LLVMTypeRef raw_type_ref;
@ -1057,7 +1056,7 @@ struct ImportTableEntry {
PackageTableEntry *package;
ZigLLVMDIFile *di_file;
Buf *source_code;
ZigList<int> *line_offsets;
ZigList<size_t> *line_offsets;
BlockContext *block_context;
AstNode *c_import_node;
bool any_imports_failed;
@ -1127,8 +1126,8 @@ struct EvalFnRoot {
CodeGen *codegen;
FnTableEntry *fn;
AstNode *call_node;
int branch_quota;
int branches_used;
size_t branch_quota;
size_t branches_used;
AstNode *exceeded_quota_node;
bool abort;
};
@ -1180,7 +1179,7 @@ enum BuiltinFnId {
struct BuiltinFnEntry {
BuiltinFnId id;
Buf name;
int param_count;
size_t param_count;
TypeTableEntry *return_type;
TypeTableEntry **param_types;
uint32_t ref_count;
@ -1207,11 +1206,11 @@ struct CodeGen {
HashMap<GenericFnTypeId *, AstNode *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;
ZigList<ImportTableEntry *> import_queue;
int import_queue_index;
size_t import_queue_index;
ZigList<AstNode *> resolve_queue;
int resolve_queue_index;
size_t resolve_queue_index;
ZigList<AstNode *> use_queue;
int use_queue_index;
size_t use_queue_index;
uint32_t next_unresolved_index;
@ -1305,9 +1304,9 @@ struct CodeGen {
bool c_want_stdint;
bool c_want_stdbool;
AstNode *root_export_decl;
int version_major;
int version_minor;
int version_patch;
size_t version_major;
size_t version_minor;
size_t version_patch;
bool verbose;
ErrColor err_color;
ImportTableEntry *root_import;
@ -1323,7 +1322,7 @@ struct CodeGen {
LLVMValueRef int_builtin_fns[2][4]; // [0-ctz,1-clz][0-8,1-16,2-32,3-64]
const char **clang_argv;
int clang_argv_len;
size_t clang_argv_len;
ZigList<const char *> lib_dirs;
uint32_t test_fn_count;
@ -1345,8 +1344,8 @@ struct VariableTableEntry {
// which node contains the ConstExprValue for this variable's value
AstNode *val_node;
ZigLLVMDILocalVariable *di_loc_var;
int src_arg_index;
int gen_arg_index;
size_t src_arg_index;
size_t gen_arg_index;
BlockContext *block_context;
LLVMValueRef param_value_ref;
bool force_depends_on_compile_var;

View File

@ -205,7 +205,7 @@ static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *so
}
static int bits_needed_for_unsigned(uint64_t x) {
static size_t bits_needed_for_unsigned(uint64_t x) {
if (x <= UINT8_MAX) {
return 8;
} else if (x <= UINT16_MAX) {
@ -579,7 +579,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c
slice_type_common_init(g, child_type, is_const, entry);
if (child_type->zero_bits) {
entry->data.structure.gen_field_count = 1;
entry->data.structure.fields[0].gen_index = -1;
entry->data.structure.fields[0].gen_index = SIZE_MAX;
entry->data.structure.fields[1].gen_index = 0;
}
@ -736,7 +736,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf
const char *naked_str = fn_type_id->is_naked ? "naked " : "";
const char *cold_str = fn_type_id->is_cold ? "cold " : "";
buf_appendf(&fn_type->name, "%s%s%sfn(", extern_str, naked_str, cold_str);
for (int i = 0; i < fn_type_id->param_count; i += 1) {
for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
TypeTableEntry *param_type = param_info->type;
@ -763,7 +763,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf
// +1 because 0 is the return type and +1 for maybe making first arg ret val
ZigLLVMDIType **param_di_types = allocate<ZigLLVMDIType*>(2 + fn_type_id->param_count);
param_di_types[0] = fn_type_id->return_type->di_type;
int gen_param_index = 0;
size_t gen_param_index = 0;
TypeTableEntry *gen_return_type;
if (!type_has_bits(fn_type_id->return_type)) {
gen_return_type = g->builtin_types.entry_void;
@ -780,13 +780,13 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf
fn_type->data.fn.gen_return_type = gen_return_type;
fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);
for (int i = 0; i < fn_type_id->param_count; i += 1) {
for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];
TypeTableEntry *type_entry = src_param_info->type;
FnGenParamInfo *gen_param_info = &fn_type->data.fn.gen_param_info[i];
gen_param_info->src_index = i;
gen_param_info->gen_index = -1;
gen_param_info->gen_index = SIZE_MAX;
assert(type_is_complete(type_entry));
if (type_has_bits(type_entry)) {
@ -946,7 +946,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
fn_type_id.is_var_args = fn_proto->is_var_args;
fn_type_id.return_type = analyze_type_expr(g, import, context, fn_proto->return_type);
for (int i = 0; i < fn_type_id.param_count; i += 1) {
for (size_t i = 0; i < fn_type_id.param_count; i += 1) {
AstNode *child = fn_proto->params.at(i);
assert(child->type == NodeTypeParamDecl);
@ -1047,7 +1047,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
fn_table_entry->want_pure_return_type = fn_proto->return_type;
ErrorMsg *err_msg = nullptr;
for (int i = 0; i < fn_proto->params.length; i += 1) {
for (size_t i = 0; i < fn_proto->params.length; i += 1) {
AstNode *param_decl_node = fn_proto->params.at(i);
assert(param_decl_node->type == NodeTypeParamDecl);
if (!param_decl_node->data.param_decl.is_inline) {
@ -1135,7 +1135,7 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t
bool is_noinline = false;
if (fn_proto->top_level_decl.directives) {
for (int i = 0; i < fn_proto->top_level_decl.directives->length; i += 1) {
for (size_t i = 0; i < fn_proto->top_level_decl.directives->length; i += 1) {
AstNode *directive_node = fn_proto->top_level_decl.directives->at(i);
Buf *name = directive_node->data.directive.name;
@ -1342,7 +1342,7 @@ static void resolve_enum_type(CodeGen *g, ImportTableEntry *import, TypeTableEnt
// set temporary flag
enum_type->data.enumeration.embedded_in_current = true;
int gen_field_index = 0;
size_t gen_field_index = 0;
for (uint32_t i = 0; i < field_count; i += 1) {
AstNode *field_node = decl_node->data.struct_decl.fields.at(i);
TypeEnumField *type_enum_field = &enum_type->data.enumeration.fields[i];
@ -1518,7 +1518,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
struct_type->deep_const = true;
int field_count = decl_node->data.struct_decl.fields.length;
size_t field_count = decl_node->data.struct_decl.fields.length;
struct_type->data.structure.src_field_count = field_count;
struct_type->data.structure.fields = allocate<TypeStructField>(field_count);
@ -1532,8 +1532,8 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
BlockContext *context = struct_type->data.structure.block_context;
int gen_field_index = 0;
for (int i = 0; i < field_count; i += 1) {
size_t gen_field_index = 0;
for (size_t i = 0; i < field_count; i += 1) {
AstNode *field_node = decl_node->data.struct_decl.fields.at(i);
TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
type_struct_field->name = field_node->data.struct_field.name;
@ -1541,7 +1541,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
field_node->data.struct_field.type);
type_struct_field->type_entry = field_type;
type_struct_field->src_index = i;
type_struct_field->gen_index = -1;
type_struct_field->gen_index = SIZE_MAX;
if (!field_type->deep_const) {
struct_type->deep_const = false;
@ -1574,16 +1574,16 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
return;
}
int gen_field_count = gen_field_index;
size_t gen_field_count = gen_field_index;
LLVMStructSetBody(struct_type->type_ref, element_types, gen_field_count, false);
ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(gen_field_count);
for (int i = 0; i < field_count; i += 1) {
for (size_t i = 0; i < field_count; i += 1) {
AstNode *field_node = decl_node->data.struct_decl.fields.at(i);
TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
gen_field_index = type_struct_field->gen_index;
if (gen_field_index == -1) {
if (gen_field_index == SIZE_MAX) {
continue;
}
@ -1697,7 +1697,7 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN
fn_table_entry->type_entry = get_generic_fn_type(g, proto_node);
if (is_extern || proto_node->data.fn_proto.top_level_decl.visib_mod == VisibModExport) {
for (int i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
AstNode *param_decl_node = proto_node->data.fn_proto.params.at(i);
if (param_decl_node->data.param_decl.is_inline) {
proto_node->data.fn_proto.skip = true;
@ -1754,7 +1754,7 @@ static void scan_struct_decl(CodeGen *g, ImportTableEntry *import, BlockContext
node->data.struct_decl.type_entry = container_type;
// handle the member function definitions independently
for (int i = 0; i < node->data.struct_decl.decls.length; i += 1) {
for (size_t i = 0; i < node->data.struct_decl.decls.length; i += 1) {
AstNode *child_node = node->data.struct_decl.decls.at(i);
get_as_top_level_decl(child_node)->parent_decl = node;
BlockContext *child_context = get_container_block_context(container_type);
@ -1802,7 +1802,7 @@ static void preview_error_value_decl(CodeGen *g, AstNode *node) {
// duplicate error definitions allowed and they get the same value
err->value = existing_entry->value->value;
} else {
int error_value_count = g->error_decls.length;
size_t error_value_count = g->error_decls.length;
assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)g->err_tag_type->data.integral.bit_count));
err->value = error_value_count;
g->error_decls.append(node);
@ -2100,7 +2100,7 @@ static bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTable
if (expected_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {
return false;
}
for (int i = 0; i < expected_type->data.fn.fn_type_id.param_count; i += 1) {
for (size_t i = 0; i < expected_type->data.fn.fn_type_id.param_count; i += 1) {
// note it's reversed for parameters
FnTypeParamInfo *actual_param_info = &actual_type->data.fn.fn_type_id.param_info[i];
FnTypeParamInfo *expected_param_info = &expected_type->data.fn.fn_type_id.param_info[i];
@ -2121,14 +2121,14 @@ static bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTable
}
static TypeTableEntry *determine_peer_type_compatibility(CodeGen *g, AstNode *parent_source_node,
AstNode **child_nodes, TypeTableEntry **child_types, int child_count)
AstNode **child_nodes, TypeTableEntry **child_types, size_t child_count)
{
TypeTableEntry *prev_type = child_types[0];
AstNode *prev_node = child_nodes[0];
if (prev_type->id == TypeTableEntryIdInvalid) {
return prev_type;
}
for (int i = 1; i < child_count; i += 1) {
for (size_t i = 1; i < child_count; i += 1) {
TypeTableEntry *cur_type = child_types[i];
AstNode *cur_node = child_nodes[i];
if (cur_type->id == TypeTableEntryIdInvalid) {
@ -2359,7 +2359,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, ImportTableEntry *
static TypeTableEntry *resolve_peer_type_compatibility(CodeGen *g, ImportTableEntry *import,
BlockContext *block_context, AstNode *parent_source_node,
AstNode **child_nodes, TypeTableEntry **child_types, int child_count)
AstNode **child_nodes, TypeTableEntry **child_types, size_t child_count)
{
assert(child_count > 0);
@ -2370,7 +2370,7 @@ static TypeTableEntry *resolve_peer_type_compatibility(CodeGen *g, ImportTableEn
return expected_type;
}
for (int i = 0; i < child_count; i += 1) {
for (size_t i = 0; i < child_count; i += 1) {
if (!child_nodes[i]) {
continue;
}
@ -2579,16 +2579,16 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
codegen->source_node = node;
int expr_field_count = container_init_expr->entries.length;
int actual_field_count = container_type->data.structure.src_field_count;
size_t expr_field_count = container_init_expr->entries.length;
size_t actual_field_count = container_type->data.structure.src_field_count;
AstNode *non_const_expr_culprit = nullptr;
int *field_use_counts = allocate<int>(actual_field_count);
size_t *field_use_counts = allocate<size_t>(actual_field_count);
ConstExprValue *const_val = &get_resolved_expr(node)->const_val;
const_val->ok = true;
const_val->data.x_struct.fields = allocate<ConstExprValue*>(actual_field_count);
for (int i = 0; i < expr_field_count; i += 1) {
for (size_t i = 0; i < expr_field_count; i += 1) {
AstNode *val_field_node = container_init_expr->entries.at(i);
assert(val_field_node->type == NodeTypeStructValueField);
@ -2608,7 +2608,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
return g->builtin_types.entry_invalid;
}
int field_index = type_field->src_index;
size_t field_index = type_field->src_index;
field_use_counts[field_index] += 1;
if (field_use_counts[field_index] > 1) {
add_node_error(g, val_field_node, buf_sprintf("duplicate field"));
@ -2641,7 +2641,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
}
}
for (int i = 0; i < actual_field_count; i += 1) {
for (size_t i = 0; i < actual_field_count; i += 1) {
if (field_use_counts[i] == 0) {
add_node_error(g, node,
buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i].name)));
@ -2652,7 +2652,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
container_type->data.structure.is_slice &&
kind == ContainerInitKindArray)
{
int elem_count = container_init_expr->entries.length;
size_t elem_count = container_init_expr->entries.length;
TypeTableEntry *pointer_type = container_type->data.structure.fields[0].type_entry;
assert(pointer_type->id == TypeTableEntryIdPointer);
@ -2662,7 +2662,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
const_val->ok = true;
const_val->data.x_array.fields = allocate<ConstExprValue*>(elem_count);
for (int i = 0; i < elem_count; i += 1) {
for (size_t i = 0; i < elem_count; i += 1) {
AstNode **elem_node = &container_init_expr->entries.at(i);
analyze_expression(g, import, context, child_type, *elem_node);
@ -2787,7 +2787,7 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i
AstNode *value_node;
if (container_init_node) {
assert(container_init_node->type == NodeTypeContainerInitExpr);
int param_count = container_init_node->data.container_init_expr.entries.length;
size_t param_count = container_init_node->data.container_init_expr.entries.length;
if (param_count > 1) {
AstNode *first_invalid_node = container_init_node->data.container_init_expr.entries.at(1);
add_node_error(g, first_executing_node(first_invalid_node),
@ -2849,7 +2849,7 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i
AstNode *decl_node = find_decl(namespace_import->block_context, field_name);
if (!decl_node) {
// we must now resolve all the use decls
for (int i = 0; i < namespace_import->use_decls.length; i += 1) {
for (size_t i = 0; i < namespace_import->use_decls.length; i += 1) {
AstNode *use_decl_node = namespace_import->use_decls.at(i);
if (!get_resolved_expr(use_decl_node->data.use.expr)->type_entry) {
preview_use_decl(g, use_decl_node);
@ -3051,13 +3051,13 @@ static TypeTableEntry *resolve_expr_const_val_as_c_string_lit(CodeGen *g, AstNod
Expr *expr = get_resolved_expr(node);
expr->const_val.ok = true;
int len_with_null = buf_len(str) + 1;
size_t len_with_null = buf_len(str) + 1;
expr->const_val.data.x_ptr.ptr = allocate<ConstExprValue*>(len_with_null);
expr->const_val.data.x_ptr.len = len_with_null;
expr->const_val.data.x_ptr.is_c_str = true;
ConstExprValue *all_chars = allocate<ConstExprValue>(len_with_null);
for (int i = 0; i < buf_len(str); i += 1) {
for (size_t i = 0; i < buf_len(str); i += 1) {
ConstExprValue *this_char = &all_chars[i];
this_char->ok = true;
bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]);
@ -3078,7 +3078,7 @@ static TypeTableEntry *resolve_expr_const_val_as_string_lit(CodeGen *g, AstNode
expr->const_val.data.x_array.fields = allocate<ConstExprValue*>(buf_len(str));
ConstExprValue *all_chars = allocate<ConstExprValue>(buf_len(str));
for (int i = 0; i < buf_len(str); i += 1) {
for (size_t i = 0; i < buf_len(str); i += 1) {
ConstExprValue *this_char = &all_chars[i];
this_char->ok = true;
bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]);
@ -4437,7 +4437,7 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B
assert(node->type == NodeTypeFnCallExpr);
AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr;
int actual_param_count = node->data.fn_call_expr.params.length;
size_t actual_param_count = node->data.fn_call_expr.params.length;
if (actual_param_count != 1) {
add_node_error(g, fn_ref_expr, buf_sprintf("cast expression expects exactly one parameter"));
@ -4799,7 +4799,7 @@ static TypeTableEntry *analyze_c_import(CodeGen *g, ImportTableEntry *parent_imp
if (errors.length > 0) {
ErrorMsg *parent_err_msg = add_node_error(g, node, buf_sprintf("C import failed"));
for (int i = 0; i < errors.length; i += 1) {
for (size_t i = 0; i < errors.length; i += 1) {
ErrorMsg *err_msg = errors.at(i);
err_msg_add_note(parent_err_msg, err_msg);
}
@ -5113,13 +5113,13 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
}
BuiltinFnEntry *builtin_fn = entry->value;
int actual_param_count = node->data.fn_call_expr.params.length;
size_t actual_param_count = node->data.fn_call_expr.params.length;
node->data.fn_call_expr.builtin_fn = builtin_fn;
if (builtin_fn->param_count != actual_param_count) {
add_node_error(g, node,
buf_sprintf("expected %d arguments, got %d",
buf_sprintf("expected %zu arguments, got %zu",
builtin_fn->param_count, actual_param_count));
return g->builtin_types.entry_invalid;
}
@ -5479,11 +5479,11 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
fn_table_entry->proto_node->data.fn_proto.generic_proto_node : nullptr;
// count parameters
int struct_node_1_or_0 = struct_node ? 1 : 0;
int src_param_count = fn_type->data.fn.fn_type_id.param_count +
size_t struct_node_1_or_0 = struct_node ? 1 : 0;
size_t src_param_count = fn_type->data.fn.fn_type_id.param_count +
(generic_proto_node ? generic_proto_node->data.fn_proto.inline_arg_count : 0);
int call_param_count = node->data.fn_call_expr.params.length;
int expect_arg_count = src_param_count - struct_node_1_or_0;
size_t call_param_count = node->data.fn_call_expr.params.length;
size_t expect_arg_count = src_param_count - struct_node_1_or_0;
bool ok_invocation = true;
@ -5491,12 +5491,12 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
if (call_param_count < expect_arg_count) {
ok_invocation = false;
add_node_error(g, node,
buf_sprintf("expected at least %d arguments, got %d", src_param_count, call_param_count));
buf_sprintf("expected at least %zu arguments, got %zu", src_param_count, call_param_count));
}
} else if (expect_arg_count != call_param_count) {
ok_invocation = false;
add_node_error(g, node,
buf_sprintf("expected %d arguments, got %d", expect_arg_count, call_param_count));
buf_sprintf("expected %zu arguments, got %zu", expect_arg_count, call_param_count));
}
bool all_args_const_expr = true;
@ -5510,9 +5510,9 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
// analyze each parameter. in the case of a method, we already analyzed the
// first parameter in order to figure out which struct we were calling a method on.
int next_type_i = struct_node_1_or_0;
for (int call_i = 0; call_i < call_param_count; call_i += 1) {
int proto_i = call_i + struct_node_1_or_0;
size_t next_type_i = struct_node_1_or_0;
for (size_t call_i = 0; call_i < call_param_count; call_i += 1) {
size_t proto_i = call_i + struct_node_1_or_0;
AstNode **param_node = &node->data.fn_call_expr.params.at(call_i);
// determine the expected type for each parameter
TypeTableEntry *expected_param_type = nullptr;
@ -5592,30 +5592,30 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE
AstNode *decl_node = fn_table_entry->proto_node;
// count parameters
int struct_node_1_or_0 = (struct_node ? 1 : 0);
int src_param_count = decl_node->data.fn_proto.params.length;
int call_param_count = call_node->data.fn_call_expr.params.length;
size_t struct_node_1_or_0 = (struct_node ? 1 : 0);
size_t src_param_count = decl_node->data.fn_proto.params.length;
size_t call_param_count = call_node->data.fn_call_expr.params.length;
if (src_param_count != call_param_count + struct_node_1_or_0) {
add_node_error(g, call_node,
buf_sprintf("expected %d arguments, got %d", src_param_count - struct_node_1_or_0, call_param_count));
buf_sprintf("expected %zu arguments, got %zu", src_param_count - struct_node_1_or_0, call_param_count));
return g->builtin_types.entry_invalid;
}
int inline_or_var_type_arg_count = decl_node->data.fn_proto.inline_or_var_type_arg_count;
size_t inline_or_var_type_arg_count = decl_node->data.fn_proto.inline_or_var_type_arg_count;
assert(inline_or_var_type_arg_count > 0);
BlockContext *child_context = decl_node->owner->block_context;
int next_generic_param_index = 0;
size_t next_generic_param_index = 0;
GenericFnTypeId *generic_fn_type_id = allocate<GenericFnTypeId>(1);
generic_fn_type_id->decl_node = decl_node;
generic_fn_type_id->generic_param_count = inline_or_var_type_arg_count;
generic_fn_type_id->generic_params = allocate<GenericParamValue>(inline_or_var_type_arg_count);
int next_impl_i = 0;
for (int call_i = 0; call_i < call_param_count; call_i += 1) {
int proto_i = call_i + struct_node_1_or_0;
size_t next_impl_i = 0;
for (size_t call_i = 0; call_i < call_param_count; call_i += 1) {
size_t proto_i = call_i + struct_node_1_or_0;
AstNode *generic_param_decl_node = decl_node->data.fn_proto.params.at(proto_i);
assert(generic_param_decl_node->type == NodeTypeParamDecl);
@ -5688,10 +5688,10 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE
impl_decl_node->data.fn_proto.generic_proto_node = decl_node;
// replace var arg types with actual types
for (int generic_arg_i = 0; generic_arg_i < inline_or_var_type_arg_count; generic_arg_i += 1) {
for (size_t generic_arg_i = 0; generic_arg_i < inline_or_var_type_arg_count; generic_arg_i += 1) {
GenericParamValue *generic_param_value = &generic_fn_type_id->generic_params[generic_arg_i];
if (!generic_param_value->node) {
int impl_i = generic_param_value->impl_index;
size_t impl_i = generic_param_value->impl_index;
AstNode *impl_param_decl_node = impl_decl_node->data.fn_proto.params.at(impl_i);
assert(impl_param_decl_node->type == NodeTypeParamDecl);
@ -5721,12 +5721,12 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
assert(decl_node->type == NodeTypeContainerDecl);
ZigList<AstNode *> *generic_params = &decl_node->data.struct_decl.generic_params;
int expected_param_count = generic_params->length;
int actual_param_count = node->data.fn_call_expr.params.length;
size_t expected_param_count = generic_params->length;
size_t actual_param_count = node->data.fn_call_expr.params.length;
if (actual_param_count != expected_param_count) {
add_node_error(g, first_executing_node(node),
buf_sprintf("expected %d arguments, got %d", expected_param_count, actual_param_count));
buf_sprintf("expected %zu arguments, got %zu", expected_param_count, actual_param_count));
return g->builtin_types.entry_invalid;
}
@ -5736,7 +5736,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
generic_fn_type_id->generic_params = allocate<GenericParamValue>(actual_param_count);
BlockContext *child_context = decl_node->owner->block_context;
for (int i = 0; i < actual_param_count; i += 1) {
for (size_t i = 0; i < actual_param_count; i += 1) {
AstNode *generic_param_decl_node = generic_params->at(i);
assert(generic_param_decl_node->type == NodeTypeParamDecl);
@ -6104,7 +6104,7 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
ConstExprValue *const_val = &get_resolved_expr(node)->const_val;
int prong_count = node->data.switch_expr.prongs.length;
size_t prong_count = node->data.switch_expr.prongs.length;
AstNode **peer_nodes = allocate<AstNode*>(prong_count);
TypeTableEntry **peer_types = allocate<TypeTableEntry*>(prong_count);
@ -6118,18 +6118,18 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
}
int *field_use_counts = nullptr;
size_t *field_use_counts = nullptr;
HashMap<int, AstNode *, int_hash, int_eq> err_use_nodes = {};
if (expr_type->id == TypeTableEntryIdEnum) {
field_use_counts = allocate<int>(expr_type->data.enumeration.field_count);
field_use_counts = allocate<size_t>(expr_type->data.enumeration.field_count);
} else if (expr_type->id == TypeTableEntryIdErrorUnion) {
err_use_nodes.init(10);
}
int *const_chosen_prong_index = &node->data.switch_expr.const_chosen_prong_index;
*const_chosen_prong_index = -1;
size_t *const_chosen_prong_index = &node->data.switch_expr.const_chosen_prong_index;
*const_chosen_prong_index = SIZE_MAX;
AstNode *else_prong = nullptr;
for (int prong_i = 0; prong_i < prong_count; prong_i += 1) {
for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {
AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);
TypeTableEntry *var_type;
@ -6143,14 +6143,14 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
}
var_type = expr_type;
var_is_target_expr = true;
if (*const_chosen_prong_index == -1 && expr_val->ok) {
if (*const_chosen_prong_index == SIZE_MAX && expr_val->ok) {
*const_chosen_prong_index = prong_i;
}
} else {
bool all_agree_on_var_type = true;
var_type = nullptr;
for (int item_i = 0; item_i < prong_node->data.switch_prong.items.length; item_i += 1) {
for (size_t item_i = 0; item_i < prong_node->data.switch_prong.items.length; item_i += 1) {
AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
if (item_node->type == NodeTypeSwitchRange) {
zig_panic("TODO range in switch statement");
@ -6274,7 +6274,7 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
}
}
for (int prong_i = 0; prong_i < prong_count; prong_i += 1) {
for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {
AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);
BlockContext *child_context = prong_node->data.switch_prong.block_context;
child_context->codegen_excluded = expr_val->ok && (*const_chosen_prong_index != prong_i);
@ -6312,7 +6312,7 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
peer_nodes, peer_types, prong_count);
if (expr_val->ok) {
assert(*const_chosen_prong_index != -1);
assert(*const_chosen_prong_index != SIZE_MAX);
*const_val = get_resolved_expr(peer_nodes[*const_chosen_prong_index])->const_val;
// the target expr depends on a compile var because we have an error on unnecessary
@ -6460,7 +6460,7 @@ static TypeTableEntry *analyze_block_expr(CodeGen *g, ImportTableEntry *import,
node->data.block.child_block = child_context;
TypeTableEntry *return_type = g->builtin_types.entry_void;
for (int i = 0; i < node->data.block.statements.length; i += 1) {
for (size_t i = 0; i < node->data.block.statements.length; i += 1) {
AstNode *child = node->data.block.statements.at(i);
if (child->type == NodeTypeLabel) {
FnTableEntry *fn_table_entry = child_context->fn_entry;
@ -6524,7 +6524,7 @@ static TypeTableEntry *analyze_asm_expr(CodeGen *g, ImportTableEntry *import, Bl
node->data.asm_expr.return_count = 0;
TypeTableEntry *return_type = g->builtin_types.entry_void;
for (int i = 0; i < node->data.asm_expr.output_list.length; i += 1) {
for (size_t i = 0; i < node->data.asm_expr.output_list.length; i += 1) {
AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);
if (asm_output->return_type) {
node->data.asm_expr.return_count += 1;
@ -6547,7 +6547,7 @@ static TypeTableEntry *analyze_asm_expr(CodeGen *g, ImportTableEntry *import, Bl
}
}
}
for (int i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
analyze_expression(g, import, context, nullptr, asm_input->expr);
}
@ -6757,7 +6757,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
TypeTableEntry *fn_type = fn_table_entry->type_entry;
AstNodeFnProto *fn_proto = &fn_proto_node->data.fn_proto;
for (int i = 0; i < fn_proto->params.length; i += 1) {
for (size_t i = 0; i < fn_proto->params.length; i += 1) {
AstNode *param_decl_node = fn_proto->params.at(i);
assert(param_decl_node->type == NodeTypeParamDecl);
@ -6797,13 +6797,13 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
node->data.fn_def.implicit_return_type = block_return_type;
for (int i = 0; i < fn_table_entry->goto_list.length; i += 1) {
for (size_t i = 0; i < fn_table_entry->goto_list.length; i += 1) {
AstNode *goto_node = fn_table_entry->goto_list.at(i);
assert(goto_node->type == NodeTypeGoto);
analyze_goto_pass2(g, import, goto_node);
}
for (int i = 0; i < fn_table_entry->all_labels.length; i += 1) {
for (size_t i = 0; i < fn_table_entry->all_labels.length; i += 1) {
LabelTableEntry *label = fn_table_entry->all_labels.at(i);
if (!label->used) {
add_node_error(g, label->decl_node,
@ -6846,8 +6846,8 @@ static void add_top_level_decl(CodeGen *g, ImportTableEntry *import, BlockContex
static void count_inline_and_var_args(AstNode *proto_node) {
assert(proto_node->type == NodeTypeFnProto);
int *inline_arg_count = &proto_node->data.fn_proto.inline_arg_count;
int *inline_or_var_type_arg_count = &proto_node->data.fn_proto.inline_or_var_type_arg_count;
size_t *inline_arg_count = &proto_node->data.fn_proto.inline_arg_count;
size_t *inline_or_var_type_arg_count = &proto_node->data.fn_proto.inline_or_var_type_arg_count;
*inline_arg_count = 0;
*inline_or_var_type_arg_count = 0;
@ -6855,7 +6855,7 @@ static void count_inline_and_var_args(AstNode *proto_node) {
// TODO run these nodes through the type analysis system rather than looking for
// specialized ast nodes. this would get fooled by `{var}` instead of `var` which
// is supposed to be equivalent
for (int i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
AstNode *param_node = proto_node->data.fn_proto.params.at(i);
assert(param_node->type == NodeTypeParamDecl);
if (param_node->data.param_decl.is_inline) {
@ -6870,7 +6870,7 @@ static void count_inline_and_var_args(AstNode *proto_node) {
static void scan_decls(CodeGen *g, ImportTableEntry *import, BlockContext *context, AstNode *node) {
switch (node->type) {
case NodeTypeRoot:
for (int i = 0; i < import->root->data.root.top_level_decls.length; i += 1) {
for (size_t i = 0; i < import->root->data.root.top_level_decls.length; i += 1) {
AstNode *child = import->root->data.root.top_level_decls.at(i);
scan_decls(g, import, context, child);
}
@ -6992,7 +6992,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
tld->import->any_imports_failed = true;
}
for (int i = 0; i < target_import->root->data.root.top_level_decls.length; i += 1) {
for (size_t i = 0; i < target_import->root->data.root.top_level_decls.length; i += 1) {
AstNode *decl_node = target_import->root->data.root.top_level_decls.at(i);
if (decl_node->type == NodeTypeFnDef) {
decl_node = decl_node->data.fn_def.fn_proto;
@ -7018,7 +7018,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
}
}
for (int i = 0; i < target_import->use_decls.length; i += 1) {
for (size_t i = 0; i < target_import->use_decls.length; i += 1) {
AstNode *use_decl_node = target_import->use_decls.at(i);
TopLevelDecl *target_tld = get_as_top_level_decl(use_decl_node);
if (target_tld->visib_mod != VisibModPrivate) {
@ -7104,7 +7104,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
assert(import_entry->root->type == NodeTypeRoot);
for (int decl_i = 0; decl_i < import_entry->root->data.root.top_level_decls.length; decl_i += 1) {
for (size_t decl_i = 0; decl_i < import_entry->root->data.root.top_level_decls.length; decl_i += 1) {
AstNode *top_level_decl = import_entry->root->data.root.top_level_decls.at(decl_i);
if (top_level_decl->type == NodeTypeFnDef) {
@ -7135,7 +7135,7 @@ void semantic_analyze(CodeGen *g) {
preview_use_decl(g, use_decl_node);
}
for (int i = 0; i < g->use_queue.length; i += 1) {
for (size_t i = 0; i < g->use_queue.length; i += 1) {
AstNode *use_decl_node = g->use_queue.at(i);
resolve_use_decl(g, use_decl_node);
}
@ -7146,7 +7146,7 @@ void semantic_analyze(CodeGen *g) {
resolve_top_level_decl(g, decl_node, pointer_only);
}
for (int i = 0; i < g->fn_defs.length; i += 1) {
for (size_t i = 0; i < g->fn_defs.length; i += 1) {
FnTableEntry *fn_entry = g->fn_defs.at(i);
if (fn_entry->anal_state == FnAnalStateReady) {
analyze_fn_body(g, fn_entry);
@ -7321,8 +7321,8 @@ bool is_node_void_expr(AstNode *node) {
return false;
}
TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits) {
int index;
TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, size_t size_in_bits) {
size_t index;
if (size_in_bits == 8) {
index = 0;
} else if (size_in_bits == 16) {
@ -7337,7 +7337,7 @@ TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits)
return &g->builtin_types.entry_int[is_signed ? 0 : 1][index];
}
TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, int size_in_bits) {
TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, size_t size_in_bits) {
return *get_int_type_ptr(g, is_signed, size_in_bits);
}
@ -7417,7 +7417,7 @@ uint32_t fn_type_id_hash(FnTypeId *id) {
result += id->is_cold ? 3605523458 : 0;
result += id->is_var_args ? 1931444534 : 0;
result += hash_ptr(id->return_type);
for (int i = 0; i < id->param_count; i += 1) {
for (size_t i = 0; i < id->param_count; i += 1) {
FnTypeParamInfo *info = &id->param_info[i];
result += info->is_noalias ? 892356923 : 0;
result += hash_ptr(info->type);
@ -7435,7 +7435,7 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {
{
return false;
}
for (int i = 0; i < a->param_count; i += 1) {
for (size_t i = 0; i < a->param_count; i += 1) {
FnTypeParamInfo *a_param_info = &a->param_info[i];
FnTypeParamInfo *b_param_info = &b->param_info[i];
@ -7511,7 +7511,7 @@ static uint32_t hash_const_val(TypeTableEntry *type, ConstExprValue *const_val)
uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {
uint32_t result = 0;
result += hash_ptr(id->decl_node);
for (int i = 0; i < id->generic_param_count; i += 1) {
for (size_t i = 0; i < id->generic_param_count; i += 1) {
GenericParamValue *generic_param = &id->generic_params[i];
if (generic_param->node) {
ConstExprValue *const_val = &get_resolved_expr(generic_param->node)->const_val;
@ -7526,7 +7526,7 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {
bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
if (a->decl_node != b->decl_node) return false;
assert(a->generic_param_count == b->generic_param_count);
for (int i = 0; i < a->generic_param_count; i += 1) {
for (size_t i = 0; i < a->generic_param_count; i += 1) {
GenericParamValue *a_val = &a->generic_params[i];
GenericParamValue *b_val = &b->generic_params[i];
if (a_val->type != b_val->type) return false;

View File

@ -19,8 +19,8 @@ BlockContext *new_block_context(AstNode *node, BlockContext *parent);
Expr *get_resolved_expr(AstNode *node);
bool is_node_void_expr(AstNode *node);
uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits);
TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, int size_in_bits);
TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, size_t size_in_bits);
TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, size_t size_in_bits);
TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);
TypeTableEntry *get_typedecl_type(CodeGen *g, const char *name, TypeTableEntry *child_type);

View File

@ -292,7 +292,7 @@ static bool is_printable(uint8_t c) {
static void string_literal_escape(Buf *source, Buf *dest) {
buf_resize(dest, 0);
for (int i = 0; i < buf_len(source); i += 1) {
for (size_t i = 0; i < buf_len(source); i += 1) {
uint8_t c = *((uint8_t*)buf_ptr(source) + i);
if (is_printable(c)) {
buf_append_char(dest, c);
@ -330,7 +330,7 @@ static bool is_valid_bare_symbol(Buf *symbol) {
if (!is_alpha_under(first_char)) {
return false;
}
for (int i = 1; i < buf_len(symbol); i += 1) {
for (size_t i = 1; i < buf_len(symbol); i += 1) {
uint8_t c = *((uint8_t*)buf_ptr(symbol) + i);
if (!is_alpha_under(c) && !is_digit(c)) {
return false;
@ -358,7 +358,7 @@ static void render_node(AstRender *ar, AstNode *node) {
switch (node->type) {
case NodeTypeRoot:
for (int i = 0; i < node->data.root.top_level_decls.length; i += 1) {
for (size_t i = 0; i < node->data.root.top_level_decls.length; i += 1) {
AstNode *child = node->data.root.top_level_decls.at(i);
print_indent(ar);
render_node(ar, child);
@ -417,7 +417,7 @@ static void render_node(AstRender *ar, AstNode *node) {
ZigList<AstNode *> *directives =
node->data.fn_def.fn_proto->data.fn_proto.top_level_decl.directives;
if (directives) {
for (int i = 0; i < directives->length; i += 1) {
for (size_t i = 0; i < directives->length; i += 1) {
render_node(ar, directives->at(i));
}
}
@ -433,7 +433,7 @@ static void render_node(AstRender *ar, AstNode *node) {
case NodeTypeBlock:
fprintf(ar->f, "{\n");
ar->indent += ar->indent_size;
for (int i = 0; i < node->data.block.statements.length; i += 1) {
for (size_t i = 0; i < node->data.block.statements.length; i += 1) {
AstNode *statement = node->data.block.statements.at(i);
print_indent(ar);
render_node(ar, statement);
@ -561,7 +561,7 @@ static void render_node(AstRender *ar, AstNode *node) {
fprintf(ar->f, ")");
}
fprintf(ar->f, "(");
for (int i = 0; i < node->data.fn_call_expr.params.length; i += 1) {
for (size_t i = 0; i < node->data.fn_call_expr.params.length; i += 1) {
AstNode *param = node->data.fn_call_expr.params.at(i);
if (i != 0) {
fprintf(ar->f, ", ");
@ -628,7 +628,7 @@ static void render_node(AstRender *ar, AstNode *node) {
const char *container_str = container_string(node->data.struct_decl.kind);
fprintf(ar->f, "%s%s %s {\n", pub_str, container_str, struct_name);
ar->indent += ar->indent_size;
for (int field_i = 0; field_i < node->data.struct_decl.fields.length; field_i += 1) {
for (size_t field_i = 0; field_i < node->data.struct_decl.fields.length; field_i += 1) {
AstNode *field_node = node->data.struct_decl.fields.at(field_i);
assert(field_node->type == NodeTypeStructField);
print_indent(ar);

View File

@ -43,7 +43,7 @@ void bignum_init_signed(BigNum *dest, int64_t x) {
}
void bignum_init_bignum(BigNum *dest, BigNum *src) {
memcpy(dest, src, sizeof(BigNum));
safe_memcpy(dest, src, 1);
}
bool bignum_fits_in_bits(BigNum *bn, int bit_count, bool is_signed) {

View File

@ -41,7 +41,7 @@ void buf_appendf(Buf *buf, const char *format, ...) {
size_t required_size = len1 + 1;
int orig_len = buf_len(buf);
size_t orig_len = buf_len(buf);
buf_resize(buf, orig_len + len1);
@ -62,7 +62,7 @@ uint32_t buf_hash(Buf *buf) {
assert(buf->list.length);
// FNV 32-bit hash
uint32_t h = 2166136261;
for (int i = 0; i < buf_len(buf); i += 1) {
for (size_t i = 0; i < buf_len(buf); i += 1) {
h = h ^ ((uint8_t)buf->list.at(i));
h = h * 16777619;
}

View File

@ -27,7 +27,7 @@ Buf *buf_sprintf(const char *format, ...)
__attribute__ ((format (printf, 1, 2)));
Buf *buf_vprintf(const char *format, va_list ap);
static inline int buf_len(Buf *buf) {
static inline size_t buf_len(Buf *buf) {
assert(buf->list.length);
return buf->list.length - 1;
}
@ -37,31 +37,29 @@ static inline char *buf_ptr(Buf *buf) {
return buf->list.items;
}
static inline void buf_resize(Buf *buf, int new_len) {
static inline void buf_resize(Buf *buf, size_t new_len) {
buf->list.resize(new_len + 1);
buf->list.at(buf_len(buf)) = 0;
}
static inline Buf *buf_alloc(void) {
Buf *buf = allocate<Buf>(1);
buf_resize(buf, 0);
return buf;
}
static inline Buf *buf_alloc_fixed(int size) {
static inline Buf *buf_alloc_fixed(size_t size) {
Buf *buf = allocate<Buf>(1);
buf_resize(buf, size);
return buf;
}
static inline Buf *buf_alloc(void) {
return buf_alloc_fixed(0);
}
static inline void buf_deinit(Buf *buf) {
buf->list.deinit();
}
static inline void buf_init_from_mem(Buf *buf, const char *ptr, int len) {
assert(len >= 0);
static inline void buf_init_from_mem(Buf *buf, const char *ptr, size_t len) {
assert(len != SIZE_MAX);
buf->list.resize(len + 1);
memcpy(buf_ptr(buf), ptr, len);
safe_memcpy(buf_ptr(buf), ptr, len);
buf->list.at(buf_len(buf)) = 0;
}
@ -73,8 +71,8 @@ static inline void buf_init_from_buf(Buf *buf, Buf *other) {
buf_init_from_mem(buf, buf_ptr(other), buf_len(other));
}
static inline Buf *buf_create_from_mem(const char *ptr, int len) {
assert(len >= 0);
static inline Buf *buf_create_from_mem(const char *ptr, size_t len) {
assert(len != SIZE_MAX);
Buf *buf = allocate<Buf>(1);
buf_init_from_mem(buf, ptr, len);
return buf;
@ -88,25 +86,25 @@ static inline Buf *buf_create_from_buf(Buf *buf) {
return buf_create_from_mem(buf_ptr(buf), buf_len(buf));
}
static inline Buf *buf_slice(Buf *in_buf, int start, int end) {
static inline Buf *buf_slice(Buf *in_buf, size_t start, size_t end) {
assert(in_buf->list.length);
assert(start >= 0);
assert(end >= 0);
assert(start != SIZE_MAX);
assert(end != SIZE_MAX);
assert(start < buf_len(in_buf));
assert(end <= buf_len(in_buf));
Buf *out_buf = allocate<Buf>(1);
out_buf->list.resize(end - start + 1);
memcpy(buf_ptr(out_buf), buf_ptr(in_buf) + start, end - start);
safe_memcpy(buf_ptr(out_buf), buf_ptr(in_buf) + start, end - start);
out_buf->list.at(buf_len(out_buf)) = 0;
return out_buf;
}
static inline void buf_append_mem(Buf *buf, const char *mem, int mem_len) {
static inline void buf_append_mem(Buf *buf, const char *mem, size_t mem_len) {
assert(buf->list.length);
assert(mem_len >= 0);
int old_len = buf_len(buf);
assert(mem_len != SIZE_MAX);
size_t old_len = buf_len(buf);
buf_resize(buf, old_len + mem_len);
memcpy(buf_ptr(buf) + old_len, mem, mem_len);
safe_memcpy(buf_ptr(buf) + old_len, mem, mem_len);
buf->list.at(buf_len(buf)) = 0;
}
@ -128,7 +126,7 @@ static inline void buf_append_char(Buf *buf, uint8_t c) {
void buf_appendf(Buf *buf, const char *format, ...)
__attribute__ ((format (printf, 2, 3)));
static inline bool buf_eql_mem(Buf *buf, const char *mem, int mem_len) {
static inline bool buf_eql_mem(Buf *buf, const char *mem, size_t mem_len) {
assert(buf->list.length);
if (buf_len(buf) != mem_len)
return false;
@ -140,7 +138,7 @@ static inline bool buf_eql_str(Buf *buf, const char *str) {
return buf_eql_mem(buf, str, strlen(str));
}
static inline bool buf_starts_with_mem(Buf *buf, const char *mem, int mem_len) {
static inline bool buf_starts_with_mem(Buf *buf, const char *mem, size_t mem_len) {
if (buf_len(buf) < mem_len) {
return false;
}
@ -155,7 +153,7 @@ static inline bool buf_starts_with_str(Buf *buf, const char *str) {
return buf_starts_with_mem(buf, str, strlen(str));
}
static inline bool buf_ends_with_mem(Buf *buf, const char *mem, int mem_len) {
static inline bool buf_ends_with_mem(Buf *buf, const char *mem, size_t mem_len) {
if (buf_len(buf) < mem_len) {
return false;
}
@ -170,7 +168,7 @@ bool buf_eql_buf(Buf *buf, Buf *other);
uint32_t buf_hash(Buf *buf);
static inline void buf_upcase(Buf *buf) {
for (int i = 0; i < buf_len(buf); i += 1) {
for (size_t i = 0; i < buf_len(buf); i += 1) {
buf_ptr(buf)[i] = toupper(buf_ptr(buf)[i]);
}
}

View File

@ -111,7 +111,7 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) {
return g;
}
void codegen_set_clang_argv(CodeGen *g, const char **args, int len) {
void codegen_set_clang_argv(CodeGen *g, const char **args, size_t len) {
g->clang_argv = args;
g->clang_argv_len = len;
}
@ -166,6 +166,7 @@ void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) {
void codegen_set_zig_std_dir(CodeGen *g, Buf *zig_std_dir) {
g->zig_std_dir = zig_std_dir;
g->std_package->root_src_dir = *zig_std_dir;
}
@ -261,7 +262,7 @@ enum AddSubMul {
AddSubMulMul = 2,
};
static int bits_index(int size_in_bits) {
static size_t bits_index(size_t size_in_bits) {
switch (size_in_bits) {
case 8:
return 0;
@ -281,7 +282,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_
{
assert(type_entry->id == TypeTableEntryIdInt);
const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;
Buf *llvm_name = buf_sprintf("llvm.%s.with.overflow.i%d", signed_str, type_entry->data.integral.bit_count);
Buf *llvm_name = buf_sprintf("llvm.%s.with.overflow.i%zu", signed_str, type_entry->data.integral.bit_count);
LLVMTypeRef return_elem_types[] = {
type_entry->type_ref,
@ -301,9 +302,9 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_
static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry, AddSubMul add_sub_mul) {
assert(type_entry->id == TypeTableEntryIdInt);
// [0-signed,1-unsigned][0-add,1-sub,2-mul][0-8,1-16,2-32,3-64]
int index0 = type_entry->data.integral.is_signed ? 0 : 1;
int index1 = add_sub_mul;
int index2 = bits_index(type_entry->data.integral.bit_count);
size_t index0 = type_entry->data.integral.is_signed ? 0 : 1;
size_t index1 = add_sub_mul;
size_t index2 = bits_index(type_entry->data.integral.bit_count);
LLVMValueRef *fn = &g->int_overflow_fns[index0][index1][index2];
if (*fn) {
return *fn;
@ -325,12 +326,12 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, BuiltinFnId fn_id) {
// [0-ctz,1-clz][0-8,1-16,2-32,3-64]
int index0 = (fn_id == BuiltinFnIdCtz) ? 0 : 1;
int index1 = bits_index(int_type->data.integral.bit_count);
size_t index0 = (fn_id == BuiltinFnIdCtz) ? 0 : 1;
size_t index1 = bits_index(int_type->data.integral.bit_count);
LLVMValueRef *fn = &g->int_builtin_fns[index0][index1];
if (!*fn) {
const char *fn_name = (fn_id == BuiltinFnIdCtz) ? "cttz" : "ctlz";
Buf *llvm_name = buf_sprintf("llvm.%s.i%d", fn_name, int_type->data.integral.bit_count);
Buf *llvm_name = buf_sprintf("llvm.%s.i%zu", fn_name, int_type->data.integral.bit_count);
LLVMTypeRef param_types[] = {
int_type->type_ref,
LLVMInt1Type(),
@ -516,7 +517,7 @@ static LLVMValueRef gen_unreachable(CodeGen *g, AstNode *node) {
static LLVMValueRef gen_shl_with_overflow(CodeGen *g, AstNode *node) {
assert(node->type == NodeTypeFnCallExpr);
int fn_call_param_count = node->data.fn_call_expr.params.length;
size_t fn_call_param_count = node->data.fn_call_expr.params.length;
assert(fn_call_param_count == 4);
TypeTableEntry *int_type = get_type_for_type_node(node->data.fn_call_expr.params.at(0));
@ -561,7 +562,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {
case BuiltinFnIdCtz:
case BuiltinFnIdClz:
{
int fn_call_param_count = node->data.fn_call_expr.params.length;
size_t fn_call_param_count = node->data.fn_call_expr.params.length;
assert(fn_call_param_count == 2);
TypeTableEntry *int_type = get_type_for_type_node(node->data.fn_call_expr.params.at(0));
assert(int_type->id == TypeTableEntryIdInt);
@ -578,7 +579,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {
case BuiltinFnIdSubWithOverflow:
case BuiltinFnIdMulWithOverflow:
{
int fn_call_param_count = node->data.fn_call_expr.params.length;
size_t fn_call_param_count = node->data.fn_call_expr.params.length;
assert(fn_call_param_count == 4);
TypeTableEntry *int_type = get_type_for_type_node(node->data.fn_call_expr.params.at(0));
@ -615,7 +616,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {
return gen_shl_with_overflow(g, node);
case BuiltinFnIdMemcpy:
{
int fn_call_param_count = node->data.fn_call_expr.params.length;
size_t fn_call_param_count = node->data.fn_call_expr.params.length;
assert(fn_call_param_count == 3);
AstNode *dest_node = node->data.fn_call_expr.params.at(0);
@ -646,7 +647,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {
}
case BuiltinFnIdMemset:
{
int fn_call_param_count = node->data.fn_call_expr.params.length;
size_t fn_call_param_count = node->data.fn_call_expr.params.length;
assert(fn_call_param_count == 3);
AstNode *dest_node = node->data.fn_call_expr.params.at(0);
@ -949,14 +950,14 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
set_debug_source_node(g, node);
int ptr_index = wanted_type->data.structure.fields[0].gen_index;
if (ptr_index >= 0) {
size_t ptr_index = wanted_type->data.structure.fields[0].gen_index;
if (ptr_index != SIZE_MAX) {
LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, ptr_index, "");
LLVMValueRef expr_bitcast = LLVMBuildBitCast(g->builder, expr_val, pointer_type->type_ref, "");
LLVMBuildStore(g->builder, expr_bitcast, ptr_ptr);
}
int len_index = wanted_type->data.structure.fields[1].gen_index;
size_t len_index = wanted_type->data.structure.fields[1].gen_index;
LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, len_index, "");
LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
actual_type->data.array.len, false);
@ -979,10 +980,10 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
set_debug_source_node(g, node);
int actual_ptr_index = actual_type->data.structure.fields[0].gen_index;
int actual_len_index = actual_type->data.structure.fields[1].gen_index;
int wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
int wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
size_t actual_ptr_index = actual_type->data.structure.fields[0].gen_index;
size_t actual_len_index = actual_type->data.structure.fields[1].gen_index;
size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
size_t wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, expr_val, actual_ptr_index, "");
LLVMValueRef src_ptr = LLVMBuildLoad(g->builder, src_ptr_ptr, "");
@ -1040,12 +1041,12 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
set_debug_source_node(g, node);
int wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, wanted_ptr_index, "");
LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, expr_val, wanted_pointer_type->type_ref, "");
LLVMBuildStore(g->builder, src_ptr_casted, dest_ptr_ptr);
int wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
size_t wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, wanted_len_index, "");
LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
actual_type->data.array.len / type_size(g, wanted_child_type), false);
@ -1125,15 +1126,15 @@ static LLVMValueRef gen_fn_call_expr(CodeGen *g, AstNode *node) {
bool ret_has_bits = type_has_bits(src_return_type);
int fn_call_param_count = node->data.fn_call_expr.params.length;
size_t fn_call_param_count = node->data.fn_call_expr.params.length;
bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type);
int actual_param_count = fn_call_param_count + (struct_type ? 1 : 0) + (first_arg_ret ? 1 : 0);
size_t actual_param_count = fn_call_param_count + (struct_type ? 1 : 0) + (first_arg_ret ? 1 : 0);
bool is_var_args = fn_type->data.fn.fn_type_id.is_var_args;
// don't really include void values
LLVMValueRef *gen_param_values = allocate<LLVMValueRef>(actual_param_count);
int gen_param_index = 0;
size_t gen_param_index = 0;
if (first_arg_ret) {
gen_param_values[gen_param_index] = node->data.fn_call_expr.tmp_ptr;
gen_param_index += 1;
@ -1144,8 +1145,8 @@ static LLVMValueRef gen_fn_call_expr(CodeGen *g, AstNode *node) {
gen_param_index += 1;
}
for (int call_i = 0; call_i < fn_call_param_count; call_i += 1) {
int proto_i = call_i + (struct_type ? 1 : 0);
for (size_t call_i = 0; call_i < fn_call_param_count; call_i += 1) {
size_t proto_i = call_i + (struct_type ? 1 : 0);
if (generic_proto_node &&
generic_proto_node->data.fn_proto.params.at(proto_i)->data.param_decl.is_inline)
{
@ -1231,16 +1232,16 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal
if (want_debug_safety(g, source_node)) {
set_debug_source_node(g, source_node);
int len_index = array_type->data.structure.fields[1].gen_index;
assert(len_index >= 0);
size_t len_index = array_type->data.structure.fields[1].gen_index;
assert(len_index != SIZE_MAX);
LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, len_index, "");
LLVMValueRef len = LLVMBuildLoad(g->builder, len_ptr, "");
add_bounds_check(g, source_node, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len);
}
set_debug_source_node(g, source_node);
int ptr_index = array_type->data.structure.fields[0].gen_index;
assert(ptr_index >= 0);
size_t ptr_index = array_type->data.structure.fields[0].gen_index;
assert(ptr_index != SIZE_MAX);
LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, ptr_index, "");
LLVMValueRef ptr = LLVMBuildLoad(g->builder, ptr_ptr, "");
return LLVMBuildInBoundsGEP(g->builder, ptr, &subscript_value, 1, "");
@ -1297,8 +1298,8 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou
assert(LLVMGetTypeKind(LLVMTypeOf(struct_ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(struct_ptr))) == LLVMStructTypeKind);
int gen_field_index = node->data.field_access_expr.type_struct_field->gen_index;
assert(gen_field_index >= 0);
size_t gen_field_index = node->data.field_access_expr.type_struct_field->gen_index;
assert(gen_field_index != SIZE_MAX);
set_debug_source_node(g, node);
return LLVMBuildStructGEP(g->builder, struct_ptr, gen_field_index, "");
@ -1368,10 +1369,10 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) {
assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
int ptr_index = array_type->data.structure.fields[0].gen_index;
assert(ptr_index >= 0);
int len_index = array_type->data.structure.fields[1].gen_index;
assert(len_index >= 0);
size_t ptr_index = array_type->data.structure.fields[0].gen_index;
assert(ptr_index != SIZE_MAX);
size_t len_index = array_type->data.structure.fields[1].gen_index;
assert(len_index != SIZE_MAX);
LLVMValueRef prev_end = nullptr;
if (!node->data.slice_expr.end || want_debug_safety(g, node)) {
@ -2395,8 +2396,8 @@ static void gen_defers_for_block(CodeGen *g, BlockContext *inner_block, BlockCon
}
}
static int get_conditional_defer_count(BlockContext *inner_block, BlockContext *outer_block) {
int result = 0;
static size_t get_conditional_defer_count(BlockContext *inner_block, BlockContext *outer_block) {
size_t result = 0;
while (inner_block != outer_block) {
if (inner_block->node->type == NodeTypeDefer &&
(inner_block->node->data.defer.kind == ReturnKindError ||
@ -2776,7 +2777,7 @@ static LLVMValueRef gen_block(CodeGen *g, AstNode *block_node, TypeTableEntry *i
assert(block_node->type == NodeTypeBlock);
LLVMValueRef return_value = nullptr;
for (int i = 0; i < block_node->data.block.statements.length; i += 1) {
for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
AstNode *statement_node = block_node->data.block.statements.at(i);
return_value = gen_expr(g, statement_node);
}
@ -2796,23 +2797,23 @@ static LLVMValueRef gen_block(CodeGen *g, AstNode *block_node, TypeTableEntry *i
}
}
static int find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok) {
static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok) {
const char *ptr = buf_ptr(node->data.asm_expr.asm_template) + tok->start + 2;
int len = tok->end - tok->start - 2;
int result = 0;
for (int i = 0; i < node->data.asm_expr.output_list.length; i += 1, result += 1) {
size_t len = tok->end - tok->start - 2;
size_t result = 0;
for (size_t i = 0; i < node->data.asm_expr.output_list.length; i += 1, result += 1) {
AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);
if (buf_eql_mem(asm_output->asm_symbolic_name, ptr, len)) {
return result;
}
}
for (int i = 0; i < node->data.asm_expr.input_list.length; i += 1, result += 1) {
for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1, result += 1) {
AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
if (buf_eql_mem(asm_input->asm_symbolic_name, ptr, len)) {
return result;
}
}
return -1;
return SIZE_MAX;
}
static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
@ -2825,11 +2826,11 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
Buf llvm_template = BUF_INIT;
buf_resize(&llvm_template, 0);
for (int token_i = 0; token_i < asm_expr->token_list.length; token_i += 1) {
for (size_t token_i = 0; token_i < asm_expr->token_list.length; token_i += 1) {
AsmToken *asm_token = &asm_expr->token_list.at(token_i);
switch (asm_token->id) {
case AsmTokenIdTemplate:
for (int offset = asm_token->start; offset < asm_token->end; offset += 1) {
for (size_t offset = asm_token->start; offset < asm_token->end; offset += 1) {
uint8_t c = *((uint8_t*)(buf_ptr(src_template) + offset));
if (c == '$') {
buf_append_str(&llvm_template, "$$");
@ -2842,9 +2843,9 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
buf_append_char(&llvm_template, '%');
break;
case AsmTokenIdVar:
int index = find_asm_index(g, node, asm_token);
assert(index >= 0);
buf_appendf(&llvm_template, "$%d", index);
size_t index = find_asm_index(g, node, asm_token);
assert(index < SIZE_MAX);
buf_appendf(&llvm_template, "$%zu", index);
break;
}
}
@ -2854,17 +2855,17 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
assert(asm_expr->return_count == 0 || asm_expr->return_count == 1);
int total_constraint_count = asm_expr->output_list.length +
size_t total_constraint_count = asm_expr->output_list.length +
asm_expr->input_list.length +
asm_expr->clobber_list.length;
int input_and_output_count = asm_expr->output_list.length +
size_t input_and_output_count = asm_expr->output_list.length +
asm_expr->input_list.length -
asm_expr->return_count;
int total_index = 0;
int param_index = 0;
size_t total_index = 0;
size_t param_index = 0;
LLVMTypeRef *param_types = allocate<LLVMTypeRef>(input_and_output_count);
LLVMValueRef *param_values = allocate<LLVMValueRef>(input_and_output_count);
for (int i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {
for (size_t i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {
AsmOutput *asm_output = asm_expr->output_list.at(i);
bool is_return = (asm_output->return_type != nullptr);
assert(*buf_ptr(asm_output->constraint) == '=');
@ -2885,7 +2886,7 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
param_index += 1;
}
}
for (int i = 0; i < asm_expr->input_list.length; i += 1, total_index += 1, param_index += 1) {
for (size_t i = 0; i < asm_expr->input_list.length; i += 1, total_index += 1, param_index += 1) {
AsmInput *asm_input = asm_expr->input_list.at(i);
buf_append_buf(&constraint_buf, asm_input->constraint);
if (total_index + 1 < total_constraint_count) {
@ -2896,7 +2897,7 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
param_types[param_index] = expr_type->type_ref;
param_values[param_index] = gen_expr(g, asm_input->expr);
}
for (int i = 0; i < asm_expr->clobber_list.length; i += 1, total_index += 1) {
for (size_t i = 0; i < asm_expr->clobber_list.length; i += 1, total_index += 1) {
Buf *clobber_buf = asm_expr->clobber_list.at(i);
buf_appendf(&constraint_buf, "~{%s}", buf_ptr(clobber_buf));
if (total_index + 1 < total_constraint_count) {
@ -2927,7 +2928,7 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
if (node->data.container_init_expr.enum_type) {
int param_count = node->data.container_init_expr.entries.length;
size_t param_count = node->data.container_init_expr.entries.length;
AstNode *arg1_node;
if (param_count == 1) {
arg1_node = node->data.container_init_expr.entries.at(0);
@ -2943,13 +2944,13 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
if (type_entry->id == TypeTableEntryIdStruct) {
assert(node->data.container_init_expr.kind == ContainerInitKindStruct);
int src_field_count = type_entry->data.structure.src_field_count;
size_t src_field_count = type_entry->data.structure.src_field_count;
assert(src_field_count == node->data.container_init_expr.entries.length);
StructValExprCodeGen *struct_val_expr_node = &node->data.container_init_expr.resolved_struct_val_expr;
LLVMValueRef tmp_struct_ptr = struct_val_expr_node->ptr;
for (int i = 0; i < src_field_count; i += 1) {
for (size_t i = 0; i < src_field_count; i += 1) {
AstNode *field_node = node->data.container_init_expr.entries.at(i);
assert(field_node->type == NodeTypeStructValueField);
TypeStructField *type_struct_field = field_node->data.struct_val_field.type_struct_field;
@ -2974,12 +2975,12 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
StructValExprCodeGen *struct_val_expr_node = &node->data.container_init_expr.resolved_struct_val_expr;
LLVMValueRef tmp_array_ptr = struct_val_expr_node->ptr;
int field_count = type_entry->data.array.len;
size_t field_count = type_entry->data.array.len;
assert(field_count == node->data.container_init_expr.entries.length);
TypeTableEntry *child_type = type_entry->data.array.child_type;
for (int i = 0; i < field_count; i += 1) {
for (size_t i = 0; i < field_count; i += 1) {
AstNode *field_node = node->data.container_init_expr.entries.at(i);
LLVMValueRef elem_val = gen_expr(g, field_node);
@ -3126,8 +3127,8 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
TypeTableEntry *child_ptr_type = array_type->data.structure.fields[0].type_entry;
assert(child_ptr_type->id == TypeTableEntryIdPointer);
child_type = child_ptr_type->data.pointer.child_type;
int len_index = array_type->data.structure.fields[1].gen_index;
assert(len_index >= 0);
size_t len_index = array_type->data.structure.fields[1].gen_index;
assert(len_index != SIZE_MAX);
LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, array_val, len_index, "");
len_val = LLVMBuildLoad(g->builder, len_field_ptr, "");
} else {
@ -3249,10 +3250,10 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa
LLVMValueRef ptr_val = LLVMBuildArrayAlloca(g->builder, child_type->type_ref,
size_val, "");
int ptr_index = var_type->data.structure.fields[0].gen_index;
assert(ptr_index >= 0);
int len_index = var_type->data.structure.fields[1].gen_index;
assert(len_index >= 0);
size_t ptr_index = var_type->data.structure.fields[0].gen_index;
assert(ptr_index != SIZE_MAX);
size_t len_index = var_type->data.structure.fields[1].gen_index;
assert(len_index != SIZE_MAX);
// store the freshly allocated pointer in the unknown size array struct
LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder,
@ -3328,7 +3329,7 @@ static LLVMValueRef gen_symbol(CodeGen *g, AstNode *node) {
static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
assert(node->type == NodeTypeSwitchExpr);
if (node->data.switch_expr.const_chosen_prong_index >= 0) {
if (node->data.switch_expr.const_chosen_prong_index != SIZE_MAX) {
AstNode *prong_node = node->data.switch_expr.prongs.at(node->data.switch_expr.const_chosen_prong_index);
assert(prong_node->type == NodeTypeSwitchProng);
AstNode *prong_expr = prong_node->data.switch_prong.expr;
@ -3362,7 +3363,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
LLVMBasicBlockRef end_block = end_unreachable ?
nullptr : LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchEnd");
LLVMBasicBlockRef else_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchElse");
int prong_count = node->data.switch_expr.prongs.length;
size_t prong_count = node->data.switch_expr.prongs.length;
set_debug_source_node(g, node);
LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, target_value, else_block, prong_count);
@ -3371,7 +3372,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
ZigList<LLVMBasicBlockRef> incoming_blocks = {0};
AstNode *else_prong = nullptr;
for (int prong_i = 0; prong_i < prong_count; prong_i += 1) {
for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {
AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);
VariableTableEntry *prong_var = prong_node->data.switch_prong.var;
@ -3382,10 +3383,10 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
prong_block = else_block;
} else {
prong_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchProng");
int prong_item_count = prong_node->data.switch_prong.items.length;
size_t prong_item_count = prong_node->data.switch_prong.items.length;
bool make_item_blocks = prong_var && prong_item_count > 1;
for (int item_i = 0; item_i < prong_item_count; item_i += 1) {
for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
assert(item_node->type != NodeTypeSwitchRange);
@ -3699,7 +3700,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
TypeStructField *type_struct_field = &type_entry->data.structure.fields[i];
if (type_struct_field->gen_index == -1) {
if (type_struct_field->gen_index == SIZE_MAX) {
continue;
}
fields[type_struct_field->gen_index] = gen_const_val(g, type_struct_field->type_entry,
@ -3767,13 +3768,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
case TypeTableEntryIdPointer:
{
TypeTableEntry *child_type = type_entry->data.pointer.child_type;
int len = const_val->data.x_ptr.len;
size_t len = const_val->data.x_ptr.len;
LLVMValueRef target_val;
if (len == 1) {
target_val = gen_const_val(g, child_type, const_val->data.x_ptr.ptr[0]);
} else if (len > 1) {
LLVMValueRef *values = allocate<LLVMValueRef>(len);
for (int i = 0; i < len; i += 1) {
for (size_t i = 0; i < len; i += 1) {
values[i] = gen_const_val(g, child_type, const_val->data.x_ptr.ptr[i]);
}
target_val = LLVMConstArray(child_type->type_ref, values, len);
@ -3833,7 +3834,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
}
static void gen_const_globals(CodeGen *g) {
for (int i = 0; i < g->global_const_list.length; i += 1) {
for (size_t i = 0; i < g->global_const_list.length; i += 1) {
AstNode *expr_node = g->global_const_list.at(i);
Expr *expr = get_resolved_expr(expr_node);
ConstExprValue *const_val = &expr->const_val;
@ -3927,7 +3928,7 @@ static void generate_error_name_table(CodeGen *g) {
LLVMValueRef *values = allocate<LLVMValueRef>(g->error_decls.length);
values[0] = LLVMGetUndef(str_type->type_ref);
for (int i = 1; i < g->error_decls.length; i += 1) {
for (size_t i = 1; i < g->error_decls.length; i += 1) {
AstNode *error_decl_node = g->error_decls.at(i);
assert(error_decl_node->type == NodeTypeErrorValueDecl);
Buf *name = error_decl_node->data.error_value_decl.name;
@ -3957,7 +3958,7 @@ static void generate_error_name_table(CodeGen *g) {
static void build_label_blocks(CodeGen *g, FnTableEntry *fn) {
LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn->fn_value, "entry");
for (int i = 0; i < fn->all_labels.length; i += 1) {
for (size_t i = 0; i < fn->all_labels.length; i += 1) {
LabelTableEntry *label = fn->all_labels.at(i);
Buf *name = label->decl_node->data.label.name;
label->basic_block = LLVMAppendBasicBlock(fn->fn_value, buf_ptr(name));
@ -3988,7 +3989,7 @@ static void do_code_gen(CodeGen *g) {
generate_error_name_table(g);
// Generate module level variables
for (int i = 0; i < g->global_vars.length; i += 1) {
for (size_t i = 0; i < g->global_vars.length; i += 1) {
VariableTableEntry *var = g->global_vars.at(i);
if (var->type->id == TypeTableEntryIdNumLitFloat) {
@ -4063,7 +4064,7 @@ static void do_code_gen(CodeGen *g) {
}
// Generate function prototypes
for (int fn_proto_i = 0; fn_proto_i < g->fn_protos.length; fn_proto_i += 1) {
for (size_t fn_proto_i = 0; fn_proto_i < g->fn_protos.length; fn_proto_i += 1) {
FnTableEntry *fn_table_entry = g->fn_protos.at(fn_proto_i);
if (should_skip_fn_codegen(g, fn_table_entry)) {
// huge time saver
@ -4097,15 +4098,15 @@ static void do_code_gen(CodeGen *g) {
// set parameter attributes
for (int param_decl_i = 0; param_decl_i < fn_proto->params.length; param_decl_i += 1) {
for (size_t param_decl_i = 0; param_decl_i < fn_proto->params.length; param_decl_i += 1) {
AstNode *param_node = fn_proto->params.at(param_decl_i);
assert(param_node->type == NodeTypeParamDecl);
FnGenParamInfo *info = &fn_type->data.fn.gen_param_info[param_decl_i];
int gen_index = info->gen_index;
size_t gen_index = info->gen_index;
bool is_byval = info->is_byval;
if (gen_index < 0) {
if (gen_index == SIZE_MAX) {
continue;
}
@ -4169,7 +4170,7 @@ static void do_code_gen(CodeGen *g) {
}
// Generate function definitions.
for (int fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) {
for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) {
FnTableEntry *fn_table_entry = g->fn_defs.at(fn_i);
if (should_skip_fn_codegen(g, fn_table_entry)) {
// huge time saver
@ -4194,7 +4195,7 @@ static void do_code_gen(CodeGen *g) {
// Set up debug info for blocks
for (int bc_i = 0; bc_i < fn_table_entry->all_block_contexts.length; bc_i += 1) {
for (size_t bc_i = 0; bc_i < fn_table_entry->all_block_contexts.length; bc_i += 1) {
BlockContext *block_context = fn_table_entry->all_block_contexts.at(bc_i);
if (!block_context->di_scope) {
@ -4212,7 +4213,7 @@ static void do_code_gen(CodeGen *g) {
clear_debug_source_node(g);
// allocate structs which are the result of casts
for (int cea_i = 0; cea_i < fn_table_entry->cast_alloca_list.length; cea_i += 1) {
for (size_t cea_i = 0; cea_i < fn_table_entry->cast_alloca_list.length; cea_i += 1) {
AstNode *fn_call_node = fn_table_entry->cast_alloca_list.at(cea_i);
Expr *expr = &fn_call_node->data.fn_call_expr.resolved_expr;
fn_call_node->data.fn_call_expr.tmp_ptr = LLVMBuildAlloca(g->builder,
@ -4220,14 +4221,14 @@ static void do_code_gen(CodeGen *g) {
}
// allocate structs which are struct value expressions
for (int alloca_i = 0; alloca_i < fn_table_entry->struct_val_expr_alloca_list.length; alloca_i += 1) {
for (size_t alloca_i = 0; alloca_i < fn_table_entry->struct_val_expr_alloca_list.length; alloca_i += 1) {
StructValExprCodeGen *struct_val_expr_node = fn_table_entry->struct_val_expr_alloca_list.at(alloca_i);
struct_val_expr_node->ptr = LLVMBuildAlloca(g->builder,
struct_val_expr_node->type_entry->type_ref, "");
}
// create debug variable declarations for variables and allocate all local variables
for (int var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {
for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {
VariableTableEntry *var = fn_table_entry->variable_list.at(var_i);
if (!type_has_bits(var->type)) {
@ -4235,7 +4236,7 @@ static void do_code_gen(CodeGen *g) {
}
if (var->block_context->node->type == NodeTypeFnDef) {
assert(var->gen_arg_index >= 0);
assert(var->gen_arg_index != SIZE_MAX);
TypeTableEntry *gen_type;
if (handle_is_ptr(var->type)) {
gen_type = fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index].type;
@ -4264,13 +4265,13 @@ static void do_code_gen(CodeGen *g) {
}
// create debug variable declarations for parameters
for (int param_i = 0; param_i < fn_proto->params.length; param_i += 1) {
for (size_t param_i = 0; param_i < fn_proto->params.length; param_i += 1) {
AstNode *param_decl = fn_proto->params.at(param_i);
assert(param_decl->type == NodeTypeParamDecl);
FnGenParamInfo *info = &fn_table_entry->type_entry->data.fn.gen_param_info[param_i];
if (info->gen_index < 0) {
if (info->gen_index == SIZE_MAX) {
continue;
}
@ -4306,7 +4307,7 @@ static void do_code_gen(CodeGen *g) {
#endif
}
static const int int_sizes_in_bits[] = {
static const size_t int_sizes_in_bits[] = {
8,
16,
32,
@ -4380,9 +4381,9 @@ static void define_builtin_types(CodeGen *g) {
g->builtin_types.entry_var = entry;
}
for (int int_size_i = 0; int_size_i < array_length(int_sizes_in_bits); int_size_i += 1) {
int size_in_bits = int_sizes_in_bits[int_size_i];
for (int is_sign_i = 0; is_sign_i < array_length(is_signed_list); is_sign_i += 1) {
for (size_t int_size_i = 0; int_size_i < array_length(int_sizes_in_bits); int_size_i += 1) {
size_t size_in_bits = int_sizes_in_bits[int_size_i];
for (size_t is_sign_i = 0; is_sign_i < array_length(is_signed_list); is_sign_i += 1) {
bool is_signed = is_signed_list[is_sign_i];
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
@ -4391,7 +4392,7 @@ static void define_builtin_types(CodeGen *g) {
const char u_or_i = is_signed ? 'i' : 'u';
buf_resize(&entry->name, 0);
buf_appendf(&entry->name, "%c%d", u_or_i, size_in_bits);
buf_appendf(&entry->name, "%c%zu", u_or_i, size_in_bits);
unsigned dwarf_tag;
if (is_signed) {
@ -4420,7 +4421,7 @@ static void define_builtin_types(CodeGen *g) {
}
}
for (int i = 0; i < array_length(c_int_type_infos); i += 1) {
for (size_t i = 0; i < array_length(c_int_type_infos); i += 1) {
const CIntTypeInfo *info = &c_int_type_infos[i];
uint64_t size_in_bits = get_c_type_size_in_bits(&g->zig_target, info->id);
bool is_signed = info->is_signed;
@ -4459,7 +4460,7 @@ static void define_builtin_types(CodeGen *g) {
g->primitive_type_table.put(&entry->name, entry);
}
for (int sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) {
for (size_t sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) {
bool is_signed = is_signed_list[sign_i];
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
@ -4754,7 +4755,7 @@ static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char
return builtin_fn;
}
static BuiltinFnEntry *create_builtin_fn_with_arg_count(CodeGen *g, BuiltinFnId id, const char *name, int count) {
static BuiltinFnEntry *create_builtin_fn_with_arg_count(CodeGen *g, BuiltinFnId id, const char *name, size_t count) {
BuiltinFnEntry *builtin_fn = create_builtin_fn(g, id, name);
builtin_fn->param_count = count;
builtin_fn->param_types = allocate<TypeTableEntry *>(count);
@ -4958,7 +4959,7 @@ void codegen_parseh(CodeGen *g, Buf *src_dirname, Buf *src_basename, Buf *source
}
if (errors.length > 0) {
for (int i = 0; i < errors.length; i += 1) {
for (size_t i = 0; i < errors.length; i += 1) {
ErrorMsg *err_msg = errors.at(i);
print_err_msg(err_msg, g->err_color);
}
@ -5034,7 +5035,7 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou
fprintf(stderr, "OK\n");
}
} else {
for (int i = 0; i < g->errors.length; i += 1) {
for (size_t i = 0; i < g->errors.length; i += 1) {
ErrorMsg *err = g->errors.at(i);
print_err_msg(err, g->err_color);
}
@ -5063,7 +5064,7 @@ static const char *c_int_type_names[] = {
static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
assert(type_entry);
for (int i = 0; i < array_length(c_int_type_names); i += 1) {
for (size_t i = 0; i < array_length(c_int_type_names); i += 1) {
if (type_entry == g->builtin_types.entry_c_int[i]) {
buf_init_from_str(out_buf, c_int_type_names[i]);
return;
@ -5114,7 +5115,7 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
case TypeTableEntryIdInt:
g->c_want_stdint = true;
buf_resize(out_buf, 0);
buf_appendf(out_buf, "%sint%d_t",
buf_appendf(out_buf, "%sint%zu_t",
type_entry->data.integral.is_signed ? "" : "u",
type_entry->data.integral.bit_count);
break;
@ -5183,7 +5184,7 @@ void codegen_generate_h_file(CodeGen *g) {
Buf h_buf = BUF_INIT;
buf_resize(&h_buf, 0);
for (int fn_def_i = 0; fn_def_i < g->fn_defs.length; fn_def_i += 1) {
for (size_t fn_def_i = 0; fn_def_i < g->fn_defs.length; fn_def_i += 1) {
FnTableEntry *fn_table_entry = g->fn_defs.at(fn_def_i);
AstNode *proto_node = fn_table_entry->proto_node;
assert(proto_node->type == NodeTypeFnProto);
@ -5202,7 +5203,7 @@ void codegen_generate_h_file(CodeGen *g) {
Buf param_type_c = BUF_INIT;
if (fn_proto->params.length) {
for (int param_i = 0; param_i < fn_proto->params.length; param_i += 1) {
for (size_t param_i = 0; param_i < fn_proto->params.length; param_i += 1) {
AstNode *param_decl_node = fn_proto->params.at(param_i);
AstNode *param_type = param_decl_node->data.param_decl.type;
get_c_type_node(g, param_type, &param_type_c);

View File

@ -16,7 +16,7 @@
CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target);
void codegen_set_clang_argv(CodeGen *codegen, const char **args, int len);
void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);
void codegen_set_is_release(CodeGen *codegen, bool is_release);
void codegen_set_is_test(CodeGen *codegen, bool is_test);
void codegen_set_check_unused(CodeGen *codegen, bool check_unused);

View File

@ -16,36 +16,36 @@ enum ErrType {
static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) {
const char *path = buf_ptr(err->path);
int line = err->line_start + 1;
int col = err->column_start + 1;
size_t line = err->line_start + 1;
size_t col = err->column_start + 1;
const char *text = buf_ptr(err->msg);
if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) {
if (err_type == ErrTypeError) {
fprintf(stderr, WHITE "%s:%d:%d: " RED "error:" WHITE " %s" RESET "\n", path, line, col, text);
fprintf(stderr, WHITE "%s:%zu:%zu: " RED "error:" WHITE " %s" RESET "\n", path, line, col, text);
} else if (err_type == ErrTypeNote) {
fprintf(stderr, WHITE "%s:%d:%d: " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text);
fprintf(stderr, WHITE "%s:%zu:%zu: " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text);
} else {
zig_unreachable();
}
fprintf(stderr, "%s\n", buf_ptr(&err->line_buf));
for (int i = 0; i < err->column_start; i += 1) {
for (size_t i = 0; i < err->column_start; i += 1) {
fprintf(stderr, " ");
}
fprintf(stderr, GREEN "^" RESET "\n");
} else {
if (err_type == ErrTypeError) {
fprintf(stderr, "%s:%d:%d: error: %s\n", path, line, col, text);
fprintf(stderr, "%s:%zu:%zu: error: %s\n", path, line, col, text);
} else if (err_type == ErrTypeNote) {
fprintf(stderr, " %s:%d:%d: note: %s\n", path, line, col, text);
fprintf(stderr, " %s:%zu:%zu: note: %s\n", path, line, col, text);
} else {
zig_unreachable();
}
}
for (int i = 0; i < err->notes.length; i += 1) {
for (size_t i = 0; i < err->notes.length; i += 1) {
ErrorMsg *note = err->notes.at(i);
print_err_msg_type(note, color, ErrTypeNote);
}
@ -59,7 +59,7 @@ void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note) {
parent->notes.append(note);
}
ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset,
ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size_t offset,
const char *source, Buf *msg)
{
ErrorMsg *err_msg = allocate<ErrorMsg>(1);
@ -68,7 +68,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset
err_msg->column_start = column;
err_msg->msg = msg;
int line_start_offset = offset;
size_t line_start_offset = offset;
for (;;) {
if (line_start_offset == 0) {
break;
@ -79,7 +79,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset
line_start_offset -= 1;
}
int line_end_offset = offset;
size_t line_end_offset = offset;
while (source[line_end_offset] && source[line_end_offset] != '\n') {
line_end_offset += 1;
}
@ -89,8 +89,8 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset
return err_msg;
}
ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column,
Buf *source, ZigList<int> *line_offsets, Buf *msg)
ErrorMsg *err_msg_create_with_line(Buf *path, size_t line, size_t column,
Buf *source, ZigList<size_t> *line_offsets, Buf *msg)
{
ErrorMsg *err_msg = allocate<ErrorMsg>(1);
err_msg->path = path;
@ -98,13 +98,10 @@ ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column,
err_msg->column_start = column;
err_msg->msg = msg;
int line_start_offset = line_offsets->at(line);
int end_line = line + 1;
int line_end_offset = (end_line >= line_offsets->length) ? buf_len(source) : line_offsets->at(line + 1);
int len = line_end_offset - line_start_offset - 1;
if (len < 0) {
len = 0;
}
size_t line_start_offset = line_offsets->at(line);
size_t end_line = line + 1;
size_t line_end_offset = (end_line >= line_offsets->length) ? buf_len(source) : line_offsets->at(line + 1);
size_t len = (line_end_offset + 1 > line_start_offset) ? (line_end_offset - line_start_offset - 1) : 0;
buf_init_from_mem(&err_msg->line_buf, buf_ptr(source) + line_start_offset, len);

View File

@ -18,8 +18,8 @@ enum ErrColor {
};
struct ErrorMsg {
int line_start;
int column_start;
size_t line_start;
size_t column_start;
Buf *msg;
Buf *path;
Buf line_buf;
@ -30,10 +30,10 @@ struct ErrorMsg {
void print_err_msg(ErrorMsg *msg, ErrColor color);
void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note);
ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset,
ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size_t offset,
const char *source, Buf *msg);
ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column,
Buf *source, ZigList<int> *line_offsets, Buf *msg);
ErrorMsg *err_msg_create_with_line(Buf *path, size_t line, size_t column,
Buf *source, ZigList<size_t> *line_offsets, Buf *msg);
#endif

View File

@ -75,7 +75,7 @@ static bool eval_block(EvalFn *ef, AstNode *node, ConstExprValue *out) {
my_scope->block_context = node->block_context;
ef->scope_stack.append(my_scope);
for (int i = 0; i < node->data.block.statements.length; i += 1) {
for (size_t i = 0; i < node->data.block.statements.length; i += 1) {
AstNode *child = node->data.block.statements.at(i);
memset(out, 0, sizeof(ConstExprValue));
if (eval_expr(ef, child, out)) return true;
@ -413,10 +413,10 @@ static bool eval_bin_op_expr(EvalFn *ef, AstNode *node, ConstExprValue *out_val)
}
static EvalVar *find_var(EvalFn *ef, Buf *name) {
int scope_index = ef->scope_stack.length - 1;
while (scope_index >= 0) {
size_t scope_index = ef->scope_stack.length - 1;
while (scope_index != SIZE_MAX) {
EvalScope *scope = ef->scope_stack.at(scope_index);
for (int var_i = 0; var_i < scope->vars.length; var_i += 1) {
for (size_t var_i = 0; var_i < scope->vars.length; var_i += 1) {
EvalVar *var = &scope->vars.at(var_i);
if (buf_eql_buf(var->name, name)) {
return var;
@ -466,18 +466,18 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue *
!container_type->data.structure.is_slice &&
kind == ContainerInitKindStruct)
{
int expr_field_count = container_init_expr->entries.length;
int actual_field_count = container_type->data.structure.src_field_count;
size_t expr_field_count = container_init_expr->entries.length;
size_t actual_field_count = container_type->data.structure.src_field_count;
assert(expr_field_count == actual_field_count);
out_val->data.x_struct.fields = allocate<ConstExprValue*>(actual_field_count);
for (int i = 0; i < expr_field_count; i += 1) {
for (size_t i = 0; i < expr_field_count; i += 1) {
AstNode *val_field_node = container_init_expr->entries.at(i);
assert(val_field_node->type == NodeTypeStructValueField);
TypeStructField *type_field = val_field_node->data.struct_val_field.type_struct_field;
int field_index = type_field->src_index;
size_t field_index = type_field->src_index;
ConstExprValue src_field_val = {0};
if (eval_expr(ef, val_field_node->data.struct_val_field.expr, &src_field_val)) return true;
@ -496,12 +496,12 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue *
kind == ContainerInitKindArray)
{
int elem_count = container_init_expr->entries.length;
size_t elem_count = container_init_expr->entries.length;
out_val->ok = true;
out_val->data.x_array.fields = allocate<ConstExprValue*>(elem_count);
for (int i = 0; i < elem_count; i += 1) {
for (size_t i = 0; i < elem_count; i += 1) {
AstNode *elem_node = container_init_expr->entries.at(i);
ConstExprValue *elem_val = allocate<ConstExprValue>(1);
@ -698,7 +698,7 @@ void eval_const_expr_implicit_cast(CastOp cast_op,
static bool int_type_depends_on_compile_var(CodeGen *g, TypeTableEntry *int_type) {
assert(int_type->id == TypeTableEntryIdInt);
for (int i = 0; i < CIntTypeCount; i += 1) {
for (size_t i = 0; i < CIntTypeCount; i += 1) {
if (int_type == g->builtin_types.entry_c_int[i]) {
return true;
}
@ -918,9 +918,9 @@ static bool eval_fn_call_expr(EvalFn *ef, AstNode *node, ConstExprValue *out_val
fn_table_entry = fn_val.data.x_fn;
}
int param_count = node->data.fn_call_expr.params.length;
size_t param_count = node->data.fn_call_expr.params.length;
ConstExprValue *args = allocate<ConstExprValue>(param_count);
for (int call_i = 0; call_i < param_count; call_i += 1) {
for (size_t call_i = 0; call_i < param_count; call_i += 1) {
AstNode *param_expr_node = node->data.fn_call_expr.params.at(call_i);
ConstExprValue *param_val = &args[call_i];
if (eval_expr(ef, param_expr_node, param_val)) return true;
@ -1340,8 +1340,8 @@ static bool eval_fn_args(EvalFnRoot *efr, FnTableEntry *fn, ConstExprValue *args
root_scope->block_context = fn->fn_def_node->data.fn_def.body->block_context;
ef.scope_stack.append(root_scope);
int param_count = acting_proto_node->data.fn_proto.params.length;
for (int proto_i = 0; proto_i < param_count; proto_i += 1) {
size_t param_count = acting_proto_node->data.fn_proto.params.length;
for (size_t proto_i = 0; proto_i < param_count; proto_i += 1) {
AstNode *decl_param_node = acting_proto_node->data.fn_proto.params.at(proto_i);
assert(decl_param_node->type == NodeTypeParamDecl);
@ -1358,7 +1358,7 @@ static bool eval_fn_args(EvalFnRoot *efr, FnTableEntry *fn, ConstExprValue *args
}
bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_val,
int branch_quota, AstNode *struct_node)
size_t branch_quota, AstNode *struct_node)
{
assert(node->type == NodeTypeFnCallExpr);
@ -1375,17 +1375,17 @@ bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_va
acting_proto_node = fn->proto_node;
}
int call_param_count = node->data.fn_call_expr.params.length;
int proto_param_count = acting_proto_node->data.fn_proto.params.length;
size_t call_param_count = node->data.fn_call_expr.params.length;
size_t proto_param_count = acting_proto_node->data.fn_proto.params.length;
ConstExprValue *args = allocate<ConstExprValue>(proto_param_count);
int next_arg_index = 0;
size_t next_arg_index = 0;
if (struct_node) {
ConstExprValue *struct_val = &get_resolved_expr(struct_node)->const_val;
assert(struct_val->ok);
args[next_arg_index] = *struct_val;
next_arg_index += 1;
}
for (int call_index = 0; call_index < call_param_count; call_index += 1) {
for (size_t call_index = 0; call_index < call_param_count; call_index += 1) {
AstNode *call_param_node = node->data.fn_call_expr.params.at(call_index);
ConstExprValue *src_const_val = &get_resolved_expr(call_param_node)->const_val;
assert(src_const_val->ok);
@ -1396,7 +1396,7 @@ bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_va
if (efr.exceeded_quota_node) {
ErrorMsg *msg = add_node_error(g, fn->fn_def_node,
buf_sprintf("function evaluation exceeded %d branches", efr.branch_quota));
buf_sprintf("function evaluation exceeded %zu branches", efr.branch_quota));
add_error_note(g, msg, efr.call_node, buf_sprintf("called from here"));
add_error_note(g, msg, efr.exceeded_quota_node, buf_sprintf("quota exceeded here"));

View File

@ -10,7 +10,7 @@
#include "all_types.hpp"
bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_val, int branch_quota,
bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_val, size_t branch_quota,
AstNode *struct_node);
bool const_values_equal(ConstExprValue *a, ConstExprValue *b, TypeTableEntry *type_entry);

View File

@ -172,9 +172,9 @@ static void construct_linker_job_linux(LinkJob *lj) {
lj->args.append("-shared");
buf_resize(&lj->out_file, 0);
buf_appendf(&lj->out_file, "lib%s.so.%d.%d.%d",
buf_appendf(&lj->out_file, "lib%s.so.%zu.%zu.%zu",
buf_ptr(g->root_out_name), g->version_major, g->version_minor, g->version_patch);
soname = buf_sprintf("lib%s.so.%d", buf_ptr(g->root_out_name), g->version_major);
soname = buf_sprintf("lib%s.so.%zu", buf_ptr(g->root_out_name), g->version_major);
}
lj->args.append("-o");
@ -195,7 +195,7 @@ static void construct_linker_job_linux(LinkJob *lj) {
lj->args.append(get_libc_static_file(g, crtbegino));
}
for (int i = 0; i < g->lib_dirs.length; i += 1) {
for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
const char *lib_dir = g->lib_dirs.at(i);
lj->args.append("-L");
lj->args.append(lib_dir);
@ -239,7 +239,7 @@ static void construct_linker_job_linux(LinkJob *lj) {
lj->args.append(buf_ptr(compiler_rt_o_path));
}
for (int i = 0; i < g->link_libs.length; i += 1) {
for (size_t i = 0; i < g->link_libs.length; i += 1) {
Buf *link_lib = g->link_libs.at(i);
Buf *arg;
if (buf_starts_with_str(link_lib, "/") || buf_ends_with_str(link_lib, ".a") ||
@ -350,7 +350,7 @@ static void construct_linker_job_mingw(LinkJob *lj) {
lj->args.append(get_libc_static_file(g, "crtbegin.o"));
}
for (int i = 0; i < g->lib_dirs.length; i += 1) {
for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
const char *lib_dir = g->lib_dirs.at(i);
lj->args.append("-L");
lj->args.append(lib_dir);
@ -381,7 +381,7 @@ static void construct_linker_job_mingw(LinkJob *lj) {
}
for (int i = 0; i < g->link_libs.length; i += 1) {
for (size_t i = 0; i < g->link_libs.length; i += 1) {
Buf *link_lib = g->link_libs.at(i);
Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
lj->args.append(buf_ptr(arg));
@ -635,7 +635,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {
}
}
for (int i = 0; i < g->lib_dirs.length; i += 1) {
for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
const char *lib_dir = g->lib_dirs.at(i);
lj->args.append("-L");
lj->args.append(lib_dir);
@ -649,7 +649,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {
lj->args.append(buf_ptr(test_runner_o_path));
}
for (int i = 0; i < g->link_libs.length; i += 1) {
for (size_t i = 0; i < g->link_libs.length; i += 1) {
Buf *link_lib = g->link_libs.at(i);
Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
lj->args.append(buf_ptr(arg));
@ -671,7 +671,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {
zig_panic("TODO");
}
for (int i = 0; i < g->darwin_frameworks.length; i += 1) {
for (size_t i = 0; i < g->darwin_frameworks.length; i += 1) {
lj->args.append("-framework");
lj->args.append(buf_ptr(g->darwin_frameworks.at(i)));
}
@ -829,7 +829,7 @@ void codegen_link(CodeGen *g, const char *out_file) {
if (g->verbose) {
fprintf(stderr, "%s", buf_ptr(g->linker_path));
for (int i = 0; i < lj.args.length; i += 1) {
for (size_t i = 0; i < lj.args.length; i += 1) {
fprintf(stderr, " %s", lj.args.at(i));
}
fprintf(stderr, "\n");
@ -853,7 +853,7 @@ void codegen_link(CodeGen *g, const char *out_file) {
fprintf(stderr, "linker failed\n");
}
fprintf(stderr, "%s ", buf_ptr(g->linker_path));
for (int i = 0; i < lj.args.length; i += 1) {
for (size_t i = 0; i < lj.args.length; i += 1) {
fprintf(stderr, "%s ", lj.args.at(i));
}
fprintf(stderr, "\n%s\n", buf_ptr(&ld_stderr));

View File

@ -23,13 +23,13 @@ struct ZigList {
}
// remember that the pointer to this item is invalid after you
// modify the length of the list
const T & at(int index) const {
assert(index >= 0);
const T & at(size_t index) const {
assert(index != SIZE_MAX);
assert(index < length);
return items[index];
}
T & at(int index) {
assert(index >= 0);
T & at(size_t index) {
assert(index != SIZE_MAX);
assert(index < length);
return items[index];
}
@ -52,8 +52,8 @@ struct ZigList {
return items[length - 1];
}
void resize(int new_length) {
assert(new_length >= 0);
void resize(size_t new_length) {
assert(new_length != SIZE_MAX);
ensure_capacity(new_length);
length = new_length;
}
@ -62,19 +62,22 @@ struct ZigList {
length = 0;
}
void ensure_capacity(int new_capacity) {
int better_capacity = max(capacity, 16);
while (better_capacity < new_capacity)
better_capacity = better_capacity * 2;
if (better_capacity != capacity) {
items = reallocate_nonzero(items, better_capacity);
capacity = better_capacity;
}
void ensure_capacity(size_t new_capacity) {
if (capacity >= new_capacity)
return;
size_t better_capacity = capacity;
do {
better_capacity = better_capacity * 1.4 + 8;
} while (better_capacity < new_capacity);
items = reallocate_nonzero(items, capacity, better_capacity);
capacity = better_capacity;
}
T * items;
int length;
int capacity;
T *items;
size_t length;
size_t capacity;
};
#endif

View File

@ -64,8 +64,8 @@ static int print_target_list(FILE *f) {
get_native_target(&native);
fprintf(f, "Architectures:\n");
int arch_count = target_arch_count();
for (int arch_i = 0; arch_i < arch_count; arch_i += 1) {
size_t arch_count = target_arch_count();
for (size_t arch_i = 0; arch_i < arch_count; arch_i += 1) {
const ArchType *arch = get_target_arch(arch_i);
char arch_name[50];
get_arch_name(arch_name, arch);
@ -75,16 +75,16 @@ static int print_target_list(FILE *f) {
}
fprintf(f, "\nOperating Systems:\n");
int os_count = target_os_count();
for (int i = 0; i < os_count; i += 1) {
size_t os_count = target_os_count();
for (size_t i = 0; i < os_count; i += 1) {
ZigLLVM_OSType os_type = get_target_os(i);
const char *native_str = (native.os == os_type) ? " (native)" : "";
fprintf(f, " %s%s\n", get_target_os_name(os_type), native_str);
}
fprintf(f, "\nEnvironments:\n");
int environ_count = target_environ_count();
for (int i = 0; i < environ_count; i += 1) {
size_t environ_count = target_environ_count();
for (size_t i = 0; i < environ_count; i += 1) {
ZigLLVM_EnvironmentType environ_type = get_target_environ(i);
const char *native_str = (native.env_type == environ_type) ? " (native)" : "";
fprintf(f, " %s%s\n", ZigLLVMGetEnvironmentTypeName(environ_type), native_str);
@ -375,13 +375,13 @@ int main(int argc, char **argv) {
codegen_set_verbose(g, verbose);
codegen_set_errmsg_color(g, color);
for (int i = 0; i < lib_dirs.length; i += 1) {
for (size_t i = 0; i < lib_dirs.length; i += 1) {
codegen_add_lib_dir(g, lib_dirs.at(i));
}
for (int i = 0; i < link_libs.length; i += 1) {
for (size_t i = 0; i < link_libs.length; i += 1) {
codegen_add_link_lib(g, link_libs.at(i));
}
for (int i = 0; i < frameworks.length; i += 1) {
for (size_t i = 0; i < frameworks.length; i += 1) {
codegen_add_framework(g, frameworks.at(i));
}

View File

@ -73,7 +73,7 @@ static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args,
const char **argv = allocate<const char *>(args.length + 2);
argv[0] = exe;
argv[args.length + 1] = nullptr;
for (int i = 0; i < args.length; i += 1) {
for (size_t i = 0; i < args.length; i += 1) {
argv[i + 1] = args.at(i);
}
execvp(exe, const_cast<char * const *>(argv));
@ -114,20 +114,25 @@ void os_path_dirname(Buf *full_path, Buf *out_dirname) {
}
void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename) {
int last_index = buf_len(full_path) - 1;
if (last_index >= 0 && buf_ptr(full_path)[last_index] == '/') {
last_index -= 1;
}
for (int i = last_index; i >= 0; i -= 1) {
uint8_t c = buf_ptr(full_path)[i];
if (c == '/') {
if (out_dirname) {
buf_init_from_mem(out_dirname, buf_ptr(full_path), i);
size_t len = buf_len(full_path);
if (len != 0) {
size_t last_index = len - 1;
if (buf_ptr(full_path)[last_index] == '/') {
last_index -= 1;
}
for (size_t i = last_index;;) {
uint8_t c = buf_ptr(full_path)[i];
if (c == '/') {
if (out_dirname) {
buf_init_from_mem(out_dirname, buf_ptr(full_path), i);
}
if (out_basename) {
buf_init_from_mem(out_basename, buf_ptr(full_path) + i + 1, buf_len(full_path) - (i + 1));
}
return;
}
if (out_basename) {
buf_init_from_mem(out_basename, buf_ptr(full_path) + i + 1, buf_len(full_path) - (i + 1));
}
return;
if (i == 0) break;
i -= 1;
}
}
if (out_dirname) buf_init_from_mem(out_dirname, ".", 1);
@ -246,7 +251,7 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args,
const char **argv = allocate<const char *>(args.length + 2);
argv[0] = exe;
argv[args.length + 1] = nullptr;
for (int i = 0; i < args.length; i += 1) {
for (size_t i = 0; i < args.length; i += 1) {
argv[i + 1] = args.at(i);
}
execvp(exe, const_cast<char * const *>(argv));
@ -297,11 +302,11 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args,
buf_append_str(&command_line, exe);
buf_append_char(&command_line, '\"');
for (int arg_i = 0; arg_i < args.length; arg_i += 1) {
for (size_t arg_i = 0; arg_i < args.length; arg_i += 1) {
buf_append_str(&command_line, " \"");
const char *arg = args.at(arg_i);
int arg_len = strlen(arg);
for (int c_i = 0; c_i < arg_len; c_i += 1) {
size_t arg_len = strlen(arg);
for (size_t c_i = 0; c_i < arg_len; c_i += 1) {
if (arg[c_i] == '\"') {
zig_panic("TODO");
}
@ -376,7 +381,7 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args,
CloseHandle(g_hChildStd_ERR_Wr);
CloseHandle(g_hChildStd_OUT_Wr);
static const int BUF_SIZE = 4 * 1024;
static const size_t BUF_SIZE = 4 * 1024;
{
DWORD dwRead;
char chBuf[BUF_SIZE];
@ -540,7 +545,7 @@ static int os_buf_to_tmp_file_windows(Buf *contents, Buf *suffix, Buf *out_tmp_p
const char base64[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
assert(array_length(base64) == 64 + 1);
for (int i = 0; i < 8; i += 1) {
for (size_t i = 0; i < 8; i += 1) {
buf_append_char(out_tmp_path, base64[rand() % 64]);
}

View File

@ -244,10 +244,10 @@ static AstNode *create_fn_proto_node(Context *c, Buf *name, TypeTableEntry *fn_t
node->data.fn_proto.name = name;
node->data.fn_proto.return_type = make_type_node(c, fn_type->data.fn.fn_type_id.return_type);
for (int i = 0; i < fn_type->data.fn.fn_type_id.param_count; i += 1) {
for (size_t i = 0; i < fn_type->data.fn.fn_type_id.param_count; i += 1) {
FnTypeParamInfo *info = &fn_type->data.fn.fn_type_id.param_info[i];
char arg_name[20];
sprintf(arg_name, "arg_%d", i);
sprintf(arg_name, "arg_%zu", i);
node->data.fn_proto.params.append(create_param_decl_node(c, arg_name,
make_type_node(c, info->type), info->is_noalias));
}
@ -272,7 +272,7 @@ static AstNode *create_inline_fn_node(Context *c, Buf *fn_name, Buf *var_name, T
AstNode *fn_call_node = create_node(c, NodeTypeFnCallExpr);
fn_call_node->data.fn_call_expr.fn_ref_expr = unwrap_node;
for (int i = 0; i < fn_type->data.fn.fn_type_id.param_count; i += 1) {
for (size_t i = 0; i < fn_type->data.fn.fn_type_id.param_count; i += 1) {
AstNode *decl_node = node->data.fn_def.fn_proto->data.fn_proto.params.at(i);
Buf *param_name = decl_node->data.param_decl.name;
fn_call_node->data.fn_call_expr.params.append(create_symbol_node(c, buf_ptr(param_name)));
@ -621,7 +621,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
fn_type_id.param_info = &fn_type_id.prealloc_param_info[0];
}
for (int i = 0; i < fn_type_id.param_count; i += 1) {
for (size_t i = 0; i < fn_type_id.param_count; i += 1) {
QualType qt = fn_proto_ty->getParamType(i);
TypeTableEntry *param_type = resolve_qual_type(c, qt, decl);
@ -748,16 +748,16 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
assert(!fn_type->data.fn.fn_type_id.is_naked);
int arg_count = fn_type->data.fn.fn_type_id.param_count;
size_t arg_count = fn_type->data.fn.fn_type_id.param_count;
Buf name_buf = BUF_INIT;
for (int i = 0; i < arg_count; i += 1) {
for (size_t i = 0; i < arg_count; i += 1) {
FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[i];
AstNode *type_node = make_type_node(c, param_info->type);
const ParmVarDecl *param = fn_decl->getParamDecl(i);
const char *name = decl_name(param);
if (strlen(name) == 0) {
buf_resize(&name_buf, 0);
buf_appendf(&name_buf, "arg%d", i);
buf_appendf(&name_buf, "arg%zu", i);
name = buf_ptr(&name_buf);
}
@ -1316,7 +1316,7 @@ static bool name_exists_and_const(Context *c, Buf *name) {
}
static void render_aliases(Context *c) {
for (int i = 0; i < c->aliases.length; i += 1) {
for (size_t i = 0; i < c->aliases.length; i += 1) {
AstNode *alias_node = c->aliases.at(i);
assert(alias_node->type == NodeTypeVariableDeclaration);
Buf *name = alias_node->data.variable_declaration.symbol;
@ -1347,7 +1347,7 @@ static void process_macro(Context *c, CTokenize *ctok, Buf *name, const char *ch
}
bool negate = false;
for (int i = 0; i < ctok->tokens.length; i += 1) {
for (size_t i = 0; i < ctok->tokens.length; i += 1) {
bool is_first = (i == 0);
bool is_last = (i == ctok->tokens.length - 1);
CTok *tok = &ctok->tokens.at(i);
@ -1403,7 +1403,7 @@ static void process_macro(Context *c, CTokenize *ctok, Buf *name, const char *ch
}
static void process_symbol_macros(Context *c) {
for (int i = 0; i < c->macro_symbols.length; i += 1) {
for (size_t i = 0; i < c->macro_symbols.length; i += 1) {
MacroSymbol ms = c->macro_symbols.at(i);
if (name_exists_and_const(c, ms.value)) {
AstNode *var_node = create_var_decl_node(c, buf_ptr(ms.name),
@ -1524,7 +1524,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
clang_argv.append("-isystem");
clang_argv.append(buf_ptr(codegen->libc_include_dir));
for (int i = 0; i < codegen->clang_argv_len; i += 1) {
for (size_t i = 0; i < codegen->clang_argv_len; i += 1) {
clang_argv.append(codegen->clang_argv[i]);
}

View File

@ -28,7 +28,7 @@ struct ParseContext {
__attribute__ ((format (printf, 4, 5)))
__attribute__ ((noreturn))
static void ast_asm_error(ParseContext *pc, AstNode *node, int offset, const char *format, ...) {
static void ast_asm_error(ParseContext *pc, AstNode *node, size_t offset, const char *format, ...) {
assert(node->type == NodeTypeAsmExpr);
@ -109,7 +109,7 @@ static void parse_asm_template(ParseContext *pc, AstNode *node) {
enum State state = StateStart;
for (int i = 0; i < buf_len(asm_template); i += 1) {
for (size_t i = 0; i < buf_len(asm_template); i += 1) {
uint8_t c = *((uint8_t*)buf_ptr(asm_template) + i);
switch (state) {
case StateStart:
@ -205,16 +205,16 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {
ast_error(pc, token, "invalid token: '%s'", buf_ptr(&token_value));
}
static AstNode *ast_parse_expression(ParseContext *pc, int *token_index, bool mandatory);
static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandatory);
static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool mandatory);
static AstNode *ast_parse_block_expr(ParseContext *pc, int *token_index, bool mandatory);
static AstNode *ast_parse_unwrap_expr(ParseContext *pc, int *token_index, bool mandatory);
static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, bool mandatory);
static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory,
static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool mandatory);
static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mandatory);
static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool mandatory);
static AstNode *ast_parse_block_expr(ParseContext *pc, size_t *token_index, bool mandatory);
static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory);
static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory);
static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory,
ZigList<AstNode*> *directives, VisibMod visib_mod);
static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index);
static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool mandatory);
static AstNode *ast_parse_return_expr(ParseContext *pc, size_t *token_index);
static AstNode *ast_parse_grouped_expr(ParseContext *pc, size_t *token_index, bool mandatory);
static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {
if (token->id == token_id) {
@ -226,7 +226,7 @@ static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {
ast_error(pc, token, "expected token '%s', found '%s'", token_name(token_id), token_name(token->id));
}
static Token *ast_eat_token(ParseContext *pc, int *token_index, TokenId token_id) {
static Token *ast_eat_token(ParseContext *pc, size_t *token_index, TokenId token_id) {
Token *token = &pc->tokens->at(*token_index);
ast_expect_token(pc, token, token_id);
*token_index += 1;
@ -236,7 +236,7 @@ static Token *ast_eat_token(ParseContext *pc, int *token_index, TokenId token_id
/*
Directive = "#" "Symbol" "(" Expression ")"
*/
static AstNode *ast_parse_directive(ParseContext *pc, int *token_index) {
static AstNode *ast_parse_directive(ParseContext *pc, size_t *token_index) {
Token *number_sign = ast_eat_token(pc, token_index, TokenIdNumberSign);
AstNode *node = ast_create_node(pc, NodeTypeDirective, number_sign);
@ -251,7 +251,7 @@ static AstNode *ast_parse_directive(ParseContext *pc, int *token_index) {
return node;
}
static void ast_parse_directives(ParseContext *pc, int *token_index,
static void ast_parse_directives(ParseContext *pc, size_t *token_index,
ZigList<AstNode *> *directives)
{
for (;;) {
@ -269,7 +269,7 @@ static void ast_parse_directives(ParseContext *pc, int *token_index,
/*
TypeExpr = PrefixOpExpression | "var"
*/
static AstNode *ast_parse_type_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
if (token->id == TokenIdKeywordVar) {
AstNode *node = ast_create_node(pc, NodeTypeVarLiteral, token);
@ -283,7 +283,7 @@ static AstNode *ast_parse_type_expr(ParseContext *pc, int *token_index, bool man
/*
ParamDecl = option("noalias" | "inline") option("Symbol" ":") TypeExpr | "..."
*/
static AstNode *ast_parse_param_decl(ParseContext *pc, int *token_index) {
static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) {
Token *token = &pc->tokens->at(*token_index);
if (token->id == TokenIdEllipsis) {
@ -320,7 +320,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, int *token_index) {
}
static void ast_parse_param_decl_list(ParseContext *pc, int *token_index,
static void ast_parse_param_decl_list(ParseContext *pc, size_t *token_index,
ZigList<AstNode *> *params, bool *is_var_args)
{
*is_var_args = false;
@ -356,7 +356,7 @@ static void ast_parse_param_decl_list(ParseContext *pc, int *token_index,
zig_unreachable();
}
static void ast_parse_fn_call_param_list(ParseContext *pc, int *token_index, ZigList<AstNode*> *params) {
static void ast_parse_fn_call_param_list(ParseContext *pc, size_t *token_index, ZigList<AstNode*> *params) {
Token *token = &pc->tokens->at(*token_index);
if (token->id == TokenIdRParen) {
*token_index += 1;
@ -381,7 +381,7 @@ static void ast_parse_fn_call_param_list(ParseContext *pc, int *token_index, Zig
/*
GroupedExpression : token(LParen) Expression token(RParen)
*/
static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_grouped_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *l_paren = &pc->tokens->at(*token_index);
if (l_paren->id != TokenIdLParen) {
if (mandatory) {
@ -405,7 +405,7 @@ static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool
/*
ArrayType : "[" option(Expression) "]" option("const") PrefixOpExpression
*/
static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_array_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *l_bracket = &pc->tokens->at(*token_index);
if (l_bracket->id != TokenIdLBracket) {
if (mandatory) {
@ -437,7 +437,7 @@ static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bo
/*
AsmInputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) Expression token(RParen)
*/
static void ast_parse_asm_input_item(ParseContext *pc, int *token_index, AstNode *node) {
static void ast_parse_asm_input_item(ParseContext *pc, size_t *token_index, AstNode *node) {
ast_eat_token(pc, token_index, TokenIdLBracket);
Token *alias = ast_eat_token(pc, token_index, TokenIdSymbol);
ast_eat_token(pc, token_index, TokenIdRBracket);
@ -458,7 +458,7 @@ static void ast_parse_asm_input_item(ParseContext *pc, int *token_index, AstNode
/*
AsmOutputItem : "[" "Symbol" "]" "String" "(" ("Symbol" | "->" PrefixOpExpression) ")"
*/
static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNode *node) {
static void ast_parse_asm_output_item(ParseContext *pc, size_t *token_index, AstNode *node) {
ast_eat_token(pc, token_index, TokenIdLBracket);
Token *alias = ast_eat_token(pc, token_index, TokenIdSymbol);
ast_eat_token(pc, token_index, TokenIdRBracket);
@ -489,7 +489,7 @@ static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNod
/*
AsmClobbers: token(Colon) list(token(String), token(Comma))
*/
static void ast_parse_asm_clobbers(ParseContext *pc, int *token_index, AstNode *node) {
static void ast_parse_asm_clobbers(ParseContext *pc, size_t *token_index, AstNode *node) {
Token *colon_tok = &pc->tokens->at(*token_index);
if (colon_tok->id != TokenIdColon)
@ -519,7 +519,7 @@ static void ast_parse_asm_clobbers(ParseContext *pc, int *token_index, AstNode *
/*
AsmInput : token(Colon) list(AsmInputItem, token(Comma)) option(AsmClobbers)
*/
static void ast_parse_asm_input(ParseContext *pc, int *token_index, AstNode *node) {
static void ast_parse_asm_input(ParseContext *pc, size_t *token_index, AstNode *node) {
Token *colon_tok = &pc->tokens->at(*token_index);
if (colon_tok->id != TokenIdColon)
@ -546,7 +546,7 @@ static void ast_parse_asm_input(ParseContext *pc, int *token_index, AstNode *nod
/*
AsmOutput : token(Colon) list(AsmOutputItem, token(Comma)) option(AsmInput)
*/
static void ast_parse_asm_output(ParseContext *pc, int *token_index, AstNode *node) {
static void ast_parse_asm_output(ParseContext *pc, size_t *token_index, AstNode *node) {
Token *colon_tok = &pc->tokens->at(*token_index);
if (colon_tok->id != TokenIdColon)
@ -579,7 +579,7 @@ static void ast_parse_asm_output(ParseContext *pc, int *token_index, AstNode *no
/*
AsmExpression : token(Asm) option(token(Volatile)) token(LParen) token(String) option(AsmOutput) token(RParen)
*/
static AstNode *ast_parse_asm_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_asm_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *asm_token = &pc->tokens->at(*token_index);
if (asm_token->id != TokenIdKeywordAsm) {
@ -622,7 +622,7 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc, int *token_index, bool mand
PrimaryExpression = "Number" | "String" | "CharLiteral" | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | "Symbol" | ("@" "Symbol" FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." "Symbol")
KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "zeroes" | "error" | "type"
*/
static AstNode *ast_parse_primary_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
if (token->id == TokenIdNumberLiteral) {
@ -752,7 +752,7 @@ CurlySuffixExpression : PrefixOpExpression option(ContainerInitExpression)
ContainerInitExpression : token(LBrace) ContainerInitBody token(RBrace)
ContainerInitBody : list(StructLiteralField, token(Comma)) | list(Expression, token(Comma))
*/
static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *prefix_op_expr = ast_parse_prefix_op_expr(pc, token_index, mandatory);
if (!prefix_op_expr) {
return nullptr;
@ -843,7 +843,7 @@ SliceExpression : token(LBracket) Expression token(Ellipsis) option(Expression)
FieldAccessExpression : token(Dot) token(Symbol)
StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression
*/
static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *primary_expr = ast_parse_primary_expr(pc, token_index, mandatory);
if (!primary_expr) {
return nullptr;
@ -936,7 +936,7 @@ static PrefixOp tok_to_prefix_op(Token *token) {
PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression
PrefixOp = "!" | "-" | "~" | "*" | ("&" option("const")) | "?" | "%" | "%%" | "??" | "-%"
*/
static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
PrefixOp prefix_op = tok_to_prefix_op(token);
if (prefix_op == PrefixOpInvalid) {
@ -1005,7 +1005,7 @@ static BinOpType tok_to_mult_op(Token *token) {
/*
MultiplyOperator = "*" | "/" | "%" | "**" | "*%"
*/
static BinOpType ast_parse_mult_op(ParseContext *pc, int *token_index, bool mandatory) {
static BinOpType ast_parse_mult_op(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
BinOpType result = tok_to_mult_op(token);
if (result == BinOpTypeInvalid) {
@ -1022,7 +1022,7 @@ static BinOpType ast_parse_mult_op(ParseContext *pc, int *token_index, bool mand
/*
MultiplyExpression : CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression
*/
static AstNode *ast_parse_mult_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_mult_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *operand_1 = ast_parse_curly_suffix_expr(pc, token_index, mandatory);
if (!operand_1)
return nullptr;
@ -1059,7 +1059,7 @@ static BinOpType tok_to_add_op(Token *token) {
/*
AdditionOperator = "+" | "-" | "++" | "+%" | "-%"
*/
static BinOpType ast_parse_add_op(ParseContext *pc, int *token_index, bool mandatory) {
static BinOpType ast_parse_add_op(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
BinOpType result = tok_to_add_op(token);
if (result == BinOpTypeInvalid) {
@ -1076,7 +1076,7 @@ static BinOpType ast_parse_add_op(ParseContext *pc, int *token_index, bool manda
/*
AdditionExpression : MultiplyExpression AdditionOperator AdditionExpression | MultiplyExpression
*/
static AstNode *ast_parse_add_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_add_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *operand_1 = ast_parse_mult_expr(pc, token_index, mandatory);
if (!operand_1)
return nullptr;
@ -1111,7 +1111,7 @@ static BinOpType tok_to_bit_shift_op(Token *token) {
/*
BitShiftOperator = "<<" | ">>" | "<<%"
*/
static BinOpType ast_parse_bit_shift_op(ParseContext *pc, int *token_index, bool mandatory) {
static BinOpType ast_parse_bit_shift_op(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
BinOpType result = tok_to_bit_shift_op(token);
if (result == BinOpTypeInvalid) {
@ -1128,7 +1128,7 @@ static BinOpType ast_parse_bit_shift_op(ParseContext *pc, int *token_index, bool
/*
BitShiftExpression : AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression
*/
static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *operand_1 = ast_parse_add_expr(pc, token_index, mandatory);
if (!operand_1)
return nullptr;
@ -1155,7 +1155,7 @@ static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, int *token_index, boo
/*
BinaryAndExpression : BitShiftExpression token(Ampersand) BinaryAndExpression | BitShiftExpression
*/
static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_bin_and_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *operand_1 = ast_parse_bit_shift_expr(pc, token_index, mandatory);
if (!operand_1)
return nullptr;
@ -1181,7 +1181,7 @@ static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool
/*
BinaryXorExpression : BinaryAndExpression token(BinXor) BinaryXorExpression | BinaryAndExpression
*/
static AstNode *ast_parse_bin_xor_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_bin_xor_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *operand_1 = ast_parse_bin_and_expr(pc, token_index, mandatory);
if (!operand_1)
return nullptr;
@ -1207,7 +1207,7 @@ static AstNode *ast_parse_bin_xor_expr(ParseContext *pc, int *token_index, bool
/*
BinaryOrExpression : BinaryXorExpression token(BinOr) BinaryOrExpression | BinaryXorExpression
*/
static AstNode *ast_parse_bin_or_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_bin_or_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *operand_1 = ast_parse_bin_xor_expr(pc, token_index, mandatory);
if (!operand_1)
return nullptr;
@ -1242,7 +1242,7 @@ static BinOpType tok_to_cmp_op(Token *token) {
}
}
static BinOpType ast_parse_comparison_operator(ParseContext *pc, int *token_index, bool mandatory) {
static BinOpType ast_parse_comparison_operator(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
BinOpType result = tok_to_cmp_op(token);
if (result == BinOpTypeInvalid) {
@ -1259,7 +1259,7 @@ static BinOpType ast_parse_comparison_operator(ParseContext *pc, int *token_inde
/*
ComparisonExpression : BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression
*/
static AstNode *ast_parse_comparison_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_comparison_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *operand_1 = ast_parse_bin_or_expr(pc, token_index, mandatory);
if (!operand_1)
return nullptr;
@ -1283,7 +1283,7 @@ static AstNode *ast_parse_comparison_expr(ParseContext *pc, int *token_index, bo
/*
BoolAndExpression : ComparisonExpression token(BoolAnd) BoolAndExpression | ComparisonExpression
*/
static AstNode *ast_parse_bool_and_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_bool_and_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *operand_1 = ast_parse_comparison_expr(pc, token_index, mandatory);
if (!operand_1)
return nullptr;
@ -1309,7 +1309,7 @@ static AstNode *ast_parse_bool_and_expr(ParseContext *pc, int *token_index, bool
/*
Else : token(Else) Expression
*/
static AstNode *ast_parse_else(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_else(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *else_token = &pc->tokens->at(*token_index);
if (else_token->id != TokenIdKeywordElse) {
@ -1329,7 +1329,7 @@ IfExpression : IfVarExpression | IfBoolExpression
IfBoolExpression : token(If) token(LParen) Expression token(RParen) Expression option(Else)
IfVarExpression = "if" "(" ("const" | "var") option("*") "Symbol" option(":" TypeExpr) "?=" Expression ")" Expression Option(Else)
*/
static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *if_tok = &pc->tokens->at(*token_index);
if (if_tok->id != TokenIdKeywordIf) {
if (mandatory) {
@ -1396,7 +1396,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool manda
/*
ReturnExpression : option("%" | "?") "return" option(Expression)
*/
static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index) {
static AstNode *ast_parse_return_expr(ParseContext *pc, size_t *token_index) {
Token *token = &pc->tokens->at(*token_index);
NodeType node_type;
@ -1439,7 +1439,7 @@ static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index) {
/*
Defer = option("%" | "?") "defer" option(Expression)
*/
static AstNode *ast_parse_defer_expr(ParseContext *pc, int *token_index) {
static AstNode *ast_parse_defer_expr(ParseContext *pc, size_t *token_index) {
Token *token = &pc->tokens->at(*token_index);
NodeType node_type;
@ -1482,7 +1482,7 @@ static AstNode *ast_parse_defer_expr(ParseContext *pc, int *token_index) {
/*
VariableDeclaration : ("var" | "const") "Symbol" ("=" Expression | ":" PrefixOpExpression option("=" Expression))
*/
static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token_index, bool mandatory,
static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *token_index, bool mandatory,
ZigList<AstNode*> *directives, VisibMod visib_mod)
{
Token *first_token = &pc->tokens->at(*token_index);
@ -1536,7 +1536,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token
/*
BoolOrExpression : BoolAndExpression token(BoolOr) BoolOrExpression | BoolAndExpression
*/
static AstNode *ast_parse_bool_or_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_bool_or_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *operand_1 = ast_parse_bool_and_expr(pc, token_index, mandatory);
if (!operand_1)
return nullptr;
@ -1562,7 +1562,7 @@ static AstNode *ast_parse_bool_or_expr(ParseContext *pc, int *token_index, bool
/*
WhileExpression = "while" "(" Expression option(";" Expression) ")" Expression
*/
static AstNode *ast_parse_while_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_while_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
if (token->id != TokenIdKeywordWhile) {
@ -1598,7 +1598,7 @@ static AstNode *ast_parse_while_expr(ParseContext *pc, int *token_index, bool ma
return node;
}
static AstNode *ast_parse_symbol(ParseContext *pc, int *token_index) {
static AstNode *ast_parse_symbol(ParseContext *pc, size_t *token_index) {
Token *token = ast_eat_token(pc, token_index, TokenIdSymbol);
AstNode *node = ast_create_node(pc, NodeTypeSymbol, token);
node->data.symbol_expr.symbol = token_buf(token);
@ -1608,7 +1608,7 @@ static AstNode *ast_parse_symbol(ParseContext *pc, int *token_index) {
/*
ForExpression = "for" "(" Expression ")" option("|" option("*") "Symbol" option("," "Symbol") "|") Expression
*/
static AstNode *ast_parse_for_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_for_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
if (token->id != TokenIdKeywordFor) {
@ -1659,7 +1659,7 @@ SwitchExpression : "switch" "(" Expression ")" "{" many(SwitchProng) "}"
SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" "Symbol" "|") Expression ","
SwitchItem : Expression | (Expression "..." Expression)
*/
static AstNode *ast_parse_switch_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
if (token->id != TokenIdKeywordSwitch) {
@ -1736,7 +1736,7 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, int *token_index, bool m
/*
BlockExpression : IfExpression | Block | WhileExpression | ForExpression | SwitchExpression
*/
static AstNode *ast_parse_block_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_block_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
AstNode *if_expr = ast_parse_if_expr(pc, token_index, false);
@ -1791,7 +1791,7 @@ static BinOpType tok_to_ass_op(Token *token) {
/*
AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "&&=" | "||=" | "*%=" | "+%=" | "-%=" | "<<%="
*/
static BinOpType ast_parse_ass_op(ParseContext *pc, int *token_index, bool mandatory) {
static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
BinOpType result = tok_to_ass_op(token);
if (result == BinOpTypeInvalid) {
@ -1810,7 +1810,7 @@ UnwrapExpression : BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpressi
UnwrapMaybe : "??" BoolOrExpression
UnwrapError : "%%" option("|" "Symbol" "|") BoolOrExpression
*/
static AstNode *ast_parse_unwrap_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *lhs = ast_parse_bool_or_expr(pc, token_index, mandatory);
if (!lhs)
return nullptr;
@ -1853,7 +1853,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, int *token_index, bool m
/*
AssignmentExpression : UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression
*/
static AstNode *ast_parse_ass_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_ass_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
AstNode *lhs = ast_parse_unwrap_expr(pc, token_index, mandatory);
if (!lhs)
return nullptr;
@ -1877,7 +1877,7 @@ static AstNode *ast_parse_ass_expr(ParseContext *pc, int *token_index, bool mand
/*
NonBlockExpression : ReturnExpression | AssignmentExpression
*/
static AstNode *ast_parse_non_block_expr(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_non_block_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
AstNode *return_expr = ast_parse_return_expr(pc, token_index);
@ -1897,7 +1897,7 @@ static AstNode *ast_parse_non_block_expr(ParseContext *pc, int *token_index, boo
/*
Expression : BlockExpression | NonBlockExpression
*/
static AstNode *ast_parse_expression(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
AstNode *block_expr = ast_parse_block_expr(pc, token_index, false);
@ -1917,7 +1917,7 @@ static AstNode *ast_parse_expression(ParseContext *pc, int *token_index, bool ma
/*
Label: token(Symbol) token(Colon)
*/
static AstNode *ast_parse_label(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_label(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *symbol_token = &pc->tokens->at(*token_index);
if (symbol_token->id != TokenIdSymbol) {
if (mandatory) {
@ -1956,7 +1956,7 @@ static AstNode *ast_create_void_expr(ParseContext *pc, Token *token) {
Block : token(LBrace) list(option(Statement), token(Semicolon)) token(RBrace)
Statement = Label | VariableDeclaration ";" | Defer ";" | NonBlockExpression ";" | BlockExpression
*/
static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandatory) {
static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *last_token = &pc->tokens->at(*token_index);
if (last_token->id != TokenIdLBrace) {
@ -2021,7 +2021,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato
/*
FnProto = "fn" option("Symbol") ParamDeclList option("->" TypeExpr)
*/
static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory,
static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory,
ZigList<AstNode*> *directives, VisibMod visib_mod)
{
Token *first_token = &pc->tokens->at(*token_index);
@ -2064,7 +2064,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand
/*
FnDef = option("inline" | "extern") FnProto Block
*/
static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandatory,
static AstNode *ast_parse_fn_def(ParseContext *pc, size_t *token_index, bool mandatory,
ZigList<AstNode*> *directives, VisibMod visib_mod)
{
Token *first_token = &pc->tokens->at(*token_index);
@ -2111,7 +2111,7 @@ static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandat
/*
ExternDecl = "extern" (FnProto | VariableDeclaration) ";"
*/
static AstNode *ast_parse_extern_decl(ParseContext *pc, int *token_index, bool mandatory,
static AstNode *ast_parse_extern_decl(ParseContext *pc, size_t *token_index, bool mandatory,
ZigList<AstNode *> *directives, VisibMod visib_mod)
{
Token *extern_kw = &pc->tokens->at(*token_index);
@ -2151,7 +2151,7 @@ static AstNode *ast_parse_extern_decl(ParseContext *pc, int *token_index, bool m
/*
UseDecl = "use" Expression ";"
*/
static AstNode *ast_parse_use(ParseContext *pc, int *token_index,
static AstNode *ast_parse_use(ParseContext *pc, size_t *token_index,
ZigList<AstNode*> *directives, VisibMod visib_mod)
{
Token *use_kw = &pc->tokens->at(*token_index);
@ -2175,7 +2175,7 @@ ContainerDecl = ("struct" | "enum" | "union") "Symbol" option(ParamDeclList) "{"
StructMember = many(Directive) option(VisibleMod) (StructField | FnDef | GlobalVarDecl | ContainerDecl)
StructField : "Symbol" option(":" Expression) ",")
*/
static AstNode *ast_parse_container_decl(ParseContext *pc, int *token_index,
static AstNode *ast_parse_container_decl(ParseContext *pc, size_t *token_index,
ZigList<AstNode*> *directives, VisibMod visib_mod)
{
Token *first_token = &pc->tokens->at(*token_index);
@ -2289,7 +2289,7 @@ static AstNode *ast_parse_container_decl(ParseContext *pc, int *token_index,
/*
ErrorValueDecl : "error" "Symbol" ";"
*/
static AstNode *ast_parse_error_value_decl(ParseContext *pc, int *token_index,
static AstNode *ast_parse_error_value_decl(ParseContext *pc, size_t *token_index,
ZigList<AstNode*> *directives, VisibMod visib_mod)
{
Token *first_token = &pc->tokens->at(*token_index);
@ -2314,7 +2314,7 @@ static AstNode *ast_parse_error_value_decl(ParseContext *pc, int *token_index,
/*
TypeDecl = "type" "Symbol" "=" TypeExpr ";"
*/
static AstNode *ast_parse_type_decl(ParseContext *pc, int *token_index,
static AstNode *ast_parse_type_decl(ParseContext *pc, size_t *token_index,
ZigList<AstNode*> *directives, VisibMod visib_mod)
{
Token *first_token = &pc->tokens->at(*token_index);
@ -2343,7 +2343,7 @@ static AstNode *ast_parse_type_decl(ParseContext *pc, int *token_index,
/*
TopLevelDecl = many(Directive) option(VisibleMod) (FnDef | ExternDecl | Import | ContainerDecl | GlobalVarDecl | ErrorValueDecl | CImportDecl | TypeDecl)
*/
static void ast_parse_top_level_decls(ParseContext *pc, int *token_index, ZigList<AstNode *> *top_level_decls) {
static void ast_parse_top_level_decls(ParseContext *pc, size_t *token_index, ZigList<AstNode *> *top_level_decls) {
for (;;) {
Token *directive_token = &pc->tokens->at(*token_index);
ZigList<AstNode *> *directives = allocate<ZigList<AstNode*>>(1);
@ -2417,7 +2417,7 @@ static void ast_parse_top_level_decls(ParseContext *pc, int *token_index, ZigLis
/*
Root : many(TopLevelDecl) token(EOF)
*/
static AstNode *ast_parse_root(ParseContext *pc, int *token_index) {
static AstNode *ast_parse_root(ParseContext *pc, size_t *token_index) {
AstNode *node = ast_create_node(pc, NodeTypeRoot, &pc->tokens->at(*token_index));
ast_parse_top_level_decls(pc, token_index, &node->data.root.top_level_decls);
@ -2441,7 +2441,7 @@ AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner,
pc.buf = buf;
pc.tokens = tokens;
pc.next_node_index = next_node_index;
int token_index = 0;
size_t token_index = 0;
pc.root = ast_parse_root(&pc, &token_index);
return pc.root;
}
@ -2454,7 +2454,7 @@ static void visit_field(AstNode **node, void (*visit)(AstNode **, void *context)
static void visit_node_list(ZigList<AstNode *> *list, void (*visit)(AstNode **, void *context), void *context) {
if (list) {
for (int i = 0; i < list->length; i += 1) {
for (size_t i = 0; i < list->length; i += 1) {
visit(&list->at(i), context);
}
}
@ -2607,11 +2607,11 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
// none
break;
case NodeTypeAsmExpr:
for (int i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
visit_field(&asm_input->expr, visit, context);
}
for (int i = 0; i < node->data.asm_expr.output_list.length; i += 1) {
for (size_t i = 0; i < node->data.asm_expr.output_list.length; i += 1) {
AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);
visit_field(&asm_output->return_type, visit, context);
}
@ -2659,7 +2659,7 @@ void normalize_parent_ptrs(AstNode *node) {
static void clone_subtree_list(ZigList<AstNode *> *dest, ZigList<AstNode *> *src, uint32_t *next_node_index) {
memset(dest, 0, sizeof(ZigList<AstNode *>));
dest->resize(src->length);
for (int i = 0; i < src->length; i += 1) {
for (size_t i = 0; i < src->length; i += 1) {
dest->at(i) = ast_clone_subtree(src->at(i), next_node_index);
dest->at(i)->parent_field = &dest->at(i);
}
@ -2670,7 +2670,7 @@ static void clone_subtree_list_omit_inline_params(ZigList<AstNode *> *dest, ZigL
{
memset(dest, 0, sizeof(ZigList<AstNode *>));
dest->ensure_capacity(src->length);
for (int i = 0; i < src->length; i += 1) {
for (size_t i = 0; i < src->length; i += 1) {
AstNode *src_node = src->at(i);
assert(src_node->type == NodeTypeParamDecl);
if (src_node->data.param_decl.is_inline) {
@ -2712,7 +2712,7 @@ static void clone_subtree_tld(TopLevelDecl *dest, TopLevelDecl *src, uint32_t *n
AstNode *ast_clone_subtree_special(AstNode *old_node, uint32_t *next_node_index, enum AstCloneSpecial special) {
AstNode *new_node = allocate_nonzero<AstNode>(1);
memcpy(new_node, old_node, sizeof(AstNode));
safe_memcpy(new_node, old_node, 1);
new_node->create_index = *next_node_index;
*next_node_index += 1;
new_node->parent_field = nullptr;

View File

@ -156,7 +156,7 @@ static const ZigLLVM_ObjectFormatType oformat_list[] = {
ZigLLVM_MachO,
};
int target_oformat_count(void) {
size_t target_oformat_count(void) {
return array_length(oformat_list);
}
@ -174,7 +174,7 @@ const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat) {
zig_unreachable();
}
int target_arch_count(void) {
size_t target_arch_count(void) {
return array_length(arch_list);
}
@ -182,7 +182,7 @@ const ArchType *get_target_arch(int index) {
return &arch_list[index];
}
int target_vendor_count(void) {
size_t target_vendor_count(void) {
return array_length(vendor_list);
}
@ -190,7 +190,7 @@ ZigLLVM_VendorType get_target_vendor(int index) {
return vendor_list[index];
}
int target_os_count(void) {
size_t target_os_count(void) {
return array_length(os_list);
}
ZigLLVM_OSType get_target_os(int index) {
@ -201,7 +201,7 @@ const char *get_target_os_name(ZigLLVM_OSType os_type) {
return (os_type == ZigLLVM_UnknownOS) ? "freestanding" : ZigLLVMGetOSTypeName(os_type);
}
int target_environ_count(void) {
size_t target_environ_count(void) {
return array_length(environ_list);
}
ZigLLVM_EnvironmentType get_target_environ(int index) {
@ -237,7 +237,7 @@ void get_arch_name(char *out_str, const ArchType *arch) {
}
int parse_target_arch(const char *str, ArchType *out_arch) {
for (int i = 0; i < array_length(arch_list); i += 1) {
for (size_t i = 0; i < array_length(arch_list); i += 1) {
const ArchType *arch = &arch_list[i];
char arch_name[50];
get_arch_name_raw(arch_name, arch->arch, arch->sub_arch);
@ -250,7 +250,7 @@ int parse_target_arch(const char *str, ArchType *out_arch) {
}
int parse_target_os(const char *str, ZigLLVM_OSType *out_os) {
for (int i = 0; i < array_length(os_list); i += 1) {
for (size_t i = 0; i < array_length(os_list); i += 1) {
ZigLLVM_OSType os = os_list[i];
const char *os_name = get_target_os_name(os);
if (strcmp(os_name, str) == 0) {
@ -262,7 +262,7 @@ int parse_target_os(const char *str, ZigLLVM_OSType *out_os) {
}
int parse_target_environ(const char *str, ZigLLVM_EnvironmentType *out_environ) {
for (int i = 0; i < array_length(environ_list); i += 1) {
for (size_t i = 0; i < array_length(environ_list); i += 1) {
ZigLLVM_EnvironmentType env_type = environ_list[i];
const char *environ_name = ZigLLVMGetEnvironmentTypeName(env_type);
if (strcmp(environ_name, str) == 0) {

View File

@ -38,22 +38,22 @@ enum CIntType {
CIntTypeCount,
};
int target_arch_count(void);
size_t target_arch_count(void);
const ArchType *get_target_arch(int index);
void get_arch_name(char *out_str, const ArchType *arch);
int target_vendor_count(void);
size_t target_vendor_count(void);
ZigLLVM_VendorType get_target_vendor(int index);
int target_os_count(void);
size_t target_os_count(void);
ZigLLVM_OSType get_target_os(int index);
const char *get_target_os_name(ZigLLVM_OSType os_type);
int target_environ_count(void);
size_t target_environ_count(void);
ZigLLVM_EnvironmentType get_target_environ(int index);
int target_oformat_count(void);
size_t target_oformat_count(void);
const ZigLLVM_ObjectFormatType get_target_oformat(int index);
const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat);

View File

@ -141,7 +141,7 @@ static const struct ZigKeyword zig_keywords[] = {
};
bool is_zig_keyword(Buf *buf) {
for (int i = 0; i < array_length(zig_keywords); i += 1) {
for (size_t i = 0; i < array_length(zig_keywords); i += 1) {
if (buf_eql_str(buf, zig_keywords[i].text)) {
return true;
}
@ -209,7 +209,7 @@ enum TokenizeState {
struct Tokenize {
Buf *buf;
int pos;
size_t pos;
TokenizeState state;
ZigList<Token> *tokens;
int line;
@ -329,7 +329,7 @@ static void end_float_token(Tokenize *t) {
}
}
uint64_t double_bits = (exponent_bits << 52) | significand_bits;
memcpy(&t->cur_tok->data.num_lit.bignum.data.x_float, &double_bits, sizeof(double));
safe_memcpy(&t->cur_tok->data.num_lit.bignum.data.x_float, (double *)&double_bits, 1);
}
static void end_token(Tokenize *t) {
@ -397,7 +397,7 @@ void tokenize(Buf *buf, Tokenization *out) {
t.tokens = out->tokens = allocate<ZigList<Token>>(1);
t.buf = buf;
out->line_offsets = allocate<ZigList<int>>(1);
out->line_offsets = allocate<ZigList<size_t>>(1);
out->line_offsets->append(0);
for (t.pos = 0; t.pos < buf_len(t.buf); t.pos += 1) {
@ -1545,10 +1545,10 @@ const char * token_name(TokenId id) {
}
void print_tokens(Buf *buf, ZigList<Token> *tokens) {
for (int i = 0; i < tokens->length; i += 1) {
for (size_t i = 0; i < tokens->length; i += 1) {
Token *token = &tokens->at(i);
fprintf(stderr, "%s ", token_name(token->id));
if (token->start_pos >= 0) {
if (token->start_pos != SIZE_MAX) {
fwrite(buf_ptr(buf) + token->start_pos, 1, token->end_pos - token->start_pos, stderr);
}
fprintf(stderr, "\n");

View File

@ -131,10 +131,10 @@ struct TokenCharLit {
struct Token {
TokenId id;
int start_pos;
int end_pos;
int start_line;
int start_column;
size_t start_pos;
size_t end_pos;
size_t start_line;
size_t start_column;
union {
// TokenIdNumberLiteral
@ -150,12 +150,12 @@ struct Token {
struct Tokenization {
ZigList<Token> *tokens;
ZigList<int> *line_offsets;
ZigList<size_t> *line_offsets;
// if an error occurred
Buf *err;
int err_line;
int err_column;
size_t err_line;
size_t err_column;
};
void tokenize(Buf *buf, Tokenization *out_tokenization);

View File

@ -45,15 +45,35 @@ __attribute__((malloc)) static inline T *allocate(size_t count) {
}
template<typename T>
static inline T *reallocate_nonzero(T * old, size_t new_count) {
static inline void safe_memcpy(T *dest, const T *src, size_t count) {
#ifdef NDEBUG
memcpy(dest, src, count * sizeof(T));
#else
// manually assign every elment to trigger compile error for non-copyable structs
for (size_t i = 0; i < count; i += 1) {
dest[i] = src[i];
}
#endif
}
template<typename T>
static inline T *reallocate_nonzero(T *old, size_t old_count, size_t new_count) {
#ifdef NDEBUG
T *ptr = reinterpret_cast<T*>(realloc(old, new_count * sizeof(T)));
if (!ptr)
zig_panic("allocation failed");
return ptr;
#else
// manually assign every element to trigger compile error for non-copyable structs
T *ptr = allocate_nonzero<T>(new_count);
safe_memcpy(ptr, old, old_count);
free(old);
return ptr;
#endif
}
template <typename T, long n>
constexpr long array_length(const T (&)[n]) {
template <typename T, size_t n>
constexpr size_t array_length(const T (&)[n]) {
return n;
}

View File

@ -42,15 +42,14 @@ pub struct SmallList(T: type, static_size: usize) {
}
pub fn ensureCapacity(l: &Self, new_capacity: usize) -> %void {
const old_capacity = l.items.len;
var better_capacity = old_capacity;
var better_capacity = l.items.len;
while (better_capacity < new_capacity) {
better_capacity *= 2;
}
if (better_capacity != old_capacity) {
if (better_capacity != l.items.len) {
if (l.items.ptr == &l.prealloc_items[0]) {
l.items = %return l.allocator.alloc(T, better_capacity);
mem.copy(T, l.items, l.prealloc_items[0...old_capacity]);
mem.copy(T, l.items, l.prealloc_items[0...l.len]);
} else {
l.items = %return l.allocator.realloc(T, l.items, better_capacity);
}

View File

@ -93,7 +93,7 @@ static TestCase *add_simple_case_libc(const char *case_name, const char *source,
return tc;
}
static TestCase *add_compile_fail_case(const char *case_name, const char *source, int count, ...) {
static TestCase *add_compile_fail_case(const char *case_name, const char *source, size_t count, ...) {
va_list ap;
va_start(ap, count);
@ -103,7 +103,7 @@ static TestCase *add_compile_fail_case(const char *case_name, const char *source
test_case->source_files.at(0).relative_path = tmp_source_path;
test_case->source_files.at(0).source_code = source;
for (int i = 0; i < count; i += 1) {
for (size_t i = 0; i < count; i += 1) {
const char *arg = va_arg(ap, const char *);
test_case->compile_errors.append(arg);
}
@ -181,7 +181,7 @@ static void add_debug_safety_case(const char *case_name, const char *source) {
}
static TestCase *add_parseh_case(const char *case_name, AllowWarnings allow_warnings,
const char *source, int count, ...)
const char *source, size_t count, ...)
{
va_list ap;
va_start(ap, count);
@ -195,7 +195,7 @@ static TestCase *add_parseh_case(const char *case_name, AllowWarnings allow_warn
test_case->source_files.at(0).relative_path = tmp_h_path;
test_case->source_files.at(0).source_code = source;
for (int i = 0; i < count; i += 1) {
for (size_t i = 0; i < count; i += 1) {
const char *arg = va_arg(ap, const char *);
test_case->compile_errors.append(arg);
}
@ -1854,7 +1854,7 @@ static void run_self_hosted_test(bool is_release_mode) {
if (term.how != TerminationIdClean || term.code != 0) {
printf("\nSelf-hosted tests failed:\n");
printf("./zig");
for (int i = 0; i < args.length; i += 1) {
for (size_t i = 0; i < args.length; i += 1) {
printf(" %s", args.at(i));
}
printf("\n%s\n", buf_ptr(&zig_stderr));
@ -1881,7 +1881,7 @@ static void add_self_hosted_tests(void) {
static void print_compiler_invocation(TestCase *test_case) {
printf("%s", zig_exe);
for (int i = 0; i < test_case->compiler_args.length; i += 1) {
for (size_t i = 0; i < test_case->compiler_args.length; i += 1) {
printf(" %s", test_case->compiler_args.at(i));
}
printf("\n");
@ -1889,7 +1889,7 @@ static void print_compiler_invocation(TestCase *test_case) {
static void print_exe_invocation(TestCase *test_case) {
printf("%s", tmp_exe_path);
for (int i = 0; i < test_case->program_args.length; i += 1) {
for (size_t i = 0; i < test_case->program_args.length; i += 1) {
printf(" %s", test_case->program_args.at(i));
}
printf("\n");
@ -1900,7 +1900,7 @@ static void run_test(TestCase *test_case) {
return run_self_hosted_test(test_case->is_release_mode);
}
for (int i = 0; i < test_case->source_files.length; i += 1) {
for (size_t i = 0; i < test_case->source_files.length; i += 1) {
TestSourceFile *test_source = &test_case->source_files.at(i);
os_write_file(
buf_create_from_str(test_source->relative_path),
@ -1917,7 +1917,7 @@ static void run_test(TestCase *test_case) {
if (!test_case->is_parseh && test_case->compile_errors.length) {
if (term.how != TerminationIdClean || term.code != 0) {
for (int i = 0; i < test_case->compile_errors.length; i += 1) {
for (size_t i = 0; i < test_case->compile_errors.length; i += 1) {
const char *err_text = test_case->compile_errors.at(i);
if (!strstr(buf_ptr(&zig_stderr), err_text)) {
printf("\n");
@ -1957,7 +1957,7 @@ static void run_test(TestCase *test_case) {
}
}
for (int i = 0; i < test_case->compile_errors.length; i += 1) {
for (size_t i = 0; i < test_case->compile_errors.length; i += 1) {
const char *output = test_case->compile_errors.at(i);
if (!strstr(buf_ptr(&zig_stdout), output)) {
@ -2015,7 +2015,7 @@ static void run_test(TestCase *test_case) {
}
}
for (int i = 0; i < test_case->source_files.length; i += 1) {
for (size_t i = 0; i < test_case->source_files.length; i += 1) {
TestSourceFile *test_source = &test_case->source_files.at(i);
remove(test_source->relative_path);
}
@ -2023,21 +2023,23 @@ static void run_test(TestCase *test_case) {
static void run_all_tests(bool reverse) {
if (reverse) {
for (int i = test_cases.length - 1; i >= 0; i -= 1) {
for (size_t i = test_cases.length;;) {
TestCase *test_case = test_cases.at(i);
printf("Test %d/%d %s...", i + 1, test_cases.length, test_case->case_name);
printf("Test %zu/%zu %s...", i + 1, test_cases.length, test_case->case_name);
run_test(test_case);
printf("OK\n");
if (i == 0) break;
i -= 1;
}
} else {
for (int i = 0; i < test_cases.length; i += 1) {
for (size_t i = 0; i < test_cases.length; i += 1) {
TestCase *test_case = test_cases.at(i);
printf("Test %d/%d %s...", i + 1, test_cases.length, test_case->case_name);
printf("Test %zu/%zu %s...", i + 1, test_cases.length, test_case->case_name);
run_test(test_case);
printf("OK\n");
}
}
printf("%d tests passed.\n", test_cases.length);
printf("%zu tests passed.\n", test_cases.length);
}
static void cleanup(void) {