authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-15 14:05:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-19 11:54:01-04:00
log3239b3cb6957aa5f5f04c9d7d9035da14ccd0741
tree49045063682e47114d3ca51c81907c6adcb3e0e5
parent4c0259b107236b39f7b1e8f423d2bf9f48e89b54

use size_t for indexes

protect against incorrect copies in debug mode

27 files changed, 555 insertions(+), 531 deletions(-)

CMakeLists.txt+1-1
......@@ -177,7 +177,7 @@ if(MINGW)
177177 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")
178178endif()
179179
180set(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")
180set(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")
181181set(EXE_LDFLAGS " ")
182182if(ZIG_TEST_COVERAGE)
183183 set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage")
src/all_types.hpp+45-46
......@@ -18,7 +18,6 @@
1818
1919struct AstNode;
2020struct ImportTableEntry;
21struct AsmToken;
2221struct FnTableEntry;
2322struct BlockContext;
2423struct TypeTableEntry;
......@@ -218,8 +217,8 @@ struct AstNodeFnProto {
218217 bool skip;
219218 Expr resolved_expr;
220219 // computed from params field
221 int inline_arg_count;
222 int inline_or_var_type_arg_count;
220 size_t inline_arg_count;
221 size_t inline_or_var_type_arg_count;
223222 // if this is a generic function implementation, this points to the generic node
224223 AstNode *generic_proto_node;
225224};
......@@ -282,7 +281,7 @@ struct AstNodeDefer {
282281
283282 // populated by semantic analyzer:
284283 Expr resolved_expr;
285 int index_in_block;
284 size_t index_in_block;
286285 LLVMBasicBlockRef basic_block;
287286 BlockContext *child_block;
288287};
......@@ -547,7 +546,7 @@ struct AstNodeSwitchExpr {
547546
548547 // populated by semantic analyzer
549548 Expr resolved_expr;
550 int const_chosen_prong_index;
549 size_t const_chosen_prong_index;
551550};
552551
553552struct AstNodeSwitchProng {
......@@ -599,8 +598,20 @@ struct AsmInput {
599598};
600599
601600struct SrcPos {
602 int line;
603 int column;
601 size_t line;
602 size_t column;
603};
604
605enum AsmTokenId {
606 AsmTokenIdTemplate,
607 AsmTokenIdPercent,
608 AsmTokenIdVar,
609};
610
611struct AsmToken {
612 enum AsmTokenId id;
613 size_t start;
614 size_t end;
604615};
605616
606617struct AstNodeAsmExpr {
......@@ -612,7 +623,7 @@ struct AstNodeAsmExpr {
612623 ZigList<Buf*> clobber_list;
613624
614625 // populated by semantic analyzer
615 int return_count;
626 size_t return_count;
616627 Expr resolved_expr;
617628};
618629
......@@ -763,8 +774,8 @@ struct AstNodeVarLiteral {
763774
764775struct AstNode {
765776 enum NodeType type;
766 int line;
767 int column;
777 size_t line;
778 size_t column;
768779 uint32_t create_index; // for determinism purposes
769780 ImportTableEntry *owner;
770781 AstNode **parent_field; // for AST rewriting
......@@ -823,18 +834,6 @@ struct AstNode {
823834 } data;
824835};
825836
826enum AsmTokenId {
827 AsmTokenIdTemplate,
828 AsmTokenIdPercent,
829 AsmTokenIdVar,
830};
831
832struct AsmToken {
833 enum AsmTokenId id;
834 int start;
835 int end;
836};
837
838837// this struct is allocated with allocate_nonzero
839838struct FnTypeParamInfo {
840839 bool is_noalias;
......@@ -844,24 +843,24 @@ struct FnTypeParamInfo {
844843struct GenericParamValue {
845844 TypeTableEntry *type;
846845 AstNode *node;
847 int impl_index;
846 size_t impl_index;
848847};
849848
850849struct GenericFnTypeId {
851850 AstNode *decl_node; // the generic fn or container decl node
852851 GenericParamValue *generic_params;
853 int generic_param_count;
852 size_t generic_param_count;
854853};
855854
856855uint32_t generic_fn_type_id_hash(GenericFnTypeId *id);
857856bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b);
858857
859858
860static const int fn_type_id_prealloc_param_info_count = 4;
859static const size_t fn_type_id_prealloc_param_info_count = 4;
861860struct FnTypeId {
862861 TypeTableEntry *return_type;
863862 FnTypeParamInfo *param_info;
864 int param_count;
863 size_t param_count;
865864 bool is_var_args;
866865 bool is_naked;
867866 bool is_cold;
......@@ -878,12 +877,12 @@ struct TypeTableEntryPointer {
878877};
879878
880879struct TypeTableEntryInt {
881 int bit_count;
880 size_t bit_count;
882881 bool is_signed;
883882};
884883
885884struct TypeTableEntryFloat {
886 int bit_count;
885 size_t bit_count;
887886};
888887
889888struct TypeTableEntryArray {
......@@ -894,8 +893,8 @@ struct TypeTableEntryArray {
894893struct TypeStructField {
895894 Buf *name;
896895 TypeTableEntry *type_entry;
897 int src_index;
898 int gen_index;
896 size_t src_index;
897 size_t gen_index;
899898};
900899struct TypeTableEntryStruct {
901900 AstNode *decl_node;
......@@ -958,8 +957,8 @@ struct TypeTableEntryUnion {
958957};
959958
960959struct FnGenParamInfo {
961 int src_index;
962 int gen_index;
960 size_t src_index;
961 size_t gen_index;
963962 bool is_byval;
964963 TypeTableEntry *type;
965964};
......@@ -967,7 +966,7 @@ struct FnGenParamInfo {
967966struct TypeTableEntryFn {
968967 FnTypeId fn_type_id;
969968 TypeTableEntry *gen_return_type;
970 int gen_param_count;
969 size_t gen_param_count;
971970 FnGenParamInfo *gen_param_info;
972971
973972 LLVMTypeRef raw_type_ref;
......@@ -1057,7 +1056,7 @@ struct ImportTableEntry {
10571056 PackageTableEntry *package;
10581057 ZigLLVMDIFile *di_file;
10591058 Buf *source_code;
1060 ZigList<int> *line_offsets;
1059 ZigList<size_t> *line_offsets;
10611060 BlockContext *block_context;
10621061 AstNode *c_import_node;
10631062 bool any_imports_failed;
......@@ -1127,8 +1126,8 @@ struct EvalFnRoot {
11271126 CodeGen *codegen;
11281127 FnTableEntry *fn;
11291128 AstNode *call_node;
1130 int branch_quota;
1131 int branches_used;
1129 size_t branch_quota;
1130 size_t branches_used;
11321131 AstNode *exceeded_quota_node;
11331132 bool abort;
11341133};
......@@ -1180,7 +1179,7 @@ enum BuiltinFnId {
11801179struct BuiltinFnEntry {
11811180 BuiltinFnId id;
11821181 Buf name;
1183 int param_count;
1182 size_t param_count;
11841183 TypeTableEntry *return_type;
11851184 TypeTableEntry **param_types;
11861185 uint32_t ref_count;
......@@ -1207,11 +1206,11 @@ struct CodeGen {
12071206 HashMap<GenericFnTypeId *, AstNode *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;
12081207
12091208 ZigList<ImportTableEntry *> import_queue;
1210 int import_queue_index;
1209 size_t import_queue_index;
12111210 ZigList<AstNode *> resolve_queue;
1212 int resolve_queue_index;
1211 size_t resolve_queue_index;
12131212 ZigList<AstNode *> use_queue;
1214 int use_queue_index;
1213 size_t use_queue_index;
12151214
12161215 uint32_t next_unresolved_index;
12171216
......@@ -1305,9 +1304,9 @@ struct CodeGen {
13051304 bool c_want_stdint;
13061305 bool c_want_stdbool;
13071306 AstNode *root_export_decl;
1308 int version_major;
1309 int version_minor;
1310 int version_patch;
1307 size_t version_major;
1308 size_t version_minor;
1309 size_t version_patch;
13111310 bool verbose;
13121311 ErrColor err_color;
13131312 ImportTableEntry *root_import;
......@@ -1323,7 +1322,7 @@ struct CodeGen {
13231322 LLVMValueRef int_builtin_fns[2][4]; // [0-ctz,1-clz][0-8,1-16,2-32,3-64]
13241323
13251324 const char **clang_argv;
1326 int clang_argv_len;
1325 size_t clang_argv_len;
13271326 ZigList<const char *> lib_dirs;
13281327
13291328 uint32_t test_fn_count;
......@@ -1345,8 +1344,8 @@ struct VariableTableEntry {
13451344 // which node contains the ConstExprValue for this variable's value
13461345 AstNode *val_node;
13471346 ZigLLVMDILocalVariable *di_loc_var;
1348 int src_arg_index;
1349 int gen_arg_index;
1347 size_t src_arg_index;
1348 size_t gen_arg_index;
13501349 BlockContext *block_context;
13511350 LLVMValueRef param_value_ref;
13521351 bool force_depends_on_compile_var;
src/analyze.cpp+98-98
......@@ -205,7 +205,7 @@ static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *so
205205}
206206
207207
208static int bits_needed_for_unsigned(uint64_t x) {
208static size_t bits_needed_for_unsigned(uint64_t x) {
209209 if (x <= UINT8_MAX) {
210210 return 8;
211211 } else if (x <= UINT16_MAX) {
......@@ -579,7 +579,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c
579579 slice_type_common_init(g, child_type, is_const, entry);
580580 if (child_type->zero_bits) {
581581 entry->data.structure.gen_field_count = 1;
582 entry->data.structure.fields[0].gen_index = -1;
582 entry->data.structure.fields[0].gen_index = SIZE_MAX;
583583 entry->data.structure.fields[1].gen_index = 0;
584584 }
585585
......@@ -736,7 +736,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf
736736 const char *naked_str = fn_type_id->is_naked ? "naked " : "";
737737 const char *cold_str = fn_type_id->is_cold ? "cold " : "";
738738 buf_appendf(&fn_type->name, "%s%s%sfn(", extern_str, naked_str, cold_str);
739 for (int i = 0; i < fn_type_id->param_count; i += 1) {
739 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
740740 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
741741
742742 TypeTableEntry *param_type = param_info->type;
......@@ -763,7 +763,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf
763763 // +1 because 0 is the return type and +1 for maybe making first arg ret val
764764 ZigLLVMDIType **param_di_types = allocate<ZigLLVMDIType*>(2 + fn_type_id->param_count);
765765 param_di_types[0] = fn_type_id->return_type->di_type;
766 int gen_param_index = 0;
766 size_t gen_param_index = 0;
767767 TypeTableEntry *gen_return_type;
768768 if (!type_has_bits(fn_type_id->return_type)) {
769769 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
780780 fn_type->data.fn.gen_return_type = gen_return_type;
781781
782782 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);
783 for (int i = 0; i < fn_type_id->param_count; i += 1) {
783 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
784784 FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];
785785 TypeTableEntry *type_entry = src_param_info->type;
786786 FnGenParamInfo *gen_param_info = &fn_type->data.fn.gen_param_info[i];
787787
788788 gen_param_info->src_index = i;
789 gen_param_info->gen_index = -1;
789 gen_param_info->gen_index = SIZE_MAX;
790790
791791 assert(type_is_complete(type_entry));
792792 if (type_has_bits(type_entry)) {
......@@ -946,7 +946,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
946946 fn_type_id.is_var_args = fn_proto->is_var_args;
947947 fn_type_id.return_type = analyze_type_expr(g, import, context, fn_proto->return_type);
948948
949 for (int i = 0; i < fn_type_id.param_count; i += 1) {
949 for (size_t i = 0; i < fn_type_id.param_count; i += 1) {
950950 AstNode *child = fn_proto->params.at(i);
951951 assert(child->type == NodeTypeParamDecl);
952952
......@@ -1047,7 +1047,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
10471047 fn_table_entry->want_pure_return_type = fn_proto->return_type;
10481048
10491049 ErrorMsg *err_msg = nullptr;
1050 for (int i = 0; i < fn_proto->params.length; i += 1) {
1050 for (size_t i = 0; i < fn_proto->params.length; i += 1) {
10511051 AstNode *param_decl_node = fn_proto->params.at(i);
10521052 assert(param_decl_node->type == NodeTypeParamDecl);
10531053 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
11351135 bool is_noinline = false;
11361136
11371137 if (fn_proto->top_level_decl.directives) {
1138 for (int i = 0; i < fn_proto->top_level_decl.directives->length; i += 1) {
1138 for (size_t i = 0; i < fn_proto->top_level_decl.directives->length; i += 1) {
11391139 AstNode *directive_node = fn_proto->top_level_decl.directives->at(i);
11401140 Buf *name = directive_node->data.directive.name;
11411141
......@@ -1342,7 +1342,7 @@ static void resolve_enum_type(CodeGen *g, ImportTableEntry *import, TypeTableEnt
13421342 // set temporary flag
13431343 enum_type->data.enumeration.embedded_in_current = true;
13441344
1345 int gen_field_index = 0;
1345 size_t gen_field_index = 0;
13461346 for (uint32_t i = 0; i < field_count; i += 1) {
13471347 AstNode *field_node = decl_node->data.struct_decl.fields.at(i);
13481348 TypeEnumField *type_enum_field = &enum_type->data.enumeration.fields[i];
......@@ -1518,7 +1518,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
15181518
15191519 struct_type->deep_const = true;
15201520
1521 int field_count = decl_node->data.struct_decl.fields.length;
1521 size_t field_count = decl_node->data.struct_decl.fields.length;
15221522
15231523 struct_type->data.structure.src_field_count = field_count;
15241524 struct_type->data.structure.fields = allocate<TypeStructField>(field_count);
......@@ -1532,8 +1532,8 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
15321532
15331533 BlockContext *context = struct_type->data.structure.block_context;
15341534
1535 int gen_field_index = 0;
1536 for (int i = 0; i < field_count; i += 1) {
1535 size_t gen_field_index = 0;
1536 for (size_t i = 0; i < field_count; i += 1) {
15371537 AstNode *field_node = decl_node->data.struct_decl.fields.at(i);
15381538 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
15391539 type_struct_field->name = field_node->data.struct_field.name;
......@@ -1541,7 +1541,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
15411541 field_node->data.struct_field.type);
15421542 type_struct_field->type_entry = field_type;
15431543 type_struct_field->src_index = i;
1544 type_struct_field->gen_index = -1;
1544 type_struct_field->gen_index = SIZE_MAX;
15451545
15461546 if (!field_type->deep_const) {
15471547 struct_type->deep_const = false;
......@@ -1574,16 +1574,16 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
15741574 return;
15751575 }
15761576
1577 int gen_field_count = gen_field_index;
1577 size_t gen_field_count = gen_field_index;
15781578 LLVMStructSetBody(struct_type->type_ref, element_types, gen_field_count, false);
15791579
15801580 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(gen_field_count);
15811581
1582 for (int i = 0; i < field_count; i += 1) {
1582 for (size_t i = 0; i < field_count; i += 1) {
15831583 AstNode *field_node = decl_node->data.struct_decl.fields.at(i);
15841584 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
15851585 gen_field_index = type_struct_field->gen_index;
1586 if (gen_field_index == -1) {
1586 if (gen_field_index == SIZE_MAX) {
15871587 continue;
15881588 }
15891589
......@@ -1697,7 +1697,7 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN
16971697 fn_table_entry->type_entry = get_generic_fn_type(g, proto_node);
16981698
16991699 if (is_extern || proto_node->data.fn_proto.top_level_decl.visib_mod == VisibModExport) {
1700 for (int i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
1700 for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
17011701 AstNode *param_decl_node = proto_node->data.fn_proto.params.at(i);
17021702 if (param_decl_node->data.param_decl.is_inline) {
17031703 proto_node->data.fn_proto.skip = true;
......@@ -1754,7 +1754,7 @@ static void scan_struct_decl(CodeGen *g, ImportTableEntry *import, BlockContext
17541754 node->data.struct_decl.type_entry = container_type;
17551755
17561756 // handle the member function definitions independently
1757 for (int i = 0; i < node->data.struct_decl.decls.length; i += 1) {
1757 for (size_t i = 0; i < node->data.struct_decl.decls.length; i += 1) {
17581758 AstNode *child_node = node->data.struct_decl.decls.at(i);
17591759 get_as_top_level_decl(child_node)->parent_decl = node;
17601760 BlockContext *child_context = get_container_block_context(container_type);
......@@ -1802,7 +1802,7 @@ static void preview_error_value_decl(CodeGen *g, AstNode *node) {
18021802 // duplicate error definitions allowed and they get the same value
18031803 err->value = existing_entry->value->value;
18041804 } else {
1805 int error_value_count = g->error_decls.length;
1805 size_t error_value_count = g->error_decls.length;
18061806 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)g->err_tag_type->data.integral.bit_count));
18071807 err->value = error_value_count;
18081808 g->error_decls.append(node);
......@@ -2100,7 +2100,7 @@ static bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTable
21002100 if (expected_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {
21012101 return false;
21022102 }
2103 for (int i = 0; i < expected_type->data.fn.fn_type_id.param_count; i += 1) {
2103 for (size_t i = 0; i < expected_type->data.fn.fn_type_id.param_count; i += 1) {
21042104 // note it's reversed for parameters
21052105 FnTypeParamInfo *actual_param_info = &actual_type->data.fn.fn_type_id.param_info[i];
21062106 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
21212121}
21222122
21232123static TypeTableEntry *determine_peer_type_compatibility(CodeGen *g, AstNode *parent_source_node,
2124 AstNode **child_nodes, TypeTableEntry **child_types, int child_count)
2124 AstNode **child_nodes, TypeTableEntry **child_types, size_t child_count)
21252125{
21262126 TypeTableEntry *prev_type = child_types[0];
21272127 AstNode *prev_node = child_nodes[0];
21282128 if (prev_type->id == TypeTableEntryIdInvalid) {
21292129 return prev_type;
21302130 }
2131 for (int i = 1; i < child_count; i += 1) {
2131 for (size_t i = 1; i < child_count; i += 1) {
21322132 TypeTableEntry *cur_type = child_types[i];
21332133 AstNode *cur_node = child_nodes[i];
21342134 if (cur_type->id == TypeTableEntryIdInvalid) {
......@@ -2359,7 +2359,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, ImportTableEntry *
23592359
23602360static TypeTableEntry *resolve_peer_type_compatibility(CodeGen *g, ImportTableEntry *import,
23612361 BlockContext *block_context, AstNode *parent_source_node,
2362 AstNode **child_nodes, TypeTableEntry **child_types, int child_count)
2362 AstNode **child_nodes, TypeTableEntry **child_types, size_t child_count)
23632363{
23642364 assert(child_count > 0);
23652365
......@@ -2370,7 +2370,7 @@ static TypeTableEntry *resolve_peer_type_compatibility(CodeGen *g, ImportTableEn
23702370 return expected_type;
23712371 }
23722372
2373 for (int i = 0; i < child_count; i += 1) {
2373 for (size_t i = 0; i < child_count; i += 1) {
23742374 if (!child_nodes[i]) {
23752375 continue;
23762376 }
......@@ -2579,16 +2579,16 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
25792579 codegen->source_node = node;
25802580
25812581
2582 int expr_field_count = container_init_expr->entries.length;
2583 int actual_field_count = container_type->data.structure.src_field_count;
2582 size_t expr_field_count = container_init_expr->entries.length;
2583 size_t actual_field_count = container_type->data.structure.src_field_count;
25842584
25852585 AstNode *non_const_expr_culprit = nullptr;
25862586
2587 int *field_use_counts = allocate<int>(actual_field_count);
2587 size_t *field_use_counts = allocate<size_t>(actual_field_count);
25882588 ConstExprValue *const_val = &get_resolved_expr(node)->const_val;
25892589 const_val->ok = true;
25902590 const_val->data.x_struct.fields = allocate<ConstExprValue*>(actual_field_count);
2591 for (int i = 0; i < expr_field_count; i += 1) {
2591 for (size_t i = 0; i < expr_field_count; i += 1) {
25922592 AstNode *val_field_node = container_init_expr->entries.at(i);
25932593 assert(val_field_node->type == NodeTypeStructValueField);
25942594
......@@ -2608,7 +2608,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
26082608 return g->builtin_types.entry_invalid;
26092609 }
26102610
2611 int field_index = type_field->src_index;
2611 size_t field_index = type_field->src_index;
26122612 field_use_counts[field_index] += 1;
26132613 if (field_use_counts[field_index] > 1) {
26142614 add_node_error(g, val_field_node, buf_sprintf("duplicate field"));
......@@ -2641,7 +2641,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
26412641 }
26422642 }
26432643
2644 for (int i = 0; i < actual_field_count; i += 1) {
2644 for (size_t i = 0; i < actual_field_count; i += 1) {
26452645 if (field_use_counts[i] == 0) {
26462646 add_node_error(g, node,
26472647 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
26522652 container_type->data.structure.is_slice &&
26532653 kind == ContainerInitKindArray)
26542654 {
2655 int elem_count = container_init_expr->entries.length;
2655 size_t elem_count = container_init_expr->entries.length;
26562656
26572657 TypeTableEntry *pointer_type = container_type->data.structure.fields[0].type_entry;
26582658 assert(pointer_type->id == TypeTableEntryIdPointer);
......@@ -2662,7 +2662,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
26622662 const_val->ok = true;
26632663 const_val->data.x_array.fields = allocate<ConstExprValue*>(elem_count);
26642664
2665 for (int i = 0; i < elem_count; i += 1) {
2665 for (size_t i = 0; i < elem_count; i += 1) {
26662666 AstNode **elem_node = &container_init_expr->entries.at(i);
26672667 analyze_expression(g, import, context, child_type, *elem_node);
26682668
......@@ -2787,7 +2787,7 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i
27872787 AstNode *value_node;
27882788 if (container_init_node) {
27892789 assert(container_init_node->type == NodeTypeContainerInitExpr);
2790 int param_count = container_init_node->data.container_init_expr.entries.length;
2790 size_t param_count = container_init_node->data.container_init_expr.entries.length;
27912791 if (param_count > 1) {
27922792 AstNode *first_invalid_node = container_init_node->data.container_init_expr.entries.at(1);
27932793 add_node_error(g, first_executing_node(first_invalid_node),
......@@ -2849,7 +2849,7 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i
28492849 AstNode *decl_node = find_decl(namespace_import->block_context, field_name);
28502850 if (!decl_node) {
28512851 // we must now resolve all the use decls
2852 for (int i = 0; i < namespace_import->use_decls.length; i += 1) {
2852 for (size_t i = 0; i < namespace_import->use_decls.length; i += 1) {
28532853 AstNode *use_decl_node = namespace_import->use_decls.at(i);
28542854 if (!get_resolved_expr(use_decl_node->data.use.expr)->type_entry) {
28552855 preview_use_decl(g, use_decl_node);
......@@ -3051,13 +3051,13 @@ static TypeTableEntry *resolve_expr_const_val_as_c_string_lit(CodeGen *g, AstNod
30513051 Expr *expr = get_resolved_expr(node);
30523052 expr->const_val.ok = true;
30533053
3054 int len_with_null = buf_len(str) + 1;
3054 size_t len_with_null = buf_len(str) + 1;
30553055 expr->const_val.data.x_ptr.ptr = allocate<ConstExprValue*>(len_with_null);
30563056 expr->const_val.data.x_ptr.len = len_with_null;
30573057 expr->const_val.data.x_ptr.is_c_str = true;
30583058
30593059 ConstExprValue *all_chars = allocate<ConstExprValue>(len_with_null);
3060 for (int i = 0; i < buf_len(str); i += 1) {
3060 for (size_t i = 0; i < buf_len(str); i += 1) {
30613061 ConstExprValue *this_char = &all_chars[i];
30623062 this_char->ok = true;
30633063 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
30783078 expr->const_val.data.x_array.fields = allocate<ConstExprValue*>(buf_len(str));
30793079
30803080 ConstExprValue *all_chars = allocate<ConstExprValue>(buf_len(str));
3081 for (int i = 0; i < buf_len(str); i += 1) {
3081 for (size_t i = 0; i < buf_len(str); i += 1) {
30823082 ConstExprValue *this_char = &all_chars[i];
30833083 this_char->ok = true;
30843084 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
44374437 assert(node->type == NodeTypeFnCallExpr);
44384438
44394439 AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr;
4440 int actual_param_count = node->data.fn_call_expr.params.length;
4440 size_t actual_param_count = node->data.fn_call_expr.params.length;
44414441
44424442 if (actual_param_count != 1) {
44434443 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
47994799
48004800 if (errors.length > 0) {
48014801 ErrorMsg *parent_err_msg = add_node_error(g, node, buf_sprintf("C import failed"));
4802 for (int i = 0; i < errors.length; i += 1) {
4802 for (size_t i = 0; i < errors.length; i += 1) {
48034803 ErrorMsg *err_msg = errors.at(i);
48044804 err_msg_add_note(parent_err_msg, err_msg);
48054805 }
......@@ -5113,13 +5113,13 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
51135113 }
51145114
51155115 BuiltinFnEntry *builtin_fn = entry->value;
5116 int actual_param_count = node->data.fn_call_expr.params.length;
5116 size_t actual_param_count = node->data.fn_call_expr.params.length;
51175117
51185118 node->data.fn_call_expr.builtin_fn = builtin_fn;
51195119
51205120 if (builtin_fn->param_count != actual_param_count) {
51215121 add_node_error(g, node,
5122 buf_sprintf("expected %d arguments, got %d",
5122 buf_sprintf("expected %zu arguments, got %zu",
51235123 builtin_fn->param_count, actual_param_count));
51245124 return g->builtin_types.entry_invalid;
51255125 }
......@@ -5479,11 +5479,11 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
54795479 fn_table_entry->proto_node->data.fn_proto.generic_proto_node : nullptr;
54805480
54815481 // count parameters
5482 int struct_node_1_or_0 = struct_node ? 1 : 0;
5483 int src_param_count = fn_type->data.fn.fn_type_id.param_count +
5482 size_t struct_node_1_or_0 = struct_node ? 1 : 0;
5483 size_t src_param_count = fn_type->data.fn.fn_type_id.param_count +
54845484 (generic_proto_node ? generic_proto_node->data.fn_proto.inline_arg_count : 0);
5485 int call_param_count = node->data.fn_call_expr.params.length;
5486 int expect_arg_count = src_param_count - struct_node_1_or_0;
5485 size_t call_param_count = node->data.fn_call_expr.params.length;
5486 size_t expect_arg_count = src_param_count - struct_node_1_or_0;
54875487
54885488 bool ok_invocation = true;
54895489
......@@ -5491,12 +5491,12 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
54915491 if (call_param_count < expect_arg_count) {
54925492 ok_invocation = false;
54935493 add_node_error(g, node,
5494 buf_sprintf("expected at least %d arguments, got %d", src_param_count, call_param_count));
5494 buf_sprintf("expected at least %zu arguments, got %zu", src_param_count, call_param_count));
54955495 }
54965496 } else if (expect_arg_count != call_param_count) {
54975497 ok_invocation = false;
54985498 add_node_error(g, node,
5499 buf_sprintf("expected %d arguments, got %d", expect_arg_count, call_param_count));
5499 buf_sprintf("expected %zu arguments, got %zu", expect_arg_count, call_param_count));
55005500 }
55015501
55025502 bool all_args_const_expr = true;
......@@ -5510,9 +5510,9 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
55105510
55115511 // analyze each parameter. in the case of a method, we already analyzed the
55125512 // first parameter in order to figure out which struct we were calling a method on.
5513 int next_type_i = struct_node_1_or_0;
5514 for (int call_i = 0; call_i < call_param_count; call_i += 1) {
5515 int proto_i = call_i + struct_node_1_or_0;
5513 size_t next_type_i = struct_node_1_or_0;
5514 for (size_t call_i = 0; call_i < call_param_count; call_i += 1) {
5515 size_t proto_i = call_i + struct_node_1_or_0;
55165516 AstNode **param_node = &node->data.fn_call_expr.params.at(call_i);
55175517 // determine the expected type for each parameter
55185518 TypeTableEntry *expected_param_type = nullptr;
......@@ -5592,30 +5592,30 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE
55925592 AstNode *decl_node = fn_table_entry->proto_node;
55935593
55945594 // count parameters
5595 int struct_node_1_or_0 = (struct_node ? 1 : 0);
5596 int src_param_count = decl_node->data.fn_proto.params.length;
5597 int call_param_count = call_node->data.fn_call_expr.params.length;
5595 size_t struct_node_1_or_0 = (struct_node ? 1 : 0);
5596 size_t src_param_count = decl_node->data.fn_proto.params.length;
5597 size_t call_param_count = call_node->data.fn_call_expr.params.length;
55985598
55995599 if (src_param_count != call_param_count + struct_node_1_or_0) {
56005600 add_node_error(g, call_node,
5601 buf_sprintf("expected %d arguments, got %d", src_param_count - struct_node_1_or_0, call_param_count));
5601 buf_sprintf("expected %zu arguments, got %zu", src_param_count - struct_node_1_or_0, call_param_count));
56025602 return g->builtin_types.entry_invalid;
56035603 }
56045604
5605 int inline_or_var_type_arg_count = decl_node->data.fn_proto.inline_or_var_type_arg_count;
5605 size_t inline_or_var_type_arg_count = decl_node->data.fn_proto.inline_or_var_type_arg_count;
56065606 assert(inline_or_var_type_arg_count > 0);
56075607
56085608 BlockContext *child_context = decl_node->owner->block_context;
5609 int next_generic_param_index = 0;
5609 size_t next_generic_param_index = 0;
56105610
56115611 GenericFnTypeId *generic_fn_type_id = allocate<GenericFnTypeId>(1);
56125612 generic_fn_type_id->decl_node = decl_node;
56135613 generic_fn_type_id->generic_param_count = inline_or_var_type_arg_count;
56145614 generic_fn_type_id->generic_params = allocate<GenericParamValue>(inline_or_var_type_arg_count);
56155615
5616 int next_impl_i = 0;
5617 for (int call_i = 0; call_i < call_param_count; call_i += 1) {
5618 int proto_i = call_i + struct_node_1_or_0;
5616 size_t next_impl_i = 0;
5617 for (size_t call_i = 0; call_i < call_param_count; call_i += 1) {
5618 size_t proto_i = call_i + struct_node_1_or_0;
56195619 AstNode *generic_param_decl_node = decl_node->data.fn_proto.params.at(proto_i);
56205620 assert(generic_param_decl_node->type == NodeTypeParamDecl);
56215621
......@@ -5688,10 +5688,10 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE
56885688 impl_decl_node->data.fn_proto.generic_proto_node = decl_node;
56895689
56905690 // replace var arg types with actual types
5691 for (int generic_arg_i = 0; generic_arg_i < inline_or_var_type_arg_count; generic_arg_i += 1) {
5691 for (size_t generic_arg_i = 0; generic_arg_i < inline_or_var_type_arg_count; generic_arg_i += 1) {
56925692 GenericParamValue *generic_param_value = &generic_fn_type_id->generic_params[generic_arg_i];
56935693 if (!generic_param_value->node) {
5694 int impl_i = generic_param_value->impl_index;
5694 size_t impl_i = generic_param_value->impl_index;
56955695 AstNode *impl_param_decl_node = impl_decl_node->data.fn_proto.params.at(impl_i);
56965696 assert(impl_param_decl_node->type == NodeTypeParamDecl);
56975697
......@@ -5721,12 +5721,12 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
57215721 assert(decl_node->type == NodeTypeContainerDecl);
57225722 ZigList<AstNode *> *generic_params = &decl_node->data.struct_decl.generic_params;
57235723
5724 int expected_param_count = generic_params->length;
5725 int actual_param_count = node->data.fn_call_expr.params.length;
5724 size_t expected_param_count = generic_params->length;
5725 size_t actual_param_count = node->data.fn_call_expr.params.length;
57265726
57275727 if (actual_param_count != expected_param_count) {
57285728 add_node_error(g, first_executing_node(node),
5729 buf_sprintf("expected %d arguments, got %d", expected_param_count, actual_param_count));
5729 buf_sprintf("expected %zu arguments, got %zu", expected_param_count, actual_param_count));
57305730 return g->builtin_types.entry_invalid;
57315731 }
57325732
......@@ -5736,7 +5736,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
57365736 generic_fn_type_id->generic_params = allocate<GenericParamValue>(actual_param_count);
57375737
57385738 BlockContext *child_context = decl_node->owner->block_context;
5739 for (int i = 0; i < actual_param_count; i += 1) {
5739 for (size_t i = 0; i < actual_param_count; i += 1) {
57405740 AstNode *generic_param_decl_node = generic_params->at(i);
57415741 assert(generic_param_decl_node->type == NodeTypeParamDecl);
57425742
......@@ -6104,7 +6104,7 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
61046104 ConstExprValue *const_val = &get_resolved_expr(node)->const_val;
61056105
61066106
6107 int prong_count = node->data.switch_expr.prongs.length;
6107 size_t prong_count = node->data.switch_expr.prongs.length;
61086108 AstNode **peer_nodes = allocate<AstNode*>(prong_count);
61096109 TypeTableEntry **peer_types = allocate<TypeTableEntry*>(prong_count);
61106110
......@@ -6118,18 +6118,18 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
61186118 }
61196119
61206120
6121 int *field_use_counts = nullptr;
6121 size_t *field_use_counts = nullptr;
61226122 HashMap<int, AstNode *, int_hash, int_eq> err_use_nodes = {};
61236123 if (expr_type->id == TypeTableEntryIdEnum) {
6124 field_use_counts = allocate<int>(expr_type->data.enumeration.field_count);
6124 field_use_counts = allocate<size_t>(expr_type->data.enumeration.field_count);
61256125 } else if (expr_type->id == TypeTableEntryIdErrorUnion) {
61266126 err_use_nodes.init(10);
61276127 }
61286128
6129 int *const_chosen_prong_index = &node->data.switch_expr.const_chosen_prong_index;
6130 *const_chosen_prong_index = -1;
6129 size_t *const_chosen_prong_index = &node->data.switch_expr.const_chosen_prong_index;
6130 *const_chosen_prong_index = SIZE_MAX;
61316131 AstNode *else_prong = nullptr;
6132 for (int prong_i = 0; prong_i < prong_count; prong_i += 1) {
6132 for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {
61336133 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);
61346134
61356135 TypeTableEntry *var_type;
......@@ -6143,14 +6143,14 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
61436143 }
61446144 var_type = expr_type;
61456145 var_is_target_expr = true;
6146 if (*const_chosen_prong_index == -1 && expr_val->ok) {
6146 if (*const_chosen_prong_index == SIZE_MAX && expr_val->ok) {
61476147 *const_chosen_prong_index = prong_i;
61486148 }
61496149 } else {
61506150 bool all_agree_on_var_type = true;
61516151 var_type = nullptr;
61526152
6153 for (int item_i = 0; item_i < prong_node->data.switch_prong.items.length; item_i += 1) {
6153 for (size_t item_i = 0; item_i < prong_node->data.switch_prong.items.length; item_i += 1) {
61546154 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
61556155 if (item_node->type == NodeTypeSwitchRange) {
61566156 zig_panic("TODO range in switch statement");
......@@ -6274,7 +6274,7 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
62746274 }
62756275 }
62766276
6277 for (int prong_i = 0; prong_i < prong_count; prong_i += 1) {
6277 for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {
62786278 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);
62796279 BlockContext *child_context = prong_node->data.switch_prong.block_context;
62806280 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,
63126312 peer_nodes, peer_types, prong_count);
63136313
63146314 if (expr_val->ok) {
6315 assert(*const_chosen_prong_index != -1);
6315 assert(*const_chosen_prong_index != SIZE_MAX);
63166316
63176317 *const_val = get_resolved_expr(peer_nodes[*const_chosen_prong_index])->const_val;
63186318 // 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,
64606460 node->data.block.child_block = child_context;
64616461 TypeTableEntry *return_type = g->builtin_types.entry_void;
64626462
6463 for (int i = 0; i < node->data.block.statements.length; i += 1) {
6463 for (size_t i = 0; i < node->data.block.statements.length; i += 1) {
64646464 AstNode *child = node->data.block.statements.at(i);
64656465 if (child->type == NodeTypeLabel) {
64666466 FnTableEntry *fn_table_entry = child_context->fn_entry;
......@@ -6524,7 +6524,7 @@ static TypeTableEntry *analyze_asm_expr(CodeGen *g, ImportTableEntry *import, Bl
65246524
65256525 node->data.asm_expr.return_count = 0;
65266526 TypeTableEntry *return_type = g->builtin_types.entry_void;
6527 for (int i = 0; i < node->data.asm_expr.output_list.length; i += 1) {
6527 for (size_t i = 0; i < node->data.asm_expr.output_list.length; i += 1) {
65286528 AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);
65296529 if (asm_output->return_type) {
65306530 node->data.asm_expr.return_count += 1;
......@@ -6547,7 +6547,7 @@ static TypeTableEntry *analyze_asm_expr(CodeGen *g, ImportTableEntry *import, Bl
65476547 }
65486548 }
65496549 }
6550 for (int i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
6550 for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
65516551 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
65526552 analyze_expression(g, import, context, nullptr, asm_input->expr);
65536553 }
......@@ -6757,7 +6757,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
67576757
67586758 TypeTableEntry *fn_type = fn_table_entry->type_entry;
67596759 AstNodeFnProto *fn_proto = &fn_proto_node->data.fn_proto;
6760 for (int i = 0; i < fn_proto->params.length; i += 1) {
6760 for (size_t i = 0; i < fn_proto->params.length; i += 1) {
67616761 AstNode *param_decl_node = fn_proto->params.at(i);
67626762 assert(param_decl_node->type == NodeTypeParamDecl);
67636763
......@@ -6797,13 +6797,13 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
67976797
67986798 node->data.fn_def.implicit_return_type = block_return_type;
67996799
6800 for (int i = 0; i < fn_table_entry->goto_list.length; i += 1) {
6800 for (size_t i = 0; i < fn_table_entry->goto_list.length; i += 1) {
68016801 AstNode *goto_node = fn_table_entry->goto_list.at(i);
68026802 assert(goto_node->type == NodeTypeGoto);
68036803 analyze_goto_pass2(g, import, goto_node);
68046804 }
68056805
6806 for (int i = 0; i < fn_table_entry->all_labels.length; i += 1) {
6806 for (size_t i = 0; i < fn_table_entry->all_labels.length; i += 1) {
68076807 LabelTableEntry *label = fn_table_entry->all_labels.at(i);
68086808 if (!label->used) {
68096809 add_node_error(g, label->decl_node,
......@@ -6846,8 +6846,8 @@ static void add_top_level_decl(CodeGen *g, ImportTableEntry *import, BlockContex
68466846static void count_inline_and_var_args(AstNode *proto_node) {
68476847 assert(proto_node->type == NodeTypeFnProto);
68486848
6849 int *inline_arg_count = &proto_node->data.fn_proto.inline_arg_count;
6850 int *inline_or_var_type_arg_count = &proto_node->data.fn_proto.inline_or_var_type_arg_count;
6849 size_t *inline_arg_count = &proto_node->data.fn_proto.inline_arg_count;
6850 size_t *inline_or_var_type_arg_count = &proto_node->data.fn_proto.inline_or_var_type_arg_count;
68516851
68526852 *inline_arg_count = 0;
68536853 *inline_or_var_type_arg_count = 0;
......@@ -6855,7 +6855,7 @@ static void count_inline_and_var_args(AstNode *proto_node) {
68556855 // TODO run these nodes through the type analysis system rather than looking for
68566856 // specialized ast nodes. this would get fooled by `{var}` instead of `var` which
68576857 // is supposed to be equivalent
6858 for (int i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
6858 for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
68596859 AstNode *param_node = proto_node->data.fn_proto.params.at(i);
68606860 assert(param_node->type == NodeTypeParamDecl);
68616861 if (param_node->data.param_decl.is_inline) {
......@@ -6870,7 +6870,7 @@ static void count_inline_and_var_args(AstNode *proto_node) {
68706870static void scan_decls(CodeGen *g, ImportTableEntry *import, BlockContext *context, AstNode *node) {
68716871 switch (node->type) {
68726872 case NodeTypeRoot:
6873 for (int i = 0; i < import->root->data.root.top_level_decls.length; i += 1) {
6873 for (size_t i = 0; i < import->root->data.root.top_level_decls.length; i += 1) {
68746874 AstNode *child = import->root->data.root.top_level_decls.at(i);
68756875 scan_decls(g, import, context, child);
68766876 }
......@@ -6992,7 +6992,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
69926992 tld->import->any_imports_failed = true;
69936993 }
69946994
6995 for (int i = 0; i < target_import->root->data.root.top_level_decls.length; i += 1) {
6995 for (size_t i = 0; i < target_import->root->data.root.top_level_decls.length; i += 1) {
69966996 AstNode *decl_node = target_import->root->data.root.top_level_decls.at(i);
69976997 if (decl_node->type == NodeTypeFnDef) {
69986998 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 *
70187018 }
70197019 }
70207020
7021 for (int i = 0; i < target_import->use_decls.length; i += 1) {
7021 for (size_t i = 0; i < target_import->use_decls.length; i += 1) {
70227022 AstNode *use_decl_node = target_import->use_decls.at(i);
70237023 TopLevelDecl *target_tld = get_as_top_level_decl(use_decl_node);
70247024 if (target_tld->visib_mod != VisibModPrivate) {
......@@ -7104,7 +7104,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
71047104
71057105
71067106 assert(import_entry->root->type == NodeTypeRoot);
7107 for (int decl_i = 0; decl_i < import_entry->root->data.root.top_level_decls.length; decl_i += 1) {
7107 for (size_t decl_i = 0; decl_i < import_entry->root->data.root.top_level_decls.length; decl_i += 1) {
71087108 AstNode *top_level_decl = import_entry->root->data.root.top_level_decls.at(decl_i);
71097109
71107110 if (top_level_decl->type == NodeTypeFnDef) {
......@@ -7135,7 +7135,7 @@ void semantic_analyze(CodeGen *g) {
71357135 preview_use_decl(g, use_decl_node);
71367136 }
71377137
7138 for (int i = 0; i < g->use_queue.length; i += 1) {
7138 for (size_t i = 0; i < g->use_queue.length; i += 1) {
71397139 AstNode *use_decl_node = g->use_queue.at(i);
71407140 resolve_use_decl(g, use_decl_node);
71417141 }
......@@ -7146,7 +7146,7 @@ void semantic_analyze(CodeGen *g) {
71467146 resolve_top_level_decl(g, decl_node, pointer_only);
71477147 }
71487148
7149 for (int i = 0; i < g->fn_defs.length; i += 1) {
7149 for (size_t i = 0; i < g->fn_defs.length; i += 1) {
71507150 FnTableEntry *fn_entry = g->fn_defs.at(i);
71517151 if (fn_entry->anal_state == FnAnalStateReady) {
71527152 analyze_fn_body(g, fn_entry);
......@@ -7321,8 +7321,8 @@ bool is_node_void_expr(AstNode *node) {
73217321 return false;
73227322}
73237323
7324TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits) {
7325 int index;
7324TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, size_t size_in_bits) {
7325 size_t index;
73267326 if (size_in_bits == 8) {
73277327 index = 0;
73287328 } else if (size_in_bits == 16) {
......@@ -7337,7 +7337,7 @@ TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits)
73377337 return &g->builtin_types.entry_int[is_signed ? 0 : 1][index];
73387338}
73397339
7340TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, int size_in_bits) {
7340TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, size_t size_in_bits) {
73417341 return *get_int_type_ptr(g, is_signed, size_in_bits);
73427342}
73437343
......@@ -7417,7 +7417,7 @@ uint32_t fn_type_id_hash(FnTypeId *id) {
74177417 result += id->is_cold ? 3605523458 : 0;
74187418 result += id->is_var_args ? 1931444534 : 0;
74197419 result += hash_ptr(id->return_type);
7420 for (int i = 0; i < id->param_count; i += 1) {
7420 for (size_t i = 0; i < id->param_count; i += 1) {
74217421 FnTypeParamInfo *info = &id->param_info[i];
74227422 result += info->is_noalias ? 892356923 : 0;
74237423 result += hash_ptr(info->type);
......@@ -7435,7 +7435,7 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {
74357435 {
74367436 return false;
74377437 }
7438 for (int i = 0; i < a->param_count; i += 1) {
7438 for (size_t i = 0; i < a->param_count; i += 1) {
74397439 FnTypeParamInfo *a_param_info = &a->param_info[i];
74407440 FnTypeParamInfo *b_param_info = &b->param_info[i];
74417441
......@@ -7511,7 +7511,7 @@ static uint32_t hash_const_val(TypeTableEntry *type, ConstExprValue *const_val)
75117511uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {
75127512 uint32_t result = 0;
75137513 result += hash_ptr(id->decl_node);
7514 for (int i = 0; i < id->generic_param_count; i += 1) {
7514 for (size_t i = 0; i < id->generic_param_count; i += 1) {
75157515 GenericParamValue *generic_param = &id->generic_params[i];
75167516 if (generic_param->node) {
75177517 ConstExprValue *const_val = &get_resolved_expr(generic_param->node)->const_val;
......@@ -7526,7 +7526,7 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {
75267526bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
75277527 if (a->decl_node != b->decl_node) return false;
75287528 assert(a->generic_param_count == b->generic_param_count);
7529 for (int i = 0; i < a->generic_param_count; i += 1) {
7529 for (size_t i = 0; i < a->generic_param_count; i += 1) {
75307530 GenericParamValue *a_val = &a->generic_params[i];
75317531 GenericParamValue *b_val = &b->generic_params[i];
75327532 if (a_val->type != b_val->type) return false;
src/analyze.hpp+2-2
......@@ -19,8 +19,8 @@ BlockContext *new_block_context(AstNode *node, BlockContext *parent);
1919Expr *get_resolved_expr(AstNode *node);
2020bool is_node_void_expr(AstNode *node);
2121uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
22TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits);
23TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, int size_in_bits);
22TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, size_t size_in_bits);
23TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, size_t size_in_bits);
2424TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
2525TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);
2626TypeTableEntry *get_typedecl_type(CodeGen *g, const char *name, TypeTableEntry *child_type);
src/ast_render.cpp+7-7
......@@ -292,7 +292,7 @@ static bool is_printable(uint8_t c) {
292292
293293static void string_literal_escape(Buf *source, Buf *dest) {
294294 buf_resize(dest, 0);
295 for (int i = 0; i < buf_len(source); i += 1) {
295 for (size_t i = 0; i < buf_len(source); i += 1) {
296296 uint8_t c = *((uint8_t*)buf_ptr(source) + i);
297297 if (is_printable(c)) {
298298 buf_append_char(dest, c);
......@@ -330,7 +330,7 @@ static bool is_valid_bare_symbol(Buf *symbol) {
330330 if (!is_alpha_under(first_char)) {
331331 return false;
332332 }
333 for (int i = 1; i < buf_len(symbol); i += 1) {
333 for (size_t i = 1; i < buf_len(symbol); i += 1) {
334334 uint8_t c = *((uint8_t*)buf_ptr(symbol) + i);
335335 if (!is_alpha_under(c) && !is_digit(c)) {
336336 return false;
......@@ -358,7 +358,7 @@ static void render_node(AstRender *ar, AstNode *node) {
358358
359359 switch (node->type) {
360360 case NodeTypeRoot:
361 for (int i = 0; i < node->data.root.top_level_decls.length; i += 1) {
361 for (size_t i = 0; i < node->data.root.top_level_decls.length; i += 1) {
362362 AstNode *child = node->data.root.top_level_decls.at(i);
363363 print_indent(ar);
364364 render_node(ar, child);
......@@ -417,7 +417,7 @@ static void render_node(AstRender *ar, AstNode *node) {
417417 ZigList<AstNode *> *directives =
418418 node->data.fn_def.fn_proto->data.fn_proto.top_level_decl.directives;
419419 if (directives) {
420 for (int i = 0; i < directives->length; i += 1) {
420 for (size_t i = 0; i < directives->length; i += 1) {
421421 render_node(ar, directives->at(i));
422422 }
423423 }
......@@ -433,7 +433,7 @@ static void render_node(AstRender *ar, AstNode *node) {
433433 case NodeTypeBlock:
434434 fprintf(ar->f, "{\n");
435435 ar->indent += ar->indent_size;
436 for (int i = 0; i < node->data.block.statements.length; i += 1) {
436 for (size_t i = 0; i < node->data.block.statements.length; i += 1) {
437437 AstNode *statement = node->data.block.statements.at(i);
438438 print_indent(ar);
439439 render_node(ar, statement);
......@@ -561,7 +561,7 @@ static void render_node(AstRender *ar, AstNode *node) {
561561 fprintf(ar->f, ")");
562562 }
563563 fprintf(ar->f, "(");
564 for (int i = 0; i < node->data.fn_call_expr.params.length; i += 1) {
564 for (size_t i = 0; i < node->data.fn_call_expr.params.length; i += 1) {
565565 AstNode *param = node->data.fn_call_expr.params.at(i);
566566 if (i != 0) {
567567 fprintf(ar->f, ", ");
......@@ -628,7 +628,7 @@ static void render_node(AstRender *ar, AstNode *node) {
628628 const char *container_str = container_string(node->data.struct_decl.kind);
629629 fprintf(ar->f, "%s%s %s {\n", pub_str, container_str, struct_name);
630630 ar->indent += ar->indent_size;
631 for (int field_i = 0; field_i < node->data.struct_decl.fields.length; field_i += 1) {
631 for (size_t field_i = 0; field_i < node->data.struct_decl.fields.length; field_i += 1) {
632632 AstNode *field_node = node->data.struct_decl.fields.at(field_i);
633633 assert(field_node->type == NodeTypeStructField);
634634 print_indent(ar);
src/bignum.cpp+1-1
......@@ -43,7 +43,7 @@ void bignum_init_signed(BigNum *dest, int64_t x) {
4343}
4444
4545void bignum_init_bignum(BigNum *dest, BigNum *src) {
46 memcpy(dest, src, sizeof(BigNum));
46 safe_memcpy(dest, src, 1);
4747}
4848
4949bool bignum_fits_in_bits(BigNum *bn, int bit_count, bool is_signed) {
src/buffer.cpp+2-2
......@@ -41,7 +41,7 @@ void buf_appendf(Buf *buf, const char *format, ...) {
4141
4242 size_t required_size = len1 + 1;
4343
44 int orig_len = buf_len(buf);
44 size_t orig_len = buf_len(buf);
4545
4646 buf_resize(buf, orig_len + len1);
4747
......@@ -62,7 +62,7 @@ uint32_t buf_hash(Buf *buf) {
6262 assert(buf->list.length);
6363 // FNV 32-bit hash
6464 uint32_t h = 2166136261;
65 for (int i = 0; i < buf_len(buf); i += 1) {
65 for (size_t i = 0; i < buf_len(buf); i += 1) {
6666 h = h ^ ((uint8_t)buf->list.at(i));
6767 h = h * 16777619;
6868 }
src/buffer.hpp+23-25
......@@ -27,7 +27,7 @@ Buf *buf_sprintf(const char *format, ...)
2727 __attribute__ ((format (printf, 1, 2)));
2828Buf *buf_vprintf(const char *format, va_list ap);
2929
30static inline int buf_len(Buf *buf) {
30static inline size_t buf_len(Buf *buf) {
3131 assert(buf->list.length);
3232 return buf->list.length - 1;
3333}
......@@ -37,31 +37,29 @@ static inline char *buf_ptr(Buf *buf) {
3737 return buf->list.items;
3838}
3939
40static inline void buf_resize(Buf *buf, int new_len) {
40static inline void buf_resize(Buf *buf, size_t new_len) {
4141 buf->list.resize(new_len + 1);
4242 buf->list.at(buf_len(buf)) = 0;
4343}
4444
45static inline Buf *buf_alloc(void) {
45static inline Buf *buf_alloc_fixed(size_t size) {
4646 Buf *buf = allocate<Buf>(1);
47 buf_resize(buf, 0);
47 buf_resize(buf, size);
4848 return buf;
4949}
5050
51static inline Buf *buf_alloc_fixed(int size) {
52 Buf *buf = allocate<Buf>(1);
53 buf_resize(buf, size);
54 return buf;
51static inline Buf *buf_alloc(void) {
52 return buf_alloc_fixed(0);
5553}
5654
5755static inline void buf_deinit(Buf *buf) {
5856 buf->list.deinit();
5957}
6058
61static inline void buf_init_from_mem(Buf *buf, const char *ptr, int len) {
62 assert(len >= 0);
59static inline void buf_init_from_mem(Buf *buf, const char *ptr, size_t len) {
60 assert(len != SIZE_MAX);
6361 buf->list.resize(len + 1);
64 memcpy(buf_ptr(buf), ptr, len);
62 safe_memcpy(buf_ptr(buf), ptr, len);
6563 buf->list.at(buf_len(buf)) = 0;
6664}
6765
......@@ -73,8 +71,8 @@ static inline void buf_init_from_buf(Buf *buf, Buf *other) {
7371 buf_init_from_mem(buf, buf_ptr(other), buf_len(other));
7472}
7573
76static inline Buf *buf_create_from_mem(const char *ptr, int len) {
77 assert(len >= 0);
74static inline Buf *buf_create_from_mem(const char *ptr, size_t len) {
75 assert(len != SIZE_MAX);
7876 Buf *buf = allocate<Buf>(1);
7977 buf_init_from_mem(buf, ptr, len);
8078 return buf;
......@@ -88,25 +86,25 @@ static inline Buf *buf_create_from_buf(Buf *buf) {
8886 return buf_create_from_mem(buf_ptr(buf), buf_len(buf));
8987}
9088
91static inline Buf *buf_slice(Buf *in_buf, int start, int end) {
89static inline Buf *buf_slice(Buf *in_buf, size_t start, size_t end) {
9290 assert(in_buf->list.length);
93 assert(start >= 0);
94 assert(end >= 0);
91 assert(start != SIZE_MAX);
92 assert(end != SIZE_MAX);
9593 assert(start < buf_len(in_buf));
9694 assert(end <= buf_len(in_buf));
9795 Buf *out_buf = allocate<Buf>(1);
9896 out_buf->list.resize(end - start + 1);
99 memcpy(buf_ptr(out_buf), buf_ptr(in_buf) + start, end - start);
97 safe_memcpy(buf_ptr(out_buf), buf_ptr(in_buf) + start, end - start);
10098 out_buf->list.at(buf_len(out_buf)) = 0;
10199 return out_buf;
102100}
103101
104static inline void buf_append_mem(Buf *buf, const char *mem, int mem_len) {
102static inline void buf_append_mem(Buf *buf, const char *mem, size_t mem_len) {
105103 assert(buf->list.length);
106 assert(mem_len >= 0);
107 int old_len = buf_len(buf);
104 assert(mem_len != SIZE_MAX);
105 size_t old_len = buf_len(buf);
108106 buf_resize(buf, old_len + mem_len);
109 memcpy(buf_ptr(buf) + old_len, mem, mem_len);
107 safe_memcpy(buf_ptr(buf) + old_len, mem, mem_len);
110108 buf->list.at(buf_len(buf)) = 0;
111109}
112110
......@@ -128,7 +126,7 @@ static inline void buf_append_char(Buf *buf, uint8_t c) {
128126void buf_appendf(Buf *buf, const char *format, ...)
129127 __attribute__ ((format (printf, 2, 3)));
130128
131static inline bool buf_eql_mem(Buf *buf, const char *mem, int mem_len) {
129static inline bool buf_eql_mem(Buf *buf, const char *mem, size_t mem_len) {
132130 assert(buf->list.length);
133131 if (buf_len(buf) != mem_len)
134132 return false;
......@@ -140,7 +138,7 @@ static inline bool buf_eql_str(Buf *buf, const char *str) {
140138 return buf_eql_mem(buf, str, strlen(str));
141139}
142140
143static inline bool buf_starts_with_mem(Buf *buf, const char *mem, int mem_len) {
141static inline bool buf_starts_with_mem(Buf *buf, const char *mem, size_t mem_len) {
144142 if (buf_len(buf) < mem_len) {
145143 return false;
146144 }
......@@ -155,7 +153,7 @@ static inline bool buf_starts_with_str(Buf *buf, const char *str) {
155153 return buf_starts_with_mem(buf, str, strlen(str));
156154}
157155
158static inline bool buf_ends_with_mem(Buf *buf, const char *mem, int mem_len) {
156static inline bool buf_ends_with_mem(Buf *buf, const char *mem, size_t mem_len) {
159157 if (buf_len(buf) < mem_len) {
160158 return false;
161159 }
......@@ -170,7 +168,7 @@ bool buf_eql_buf(Buf *buf, Buf *other);
170168uint32_t buf_hash(Buf *buf);
171169
172170static inline void buf_upcase(Buf *buf) {
173 for (int i = 0; i < buf_len(buf); i += 1) {
171 for (size_t i = 0; i < buf_len(buf); i += 1) {
174172 buf_ptr(buf)[i] = toupper(buf_ptr(buf)[i]);
175173 }
176174}
src/codegen.cpp+109-108
......@@ -111,7 +111,7 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) {
111111 return g;
112112}
113113
114void codegen_set_clang_argv(CodeGen *g, const char **args, int len) {
114void codegen_set_clang_argv(CodeGen *g, const char **args, size_t len) {
115115 g->clang_argv = args;
116116 g->clang_argv_len = len;
117117}
......@@ -166,6 +166,7 @@ void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) {
166166
167167void codegen_set_zig_std_dir(CodeGen *g, Buf *zig_std_dir) {
168168 g->zig_std_dir = zig_std_dir;
169
169170 g->std_package->root_src_dir = *zig_std_dir;
170171}
171172
......@@ -261,7 +262,7 @@ enum AddSubMul {
261262 AddSubMulMul = 2,
262263};
263264
264static int bits_index(int size_in_bits) {
265static size_t bits_index(size_t size_in_bits) {
265266 switch (size_in_bits) {
266267 case 8:
267268 return 0;
......@@ -281,7 +282,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_
281282{
282283 assert(type_entry->id == TypeTableEntryIdInt);
283284 const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;
284 Buf *llvm_name = buf_sprintf("llvm.%s.with.overflow.i%d", signed_str, type_entry->data.integral.bit_count);
285 Buf *llvm_name = buf_sprintf("llvm.%s.with.overflow.i%zu", signed_str, type_entry->data.integral.bit_count);
285286
286287 LLVMTypeRef return_elem_types[] = {
287288 type_entry->type_ref,
......@@ -301,9 +302,9 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_
301302static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry, AddSubMul add_sub_mul) {
302303 assert(type_entry->id == TypeTableEntryIdInt);
303304 // [0-signed,1-unsigned][0-add,1-sub,2-mul][0-8,1-16,2-32,3-64]
304 int index0 = type_entry->data.integral.is_signed ? 0 : 1;
305 int index1 = add_sub_mul;
306 int index2 = bits_index(type_entry->data.integral.bit_count);
305 size_t index0 = type_entry->data.integral.is_signed ? 0 : 1;
306 size_t index1 = add_sub_mul;
307 size_t index2 = bits_index(type_entry->data.integral.bit_count);
307308 LLVMValueRef *fn = &g->int_overflow_fns[index0][index1][index2];
308309 if (*fn) {
309310 return *fn;
......@@ -325,12 +326,12 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
325326
326327static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, BuiltinFnId fn_id) {
327328 // [0-ctz,1-clz][0-8,1-16,2-32,3-64]
328 int index0 = (fn_id == BuiltinFnIdCtz) ? 0 : 1;
329 int index1 = bits_index(int_type->data.integral.bit_count);
329 size_t index0 = (fn_id == BuiltinFnIdCtz) ? 0 : 1;
330 size_t index1 = bits_index(int_type->data.integral.bit_count);
330331 LLVMValueRef *fn = &g->int_builtin_fns[index0][index1];
331332 if (!*fn) {
332333 const char *fn_name = (fn_id == BuiltinFnIdCtz) ? "cttz" : "ctlz";
333 Buf *llvm_name = buf_sprintf("llvm.%s.i%d", fn_name, int_type->data.integral.bit_count);
334 Buf *llvm_name = buf_sprintf("llvm.%s.i%zu", fn_name, int_type->data.integral.bit_count);
334335 LLVMTypeRef param_types[] = {
335336 int_type->type_ref,
336337 LLVMInt1Type(),
......@@ -516,7 +517,7 @@ static LLVMValueRef gen_unreachable(CodeGen *g, AstNode *node) {
516517static LLVMValueRef gen_shl_with_overflow(CodeGen *g, AstNode *node) {
517518 assert(node->type == NodeTypeFnCallExpr);
518519
519 int fn_call_param_count = node->data.fn_call_expr.params.length;
520 size_t fn_call_param_count = node->data.fn_call_expr.params.length;
520521 assert(fn_call_param_count == 4);
521522
522523 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) {
561562 case BuiltinFnIdCtz:
562563 case BuiltinFnIdClz:
563564 {
564 int fn_call_param_count = node->data.fn_call_expr.params.length;
565 size_t fn_call_param_count = node->data.fn_call_expr.params.length;
565566 assert(fn_call_param_count == 2);
566567 TypeTableEntry *int_type = get_type_for_type_node(node->data.fn_call_expr.params.at(0));
567568 assert(int_type->id == TypeTableEntryIdInt);
......@@ -578,7 +579,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {
578579 case BuiltinFnIdSubWithOverflow:
579580 case BuiltinFnIdMulWithOverflow:
580581 {
581 int fn_call_param_count = node->data.fn_call_expr.params.length;
582 size_t fn_call_param_count = node->data.fn_call_expr.params.length;
582583 assert(fn_call_param_count == 4);
583584
584585 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) {
615616 return gen_shl_with_overflow(g, node);
616617 case BuiltinFnIdMemcpy:
617618 {
618 int fn_call_param_count = node->data.fn_call_expr.params.length;
619 size_t fn_call_param_count = node->data.fn_call_expr.params.length;
619620 assert(fn_call_param_count == 3);
620621
621622 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) {
646647 }
647648 case BuiltinFnIdMemset:
648649 {
649 int fn_call_param_count = node->data.fn_call_expr.params.length;
650 size_t fn_call_param_count = node->data.fn_call_expr.params.length;
650651 assert(fn_call_param_count == 3);
651652
652653 AstNode *dest_node = node->data.fn_call_expr.params.at(0);
......@@ -949,14 +950,14 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
949950
950951 set_debug_source_node(g, node);
951952
952 int ptr_index = wanted_type->data.structure.fields[0].gen_index;
953 if (ptr_index >= 0) {
953 size_t ptr_index = wanted_type->data.structure.fields[0].gen_index;
954 if (ptr_index != SIZE_MAX) {
954955 LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, ptr_index, "");
955956 LLVMValueRef expr_bitcast = LLVMBuildBitCast(g->builder, expr_val, pointer_type->type_ref, "");
956957 LLVMBuildStore(g->builder, expr_bitcast, ptr_ptr);
957958 }
958959
959 int len_index = wanted_type->data.structure.fields[1].gen_index;
960 size_t len_index = wanted_type->data.structure.fields[1].gen_index;
960961 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, len_index, "");
961962 LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
962963 actual_type->data.array.len, false);
......@@ -979,10 +980,10 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
979980
980981 set_debug_source_node(g, node);
981982
982 int actual_ptr_index = actual_type->data.structure.fields[0].gen_index;
983 int actual_len_index = actual_type->data.structure.fields[1].gen_index;
984 int wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
985 int wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
983 size_t actual_ptr_index = actual_type->data.structure.fields[0].gen_index;
984 size_t actual_len_index = actual_type->data.structure.fields[1].gen_index;
985 size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
986 size_t wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
986987
987988 LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, expr_val, actual_ptr_index, "");
988989 LLVMValueRef src_ptr = LLVMBuildLoad(g->builder, src_ptr_ptr, "");
......@@ -1040,12 +1041,12 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
10401041
10411042 set_debug_source_node(g, node);
10421043
1043 int wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
1044 size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
10441045 LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, wanted_ptr_index, "");
10451046 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, expr_val, wanted_pointer_type->type_ref, "");
10461047 LLVMBuildStore(g->builder, src_ptr_casted, dest_ptr_ptr);
10471048
1048 int wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
1049 size_t wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
10491050 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, wanted_len_index, "");
10501051 LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
10511052 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) {
11251126
11261127 bool ret_has_bits = type_has_bits(src_return_type);
11271128
1128 int fn_call_param_count = node->data.fn_call_expr.params.length;
1129 size_t fn_call_param_count = node->data.fn_call_expr.params.length;
11291130 bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type);
1130 int actual_param_count = fn_call_param_count + (struct_type ? 1 : 0) + (first_arg_ret ? 1 : 0);
1131 size_t actual_param_count = fn_call_param_count + (struct_type ? 1 : 0) + (first_arg_ret ? 1 : 0);
11311132 bool is_var_args = fn_type->data.fn.fn_type_id.is_var_args;
11321133
11331134 // don't really include void values
11341135 LLVMValueRef *gen_param_values = allocate<LLVMValueRef>(actual_param_count);
11351136
1136 int gen_param_index = 0;
1137 size_t gen_param_index = 0;
11371138 if (first_arg_ret) {
11381139 gen_param_values[gen_param_index] = node->data.fn_call_expr.tmp_ptr;
11391140 gen_param_index += 1;
......@@ -1144,8 +1145,8 @@ static LLVMValueRef gen_fn_call_expr(CodeGen *g, AstNode *node) {
11441145 gen_param_index += 1;
11451146 }
11461147
1147 for (int call_i = 0; call_i < fn_call_param_count; call_i += 1) {
1148 int proto_i = call_i + (struct_type ? 1 : 0);
1148 for (size_t call_i = 0; call_i < fn_call_param_count; call_i += 1) {
1149 size_t proto_i = call_i + (struct_type ? 1 : 0);
11491150 if (generic_proto_node &&
11501151 generic_proto_node->data.fn_proto.params.at(proto_i)->data.param_decl.is_inline)
11511152 {
......@@ -1231,16 +1232,16 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal
12311232
12321233 if (want_debug_safety(g, source_node)) {
12331234 set_debug_source_node(g, source_node);
1234 int len_index = array_type->data.structure.fields[1].gen_index;
1235 assert(len_index >= 0);
1235 size_t len_index = array_type->data.structure.fields[1].gen_index;
1236 assert(len_index != SIZE_MAX);
12361237 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, len_index, "");
12371238 LLVMValueRef len = LLVMBuildLoad(g->builder, len_ptr, "");
12381239 add_bounds_check(g, source_node, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len);
12391240 }
12401241
12411242 set_debug_source_node(g, source_node);
1242 int ptr_index = array_type->data.structure.fields[0].gen_index;
1243 assert(ptr_index >= 0);
1243 size_t ptr_index = array_type->data.structure.fields[0].gen_index;
1244 assert(ptr_index != SIZE_MAX);
12441245 LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, ptr_index, "");
12451246 LLVMValueRef ptr = LLVMBuildLoad(g->builder, ptr_ptr, "");
12461247 return LLVMBuildInBoundsGEP(g->builder, ptr, &subscript_value, 1, "");
......@@ -1297,8 +1298,8 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou
12971298 assert(LLVMGetTypeKind(LLVMTypeOf(struct_ptr)) == LLVMPointerTypeKind);
12981299 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(struct_ptr))) == LLVMStructTypeKind);
12991300
1300 int gen_field_index = node->data.field_access_expr.type_struct_field->gen_index;
1301 assert(gen_field_index >= 0);
1301 size_t gen_field_index = node->data.field_access_expr.type_struct_field->gen_index;
1302 assert(gen_field_index != SIZE_MAX);
13021303
13031304 set_debug_source_node(g, node);
13041305 return LLVMBuildStructGEP(g->builder, struct_ptr, gen_field_index, "");
......@@ -1368,10 +1369,10 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) {
13681369 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
13691370 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
13701371
1371 int ptr_index = array_type->data.structure.fields[0].gen_index;
1372 assert(ptr_index >= 0);
1373 int len_index = array_type->data.structure.fields[1].gen_index;
1374 assert(len_index >= 0);
1372 size_t ptr_index = array_type->data.structure.fields[0].gen_index;
1373 assert(ptr_index != SIZE_MAX);
1374 size_t len_index = array_type->data.structure.fields[1].gen_index;
1375 assert(len_index != SIZE_MAX);
13751376
13761377 LLVMValueRef prev_end = nullptr;
13771378 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
23952396 }
23962397}
23972398
2398static int get_conditional_defer_count(BlockContext *inner_block, BlockContext *outer_block) {
2399 int result = 0;
2399static size_t get_conditional_defer_count(BlockContext *inner_block, BlockContext *outer_block) {
2400 size_t result = 0;
24002401 while (inner_block != outer_block) {
24012402 if (inner_block->node->type == NodeTypeDefer &&
24022403 (inner_block->node->data.defer.kind == ReturnKindError ||
......@@ -2776,7 +2777,7 @@ static LLVMValueRef gen_block(CodeGen *g, AstNode *block_node, TypeTableEntry *i
27762777 assert(block_node->type == NodeTypeBlock);
27772778
27782779 LLVMValueRef return_value = nullptr;
2779 for (int i = 0; i < block_node->data.block.statements.length; i += 1) {
2780 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
27802781 AstNode *statement_node = block_node->data.block.statements.at(i);
27812782 return_value = gen_expr(g, statement_node);
27822783 }
......@@ -2796,23 +2797,23 @@ static LLVMValueRef gen_block(CodeGen *g, AstNode *block_node, TypeTableEntry *i
27962797 }
27972798}
27982799
2799static int find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok) {
2800static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok) {
28002801 const char *ptr = buf_ptr(node->data.asm_expr.asm_template) + tok->start + 2;
2801 int len = tok->end - tok->start - 2;
2802 int result = 0;
2803 for (int i = 0; i < node->data.asm_expr.output_list.length; i += 1, result += 1) {
2802 size_t len = tok->end - tok->start - 2;
2803 size_t result = 0;
2804 for (size_t i = 0; i < node->data.asm_expr.output_list.length; i += 1, result += 1) {
28042805 AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);
28052806 if (buf_eql_mem(asm_output->asm_symbolic_name, ptr, len)) {
28062807 return result;
28072808 }
28082809 }
2809 for (int i = 0; i < node->data.asm_expr.input_list.length; i += 1, result += 1) {
2810 for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1, result += 1) {
28102811 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
28112812 if (buf_eql_mem(asm_input->asm_symbolic_name, ptr, len)) {
28122813 return result;
28132814 }
28142815 }
2815 return -1;
2816 return SIZE_MAX;
28162817}
28172818
28182819static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
......@@ -2825,11 +2826,11 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
28252826 Buf llvm_template = BUF_INIT;
28262827 buf_resize(&llvm_template, 0);
28272828
2828 for (int token_i = 0; token_i < asm_expr->token_list.length; token_i += 1) {
2829 for (size_t token_i = 0; token_i < asm_expr->token_list.length; token_i += 1) {
28292830 AsmToken *asm_token = &asm_expr->token_list.at(token_i);
28302831 switch (asm_token->id) {
28312832 case AsmTokenIdTemplate:
2832 for (int offset = asm_token->start; offset < asm_token->end; offset += 1) {
2833 for (size_t offset = asm_token->start; offset < asm_token->end; offset += 1) {
28332834 uint8_t c = *((uint8_t*)(buf_ptr(src_template) + offset));
28342835 if (c == '$') {
28352836 buf_append_str(&llvm_template, "$$");
......@@ -2842,9 +2843,9 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
28422843 buf_append_char(&llvm_template, '%');
28432844 break;
28442845 case AsmTokenIdVar:
2845 int index = find_asm_index(g, node, asm_token);
2846 assert(index >= 0);
2847 buf_appendf(&llvm_template, "$%d", index);
2846 size_t index = find_asm_index(g, node, asm_token);
2847 assert(index < SIZE_MAX);
2848 buf_appendf(&llvm_template, "$%zu", index);
28482849 break;
28492850 }
28502851 }
......@@ -2854,17 +2855,17 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
28542855
28552856 assert(asm_expr->return_count == 0 || asm_expr->return_count == 1);
28562857
2857 int total_constraint_count = asm_expr->output_list.length +
2858 size_t total_constraint_count = asm_expr->output_list.length +
28582859 asm_expr->input_list.length +
28592860 asm_expr->clobber_list.length;
2860 int input_and_output_count = asm_expr->output_list.length +
2861 size_t input_and_output_count = asm_expr->output_list.length +
28612862 asm_expr->input_list.length -
28622863 asm_expr->return_count;
2863 int total_index = 0;
2864 int param_index = 0;
2864 size_t total_index = 0;
2865 size_t param_index = 0;
28652866 LLVMTypeRef *param_types = allocate<LLVMTypeRef>(input_and_output_count);
28662867 LLVMValueRef *param_values = allocate<LLVMValueRef>(input_and_output_count);
2867 for (int i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {
2868 for (size_t i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {
28682869 AsmOutput *asm_output = asm_expr->output_list.at(i);
28692870 bool is_return = (asm_output->return_type != nullptr);
28702871 assert(*buf_ptr(asm_output->constraint) == '=');
......@@ -2885,7 +2886,7 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
28852886 param_index += 1;
28862887 }
28872888 }
2888 for (int i = 0; i < asm_expr->input_list.length; i += 1, total_index += 1, param_index += 1) {
2889 for (size_t i = 0; i < asm_expr->input_list.length; i += 1, total_index += 1, param_index += 1) {
28892890 AsmInput *asm_input = asm_expr->input_list.at(i);
28902891 buf_append_buf(&constraint_buf, asm_input->constraint);
28912892 if (total_index + 1 < total_constraint_count) {
......@@ -2896,7 +2897,7 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
28962897 param_types[param_index] = expr_type->type_ref;
28972898 param_values[param_index] = gen_expr(g, asm_input->expr);
28982899 }
2899 for (int i = 0; i < asm_expr->clobber_list.length; i += 1, total_index += 1) {
2900 for (size_t i = 0; i < asm_expr->clobber_list.length; i += 1, total_index += 1) {
29002901 Buf *clobber_buf = asm_expr->clobber_list.at(i);
29012902 buf_appendf(&constraint_buf, "~{%s}", buf_ptr(clobber_buf));
29022903 if (total_index + 1 < total_constraint_count) {
......@@ -2927,7 +2928,7 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
29272928
29282929
29292930 if (node->data.container_init_expr.enum_type) {
2930 int param_count = node->data.container_init_expr.entries.length;
2931 size_t param_count = node->data.container_init_expr.entries.length;
29312932 AstNode *arg1_node;
29322933 if (param_count == 1) {
29332934 arg1_node = node->data.container_init_expr.entries.at(0);
......@@ -2943,13 +2944,13 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
29432944 if (type_entry->id == TypeTableEntryIdStruct) {
29442945 assert(node->data.container_init_expr.kind == ContainerInitKindStruct);
29452946
2946 int src_field_count = type_entry->data.structure.src_field_count;
2947 size_t src_field_count = type_entry->data.structure.src_field_count;
29472948 assert(src_field_count == node->data.container_init_expr.entries.length);
29482949
29492950 StructValExprCodeGen *struct_val_expr_node = &node->data.container_init_expr.resolved_struct_val_expr;
29502951 LLVMValueRef tmp_struct_ptr = struct_val_expr_node->ptr;
29512952
2952 for (int i = 0; i < src_field_count; i += 1) {
2953 for (size_t i = 0; i < src_field_count; i += 1) {
29532954 AstNode *field_node = node->data.container_init_expr.entries.at(i);
29542955 assert(field_node->type == NodeTypeStructValueField);
29552956 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) {
29742975 StructValExprCodeGen *struct_val_expr_node = &node->data.container_init_expr.resolved_struct_val_expr;
29752976 LLVMValueRef tmp_array_ptr = struct_val_expr_node->ptr;
29762977
2977 int field_count = type_entry->data.array.len;
2978 size_t field_count = type_entry->data.array.len;
29782979 assert(field_count == node->data.container_init_expr.entries.length);
29792980
29802981 TypeTableEntry *child_type = type_entry->data.array.child_type;
29812982
2982 for (int i = 0; i < field_count; i += 1) {
2983 for (size_t i = 0; i < field_count; i += 1) {
29832984 AstNode *field_node = node->data.container_init_expr.entries.at(i);
29842985 LLVMValueRef elem_val = gen_expr(g, field_node);
29852986
......@@ -3126,8 +3127,8 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
31263127 TypeTableEntry *child_ptr_type = array_type->data.structure.fields[0].type_entry;
31273128 assert(child_ptr_type->id == TypeTableEntryIdPointer);
31283129 child_type = child_ptr_type->data.pointer.child_type;
3129 int len_index = array_type->data.structure.fields[1].gen_index;
3130 assert(len_index >= 0);
3130 size_t len_index = array_type->data.structure.fields[1].gen_index;
3131 assert(len_index != SIZE_MAX);
31313132 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, array_val, len_index, "");
31323133 len_val = LLVMBuildLoad(g->builder, len_field_ptr, "");
31333134 } else {
......@@ -3249,10 +3250,10 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa
32493250 LLVMValueRef ptr_val = LLVMBuildArrayAlloca(g->builder, child_type->type_ref,
32503251 size_val, "");
32513252
3252 int ptr_index = var_type->data.structure.fields[0].gen_index;
3253 assert(ptr_index >= 0);
3254 int len_index = var_type->data.structure.fields[1].gen_index;
3255 assert(len_index >= 0);
3253 size_t ptr_index = var_type->data.structure.fields[0].gen_index;
3254 assert(ptr_index != SIZE_MAX);
3255 size_t len_index = var_type->data.structure.fields[1].gen_index;
3256 assert(len_index != SIZE_MAX);
32563257
32573258 // store the freshly allocated pointer in the unknown size array struct
32583259 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder,
......@@ -3328,7 +3329,7 @@ static LLVMValueRef gen_symbol(CodeGen *g, AstNode *node) {
33283329static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
33293330 assert(node->type == NodeTypeSwitchExpr);
33303331
3331 if (node->data.switch_expr.const_chosen_prong_index >= 0) {
3332 if (node->data.switch_expr.const_chosen_prong_index != SIZE_MAX) {
33323333 AstNode *prong_node = node->data.switch_expr.prongs.at(node->data.switch_expr.const_chosen_prong_index);
33333334 assert(prong_node->type == NodeTypeSwitchProng);
33343335 AstNode *prong_expr = prong_node->data.switch_prong.expr;
......@@ -3362,7 +3363,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
33623363 LLVMBasicBlockRef end_block = end_unreachable ?
33633364 nullptr : LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchEnd");
33643365 LLVMBasicBlockRef else_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchElse");
3365 int prong_count = node->data.switch_expr.prongs.length;
3366 size_t prong_count = node->data.switch_expr.prongs.length;
33663367
33673368 set_debug_source_node(g, node);
33683369 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) {
33713372 ZigList<LLVMBasicBlockRef> incoming_blocks = {0};
33723373
33733374 AstNode *else_prong = nullptr;
3374 for (int prong_i = 0; prong_i < prong_count; prong_i += 1) {
3375 for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {
33753376 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);
33763377 VariableTableEntry *prong_var = prong_node->data.switch_prong.var;
33773378
......@@ -3382,10 +3383,10 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
33823383 prong_block = else_block;
33833384 } else {
33843385 prong_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchProng");
3385 int prong_item_count = prong_node->data.switch_prong.items.length;
3386 size_t prong_item_count = prong_node->data.switch_prong.items.length;
33863387 bool make_item_blocks = prong_var && prong_item_count > 1;
33873388
3388 for (int item_i = 0; item_i < prong_item_count; item_i += 1) {
3389 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
33893390 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
33903391
33913392 assert(item_node->type != NodeTypeSwitchRange);
......@@ -3699,7 +3700,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
36993700 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
37003701 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
37013702 TypeStructField *type_struct_field = &type_entry->data.structure.fields[i];
3702 if (type_struct_field->gen_index == -1) {
3703 if (type_struct_field->gen_index == SIZE_MAX) {
37033704 continue;
37043705 }
37053706 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
37673768 case TypeTableEntryIdPointer:
37683769 {
37693770 TypeTableEntry *child_type = type_entry->data.pointer.child_type;
3770 int len = const_val->data.x_ptr.len;
3771 size_t len = const_val->data.x_ptr.len;
37713772 LLVMValueRef target_val;
37723773 if (len == 1) {
37733774 target_val = gen_const_val(g, child_type, const_val->data.x_ptr.ptr[0]);
37743775 } else if (len > 1) {
37753776 LLVMValueRef *values = allocate<LLVMValueRef>(len);
3776 for (int i = 0; i < len; i += 1) {
3777 for (size_t i = 0; i < len; i += 1) {
37773778 values[i] = gen_const_val(g, child_type, const_val->data.x_ptr.ptr[i]);
37783779 }
37793780 target_val = LLVMConstArray(child_type->type_ref, values, len);
......@@ -3833,7 +3834,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
38333834}
38343835
38353836static void gen_const_globals(CodeGen *g) {
3836 for (int i = 0; i < g->global_const_list.length; i += 1) {
3837 for (size_t i = 0; i < g->global_const_list.length; i += 1) {
38373838 AstNode *expr_node = g->global_const_list.at(i);
38383839 Expr *expr = get_resolved_expr(expr_node);
38393840 ConstExprValue *const_val = &expr->const_val;
......@@ -3927,7 +3928,7 @@ static void generate_error_name_table(CodeGen *g) {
39273928
39283929 LLVMValueRef *values = allocate<LLVMValueRef>(g->error_decls.length);
39293930 values[0] = LLVMGetUndef(str_type->type_ref);
3930 for (int i = 1; i < g->error_decls.length; i += 1) {
3931 for (size_t i = 1; i < g->error_decls.length; i += 1) {
39313932 AstNode *error_decl_node = g->error_decls.at(i);
39323933 assert(error_decl_node->type == NodeTypeErrorValueDecl);
39333934 Buf *name = error_decl_node->data.error_value_decl.name;
......@@ -3957,7 +3958,7 @@ static void generate_error_name_table(CodeGen *g) {
39573958
39583959static void build_label_blocks(CodeGen *g, FnTableEntry *fn) {
39593960 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn->fn_value, "entry");
3960 for (int i = 0; i < fn->all_labels.length; i += 1) {
3961 for (size_t i = 0; i < fn->all_labels.length; i += 1) {
39613962 LabelTableEntry *label = fn->all_labels.at(i);
39623963 Buf *name = label->decl_node->data.label.name;
39633964 label->basic_block = LLVMAppendBasicBlock(fn->fn_value, buf_ptr(name));
......@@ -3988,7 +3989,7 @@ static void do_code_gen(CodeGen *g) {
39883989 generate_error_name_table(g);
39893990
39903991 // Generate module level variables
3991 for (int i = 0; i < g->global_vars.length; i += 1) {
3992 for (size_t i = 0; i < g->global_vars.length; i += 1) {
39923993 VariableTableEntry *var = g->global_vars.at(i);
39933994
39943995 if (var->type->id == TypeTableEntryIdNumLitFloat) {
......@@ -4063,7 +4064,7 @@ static void do_code_gen(CodeGen *g) {
40634064 }
40644065
40654066 // Generate function prototypes
4066 for (int fn_proto_i = 0; fn_proto_i < g->fn_protos.length; fn_proto_i += 1) {
4067 for (size_t fn_proto_i = 0; fn_proto_i < g->fn_protos.length; fn_proto_i += 1) {
40674068 FnTableEntry *fn_table_entry = g->fn_protos.at(fn_proto_i);
40684069 if (should_skip_fn_codegen(g, fn_table_entry)) {
40694070 // huge time saver
......@@ -4097,15 +4098,15 @@ static void do_code_gen(CodeGen *g) {
40974098
40984099
40994100 // set parameter attributes
4100 for (int param_decl_i = 0; param_decl_i < fn_proto->params.length; param_decl_i += 1) {
4101 for (size_t param_decl_i = 0; param_decl_i < fn_proto->params.length; param_decl_i += 1) {
41014102 AstNode *param_node = fn_proto->params.at(param_decl_i);
41024103 assert(param_node->type == NodeTypeParamDecl);
41034104
41044105 FnGenParamInfo *info = &fn_type->data.fn.gen_param_info[param_decl_i];
4105 int gen_index = info->gen_index;
4106 size_t gen_index = info->gen_index;
41064107 bool is_byval = info->is_byval;
41074108
4108 if (gen_index < 0) {
4109 if (gen_index == SIZE_MAX) {
41094110 continue;
41104111 }
41114112
......@@ -4169,7 +4170,7 @@ static void do_code_gen(CodeGen *g) {
41694170 }
41704171
41714172 // Generate function definitions.
4172 for (int fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) {
4173 for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) {
41734174 FnTableEntry *fn_table_entry = g->fn_defs.at(fn_i);
41744175 if (should_skip_fn_codegen(g, fn_table_entry)) {
41754176 // huge time saver
......@@ -4194,7 +4195,7 @@ static void do_code_gen(CodeGen *g) {
41944195
41954196
41964197 // Set up debug info for blocks
4197 for (int bc_i = 0; bc_i < fn_table_entry->all_block_contexts.length; bc_i += 1) {
4198 for (size_t bc_i = 0; bc_i < fn_table_entry->all_block_contexts.length; bc_i += 1) {
41984199 BlockContext *block_context = fn_table_entry->all_block_contexts.at(bc_i);
41994200
42004201 if (!block_context->di_scope) {
......@@ -4212,7 +4213,7 @@ static void do_code_gen(CodeGen *g) {
42124213 clear_debug_source_node(g);
42134214
42144215 // allocate structs which are the result of casts
4215 for (int cea_i = 0; cea_i < fn_table_entry->cast_alloca_list.length; cea_i += 1) {
4216 for (size_t cea_i = 0; cea_i < fn_table_entry->cast_alloca_list.length; cea_i += 1) {
42164217 AstNode *fn_call_node = fn_table_entry->cast_alloca_list.at(cea_i);
42174218 Expr *expr = &fn_call_node->data.fn_call_expr.resolved_expr;
42184219 fn_call_node->data.fn_call_expr.tmp_ptr = LLVMBuildAlloca(g->builder,
......@@ -4220,14 +4221,14 @@ static void do_code_gen(CodeGen *g) {
42204221 }
42214222
42224223 // allocate structs which are struct value expressions
4223 for (int alloca_i = 0; alloca_i < fn_table_entry->struct_val_expr_alloca_list.length; alloca_i += 1) {
4224 for (size_t alloca_i = 0; alloca_i < fn_table_entry->struct_val_expr_alloca_list.length; alloca_i += 1) {
42244225 StructValExprCodeGen *struct_val_expr_node = fn_table_entry->struct_val_expr_alloca_list.at(alloca_i);
42254226 struct_val_expr_node->ptr = LLVMBuildAlloca(g->builder,
42264227 struct_val_expr_node->type_entry->type_ref, "");
42274228 }
42284229
42294230 // create debug variable declarations for variables and allocate all local variables
4230 for (int var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {
4231 for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {
42314232 VariableTableEntry *var = fn_table_entry->variable_list.at(var_i);
42324233
42334234 if (!type_has_bits(var->type)) {
......@@ -4235,7 +4236,7 @@ static void do_code_gen(CodeGen *g) {
42354236 }
42364237
42374238 if (var->block_context->node->type == NodeTypeFnDef) {
4238 assert(var->gen_arg_index >= 0);
4239 assert(var->gen_arg_index != SIZE_MAX);
42394240 TypeTableEntry *gen_type;
42404241 if (handle_is_ptr(var->type)) {
42414242 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) {
42644265 }
42654266
42664267 // create debug variable declarations for parameters
4267 for (int param_i = 0; param_i < fn_proto->params.length; param_i += 1) {
4268 for (size_t param_i = 0; param_i < fn_proto->params.length; param_i += 1) {
42684269 AstNode *param_decl = fn_proto->params.at(param_i);
42694270 assert(param_decl->type == NodeTypeParamDecl);
42704271
42714272 FnGenParamInfo *info = &fn_table_entry->type_entry->data.fn.gen_param_info[param_i];
42724273
4273 if (info->gen_index < 0) {
4274 if (info->gen_index == SIZE_MAX) {
42744275 continue;
42754276 }
42764277
......@@ -4306,7 +4307,7 @@ static void do_code_gen(CodeGen *g) {
43064307#endif
43074308}
43084309
4309static const int int_sizes_in_bits[] = {
4310static const size_t int_sizes_in_bits[] = {
43104311 8,
43114312 16,
43124313 32,
......@@ -4380,9 +4381,9 @@ static void define_builtin_types(CodeGen *g) {
43804381 g->builtin_types.entry_var = entry;
43814382 }
43824383
4383 for (int int_size_i = 0; int_size_i < array_length(int_sizes_in_bits); int_size_i += 1) {
4384 int size_in_bits = int_sizes_in_bits[int_size_i];
4385 for (int is_sign_i = 0; is_sign_i < array_length(is_signed_list); is_sign_i += 1) {
4384 for (size_t int_size_i = 0; int_size_i < array_length(int_sizes_in_bits); int_size_i += 1) {
4385 size_t size_in_bits = int_sizes_in_bits[int_size_i];
4386 for (size_t is_sign_i = 0; is_sign_i < array_length(is_signed_list); is_sign_i += 1) {
43864387 bool is_signed = is_signed_list[is_sign_i];
43874388
43884389 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
......@@ -4391,7 +4392,7 @@ static void define_builtin_types(CodeGen *g) {
43914392
43924393 const char u_or_i = is_signed ? 'i' : 'u';
43934394 buf_resize(&entry->name, 0);
4394 buf_appendf(&entry->name, "%c%d", u_or_i, size_in_bits);
4395 buf_appendf(&entry->name, "%c%zu", u_or_i, size_in_bits);
43954396
43964397 unsigned dwarf_tag;
43974398 if (is_signed) {
......@@ -4420,7 +4421,7 @@ static void define_builtin_types(CodeGen *g) {
44204421 }
44214422 }
44224423
4423 for (int i = 0; i < array_length(c_int_type_infos); i += 1) {
4424 for (size_t i = 0; i < array_length(c_int_type_infos); i += 1) {
44244425 const CIntTypeInfo *info = &c_int_type_infos[i];
44254426 uint64_t size_in_bits = get_c_type_size_in_bits(&g->zig_target, info->id);
44264427 bool is_signed = info->is_signed;
......@@ -4459,7 +4460,7 @@ static void define_builtin_types(CodeGen *g) {
44594460 g->primitive_type_table.put(&entry->name, entry);
44604461 }
44614462
4462 for (int sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) {
4463 for (size_t sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) {
44634464 bool is_signed = is_signed_list[sign_i];
44644465
44654466 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
......@@ -4754,7 +4755,7 @@ static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char
47544755 return builtin_fn;
47554756}
47564757
4757static BuiltinFnEntry *create_builtin_fn_with_arg_count(CodeGen *g, BuiltinFnId id, const char *name, int count) {
4758static BuiltinFnEntry *create_builtin_fn_with_arg_count(CodeGen *g, BuiltinFnId id, const char *name, size_t count) {
47584759 BuiltinFnEntry *builtin_fn = create_builtin_fn(g, id, name);
47594760 builtin_fn->param_count = count;
47604761 builtin_fn->param_types = allocate<TypeTableEntry *>(count);
......@@ -4958,7 +4959,7 @@ void codegen_parseh(CodeGen *g, Buf *src_dirname, Buf *src_basename, Buf *source
49584959 }
49594960
49604961 if (errors.length > 0) {
4961 for (int i = 0; i < errors.length; i += 1) {
4962 for (size_t i = 0; i < errors.length; i += 1) {
49624963 ErrorMsg *err_msg = errors.at(i);
49634964 print_err_msg(err_msg, g->err_color);
49644965 }
......@@ -5034,7 +5035,7 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou
50345035 fprintf(stderr, "OK\n");
50355036 }
50365037 } else {
5037 for (int i = 0; i < g->errors.length; i += 1) {
5038 for (size_t i = 0; i < g->errors.length; i += 1) {
50385039 ErrorMsg *err = g->errors.at(i);
50395040 print_err_msg(err, g->err_color);
50405041 }
......@@ -5063,7 +5064,7 @@ static const char *c_int_type_names[] = {
50635064static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
50645065 assert(type_entry);
50655066
5066 for (int i = 0; i < array_length(c_int_type_names); i += 1) {
5067 for (size_t i = 0; i < array_length(c_int_type_names); i += 1) {
50675068 if (type_entry == g->builtin_types.entry_c_int[i]) {
50685069 buf_init_from_str(out_buf, c_int_type_names[i]);
50695070 return;
......@@ -5114,7 +5115,7 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
51145115 case TypeTableEntryIdInt:
51155116 g->c_want_stdint = true;
51165117 buf_resize(out_buf, 0);
5117 buf_appendf(out_buf, "%sint%d_t",
5118 buf_appendf(out_buf, "%sint%zu_t",
51185119 type_entry->data.integral.is_signed ? "" : "u",
51195120 type_entry->data.integral.bit_count);
51205121 break;
......@@ -5183,7 +5184,7 @@ void codegen_generate_h_file(CodeGen *g) {
51835184
51845185 Buf h_buf = BUF_INIT;
51855186 buf_resize(&h_buf, 0);
5186 for (int fn_def_i = 0; fn_def_i < g->fn_defs.length; fn_def_i += 1) {
5187 for (size_t fn_def_i = 0; fn_def_i < g->fn_defs.length; fn_def_i += 1) {
51875188 FnTableEntry *fn_table_entry = g->fn_defs.at(fn_def_i);
51885189 AstNode *proto_node = fn_table_entry->proto_node;
51895190 assert(proto_node->type == NodeTypeFnProto);
......@@ -5202,7 +5203,7 @@ void codegen_generate_h_file(CodeGen *g) {
52025203
52035204 Buf param_type_c = BUF_INIT;
52045205 if (fn_proto->params.length) {
5205 for (int param_i = 0; param_i < fn_proto->params.length; param_i += 1) {
5206 for (size_t param_i = 0; param_i < fn_proto->params.length; param_i += 1) {
52065207 AstNode *param_decl_node = fn_proto->params.at(param_i);
52075208 AstNode *param_type = param_decl_node->data.param_decl.type;
52085209 get_c_type_node(g, param_type, &param_type_c);
src/codegen.hpp+1-1
......@@ -16,7 +16,7 @@
1616
1717CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target);
1818
19void codegen_set_clang_argv(CodeGen *codegen, const char **args, int len);
19void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);
2020void codegen_set_is_release(CodeGen *codegen, bool is_release);
2121void codegen_set_is_test(CodeGen *codegen, bool is_test);
2222void codegen_set_check_unused(CodeGen *codegen, bool check_unused);
src/errmsg.cpp+17-20
......@@ -16,36 +16,36 @@ enum ErrType {
1616
1717static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) {
1818 const char *path = buf_ptr(err->path);
19 int line = err->line_start + 1;
20 int col = err->column_start + 1;
19 size_t line = err->line_start + 1;
20 size_t col = err->column_start + 1;
2121 const char *text = buf_ptr(err->msg);
2222
2323
2424 if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) {
2525 if (err_type == ErrTypeError) {
26 fprintf(stderr, WHITE "%s:%d:%d: " RED "error:" WHITE " %s" RESET "\n", path, line, col, text);
26 fprintf(stderr, WHITE "%s:%zu:%zu: " RED "error:" WHITE " %s" RESET "\n", path, line, col, text);
2727 } else if (err_type == ErrTypeNote) {
28 fprintf(stderr, WHITE "%s:%d:%d: " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text);
28 fprintf(stderr, WHITE "%s:%zu:%zu: " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text);
2929 } else {
3030 zig_unreachable();
3131 }
3232
3333 fprintf(stderr, "%s\n", buf_ptr(&err->line_buf));
34 for (int i = 0; i < err->column_start; i += 1) {
34 for (size_t i = 0; i < err->column_start; i += 1) {
3535 fprintf(stderr, " ");
3636 }
3737 fprintf(stderr, GREEN "^" RESET "\n");
3838 } else {
3939 if (err_type == ErrTypeError) {
40 fprintf(stderr, "%s:%d:%d: error: %s\n", path, line, col, text);
40 fprintf(stderr, "%s:%zu:%zu: error: %s\n", path, line, col, text);
4141 } else if (err_type == ErrTypeNote) {
42 fprintf(stderr, " %s:%d:%d: note: %s\n", path, line, col, text);
42 fprintf(stderr, " %s:%zu:%zu: note: %s\n", path, line, col, text);
4343 } else {
4444 zig_unreachable();
4545 }
4646 }
4747
48 for (int i = 0; i < err->notes.length; i += 1) {
48 for (size_t i = 0; i < err->notes.length; i += 1) {
4949 ErrorMsg *note = err->notes.at(i);
5050 print_err_msg_type(note, color, ErrTypeNote);
5151 }
......@@ -59,7 +59,7 @@ void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note) {
5959 parent->notes.append(note);
6060}
6161
62ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset,
62ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size_t offset,
6363 const char *source, Buf *msg)
6464{
6565 ErrorMsg *err_msg = allocate<ErrorMsg>(1);
......@@ -68,7 +68,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset
6868 err_msg->column_start = column;
6969 err_msg->msg = msg;
7070
71 int line_start_offset = offset;
71 size_t line_start_offset = offset;
7272 for (;;) {
7373 if (line_start_offset == 0) {
7474 break;
......@@ -79,7 +79,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset
7979 line_start_offset -= 1;
8080 }
8181
82 int line_end_offset = offset;
82 size_t line_end_offset = offset;
8383 while (source[line_end_offset] && source[line_end_offset] != '\n') {
8484 line_end_offset += 1;
8585 }
......@@ -89,8 +89,8 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset
8989 return err_msg;
9090}
9191
92ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column,
93 Buf *source, ZigList<int> *line_offsets, Buf *msg)
92ErrorMsg *err_msg_create_with_line(Buf *path, size_t line, size_t column,
93 Buf *source, ZigList<size_t> *line_offsets, Buf *msg)
9494{
9595 ErrorMsg *err_msg = allocate<ErrorMsg>(1);
9696 err_msg->path = path;
......@@ -98,13 +98,10 @@ ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column,
9898 err_msg->column_start = column;
9999 err_msg->msg = msg;
100100
101 int line_start_offset = line_offsets->at(line);
102 int end_line = line + 1;
103 int line_end_offset = (end_line >= line_offsets->length) ? buf_len(source) : line_offsets->at(line + 1);
104 int len = line_end_offset - line_start_offset - 1;
105 if (len < 0) {
106 len = 0;
107 }
101 size_t line_start_offset = line_offsets->at(line);
102 size_t end_line = line + 1;
103 size_t line_end_offset = (end_line >= line_offsets->length) ? buf_len(source) : line_offsets->at(line + 1);
104 size_t len = (line_end_offset + 1 > line_start_offset) ? (line_end_offset - line_start_offset - 1) : 0;
108105
109106 buf_init_from_mem(&err_msg->line_buf, buf_ptr(source) + line_start_offset, len);
110107
src/errmsg.hpp+5-5
......@@ -18,8 +18,8 @@ enum ErrColor {
1818};
1919
2020struct ErrorMsg {
21 int line_start;
22 int column_start;
21 size_t line_start;
22 size_t column_start;
2323 Buf *msg;
2424 Buf *path;
2525 Buf line_buf;
......@@ -30,10 +30,10 @@ struct ErrorMsg {
3030void print_err_msg(ErrorMsg *msg, ErrColor color);
3131
3232void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note);
33ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset,
33ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size_t offset,
3434 const char *source, Buf *msg);
3535
36ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column,
37 Buf *source, ZigList<int> *line_offsets, Buf *msg);
36ErrorMsg *err_msg_create_with_line(Buf *path, size_t line, size_t column,
37 Buf *source, ZigList<size_t> *line_offsets, Buf *msg);
3838
3939#endif
src/eval.cpp+21-21
......@@ -75,7 +75,7 @@ static bool eval_block(EvalFn *ef, AstNode *node, ConstExprValue *out) {
7575 my_scope->block_context = node->block_context;
7676 ef->scope_stack.append(my_scope);
7777
78 for (int i = 0; i < node->data.block.statements.length; i += 1) {
78 for (size_t i = 0; i < node->data.block.statements.length; i += 1) {
7979 AstNode *child = node->data.block.statements.at(i);
8080 memset(out, 0, sizeof(ConstExprValue));
8181 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)
413413}
414414
415415static EvalVar *find_var(EvalFn *ef, Buf *name) {
416 int scope_index = ef->scope_stack.length - 1;
417 while (scope_index >= 0) {
416 size_t scope_index = ef->scope_stack.length - 1;
417 while (scope_index != SIZE_MAX) {
418418 EvalScope *scope = ef->scope_stack.at(scope_index);
419 for (int var_i = 0; var_i < scope->vars.length; var_i += 1) {
419 for (size_t var_i = 0; var_i < scope->vars.length; var_i += 1) {
420420 EvalVar *var = &scope->vars.at(var_i);
421421 if (buf_eql_buf(var->name, name)) {
422422 return var;
......@@ -466,18 +466,18 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue *
466466 !container_type->data.structure.is_slice &&
467467 kind == ContainerInitKindStruct)
468468 {
469 int expr_field_count = container_init_expr->entries.length;
470 int actual_field_count = container_type->data.structure.src_field_count;
469 size_t expr_field_count = container_init_expr->entries.length;
470 size_t actual_field_count = container_type->data.structure.src_field_count;
471471 assert(expr_field_count == actual_field_count);
472472
473473 out_val->data.x_struct.fields = allocate<ConstExprValue*>(actual_field_count);
474474
475 for (int i = 0; i < expr_field_count; i += 1) {
475 for (size_t i = 0; i < expr_field_count; i += 1) {
476476 AstNode *val_field_node = container_init_expr->entries.at(i);
477477 assert(val_field_node->type == NodeTypeStructValueField);
478478
479479 TypeStructField *type_field = val_field_node->data.struct_val_field.type_struct_field;
480 int field_index = type_field->src_index;
480 size_t field_index = type_field->src_index;
481481
482482 ConstExprValue src_field_val = {0};
483483 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 *
496496 kind == ContainerInitKindArray)
497497 {
498498
499 int elem_count = container_init_expr->entries.length;
499 size_t elem_count = container_init_expr->entries.length;
500500
501501 out_val->ok = true;
502502 out_val->data.x_array.fields = allocate<ConstExprValue*>(elem_count);
503503
504 for (int i = 0; i < elem_count; i += 1) {
504 for (size_t i = 0; i < elem_count; i += 1) {
505505 AstNode *elem_node = container_init_expr->entries.at(i);
506506
507507 ConstExprValue *elem_val = allocate<ConstExprValue>(1);
......@@ -698,7 +698,7 @@ void eval_const_expr_implicit_cast(CastOp cast_op,
698698static bool int_type_depends_on_compile_var(CodeGen *g, TypeTableEntry *int_type) {
699699 assert(int_type->id == TypeTableEntryIdInt);
700700
701 for (int i = 0; i < CIntTypeCount; i += 1) {
701 for (size_t i = 0; i < CIntTypeCount; i += 1) {
702702 if (int_type == g->builtin_types.entry_c_int[i]) {
703703 return true;
704704 }
......@@ -918,9 +918,9 @@ static bool eval_fn_call_expr(EvalFn *ef, AstNode *node, ConstExprValue *out_val
918918 fn_table_entry = fn_val.data.x_fn;
919919 }
920920
921 int param_count = node->data.fn_call_expr.params.length;
921 size_t param_count = node->data.fn_call_expr.params.length;
922922 ConstExprValue *args = allocate<ConstExprValue>(param_count);
923 for (int call_i = 0; call_i < param_count; call_i += 1) {
923 for (size_t call_i = 0; call_i < param_count; call_i += 1) {
924924 AstNode *param_expr_node = node->data.fn_call_expr.params.at(call_i);
925925 ConstExprValue *param_val = &args[call_i];
926926 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
13401340 root_scope->block_context = fn->fn_def_node->data.fn_def.body->block_context;
13411341 ef.scope_stack.append(root_scope);
13421342
1343 int param_count = acting_proto_node->data.fn_proto.params.length;
1344 for (int proto_i = 0; proto_i < param_count; proto_i += 1) {
1343 size_t param_count = acting_proto_node->data.fn_proto.params.length;
1344 for (size_t proto_i = 0; proto_i < param_count; proto_i += 1) {
13451345 AstNode *decl_param_node = acting_proto_node->data.fn_proto.params.at(proto_i);
13461346 assert(decl_param_node->type == NodeTypeParamDecl);
13471347
......@@ -1358,7 +1358,7 @@ static bool eval_fn_args(EvalFnRoot *efr, FnTableEntry *fn, ConstExprValue *args
13581358}
13591359
13601360bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_val,
1361 int branch_quota, AstNode *struct_node)
1361 size_t branch_quota, AstNode *struct_node)
13621362{
13631363 assert(node->type == NodeTypeFnCallExpr);
13641364
......@@ -1375,17 +1375,17 @@ bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_va
13751375 acting_proto_node = fn->proto_node;
13761376 }
13771377
1378 int call_param_count = node->data.fn_call_expr.params.length;
1379 int proto_param_count = acting_proto_node->data.fn_proto.params.length;
1378 size_t call_param_count = node->data.fn_call_expr.params.length;
1379 size_t proto_param_count = acting_proto_node->data.fn_proto.params.length;
13801380 ConstExprValue *args = allocate<ConstExprValue>(proto_param_count);
1381 int next_arg_index = 0;
1381 size_t next_arg_index = 0;
13821382 if (struct_node) {
13831383 ConstExprValue *struct_val = &get_resolved_expr(struct_node)->const_val;
13841384 assert(struct_val->ok);
13851385 args[next_arg_index] = *struct_val;
13861386 next_arg_index += 1;
13871387 }
1388 for (int call_index = 0; call_index < call_param_count; call_index += 1) {
1388 for (size_t call_index = 0; call_index < call_param_count; call_index += 1) {
13891389 AstNode *call_param_node = node->data.fn_call_expr.params.at(call_index);
13901390 ConstExprValue *src_const_val = &get_resolved_expr(call_param_node)->const_val;
13911391 assert(src_const_val->ok);
......@@ -1396,7 +1396,7 @@ bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_va
13961396
13971397 if (efr.exceeded_quota_node) {
13981398 ErrorMsg *msg = add_node_error(g, fn->fn_def_node,
1399 buf_sprintf("function evaluation exceeded %d branches", efr.branch_quota));
1399 buf_sprintf("function evaluation exceeded %zu branches", efr.branch_quota));
14001400
14011401 add_error_note(g, msg, efr.call_node, buf_sprintf("called from here"));
14021402 add_error_note(g, msg, efr.exceeded_quota_node, buf_sprintf("quota exceeded here"));
src/eval.hpp+1-1
......@@ -10,7 +10,7 @@
1010
1111#include "all_types.hpp"
1212
13bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_val, int branch_quota,
13bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_val, size_t branch_quota,
1414 AstNode *struct_node);
1515
1616bool const_values_equal(ConstExprValue *a, ConstExprValue *b, TypeTableEntry *type_entry);
src/link.cpp+11-11
......@@ -172,9 +172,9 @@ static void construct_linker_job_linux(LinkJob *lj) {
172172 lj->args.append("-shared");
173173
174174 buf_resize(&lj->out_file, 0);
175 buf_appendf(&lj->out_file, "lib%s.so.%d.%d.%d",
175 buf_appendf(&lj->out_file, "lib%s.so.%zu.%zu.%zu",
176176 buf_ptr(g->root_out_name), g->version_major, g->version_minor, g->version_patch);
177 soname = buf_sprintf("lib%s.so.%d", buf_ptr(g->root_out_name), g->version_major);
177 soname = buf_sprintf("lib%s.so.%zu", buf_ptr(g->root_out_name), g->version_major);
178178 }
179179
180180 lj->args.append("-o");
......@@ -195,7 +195,7 @@ static void construct_linker_job_linux(LinkJob *lj) {
195195 lj->args.append(get_libc_static_file(g, crtbegino));
196196 }
197197
198 for (int i = 0; i < g->lib_dirs.length; i += 1) {
198 for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
199199 const char *lib_dir = g->lib_dirs.at(i);
200200 lj->args.append("-L");
201201 lj->args.append(lib_dir);
......@@ -239,7 +239,7 @@ static void construct_linker_job_linux(LinkJob *lj) {
239239 lj->args.append(buf_ptr(compiler_rt_o_path));
240240 }
241241
242 for (int i = 0; i < g->link_libs.length; i += 1) {
242 for (size_t i = 0; i < g->link_libs.length; i += 1) {
243243 Buf *link_lib = g->link_libs.at(i);
244244 Buf *arg;
245245 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) {
350350 lj->args.append(get_libc_static_file(g, "crtbegin.o"));
351351 }
352352
353 for (int i = 0; i < g->lib_dirs.length; i += 1) {
353 for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
354354 const char *lib_dir = g->lib_dirs.at(i);
355355 lj->args.append("-L");
356356 lj->args.append(lib_dir);
......@@ -381,7 +381,7 @@ static void construct_linker_job_mingw(LinkJob *lj) {
381381 }
382382
383383
384 for (int i = 0; i < g->link_libs.length; i += 1) {
384 for (size_t i = 0; i < g->link_libs.length; i += 1) {
385385 Buf *link_lib = g->link_libs.at(i);
386386 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
387387 lj->args.append(buf_ptr(arg));
......@@ -635,7 +635,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {
635635 }
636636 }
637637
638 for (int i = 0; i < g->lib_dirs.length; i += 1) {
638 for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
639639 const char *lib_dir = g->lib_dirs.at(i);
640640 lj->args.append("-L");
641641 lj->args.append(lib_dir);
......@@ -649,7 +649,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {
649649 lj->args.append(buf_ptr(test_runner_o_path));
650650 }
651651
652 for (int i = 0; i < g->link_libs.length; i += 1) {
652 for (size_t i = 0; i < g->link_libs.length; i += 1) {
653653 Buf *link_lib = g->link_libs.at(i);
654654 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
655655 lj->args.append(buf_ptr(arg));
......@@ -671,7 +671,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {
671671 zig_panic("TODO");
672672 }
673673
674 for (int i = 0; i < g->darwin_frameworks.length; i += 1) {
674 for (size_t i = 0; i < g->darwin_frameworks.length; i += 1) {
675675 lj->args.append("-framework");
676676 lj->args.append(buf_ptr(g->darwin_frameworks.at(i)));
677677 }
......@@ -829,7 +829,7 @@ void codegen_link(CodeGen *g, const char *out_file) {
829829
830830 if (g->verbose) {
831831 fprintf(stderr, "%s", buf_ptr(g->linker_path));
832 for (int i = 0; i < lj.args.length; i += 1) {
832 for (size_t i = 0; i < lj.args.length; i += 1) {
833833 fprintf(stderr, " %s", lj.args.at(i));
834834 }
835835 fprintf(stderr, "\n");
......@@ -853,7 +853,7 @@ void codegen_link(CodeGen *g, const char *out_file) {
853853 fprintf(stderr, "linker failed\n");
854854 }
855855 fprintf(stderr, "%s ", buf_ptr(g->linker_path));
856 for (int i = 0; i < lj.args.length; i += 1) {
856 for (size_t i = 0; i < lj.args.length; i += 1) {
857857 fprintf(stderr, "%s ", lj.args.at(i));
858858 }
859859 fprintf(stderr, "\n%s\n", buf_ptr(&ld_stderr));
src/list.hpp+20-17
......@@ -23,13 +23,13 @@ struct ZigList {
2323 }
2424 // remember that the pointer to this item is invalid after you
2525 // modify the length of the list
26 const T & at(int index) const {
27 assert(index >= 0);
26 const T & at(size_t index) const {
27 assert(index != SIZE_MAX);
2828 assert(index < length);
2929 return items[index];
3030 }
31 T & at(int index) {
32 assert(index >= 0);
31 T & at(size_t index) {
32 assert(index != SIZE_MAX);
3333 assert(index < length);
3434 return items[index];
3535 }
......@@ -52,8 +52,8 @@ struct ZigList {
5252 return items[length - 1];
5353 }
5454
55 void resize(int new_length) {
56 assert(new_length >= 0);
55 void resize(size_t new_length) {
56 assert(new_length != SIZE_MAX);
5757 ensure_capacity(new_length);
5858 length = new_length;
5959 }
......@@ -62,19 +62,22 @@ struct ZigList {
6262 length = 0;
6363 }
6464
65 void ensure_capacity(int new_capacity) {
66 int better_capacity = max(capacity, 16);
67 while (better_capacity < new_capacity)
68 better_capacity = better_capacity * 2;
69 if (better_capacity != capacity) {
70 items = reallocate_nonzero(items, better_capacity);
71 capacity = better_capacity;
72 }
65 void ensure_capacity(size_t new_capacity) {
66 if (capacity >= new_capacity)
67 return;
68
69 size_t better_capacity = capacity;
70 do {
71 better_capacity = better_capacity * 1.4 + 8;
72 } while (better_capacity < new_capacity);
73
74 items = reallocate_nonzero(items, capacity, better_capacity);
75 capacity = better_capacity;
7376 }
7477
75 T * items;
76 int length;
77 int capacity;
78 T *items;
79 size_t length;
80 size_t capacity;
7881};
7982
8083#endif
src/main.cpp+9-9
......@@ -64,8 +64,8 @@ static int print_target_list(FILE *f) {
6464 get_native_target(&native);
6565
6666 fprintf(f, "Architectures:\n");
67 int arch_count = target_arch_count();
68 for (int arch_i = 0; arch_i < arch_count; arch_i += 1) {
67 size_t arch_count = target_arch_count();
68 for (size_t arch_i = 0; arch_i < arch_count; arch_i += 1) {
6969 const ArchType *arch = get_target_arch(arch_i);
7070 char arch_name[50];
7171 get_arch_name(arch_name, arch);
......@@ -75,16 +75,16 @@ static int print_target_list(FILE *f) {
7575 }
7676
7777 fprintf(f, "\nOperating Systems:\n");
78 int os_count = target_os_count();
79 for (int i = 0; i < os_count; i += 1) {
78 size_t os_count = target_os_count();
79 for (size_t i = 0; i < os_count; i += 1) {
8080 ZigLLVM_OSType os_type = get_target_os(i);
8181 const char *native_str = (native.os == os_type) ? " (native)" : "";
8282 fprintf(f, " %s%s\n", get_target_os_name(os_type), native_str);
8383 }
8484
8585 fprintf(f, "\nEnvironments:\n");
86 int environ_count = target_environ_count();
87 for (int i = 0; i < environ_count; i += 1) {
86 size_t environ_count = target_environ_count();
87 for (size_t i = 0; i < environ_count; i += 1) {
8888 ZigLLVM_EnvironmentType environ_type = get_target_environ(i);
8989 const char *native_str = (native.env_type == environ_type) ? " (native)" : "";
9090 fprintf(f, " %s%s\n", ZigLLVMGetEnvironmentTypeName(environ_type), native_str);
......@@ -375,13 +375,13 @@ int main(int argc, char **argv) {
375375 codegen_set_verbose(g, verbose);
376376 codegen_set_errmsg_color(g, color);
377377
378 for (int i = 0; i < lib_dirs.length; i += 1) {
378 for (size_t i = 0; i < lib_dirs.length; i += 1) {
379379 codegen_add_lib_dir(g, lib_dirs.at(i));
380380 }
381 for (int i = 0; i < link_libs.length; i += 1) {
381 for (size_t i = 0; i < link_libs.length; i += 1) {
382382 codegen_add_link_lib(g, link_libs.at(i));
383383 }
384 for (int i = 0; i < frameworks.length; i += 1) {
384 for (size_t i = 0; i < frameworks.length; i += 1) {
385385 codegen_add_framework(g, frameworks.at(i));
386386 }
387387
src/os.cpp+25-20
......@@ -73,7 +73,7 @@ static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args,
7373 const char **argv = allocate<const char *>(args.length + 2);
7474 argv[0] = exe;
7575 argv[args.length + 1] = nullptr;
76 for (int i = 0; i < args.length; i += 1) {
76 for (size_t i = 0; i < args.length; i += 1) {
7777 argv[i + 1] = args.at(i);
7878 }
7979 execvp(exe, const_cast<char * const *>(argv));
......@@ -114,20 +114,25 @@ void os_path_dirname(Buf *full_path, Buf *out_dirname) {
114114}
115115
116116void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename) {
117 int last_index = buf_len(full_path) - 1;
118 if (last_index >= 0 && buf_ptr(full_path)[last_index] == '/') {
119 last_index -= 1;
120 }
121 for (int i = last_index; i >= 0; i -= 1) {
122 uint8_t c = buf_ptr(full_path)[i];
123 if (c == '/') {
124 if (out_dirname) {
125 buf_init_from_mem(out_dirname, buf_ptr(full_path), i);
126 }
127 if (out_basename) {
128 buf_init_from_mem(out_basename, buf_ptr(full_path) + i + 1, buf_len(full_path) - (i + 1));
117 size_t len = buf_len(full_path);
118 if (len != 0) {
119 size_t last_index = len - 1;
120 if (buf_ptr(full_path)[last_index] == '/') {
121 last_index -= 1;
122 }
123 for (size_t i = last_index;;) {
124 uint8_t c = buf_ptr(full_path)[i];
125 if (c == '/') {
126 if (out_dirname) {
127 buf_init_from_mem(out_dirname, buf_ptr(full_path), i);
128 }
129 if (out_basename) {
130 buf_init_from_mem(out_basename, buf_ptr(full_path) + i + 1, buf_len(full_path) - (i + 1));
131 }
132 return;
129133 }
130 return;
134 if (i == 0) break;
135 i -= 1;
131136 }
132137 }
133138 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,
246251 const char **argv = allocate<const char *>(args.length + 2);
247252 argv[0] = exe;
248253 argv[args.length + 1] = nullptr;
249 for (int i = 0; i < args.length; i += 1) {
254 for (size_t i = 0; i < args.length; i += 1) {
250255 argv[i + 1] = args.at(i);
251256 }
252257 execvp(exe, const_cast<char * const *>(argv));
......@@ -297,11 +302,11 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args,
297302 buf_append_str(&command_line, exe);
298303 buf_append_char(&command_line, '\"');
299304
300 for (int arg_i = 0; arg_i < args.length; arg_i += 1) {
305 for (size_t arg_i = 0; arg_i < args.length; arg_i += 1) {
301306 buf_append_str(&command_line, " \"");
302307 const char *arg = args.at(arg_i);
303 int arg_len = strlen(arg);
304 for (int c_i = 0; c_i < arg_len; c_i += 1) {
308 size_t arg_len = strlen(arg);
309 for (size_t c_i = 0; c_i < arg_len; c_i += 1) {
305310 if (arg[c_i] == '\"') {
306311 zig_panic("TODO");
307312 }
......@@ -376,7 +381,7 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args,
376381 CloseHandle(g_hChildStd_ERR_Wr);
377382 CloseHandle(g_hChildStd_OUT_Wr);
378383
379 static const int BUF_SIZE = 4 * 1024;
384 static const size_t BUF_SIZE = 4 * 1024;
380385 {
381386 DWORD dwRead;
382387 char chBuf[BUF_SIZE];
......@@ -540,7 +545,7 @@ static int os_buf_to_tmp_file_windows(Buf *contents, Buf *suffix, Buf *out_tmp_p
540545
541546 const char base64[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
542547 assert(array_length(base64) == 64 + 1);
543 for (int i = 0; i < 8; i += 1) {
548 for (size_t i = 0; i < 8; i += 1) {
544549 buf_append_char(out_tmp_path, base64[rand() % 64]);
545550 }
546551
src/parseh.cpp+11-11
......@@ -244,10 +244,10 @@ static AstNode *create_fn_proto_node(Context *c, Buf *name, TypeTableEntry *fn_t
244244 node->data.fn_proto.name = name;
245245 node->data.fn_proto.return_type = make_type_node(c, fn_type->data.fn.fn_type_id.return_type);
246246
247 for (int i = 0; i < fn_type->data.fn.fn_type_id.param_count; i += 1) {
247 for (size_t i = 0; i < fn_type->data.fn.fn_type_id.param_count; i += 1) {
248248 FnTypeParamInfo *info = &fn_type->data.fn.fn_type_id.param_info[i];
249249 char arg_name[20];
250 sprintf(arg_name, "arg_%d", i);
250 sprintf(arg_name, "arg_%zu", i);
251251 node->data.fn_proto.params.append(create_param_decl_node(c, arg_name,
252252 make_type_node(c, info->type), info->is_noalias));
253253 }
......@@ -272,7 +272,7 @@ static AstNode *create_inline_fn_node(Context *c, Buf *fn_name, Buf *var_name, T
272272
273273 AstNode *fn_call_node = create_node(c, NodeTypeFnCallExpr);
274274 fn_call_node->data.fn_call_expr.fn_ref_expr = unwrap_node;
275 for (int i = 0; i < fn_type->data.fn.fn_type_id.param_count; i += 1) {
275 for (size_t i = 0; i < fn_type->data.fn.fn_type_id.param_count; i += 1) {
276276 AstNode *decl_node = node->data.fn_def.fn_proto->data.fn_proto.params.at(i);
277277 Buf *param_name = decl_node->data.param_decl.name;
278278 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
621621 fn_type_id.param_info = &fn_type_id.prealloc_param_info[0];
622622 }
623623
624 for (int i = 0; i < fn_type_id.param_count; i += 1) {
624 for (size_t i = 0; i < fn_type_id.param_count; i += 1) {
625625 QualType qt = fn_proto_ty->getParamType(i);
626626 TypeTableEntry *param_type = resolve_qual_type(c, qt, decl);
627627
......@@ -748,16 +748,16 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
748748
749749 assert(!fn_type->data.fn.fn_type_id.is_naked);
750750
751 int arg_count = fn_type->data.fn.fn_type_id.param_count;
751 size_t arg_count = fn_type->data.fn.fn_type_id.param_count;
752752 Buf name_buf = BUF_INIT;
753 for (int i = 0; i < arg_count; i += 1) {
753 for (size_t i = 0; i < arg_count; i += 1) {
754754 FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[i];
755755 AstNode *type_node = make_type_node(c, param_info->type);
756756 const ParmVarDecl *param = fn_decl->getParamDecl(i);
757757 const char *name = decl_name(param);
758758 if (strlen(name) == 0) {
759759 buf_resize(&name_buf, 0);
760 buf_appendf(&name_buf, "arg%d", i);
760 buf_appendf(&name_buf, "arg%zu", i);
761761 name = buf_ptr(&name_buf);
762762 }
763763
......@@ -1316,7 +1316,7 @@ static bool name_exists_and_const(Context *c, Buf *name) {
13161316}
13171317
13181318static void render_aliases(Context *c) {
1319 for (int i = 0; i < c->aliases.length; i += 1) {
1319 for (size_t i = 0; i < c->aliases.length; i += 1) {
13201320 AstNode *alias_node = c->aliases.at(i);
13211321 assert(alias_node->type == NodeTypeVariableDeclaration);
13221322 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
13471347 }
13481348
13491349 bool negate = false;
1350 for (int i = 0; i < ctok->tokens.length; i += 1) {
1350 for (size_t i = 0; i < ctok->tokens.length; i += 1) {
13511351 bool is_first = (i == 0);
13521352 bool is_last = (i == ctok->tokens.length - 1);
13531353 CTok *tok = &ctok->tokens.at(i);
......@@ -1403,7 +1403,7 @@ static void process_macro(Context *c, CTokenize *ctok, Buf *name, const char *ch
14031403}
14041404
14051405static void process_symbol_macros(Context *c) {
1406 for (int i = 0; i < c->macro_symbols.length; i += 1) {
1406 for (size_t i = 0; i < c->macro_symbols.length; i += 1) {
14071407 MacroSymbol ms = c->macro_symbols.at(i);
14081408 if (name_exists_and_const(c, ms.value)) {
14091409 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
15241524 clang_argv.append("-isystem");
15251525 clang_argv.append(buf_ptr(codegen->libc_include_dir));
15261526
1527 for (int i = 0; i < codegen->clang_argv_len; i += 1) {
1527 for (size_t i = 0; i < codegen->clang_argv_len; i += 1) {
15281528 clang_argv.append(codegen->clang_argv[i]);
15291529 }
15301530
src/parser.cpp+76-76
......@@ -28,7 +28,7 @@ struct ParseContext {
2828
2929__attribute__ ((format (printf, 4, 5)))
3030__attribute__ ((noreturn))
31static void ast_asm_error(ParseContext *pc, AstNode *node, int offset, const char *format, ...) {
31static void ast_asm_error(ParseContext *pc, AstNode *node, size_t offset, const char *format, ...) {
3232 assert(node->type == NodeTypeAsmExpr);
3333
3434
......@@ -109,7 +109,7 @@ static void parse_asm_template(ParseContext *pc, AstNode *node) {
109109
110110 enum State state = StateStart;
111111
112 for (int i = 0; i < buf_len(asm_template); i += 1) {
112 for (size_t i = 0; i < buf_len(asm_template); i += 1) {
113113 uint8_t c = *((uint8_t*)buf_ptr(asm_template) + i);
114114 switch (state) {
115115 case StateStart:
......@@ -205,16 +205,16 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {
205205 ast_error(pc, token, "invalid token: '%s'", buf_ptr(&token_value));
206206}
207207
208static AstNode *ast_parse_expression(ParseContext *pc, int *token_index, bool mandatory);
209static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandatory);
210static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool mandatory);
211static AstNode *ast_parse_block_expr(ParseContext *pc, int *token_index, bool mandatory);
212static AstNode *ast_parse_unwrap_expr(ParseContext *pc, int *token_index, bool mandatory);
213static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, bool mandatory);
214static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory,
208static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool mandatory);
209static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mandatory);
210static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool mandatory);
211static AstNode *ast_parse_block_expr(ParseContext *pc, size_t *token_index, bool mandatory);
212static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory);
213static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory);
214static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory,
215215 ZigList<AstNode*> *directives, VisibMod visib_mod);
216static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index);
217static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool mandatory);
216static AstNode *ast_parse_return_expr(ParseContext *pc, size_t *token_index);
217static AstNode *ast_parse_grouped_expr(ParseContext *pc, size_t *token_index, bool mandatory);
218218
219219static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {
220220 if (token->id == token_id) {
......@@ -226,7 +226,7 @@ static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {
226226 ast_error(pc, token, "expected token '%s', found '%s'", token_name(token_id), token_name(token->id));
227227}
228228
229static Token *ast_eat_token(ParseContext *pc, int *token_index, TokenId token_id) {
229static Token *ast_eat_token(ParseContext *pc, size_t *token_index, TokenId token_id) {
230230 Token *token = &pc->tokens->at(*token_index);
231231 ast_expect_token(pc, token, token_id);
232232 *token_index += 1;
......@@ -236,7 +236,7 @@ static Token *ast_eat_token(ParseContext *pc, int *token_index, TokenId token_id
236236/*
237237Directive = "#" "Symbol" "(" Expression ")"
238238*/
239static AstNode *ast_parse_directive(ParseContext *pc, int *token_index) {
239static AstNode *ast_parse_directive(ParseContext *pc, size_t *token_index) {
240240 Token *number_sign = ast_eat_token(pc, token_index, TokenIdNumberSign);
241241
242242 AstNode *node = ast_create_node(pc, NodeTypeDirective, number_sign);
......@@ -251,7 +251,7 @@ static AstNode *ast_parse_directive(ParseContext *pc, int *token_index) {
251251 return node;
252252}
253253
254static void ast_parse_directives(ParseContext *pc, int *token_index,
254static void ast_parse_directives(ParseContext *pc, size_t *token_index,
255255 ZigList<AstNode *> *directives)
256256{
257257 for (;;) {
......@@ -269,7 +269,7 @@ static void ast_parse_directives(ParseContext *pc, int *token_index,
269269/*
270270TypeExpr = PrefixOpExpression | "var"
271271*/
272static AstNode *ast_parse_type_expr(ParseContext *pc, int *token_index, bool mandatory) {
272static AstNode *ast_parse_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
273273 Token *token = &pc->tokens->at(*token_index);
274274 if (token->id == TokenIdKeywordVar) {
275275 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
283283/*
284284ParamDecl = option("noalias" | "inline") option("Symbol" ":") TypeExpr | "..."
285285*/
286static AstNode *ast_parse_param_decl(ParseContext *pc, int *token_index) {
286static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) {
287287 Token *token = &pc->tokens->at(*token_index);
288288
289289 if (token->id == TokenIdEllipsis) {
......@@ -320,7 +320,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, int *token_index) {
320320}
321321
322322
323static void ast_parse_param_decl_list(ParseContext *pc, int *token_index,
323static void ast_parse_param_decl_list(ParseContext *pc, size_t *token_index,
324324 ZigList<AstNode *> *params, bool *is_var_args)
325325{
326326 *is_var_args = false;
......@@ -356,7 +356,7 @@ static void ast_parse_param_decl_list(ParseContext *pc, int *token_index,
356356 zig_unreachable();
357357}
358358
359static void ast_parse_fn_call_param_list(ParseContext *pc, int *token_index, ZigList<AstNode*> *params) {
359static void ast_parse_fn_call_param_list(ParseContext *pc, size_t *token_index, ZigList<AstNode*> *params) {
360360 Token *token = &pc->tokens->at(*token_index);
361361 if (token->id == TokenIdRParen) {
362362 *token_index += 1;
......@@ -381,7 +381,7 @@ static void ast_parse_fn_call_param_list(ParseContext *pc, int *token_index, Zig
381381/*
382382GroupedExpression : token(LParen) Expression token(RParen)
383383*/
384static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool mandatory) {
384static AstNode *ast_parse_grouped_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
385385 Token *l_paren = &pc->tokens->at(*token_index);
386386 if (l_paren->id != TokenIdLParen) {
387387 if (mandatory) {
......@@ -405,7 +405,7 @@ static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool
405405/*
406406ArrayType : "[" option(Expression) "]" option("const") PrefixOpExpression
407407*/
408static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bool mandatory) {
408static AstNode *ast_parse_array_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
409409 Token *l_bracket = &pc->tokens->at(*token_index);
410410 if (l_bracket->id != TokenIdLBracket) {
411411 if (mandatory) {
......@@ -437,7 +437,7 @@ static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bo
437437/*
438438AsmInputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) Expression token(RParen)
439439*/
440static void ast_parse_asm_input_item(ParseContext *pc, int *token_index, AstNode *node) {
440static void ast_parse_asm_input_item(ParseContext *pc, size_t *token_index, AstNode *node) {
441441 ast_eat_token(pc, token_index, TokenIdLBracket);
442442 Token *alias = ast_eat_token(pc, token_index, TokenIdSymbol);
443443 ast_eat_token(pc, token_index, TokenIdRBracket);
......@@ -458,7 +458,7 @@ static void ast_parse_asm_input_item(ParseContext *pc, int *token_index, AstNode
458458/*
459459AsmOutputItem : "[" "Symbol" "]" "String" "(" ("Symbol" | "->" PrefixOpExpression) ")"
460460*/
461static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNode *node) {
461static void ast_parse_asm_output_item(ParseContext *pc, size_t *token_index, AstNode *node) {
462462 ast_eat_token(pc, token_index, TokenIdLBracket);
463463 Token *alias = ast_eat_token(pc, token_index, TokenIdSymbol);
464464 ast_eat_token(pc, token_index, TokenIdRBracket);
......@@ -489,7 +489,7 @@ static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNod
489489/*
490490AsmClobbers: token(Colon) list(token(String), token(Comma))
491491*/
492static void ast_parse_asm_clobbers(ParseContext *pc, int *token_index, AstNode *node) {
492static void ast_parse_asm_clobbers(ParseContext *pc, size_t *token_index, AstNode *node) {
493493 Token *colon_tok = &pc->tokens->at(*token_index);
494494
495495 if (colon_tok->id != TokenIdColon)
......@@ -519,7 +519,7 @@ static void ast_parse_asm_clobbers(ParseContext *pc, int *token_index, AstNode *
519519/*
520520AsmInput : token(Colon) list(AsmInputItem, token(Comma)) option(AsmClobbers)
521521*/
522static void ast_parse_asm_input(ParseContext *pc, int *token_index, AstNode *node) {
522static void ast_parse_asm_input(ParseContext *pc, size_t *token_index, AstNode *node) {
523523 Token *colon_tok = &pc->tokens->at(*token_index);
524524
525525 if (colon_tok->id != TokenIdColon)
......@@ -546,7 +546,7 @@ static void ast_parse_asm_input(ParseContext *pc, int *token_index, AstNode *nod
546546/*
547547AsmOutput : token(Colon) list(AsmOutputItem, token(Comma)) option(AsmInput)
548548*/
549static void ast_parse_asm_output(ParseContext *pc, int *token_index, AstNode *node) {
549static void ast_parse_asm_output(ParseContext *pc, size_t *token_index, AstNode *node) {
550550 Token *colon_tok = &pc->tokens->at(*token_index);
551551
552552 if (colon_tok->id != TokenIdColon)
......@@ -579,7 +579,7 @@ static void ast_parse_asm_output(ParseContext *pc, int *token_index, AstNode *no
579579/*
580580AsmExpression : token(Asm) option(token(Volatile)) token(LParen) token(String) option(AsmOutput) token(RParen)
581581*/
582static AstNode *ast_parse_asm_expr(ParseContext *pc, int *token_index, bool mandatory) {
582static AstNode *ast_parse_asm_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
583583 Token *asm_token = &pc->tokens->at(*token_index);
584584
585585 if (asm_token->id != TokenIdKeywordAsm) {
......@@ -622,7 +622,7 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc, int *token_index, bool mand
622622PrimaryExpression = "Number" | "String" | "CharLiteral" | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | "Symbol" | ("@" "Symbol" FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." "Symbol")
623623KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "zeroes" | "error" | "type"
624624*/
625static AstNode *ast_parse_primary_expr(ParseContext *pc, int *token_index, bool mandatory) {
625static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
626626 Token *token = &pc->tokens->at(*token_index);
627627
628628 if (token->id == TokenIdNumberLiteral) {
......@@ -752,7 +752,7 @@ CurlySuffixExpression : PrefixOpExpression option(ContainerInitExpression)
752752ContainerInitExpression : token(LBrace) ContainerInitBody token(RBrace)
753753ContainerInitBody : list(StructLiteralField, token(Comma)) | list(Expression, token(Comma))
754754*/
755static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc, int *token_index, bool mandatory) {
755static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
756756 AstNode *prefix_op_expr = ast_parse_prefix_op_expr(pc, token_index, mandatory);
757757 if (!prefix_op_expr) {
758758 return nullptr;
......@@ -843,7 +843,7 @@ SliceExpression : token(LBracket) Expression token(Ellipsis) option(Expression)
843843FieldAccessExpression : token(Dot) token(Symbol)
844844StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression
845845*/
846static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, int *token_index, bool mandatory) {
846static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
847847 AstNode *primary_expr = ast_parse_primary_expr(pc, token_index, mandatory);
848848 if (!primary_expr) {
849849 return nullptr;
......@@ -936,7 +936,7 @@ static PrefixOp tok_to_prefix_op(Token *token) {
936936PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression
937937PrefixOp = "!" | "-" | "~" | "*" | ("&" option("const")) | "?" | "%" | "%%" | "??" | "-%"
938938*/
939static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, bool mandatory) {
939static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
940940 Token *token = &pc->tokens->at(*token_index);
941941 PrefixOp prefix_op = tok_to_prefix_op(token);
942942 if (prefix_op == PrefixOpInvalid) {
......@@ -1005,7 +1005,7 @@ static BinOpType tok_to_mult_op(Token *token) {
10051005/*
10061006MultiplyOperator = "*" | "/" | "%" | "**" | "*%"
10071007*/
1008static BinOpType ast_parse_mult_op(ParseContext *pc, int *token_index, bool mandatory) {
1008static BinOpType ast_parse_mult_op(ParseContext *pc, size_t *token_index, bool mandatory) {
10091009 Token *token = &pc->tokens->at(*token_index);
10101010 BinOpType result = tok_to_mult_op(token);
10111011 if (result == BinOpTypeInvalid) {
......@@ -1022,7 +1022,7 @@ static BinOpType ast_parse_mult_op(ParseContext *pc, int *token_index, bool mand
10221022/*
10231023MultiplyExpression : CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression
10241024*/
1025static AstNode *ast_parse_mult_expr(ParseContext *pc, int *token_index, bool mandatory) {
1025static AstNode *ast_parse_mult_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
10261026 AstNode *operand_1 = ast_parse_curly_suffix_expr(pc, token_index, mandatory);
10271027 if (!operand_1)
10281028 return nullptr;
......@@ -1059,7 +1059,7 @@ static BinOpType tok_to_add_op(Token *token) {
10591059/*
10601060AdditionOperator = "+" | "-" | "++" | "+%" | "-%"
10611061*/
1062static BinOpType ast_parse_add_op(ParseContext *pc, int *token_index, bool mandatory) {
1062static BinOpType ast_parse_add_op(ParseContext *pc, size_t *token_index, bool mandatory) {
10631063 Token *token = &pc->tokens->at(*token_index);
10641064 BinOpType result = tok_to_add_op(token);
10651065 if (result == BinOpTypeInvalid) {
......@@ -1076,7 +1076,7 @@ static BinOpType ast_parse_add_op(ParseContext *pc, int *token_index, bool manda
10761076/*
10771077AdditionExpression : MultiplyExpression AdditionOperator AdditionExpression | MultiplyExpression
10781078*/
1079static AstNode *ast_parse_add_expr(ParseContext *pc, int *token_index, bool mandatory) {
1079static AstNode *ast_parse_add_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
10801080 AstNode *operand_1 = ast_parse_mult_expr(pc, token_index, mandatory);
10811081 if (!operand_1)
10821082 return nullptr;
......@@ -1111,7 +1111,7 @@ static BinOpType tok_to_bit_shift_op(Token *token) {
11111111/*
11121112BitShiftOperator = "<<" | ">>" | "<<%"
11131113*/
1114static BinOpType ast_parse_bit_shift_op(ParseContext *pc, int *token_index, bool mandatory) {
1114static BinOpType ast_parse_bit_shift_op(ParseContext *pc, size_t *token_index, bool mandatory) {
11151115 Token *token = &pc->tokens->at(*token_index);
11161116 BinOpType result = tok_to_bit_shift_op(token);
11171117 if (result == BinOpTypeInvalid) {
......@@ -1128,7 +1128,7 @@ static BinOpType ast_parse_bit_shift_op(ParseContext *pc, int *token_index, bool
11281128/*
11291129BitShiftExpression : AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression
11301130*/
1131static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, int *token_index, bool mandatory) {
1131static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
11321132 AstNode *operand_1 = ast_parse_add_expr(pc, token_index, mandatory);
11331133 if (!operand_1)
11341134 return nullptr;
......@@ -1155,7 +1155,7 @@ static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, int *token_index, boo
11551155/*
11561156BinaryAndExpression : BitShiftExpression token(Ampersand) BinaryAndExpression | BitShiftExpression
11571157*/
1158static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool mandatory) {
1158static AstNode *ast_parse_bin_and_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
11591159 AstNode *operand_1 = ast_parse_bit_shift_expr(pc, token_index, mandatory);
11601160 if (!operand_1)
11611161 return nullptr;
......@@ -1181,7 +1181,7 @@ static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool
11811181/*
11821182BinaryXorExpression : BinaryAndExpression token(BinXor) BinaryXorExpression | BinaryAndExpression
11831183*/
1184static AstNode *ast_parse_bin_xor_expr(ParseContext *pc, int *token_index, bool mandatory) {
1184static AstNode *ast_parse_bin_xor_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
11851185 AstNode *operand_1 = ast_parse_bin_and_expr(pc, token_index, mandatory);
11861186 if (!operand_1)
11871187 return nullptr;
......@@ -1207,7 +1207,7 @@ static AstNode *ast_parse_bin_xor_expr(ParseContext *pc, int *token_index, bool
12071207/*
12081208BinaryOrExpression : BinaryXorExpression token(BinOr) BinaryOrExpression | BinaryXorExpression
12091209*/
1210static AstNode *ast_parse_bin_or_expr(ParseContext *pc, int *token_index, bool mandatory) {
1210static AstNode *ast_parse_bin_or_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
12111211 AstNode *operand_1 = ast_parse_bin_xor_expr(pc, token_index, mandatory);
12121212 if (!operand_1)
12131213 return nullptr;
......@@ -1242,7 +1242,7 @@ static BinOpType tok_to_cmp_op(Token *token) {
12421242 }
12431243}
12441244
1245static BinOpType ast_parse_comparison_operator(ParseContext *pc, int *token_index, bool mandatory) {
1245static BinOpType ast_parse_comparison_operator(ParseContext *pc, size_t *token_index, bool mandatory) {
12461246 Token *token = &pc->tokens->at(*token_index);
12471247 BinOpType result = tok_to_cmp_op(token);
12481248 if (result == BinOpTypeInvalid) {
......@@ -1259,7 +1259,7 @@ static BinOpType ast_parse_comparison_operator(ParseContext *pc, int *token_inde
12591259/*
12601260ComparisonExpression : BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression
12611261*/
1262static AstNode *ast_parse_comparison_expr(ParseContext *pc, int *token_index, bool mandatory) {
1262static AstNode *ast_parse_comparison_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
12631263 AstNode *operand_1 = ast_parse_bin_or_expr(pc, token_index, mandatory);
12641264 if (!operand_1)
12651265 return nullptr;
......@@ -1283,7 +1283,7 @@ static AstNode *ast_parse_comparison_expr(ParseContext *pc, int *token_index, bo
12831283/*
12841284BoolAndExpression : ComparisonExpression token(BoolAnd) BoolAndExpression | ComparisonExpression
12851285 */
1286static AstNode *ast_parse_bool_and_expr(ParseContext *pc, int *token_index, bool mandatory) {
1286static AstNode *ast_parse_bool_and_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
12871287 AstNode *operand_1 = ast_parse_comparison_expr(pc, token_index, mandatory);
12881288 if (!operand_1)
12891289 return nullptr;
......@@ -1309,7 +1309,7 @@ static AstNode *ast_parse_bool_and_expr(ParseContext *pc, int *token_index, bool
13091309/*
13101310Else : token(Else) Expression
13111311*/
1312static AstNode *ast_parse_else(ParseContext *pc, int *token_index, bool mandatory) {
1312static AstNode *ast_parse_else(ParseContext *pc, size_t *token_index, bool mandatory) {
13131313 Token *else_token = &pc->tokens->at(*token_index);
13141314
13151315 if (else_token->id != TokenIdKeywordElse) {
......@@ -1329,7 +1329,7 @@ IfExpression : IfVarExpression | IfBoolExpression
13291329IfBoolExpression : token(If) token(LParen) Expression token(RParen) Expression option(Else)
13301330IfVarExpression = "if" "(" ("const" | "var") option("*") "Symbol" option(":" TypeExpr) "?=" Expression ")" Expression Option(Else)
13311331*/
1332static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool mandatory) {
1332static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
13331333 Token *if_tok = &pc->tokens->at(*token_index);
13341334 if (if_tok->id != TokenIdKeywordIf) {
13351335 if (mandatory) {
......@@ -1396,7 +1396,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool manda
13961396/*
13971397ReturnExpression : option("%" | "?") "return" option(Expression)
13981398*/
1399static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index) {
1399static AstNode *ast_parse_return_expr(ParseContext *pc, size_t *token_index) {
14001400 Token *token = &pc->tokens->at(*token_index);
14011401
14021402 NodeType node_type;
......@@ -1439,7 +1439,7 @@ static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index) {
14391439/*
14401440Defer = option("%" | "?") "defer" option(Expression)
14411441*/
1442static AstNode *ast_parse_defer_expr(ParseContext *pc, int *token_index) {
1442static AstNode *ast_parse_defer_expr(ParseContext *pc, size_t *token_index) {
14431443 Token *token = &pc->tokens->at(*token_index);
14441444
14451445 NodeType node_type;
......@@ -1482,7 +1482,7 @@ static AstNode *ast_parse_defer_expr(ParseContext *pc, int *token_index) {
14821482/*
14831483VariableDeclaration : ("var" | "const") "Symbol" ("=" Expression | ":" PrefixOpExpression option("=" Expression))
14841484*/
1485static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token_index, bool mandatory,
1485static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *token_index, bool mandatory,
14861486 ZigList<AstNode*> *directives, VisibMod visib_mod)
14871487{
14881488 Token *first_token = &pc->tokens->at(*token_index);
......@@ -1536,7 +1536,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token
15361536/*
15371537BoolOrExpression : BoolAndExpression token(BoolOr) BoolOrExpression | BoolAndExpression
15381538*/
1539static AstNode *ast_parse_bool_or_expr(ParseContext *pc, int *token_index, bool mandatory) {
1539static AstNode *ast_parse_bool_or_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
15401540 AstNode *operand_1 = ast_parse_bool_and_expr(pc, token_index, mandatory);
15411541 if (!operand_1)
15421542 return nullptr;
......@@ -1562,7 +1562,7 @@ static AstNode *ast_parse_bool_or_expr(ParseContext *pc, int *token_index, bool
15621562/*
15631563WhileExpression = "while" "(" Expression option(";" Expression) ")" Expression
15641564*/
1565static AstNode *ast_parse_while_expr(ParseContext *pc, int *token_index, bool mandatory) {
1565static AstNode *ast_parse_while_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
15661566 Token *token = &pc->tokens->at(*token_index);
15671567
15681568 if (token->id != TokenIdKeywordWhile) {
......@@ -1598,7 +1598,7 @@ static AstNode *ast_parse_while_expr(ParseContext *pc, int *token_index, bool ma
15981598 return node;
15991599}
16001600
1601static AstNode *ast_parse_symbol(ParseContext *pc, int *token_index) {
1601static AstNode *ast_parse_symbol(ParseContext *pc, size_t *token_index) {
16021602 Token *token = ast_eat_token(pc, token_index, TokenIdSymbol);
16031603 AstNode *node = ast_create_node(pc, NodeTypeSymbol, token);
16041604 node->data.symbol_expr.symbol = token_buf(token);
......@@ -1608,7 +1608,7 @@ static AstNode *ast_parse_symbol(ParseContext *pc, int *token_index) {
16081608/*
16091609ForExpression = "for" "(" Expression ")" option("|" option("*") "Symbol" option("," "Symbol") "|") Expression
16101610*/
1611static AstNode *ast_parse_for_expr(ParseContext *pc, int *token_index, bool mandatory) {
1611static AstNode *ast_parse_for_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
16121612 Token *token = &pc->tokens->at(*token_index);
16131613
16141614 if (token->id != TokenIdKeywordFor) {
......@@ -1659,7 +1659,7 @@ SwitchExpression : "switch" "(" Expression ")" "{" many(SwitchProng) "}"
16591659SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" "Symbol" "|") Expression ","
16601660SwitchItem : Expression | (Expression "..." Expression)
16611661*/
1662static AstNode *ast_parse_switch_expr(ParseContext *pc, int *token_index, bool mandatory) {
1662static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
16631663 Token *token = &pc->tokens->at(*token_index);
16641664
16651665 if (token->id != TokenIdKeywordSwitch) {
......@@ -1736,7 +1736,7 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, int *token_index, bool m
17361736/*
17371737BlockExpression : IfExpression | Block | WhileExpression | ForExpression | SwitchExpression
17381738*/
1739static AstNode *ast_parse_block_expr(ParseContext *pc, int *token_index, bool mandatory) {
1739static AstNode *ast_parse_block_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
17401740 Token *token = &pc->tokens->at(*token_index);
17411741
17421742 AstNode *if_expr = ast_parse_if_expr(pc, token_index, false);
......@@ -1791,7 +1791,7 @@ static BinOpType tok_to_ass_op(Token *token) {
17911791/*
17921792AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "&&=" | "||=" | "*%=" | "+%=" | "-%=" | "<<%="
17931793*/
1794static BinOpType ast_parse_ass_op(ParseContext *pc, int *token_index, bool mandatory) {
1794static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool mandatory) {
17951795 Token *token = &pc->tokens->at(*token_index);
17961796 BinOpType result = tok_to_ass_op(token);
17971797 if (result == BinOpTypeInvalid) {
......@@ -1810,7 +1810,7 @@ UnwrapExpression : BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpressi
18101810UnwrapMaybe : "??" BoolOrExpression
18111811UnwrapError : "%%" option("|" "Symbol" "|") BoolOrExpression
18121812*/
1813static AstNode *ast_parse_unwrap_expr(ParseContext *pc, int *token_index, bool mandatory) {
1813static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
18141814 AstNode *lhs = ast_parse_bool_or_expr(pc, token_index, mandatory);
18151815 if (!lhs)
18161816 return nullptr;
......@@ -1853,7 +1853,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, int *token_index, bool m
18531853/*
18541854AssignmentExpression : UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression
18551855*/
1856static AstNode *ast_parse_ass_expr(ParseContext *pc, int *token_index, bool mandatory) {
1856static AstNode *ast_parse_ass_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
18571857 AstNode *lhs = ast_parse_unwrap_expr(pc, token_index, mandatory);
18581858 if (!lhs)
18591859 return nullptr;
......@@ -1877,7 +1877,7 @@ static AstNode *ast_parse_ass_expr(ParseContext *pc, int *token_index, bool mand
18771877/*
18781878NonBlockExpression : ReturnExpression | AssignmentExpression
18791879*/
1880static AstNode *ast_parse_non_block_expr(ParseContext *pc, int *token_index, bool mandatory) {
1880static AstNode *ast_parse_non_block_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
18811881 Token *token = &pc->tokens->at(*token_index);
18821882
18831883 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
18971897/*
18981898Expression : BlockExpression | NonBlockExpression
18991899*/
1900static AstNode *ast_parse_expression(ParseContext *pc, int *token_index, bool mandatory) {
1900static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool mandatory) {
19011901 Token *token = &pc->tokens->at(*token_index);
19021902
19031903 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
19171917/*
19181918Label: token(Symbol) token(Colon)
19191919*/
1920static AstNode *ast_parse_label(ParseContext *pc, int *token_index, bool mandatory) {
1920static AstNode *ast_parse_label(ParseContext *pc, size_t *token_index, bool mandatory) {
19211921 Token *symbol_token = &pc->tokens->at(*token_index);
19221922 if (symbol_token->id != TokenIdSymbol) {
19231923 if (mandatory) {
......@@ -1956,7 +1956,7 @@ static AstNode *ast_create_void_expr(ParseContext *pc, Token *token) {
19561956Block : token(LBrace) list(option(Statement), token(Semicolon)) token(RBrace)
19571957Statement = Label | VariableDeclaration ";" | Defer ";" | NonBlockExpression ";" | BlockExpression
19581958*/
1959static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandatory) {
1959static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mandatory) {
19601960 Token *last_token = &pc->tokens->at(*token_index);
19611961
19621962 if (last_token->id != TokenIdLBrace) {
......@@ -2021,7 +2021,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato
20212021/*
20222022FnProto = "fn" option("Symbol") ParamDeclList option("->" TypeExpr)
20232023*/
2024static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory,
2024static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory,
20252025 ZigList<AstNode*> *directives, VisibMod visib_mod)
20262026{
20272027 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
20642064/*
20652065FnDef = option("inline" | "extern") FnProto Block
20662066*/
2067static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandatory,
2067static AstNode *ast_parse_fn_def(ParseContext *pc, size_t *token_index, bool mandatory,
20682068 ZigList<AstNode*> *directives, VisibMod visib_mod)
20692069{
20702070 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
21112111/*
21122112ExternDecl = "extern" (FnProto | VariableDeclaration) ";"
21132113*/
2114static AstNode *ast_parse_extern_decl(ParseContext *pc, int *token_index, bool mandatory,
2114static AstNode *ast_parse_extern_decl(ParseContext *pc, size_t *token_index, bool mandatory,
21152115 ZigList<AstNode *> *directives, VisibMod visib_mod)
21162116{
21172117 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
21512151/*
21522152UseDecl = "use" Expression ";"
21532153*/
2154static AstNode *ast_parse_use(ParseContext *pc, int *token_index,
2154static AstNode *ast_parse_use(ParseContext *pc, size_t *token_index,
21552155 ZigList<AstNode*> *directives, VisibMod visib_mod)
21562156{
21572157 Token *use_kw = &pc->tokens->at(*token_index);
......@@ -2175,7 +2175,7 @@ ContainerDecl = ("struct" | "enum" | "union") "Symbol" option(ParamDeclList) "{"
21752175StructMember = many(Directive) option(VisibleMod) (StructField | FnDef | GlobalVarDecl | ContainerDecl)
21762176StructField : "Symbol" option(":" Expression) ",")
21772177*/
2178static AstNode *ast_parse_container_decl(ParseContext *pc, int *token_index,
2178static AstNode *ast_parse_container_decl(ParseContext *pc, size_t *token_index,
21792179 ZigList<AstNode*> *directives, VisibMod visib_mod)
21802180{
21812181 Token *first_token = &pc->tokens->at(*token_index);
......@@ -2289,7 +2289,7 @@ static AstNode *ast_parse_container_decl(ParseContext *pc, int *token_index,
22892289/*
22902290ErrorValueDecl : "error" "Symbol" ";"
22912291*/
2292static AstNode *ast_parse_error_value_decl(ParseContext *pc, int *token_index,
2292static AstNode *ast_parse_error_value_decl(ParseContext *pc, size_t *token_index,
22932293 ZigList<AstNode*> *directives, VisibMod visib_mod)
22942294{
22952295 Token *first_token = &pc->tokens->at(*token_index);
......@@ -2314,7 +2314,7 @@ static AstNode *ast_parse_error_value_decl(ParseContext *pc, int *token_index,
23142314/*
23152315TypeDecl = "type" "Symbol" "=" TypeExpr ";"
23162316*/
2317static AstNode *ast_parse_type_decl(ParseContext *pc, int *token_index,
2317static AstNode *ast_parse_type_decl(ParseContext *pc, size_t *token_index,
23182318 ZigList<AstNode*> *directives, VisibMod visib_mod)
23192319{
23202320 Token *first_token = &pc->tokens->at(*token_index);
......@@ -2343,7 +2343,7 @@ static AstNode *ast_parse_type_decl(ParseContext *pc, int *token_index,
23432343/*
23442344TopLevelDecl = many(Directive) option(VisibleMod) (FnDef | ExternDecl | Import | ContainerDecl | GlobalVarDecl | ErrorValueDecl | CImportDecl | TypeDecl)
23452345*/
2346static void ast_parse_top_level_decls(ParseContext *pc, int *token_index, ZigList<AstNode *> *top_level_decls) {
2346static void ast_parse_top_level_decls(ParseContext *pc, size_t *token_index, ZigList<AstNode *> *top_level_decls) {
23472347 for (;;) {
23482348 Token *directive_token = &pc->tokens->at(*token_index);
23492349 ZigList<AstNode *> *directives = allocate<ZigList<AstNode*>>(1);
......@@ -2417,7 +2417,7 @@ static void ast_parse_top_level_decls(ParseContext *pc, int *token_index, ZigLis
24172417/*
24182418Root : many(TopLevelDecl) token(EOF)
24192419 */
2420static AstNode *ast_parse_root(ParseContext *pc, int *token_index) {
2420static AstNode *ast_parse_root(ParseContext *pc, size_t *token_index) {
24212421 AstNode *node = ast_create_node(pc, NodeTypeRoot, &pc->tokens->at(*token_index));
24222422
24232423 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,
24412441 pc.buf = buf;
24422442 pc.tokens = tokens;
24432443 pc.next_node_index = next_node_index;
2444 int token_index = 0;
2444 size_t token_index = 0;
24452445 pc.root = ast_parse_root(&pc, &token_index);
24462446 return pc.root;
24472447}
......@@ -2454,7 +2454,7 @@ static void visit_field(AstNode **node, void (*visit)(AstNode **, void *context)
24542454
24552455static void visit_node_list(ZigList<AstNode *> *list, void (*visit)(AstNode **, void *context), void *context) {
24562456 if (list) {
2457 for (int i = 0; i < list->length; i += 1) {
2457 for (size_t i = 0; i < list->length; i += 1) {
24582458 visit(&list->at(i), context);
24592459 }
24602460 }
......@@ -2607,11 +2607,11 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
26072607 // none
26082608 break;
26092609 case NodeTypeAsmExpr:
2610 for (int i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
2610 for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
26112611 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
26122612 visit_field(&asm_input->expr, visit, context);
26132613 }
2614 for (int i = 0; i < node->data.asm_expr.output_list.length; i += 1) {
2614 for (size_t i = 0; i < node->data.asm_expr.output_list.length; i += 1) {
26152615 AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);
26162616 visit_field(&asm_output->return_type, visit, context);
26172617 }
......@@ -2659,7 +2659,7 @@ void normalize_parent_ptrs(AstNode *node) {
26592659static void clone_subtree_list(ZigList<AstNode *> *dest, ZigList<AstNode *> *src, uint32_t *next_node_index) {
26602660 memset(dest, 0, sizeof(ZigList<AstNode *>));
26612661 dest->resize(src->length);
2662 for (int i = 0; i < src->length; i += 1) {
2662 for (size_t i = 0; i < src->length; i += 1) {
26632663 dest->at(i) = ast_clone_subtree(src->at(i), next_node_index);
26642664 dest->at(i)->parent_field = &dest->at(i);
26652665 }
......@@ -2670,7 +2670,7 @@ static void clone_subtree_list_omit_inline_params(ZigList<AstNode *> *dest, ZigL
26702670{
26712671 memset(dest, 0, sizeof(ZigList<AstNode *>));
26722672 dest->ensure_capacity(src->length);
2673 for (int i = 0; i < src->length; i += 1) {
2673 for (size_t i = 0; i < src->length; i += 1) {
26742674 AstNode *src_node = src->at(i);
26752675 assert(src_node->type == NodeTypeParamDecl);
26762676 if (src_node->data.param_decl.is_inline) {
......@@ -2712,7 +2712,7 @@ static void clone_subtree_tld(TopLevelDecl *dest, TopLevelDecl *src, uint32_t *n
27122712
27132713AstNode *ast_clone_subtree_special(AstNode *old_node, uint32_t *next_node_index, enum AstCloneSpecial special) {
27142714 AstNode *new_node = allocate_nonzero<AstNode>(1);
2715 memcpy(new_node, old_node, sizeof(AstNode));
2715 safe_memcpy(new_node, old_node, 1);
27162716 new_node->create_index = *next_node_index;
27172717 *next_node_index += 1;
27182718 new_node->parent_field = nullptr;
src/target.cpp+8-8
......@@ -156,7 +156,7 @@ static const ZigLLVM_ObjectFormatType oformat_list[] = {
156156 ZigLLVM_MachO,
157157};
158158
159int target_oformat_count(void) {
159size_t target_oformat_count(void) {
160160 return array_length(oformat_list);
161161}
162162
......@@ -174,7 +174,7 @@ const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat) {
174174 zig_unreachable();
175175}
176176
177int target_arch_count(void) {
177size_t target_arch_count(void) {
178178 return array_length(arch_list);
179179}
180180
......@@ -182,7 +182,7 @@ const ArchType *get_target_arch(int index) {
182182 return &arch_list[index];
183183}
184184
185int target_vendor_count(void) {
185size_t target_vendor_count(void) {
186186 return array_length(vendor_list);
187187}
188188
......@@ -190,7 +190,7 @@ ZigLLVM_VendorType get_target_vendor(int index) {
190190 return vendor_list[index];
191191}
192192
193int target_os_count(void) {
193size_t target_os_count(void) {
194194 return array_length(os_list);
195195}
196196ZigLLVM_OSType get_target_os(int index) {
......@@ -201,7 +201,7 @@ const char *get_target_os_name(ZigLLVM_OSType os_type) {
201201 return (os_type == ZigLLVM_UnknownOS) ? "freestanding" : ZigLLVMGetOSTypeName(os_type);
202202}
203203
204int target_environ_count(void) {
204size_t target_environ_count(void) {
205205 return array_length(environ_list);
206206}
207207ZigLLVM_EnvironmentType get_target_environ(int index) {
......@@ -237,7 +237,7 @@ void get_arch_name(char *out_str, const ArchType *arch) {
237237}
238238
239239int parse_target_arch(const char *str, ArchType *out_arch) {
240 for (int i = 0; i < array_length(arch_list); i += 1) {
240 for (size_t i = 0; i < array_length(arch_list); i += 1) {
241241 const ArchType *arch = &arch_list[i];
242242 char arch_name[50];
243243 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) {
250250}
251251
252252int parse_target_os(const char *str, ZigLLVM_OSType *out_os) {
253 for (int i = 0; i < array_length(os_list); i += 1) {
253 for (size_t i = 0; i < array_length(os_list); i += 1) {
254254 ZigLLVM_OSType os = os_list[i];
255255 const char *os_name = get_target_os_name(os);
256256 if (strcmp(os_name, str) == 0) {
......@@ -262,7 +262,7 @@ int parse_target_os(const char *str, ZigLLVM_OSType *out_os) {
262262}
263263
264264int parse_target_environ(const char *str, ZigLLVM_EnvironmentType *out_environ) {
265 for (int i = 0; i < array_length(environ_list); i += 1) {
265 for (size_t i = 0; i < array_length(environ_list); i += 1) {
266266 ZigLLVM_EnvironmentType env_type = environ_list[i];
267267 const char *environ_name = ZigLLVMGetEnvironmentTypeName(env_type);
268268 if (strcmp(environ_name, str) == 0) {
src/target.hpp+5-5
......@@ -38,22 +38,22 @@ enum CIntType {
3838 CIntTypeCount,
3939};
4040
41int target_arch_count(void);
41size_t target_arch_count(void);
4242const ArchType *get_target_arch(int index);
4343void get_arch_name(char *out_str, const ArchType *arch);
4444
45int target_vendor_count(void);
45size_t target_vendor_count(void);
4646ZigLLVM_VendorType get_target_vendor(int index);
4747
48int target_os_count(void);
48size_t target_os_count(void);
4949ZigLLVM_OSType get_target_os(int index);
5050const char *get_target_os_name(ZigLLVM_OSType os_type);
5151
52int target_environ_count(void);
52size_t target_environ_count(void);
5353ZigLLVM_EnvironmentType get_target_environ(int index);
5454
5555
56int target_oformat_count(void);
56size_t target_oformat_count(void);
5757const ZigLLVM_ObjectFormatType get_target_oformat(int index);
5858const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat);
5959
src/tokenizer.cpp+6-6
......@@ -141,7 +141,7 @@ static const struct ZigKeyword zig_keywords[] = {
141141};
142142
143143bool is_zig_keyword(Buf *buf) {
144 for (int i = 0; i < array_length(zig_keywords); i += 1) {
144 for (size_t i = 0; i < array_length(zig_keywords); i += 1) {
145145 if (buf_eql_str(buf, zig_keywords[i].text)) {
146146 return true;
147147 }
......@@ -209,7 +209,7 @@ enum TokenizeState {
209209
210210struct Tokenize {
211211 Buf *buf;
212 int pos;
212 size_t pos;
213213 TokenizeState state;
214214 ZigList<Token> *tokens;
215215 int line;
......@@ -329,7 +329,7 @@ static void end_float_token(Tokenize *t) {
329329 }
330330 }
331331 uint64_t double_bits = (exponent_bits << 52) | significand_bits;
332 memcpy(&t->cur_tok->data.num_lit.bignum.data.x_float, &double_bits, sizeof(double));
332 safe_memcpy(&t->cur_tok->data.num_lit.bignum.data.x_float, (double *)&double_bits, 1);
333333}
334334
335335static void end_token(Tokenize *t) {
......@@ -397,7 +397,7 @@ void tokenize(Buf *buf, Tokenization *out) {
397397 t.tokens = out->tokens = allocate<ZigList<Token>>(1);
398398 t.buf = buf;
399399
400 out->line_offsets = allocate<ZigList<int>>(1);
400 out->line_offsets = allocate<ZigList<size_t>>(1);
401401
402402 out->line_offsets->append(0);
403403 for (t.pos = 0; t.pos < buf_len(t.buf); t.pos += 1) {
......@@ -1545,10 +1545,10 @@ const char * token_name(TokenId id) {
15451545}
15461546
15471547void print_tokens(Buf *buf, ZigList<Token> *tokens) {
1548 for (int i = 0; i < tokens->length; i += 1) {
1548 for (size_t i = 0; i < tokens->length; i += 1) {
15491549 Token *token = &tokens->at(i);
15501550 fprintf(stderr, "%s ", token_name(token->id));
1551 if (token->start_pos >= 0) {
1551 if (token->start_pos != SIZE_MAX) {
15521552 fwrite(buf_ptr(buf) + token->start_pos, 1, token->end_pos - token->start_pos, stderr);
15531553 }
15541554 fprintf(stderr, "\n");
src/tokenizer.hpp+7-7
......@@ -131,10 +131,10 @@ struct TokenCharLit {
131131
132132struct Token {
133133 TokenId id;
134 int start_pos;
135 int end_pos;
136 int start_line;
137 int start_column;
134 size_t start_pos;
135 size_t end_pos;
136 size_t start_line;
137 size_t start_column;
138138
139139 union {
140140 // TokenIdNumberLiteral
......@@ -150,12 +150,12 @@ struct Token {
150150
151151struct Tokenization {
152152 ZigList<Token> *tokens;
153 ZigList<int> *line_offsets;
153 ZigList<size_t> *line_offsets;
154154
155155 // if an error occurred
156156 Buf *err;
157 int err_line;
158 int err_column;
157 size_t err_line;
158 size_t err_column;
159159};
160160
161161void tokenize(Buf *buf, Tokenization *out_tokenization);
src/util.hpp+23-3
......@@ -45,15 +45,35 @@ __attribute__((malloc)) static inline T *allocate(size_t count) {
4545}
4646
4747template<typename T>
48static inline T *reallocate_nonzero(T * old, size_t new_count) {
48static inline void safe_memcpy(T *dest, const T *src, size_t count) {
49#ifdef NDEBUG
50 memcpy(dest, src, count * sizeof(T));
51#else
52 // manually assign every elment to trigger compile error for non-copyable structs
53 for (size_t i = 0; i < count; i += 1) {
54 dest[i] = src[i];
55 }
56#endif
57}
58
59template<typename T>
60static inline T *reallocate_nonzero(T *old, size_t old_count, size_t new_count) {
61#ifdef NDEBUG
4962 T *ptr = reinterpret_cast<T*>(realloc(old, new_count * sizeof(T)));
5063 if (!ptr)
5164 zig_panic("allocation failed");
5265 return ptr;
66#else
67 // manually assign every element to trigger compile error for non-copyable structs
68 T *ptr = allocate_nonzero<T>(new_count);
69 safe_memcpy(ptr, old, old_count);
70 free(old);
71 return ptr;
72#endif
5373}
5474
55template <typename T, long n>
56constexpr long array_length(const T (&)[n]) {
75template <typename T, size_t n>
76constexpr size_t array_length(const T (&)[n]) {
5777 return n;
5878}
5979
std/list.zig+3-4
......@@ -42,15 +42,14 @@ pub struct SmallList(T: type, static_size: usize) {
4242 }
4343
4444 pub fn ensureCapacity(l: &Self, new_capacity: usize) -> %void {
45 const old_capacity = l.items.len;
46 var better_capacity = old_capacity;
45 var better_capacity = l.items.len;
4746 while (better_capacity < new_capacity) {
4847 better_capacity *= 2;
4948 }
50 if (better_capacity != old_capacity) {
49 if (better_capacity != l.items.len) {
5150 if (l.items.ptr == &l.prealloc_items[0]) {
5251 l.items = %return l.allocator.alloc(T, better_capacity);
53 mem.copy(T, l.items, l.prealloc_items[0...old_capacity]);
52 mem.copy(T, l.items, l.prealloc_items[0...l.len]);
5453 } else {
5554 l.items = %return l.allocator.realloc(T, l.items, better_capacity);
5655 }
test/run_tests.cpp+18-16
......@@ -93,7 +93,7 @@ static TestCase *add_simple_case_libc(const char *case_name, const char *source,
9393 return tc;
9494}
9595
96static TestCase *add_compile_fail_case(const char *case_name, const char *source, int count, ...) {
96static TestCase *add_compile_fail_case(const char *case_name, const char *source, size_t count, ...) {
9797 va_list ap;
9898 va_start(ap, count);
9999
......@@ -103,7 +103,7 @@ static TestCase *add_compile_fail_case(const char *case_name, const char *source
103103 test_case->source_files.at(0).relative_path = tmp_source_path;
104104 test_case->source_files.at(0).source_code = source;
105105
106 for (int i = 0; i < count; i += 1) {
106 for (size_t i = 0; i < count; i += 1) {
107107 const char *arg = va_arg(ap, const char *);
108108 test_case->compile_errors.append(arg);
109109 }
......@@ -181,7 +181,7 @@ static void add_debug_safety_case(const char *case_name, const char *source) {
181181}
182182
183183static TestCase *add_parseh_case(const char *case_name, AllowWarnings allow_warnings,
184 const char *source, int count, ...)
184 const char *source, size_t count, ...)
185185{
186186 va_list ap;
187187 va_start(ap, count);
......@@ -195,7 +195,7 @@ static TestCase *add_parseh_case(const char *case_name, AllowWarnings allow_warn
195195 test_case->source_files.at(0).relative_path = tmp_h_path;
196196 test_case->source_files.at(0).source_code = source;
197197
198 for (int i = 0; i < count; i += 1) {
198 for (size_t i = 0; i < count; i += 1) {
199199 const char *arg = va_arg(ap, const char *);
200200 test_case->compile_errors.append(arg);
201201 }
......@@ -1854,7 +1854,7 @@ static void run_self_hosted_test(bool is_release_mode) {
18541854 if (term.how != TerminationIdClean || term.code != 0) {
18551855 printf("\nSelf-hosted tests failed:\n");
18561856 printf("./zig");
1857 for (int i = 0; i < args.length; i += 1) {
1857 for (size_t i = 0; i < args.length; i += 1) {
18581858 printf(" %s", args.at(i));
18591859 }
18601860 printf("\n%s\n", buf_ptr(&zig_stderr));
......@@ -1881,7 +1881,7 @@ static void add_self_hosted_tests(void) {
18811881
18821882static void print_compiler_invocation(TestCase *test_case) {
18831883 printf("%s", zig_exe);
1884 for (int i = 0; i < test_case->compiler_args.length; i += 1) {
1884 for (size_t i = 0; i < test_case->compiler_args.length; i += 1) {
18851885 printf(" %s", test_case->compiler_args.at(i));
18861886 }
18871887 printf("\n");
......@@ -1889,7 +1889,7 @@ static void print_compiler_invocation(TestCase *test_case) {
18891889
18901890static void print_exe_invocation(TestCase *test_case) {
18911891 printf("%s", tmp_exe_path);
1892 for (int i = 0; i < test_case->program_args.length; i += 1) {
1892 for (size_t i = 0; i < test_case->program_args.length; i += 1) {
18931893 printf(" %s", test_case->program_args.at(i));
18941894 }
18951895 printf("\n");
......@@ -1900,7 +1900,7 @@ static void run_test(TestCase *test_case) {
19001900 return run_self_hosted_test(test_case->is_release_mode);
19011901 }
19021902
1903 for (int i = 0; i < test_case->source_files.length; i += 1) {
1903 for (size_t i = 0; i < test_case->source_files.length; i += 1) {
19041904 TestSourceFile *test_source = &test_case->source_files.at(i);
19051905 os_write_file(
19061906 buf_create_from_str(test_source->relative_path),
......@@ -1917,7 +1917,7 @@ static void run_test(TestCase *test_case) {
19171917
19181918 if (!test_case->is_parseh && test_case->compile_errors.length) {
19191919 if (term.how != TerminationIdClean || term.code != 0) {
1920 for (int i = 0; i < test_case->compile_errors.length; i += 1) {
1920 for (size_t i = 0; i < test_case->compile_errors.length; i += 1) {
19211921 const char *err_text = test_case->compile_errors.at(i);
19221922 if (!strstr(buf_ptr(&zig_stderr), err_text)) {
19231923 printf("\n");
......@@ -1957,7 +1957,7 @@ static void run_test(TestCase *test_case) {
19571957 }
19581958 }
19591959
1960 for (int i = 0; i < test_case->compile_errors.length; i += 1) {
1960 for (size_t i = 0; i < test_case->compile_errors.length; i += 1) {
19611961 const char *output = test_case->compile_errors.at(i);
19621962
19631963 if (!strstr(buf_ptr(&zig_stdout), output)) {
......@@ -2015,7 +2015,7 @@ static void run_test(TestCase *test_case) {
20152015 }
20162016 }
20172017
2018 for (int i = 0; i < test_case->source_files.length; i += 1) {
2018 for (size_t i = 0; i < test_case->source_files.length; i += 1) {
20192019 TestSourceFile *test_source = &test_case->source_files.at(i);
20202020 remove(test_source->relative_path);
20212021 }
......@@ -2023,21 +2023,23 @@ static void run_test(TestCase *test_case) {
20232023
20242024static void run_all_tests(bool reverse) {
20252025 if (reverse) {
2026 for (int i = test_cases.length - 1; i >= 0; i -= 1) {
2026 for (size_t i = test_cases.length;;) {
20272027 TestCase *test_case = test_cases.at(i);
2028 printf("Test %d/%d %s...", i + 1, test_cases.length, test_case->case_name);
2028 printf("Test %zu/%zu %s...", i + 1, test_cases.length, test_case->case_name);
20292029 run_test(test_case);
20302030 printf("OK\n");
2031 if (i == 0) break;
2032 i -= 1;
20312033 }
20322034 } else {
2033 for (int i = 0; i < test_cases.length; i += 1) {
2035 for (size_t i = 0; i < test_cases.length; i += 1) {
20342036 TestCase *test_case = test_cases.at(i);
2035 printf("Test %d/%d %s...", i + 1, test_cases.length, test_case->case_name);
2037 printf("Test %zu/%zu %s...", i + 1, test_cases.length, test_case->case_name);
20362038 run_test(test_case);
20372039 printf("OK\n");
20382040 }
20392041 }
2040 printf("%d tests passed.\n", test_cases.length);
2042 printf("%zu tests passed.\n", test_cases.length);
20412043}
20422044
20432045static void cleanup(void) {