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)...@@ -177,7 +177,7 @@ if(MINGW)
177 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")177 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")
178endif()178endif()
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")
181set(EXE_LDFLAGS " ")181set(EXE_LDFLAGS " ")
182if(ZIG_TEST_COVERAGE)182if(ZIG_TEST_COVERAGE)
183 set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage")183 set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage")
src/all_types.hpp+45-46
...@@ -18,7 +18,6 @@...@@ -18,7 +18,6 @@
1818
19struct AstNode;19struct AstNode;
20struct ImportTableEntry;20struct ImportTableEntry;
21struct AsmToken;
22struct FnTableEntry;21struct FnTableEntry;
23struct BlockContext;22struct BlockContext;
24struct TypeTableEntry;23struct TypeTableEntry;
...@@ -218,8 +217,8 @@ struct AstNodeFnProto {...@@ -218,8 +217,8 @@ struct AstNodeFnProto {
218 bool skip;217 bool skip;
219 Expr resolved_expr;218 Expr resolved_expr;
220 // computed from params field219 // computed from params field
221 int inline_arg_count;220 size_t inline_arg_count;
222 int inline_or_var_type_arg_count;221 size_t inline_or_var_type_arg_count;
223 // if this is a generic function implementation, this points to the generic node222 // if this is a generic function implementation, this points to the generic node
224 AstNode *generic_proto_node;223 AstNode *generic_proto_node;
225};224};
...@@ -282,7 +281,7 @@ struct AstNodeDefer {...@@ -282,7 +281,7 @@ struct AstNodeDefer {
282281
283 // populated by semantic analyzer:282 // populated by semantic analyzer:
284 Expr resolved_expr;283 Expr resolved_expr;
285 int index_in_block;284 size_t index_in_block;
286 LLVMBasicBlockRef basic_block;285 LLVMBasicBlockRef basic_block;
287 BlockContext *child_block;286 BlockContext *child_block;
288};287};
...@@ -547,7 +546,7 @@ struct AstNodeSwitchExpr {...@@ -547,7 +546,7 @@ struct AstNodeSwitchExpr {
547546
548 // populated by semantic analyzer547 // populated by semantic analyzer
549 Expr resolved_expr;548 Expr resolved_expr;
550 int const_chosen_prong_index;549 size_t const_chosen_prong_index;
551};550};
552551
553struct AstNodeSwitchProng {552struct AstNodeSwitchProng {
...@@ -599,8 +598,20 @@ struct AsmInput {...@@ -599,8 +598,20 @@ struct AsmInput {
599};598};
600599
601struct SrcPos {600struct SrcPos {
602 int line;601 size_t line;
603 int column;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;
604};615};
605616
606struct AstNodeAsmExpr {617struct AstNodeAsmExpr {
...@@ -612,7 +623,7 @@ struct AstNodeAsmExpr {...@@ -612,7 +623,7 @@ struct AstNodeAsmExpr {
612 ZigList<Buf*> clobber_list;623 ZigList<Buf*> clobber_list;
613624
614 // populated by semantic analyzer625 // populated by semantic analyzer
615 int return_count;626 size_t return_count;
616 Expr resolved_expr;627 Expr resolved_expr;
617};628};
618629
...@@ -763,8 +774,8 @@ struct AstNodeVarLiteral {...@@ -763,8 +774,8 @@ struct AstNodeVarLiteral {
763774
764struct AstNode {775struct AstNode {
765 enum NodeType type;776 enum NodeType type;
766 int line;777 size_t line;
767 int column;778 size_t column;
768 uint32_t create_index; // for determinism purposes779 uint32_t create_index; // for determinism purposes
769 ImportTableEntry *owner;780 ImportTableEntry *owner;
770 AstNode **parent_field; // for AST rewriting781 AstNode **parent_field; // for AST rewriting
...@@ -823,18 +834,6 @@ struct AstNode {...@@ -823,18 +834,6 @@ struct AstNode {
823 } data;834 } data;
824};835};
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
838// this struct is allocated with allocate_nonzero837// this struct is allocated with allocate_nonzero
839struct FnTypeParamInfo {838struct FnTypeParamInfo {
840 bool is_noalias;839 bool is_noalias;
...@@ -844,24 +843,24 @@ struct FnTypeParamInfo {...@@ -844,24 +843,24 @@ struct FnTypeParamInfo {
844struct GenericParamValue {843struct GenericParamValue {
845 TypeTableEntry *type;844 TypeTableEntry *type;
846 AstNode *node;845 AstNode *node;
847 int impl_index;846 size_t impl_index;
848};847};
849848
850struct GenericFnTypeId {849struct GenericFnTypeId {
851 AstNode *decl_node; // the generic fn or container decl node850 AstNode *decl_node; // the generic fn or container decl node
852 GenericParamValue *generic_params;851 GenericParamValue *generic_params;
853 int generic_param_count;852 size_t generic_param_count;
854};853};
855854
856uint32_t generic_fn_type_id_hash(GenericFnTypeId *id);855uint32_t generic_fn_type_id_hash(GenericFnTypeId *id);
857bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b);856bool 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;
861struct FnTypeId {860struct FnTypeId {
862 TypeTableEntry *return_type;861 TypeTableEntry *return_type;
863 FnTypeParamInfo *param_info;862 FnTypeParamInfo *param_info;
864 int param_count;863 size_t param_count;
865 bool is_var_args;864 bool is_var_args;
866 bool is_naked;865 bool is_naked;
867 bool is_cold;866 bool is_cold;
...@@ -878,12 +877,12 @@ struct TypeTableEntryPointer {...@@ -878,12 +877,12 @@ struct TypeTableEntryPointer {
878};877};
879878
880struct TypeTableEntryInt {879struct TypeTableEntryInt {
881 int bit_count;880 size_t bit_count;
882 bool is_signed;881 bool is_signed;
883};882};
884883
885struct TypeTableEntryFloat {884struct TypeTableEntryFloat {
886 int bit_count;885 size_t bit_count;
887};886};
888887
889struct TypeTableEntryArray {888struct TypeTableEntryArray {
...@@ -894,8 +893,8 @@ struct TypeTableEntryArray {...@@ -894,8 +893,8 @@ struct TypeTableEntryArray {
894struct TypeStructField {893struct TypeStructField {
895 Buf *name;894 Buf *name;
896 TypeTableEntry *type_entry;895 TypeTableEntry *type_entry;
897 int src_index;896 size_t src_index;
898 int gen_index;897 size_t gen_index;
899};898};
900struct TypeTableEntryStruct {899struct TypeTableEntryStruct {
901 AstNode *decl_node;900 AstNode *decl_node;
...@@ -958,8 +957,8 @@ struct TypeTableEntryUnion {...@@ -958,8 +957,8 @@ struct TypeTableEntryUnion {
958};957};
959958
960struct FnGenParamInfo {959struct FnGenParamInfo {
961 int src_index;960 size_t src_index;
962 int gen_index;961 size_t gen_index;
963 bool is_byval;962 bool is_byval;
964 TypeTableEntry *type;963 TypeTableEntry *type;
965};964};
...@@ -967,7 +966,7 @@ struct FnGenParamInfo {...@@ -967,7 +966,7 @@ struct FnGenParamInfo {
967struct TypeTableEntryFn {966struct TypeTableEntryFn {
968 FnTypeId fn_type_id;967 FnTypeId fn_type_id;
969 TypeTableEntry *gen_return_type;968 TypeTableEntry *gen_return_type;
970 int gen_param_count;969 size_t gen_param_count;
971 FnGenParamInfo *gen_param_info;970 FnGenParamInfo *gen_param_info;
972971
973 LLVMTypeRef raw_type_ref;972 LLVMTypeRef raw_type_ref;
...@@ -1057,7 +1056,7 @@ struct ImportTableEntry {...@@ -1057,7 +1056,7 @@ struct ImportTableEntry {
1057 PackageTableEntry *package;1056 PackageTableEntry *package;
1058 ZigLLVMDIFile *di_file;1057 ZigLLVMDIFile *di_file;
1059 Buf *source_code;1058 Buf *source_code;
1060 ZigList<int> *line_offsets;1059 ZigList<size_t> *line_offsets;
1061 BlockContext *block_context;1060 BlockContext *block_context;
1062 AstNode *c_import_node;1061 AstNode *c_import_node;
1063 bool any_imports_failed;1062 bool any_imports_failed;
...@@ -1127,8 +1126,8 @@ struct EvalFnRoot {...@@ -1127,8 +1126,8 @@ struct EvalFnRoot {
1127 CodeGen *codegen;1126 CodeGen *codegen;
1128 FnTableEntry *fn;1127 FnTableEntry *fn;
1129 AstNode *call_node;1128 AstNode *call_node;
1130 int branch_quota;1129 size_t branch_quota;
1131 int branches_used;1130 size_t branches_used;
1132 AstNode *exceeded_quota_node;1131 AstNode *exceeded_quota_node;
1133 bool abort;1132 bool abort;
1134};1133};
...@@ -1180,7 +1179,7 @@ enum BuiltinFnId {...@@ -1180,7 +1179,7 @@ enum BuiltinFnId {
1180struct BuiltinFnEntry {1179struct BuiltinFnEntry {
1181 BuiltinFnId id;1180 BuiltinFnId id;
1182 Buf name;1181 Buf name;
1183 int param_count;1182 size_t param_count;
1184 TypeTableEntry *return_type;1183 TypeTableEntry *return_type;
1185 TypeTableEntry **param_types;1184 TypeTableEntry **param_types;
1186 uint32_t ref_count;1185 uint32_t ref_count;
...@@ -1207,11 +1206,11 @@ struct CodeGen {...@@ -1207,11 +1206,11 @@ struct CodeGen {
1207 HashMap<GenericFnTypeId *, AstNode *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;1206 HashMap<GenericFnTypeId *, AstNode *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;
12081207
1209 ZigList<ImportTableEntry *> import_queue;1208 ZigList<ImportTableEntry *> import_queue;
1210 int import_queue_index;1209 size_t import_queue_index;
1211 ZigList<AstNode *> resolve_queue;1210 ZigList<AstNode *> resolve_queue;
1212 int resolve_queue_index;1211 size_t resolve_queue_index;
1213 ZigList<AstNode *> use_queue;1212 ZigList<AstNode *> use_queue;
1214 int use_queue_index;1213 size_t use_queue_index;
12151214
1216 uint32_t next_unresolved_index;1215 uint32_t next_unresolved_index;
12171216
...@@ -1305,9 +1304,9 @@ struct CodeGen {...@@ -1305,9 +1304,9 @@ struct CodeGen {
1305 bool c_want_stdint;1304 bool c_want_stdint;
1306 bool c_want_stdbool;1305 bool c_want_stdbool;
1307 AstNode *root_export_decl;1306 AstNode *root_export_decl;
1308 int version_major;1307 size_t version_major;
1309 int version_minor;1308 size_t version_minor;
1310 int version_patch;1309 size_t version_patch;
1311 bool verbose;1310 bool verbose;
1312 ErrColor err_color;1311 ErrColor err_color;
1313 ImportTableEntry *root_import;1312 ImportTableEntry *root_import;
...@@ -1323,7 +1322,7 @@ struct CodeGen {...@@ -1323,7 +1322,7 @@ struct CodeGen {
1323 LLVMValueRef int_builtin_fns[2][4]; // [0-ctz,1-clz][0-8,1-16,2-32,3-64]1322 LLVMValueRef int_builtin_fns[2][4]; // [0-ctz,1-clz][0-8,1-16,2-32,3-64]
13241323
1325 const char **clang_argv;1324 const char **clang_argv;
1326 int clang_argv_len;1325 size_t clang_argv_len;
1327 ZigList<const char *> lib_dirs;1326 ZigList<const char *> lib_dirs;
13281327
1329 uint32_t test_fn_count;1328 uint32_t test_fn_count;
...@@ -1345,8 +1344,8 @@ struct VariableTableEntry {...@@ -1345,8 +1344,8 @@ struct VariableTableEntry {
1345 // which node contains the ConstExprValue for this variable's value1344 // which node contains the ConstExprValue for this variable's value
1346 AstNode *val_node;1345 AstNode *val_node;
1347 ZigLLVMDILocalVariable *di_loc_var;1346 ZigLLVMDILocalVariable *di_loc_var;
1348 int src_arg_index;1347 size_t src_arg_index;
1349 int gen_arg_index;1348 size_t gen_arg_index;
1350 BlockContext *block_context;1349 BlockContext *block_context;
1351 LLVMValueRef param_value_ref;1350 LLVMValueRef param_value_ref;
1352 bool force_depends_on_compile_var;1351 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...@@ -205,7 +205,7 @@ static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *so
205}205}
206206
207207
208static int bits_needed_for_unsigned(uint64_t x) {208static size_t bits_needed_for_unsigned(uint64_t x) {
209 if (x <= UINT8_MAX) {209 if (x <= UINT8_MAX) {
210 return 8;210 return 8;
211 } else if (x <= UINT16_MAX) {211 } else if (x <= UINT16_MAX) {
...@@ -579,7 +579,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c...@@ -579,7 +579,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c
579 slice_type_common_init(g, child_type, is_const, entry);579 slice_type_common_init(g, child_type, is_const, entry);
580 if (child_type->zero_bits) {580 if (child_type->zero_bits) {
581 entry->data.structure.gen_field_count = 1;581 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;
583 entry->data.structure.fields[1].gen_index = 0;583 entry->data.structure.fields[1].gen_index = 0;
584 }584 }
585585
...@@ -736,7 +736,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf...@@ -736,7 +736,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf
736 const char *naked_str = fn_type_id->is_naked ? "naked " : "";736 const char *naked_str = fn_type_id->is_naked ? "naked " : "";
737 const char *cold_str = fn_type_id->is_cold ? "cold " : "";737 const char *cold_str = fn_type_id->is_cold ? "cold " : "";
738 buf_appendf(&fn_type->name, "%s%s%sfn(", extern_str, naked_str, cold_str);738 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) {
740 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];740 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
741741
742 TypeTableEntry *param_type = param_info->type;742 TypeTableEntry *param_type = param_info->type;
...@@ -763,7 +763,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf...@@ -763,7 +763,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf
763 // +1 because 0 is the return type and +1 for maybe making first arg ret val763 // +1 because 0 is the return type and +1 for maybe making first arg ret val
764 ZigLLVMDIType **param_di_types = allocate<ZigLLVMDIType*>(2 + fn_type_id->param_count);764 ZigLLVMDIType **param_di_types = allocate<ZigLLVMDIType*>(2 + fn_type_id->param_count);
765 param_di_types[0] = fn_type_id->return_type->di_type;765 param_di_types[0] = fn_type_id->return_type->di_type;
766 int gen_param_index = 0;766 size_t gen_param_index = 0;
767 TypeTableEntry *gen_return_type;767 TypeTableEntry *gen_return_type;
768 if (!type_has_bits(fn_type_id->return_type)) {768 if (!type_has_bits(fn_type_id->return_type)) {
769 gen_return_type = g->builtin_types.entry_void;769 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...@@ -780,13 +780,13 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id, bool gen_debug_inf
780 fn_type->data.fn.gen_return_type = gen_return_type;780 fn_type->data.fn.gen_return_type = gen_return_type;
781781
782 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);782 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) {
784 FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];784 FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];
785 TypeTableEntry *type_entry = src_param_info->type;785 TypeTableEntry *type_entry = src_param_info->type;
786 FnGenParamInfo *gen_param_info = &fn_type->data.fn.gen_param_info[i];786 FnGenParamInfo *gen_param_info = &fn_type->data.fn.gen_param_info[i];
787787
788 gen_param_info->src_index = i;788 gen_param_info->src_index = i;
789 gen_param_info->gen_index = -1;789 gen_param_info->gen_index = SIZE_MAX;
790790
791 assert(type_is_complete(type_entry));791 assert(type_is_complete(type_entry));
792 if (type_has_bits(type_entry)) {792 if (type_has_bits(type_entry)) {
...@@ -946,7 +946,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor...@@ -946,7 +946,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
946 fn_type_id.is_var_args = fn_proto->is_var_args;946 fn_type_id.is_var_args = fn_proto->is_var_args;
947 fn_type_id.return_type = analyze_type_expr(g, import, context, fn_proto->return_type);947 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) {
950 AstNode *child = fn_proto->params.at(i);950 AstNode *child = fn_proto->params.at(i);
951 assert(child->type == NodeTypeParamDecl);951 assert(child->type == NodeTypeParamDecl);
952952
...@@ -1047,7 +1047,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor...@@ -1047,7 +1047,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
1047 fn_table_entry->want_pure_return_type = fn_proto->return_type;1047 fn_table_entry->want_pure_return_type = fn_proto->return_type;
10481048
1049 ErrorMsg *err_msg = nullptr;1049 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) {
1051 AstNode *param_decl_node = fn_proto->params.at(i);1051 AstNode *param_decl_node = fn_proto->params.at(i);
1052 assert(param_decl_node->type == NodeTypeParamDecl);1052 assert(param_decl_node->type == NodeTypeParamDecl);
1053 if (!param_decl_node->data.param_decl.is_inline) {1053 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...@@ -1135,7 +1135,7 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t
1135 bool is_noinline = false;1135 bool is_noinline = false;
11361136
1137 if (fn_proto->top_level_decl.directives) {1137 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) {
1139 AstNode *directive_node = fn_proto->top_level_decl.directives->at(i);1139 AstNode *directive_node = fn_proto->top_level_decl.directives->at(i);
1140 Buf *name = directive_node->data.directive.name;1140 Buf *name = directive_node->data.directive.name;
11411141
...@@ -1342,7 +1342,7 @@ static void resolve_enum_type(CodeGen *g, ImportTableEntry *import, TypeTableEnt...@@ -1342,7 +1342,7 @@ static void resolve_enum_type(CodeGen *g, ImportTableEntry *import, TypeTableEnt
1342 // set temporary flag1342 // set temporary flag
1343 enum_type->data.enumeration.embedded_in_current = true;1343 enum_type->data.enumeration.embedded_in_current = true;
13441344
1345 int gen_field_index = 0;1345 size_t gen_field_index = 0;
1346 for (uint32_t i = 0; i < field_count; i += 1) {1346 for (uint32_t i = 0; i < field_count; i += 1) {
1347 AstNode *field_node = decl_node->data.struct_decl.fields.at(i);1347 AstNode *field_node = decl_node->data.struct_decl.fields.at(i);
1348 TypeEnumField *type_enum_field = &enum_type->data.enumeration.fields[i];1348 TypeEnumField *type_enum_field = &enum_type->data.enumeration.fields[i];
...@@ -1518,7 +1518,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE...@@ -1518,7 +1518,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
15181518
1519 struct_type->deep_const = true;1519 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
1523 struct_type->data.structure.src_field_count = field_count;1523 struct_type->data.structure.src_field_count = field_count;
1524 struct_type->data.structure.fields = allocate<TypeStructField>(field_count);1524 struct_type->data.structure.fields = allocate<TypeStructField>(field_count);
...@@ -1532,8 +1532,8 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE...@@ -1532,8 +1532,8 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
15321532
1533 BlockContext *context = struct_type->data.structure.block_context;1533 BlockContext *context = struct_type->data.structure.block_context;
15341534
1535 int gen_field_index = 0;1535 size_t gen_field_index = 0;
1536 for (int i = 0; i < field_count; i += 1) {1536 for (size_t i = 0; i < field_count; i += 1) {
1537 AstNode *field_node = decl_node->data.struct_decl.fields.at(i);1537 AstNode *field_node = decl_node->data.struct_decl.fields.at(i);
1538 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];1538 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
1539 type_struct_field->name = field_node->data.struct_field.name;1539 type_struct_field->name = field_node->data.struct_field.name;
...@@ -1541,7 +1541,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE...@@ -1541,7 +1541,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
1541 field_node->data.struct_field.type);1541 field_node->data.struct_field.type);
1542 type_struct_field->type_entry = field_type;1542 type_struct_field->type_entry = field_type;
1543 type_struct_field->src_index = i;1543 type_struct_field->src_index = i;
1544 type_struct_field->gen_index = -1;1544 type_struct_field->gen_index = SIZE_MAX;
15451545
1546 if (!field_type->deep_const) {1546 if (!field_type->deep_const) {
1547 struct_type->deep_const = false;1547 struct_type->deep_const = false;
...@@ -1574,16 +1574,16 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE...@@ -1574,16 +1574,16 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
1574 return;1574 return;
1575 }1575 }
15761576
1577 int gen_field_count = gen_field_index;1577 size_t gen_field_count = gen_field_index;
1578 LLVMStructSetBody(struct_type->type_ref, element_types, gen_field_count, false);1578 LLVMStructSetBody(struct_type->type_ref, element_types, gen_field_count, false);
15791579
1580 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(gen_field_count);1580 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) {
1583 AstNode *field_node = decl_node->data.struct_decl.fields.at(i);1583 AstNode *field_node = decl_node->data.struct_decl.fields.at(i);
1584 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];1584 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
1585 gen_field_index = type_struct_field->gen_index;1585 gen_field_index = type_struct_field->gen_index;
1586 if (gen_field_index == -1) {1586 if (gen_field_index == SIZE_MAX) {
1587 continue;1587 continue;
1588 }1588 }
15891589
...@@ -1697,7 +1697,7 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN...@@ -1697,7 +1697,7 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN
1697 fn_table_entry->type_entry = get_generic_fn_type(g, proto_node);1697 fn_table_entry->type_entry = get_generic_fn_type(g, proto_node);
16981698
1699 if (is_extern || proto_node->data.fn_proto.top_level_decl.visib_mod == VisibModExport) {1699 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) {
1701 AstNode *param_decl_node = proto_node->data.fn_proto.params.at(i);1701 AstNode *param_decl_node = proto_node->data.fn_proto.params.at(i);
1702 if (param_decl_node->data.param_decl.is_inline) {1702 if (param_decl_node->data.param_decl.is_inline) {
1703 proto_node->data.fn_proto.skip = true;1703 proto_node->data.fn_proto.skip = true;
...@@ -1754,7 +1754,7 @@ static void scan_struct_decl(CodeGen *g, ImportTableEntry *import, BlockContext...@@ -1754,7 +1754,7 @@ static void scan_struct_decl(CodeGen *g, ImportTableEntry *import, BlockContext
1754 node->data.struct_decl.type_entry = container_type;1754 node->data.struct_decl.type_entry = container_type;
17551755
1756 // handle the member function definitions independently1756 // 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) {
1758 AstNode *child_node = node->data.struct_decl.decls.at(i);1758 AstNode *child_node = node->data.struct_decl.decls.at(i);
1759 get_as_top_level_decl(child_node)->parent_decl = node;1759 get_as_top_level_decl(child_node)->parent_decl = node;
1760 BlockContext *child_context = get_container_block_context(container_type);1760 BlockContext *child_context = get_container_block_context(container_type);
...@@ -1802,7 +1802,7 @@ static void preview_error_value_decl(CodeGen *g, AstNode *node) {...@@ -1802,7 +1802,7 @@ static void preview_error_value_decl(CodeGen *g, AstNode *node) {
1802 // duplicate error definitions allowed and they get the same value1802 // duplicate error definitions allowed and they get the same value
1803 err->value = existing_entry->value->value;1803 err->value = existing_entry->value->value;
1804 } else {1804 } else {
1805 int error_value_count = g->error_decls.length;1805 size_t error_value_count = g->error_decls.length;
1806 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)g->err_tag_type->data.integral.bit_count));1806 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)g->err_tag_type->data.integral.bit_count));
1807 err->value = error_value_count;1807 err->value = error_value_count;
1808 g->error_decls.append(node);1808 g->error_decls.append(node);
...@@ -2100,7 +2100,7 @@ static bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTable...@@ -2100,7 +2100,7 @@ static bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTable
2100 if (expected_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {2100 if (expected_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {
2101 return false;2101 return false;
2102 }2102 }
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) {
2104 // note it's reversed for parameters2104 // note it's reversed for parameters
2105 FnTypeParamInfo *actual_param_info = &actual_type->data.fn.fn_type_id.param_info[i];2105 FnTypeParamInfo *actual_param_info = &actual_type->data.fn.fn_type_id.param_info[i];
2106 FnTypeParamInfo *expected_param_info = &expected_type->data.fn.fn_type_id.param_info[i];2106 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...@@ -2121,14 +2121,14 @@ static bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTable
2121}2121}
21222122
2123static TypeTableEntry *determine_peer_type_compatibility(CodeGen *g, AstNode *parent_source_node,2123static 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)
2125{2125{
2126 TypeTableEntry *prev_type = child_types[0];2126 TypeTableEntry *prev_type = child_types[0];
2127 AstNode *prev_node = child_nodes[0];2127 AstNode *prev_node = child_nodes[0];
2128 if (prev_type->id == TypeTableEntryIdInvalid) {2128 if (prev_type->id == TypeTableEntryIdInvalid) {
2129 return prev_type;2129 return prev_type;
2130 }2130 }
2131 for (int i = 1; i < child_count; i += 1) {2131 for (size_t i = 1; i < child_count; i += 1) {
2132 TypeTableEntry *cur_type = child_types[i];2132 TypeTableEntry *cur_type = child_types[i];
2133 AstNode *cur_node = child_nodes[i];2133 AstNode *cur_node = child_nodes[i];
2134 if (cur_type->id == TypeTableEntryIdInvalid) {2134 if (cur_type->id == TypeTableEntryIdInvalid) {
...@@ -2359,7 +2359,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, ImportTableEntry *...@@ -2359,7 +2359,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, ImportTableEntry *
23592359
2360static TypeTableEntry *resolve_peer_type_compatibility(CodeGen *g, ImportTableEntry *import,2360static TypeTableEntry *resolve_peer_type_compatibility(CodeGen *g, ImportTableEntry *import,
2361 BlockContext *block_context, AstNode *parent_source_node,2361 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)
2363{2363{
2364 assert(child_count > 0);2364 assert(child_count > 0);
23652365
...@@ -2370,7 +2370,7 @@ static TypeTableEntry *resolve_peer_type_compatibility(CodeGen *g, ImportTableEn...@@ -2370,7 +2370,7 @@ static TypeTableEntry *resolve_peer_type_compatibility(CodeGen *g, ImportTableEn
2370 return expected_type;2370 return expected_type;
2371 }2371 }
23722372
2373 for (int i = 0; i < child_count; i += 1) {2373 for (size_t i = 0; i < child_count; i += 1) {
2374 if (!child_nodes[i]) {2374 if (!child_nodes[i]) {
2375 continue;2375 continue;
2376 }2376 }
...@@ -2579,16 +2579,16 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry...@@ -2579,16 +2579,16 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
2579 codegen->source_node = node;2579 codegen->source_node = node;
25802580
25812581
2582 int expr_field_count = container_init_expr->entries.length;2582 size_t expr_field_count = container_init_expr->entries.length;
2583 int actual_field_count = container_type->data.structure.src_field_count;2583 size_t actual_field_count = container_type->data.structure.src_field_count;
25842584
2585 AstNode *non_const_expr_culprit = nullptr;2585 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);
2588 ConstExprValue *const_val = &get_resolved_expr(node)->const_val;2588 ConstExprValue *const_val = &get_resolved_expr(node)->const_val;
2589 const_val->ok = true;2589 const_val->ok = true;
2590 const_val->data.x_struct.fields = allocate<ConstExprValue*>(actual_field_count);2590 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) {
2592 AstNode *val_field_node = container_init_expr->entries.at(i);2592 AstNode *val_field_node = container_init_expr->entries.at(i);
2593 assert(val_field_node->type == NodeTypeStructValueField);2593 assert(val_field_node->type == NodeTypeStructValueField);
25942594
...@@ -2608,7 +2608,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry...@@ -2608,7 +2608,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
2608 return g->builtin_types.entry_invalid;2608 return g->builtin_types.entry_invalid;
2609 }2609 }
26102610
2611 int field_index = type_field->src_index;2611 size_t field_index = type_field->src_index;
2612 field_use_counts[field_index] += 1;2612 field_use_counts[field_index] += 1;
2613 if (field_use_counts[field_index] > 1) {2613 if (field_use_counts[field_index] > 1) {
2614 add_node_error(g, val_field_node, buf_sprintf("duplicate field"));2614 add_node_error(g, val_field_node, buf_sprintf("duplicate field"));
...@@ -2641,7 +2641,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry...@@ -2641,7 +2641,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
2641 }2641 }
2642 }2642 }
26432643
2644 for (int i = 0; i < actual_field_count; i += 1) {2644 for (size_t i = 0; i < actual_field_count; i += 1) {
2645 if (field_use_counts[i] == 0) {2645 if (field_use_counts[i] == 0) {
2646 add_node_error(g, node,2646 add_node_error(g, node,
2647 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i].name)));2647 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...@@ -2652,7 +2652,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
2652 container_type->data.structure.is_slice &&2652 container_type->data.structure.is_slice &&
2653 kind == ContainerInitKindArray)2653 kind == ContainerInitKindArray)
2654 {2654 {
2655 int elem_count = container_init_expr->entries.length;2655 size_t elem_count = container_init_expr->entries.length;
26562656
2657 TypeTableEntry *pointer_type = container_type->data.structure.fields[0].type_entry;2657 TypeTableEntry *pointer_type = container_type->data.structure.fields[0].type_entry;
2658 assert(pointer_type->id == TypeTableEntryIdPointer);2658 assert(pointer_type->id == TypeTableEntryIdPointer);
...@@ -2662,7 +2662,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry...@@ -2662,7 +2662,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
2662 const_val->ok = true;2662 const_val->ok = true;
2663 const_val->data.x_array.fields = allocate<ConstExprValue*>(elem_count);2663 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) {
2666 AstNode **elem_node = &container_init_expr->entries.at(i);2666 AstNode **elem_node = &container_init_expr->entries.at(i);
2667 analyze_expression(g, import, context, child_type, *elem_node);2667 analyze_expression(g, import, context, child_type, *elem_node);
26682668
...@@ -2787,7 +2787,7 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i...@@ -2787,7 +2787,7 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i
2787 AstNode *value_node;2787 AstNode *value_node;
2788 if (container_init_node) {2788 if (container_init_node) {
2789 assert(container_init_node->type == NodeTypeContainerInitExpr);2789 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;
2791 if (param_count > 1) {2791 if (param_count > 1) {
2792 AstNode *first_invalid_node = container_init_node->data.container_init_expr.entries.at(1);2792 AstNode *first_invalid_node = container_init_node->data.container_init_expr.entries.at(1);
2793 add_node_error(g, first_executing_node(first_invalid_node),2793 add_node_error(g, first_executing_node(first_invalid_node),
...@@ -2849,7 +2849,7 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i...@@ -2849,7 +2849,7 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i
2849 AstNode *decl_node = find_decl(namespace_import->block_context, field_name);2849 AstNode *decl_node = find_decl(namespace_import->block_context, field_name);
2850 if (!decl_node) {2850 if (!decl_node) {
2851 // we must now resolve all the use decls2851 // 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) {
2853 AstNode *use_decl_node = namespace_import->use_decls.at(i);2853 AstNode *use_decl_node = namespace_import->use_decls.at(i);
2854 if (!get_resolved_expr(use_decl_node->data.use.expr)->type_entry) {2854 if (!get_resolved_expr(use_decl_node->data.use.expr)->type_entry) {
2855 preview_use_decl(g, use_decl_node);2855 preview_use_decl(g, use_decl_node);
...@@ -3051,13 +3051,13 @@ static TypeTableEntry *resolve_expr_const_val_as_c_string_lit(CodeGen *g, AstNod...@@ -3051,13 +3051,13 @@ static TypeTableEntry *resolve_expr_const_val_as_c_string_lit(CodeGen *g, AstNod
3051 Expr *expr = get_resolved_expr(node);3051 Expr *expr = get_resolved_expr(node);
3052 expr->const_val.ok = true;3052 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;
3055 expr->const_val.data.x_ptr.ptr = allocate<ConstExprValue*>(len_with_null);3055 expr->const_val.data.x_ptr.ptr = allocate<ConstExprValue*>(len_with_null);
3056 expr->const_val.data.x_ptr.len = len_with_null;3056 expr->const_val.data.x_ptr.len = len_with_null;
3057 expr->const_val.data.x_ptr.is_c_str = true;3057 expr->const_val.data.x_ptr.is_c_str = true;
30583058
3059 ConstExprValue *all_chars = allocate<ConstExprValue>(len_with_null);3059 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) {
3061 ConstExprValue *this_char = &all_chars[i];3061 ConstExprValue *this_char = &all_chars[i];
3062 this_char->ok = true;3062 this_char->ok = true;
3063 bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]);3063 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...@@ -3078,7 +3078,7 @@ static TypeTableEntry *resolve_expr_const_val_as_string_lit(CodeGen *g, AstNode
3078 expr->const_val.data.x_array.fields = allocate<ConstExprValue*>(buf_len(str));3078 expr->const_val.data.x_array.fields = allocate<ConstExprValue*>(buf_len(str));
30793079
3080 ConstExprValue *all_chars = allocate<ConstExprValue>(buf_len(str));3080 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) {
3082 ConstExprValue *this_char = &all_chars[i];3082 ConstExprValue *this_char = &all_chars[i];
3083 this_char->ok = true;3083 this_char->ok = true;
3084 bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]);3084 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...@@ -4437,7 +4437,7 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B
4437 assert(node->type == NodeTypeFnCallExpr);4437 assert(node->type == NodeTypeFnCallExpr);
44384438
4439 AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr;4439 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
4442 if (actual_param_count != 1) {4442 if (actual_param_count != 1) {
4443 add_node_error(g, fn_ref_expr, buf_sprintf("cast expression expects exactly one parameter"));4443 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...@@ -4799,7 +4799,7 @@ static TypeTableEntry *analyze_c_import(CodeGen *g, ImportTableEntry *parent_imp
47994799
4800 if (errors.length > 0) {4800 if (errors.length > 0) {
4801 ErrorMsg *parent_err_msg = add_node_error(g, node, buf_sprintf("C import failed"));4801 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) {
4803 ErrorMsg *err_msg = errors.at(i);4803 ErrorMsg *err_msg = errors.at(i);
4804 err_msg_add_note(parent_err_msg, err_msg);4804 err_msg_add_note(parent_err_msg, err_msg);
4805 }4805 }
...@@ -5113,13 +5113,13 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry...@@ -5113,13 +5113,13 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
5113 }5113 }
51145114
5115 BuiltinFnEntry *builtin_fn = entry->value;5115 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
5118 node->data.fn_call_expr.builtin_fn = builtin_fn;5118 node->data.fn_call_expr.builtin_fn = builtin_fn;
51195119
5120 if (builtin_fn->param_count != actual_param_count) {5120 if (builtin_fn->param_count != actual_param_count) {
5121 add_node_error(g, node,5121 add_node_error(g, node,
5122 buf_sprintf("expected %d arguments, got %d",5122 buf_sprintf("expected %zu arguments, got %zu",
5123 builtin_fn->param_count, actual_param_count));5123 builtin_fn->param_count, actual_param_count));
5124 return g->builtin_types.entry_invalid;5124 return g->builtin_types.entry_invalid;
5125 }5125 }
...@@ -5479,11 +5479,11 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,...@@ -5479,11 +5479,11 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
5479 fn_table_entry->proto_node->data.fn_proto.generic_proto_node : nullptr;5479 fn_table_entry->proto_node->data.fn_proto.generic_proto_node : nullptr;
54805480
5481 // count parameters5481 // count parameters
5482 int struct_node_1_or_0 = struct_node ? 1 : 0;5482 size_t struct_node_1_or_0 = struct_node ? 1 : 0;
5483 int src_param_count = fn_type->data.fn.fn_type_id.param_count +5483 size_t src_param_count = fn_type->data.fn.fn_type_id.param_count +
5484 (generic_proto_node ? generic_proto_node->data.fn_proto.inline_arg_count : 0);5484 (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;5485 size_t call_param_count = node->data.fn_call_expr.params.length;
5486 int expect_arg_count = src_param_count - struct_node_1_or_0;5486 size_t expect_arg_count = src_param_count - struct_node_1_or_0;
54875487
5488 bool ok_invocation = true;5488 bool ok_invocation = true;
54895489
...@@ -5491,12 +5491,12 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,...@@ -5491,12 +5491,12 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
5491 if (call_param_count < expect_arg_count) {5491 if (call_param_count < expect_arg_count) {
5492 ok_invocation = false;5492 ok_invocation = false;
5493 add_node_error(g, node,5493 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));
5495 }5495 }
5496 } else if (expect_arg_count != call_param_count) {5496 } else if (expect_arg_count != call_param_count) {
5497 ok_invocation = false;5497 ok_invocation = false;
5498 add_node_error(g, node,5498 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));
5500 }5500 }
55015501
5502 bool all_args_const_expr = true;5502 bool all_args_const_expr = true;
...@@ -5510,9 +5510,9 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,...@@ -5510,9 +5510,9 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
55105510
5511 // analyze each parameter. in the case of a method, we already analyzed the5511 // analyze each parameter. in the case of a method, we already analyzed the
5512 // first parameter in order to figure out which struct we were calling a method on.5512 // 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;5513 size_t next_type_i = struct_node_1_or_0;
5514 for (int call_i = 0; call_i < call_param_count; call_i += 1) {5514 for (size_t call_i = 0; call_i < call_param_count; call_i += 1) {
5515 int proto_i = call_i + struct_node_1_or_0;5515 size_t proto_i = call_i + struct_node_1_or_0;
5516 AstNode **param_node = &node->data.fn_call_expr.params.at(call_i);5516 AstNode **param_node = &node->data.fn_call_expr.params.at(call_i);
5517 // determine the expected type for each parameter5517 // determine the expected type for each parameter
5518 TypeTableEntry *expected_param_type = nullptr;5518 TypeTableEntry *expected_param_type = nullptr;
...@@ -5592,30 +5592,30 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE...@@ -5592,30 +5592,30 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE
5592 AstNode *decl_node = fn_table_entry->proto_node;5592 AstNode *decl_node = fn_table_entry->proto_node;
55935593
5594 // count parameters5594 // count parameters
5595 int struct_node_1_or_0 = (struct_node ? 1 : 0);5595 size_t struct_node_1_or_0 = (struct_node ? 1 : 0);
5596 int src_param_count = decl_node->data.fn_proto.params.length;5596 size_t src_param_count = decl_node->data.fn_proto.params.length;
5597 int call_param_count = call_node->data.fn_call_expr.params.length;5597 size_t call_param_count = call_node->data.fn_call_expr.params.length;
55985598
5599 if (src_param_count != call_param_count + struct_node_1_or_0) {5599 if (src_param_count != call_param_count + struct_node_1_or_0) {
5600 add_node_error(g, call_node,5600 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));
5602 return g->builtin_types.entry_invalid;5602 return g->builtin_types.entry_invalid;
5603 }5603 }
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;
5606 assert(inline_or_var_type_arg_count > 0);5606 assert(inline_or_var_type_arg_count > 0);
56075607
5608 BlockContext *child_context = decl_node->owner->block_context;5608 BlockContext *child_context = decl_node->owner->block_context;
5609 int next_generic_param_index = 0;5609 size_t next_generic_param_index = 0;
56105610
5611 GenericFnTypeId *generic_fn_type_id = allocate<GenericFnTypeId>(1);5611 GenericFnTypeId *generic_fn_type_id = allocate<GenericFnTypeId>(1);
5612 generic_fn_type_id->decl_node = decl_node;5612 generic_fn_type_id->decl_node = decl_node;
5613 generic_fn_type_id->generic_param_count = inline_or_var_type_arg_count;5613 generic_fn_type_id->generic_param_count = inline_or_var_type_arg_count;
5614 generic_fn_type_id->generic_params = allocate<GenericParamValue>(inline_or_var_type_arg_count);5614 generic_fn_type_id->generic_params = allocate<GenericParamValue>(inline_or_var_type_arg_count);
56155615
5616 int next_impl_i = 0;5616 size_t next_impl_i = 0;
5617 for (int call_i = 0; call_i < call_param_count; call_i += 1) {5617 for (size_t call_i = 0; call_i < call_param_count; call_i += 1) {
5618 int proto_i = call_i + struct_node_1_or_0;5618 size_t proto_i = call_i + struct_node_1_or_0;
5619 AstNode *generic_param_decl_node = decl_node->data.fn_proto.params.at(proto_i);5619 AstNode *generic_param_decl_node = decl_node->data.fn_proto.params.at(proto_i);
5620 assert(generic_param_decl_node->type == NodeTypeParamDecl);5620 assert(generic_param_decl_node->type == NodeTypeParamDecl);
56215621
...@@ -5688,10 +5688,10 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE...@@ -5688,10 +5688,10 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE
5688 impl_decl_node->data.fn_proto.generic_proto_node = decl_node;5688 impl_decl_node->data.fn_proto.generic_proto_node = decl_node;
56895689
5690 // replace var arg types with actual types5690 // 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) {
5692 GenericParamValue *generic_param_value = &generic_fn_type_id->generic_params[generic_arg_i];5692 GenericParamValue *generic_param_value = &generic_fn_type_id->generic_params[generic_arg_i];
5693 if (!generic_param_value->node) {5693 if (!generic_param_value->node) {
5694 int impl_i = generic_param_value->impl_index;5694 size_t impl_i = generic_param_value->impl_index;
5695 AstNode *impl_param_decl_node = impl_decl_node->data.fn_proto.params.at(impl_i);5695 AstNode *impl_param_decl_node = impl_decl_node->data.fn_proto.params.at(impl_i);
5696 assert(impl_param_decl_node->type == NodeTypeParamDecl);5696 assert(impl_param_decl_node->type == NodeTypeParamDecl);
56975697
...@@ -5721,12 +5721,12 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp...@@ -5721,12 +5721,12 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
5721 assert(decl_node->type == NodeTypeContainerDecl);5721 assert(decl_node->type == NodeTypeContainerDecl);
5722 ZigList<AstNode *> *generic_params = &decl_node->data.struct_decl.generic_params;5722 ZigList<AstNode *> *generic_params = &decl_node->data.struct_decl.generic_params;
57235723
5724 int expected_param_count = generic_params->length;5724 size_t expected_param_count = generic_params->length;
5725 int actual_param_count = node->data.fn_call_expr.params.length;5725 size_t actual_param_count = node->data.fn_call_expr.params.length;
57265726
5727 if (actual_param_count != expected_param_count) {5727 if (actual_param_count != expected_param_count) {
5728 add_node_error(g, first_executing_node(node),5728 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));
5730 return g->builtin_types.entry_invalid;5730 return g->builtin_types.entry_invalid;
5731 }5731 }
57325732
...@@ -5736,7 +5736,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp...@@ -5736,7 +5736,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
5736 generic_fn_type_id->generic_params = allocate<GenericParamValue>(actual_param_count);5736 generic_fn_type_id->generic_params = allocate<GenericParamValue>(actual_param_count);
57375737
5738 BlockContext *child_context = decl_node->owner->block_context;5738 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) {
5740 AstNode *generic_param_decl_node = generic_params->at(i);5740 AstNode *generic_param_decl_node = generic_params->at(i);
5741 assert(generic_param_decl_node->type == NodeTypeParamDecl);5741 assert(generic_param_decl_node->type == NodeTypeParamDecl);
57425742
...@@ -6104,7 +6104,7 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,...@@ -6104,7 +6104,7 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
6104 ConstExprValue *const_val = &get_resolved_expr(node)->const_val;6104 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;
6108 AstNode **peer_nodes = allocate<AstNode*>(prong_count);6108 AstNode **peer_nodes = allocate<AstNode*>(prong_count);
6109 TypeTableEntry **peer_types = allocate<TypeTableEntry*>(prong_count);6109 TypeTableEntry **peer_types = allocate<TypeTableEntry*>(prong_count);
61106110
...@@ -6118,18 +6118,18 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,...@@ -6118,18 +6118,18 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
6118 }6118 }
61196119
61206120
6121 int *field_use_counts = nullptr;6121 size_t *field_use_counts = nullptr;
6122 HashMap<int, AstNode *, int_hash, int_eq> err_use_nodes = {};6122 HashMap<int, AstNode *, int_hash, int_eq> err_use_nodes = {};
6123 if (expr_type->id == TypeTableEntryIdEnum) {6123 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);
6125 } else if (expr_type->id == TypeTableEntryIdErrorUnion) {6125 } else if (expr_type->id == TypeTableEntryIdErrorUnion) {
6126 err_use_nodes.init(10);6126 err_use_nodes.init(10);
6127 }6127 }
61286128
6129 int *const_chosen_prong_index = &node->data.switch_expr.const_chosen_prong_index;6129 size_t *const_chosen_prong_index = &node->data.switch_expr.const_chosen_prong_index;
6130 *const_chosen_prong_index = -1;6130 *const_chosen_prong_index = SIZE_MAX;
6131 AstNode *else_prong = nullptr;6131 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) {
6133 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);6133 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);
61346134
6135 TypeTableEntry *var_type;6135 TypeTableEntry *var_type;
...@@ -6143,14 +6143,14 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,...@@ -6143,14 +6143,14 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
6143 }6143 }
6144 var_type = expr_type;6144 var_type = expr_type;
6145 var_is_target_expr = true;6145 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) {
6147 *const_chosen_prong_index = prong_i;6147 *const_chosen_prong_index = prong_i;
6148 }6148 }
6149 } else {6149 } else {
6150 bool all_agree_on_var_type = true;6150 bool all_agree_on_var_type = true;
6151 var_type = nullptr;6151 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) {
6154 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);6154 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
6155 if (item_node->type == NodeTypeSwitchRange) {6155 if (item_node->type == NodeTypeSwitchRange) {
6156 zig_panic("TODO range in switch statement");6156 zig_panic("TODO range in switch statement");
...@@ -6274,7 +6274,7 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,...@@ -6274,7 +6274,7 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
6274 }6274 }
6275 }6275 }
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) {
6278 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);6278 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);
6279 BlockContext *child_context = prong_node->data.switch_prong.block_context;6279 BlockContext *child_context = prong_node->data.switch_prong.block_context;
6280 child_context->codegen_excluded = expr_val->ok && (*const_chosen_prong_index != prong_i);6280 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,...@@ -6312,7 +6312,7 @@ static TypeTableEntry *analyze_switch_expr(CodeGen *g, ImportTableEntry *import,
6312 peer_nodes, peer_types, prong_count);6312 peer_nodes, peer_types, prong_count);
63136313
6314 if (expr_val->ok) {6314 if (expr_val->ok) {
6315 assert(*const_chosen_prong_index != -1);6315 assert(*const_chosen_prong_index != SIZE_MAX);
63166316
6317 *const_val = get_resolved_expr(peer_nodes[*const_chosen_prong_index])->const_val;6317 *const_val = get_resolved_expr(peer_nodes[*const_chosen_prong_index])->const_val;
6318 // the target expr depends on a compile var because we have an error on unnecessary6318 // 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,...@@ -6460,7 +6460,7 @@ static TypeTableEntry *analyze_block_expr(CodeGen *g, ImportTableEntry *import,
6460 node->data.block.child_block = child_context;6460 node->data.block.child_block = child_context;
6461 TypeTableEntry *return_type = g->builtin_types.entry_void;6461 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) {
6464 AstNode *child = node->data.block.statements.at(i);6464 AstNode *child = node->data.block.statements.at(i);
6465 if (child->type == NodeTypeLabel) {6465 if (child->type == NodeTypeLabel) {
6466 FnTableEntry *fn_table_entry = child_context->fn_entry;6466 FnTableEntry *fn_table_entry = child_context->fn_entry;
...@@ -6524,7 +6524,7 @@ static TypeTableEntry *analyze_asm_expr(CodeGen *g, ImportTableEntry *import, Bl...@@ -6524,7 +6524,7 @@ static TypeTableEntry *analyze_asm_expr(CodeGen *g, ImportTableEntry *import, Bl
65246524
6525 node->data.asm_expr.return_count = 0;6525 node->data.asm_expr.return_count = 0;
6526 TypeTableEntry *return_type = g->builtin_types.entry_void;6526 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) {
6528 AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);6528 AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);
6529 if (asm_output->return_type) {6529 if (asm_output->return_type) {
6530 node->data.asm_expr.return_count += 1;6530 node->data.asm_expr.return_count += 1;
...@@ -6547,7 +6547,7 @@ static TypeTableEntry *analyze_asm_expr(CodeGen *g, ImportTableEntry *import, Bl...@@ -6547,7 +6547,7 @@ static TypeTableEntry *analyze_asm_expr(CodeGen *g, ImportTableEntry *import, Bl
6547 }6547 }
6548 }6548 }
6549 }6549 }
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) {
6551 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);6551 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
6552 analyze_expression(g, import, context, nullptr, asm_input->expr);6552 analyze_expression(g, import, context, nullptr, asm_input->expr);
6553 }6553 }
...@@ -6757,7 +6757,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -6757,7 +6757,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
67576757
6758 TypeTableEntry *fn_type = fn_table_entry->type_entry;6758 TypeTableEntry *fn_type = fn_table_entry->type_entry;
6759 AstNodeFnProto *fn_proto = &fn_proto_node->data.fn_proto;6759 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) {
6761 AstNode *param_decl_node = fn_proto->params.at(i);6761 AstNode *param_decl_node = fn_proto->params.at(i);
6762 assert(param_decl_node->type == NodeTypeParamDecl);6762 assert(param_decl_node->type == NodeTypeParamDecl);
67636763
...@@ -6797,13 +6797,13 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -6797,13 +6797,13 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
67976797
6798 node->data.fn_def.implicit_return_type = block_return_type;6798 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) {
6801 AstNode *goto_node = fn_table_entry->goto_list.at(i);6801 AstNode *goto_node = fn_table_entry->goto_list.at(i);
6802 assert(goto_node->type == NodeTypeGoto);6802 assert(goto_node->type == NodeTypeGoto);
6803 analyze_goto_pass2(g, import, goto_node);6803 analyze_goto_pass2(g, import, goto_node);
6804 }6804 }
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) {
6807 LabelTableEntry *label = fn_table_entry->all_labels.at(i);6807 LabelTableEntry *label = fn_table_entry->all_labels.at(i);
6808 if (!label->used) {6808 if (!label->used) {
6809 add_node_error(g, label->decl_node,6809 add_node_error(g, label->decl_node,
...@@ -6846,8 +6846,8 @@ static void add_top_level_decl(CodeGen *g, ImportTableEntry *import, BlockContex...@@ -6846,8 +6846,8 @@ static void add_top_level_decl(CodeGen *g, ImportTableEntry *import, BlockContex
6846static void count_inline_and_var_args(AstNode *proto_node) {6846static void count_inline_and_var_args(AstNode *proto_node) {
6847 assert(proto_node->type == NodeTypeFnProto);6847 assert(proto_node->type == NodeTypeFnProto);
68486848
6849 int *inline_arg_count = &proto_node->data.fn_proto.inline_arg_count;6849 size_t *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;6850 size_t *inline_or_var_type_arg_count = &proto_node->data.fn_proto.inline_or_var_type_arg_count;
68516851
6852 *inline_arg_count = 0;6852 *inline_arg_count = 0;
6853 *inline_or_var_type_arg_count = 0;6853 *inline_or_var_type_arg_count = 0;
...@@ -6855,7 +6855,7 @@ static void count_inline_and_var_args(AstNode *proto_node) {...@@ -6855,7 +6855,7 @@ static void count_inline_and_var_args(AstNode *proto_node) {
6855 // TODO run these nodes through the type analysis system rather than looking for6855 // TODO run these nodes through the type analysis system rather than looking for
6856 // specialized ast nodes. this would get fooled by `{var}` instead of `var` which6856 // specialized ast nodes. this would get fooled by `{var}` instead of `var` which
6857 // is supposed to be equivalent6857 // 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) {
6859 AstNode *param_node = proto_node->data.fn_proto.params.at(i);6859 AstNode *param_node = proto_node->data.fn_proto.params.at(i);
6860 assert(param_node->type == NodeTypeParamDecl);6860 assert(param_node->type == NodeTypeParamDecl);
6861 if (param_node->data.param_decl.is_inline) {6861 if (param_node->data.param_decl.is_inline) {
...@@ -6870,7 +6870,7 @@ static void count_inline_and_var_args(AstNode *proto_node) {...@@ -6870,7 +6870,7 @@ static void count_inline_and_var_args(AstNode *proto_node) {
6870static void scan_decls(CodeGen *g, ImportTableEntry *import, BlockContext *context, AstNode *node) {6870static void scan_decls(CodeGen *g, ImportTableEntry *import, BlockContext *context, AstNode *node) {
6871 switch (node->type) {6871 switch (node->type) {
6872 case NodeTypeRoot:6872 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) {
6874 AstNode *child = import->root->data.root.top_level_decls.at(i);6874 AstNode *child = import->root->data.root.top_level_decls.at(i);
6875 scan_decls(g, import, context, child);6875 scan_decls(g, import, context, child);
6876 }6876 }
...@@ -6992,7 +6992,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *...@@ -6992,7 +6992,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
6992 tld->import->any_imports_failed = true;6992 tld->import->any_imports_failed = true;
6993 }6993 }
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) {
6996 AstNode *decl_node = target_import->root->data.root.top_level_decls.at(i);6996 AstNode *decl_node = target_import->root->data.root.top_level_decls.at(i);
6997 if (decl_node->type == NodeTypeFnDef) {6997 if (decl_node->type == NodeTypeFnDef) {
6998 decl_node = decl_node->data.fn_def.fn_proto;6998 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 *...@@ -7018,7 +7018,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
7018 }7018 }
7019 }7019 }
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) {
7022 AstNode *use_decl_node = target_import->use_decls.at(i);7022 AstNode *use_decl_node = target_import->use_decls.at(i);
7023 TopLevelDecl *target_tld = get_as_top_level_decl(use_decl_node);7023 TopLevelDecl *target_tld = get_as_top_level_decl(use_decl_node);
7024 if (target_tld->visib_mod != VisibModPrivate) {7024 if (target_tld->visib_mod != VisibModPrivate) {
...@@ -7104,7 +7104,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,...@@ -7104,7 +7104,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
71047104
71057105
7106 assert(import_entry->root->type == NodeTypeRoot);7106 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) {
7108 AstNode *top_level_decl = import_entry->root->data.root.top_level_decls.at(decl_i);7108 AstNode *top_level_decl = import_entry->root->data.root.top_level_decls.at(decl_i);
71097109
7110 if (top_level_decl->type == NodeTypeFnDef) {7110 if (top_level_decl->type == NodeTypeFnDef) {
...@@ -7135,7 +7135,7 @@ void semantic_analyze(CodeGen *g) {...@@ -7135,7 +7135,7 @@ void semantic_analyze(CodeGen *g) {
7135 preview_use_decl(g, use_decl_node);7135 preview_use_decl(g, use_decl_node);
7136 }7136 }
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) {
7139 AstNode *use_decl_node = g->use_queue.at(i);7139 AstNode *use_decl_node = g->use_queue.at(i);
7140 resolve_use_decl(g, use_decl_node);7140 resolve_use_decl(g, use_decl_node);
7141 }7141 }
...@@ -7146,7 +7146,7 @@ void semantic_analyze(CodeGen *g) {...@@ -7146,7 +7146,7 @@ void semantic_analyze(CodeGen *g) {
7146 resolve_top_level_decl(g, decl_node, pointer_only);7146 resolve_top_level_decl(g, decl_node, pointer_only);
7147 }7147 }
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) {
7150 FnTableEntry *fn_entry = g->fn_defs.at(i);7150 FnTableEntry *fn_entry = g->fn_defs.at(i);
7151 if (fn_entry->anal_state == FnAnalStateReady) {7151 if (fn_entry->anal_state == FnAnalStateReady) {
7152 analyze_fn_body(g, fn_entry);7152 analyze_fn_body(g, fn_entry);
...@@ -7321,8 +7321,8 @@ bool is_node_void_expr(AstNode *node) {...@@ -7321,8 +7321,8 @@ bool is_node_void_expr(AstNode *node) {
7321 return false;7321 return false;
7322}7322}
73237323
7324TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits) {7324TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, size_t size_in_bits) {
7325 int index;7325 size_t index;
7326 if (size_in_bits == 8) {7326 if (size_in_bits == 8) {
7327 index = 0;7327 index = 0;
7328 } else if (size_in_bits == 16) {7328 } else if (size_in_bits == 16) {
...@@ -7337,7 +7337,7 @@ TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits)...@@ -7337,7 +7337,7 @@ TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, int size_in_bits)
7337 return &g->builtin_types.entry_int[is_signed ? 0 : 1][index];7337 return &g->builtin_types.entry_int[is_signed ? 0 : 1][index];
7338}7338}
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) {
7341 return *get_int_type_ptr(g, is_signed, size_in_bits);7341 return *get_int_type_ptr(g, is_signed, size_in_bits);
7342}7342}
73437343
...@@ -7417,7 +7417,7 @@ uint32_t fn_type_id_hash(FnTypeId *id) {...@@ -7417,7 +7417,7 @@ uint32_t fn_type_id_hash(FnTypeId *id) {
7417 result += id->is_cold ? 3605523458 : 0;7417 result += id->is_cold ? 3605523458 : 0;
7418 result += id->is_var_args ? 1931444534 : 0;7418 result += id->is_var_args ? 1931444534 : 0;
7419 result += hash_ptr(id->return_type);7419 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) {
7421 FnTypeParamInfo *info = &id->param_info[i];7421 FnTypeParamInfo *info = &id->param_info[i];
7422 result += info->is_noalias ? 892356923 : 0;7422 result += info->is_noalias ? 892356923 : 0;
7423 result += hash_ptr(info->type);7423 result += hash_ptr(info->type);
...@@ -7435,7 +7435,7 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {...@@ -7435,7 +7435,7 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {
7435 {7435 {
7436 return false;7436 return false;
7437 }7437 }
7438 for (int i = 0; i < a->param_count; i += 1) {7438 for (size_t i = 0; i < a->param_count; i += 1) {
7439 FnTypeParamInfo *a_param_info = &a->param_info[i];7439 FnTypeParamInfo *a_param_info = &a->param_info[i];
7440 FnTypeParamInfo *b_param_info = &b->param_info[i];7440 FnTypeParamInfo *b_param_info = &b->param_info[i];
74417441
...@@ -7511,7 +7511,7 @@ static uint32_t hash_const_val(TypeTableEntry *type, ConstExprValue *const_val)...@@ -7511,7 +7511,7 @@ static uint32_t hash_const_val(TypeTableEntry *type, ConstExprValue *const_val)
7511uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {7511uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {
7512 uint32_t result = 0;7512 uint32_t result = 0;
7513 result += hash_ptr(id->decl_node);7513 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) {
7515 GenericParamValue *generic_param = &id->generic_params[i];7515 GenericParamValue *generic_param = &id->generic_params[i];
7516 if (generic_param->node) {7516 if (generic_param->node) {
7517 ConstExprValue *const_val = &get_resolved_expr(generic_param->node)->const_val;7517 ConstExprValue *const_val = &get_resolved_expr(generic_param->node)->const_val;
...@@ -7526,7 +7526,7 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {...@@ -7526,7 +7526,7 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id) {
7526bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {7526bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
7527 if (a->decl_node != b->decl_node) return false;7527 if (a->decl_node != b->decl_node) return false;
7528 assert(a->generic_param_count == b->generic_param_count);7528 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) {
7530 GenericParamValue *a_val = &a->generic_params[i];7530 GenericParamValue *a_val = &a->generic_params[i];
7531 GenericParamValue *b_val = &b->generic_params[i];7531 GenericParamValue *b_val = &b->generic_params[i];
7532 if (a_val->type != b_val->type) return false;7532 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);...@@ -19,8 +19,8 @@ BlockContext *new_block_context(AstNode *node, BlockContext *parent);
19Expr *get_resolved_expr(AstNode *node);19Expr *get_resolved_expr(AstNode *node);
20bool is_node_void_expr(AstNode *node);20bool is_node_void_expr(AstNode *node);
21uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);21uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
22TypeTableEntry **get_int_type_ptr(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, int size_in_bits);23TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, size_t size_in_bits);
24TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);24TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
25TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);25TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);
26TypeTableEntry *get_typedecl_type(CodeGen *g, const char *name, TypeTableEntry *child_type);26TypeTableEntry *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) {...@@ -292,7 +292,7 @@ static bool is_printable(uint8_t c) {
292292
293static void string_literal_escape(Buf *source, Buf *dest) {293static void string_literal_escape(Buf *source, Buf *dest) {
294 buf_resize(dest, 0);294 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) {
296 uint8_t c = *((uint8_t*)buf_ptr(source) + i);296 uint8_t c = *((uint8_t*)buf_ptr(source) + i);
297 if (is_printable(c)) {297 if (is_printable(c)) {
298 buf_append_char(dest, c);298 buf_append_char(dest, c);
...@@ -330,7 +330,7 @@ static bool is_valid_bare_symbol(Buf *symbol) {...@@ -330,7 +330,7 @@ static bool is_valid_bare_symbol(Buf *symbol) {
330 if (!is_alpha_under(first_char)) {330 if (!is_alpha_under(first_char)) {
331 return false;331 return false;
332 }332 }
333 for (int i = 1; i < buf_len(symbol); i += 1) {333 for (size_t i = 1; i < buf_len(symbol); i += 1) {
334 uint8_t c = *((uint8_t*)buf_ptr(symbol) + i);334 uint8_t c = *((uint8_t*)buf_ptr(symbol) + i);
335 if (!is_alpha_under(c) && !is_digit(c)) {335 if (!is_alpha_under(c) && !is_digit(c)) {
336 return false;336 return false;
...@@ -358,7 +358,7 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -358,7 +358,7 @@ static void render_node(AstRender *ar, AstNode *node) {
358358
359 switch (node->type) {359 switch (node->type) {
360 case NodeTypeRoot:360 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) {
362 AstNode *child = node->data.root.top_level_decls.at(i);362 AstNode *child = node->data.root.top_level_decls.at(i);
363 print_indent(ar);363 print_indent(ar);
364 render_node(ar, child);364 render_node(ar, child);
...@@ -417,7 +417,7 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -417,7 +417,7 @@ static void render_node(AstRender *ar, AstNode *node) {
417 ZigList<AstNode *> *directives =417 ZigList<AstNode *> *directives =
418 node->data.fn_def.fn_proto->data.fn_proto.top_level_decl.directives;418 node->data.fn_def.fn_proto->data.fn_proto.top_level_decl.directives;
419 if (directives) {419 if (directives) {
420 for (int i = 0; i < directives->length; i += 1) {420 for (size_t i = 0; i < directives->length; i += 1) {
421 render_node(ar, directives->at(i));421 render_node(ar, directives->at(i));
422 }422 }
423 }423 }
...@@ -433,7 +433,7 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -433,7 +433,7 @@ static void render_node(AstRender *ar, AstNode *node) {
433 case NodeTypeBlock:433 case NodeTypeBlock:
434 fprintf(ar->f, "{\n");434 fprintf(ar->f, "{\n");
435 ar->indent += ar->indent_size;435 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) {
437 AstNode *statement = node->data.block.statements.at(i);437 AstNode *statement = node->data.block.statements.at(i);
438 print_indent(ar);438 print_indent(ar);
439 render_node(ar, statement);439 render_node(ar, statement);
...@@ -561,7 +561,7 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -561,7 +561,7 @@ static void render_node(AstRender *ar, AstNode *node) {
561 fprintf(ar->f, ")");561 fprintf(ar->f, ")");
562 }562 }
563 fprintf(ar->f, "(");563 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) {
565 AstNode *param = node->data.fn_call_expr.params.at(i);565 AstNode *param = node->data.fn_call_expr.params.at(i);
566 if (i != 0) {566 if (i != 0) {
567 fprintf(ar->f, ", ");567 fprintf(ar->f, ", ");
...@@ -628,7 +628,7 @@ static void render_node(AstRender *ar, AstNode *node) {...@@ -628,7 +628,7 @@ static void render_node(AstRender *ar, AstNode *node) {
628 const char *container_str = container_string(node->data.struct_decl.kind);628 const char *container_str = container_string(node->data.struct_decl.kind);
629 fprintf(ar->f, "%s%s %s {\n", pub_str, container_str, struct_name);629 fprintf(ar->f, "%s%s %s {\n", pub_str, container_str, struct_name);
630 ar->indent += ar->indent_size;630 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) {
632 AstNode *field_node = node->data.struct_decl.fields.at(field_i);632 AstNode *field_node = node->data.struct_decl.fields.at(field_i);
633 assert(field_node->type == NodeTypeStructField);633 assert(field_node->type == NodeTypeStructField);
634 print_indent(ar);634 print_indent(ar);
src/bignum.cpp+1-1
...@@ -43,7 +43,7 @@ void bignum_init_signed(BigNum *dest, int64_t x) {...@@ -43,7 +43,7 @@ void bignum_init_signed(BigNum *dest, int64_t x) {
43}43}
4444
45void bignum_init_bignum(BigNum *dest, BigNum *src) {45void bignum_init_bignum(BigNum *dest, BigNum *src) {
46 memcpy(dest, src, sizeof(BigNum));46 safe_memcpy(dest, src, 1);
47}47}
4848
49bool bignum_fits_in_bits(BigNum *bn, int bit_count, bool is_signed) {49bool 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, ...) {...@@ -41,7 +41,7 @@ void buf_appendf(Buf *buf, const char *format, ...) {
4141
42 size_t required_size = len1 + 1;42 size_t required_size = len1 + 1;
4343
44 int orig_len = buf_len(buf);44 size_t orig_len = buf_len(buf);
4545
46 buf_resize(buf, orig_len + len1);46 buf_resize(buf, orig_len + len1);
4747
...@@ -62,7 +62,7 @@ uint32_t buf_hash(Buf *buf) {...@@ -62,7 +62,7 @@ uint32_t buf_hash(Buf *buf) {
62 assert(buf->list.length);62 assert(buf->list.length);
63 // FNV 32-bit hash63 // FNV 32-bit hash
64 uint32_t h = 2166136261;64 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) {
66 h = h ^ ((uint8_t)buf->list.at(i));66 h = h ^ ((uint8_t)buf->list.at(i));
67 h = h * 16777619;67 h = h * 16777619;
68 }68 }
src/buffer.hpp+23-25
...@@ -27,7 +27,7 @@ Buf *buf_sprintf(const char *format, ...)...@@ -27,7 +27,7 @@ Buf *buf_sprintf(const char *format, ...)
27 __attribute__ ((format (printf, 1, 2)));27 __attribute__ ((format (printf, 1, 2)));
28Buf *buf_vprintf(const char *format, va_list ap);28Buf *buf_vprintf(const char *format, va_list ap);
2929
30static inline int buf_len(Buf *buf) {30static inline size_t buf_len(Buf *buf) {
31 assert(buf->list.length);31 assert(buf->list.length);
32 return buf->list.length - 1;32 return buf->list.length - 1;
33}33}
...@@ -37,31 +37,29 @@ static inline char *buf_ptr(Buf *buf) {...@@ -37,31 +37,29 @@ static inline char *buf_ptr(Buf *buf) {
37 return buf->list.items;37 return buf->list.items;
38}38}
3939
40static inline void buf_resize(Buf *buf, int new_len) {40static inline void buf_resize(Buf *buf, size_t new_len) {
41 buf->list.resize(new_len + 1);41 buf->list.resize(new_len + 1);
42 buf->list.at(buf_len(buf)) = 0;42 buf->list.at(buf_len(buf)) = 0;
43}43}
4444
45static inline Buf *buf_alloc(void) {45static inline Buf *buf_alloc_fixed(size_t size) {
46 Buf *buf = allocate<Buf>(1);46 Buf *buf = allocate<Buf>(1);
47 buf_resize(buf, 0);47 buf_resize(buf, size);
48 return buf;48 return buf;
49}49}
5050
51static inline Buf *buf_alloc_fixed(int size) {51static inline Buf *buf_alloc(void) {
52 Buf *buf = allocate<Buf>(1);52 return buf_alloc_fixed(0);
53 buf_resize(buf, size);
54 return buf;
55}53}
5654
57static inline void buf_deinit(Buf *buf) {55static inline void buf_deinit(Buf *buf) {
58 buf->list.deinit();56 buf->list.deinit();
59}57}
6058
61static inline void buf_init_from_mem(Buf *buf, const char *ptr, int len) {59static inline void buf_init_from_mem(Buf *buf, const char *ptr, size_t len) {
62 assert(len >= 0);60 assert(len != SIZE_MAX);
63 buf->list.resize(len + 1);61 buf->list.resize(len + 1);
64 memcpy(buf_ptr(buf), ptr, len);62 safe_memcpy(buf_ptr(buf), ptr, len);
65 buf->list.at(buf_len(buf)) = 0;63 buf->list.at(buf_len(buf)) = 0;
66}64}
6765
...@@ -73,8 +71,8 @@ static inline void buf_init_from_buf(Buf *buf, Buf *other) {...@@ -73,8 +71,8 @@ static inline void buf_init_from_buf(Buf *buf, Buf *other) {
73 buf_init_from_mem(buf, buf_ptr(other), buf_len(other));71 buf_init_from_mem(buf, buf_ptr(other), buf_len(other));
74}72}
7573
76static inline Buf *buf_create_from_mem(const char *ptr, int len) {74static inline Buf *buf_create_from_mem(const char *ptr, size_t len) {
77 assert(len >= 0);75 assert(len != SIZE_MAX);
78 Buf *buf = allocate<Buf>(1);76 Buf *buf = allocate<Buf>(1);
79 buf_init_from_mem(buf, ptr, len);77 buf_init_from_mem(buf, ptr, len);
80 return buf;78 return buf;
...@@ -88,25 +86,25 @@ static inline Buf *buf_create_from_buf(Buf *buf) {...@@ -88,25 +86,25 @@ static inline Buf *buf_create_from_buf(Buf *buf) {
88 return buf_create_from_mem(buf_ptr(buf), buf_len(buf));86 return buf_create_from_mem(buf_ptr(buf), buf_len(buf));
89}87}
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) {
92 assert(in_buf->list.length);90 assert(in_buf->list.length);
93 assert(start >= 0);91 assert(start != SIZE_MAX);
94 assert(end >= 0);92 assert(end != SIZE_MAX);
95 assert(start < buf_len(in_buf));93 assert(start < buf_len(in_buf));
96 assert(end <= buf_len(in_buf));94 assert(end <= buf_len(in_buf));
97 Buf *out_buf = allocate<Buf>(1);95 Buf *out_buf = allocate<Buf>(1);
98 out_buf->list.resize(end - start + 1);96 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);
100 out_buf->list.at(buf_len(out_buf)) = 0;98 out_buf->list.at(buf_len(out_buf)) = 0;
101 return out_buf;99 return out_buf;
102}100}
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) {
105 assert(buf->list.length);103 assert(buf->list.length);
106 assert(mem_len >= 0);104 assert(mem_len != SIZE_MAX);
107 int old_len = buf_len(buf);105 size_t old_len = buf_len(buf);
108 buf_resize(buf, old_len + mem_len);106 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);
110 buf->list.at(buf_len(buf)) = 0;108 buf->list.at(buf_len(buf)) = 0;
111}109}
112110
...@@ -128,7 +126,7 @@ static inline void buf_append_char(Buf *buf, uint8_t c) {...@@ -128,7 +126,7 @@ static inline void buf_append_char(Buf *buf, uint8_t c) {
128void buf_appendf(Buf *buf, const char *format, ...)126void buf_appendf(Buf *buf, const char *format, ...)
129 __attribute__ ((format (printf, 2, 3)));127 __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) {
132 assert(buf->list.length);130 assert(buf->list.length);
133 if (buf_len(buf) != mem_len)131 if (buf_len(buf) != mem_len)
134 return false;132 return false;
...@@ -140,7 +138,7 @@ static inline bool buf_eql_str(Buf *buf, const char *str) {...@@ -140,7 +138,7 @@ static inline bool buf_eql_str(Buf *buf, const char *str) {
140 return buf_eql_mem(buf, str, strlen(str));138 return buf_eql_mem(buf, str, strlen(str));
141}139}
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) {
144 if (buf_len(buf) < mem_len) {142 if (buf_len(buf) < mem_len) {
145 return false;143 return false;
146 }144 }
...@@ -155,7 +153,7 @@ static inline bool buf_starts_with_str(Buf *buf, const char *str) {...@@ -155,7 +153,7 @@ static inline bool buf_starts_with_str(Buf *buf, const char *str) {
155 return buf_starts_with_mem(buf, str, strlen(str));153 return buf_starts_with_mem(buf, str, strlen(str));
156}154}
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) {
159 if (buf_len(buf) < mem_len) {157 if (buf_len(buf) < mem_len) {
160 return false;158 return false;
161 }159 }
...@@ -170,7 +168,7 @@ bool buf_eql_buf(Buf *buf, Buf *other);...@@ -170,7 +168,7 @@ bool buf_eql_buf(Buf *buf, Buf *other);
170uint32_t buf_hash(Buf *buf);168uint32_t buf_hash(Buf *buf);
171169
172static inline void buf_upcase(Buf *buf) {170static 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) {
174 buf_ptr(buf)[i] = toupper(buf_ptr(buf)[i]);172 buf_ptr(buf)[i] = toupper(buf_ptr(buf)[i]);
175 }173 }
176}174}
src/codegen.cpp+109-108
...@@ -111,7 +111,7 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) {...@@ -111,7 +111,7 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) {
111 return g;111 return g;
112}112}
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) {
115 g->clang_argv = args;115 g->clang_argv = args;
116 g->clang_argv_len = len;116 g->clang_argv_len = len;
117}117}
...@@ -166,6 +166,7 @@ void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) {...@@ -166,6 +166,7 @@ void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) {
166166
167void codegen_set_zig_std_dir(CodeGen *g, Buf *zig_std_dir) {167void codegen_set_zig_std_dir(CodeGen *g, Buf *zig_std_dir) {
168 g->zig_std_dir = zig_std_dir;168 g->zig_std_dir = zig_std_dir;
169
169 g->std_package->root_src_dir = *zig_std_dir;170 g->std_package->root_src_dir = *zig_std_dir;
170}171}
171172
...@@ -261,7 +262,7 @@ enum AddSubMul {...@@ -261,7 +262,7 @@ enum AddSubMul {
261 AddSubMulMul = 2,262 AddSubMulMul = 2,
262};263};
263264
264static int bits_index(int size_in_bits) {265static size_t bits_index(size_t size_in_bits) {
265 switch (size_in_bits) {266 switch (size_in_bits) {
266 case 8:267 case 8:
267 return 0;268 return 0;
...@@ -281,7 +282,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_...@@ -281,7 +282,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_
281{282{
282 assert(type_entry->id == TypeTableEntryIdInt);283 assert(type_entry->id == TypeTableEntryIdInt);
283 const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;284 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
286 LLVMTypeRef return_elem_types[] = {287 LLVMTypeRef return_elem_types[] = {
287 type_entry->type_ref,288 type_entry->type_ref,
...@@ -301,9 +302,9 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_...@@ -301,9 +302,9 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_
301static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry, AddSubMul add_sub_mul) {302static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry, AddSubMul add_sub_mul) {
302 assert(type_entry->id == TypeTableEntryIdInt);303 assert(type_entry->id == TypeTableEntryIdInt);
303 // [0-signed,1-unsigned][0-add,1-sub,2-mul][0-8,1-16,2-32,3-64]304 // [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 size_t index0 = type_entry->data.integral.is_signed ? 0 : 1;
305 int index1 = add_sub_mul;306 size_t index1 = add_sub_mul;
306 int index2 = bits_index(type_entry->data.integral.bit_count);307 size_t index2 = bits_index(type_entry->data.integral.bit_count);
307 LLVMValueRef *fn = &g->int_overflow_fns[index0][index1][index2];308 LLVMValueRef *fn = &g->int_overflow_fns[index0][index1][index2];
308 if (*fn) {309 if (*fn) {
309 return *fn;310 return *fn;
...@@ -325,12 +326,12 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,...@@ -325,12 +326,12 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
325326
326static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, BuiltinFnId fn_id) {327static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, BuiltinFnId fn_id) {
327 // [0-ctz,1-clz][0-8,1-16,2-32,3-64]328 // [0-ctz,1-clz][0-8,1-16,2-32,3-64]
328 int index0 = (fn_id == BuiltinFnIdCtz) ? 0 : 1;329 size_t index0 = (fn_id == BuiltinFnIdCtz) ? 0 : 1;
329 int index1 = bits_index(int_type->data.integral.bit_count);330 size_t index1 = bits_index(int_type->data.integral.bit_count);
330 LLVMValueRef *fn = &g->int_builtin_fns[index0][index1];331 LLVMValueRef *fn = &g->int_builtin_fns[index0][index1];
331 if (!*fn) {332 if (!*fn) {
332 const char *fn_name = (fn_id == BuiltinFnIdCtz) ? "cttz" : "ctlz";333 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);
334 LLVMTypeRef param_types[] = {335 LLVMTypeRef param_types[] = {
335 int_type->type_ref,336 int_type->type_ref,
336 LLVMInt1Type(),337 LLVMInt1Type(),
...@@ -516,7 +517,7 @@ static LLVMValueRef gen_unreachable(CodeGen *g, AstNode *node) {...@@ -516,7 +517,7 @@ static LLVMValueRef gen_unreachable(CodeGen *g, AstNode *node) {
516static LLVMValueRef gen_shl_with_overflow(CodeGen *g, AstNode *node) {517static LLVMValueRef gen_shl_with_overflow(CodeGen *g, AstNode *node) {
517 assert(node->type == NodeTypeFnCallExpr);518 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;
520 assert(fn_call_param_count == 4);521 assert(fn_call_param_count == 4);
521522
522 TypeTableEntry *int_type = get_type_for_type_node(node->data.fn_call_expr.params.at(0));523 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) {...@@ -561,7 +562,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {
561 case BuiltinFnIdCtz:562 case BuiltinFnIdCtz:
562 case BuiltinFnIdClz:563 case BuiltinFnIdClz:
563 {564 {
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;
565 assert(fn_call_param_count == 2);566 assert(fn_call_param_count == 2);
566 TypeTableEntry *int_type = get_type_for_type_node(node->data.fn_call_expr.params.at(0));567 TypeTableEntry *int_type = get_type_for_type_node(node->data.fn_call_expr.params.at(0));
567 assert(int_type->id == TypeTableEntryIdInt);568 assert(int_type->id == TypeTableEntryIdInt);
...@@ -578,7 +579,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {...@@ -578,7 +579,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {
578 case BuiltinFnIdSubWithOverflow:579 case BuiltinFnIdSubWithOverflow:
579 case BuiltinFnIdMulWithOverflow:580 case BuiltinFnIdMulWithOverflow:
580 {581 {
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;
582 assert(fn_call_param_count == 4);583 assert(fn_call_param_count == 4);
583584
584 TypeTableEntry *int_type = get_type_for_type_node(node->data.fn_call_expr.params.at(0));585 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) {...@@ -615,7 +616,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {
615 return gen_shl_with_overflow(g, node);616 return gen_shl_with_overflow(g, node);
616 case BuiltinFnIdMemcpy:617 case BuiltinFnIdMemcpy:
617 {618 {
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;
619 assert(fn_call_param_count == 3);620 assert(fn_call_param_count == 3);
620621
621 AstNode *dest_node = node->data.fn_call_expr.params.at(0);622 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) {...@@ -646,7 +647,7 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {
646 }647 }
647 case BuiltinFnIdMemset:648 case BuiltinFnIdMemset:
648 {649 {
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;
650 assert(fn_call_param_count == 3);651 assert(fn_call_param_count == 3);
651652
652 AstNode *dest_node = node->data.fn_call_expr.params.at(0);653 AstNode *dest_node = node->data.fn_call_expr.params.at(0);
...@@ -949,14 +950,14 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {...@@ -949,14 +950,14 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
949950
950 set_debug_source_node(g, node);951 set_debug_source_node(g, node);
951952
952 int ptr_index = wanted_type->data.structure.fields[0].gen_index;953 size_t ptr_index = wanted_type->data.structure.fields[0].gen_index;
953 if (ptr_index >= 0) {954 if (ptr_index != SIZE_MAX) {
954 LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, ptr_index, "");955 LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, ptr_index, "");
955 LLVMValueRef expr_bitcast = LLVMBuildBitCast(g->builder, expr_val, pointer_type->type_ref, "");956 LLVMValueRef expr_bitcast = LLVMBuildBitCast(g->builder, expr_val, pointer_type->type_ref, "");
956 LLVMBuildStore(g->builder, expr_bitcast, ptr_ptr);957 LLVMBuildStore(g->builder, expr_bitcast, ptr_ptr);
957 }958 }
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;
960 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, len_index, "");961 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, len_index, "");
961 LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,962 LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
962 actual_type->data.array.len, false);963 actual_type->data.array.len, false);
...@@ -979,10 +980,10 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {...@@ -979,10 +980,10 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
979980
980 set_debug_source_node(g, node);981 set_debug_source_node(g, node);
981982
982 int actual_ptr_index = actual_type->data.structure.fields[0].gen_index;983 size_t 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 size_t 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 size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
985 int wanted_len_index = wanted_type->data.structure.fields[1].gen_index;986 size_t wanted_len_index = wanted_type->data.structure.fields[1].gen_index;
986987
987 LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, expr_val, actual_ptr_index, "");988 LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, expr_val, actual_ptr_index, "");
988 LLVMValueRef src_ptr = LLVMBuildLoad(g->builder, src_ptr_ptr, "");989 LLVMValueRef src_ptr = LLVMBuildLoad(g->builder, src_ptr_ptr, "");
...@@ -1040,12 +1041,12 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {...@@ -1040,12 +1041,12 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
10401041
1041 set_debug_source_node(g, node);1042 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;
1044 LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, wanted_ptr_index, "");1045 LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, wanted_ptr_index, "");
1045 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, expr_val, wanted_pointer_type->type_ref, "");1046 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, expr_val, wanted_pointer_type->type_ref, "");
1046 LLVMBuildStore(g->builder, src_ptr_casted, dest_ptr_ptr);1047 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;
1049 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, wanted_len_index, "");1050 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, cast_expr->tmp_ptr, wanted_len_index, "");
1050 LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,1051 LLVMValueRef len_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
1051 actual_type->data.array.len / type_size(g, wanted_child_type), false);1052 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) {...@@ -1125,15 +1126,15 @@ static LLVMValueRef gen_fn_call_expr(CodeGen *g, AstNode *node) {
11251126
1126 bool ret_has_bits = type_has_bits(src_return_type);1127 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;
1129 bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type);1130 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);
1131 bool is_var_args = fn_type->data.fn.fn_type_id.is_var_args;1132 bool is_var_args = fn_type->data.fn.fn_type_id.is_var_args;
11321133
1133 // don't really include void values1134 // don't really include void values
1134 LLVMValueRef *gen_param_values = allocate<LLVMValueRef>(actual_param_count);1135 LLVMValueRef *gen_param_values = allocate<LLVMValueRef>(actual_param_count);
11351136
1136 int gen_param_index = 0;1137 size_t gen_param_index = 0;
1137 if (first_arg_ret) {1138 if (first_arg_ret) {
1138 gen_param_values[gen_param_index] = node->data.fn_call_expr.tmp_ptr;1139 gen_param_values[gen_param_index] = node->data.fn_call_expr.tmp_ptr;
1139 gen_param_index += 1;1140 gen_param_index += 1;
...@@ -1144,8 +1145,8 @@ static LLVMValueRef gen_fn_call_expr(CodeGen *g, AstNode *node) {...@@ -1144,8 +1145,8 @@ static LLVMValueRef gen_fn_call_expr(CodeGen *g, AstNode *node) {
1144 gen_param_index += 1;1145 gen_param_index += 1;
1145 }1146 }
11461147
1147 for (int call_i = 0; call_i < fn_call_param_count; call_i += 1) {1148 for (size_t call_i = 0; call_i < fn_call_param_count; call_i += 1) {
1148 int proto_i = call_i + (struct_type ? 1 : 0);1149 size_t proto_i = call_i + (struct_type ? 1 : 0);
1149 if (generic_proto_node &&1150 if (generic_proto_node &&
1150 generic_proto_node->data.fn_proto.params.at(proto_i)->data.param_decl.is_inline)1151 generic_proto_node->data.fn_proto.params.at(proto_i)->data.param_decl.is_inline)
1151 {1152 {
...@@ -1231,16 +1232,16 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal...@@ -1231,16 +1232,16 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal
12311232
1232 if (want_debug_safety(g, source_node)) {1233 if (want_debug_safety(g, source_node)) {
1233 set_debug_source_node(g, source_node);1234 set_debug_source_node(g, source_node);
1234 int len_index = array_type->data.structure.fields[1].gen_index;1235 size_t len_index = array_type->data.structure.fields[1].gen_index;
1235 assert(len_index >= 0);1236 assert(len_index != SIZE_MAX);
1236 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, len_index, "");1237 LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, len_index, "");
1237 LLVMValueRef len = LLVMBuildLoad(g->builder, len_ptr, "");1238 LLVMValueRef len = LLVMBuildLoad(g->builder, len_ptr, "");
1238 add_bounds_check(g, source_node, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len);1239 add_bounds_check(g, source_node, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len);
1239 }1240 }
12401241
1241 set_debug_source_node(g, source_node);1242 set_debug_source_node(g, source_node);
1242 int ptr_index = array_type->data.structure.fields[0].gen_index;1243 size_t ptr_index = array_type->data.structure.fields[0].gen_index;
1243 assert(ptr_index >= 0);1244 assert(ptr_index != SIZE_MAX);
1244 LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, ptr_index, "");1245 LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, ptr_index, "");
1245 LLVMValueRef ptr = LLVMBuildLoad(g->builder, ptr_ptr, "");1246 LLVMValueRef ptr = LLVMBuildLoad(g->builder, ptr_ptr, "");
1246 return LLVMBuildInBoundsGEP(g->builder, ptr, &subscript_value, 1, "");1247 return LLVMBuildInBoundsGEP(g->builder, ptr, &subscript_value, 1, "");
...@@ -1297,8 +1298,8 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou...@@ -1297,8 +1298,8 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou
1297 assert(LLVMGetTypeKind(LLVMTypeOf(struct_ptr)) == LLVMPointerTypeKind);1298 assert(LLVMGetTypeKind(LLVMTypeOf(struct_ptr)) == LLVMPointerTypeKind);
1298 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(struct_ptr))) == LLVMStructTypeKind);1299 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(struct_ptr))) == LLVMStructTypeKind);
12991300
1300 int gen_field_index = node->data.field_access_expr.type_struct_field->gen_index;1301 size_t gen_field_index = node->data.field_access_expr.type_struct_field->gen_index;
1301 assert(gen_field_index >= 0);1302 assert(gen_field_index != SIZE_MAX);
13021303
1303 set_debug_source_node(g, node);1304 set_debug_source_node(g, node);
1304 return LLVMBuildStructGEP(g->builder, struct_ptr, gen_field_index, "");1305 return LLVMBuildStructGEP(g->builder, struct_ptr, gen_field_index, "");
...@@ -1368,10 +1369,10 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) {...@@ -1368,10 +1369,10 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) {
1368 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);1369 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
1369 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);1370 assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
13701371
1371 int ptr_index = array_type->data.structure.fields[0].gen_index;1372 size_t ptr_index = array_type->data.structure.fields[0].gen_index;
1372 assert(ptr_index >= 0);1373 assert(ptr_index != SIZE_MAX);
1373 int len_index = array_type->data.structure.fields[1].gen_index;1374 size_t len_index = array_type->data.structure.fields[1].gen_index;
1374 assert(len_index >= 0);1375 assert(len_index != SIZE_MAX);
13751376
1376 LLVMValueRef prev_end = nullptr;1377 LLVMValueRef prev_end = nullptr;
1377 if (!node->data.slice_expr.end || want_debug_safety(g, node)) {1378 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...@@ -2395,8 +2396,8 @@ static void gen_defers_for_block(CodeGen *g, BlockContext *inner_block, BlockCon
2395 }2396 }
2396}2397}
23972398
2398static int get_conditional_defer_count(BlockContext *inner_block, BlockContext *outer_block) {2399static size_t get_conditional_defer_count(BlockContext *inner_block, BlockContext *outer_block) {
2399 int result = 0;2400 size_t result = 0;
2400 while (inner_block != outer_block) {2401 while (inner_block != outer_block) {
2401 if (inner_block->node->type == NodeTypeDefer &&2402 if (inner_block->node->type == NodeTypeDefer &&
2402 (inner_block->node->data.defer.kind == ReturnKindError ||2403 (inner_block->node->data.defer.kind == ReturnKindError ||
...@@ -2776,7 +2777,7 @@ static LLVMValueRef gen_block(CodeGen *g, AstNode *block_node, TypeTableEntry *i...@@ -2776,7 +2777,7 @@ static LLVMValueRef gen_block(CodeGen *g, AstNode *block_node, TypeTableEntry *i
2776 assert(block_node->type == NodeTypeBlock);2777 assert(block_node->type == NodeTypeBlock);
27772778
2778 LLVMValueRef return_value = nullptr;2779 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) {
2780 AstNode *statement_node = block_node->data.block.statements.at(i);2781 AstNode *statement_node = block_node->data.block.statements.at(i);
2781 return_value = gen_expr(g, statement_node);2782 return_value = gen_expr(g, statement_node);
2782 }2783 }
...@@ -2796,23 +2797,23 @@ static LLVMValueRef gen_block(CodeGen *g, AstNode *block_node, TypeTableEntry *i...@@ -2796,23 +2797,23 @@ static LLVMValueRef gen_block(CodeGen *g, AstNode *block_node, TypeTableEntry *i
2796 }2797 }
2797}2798}
27982799
2799static int find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok) {2800static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok) {
2800 const char *ptr = buf_ptr(node->data.asm_expr.asm_template) + tok->start + 2;2801 const char *ptr = buf_ptr(node->data.asm_expr.asm_template) + tok->start + 2;
2801 int len = tok->end - tok->start - 2;2802 size_t len = tok->end - tok->start - 2;
2802 int result = 0;2803 size_t result = 0;
2803 for (int i = 0; i < node->data.asm_expr.output_list.length; i += 1, result += 1) {2804 for (size_t i = 0; i < node->data.asm_expr.output_list.length; i += 1, result += 1) {
2804 AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);2805 AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);
2805 if (buf_eql_mem(asm_output->asm_symbolic_name, ptr, len)) {2806 if (buf_eql_mem(asm_output->asm_symbolic_name, ptr, len)) {
2806 return result;2807 return result;
2807 }2808 }
2808 }2809 }
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) {
2810 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);2811 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
2811 if (buf_eql_mem(asm_input->asm_symbolic_name, ptr, len)) {2812 if (buf_eql_mem(asm_input->asm_symbolic_name, ptr, len)) {
2812 return result;2813 return result;
2813 }2814 }
2814 }2815 }
2815 return -1;2816 return SIZE_MAX;
2816}2817}
28172818
2818static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {2819static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
...@@ -2825,11 +2826,11 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {...@@ -2825,11 +2826,11 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
2825 Buf llvm_template = BUF_INIT;2826 Buf llvm_template = BUF_INIT;
2826 buf_resize(&llvm_template, 0);2827 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) {
2829 AsmToken *asm_token = &asm_expr->token_list.at(token_i);2830 AsmToken *asm_token = &asm_expr->token_list.at(token_i);
2830 switch (asm_token->id) {2831 switch (asm_token->id) {
2831 case AsmTokenIdTemplate:2832 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) {
2833 uint8_t c = *((uint8_t*)(buf_ptr(src_template) + offset));2834 uint8_t c = *((uint8_t*)(buf_ptr(src_template) + offset));
2834 if (c == '$') {2835 if (c == '$') {
2835 buf_append_str(&llvm_template, "$$");2836 buf_append_str(&llvm_template, "$$");
...@@ -2842,9 +2843,9 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {...@@ -2842,9 +2843,9 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
2842 buf_append_char(&llvm_template, '%');2843 buf_append_char(&llvm_template, '%');
2843 break;2844 break;
2844 case AsmTokenIdVar:2845 case AsmTokenIdVar:
2845 int index = find_asm_index(g, node, asm_token);2846 size_t index = find_asm_index(g, node, asm_token);
2846 assert(index >= 0);2847 assert(index < SIZE_MAX);
2847 buf_appendf(&llvm_template, "$%d", index);2848 buf_appendf(&llvm_template, "$%zu", index);
2848 break;2849 break;
2849 }2850 }
2850 }2851 }
...@@ -2854,17 +2855,17 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {...@@ -2854,17 +2855,17 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
28542855
2855 assert(asm_expr->return_count == 0 || asm_expr->return_count == 1);2856 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 +
2858 asm_expr->input_list.length +2859 asm_expr->input_list.length +
2859 asm_expr->clobber_list.length;2860 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 +
2861 asm_expr->input_list.length -2862 asm_expr->input_list.length -
2862 asm_expr->return_count;2863 asm_expr->return_count;
2863 int total_index = 0;2864 size_t total_index = 0;
2864 int param_index = 0;2865 size_t param_index = 0;
2865 LLVMTypeRef *param_types = allocate<LLVMTypeRef>(input_and_output_count);2866 LLVMTypeRef *param_types = allocate<LLVMTypeRef>(input_and_output_count);
2866 LLVMValueRef *param_values = allocate<LLVMValueRef>(input_and_output_count);2867 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) {
2868 AsmOutput *asm_output = asm_expr->output_list.at(i);2869 AsmOutput *asm_output = asm_expr->output_list.at(i);
2869 bool is_return = (asm_output->return_type != nullptr);2870 bool is_return = (asm_output->return_type != nullptr);
2870 assert(*buf_ptr(asm_output->constraint) == '=');2871 assert(*buf_ptr(asm_output->constraint) == '=');
...@@ -2885,7 +2886,7 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {...@@ -2885,7 +2886,7 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
2885 param_index += 1;2886 param_index += 1;
2886 }2887 }
2887 }2888 }
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) {
2889 AsmInput *asm_input = asm_expr->input_list.at(i);2890 AsmInput *asm_input = asm_expr->input_list.at(i);
2890 buf_append_buf(&constraint_buf, asm_input->constraint);2891 buf_append_buf(&constraint_buf, asm_input->constraint);
2891 if (total_index + 1 < total_constraint_count) {2892 if (total_index + 1 < total_constraint_count) {
...@@ -2896,7 +2897,7 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {...@@ -2896,7 +2897,7 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
2896 param_types[param_index] = expr_type->type_ref;2897 param_types[param_index] = expr_type->type_ref;
2897 param_values[param_index] = gen_expr(g, asm_input->expr);2898 param_values[param_index] = gen_expr(g, asm_input->expr);
2898 }2899 }
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) {
2900 Buf *clobber_buf = asm_expr->clobber_list.at(i);2901 Buf *clobber_buf = asm_expr->clobber_list.at(i);
2901 buf_appendf(&constraint_buf, "~{%s}", buf_ptr(clobber_buf));2902 buf_appendf(&constraint_buf, "~{%s}", buf_ptr(clobber_buf));
2902 if (total_index + 1 < total_constraint_count) {2903 if (total_index + 1 < total_constraint_count) {
...@@ -2927,7 +2928,7 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {...@@ -2927,7 +2928,7 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
29272928
29282929
2929 if (node->data.container_init_expr.enum_type) {2930 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;
2931 AstNode *arg1_node;2932 AstNode *arg1_node;
2932 if (param_count == 1) {2933 if (param_count == 1) {
2933 arg1_node = node->data.container_init_expr.entries.at(0);2934 arg1_node = node->data.container_init_expr.entries.at(0);
...@@ -2943,13 +2944,13 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {...@@ -2943,13 +2944,13 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
2943 if (type_entry->id == TypeTableEntryIdStruct) {2944 if (type_entry->id == TypeTableEntryIdStruct) {
2944 assert(node->data.container_init_expr.kind == ContainerInitKindStruct);2945 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;
2947 assert(src_field_count == node->data.container_init_expr.entries.length);2948 assert(src_field_count == node->data.container_init_expr.entries.length);
29482949
2949 StructValExprCodeGen *struct_val_expr_node = &node->data.container_init_expr.resolved_struct_val_expr;2950 StructValExprCodeGen *struct_val_expr_node = &node->data.container_init_expr.resolved_struct_val_expr;
2950 LLVMValueRef tmp_struct_ptr = struct_val_expr_node->ptr;2951 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) {
2953 AstNode *field_node = node->data.container_init_expr.entries.at(i);2954 AstNode *field_node = node->data.container_init_expr.entries.at(i);
2954 assert(field_node->type == NodeTypeStructValueField);2955 assert(field_node->type == NodeTypeStructValueField);
2955 TypeStructField *type_struct_field = field_node->data.struct_val_field.type_struct_field;2956 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) {...@@ -2974,12 +2975,12 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
2974 StructValExprCodeGen *struct_val_expr_node = &node->data.container_init_expr.resolved_struct_val_expr;2975 StructValExprCodeGen *struct_val_expr_node = &node->data.container_init_expr.resolved_struct_val_expr;
2975 LLVMValueRef tmp_array_ptr = struct_val_expr_node->ptr;2976 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;
2978 assert(field_count == node->data.container_init_expr.entries.length);2979 assert(field_count == node->data.container_init_expr.entries.length);
29792980
2980 TypeTableEntry *child_type = type_entry->data.array.child_type;2981 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) {
2983 AstNode *field_node = node->data.container_init_expr.entries.at(i);2984 AstNode *field_node = node->data.container_init_expr.entries.at(i);
2984 LLVMValueRef elem_val = gen_expr(g, field_node);2985 LLVMValueRef elem_val = gen_expr(g, field_node);
29852986
...@@ -3126,8 +3127,8 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {...@@ -3126,8 +3127,8 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
3126 TypeTableEntry *child_ptr_type = array_type->data.structure.fields[0].type_entry;3127 TypeTableEntry *child_ptr_type = array_type->data.structure.fields[0].type_entry;
3127 assert(child_ptr_type->id == TypeTableEntryIdPointer);3128 assert(child_ptr_type->id == TypeTableEntryIdPointer);
3128 child_type = child_ptr_type->data.pointer.child_type;3129 child_type = child_ptr_type->data.pointer.child_type;
3129 int len_index = array_type->data.structure.fields[1].gen_index;3130 size_t len_index = array_type->data.structure.fields[1].gen_index;
3130 assert(len_index >= 0);3131 assert(len_index != SIZE_MAX);
3131 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, array_val, len_index, "");3132 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, array_val, len_index, "");
3132 len_val = LLVMBuildLoad(g->builder, len_field_ptr, "");3133 len_val = LLVMBuildLoad(g->builder, len_field_ptr, "");
3133 } else {3134 } else {
...@@ -3249,10 +3250,10 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa...@@ -3249,10 +3250,10 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa
3249 LLVMValueRef ptr_val = LLVMBuildArrayAlloca(g->builder, child_type->type_ref,3250 LLVMValueRef ptr_val = LLVMBuildArrayAlloca(g->builder, child_type->type_ref,
3250 size_val, "");3251 size_val, "");
32513252
3252 int ptr_index = var_type->data.structure.fields[0].gen_index;3253 size_t ptr_index = var_type->data.structure.fields[0].gen_index;
3253 assert(ptr_index >= 0);3254 assert(ptr_index != SIZE_MAX);
3254 int len_index = var_type->data.structure.fields[1].gen_index;3255 size_t len_index = var_type->data.structure.fields[1].gen_index;
3255 assert(len_index >= 0);3256 assert(len_index != SIZE_MAX);
32563257
3257 // store the freshly allocated pointer in the unknown size array struct3258 // store the freshly allocated pointer in the unknown size array struct
3258 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder,3259 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder,
...@@ -3328,7 +3329,7 @@ static LLVMValueRef gen_symbol(CodeGen *g, AstNode *node) {...@@ -3328,7 +3329,7 @@ static LLVMValueRef gen_symbol(CodeGen *g, AstNode *node) {
3328static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {3329static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
3329 assert(node->type == NodeTypeSwitchExpr);3330 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) {
3332 AstNode *prong_node = node->data.switch_expr.prongs.at(node->data.switch_expr.const_chosen_prong_index);3333 AstNode *prong_node = node->data.switch_expr.prongs.at(node->data.switch_expr.const_chosen_prong_index);
3333 assert(prong_node->type == NodeTypeSwitchProng);3334 assert(prong_node->type == NodeTypeSwitchProng);
3334 AstNode *prong_expr = prong_node->data.switch_prong.expr;3335 AstNode *prong_expr = prong_node->data.switch_prong.expr;
...@@ -3362,7 +3363,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {...@@ -3362,7 +3363,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
3362 LLVMBasicBlockRef end_block = end_unreachable ?3363 LLVMBasicBlockRef end_block = end_unreachable ?
3363 nullptr : LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchEnd");3364 nullptr : LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchEnd");
3364 LLVMBasicBlockRef else_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchElse");3365 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
3367 set_debug_source_node(g, node);3368 set_debug_source_node(g, node);
3368 LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, target_value, else_block, prong_count);3369 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) {...@@ -3371,7 +3372,7 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
3371 ZigList<LLVMBasicBlockRef> incoming_blocks = {0};3372 ZigList<LLVMBasicBlockRef> incoming_blocks = {0};
33723373
3373 AstNode *else_prong = nullptr;3374 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) {
3375 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);3376 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);
3376 VariableTableEntry *prong_var = prong_node->data.switch_prong.var;3377 VariableTableEntry *prong_var = prong_node->data.switch_prong.var;
33773378
...@@ -3382,10 +3383,10 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {...@@ -3382,10 +3383,10 @@ static LLVMValueRef gen_switch_expr(CodeGen *g, AstNode *node) {
3382 prong_block = else_block;3383 prong_block = else_block;
3383 } else {3384 } else {
3384 prong_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "SwitchProng");3385 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;
3386 bool make_item_blocks = prong_var && prong_item_count > 1;3387 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) {
3389 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);3390 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
33903391
3391 assert(item_node->type != NodeTypeSwitchRange);3392 assert(item_node->type != NodeTypeSwitchRange);
...@@ -3699,7 +3700,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE...@@ -3699,7 +3700,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
3699 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);3700 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
3700 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {3701 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
3701 TypeStructField *type_struct_field = &type_entry->data.structure.fields[i];3702 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) {
3703 continue;3704 continue;
3704 }3705 }
3705 fields[type_struct_field->gen_index] = gen_const_val(g, type_struct_field->type_entry,3706 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...@@ -3767,13 +3768,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
3767 case TypeTableEntryIdPointer:3768 case TypeTableEntryIdPointer:
3768 {3769 {
3769 TypeTableEntry *child_type = type_entry->data.pointer.child_type;3770 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;
3771 LLVMValueRef target_val;3772 LLVMValueRef target_val;
3772 if (len == 1) {3773 if (len == 1) {
3773 target_val = gen_const_val(g, child_type, const_val->data.x_ptr.ptr[0]);3774 target_val = gen_const_val(g, child_type, const_val->data.x_ptr.ptr[0]);
3774 } else if (len > 1) {3775 } else if (len > 1) {
3775 LLVMValueRef *values = allocate<LLVMValueRef>(len);3776 LLVMValueRef *values = allocate<LLVMValueRef>(len);
3776 for (int i = 0; i < len; i += 1) {3777 for (size_t i = 0; i < len; i += 1) {
3777 values[i] = gen_const_val(g, child_type, const_val->data.x_ptr.ptr[i]);3778 values[i] = gen_const_val(g, child_type, const_val->data.x_ptr.ptr[i]);
3778 }3779 }
3779 target_val = LLVMConstArray(child_type->type_ref, values, len);3780 target_val = LLVMConstArray(child_type->type_ref, values, len);
...@@ -3833,7 +3834,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE...@@ -3833,7 +3834,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
3833}3834}
38343835
3835static void gen_const_globals(CodeGen *g) {3836static 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) {
3837 AstNode *expr_node = g->global_const_list.at(i);3838 AstNode *expr_node = g->global_const_list.at(i);
3838 Expr *expr = get_resolved_expr(expr_node);3839 Expr *expr = get_resolved_expr(expr_node);
3839 ConstExprValue *const_val = &expr->const_val;3840 ConstExprValue *const_val = &expr->const_val;
...@@ -3927,7 +3928,7 @@ static void generate_error_name_table(CodeGen *g) {...@@ -3927,7 +3928,7 @@ static void generate_error_name_table(CodeGen *g) {
39273928
3928 LLVMValueRef *values = allocate<LLVMValueRef>(g->error_decls.length);3929 LLVMValueRef *values = allocate<LLVMValueRef>(g->error_decls.length);
3929 values[0] = LLVMGetUndef(str_type->type_ref);3930 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) {
3931 AstNode *error_decl_node = g->error_decls.at(i);3932 AstNode *error_decl_node = g->error_decls.at(i);
3932 assert(error_decl_node->type == NodeTypeErrorValueDecl);3933 assert(error_decl_node->type == NodeTypeErrorValueDecl);
3933 Buf *name = error_decl_node->data.error_value_decl.name;3934 Buf *name = error_decl_node->data.error_value_decl.name;
...@@ -3957,7 +3958,7 @@ static void generate_error_name_table(CodeGen *g) {...@@ -3957,7 +3958,7 @@ static void generate_error_name_table(CodeGen *g) {
39573958
3958static void build_label_blocks(CodeGen *g, FnTableEntry *fn) {3959static void build_label_blocks(CodeGen *g, FnTableEntry *fn) {
3959 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn->fn_value, "entry");3960 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) {
3961 LabelTableEntry *label = fn->all_labels.at(i);3962 LabelTableEntry *label = fn->all_labels.at(i);
3962 Buf *name = label->decl_node->data.label.name;3963 Buf *name = label->decl_node->data.label.name;
3963 label->basic_block = LLVMAppendBasicBlock(fn->fn_value, buf_ptr(name));3964 label->basic_block = LLVMAppendBasicBlock(fn->fn_value, buf_ptr(name));
...@@ -3988,7 +3989,7 @@ static void do_code_gen(CodeGen *g) {...@@ -3988,7 +3989,7 @@ static void do_code_gen(CodeGen *g) {
3988 generate_error_name_table(g);3989 generate_error_name_table(g);
39893990
3990 // Generate module level variables3991 // 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) {
3992 VariableTableEntry *var = g->global_vars.at(i);3993 VariableTableEntry *var = g->global_vars.at(i);
39933994
3994 if (var->type->id == TypeTableEntryIdNumLitFloat) {3995 if (var->type->id == TypeTableEntryIdNumLitFloat) {
...@@ -4063,7 +4064,7 @@ static void do_code_gen(CodeGen *g) {...@@ -4063,7 +4064,7 @@ static void do_code_gen(CodeGen *g) {
4063 }4064 }
40644065
4065 // Generate function prototypes4066 // 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) {
4067 FnTableEntry *fn_table_entry = g->fn_protos.at(fn_proto_i);4068 FnTableEntry *fn_table_entry = g->fn_protos.at(fn_proto_i);
4068 if (should_skip_fn_codegen(g, fn_table_entry)) {4069 if (should_skip_fn_codegen(g, fn_table_entry)) {
4069 // huge time saver4070 // huge time saver
...@@ -4097,15 +4098,15 @@ static void do_code_gen(CodeGen *g) {...@@ -4097,15 +4098,15 @@ static void do_code_gen(CodeGen *g) {
40974098
40984099
4099 // set parameter attributes4100 // 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) {
4101 AstNode *param_node = fn_proto->params.at(param_decl_i);4102 AstNode *param_node = fn_proto->params.at(param_decl_i);
4102 assert(param_node->type == NodeTypeParamDecl);4103 assert(param_node->type == NodeTypeParamDecl);
41034104
4104 FnGenParamInfo *info = &fn_type->data.fn.gen_param_info[param_decl_i];4105 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;
4106 bool is_byval = info->is_byval;4107 bool is_byval = info->is_byval;
41074108
4108 if (gen_index < 0) {4109 if (gen_index == SIZE_MAX) {
4109 continue;4110 continue;
4110 }4111 }
41114112
...@@ -4169,7 +4170,7 @@ static void do_code_gen(CodeGen *g) {...@@ -4169,7 +4170,7 @@ static void do_code_gen(CodeGen *g) {
4169 }4170 }
41704171
4171 // Generate function definitions.4172 // 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) {
4173 FnTableEntry *fn_table_entry = g->fn_defs.at(fn_i);4174 FnTableEntry *fn_table_entry = g->fn_defs.at(fn_i);
4174 if (should_skip_fn_codegen(g, fn_table_entry)) {4175 if (should_skip_fn_codegen(g, fn_table_entry)) {
4175 // huge time saver4176 // huge time saver
...@@ -4194,7 +4195,7 @@ static void do_code_gen(CodeGen *g) {...@@ -4194,7 +4195,7 @@ static void do_code_gen(CodeGen *g) {
41944195
41954196
4196 // Set up debug info for blocks4197 // 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) {
4198 BlockContext *block_context = fn_table_entry->all_block_contexts.at(bc_i);4199 BlockContext *block_context = fn_table_entry->all_block_contexts.at(bc_i);
41994200
4200 if (!block_context->di_scope) {4201 if (!block_context->di_scope) {
...@@ -4212,7 +4213,7 @@ static void do_code_gen(CodeGen *g) {...@@ -4212,7 +4213,7 @@ static void do_code_gen(CodeGen *g) {
4212 clear_debug_source_node(g);4213 clear_debug_source_node(g);
42134214
4214 // allocate structs which are the result of casts4215 // 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) {
4216 AstNode *fn_call_node = fn_table_entry->cast_alloca_list.at(cea_i);4217 AstNode *fn_call_node = fn_table_entry->cast_alloca_list.at(cea_i);
4217 Expr *expr = &fn_call_node->data.fn_call_expr.resolved_expr;4218 Expr *expr = &fn_call_node->data.fn_call_expr.resolved_expr;
4218 fn_call_node->data.fn_call_expr.tmp_ptr = LLVMBuildAlloca(g->builder,4219 fn_call_node->data.fn_call_expr.tmp_ptr = LLVMBuildAlloca(g->builder,
...@@ -4220,14 +4221,14 @@ static void do_code_gen(CodeGen *g) {...@@ -4220,14 +4221,14 @@ static void do_code_gen(CodeGen *g) {
4220 }4221 }
42214222
4222 // allocate structs which are struct value expressions4223 // 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) {
4224 StructValExprCodeGen *struct_val_expr_node = fn_table_entry->struct_val_expr_alloca_list.at(alloca_i);4225 StructValExprCodeGen *struct_val_expr_node = fn_table_entry->struct_val_expr_alloca_list.at(alloca_i);
4225 struct_val_expr_node->ptr = LLVMBuildAlloca(g->builder,4226 struct_val_expr_node->ptr = LLVMBuildAlloca(g->builder,
4226 struct_val_expr_node->type_entry->type_ref, "");4227 struct_val_expr_node->type_entry->type_ref, "");
4227 }4228 }
42284229
4229 // create debug variable declarations for variables and allocate all local variables4230 // 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) {
4231 VariableTableEntry *var = fn_table_entry->variable_list.at(var_i);4232 VariableTableEntry *var = fn_table_entry->variable_list.at(var_i);
42324233
4233 if (!type_has_bits(var->type)) {4234 if (!type_has_bits(var->type)) {
...@@ -4235,7 +4236,7 @@ static void do_code_gen(CodeGen *g) {...@@ -4235,7 +4236,7 @@ static void do_code_gen(CodeGen *g) {
4235 }4236 }
42364237
4237 if (var->block_context->node->type == NodeTypeFnDef) {4238 if (var->block_context->node->type == NodeTypeFnDef) {
4238 assert(var->gen_arg_index >= 0);4239 assert(var->gen_arg_index != SIZE_MAX);
4239 TypeTableEntry *gen_type;4240 TypeTableEntry *gen_type;
4240 if (handle_is_ptr(var->type)) {4241 if (handle_is_ptr(var->type)) {
4241 gen_type = fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index].type;4242 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) {...@@ -4264,13 +4265,13 @@ static void do_code_gen(CodeGen *g) {
4264 }4265 }
42654266
4266 // create debug variable declarations for parameters4267 // 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) {
4268 AstNode *param_decl = fn_proto->params.at(param_i);4269 AstNode *param_decl = fn_proto->params.at(param_i);
4269 assert(param_decl->type == NodeTypeParamDecl);4270 assert(param_decl->type == NodeTypeParamDecl);
42704271
4271 FnGenParamInfo *info = &fn_table_entry->type_entry->data.fn.gen_param_info[param_i];4272 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) {
4274 continue;4275 continue;
4275 }4276 }
42764277
...@@ -4306,7 +4307,7 @@ static void do_code_gen(CodeGen *g) {...@@ -4306,7 +4307,7 @@ static void do_code_gen(CodeGen *g) {
4306#endif4307#endif
4307}4308}
43084309
4309static const int int_sizes_in_bits[] = {4310static const size_t int_sizes_in_bits[] = {
4310 8,4311 8,
4311 16,4312 16,
4312 32,4313 32,
...@@ -4380,9 +4381,9 @@ static void define_builtin_types(CodeGen *g) {...@@ -4380,9 +4381,9 @@ static void define_builtin_types(CodeGen *g) {
4380 g->builtin_types.entry_var = entry;4381 g->builtin_types.entry_var = entry;
4381 }4382 }
43824383
4383 for (int int_size_i = 0; int_size_i < array_length(int_sizes_in_bits); int_size_i += 1) {4384 for (size_t 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 size_t 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) {4386 for (size_t is_sign_i = 0; is_sign_i < array_length(is_signed_list); is_sign_i += 1) {
4386 bool is_signed = is_signed_list[is_sign_i];4387 bool is_signed = is_signed_list[is_sign_i];
43874388
4388 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);4389 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
...@@ -4391,7 +4392,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -4391,7 +4392,7 @@ static void define_builtin_types(CodeGen *g) {
43914392
4392 const char u_or_i = is_signed ? 'i' : 'u';4393 const char u_or_i = is_signed ? 'i' : 'u';
4393 buf_resize(&entry->name, 0);4394 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
4396 unsigned dwarf_tag;4397 unsigned dwarf_tag;
4397 if (is_signed) {4398 if (is_signed) {
...@@ -4420,7 +4421,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -4420,7 +4421,7 @@ static void define_builtin_types(CodeGen *g) {
4420 }4421 }
4421 }4422 }
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) {
4424 const CIntTypeInfo *info = &c_int_type_infos[i];4425 const CIntTypeInfo *info = &c_int_type_infos[i];
4425 uint64_t size_in_bits = get_c_type_size_in_bits(&g->zig_target, info->id);4426 uint64_t size_in_bits = get_c_type_size_in_bits(&g->zig_target, info->id);
4426 bool is_signed = info->is_signed;4427 bool is_signed = info->is_signed;
...@@ -4459,7 +4460,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -4459,7 +4460,7 @@ static void define_builtin_types(CodeGen *g) {
4459 g->primitive_type_table.put(&entry->name, entry);4460 g->primitive_type_table.put(&entry->name, entry);
4460 }4461 }
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) {
4463 bool is_signed = is_signed_list[sign_i];4464 bool is_signed = is_signed_list[sign_i];
44644465
4465 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);4466 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
...@@ -4754,7 +4755,7 @@ static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char...@@ -4754,7 +4755,7 @@ static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char
4754 return builtin_fn;4755 return builtin_fn;
4755}4756}
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) {
4758 BuiltinFnEntry *builtin_fn = create_builtin_fn(g, id, name);4759 BuiltinFnEntry *builtin_fn = create_builtin_fn(g, id, name);
4759 builtin_fn->param_count = count;4760 builtin_fn->param_count = count;
4760 builtin_fn->param_types = allocate<TypeTableEntry *>(count);4761 builtin_fn->param_types = allocate<TypeTableEntry *>(count);
...@@ -4958,7 +4959,7 @@ void codegen_parseh(CodeGen *g, Buf *src_dirname, Buf *src_basename, Buf *source...@@ -4958,7 +4959,7 @@ void codegen_parseh(CodeGen *g, Buf *src_dirname, Buf *src_basename, Buf *source
4958 }4959 }
49594960
4960 if (errors.length > 0) {4961 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) {
4962 ErrorMsg *err_msg = errors.at(i);4963 ErrorMsg *err_msg = errors.at(i);
4963 print_err_msg(err_msg, g->err_color);4964 print_err_msg(err_msg, g->err_color);
4964 }4965 }
...@@ -5034,7 +5035,7 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou...@@ -5034,7 +5035,7 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou
5034 fprintf(stderr, "OK\n");5035 fprintf(stderr, "OK\n");
5035 }5036 }
5036 } else {5037 } else {
5037 for (int i = 0; i < g->errors.length; i += 1) {5038 for (size_t i = 0; i < g->errors.length; i += 1) {
5038 ErrorMsg *err = g->errors.at(i);5039 ErrorMsg *err = g->errors.at(i);
5039 print_err_msg(err, g->err_color);5040 print_err_msg(err, g->err_color);
5040 }5041 }
...@@ -5063,7 +5064,7 @@ static const char *c_int_type_names[] = {...@@ -5063,7 +5064,7 @@ static const char *c_int_type_names[] = {
5063static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {5064static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
5064 assert(type_entry);5065 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) {
5067 if (type_entry == g->builtin_types.entry_c_int[i]) {5068 if (type_entry == g->builtin_types.entry_c_int[i]) {
5068 buf_init_from_str(out_buf, c_int_type_names[i]);5069 buf_init_from_str(out_buf, c_int_type_names[i]);
5069 return;5070 return;
...@@ -5114,7 +5115,7 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {...@@ -5114,7 +5115,7 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
5114 case TypeTableEntryIdInt:5115 case TypeTableEntryIdInt:
5115 g->c_want_stdint = true;5116 g->c_want_stdint = true;
5116 buf_resize(out_buf, 0);5117 buf_resize(out_buf, 0);
5117 buf_appendf(out_buf, "%sint%d_t",5118 buf_appendf(out_buf, "%sint%zu_t",
5118 type_entry->data.integral.is_signed ? "" : "u",5119 type_entry->data.integral.is_signed ? "" : "u",
5119 type_entry->data.integral.bit_count);5120 type_entry->data.integral.bit_count);
5120 break;5121 break;
...@@ -5183,7 +5184,7 @@ void codegen_generate_h_file(CodeGen *g) {...@@ -5183,7 +5184,7 @@ void codegen_generate_h_file(CodeGen *g) {
51835184
5184 Buf h_buf = BUF_INIT;5185 Buf h_buf = BUF_INIT;
5185 buf_resize(&h_buf, 0);5186 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) {
5187 FnTableEntry *fn_table_entry = g->fn_defs.at(fn_def_i);5188 FnTableEntry *fn_table_entry = g->fn_defs.at(fn_def_i);
5188 AstNode *proto_node = fn_table_entry->proto_node;5189 AstNode *proto_node = fn_table_entry->proto_node;
5189 assert(proto_node->type == NodeTypeFnProto);5190 assert(proto_node->type == NodeTypeFnProto);
...@@ -5202,7 +5203,7 @@ void codegen_generate_h_file(CodeGen *g) {...@@ -5202,7 +5203,7 @@ void codegen_generate_h_file(CodeGen *g) {
52025203
5203 Buf param_type_c = BUF_INIT;5204 Buf param_type_c = BUF_INIT;
5204 if (fn_proto->params.length) {5205 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) {
5206 AstNode *param_decl_node = fn_proto->params.at(param_i);5207 AstNode *param_decl_node = fn_proto->params.at(param_i);
5207 AstNode *param_type = param_decl_node->data.param_decl.type;5208 AstNode *param_type = param_decl_node->data.param_decl.type;
5208 get_c_type_node(g, param_type, &param_type_c);5209 get_c_type_node(g, param_type, &param_type_c);
src/codegen.hpp+1-1
...@@ -16,7 +16,7 @@...@@ -16,7 +16,7 @@
1616
17CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target);17CodeGen *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);
20void codegen_set_is_release(CodeGen *codegen, bool is_release);20void codegen_set_is_release(CodeGen *codegen, bool is_release);
21void codegen_set_is_test(CodeGen *codegen, bool is_test);21void codegen_set_is_test(CodeGen *codegen, bool is_test);
22void codegen_set_check_unused(CodeGen *codegen, bool check_unused);22void codegen_set_check_unused(CodeGen *codegen, bool check_unused);
src/errmsg.cpp+17-20
...@@ -16,36 +16,36 @@ enum ErrType {...@@ -16,36 +16,36 @@ enum ErrType {
1616
17static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) {17static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) {
18 const char *path = buf_ptr(err->path);18 const char *path = buf_ptr(err->path);
19 int line = err->line_start + 1;19 size_t line = err->line_start + 1;
20 int col = err->column_start + 1;20 size_t col = err->column_start + 1;
21 const char *text = buf_ptr(err->msg);21 const char *text = buf_ptr(err->msg);
2222
2323
24 if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) {24 if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) {
25 if (err_type == ErrTypeError) {25 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);
27 } else if (err_type == ErrTypeNote) {27 } 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);
29 } else {29 } else {
30 zig_unreachable();30 zig_unreachable();
31 }31 }
3232
33 fprintf(stderr, "%s\n", buf_ptr(&err->line_buf));33 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) {
35 fprintf(stderr, " ");35 fprintf(stderr, " ");
36 }36 }
37 fprintf(stderr, GREEN "^" RESET "\n");37 fprintf(stderr, GREEN "^" RESET "\n");
38 } else {38 } else {
39 if (err_type == ErrTypeError) {39 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);
41 } else if (err_type == ErrTypeNote) {41 } 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);
43 } else {43 } else {
44 zig_unreachable();44 zig_unreachable();
45 }45 }
46 }46 }
4747
48 for (int i = 0; i < err->notes.length; i += 1) {48 for (size_t i = 0; i < err->notes.length; i += 1) {
49 ErrorMsg *note = err->notes.at(i);49 ErrorMsg *note = err->notes.at(i);
50 print_err_msg_type(note, color, ErrTypeNote);50 print_err_msg_type(note, color, ErrTypeNote);
51 }51 }
...@@ -59,7 +59,7 @@ void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note) {...@@ -59,7 +59,7 @@ void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note) {
59 parent->notes.append(note);59 parent->notes.append(note);
60}60}
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,
63 const char *source, Buf *msg)63 const char *source, Buf *msg)
64{64{
65 ErrorMsg *err_msg = allocate<ErrorMsg>(1);65 ErrorMsg *err_msg = allocate<ErrorMsg>(1);
...@@ -68,7 +68,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset...@@ -68,7 +68,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset
68 err_msg->column_start = column;68 err_msg->column_start = column;
69 err_msg->msg = msg;69 err_msg->msg = msg;
7070
71 int line_start_offset = offset;71 size_t line_start_offset = offset;
72 for (;;) {72 for (;;) {
73 if (line_start_offset == 0) {73 if (line_start_offset == 0) {
74 break;74 break;
...@@ -79,7 +79,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset...@@ -79,7 +79,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset
79 line_start_offset -= 1;79 line_start_offset -= 1;
80 }80 }
8181
82 int line_end_offset = offset;82 size_t line_end_offset = offset;
83 while (source[line_end_offset] && source[line_end_offset] != '\n') {83 while (source[line_end_offset] && source[line_end_offset] != '\n') {
84 line_end_offset += 1;84 line_end_offset += 1;
85 }85 }
...@@ -89,8 +89,8 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset...@@ -89,8 +89,8 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, int line, int column, int offset
89 return err_msg;89 return err_msg;
90}90}
9191
92ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column,92ErrorMsg *err_msg_create_with_line(Buf *path, size_t line, size_t column,
93 Buf *source, ZigList<int> *line_offsets, Buf *msg)93 Buf *source, ZigList<size_t> *line_offsets, Buf *msg)
94{94{
95 ErrorMsg *err_msg = allocate<ErrorMsg>(1);95 ErrorMsg *err_msg = allocate<ErrorMsg>(1);
96 err_msg->path = path;96 err_msg->path = path;
...@@ -98,13 +98,10 @@ ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column,...@@ -98,13 +98,10 @@ ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column,
98 err_msg->column_start = column;98 err_msg->column_start = column;
99 err_msg->msg = msg;99 err_msg->msg = msg;
100100
101 int line_start_offset = line_offsets->at(line);101 size_t line_start_offset = line_offsets->at(line);
102 int end_line = line + 1;102 size_t end_line = line + 1;
103 int line_end_offset = (end_line >= line_offsets->length) ? buf_len(source) : line_offsets->at(line + 1);103 size_t 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;104 size_t len = (line_end_offset + 1 > line_start_offset) ? (line_end_offset - line_start_offset - 1) : 0;
105 if (len < 0) {
106 len = 0;
107 }
108105
109 buf_init_from_mem(&err_msg->line_buf, buf_ptr(source) + line_start_offset, len);106 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 {...@@ -18,8 +18,8 @@ enum ErrColor {
18};18};
1919
20struct ErrorMsg {20struct ErrorMsg {
21 int line_start;21 size_t line_start;
22 int column_start;22 size_t column_start;
23 Buf *msg;23 Buf *msg;
24 Buf *path;24 Buf *path;
25 Buf line_buf;25 Buf line_buf;
...@@ -30,10 +30,10 @@ struct ErrorMsg {...@@ -30,10 +30,10 @@ struct ErrorMsg {
30void print_err_msg(ErrorMsg *msg, ErrColor color);30void print_err_msg(ErrorMsg *msg, ErrColor color);
3131
32void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note);32void 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,
34 const char *source, Buf *msg);34 const char *source, Buf *msg);
3535
36ErrorMsg *err_msg_create_with_line(Buf *path, int line, int column,36ErrorMsg *err_msg_create_with_line(Buf *path, size_t line, size_t column,
37 Buf *source, ZigList<int> *line_offsets, Buf *msg);37 Buf *source, ZigList<size_t> *line_offsets, Buf *msg);
3838
39#endif39#endif
src/eval.cpp+21-21
...@@ -75,7 +75,7 @@ static bool eval_block(EvalFn *ef, AstNode *node, ConstExprValue *out) {...@@ -75,7 +75,7 @@ static bool eval_block(EvalFn *ef, AstNode *node, ConstExprValue *out) {
75 my_scope->block_context = node->block_context;75 my_scope->block_context = node->block_context;
76 ef->scope_stack.append(my_scope);76 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) {
79 AstNode *child = node->data.block.statements.at(i);79 AstNode *child = node->data.block.statements.at(i);
80 memset(out, 0, sizeof(ConstExprValue));80 memset(out, 0, sizeof(ConstExprValue));
81 if (eval_expr(ef, child, out)) return true;81 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)...@@ -413,10 +413,10 @@ static bool eval_bin_op_expr(EvalFn *ef, AstNode *node, ConstExprValue *out_val)
413}413}
414414
415static EvalVar *find_var(EvalFn *ef, Buf *name) {415static EvalVar *find_var(EvalFn *ef, Buf *name) {
416 int scope_index = ef->scope_stack.length - 1;416 size_t scope_index = ef->scope_stack.length - 1;
417 while (scope_index >= 0) {417 while (scope_index != SIZE_MAX) {
418 EvalScope *scope = ef->scope_stack.at(scope_index);418 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) {
420 EvalVar *var = &scope->vars.at(var_i);420 EvalVar *var = &scope->vars.at(var_i);
421 if (buf_eql_buf(var->name, name)) {421 if (buf_eql_buf(var->name, name)) {
422 return var;422 return var;
...@@ -466,18 +466,18 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue *...@@ -466,18 +466,18 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue *
466 !container_type->data.structure.is_slice &&466 !container_type->data.structure.is_slice &&
467 kind == ContainerInitKindStruct)467 kind == ContainerInitKindStruct)
468 {468 {
469 int expr_field_count = container_init_expr->entries.length;469 size_t expr_field_count = container_init_expr->entries.length;
470 int actual_field_count = container_type->data.structure.src_field_count;470 size_t actual_field_count = container_type->data.structure.src_field_count;
471 assert(expr_field_count == actual_field_count);471 assert(expr_field_count == actual_field_count);
472472
473 out_val->data.x_struct.fields = allocate<ConstExprValue*>(actual_field_count);473 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) {
476 AstNode *val_field_node = container_init_expr->entries.at(i);476 AstNode *val_field_node = container_init_expr->entries.at(i);
477 assert(val_field_node->type == NodeTypeStructValueField);477 assert(val_field_node->type == NodeTypeStructValueField);
478478
479 TypeStructField *type_field = val_field_node->data.struct_val_field.type_struct_field;479 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
482 ConstExprValue src_field_val = {0};482 ConstExprValue src_field_val = {0};
483 if (eval_expr(ef, val_field_node->data.struct_val_field.expr, &src_field_val)) return true;483 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 *...@@ -496,12 +496,12 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue *
496 kind == ContainerInitKindArray)496 kind == ContainerInitKindArray)
497 {497 {
498498
499 int elem_count = container_init_expr->entries.length;499 size_t elem_count = container_init_expr->entries.length;
500500
501 out_val->ok = true;501 out_val->ok = true;
502 out_val->data.x_array.fields = allocate<ConstExprValue*>(elem_count);502 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) {
505 AstNode *elem_node = container_init_expr->entries.at(i);505 AstNode *elem_node = container_init_expr->entries.at(i);
506506
507 ConstExprValue *elem_val = allocate<ConstExprValue>(1);507 ConstExprValue *elem_val = allocate<ConstExprValue>(1);
...@@ -698,7 +698,7 @@ void eval_const_expr_implicit_cast(CastOp cast_op,...@@ -698,7 +698,7 @@ void eval_const_expr_implicit_cast(CastOp cast_op,
698static bool int_type_depends_on_compile_var(CodeGen *g, TypeTableEntry *int_type) {698static bool int_type_depends_on_compile_var(CodeGen *g, TypeTableEntry *int_type) {
699 assert(int_type->id == TypeTableEntryIdInt);699 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) {
702 if (int_type == g->builtin_types.entry_c_int[i]) {702 if (int_type == g->builtin_types.entry_c_int[i]) {
703 return true;703 return true;
704 }704 }
...@@ -918,9 +918,9 @@ static bool eval_fn_call_expr(EvalFn *ef, AstNode *node, ConstExprValue *out_val...@@ -918,9 +918,9 @@ static bool eval_fn_call_expr(EvalFn *ef, AstNode *node, ConstExprValue *out_val
918 fn_table_entry = fn_val.data.x_fn;918 fn_table_entry = fn_val.data.x_fn;
919 }919 }
920920
921 int param_count = node->data.fn_call_expr.params.length;921 size_t param_count = node->data.fn_call_expr.params.length;
922 ConstExprValue *args = allocate<ConstExprValue>(param_count);922 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) {
924 AstNode *param_expr_node = node->data.fn_call_expr.params.at(call_i);924 AstNode *param_expr_node = node->data.fn_call_expr.params.at(call_i);
925 ConstExprValue *param_val = &args[call_i];925 ConstExprValue *param_val = &args[call_i];
926 if (eval_expr(ef, param_expr_node, param_val)) return true;926 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...@@ -1340,8 +1340,8 @@ static bool eval_fn_args(EvalFnRoot *efr, FnTableEntry *fn, ConstExprValue *args
1340 root_scope->block_context = fn->fn_def_node->data.fn_def.body->block_context;1340 root_scope->block_context = fn->fn_def_node->data.fn_def.body->block_context;
1341 ef.scope_stack.append(root_scope);1341 ef.scope_stack.append(root_scope);
13421342
1343 int param_count = acting_proto_node->data.fn_proto.params.length;1343 size_t param_count = acting_proto_node->data.fn_proto.params.length;
1344 for (int proto_i = 0; proto_i < param_count; proto_i += 1) {1344 for (size_t proto_i = 0; proto_i < param_count; proto_i += 1) {
1345 AstNode *decl_param_node = acting_proto_node->data.fn_proto.params.at(proto_i);1345 AstNode *decl_param_node = acting_proto_node->data.fn_proto.params.at(proto_i);
1346 assert(decl_param_node->type == NodeTypeParamDecl);1346 assert(decl_param_node->type == NodeTypeParamDecl);
13471347
...@@ -1358,7 +1358,7 @@ static bool eval_fn_args(EvalFnRoot *efr, FnTableEntry *fn, ConstExprValue *args...@@ -1358,7 +1358,7 @@ static bool eval_fn_args(EvalFnRoot *efr, FnTableEntry *fn, ConstExprValue *args
1358}1358}
13591359
1360bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_val,1360bool 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)
1362{1362{
1363 assert(node->type == NodeTypeFnCallExpr);1363 assert(node->type == NodeTypeFnCallExpr);
13641364
...@@ -1375,17 +1375,17 @@ bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_va...@@ -1375,17 +1375,17 @@ bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_va
1375 acting_proto_node = fn->proto_node;1375 acting_proto_node = fn->proto_node;
1376 }1376 }
13771377
1378 int call_param_count = node->data.fn_call_expr.params.length;1378 size_t call_param_count = node->data.fn_call_expr.params.length;
1379 int proto_param_count = acting_proto_node->data.fn_proto.params.length;1379 size_t proto_param_count = acting_proto_node->data.fn_proto.params.length;
1380 ConstExprValue *args = allocate<ConstExprValue>(proto_param_count);1380 ConstExprValue *args = allocate<ConstExprValue>(proto_param_count);
1381 int next_arg_index = 0;1381 size_t next_arg_index = 0;
1382 if (struct_node) {1382 if (struct_node) {
1383 ConstExprValue *struct_val = &get_resolved_expr(struct_node)->const_val;1383 ConstExprValue *struct_val = &get_resolved_expr(struct_node)->const_val;
1384 assert(struct_val->ok);1384 assert(struct_val->ok);
1385 args[next_arg_index] = *struct_val;1385 args[next_arg_index] = *struct_val;
1386 next_arg_index += 1;1386 next_arg_index += 1;
1387 }1387 }
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) {
1389 AstNode *call_param_node = node->data.fn_call_expr.params.at(call_index);1389 AstNode *call_param_node = node->data.fn_call_expr.params.at(call_index);
1390 ConstExprValue *src_const_val = &get_resolved_expr(call_param_node)->const_val;1390 ConstExprValue *src_const_val = &get_resolved_expr(call_param_node)->const_val;
1391 assert(src_const_val->ok);1391 assert(src_const_val->ok);
...@@ -1396,7 +1396,7 @@ bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_va...@@ -1396,7 +1396,7 @@ bool eval_fn(CodeGen *g, AstNode *node, FnTableEntry *fn, ConstExprValue *out_va
13961396
1397 if (efr.exceeded_quota_node) {1397 if (efr.exceeded_quota_node) {
1398 ErrorMsg *msg = add_node_error(g, fn->fn_def_node,1398 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
1401 add_error_note(g, msg, efr.call_node, buf_sprintf("called from here"));1401 add_error_note(g, msg, efr.call_node, buf_sprintf("called from here"));
1402 add_error_note(g, msg, efr.exceeded_quota_node, buf_sprintf("quota exceeded here"));1402 add_error_note(g, msg, efr.exceeded_quota_node, buf_sprintf("quota exceeded here"));
src/eval.hpp+1-1
...@@ -10,7 +10,7 @@...@@ -10,7 +10,7 @@
1010
11#include "all_types.hpp"11#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,
14 AstNode *struct_node);14 AstNode *struct_node);
1515
16bool const_values_equal(ConstExprValue *a, ConstExprValue *b, TypeTableEntry *type_entry);16bool 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) {...@@ -172,9 +172,9 @@ static void construct_linker_job_linux(LinkJob *lj) {
172 lj->args.append("-shared");172 lj->args.append("-shared");
173173
174 buf_resize(&lj->out_file, 0);174 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",
176 buf_ptr(g->root_out_name), g->version_major, g->version_minor, g->version_patch);176 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);
178 }178 }
179179
180 lj->args.append("-o");180 lj->args.append("-o");
...@@ -195,7 +195,7 @@ static void construct_linker_job_linux(LinkJob *lj) {...@@ -195,7 +195,7 @@ static void construct_linker_job_linux(LinkJob *lj) {
195 lj->args.append(get_libc_static_file(g, crtbegino));195 lj->args.append(get_libc_static_file(g, crtbegino));
196 }196 }
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) {
199 const char *lib_dir = g->lib_dirs.at(i);199 const char *lib_dir = g->lib_dirs.at(i);
200 lj->args.append("-L");200 lj->args.append("-L");
201 lj->args.append(lib_dir);201 lj->args.append(lib_dir);
...@@ -239,7 +239,7 @@ static void construct_linker_job_linux(LinkJob *lj) {...@@ -239,7 +239,7 @@ static void construct_linker_job_linux(LinkJob *lj) {
239 lj->args.append(buf_ptr(compiler_rt_o_path));239 lj->args.append(buf_ptr(compiler_rt_o_path));
240 }240 }
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) {
243 Buf *link_lib = g->link_libs.at(i);243 Buf *link_lib = g->link_libs.at(i);
244 Buf *arg;244 Buf *arg;
245 if (buf_starts_with_str(link_lib, "/") || buf_ends_with_str(link_lib, ".a") ||245 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) {...@@ -350,7 +350,7 @@ static void construct_linker_job_mingw(LinkJob *lj) {
350 lj->args.append(get_libc_static_file(g, "crtbegin.o"));350 lj->args.append(get_libc_static_file(g, "crtbegin.o"));
351 }351 }
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) {
354 const char *lib_dir = g->lib_dirs.at(i);354 const char *lib_dir = g->lib_dirs.at(i);
355 lj->args.append("-L");355 lj->args.append("-L");
356 lj->args.append(lib_dir);356 lj->args.append(lib_dir);
...@@ -381,7 +381,7 @@ static void construct_linker_job_mingw(LinkJob *lj) {...@@ -381,7 +381,7 @@ static void construct_linker_job_mingw(LinkJob *lj) {
381 }381 }
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) {
385 Buf *link_lib = g->link_libs.at(i);385 Buf *link_lib = g->link_libs.at(i);
386 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));386 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
387 lj->args.append(buf_ptr(arg));387 lj->args.append(buf_ptr(arg));
...@@ -635,7 +635,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {...@@ -635,7 +635,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {
635 }635 }
636 }636 }
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) {
639 const char *lib_dir = g->lib_dirs.at(i);639 const char *lib_dir = g->lib_dirs.at(i);
640 lj->args.append("-L");640 lj->args.append("-L");
641 lj->args.append(lib_dir);641 lj->args.append(lib_dir);
...@@ -649,7 +649,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {...@@ -649,7 +649,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {
649 lj->args.append(buf_ptr(test_runner_o_path));649 lj->args.append(buf_ptr(test_runner_o_path));
650 }650 }
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) {
653 Buf *link_lib = g->link_libs.at(i);653 Buf *link_lib = g->link_libs.at(i);
654 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));654 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
655 lj->args.append(buf_ptr(arg));655 lj->args.append(buf_ptr(arg));
...@@ -671,7 +671,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {...@@ -671,7 +671,7 @@ static void construct_linker_job_darwin(LinkJob *lj) {
671 zig_panic("TODO");671 zig_panic("TODO");
672 }672 }
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) {
675 lj->args.append("-framework");675 lj->args.append("-framework");
676 lj->args.append(buf_ptr(g->darwin_frameworks.at(i)));676 lj->args.append(buf_ptr(g->darwin_frameworks.at(i)));
677 }677 }
...@@ -829,7 +829,7 @@ void codegen_link(CodeGen *g, const char *out_file) {...@@ -829,7 +829,7 @@ void codegen_link(CodeGen *g, const char *out_file) {
829829
830 if (g->verbose) {830 if (g->verbose) {
831 fprintf(stderr, "%s", buf_ptr(g->linker_path));831 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) {
833 fprintf(stderr, " %s", lj.args.at(i));833 fprintf(stderr, " %s", lj.args.at(i));
834 }834 }
835 fprintf(stderr, "\n");835 fprintf(stderr, "\n");
...@@ -853,7 +853,7 @@ void codegen_link(CodeGen *g, const char *out_file) {...@@ -853,7 +853,7 @@ void codegen_link(CodeGen *g, const char *out_file) {
853 fprintf(stderr, "linker failed\n");853 fprintf(stderr, "linker failed\n");
854 }854 }
855 fprintf(stderr, "%s ", buf_ptr(g->linker_path));855 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) {
857 fprintf(stderr, "%s ", lj.args.at(i));857 fprintf(stderr, "%s ", lj.args.at(i));
858 }858 }
859 fprintf(stderr, "\n%s\n", buf_ptr(&ld_stderr));859 fprintf(stderr, "\n%s\n", buf_ptr(&ld_stderr));
src/list.hpp+20-17
...@@ -23,13 +23,13 @@ struct ZigList {...@@ -23,13 +23,13 @@ struct ZigList {
23 }23 }
24 // remember that the pointer to this item is invalid after you24 // remember that the pointer to this item is invalid after you
25 // modify the length of the list25 // modify the length of the list
26 const T & at(int index) const {26 const T & at(size_t index) const {
27 assert(index >= 0);27 assert(index != SIZE_MAX);
28 assert(index < length);28 assert(index < length);
29 return items[index];29 return items[index];
30 }30 }
31 T & at(int index) {31 T & at(size_t index) {
32 assert(index >= 0);32 assert(index != SIZE_MAX);
33 assert(index < length);33 assert(index < length);
34 return items[index];34 return items[index];
35 }35 }
...@@ -52,8 +52,8 @@ struct ZigList {...@@ -52,8 +52,8 @@ struct ZigList {
52 return items[length - 1];52 return items[length - 1];
53 }53 }
5454
55 void resize(int new_length) {55 void resize(size_t new_length) {
56 assert(new_length >= 0);56 assert(new_length != SIZE_MAX);
57 ensure_capacity(new_length);57 ensure_capacity(new_length);
58 length = new_length;58 length = new_length;
59 }59 }
...@@ -62,19 +62,22 @@ struct ZigList {...@@ -62,19 +62,22 @@ struct ZigList {
62 length = 0;62 length = 0;
63 }63 }
6464
65 void ensure_capacity(int new_capacity) {65 void ensure_capacity(size_t new_capacity) {
66 int better_capacity = max(capacity, 16);66 if (capacity >= new_capacity)
67 while (better_capacity < new_capacity)67 return;
68 better_capacity = better_capacity * 2;68
69 if (better_capacity != capacity) {69 size_t better_capacity = capacity;
70 items = reallocate_nonzero(items, better_capacity);70 do {
71 capacity = better_capacity;71 better_capacity = better_capacity * 1.4 + 8;
72 }72 } while (better_capacity < new_capacity);
73
74 items = reallocate_nonzero(items, capacity, better_capacity);
75 capacity = better_capacity;
73 }76 }
7477
75 T * items;78 T *items;
76 int length;79 size_t length;
77 int capacity;80 size_t capacity;
78};81};
7982
80#endif83#endif
src/main.cpp+9-9
...@@ -64,8 +64,8 @@ static int print_target_list(FILE *f) {...@@ -64,8 +64,8 @@ static int print_target_list(FILE *f) {
64 get_native_target(&native);64 get_native_target(&native);
6565
66 fprintf(f, "Architectures:\n");66 fprintf(f, "Architectures:\n");
67 int arch_count = target_arch_count();67 size_t arch_count = target_arch_count();
68 for (int arch_i = 0; arch_i < arch_count; arch_i += 1) {68 for (size_t arch_i = 0; arch_i < arch_count; arch_i += 1) {
69 const ArchType *arch = get_target_arch(arch_i);69 const ArchType *arch = get_target_arch(arch_i);
70 char arch_name[50];70 char arch_name[50];
71 get_arch_name(arch_name, arch);71 get_arch_name(arch_name, arch);
...@@ -75,16 +75,16 @@ static int print_target_list(FILE *f) {...@@ -75,16 +75,16 @@ static int print_target_list(FILE *f) {
75 }75 }
7676
77 fprintf(f, "\nOperating Systems:\n");77 fprintf(f, "\nOperating Systems:\n");
78 int os_count = target_os_count();78 size_t os_count = target_os_count();
79 for (int i = 0; i < os_count; i += 1) {79 for (size_t i = 0; i < os_count; i += 1) {
80 ZigLLVM_OSType os_type = get_target_os(i);80 ZigLLVM_OSType os_type = get_target_os(i);
81 const char *native_str = (native.os == os_type) ? " (native)" : "";81 const char *native_str = (native.os == os_type) ? " (native)" : "";
82 fprintf(f, " %s%s\n", get_target_os_name(os_type), native_str);82 fprintf(f, " %s%s\n", get_target_os_name(os_type), native_str);
83 }83 }
8484
85 fprintf(f, "\nEnvironments:\n");85 fprintf(f, "\nEnvironments:\n");
86 int environ_count = target_environ_count();86 size_t environ_count = target_environ_count();
87 for (int i = 0; i < environ_count; i += 1) {87 for (size_t i = 0; i < environ_count; i += 1) {
88 ZigLLVM_EnvironmentType environ_type = get_target_environ(i);88 ZigLLVM_EnvironmentType environ_type = get_target_environ(i);
89 const char *native_str = (native.env_type == environ_type) ? " (native)" : "";89 const char *native_str = (native.env_type == environ_type) ? " (native)" : "";
90 fprintf(f, " %s%s\n", ZigLLVMGetEnvironmentTypeName(environ_type), native_str);90 fprintf(f, " %s%s\n", ZigLLVMGetEnvironmentTypeName(environ_type), native_str);
...@@ -375,13 +375,13 @@ int main(int argc, char **argv) {...@@ -375,13 +375,13 @@ int main(int argc, char **argv) {
375 codegen_set_verbose(g, verbose);375 codegen_set_verbose(g, verbose);
376 codegen_set_errmsg_color(g, color);376 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) {
379 codegen_add_lib_dir(g, lib_dirs.at(i));379 codegen_add_lib_dir(g, lib_dirs.at(i));
380 }380 }
381 for (int i = 0; i < link_libs.length; i += 1) {381 for (size_t i = 0; i < link_libs.length; i += 1) {
382 codegen_add_link_lib(g, link_libs.at(i));382 codegen_add_link_lib(g, link_libs.at(i));
383 }383 }
384 for (int i = 0; i < frameworks.length; i += 1) {384 for (size_t i = 0; i < frameworks.length; i += 1) {
385 codegen_add_framework(g, frameworks.at(i));385 codegen_add_framework(g, frameworks.at(i));
386 }386 }
387387
src/os.cpp+25-20
...@@ -73,7 +73,7 @@ static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args,...@@ -73,7 +73,7 @@ static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args,
73 const char **argv = allocate<const char *>(args.length + 2);73 const char **argv = allocate<const char *>(args.length + 2);
74 argv[0] = exe;74 argv[0] = exe;
75 argv[args.length + 1] = nullptr;75 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) {
77 argv[i + 1] = args.at(i);77 argv[i + 1] = args.at(i);
78 }78 }
79 execvp(exe, const_cast<char * const *>(argv));79 execvp(exe, const_cast<char * const *>(argv));
...@@ -114,20 +114,25 @@ void os_path_dirname(Buf *full_path, Buf *out_dirname) {...@@ -114,20 +114,25 @@ void os_path_dirname(Buf *full_path, Buf *out_dirname) {
114}114}
115115
116void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename) {116void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename) {
117 int last_index = buf_len(full_path) - 1;117 size_t len = buf_len(full_path);
118 if (last_index >= 0 && buf_ptr(full_path)[last_index] == '/') {118 if (len != 0) {
119 last_index -= 1;119 size_t last_index = len - 1;
120 }120 if (buf_ptr(full_path)[last_index] == '/') {
121 for (int i = last_index; i >= 0; i -= 1) {121 last_index -= 1;
122 uint8_t c = buf_ptr(full_path)[i];122 }
123 if (c == '/') {123 for (size_t i = last_index;;) {
124 if (out_dirname) {124 uint8_t c = buf_ptr(full_path)[i];
125 buf_init_from_mem(out_dirname, buf_ptr(full_path), i);125 if (c == '/') {
126 }126 if (out_dirname) {
127 if (out_basename) {127 buf_init_from_mem(out_dirname, buf_ptr(full_path), i);
128 buf_init_from_mem(out_basename, buf_ptr(full_path) + i + 1, buf_len(full_path) - (i + 1));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;
129 }133 }
130 return;134 if (i == 0) break;
135 i -= 1;
131 }136 }
132 }137 }
133 if (out_dirname) buf_init_from_mem(out_dirname, ".", 1);138 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,...@@ -246,7 +251,7 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args,
246 const char **argv = allocate<const char *>(args.length + 2);251 const char **argv = allocate<const char *>(args.length + 2);
247 argv[0] = exe;252 argv[0] = exe;
248 argv[args.length + 1] = nullptr;253 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) {
250 argv[i + 1] = args.at(i);255 argv[i + 1] = args.at(i);
251 }256 }
252 execvp(exe, const_cast<char * const *>(argv));257 execvp(exe, const_cast<char * const *>(argv));
...@@ -297,11 +302,11 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args,...@@ -297,11 +302,11 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args,
297 buf_append_str(&command_line, exe);302 buf_append_str(&command_line, exe);
298 buf_append_char(&command_line, '\"');303 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) {
301 buf_append_str(&command_line, " \"");306 buf_append_str(&command_line, " \"");
302 const char *arg = args.at(arg_i);307 const char *arg = args.at(arg_i);
303 int arg_len = strlen(arg);308 size_t arg_len = strlen(arg);
304 for (int c_i = 0; c_i < arg_len; c_i += 1) {309 for (size_t c_i = 0; c_i < arg_len; c_i += 1) {
305 if (arg[c_i] == '\"') {310 if (arg[c_i] == '\"') {
306 zig_panic("TODO");311 zig_panic("TODO");
307 }312 }
...@@ -376,7 +381,7 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args,...@@ -376,7 +381,7 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args,
376 CloseHandle(g_hChildStd_ERR_Wr);381 CloseHandle(g_hChildStd_ERR_Wr);
377 CloseHandle(g_hChildStd_OUT_Wr);382 CloseHandle(g_hChildStd_OUT_Wr);
378383
379 static const int BUF_SIZE = 4 * 1024;384 static const size_t BUF_SIZE = 4 * 1024;
380 {385 {
381 DWORD dwRead;386 DWORD dwRead;
382 char chBuf[BUF_SIZE];387 char chBuf[BUF_SIZE];
...@@ -540,7 +545,7 @@ static int os_buf_to_tmp_file_windows(Buf *contents, Buf *suffix, Buf *out_tmp_p...@@ -540,7 +545,7 @@ static int os_buf_to_tmp_file_windows(Buf *contents, Buf *suffix, Buf *out_tmp_p
540545
541 const char base64[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";546 const char base64[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
542 assert(array_length(base64) == 64 + 1);547 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) {
544 buf_append_char(out_tmp_path, base64[rand() % 64]);549 buf_append_char(out_tmp_path, base64[rand() % 64]);
545 }550 }
546551
src/parseh.cpp+11-11
...@@ -244,10 +244,10 @@ static AstNode *create_fn_proto_node(Context *c, Buf *name, TypeTableEntry *fn_t...@@ -244,10 +244,10 @@ static AstNode *create_fn_proto_node(Context *c, Buf *name, TypeTableEntry *fn_t
244 node->data.fn_proto.name = name;244 node->data.fn_proto.name = name;
245 node->data.fn_proto.return_type = make_type_node(c, fn_type->data.fn.fn_type_id.return_type);245 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) {
248 FnTypeParamInfo *info = &fn_type->data.fn.fn_type_id.param_info[i];248 FnTypeParamInfo *info = &fn_type->data.fn.fn_type_id.param_info[i];
249 char arg_name[20];249 char arg_name[20];
250 sprintf(arg_name, "arg_%d", i);250 sprintf(arg_name, "arg_%zu", i);
251 node->data.fn_proto.params.append(create_param_decl_node(c, arg_name,251 node->data.fn_proto.params.append(create_param_decl_node(c, arg_name,
252 make_type_node(c, info->type), info->is_noalias));252 make_type_node(c, info->type), info->is_noalias));
253 }253 }
...@@ -272,7 +272,7 @@ static AstNode *create_inline_fn_node(Context *c, Buf *fn_name, Buf *var_name, T...@@ -272,7 +272,7 @@ static AstNode *create_inline_fn_node(Context *c, Buf *fn_name, Buf *var_name, T
272272
273 AstNode *fn_call_node = create_node(c, NodeTypeFnCallExpr);273 AstNode *fn_call_node = create_node(c, NodeTypeFnCallExpr);
274 fn_call_node->data.fn_call_expr.fn_ref_expr = unwrap_node;274 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) {
276 AstNode *decl_node = node->data.fn_def.fn_proto->data.fn_proto.params.at(i);276 AstNode *decl_node = node->data.fn_def.fn_proto->data.fn_proto.params.at(i);
277 Buf *param_name = decl_node->data.param_decl.name;277 Buf *param_name = decl_node->data.param_decl.name;
278 fn_call_node->data.fn_call_expr.params.append(create_symbol_node(c, buf_ptr(param_name)));278 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...@@ -621,7 +621,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
621 fn_type_id.param_info = &fn_type_id.prealloc_param_info[0];621 fn_type_id.param_info = &fn_type_id.prealloc_param_info[0];
622 }622 }
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) {
625 QualType qt = fn_proto_ty->getParamType(i);625 QualType qt = fn_proto_ty->getParamType(i);
626 TypeTableEntry *param_type = resolve_qual_type(c, qt, decl);626 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) {...@@ -748,16 +748,16 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
748748
749 assert(!fn_type->data.fn.fn_type_id.is_naked);749 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;
752 Buf name_buf = BUF_INIT;752 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) {
754 FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[i];754 FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[i];
755 AstNode *type_node = make_type_node(c, param_info->type);755 AstNode *type_node = make_type_node(c, param_info->type);
756 const ParmVarDecl *param = fn_decl->getParamDecl(i);756 const ParmVarDecl *param = fn_decl->getParamDecl(i);
757 const char *name = decl_name(param);757 const char *name = decl_name(param);
758 if (strlen(name) == 0) {758 if (strlen(name) == 0) {
759 buf_resize(&name_buf, 0);759 buf_resize(&name_buf, 0);
760 buf_appendf(&name_buf, "arg%d", i);760 buf_appendf(&name_buf, "arg%zu", i);
761 name = buf_ptr(&name_buf);761 name = buf_ptr(&name_buf);
762 }762 }
763763
...@@ -1316,7 +1316,7 @@ static bool name_exists_and_const(Context *c, Buf *name) {...@@ -1316,7 +1316,7 @@ static bool name_exists_and_const(Context *c, Buf *name) {
1316}1316}
13171317
1318static void render_aliases(Context *c) {1318static 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) {
1320 AstNode *alias_node = c->aliases.at(i);1320 AstNode *alias_node = c->aliases.at(i);
1321 assert(alias_node->type == NodeTypeVariableDeclaration);1321 assert(alias_node->type == NodeTypeVariableDeclaration);
1322 Buf *name = alias_node->data.variable_declaration.symbol;1322 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...@@ -1347,7 +1347,7 @@ static void process_macro(Context *c, CTokenize *ctok, Buf *name, const char *ch
1347 }1347 }
13481348
1349 bool negate = false;1349 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) {
1351 bool is_first = (i == 0);1351 bool is_first = (i == 0);
1352 bool is_last = (i == ctok->tokens.length - 1);1352 bool is_last = (i == ctok->tokens.length - 1);
1353 CTok *tok = &ctok->tokens.at(i);1353 CTok *tok = &ctok->tokens.at(i);
...@@ -1403,7 +1403,7 @@ static void process_macro(Context *c, CTokenize *ctok, Buf *name, const char *ch...@@ -1403,7 +1403,7 @@ static void process_macro(Context *c, CTokenize *ctok, Buf *name, const char *ch
1403}1403}
14041404
1405static void process_symbol_macros(Context *c) {1405static 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) {
1407 MacroSymbol ms = c->macro_symbols.at(i);1407 MacroSymbol ms = c->macro_symbols.at(i);
1408 if (name_exists_and_const(c, ms.value)) {1408 if (name_exists_and_const(c, ms.value)) {
1409 AstNode *var_node = create_var_decl_node(c, buf_ptr(ms.name),1409 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...@@ -1524,7 +1524,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
1524 clang_argv.append("-isystem");1524 clang_argv.append("-isystem");
1525 clang_argv.append(buf_ptr(codegen->libc_include_dir));1525 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) {
1528 clang_argv.append(codegen->clang_argv[i]);1528 clang_argv.append(codegen->clang_argv[i]);
1529 }1529 }
15301530
src/parser.cpp+76-76
...@@ -28,7 +28,7 @@ struct ParseContext {...@@ -28,7 +28,7 @@ struct ParseContext {
2828
29__attribute__ ((format (printf, 4, 5)))29__attribute__ ((format (printf, 4, 5)))
30__attribute__ ((noreturn))30__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, ...) {
32 assert(node->type == NodeTypeAsmExpr);32 assert(node->type == NodeTypeAsmExpr);
3333
3434
...@@ -109,7 +109,7 @@ static void parse_asm_template(ParseContext *pc, AstNode *node) {...@@ -109,7 +109,7 @@ static void parse_asm_template(ParseContext *pc, AstNode *node) {
109109
110 enum State state = StateStart;110 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) {
113 uint8_t c = *((uint8_t*)buf_ptr(asm_template) + i);113 uint8_t c = *((uint8_t*)buf_ptr(asm_template) + i);
114 switch (state) {114 switch (state) {
115 case StateStart:115 case StateStart:
...@@ -205,16 +205,16 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {...@@ -205,16 +205,16 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {
205 ast_error(pc, token, "invalid token: '%s'", buf_ptr(&token_value));205 ast_error(pc, token, "invalid token: '%s'", buf_ptr(&token_value));
206}206}
207207
208static AstNode *ast_parse_expression(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, int *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, int *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, int *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, int *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, int *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, int *token_index, bool mandatory,214static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory,
215 ZigList<AstNode*> *directives, VisibMod visib_mod);215 ZigList<AstNode*> *directives, VisibMod visib_mod);
216static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index);216static AstNode *ast_parse_return_expr(ParseContext *pc, size_t *token_index);
217static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool mandatory);217static AstNode *ast_parse_grouped_expr(ParseContext *pc, size_t *token_index, bool mandatory);
218218
219static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {219static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {
220 if (token->id == token_id) {220 if (token->id == token_id) {
...@@ -226,7 +226,7 @@ static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {...@@ -226,7 +226,7 @@ static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {
226 ast_error(pc, token, "expected token '%s', found '%s'", token_name(token_id), token_name(token->id));226 ast_error(pc, token, "expected token '%s', found '%s'", token_name(token_id), token_name(token->id));
227}227}
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) {
230 Token *token = &pc->tokens->at(*token_index);230 Token *token = &pc->tokens->at(*token_index);
231 ast_expect_token(pc, token, token_id);231 ast_expect_token(pc, token, token_id);
232 *token_index += 1;232 *token_index += 1;
...@@ -236,7 +236,7 @@ static Token *ast_eat_token(ParseContext *pc, int *token_index, TokenId token_id...@@ -236,7 +236,7 @@ static Token *ast_eat_token(ParseContext *pc, int *token_index, TokenId token_id
236/*236/*
237Directive = "#" "Symbol" "(" Expression ")"237Directive = "#" "Symbol" "(" Expression ")"
238*/238*/
239static AstNode *ast_parse_directive(ParseContext *pc, int *token_index) {239static AstNode *ast_parse_directive(ParseContext *pc, size_t *token_index) {
240 Token *number_sign = ast_eat_token(pc, token_index, TokenIdNumberSign);240 Token *number_sign = ast_eat_token(pc, token_index, TokenIdNumberSign);
241241
242 AstNode *node = ast_create_node(pc, NodeTypeDirective, number_sign);242 AstNode *node = ast_create_node(pc, NodeTypeDirective, number_sign);
...@@ -251,7 +251,7 @@ static AstNode *ast_parse_directive(ParseContext *pc, int *token_index) {...@@ -251,7 +251,7 @@ static AstNode *ast_parse_directive(ParseContext *pc, int *token_index) {
251 return node;251 return node;
252}252}
253253
254static void ast_parse_directives(ParseContext *pc, int *token_index,254static void ast_parse_directives(ParseContext *pc, size_t *token_index,
255 ZigList<AstNode *> *directives)255 ZigList<AstNode *> *directives)
256{256{
257 for (;;) {257 for (;;) {
...@@ -269,7 +269,7 @@ static void ast_parse_directives(ParseContext *pc, int *token_index,...@@ -269,7 +269,7 @@ static void ast_parse_directives(ParseContext *pc, int *token_index,
269/*269/*
270TypeExpr = PrefixOpExpression | "var"270TypeExpr = PrefixOpExpression | "var"
271*/271*/
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) {
273 Token *token = &pc->tokens->at(*token_index);273 Token *token = &pc->tokens->at(*token_index);
274 if (token->id == TokenIdKeywordVar) {274 if (token->id == TokenIdKeywordVar) {
275 AstNode *node = ast_create_node(pc, NodeTypeVarLiteral, token);275 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...@@ -283,7 +283,7 @@ static AstNode *ast_parse_type_expr(ParseContext *pc, int *token_index, bool man
283/*283/*
284ParamDecl = option("noalias" | "inline") option("Symbol" ":") TypeExpr | "..."284ParamDecl = option("noalias" | "inline") option("Symbol" ":") TypeExpr | "..."
285*/285*/
286static AstNode *ast_parse_param_decl(ParseContext *pc, int *token_index) {286static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) {
287 Token *token = &pc->tokens->at(*token_index);287 Token *token = &pc->tokens->at(*token_index);
288288
289 if (token->id == TokenIdEllipsis) {289 if (token->id == TokenIdEllipsis) {
...@@ -320,7 +320,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, int *token_index) {...@@ -320,7 +320,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, int *token_index) {
320}320}
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,
324 ZigList<AstNode *> *params, bool *is_var_args)324 ZigList<AstNode *> *params, bool *is_var_args)
325{325{
326 *is_var_args = false;326 *is_var_args = false;
...@@ -356,7 +356,7 @@ static void ast_parse_param_decl_list(ParseContext *pc, int *token_index,...@@ -356,7 +356,7 @@ static void ast_parse_param_decl_list(ParseContext *pc, int *token_index,
356 zig_unreachable();356 zig_unreachable();
357}357}
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) {
360 Token *token = &pc->tokens->at(*token_index);360 Token *token = &pc->tokens->at(*token_index);
361 if (token->id == TokenIdRParen) {361 if (token->id == TokenIdRParen) {
362 *token_index += 1;362 *token_index += 1;
...@@ -381,7 +381,7 @@ static void ast_parse_fn_call_param_list(ParseContext *pc, int *token_index, Zig...@@ -381,7 +381,7 @@ static void ast_parse_fn_call_param_list(ParseContext *pc, int *token_index, Zig
381/*381/*
382GroupedExpression : token(LParen) Expression token(RParen)382GroupedExpression : token(LParen) Expression token(RParen)
383*/383*/
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) {
385 Token *l_paren = &pc->tokens->at(*token_index);385 Token *l_paren = &pc->tokens->at(*token_index);
386 if (l_paren->id != TokenIdLParen) {386 if (l_paren->id != TokenIdLParen) {
387 if (mandatory) {387 if (mandatory) {
...@@ -405,7 +405,7 @@ static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool...@@ -405,7 +405,7 @@ static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool
405/*405/*
406ArrayType : "[" option(Expression) "]" option("const") PrefixOpExpression406ArrayType : "[" option(Expression) "]" option("const") PrefixOpExpression
407*/407*/
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) {
409 Token *l_bracket = &pc->tokens->at(*token_index);409 Token *l_bracket = &pc->tokens->at(*token_index);
410 if (l_bracket->id != TokenIdLBracket) {410 if (l_bracket->id != TokenIdLBracket) {
411 if (mandatory) {411 if (mandatory) {
...@@ -437,7 +437,7 @@ static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bo...@@ -437,7 +437,7 @@ static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bo
437/*437/*
438AsmInputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) Expression token(RParen)438AsmInputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) Expression token(RParen)
439*/439*/
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) {
441 ast_eat_token(pc, token_index, TokenIdLBracket);441 ast_eat_token(pc, token_index, TokenIdLBracket);
442 Token *alias = ast_eat_token(pc, token_index, TokenIdSymbol);442 Token *alias = ast_eat_token(pc, token_index, TokenIdSymbol);
443 ast_eat_token(pc, token_index, TokenIdRBracket);443 ast_eat_token(pc, token_index, TokenIdRBracket);
...@@ -458,7 +458,7 @@ static void ast_parse_asm_input_item(ParseContext *pc, int *token_index, AstNode...@@ -458,7 +458,7 @@ static void ast_parse_asm_input_item(ParseContext *pc, int *token_index, AstNode
458/*458/*
459AsmOutputItem : "[" "Symbol" "]" "String" "(" ("Symbol" | "->" PrefixOpExpression) ")"459AsmOutputItem : "[" "Symbol" "]" "String" "(" ("Symbol" | "->" PrefixOpExpression) ")"
460*/460*/
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) {
462 ast_eat_token(pc, token_index, TokenIdLBracket);462 ast_eat_token(pc, token_index, TokenIdLBracket);
463 Token *alias = ast_eat_token(pc, token_index, TokenIdSymbol);463 Token *alias = ast_eat_token(pc, token_index, TokenIdSymbol);
464 ast_eat_token(pc, token_index, TokenIdRBracket);464 ast_eat_token(pc, token_index, TokenIdRBracket);
...@@ -489,7 +489,7 @@ static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNod...@@ -489,7 +489,7 @@ static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNod
489/*489/*
490AsmClobbers: token(Colon) list(token(String), token(Comma))490AsmClobbers: token(Colon) list(token(String), token(Comma))
491*/491*/
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) {
493 Token *colon_tok = &pc->tokens->at(*token_index);493 Token *colon_tok = &pc->tokens->at(*token_index);
494494
495 if (colon_tok->id != TokenIdColon)495 if (colon_tok->id != TokenIdColon)
...@@ -519,7 +519,7 @@ static void ast_parse_asm_clobbers(ParseContext *pc, int *token_index, AstNode *...@@ -519,7 +519,7 @@ static void ast_parse_asm_clobbers(ParseContext *pc, int *token_index, AstNode *
519/*519/*
520AsmInput : token(Colon) list(AsmInputItem, token(Comma)) option(AsmClobbers)520AsmInput : token(Colon) list(AsmInputItem, token(Comma)) option(AsmClobbers)
521*/521*/
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) {
523 Token *colon_tok = &pc->tokens->at(*token_index);523 Token *colon_tok = &pc->tokens->at(*token_index);
524524
525 if (colon_tok->id != TokenIdColon)525 if (colon_tok->id != TokenIdColon)
...@@ -546,7 +546,7 @@ static void ast_parse_asm_input(ParseContext *pc, int *token_index, AstNode *nod...@@ -546,7 +546,7 @@ static void ast_parse_asm_input(ParseContext *pc, int *token_index, AstNode *nod
546/*546/*
547AsmOutput : token(Colon) list(AsmOutputItem, token(Comma)) option(AsmInput)547AsmOutput : token(Colon) list(AsmOutputItem, token(Comma)) option(AsmInput)
548*/548*/
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) {
550 Token *colon_tok = &pc->tokens->at(*token_index);550 Token *colon_tok = &pc->tokens->at(*token_index);
551551
552 if (colon_tok->id != TokenIdColon)552 if (colon_tok->id != TokenIdColon)
...@@ -579,7 +579,7 @@ static void ast_parse_asm_output(ParseContext *pc, int *token_index, AstNode *no...@@ -579,7 +579,7 @@ static void ast_parse_asm_output(ParseContext *pc, int *token_index, AstNode *no
579/*579/*
580AsmExpression : token(Asm) option(token(Volatile)) token(LParen) token(String) option(AsmOutput) token(RParen)580AsmExpression : token(Asm) option(token(Volatile)) token(LParen) token(String) option(AsmOutput) token(RParen)
581*/581*/
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) {
583 Token *asm_token = &pc->tokens->at(*token_index);583 Token *asm_token = &pc->tokens->at(*token_index);
584584
585 if (asm_token->id != TokenIdKeywordAsm) {585 if (asm_token->id != TokenIdKeywordAsm) {
...@@ -622,7 +622,7 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc, int *token_index, bool mand...@@ -622,7 +622,7 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc, int *token_index, bool mand
622PrimaryExpression = "Number" | "String" | "CharLiteral" | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | "Symbol" | ("@" "Symbol" FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." "Symbol")622PrimaryExpression = "Number" | "String" | "CharLiteral" | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | "Symbol" | ("@" "Symbol" FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." "Symbol")
623KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "zeroes" | "error" | "type"623KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "zeroes" | "error" | "type"
624*/624*/
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) {
626 Token *token = &pc->tokens->at(*token_index);626 Token *token = &pc->tokens->at(*token_index);
627627
628 if (token->id == TokenIdNumberLiteral) {628 if (token->id == TokenIdNumberLiteral) {
...@@ -752,7 +752,7 @@ CurlySuffixExpression : PrefixOpExpression option(ContainerInitExpression)...@@ -752,7 +752,7 @@ CurlySuffixExpression : PrefixOpExpression option(ContainerInitExpression)
752ContainerInitExpression : token(LBrace) ContainerInitBody token(RBrace)752ContainerInitExpression : token(LBrace) ContainerInitBody token(RBrace)
753ContainerInitBody : list(StructLiteralField, token(Comma)) | list(Expression, token(Comma))753ContainerInitBody : list(StructLiteralField, token(Comma)) | list(Expression, token(Comma))
754*/754*/
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) {
756 AstNode *prefix_op_expr = ast_parse_prefix_op_expr(pc, token_index, mandatory);756 AstNode *prefix_op_expr = ast_parse_prefix_op_expr(pc, token_index, mandatory);
757 if (!prefix_op_expr) {757 if (!prefix_op_expr) {
758 return nullptr;758 return nullptr;
...@@ -843,7 +843,7 @@ SliceExpression : token(LBracket) Expression token(Ellipsis) option(Expression)...@@ -843,7 +843,7 @@ SliceExpression : token(LBracket) Expression token(Ellipsis) option(Expression)
843FieldAccessExpression : token(Dot) token(Symbol)843FieldAccessExpression : token(Dot) token(Symbol)
844StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression844StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression
845*/845*/
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) {
847 AstNode *primary_expr = ast_parse_primary_expr(pc, token_index, mandatory);847 AstNode *primary_expr = ast_parse_primary_expr(pc, token_index, mandatory);
848 if (!primary_expr) {848 if (!primary_expr) {
849 return nullptr;849 return nullptr;
...@@ -936,7 +936,7 @@ static PrefixOp tok_to_prefix_op(Token *token) {...@@ -936,7 +936,7 @@ static PrefixOp tok_to_prefix_op(Token *token) {
936PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression936PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression
937PrefixOp = "!" | "-" | "~" | "*" | ("&" option("const")) | "?" | "%" | "%%" | "??" | "-%"937PrefixOp = "!" | "-" | "~" | "*" | ("&" option("const")) | "?" | "%" | "%%" | "??" | "-%"
938*/938*/
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) {
940 Token *token = &pc->tokens->at(*token_index);940 Token *token = &pc->tokens->at(*token_index);
941 PrefixOp prefix_op = tok_to_prefix_op(token);941 PrefixOp prefix_op = tok_to_prefix_op(token);
942 if (prefix_op == PrefixOpInvalid) {942 if (prefix_op == PrefixOpInvalid) {
...@@ -1005,7 +1005,7 @@ static BinOpType tok_to_mult_op(Token *token) {...@@ -1005,7 +1005,7 @@ static BinOpType tok_to_mult_op(Token *token) {
1005/*1005/*
1006MultiplyOperator = "*" | "/" | "%" | "**" | "*%"1006MultiplyOperator = "*" | "/" | "%" | "**" | "*%"
1007*/1007*/
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) {
1009 Token *token = &pc->tokens->at(*token_index);1009 Token *token = &pc->tokens->at(*token_index);
1010 BinOpType result = tok_to_mult_op(token);1010 BinOpType result = tok_to_mult_op(token);
1011 if (result == BinOpTypeInvalid) {1011 if (result == BinOpTypeInvalid) {
...@@ -1022,7 +1022,7 @@ static BinOpType ast_parse_mult_op(ParseContext *pc, int *token_index, bool mand...@@ -1022,7 +1022,7 @@ static BinOpType ast_parse_mult_op(ParseContext *pc, int *token_index, bool mand
1022/*1022/*
1023MultiplyExpression : CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression1023MultiplyExpression : CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression
1024*/1024*/
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) {
1026 AstNode *operand_1 = ast_parse_curly_suffix_expr(pc, token_index, mandatory);1026 AstNode *operand_1 = ast_parse_curly_suffix_expr(pc, token_index, mandatory);
1027 if (!operand_1)1027 if (!operand_1)
1028 return nullptr;1028 return nullptr;
...@@ -1059,7 +1059,7 @@ static BinOpType tok_to_add_op(Token *token) {...@@ -1059,7 +1059,7 @@ static BinOpType tok_to_add_op(Token *token) {
1059/*1059/*
1060AdditionOperator = "+" | "-" | "++" | "+%" | "-%"1060AdditionOperator = "+" | "-" | "++" | "+%" | "-%"
1061*/1061*/
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) {
1063 Token *token = &pc->tokens->at(*token_index);1063 Token *token = &pc->tokens->at(*token_index);
1064 BinOpType result = tok_to_add_op(token);1064 BinOpType result = tok_to_add_op(token);
1065 if (result == BinOpTypeInvalid) {1065 if (result == BinOpTypeInvalid) {
...@@ -1076,7 +1076,7 @@ static BinOpType ast_parse_add_op(ParseContext *pc, int *token_index, bool manda...@@ -1076,7 +1076,7 @@ static BinOpType ast_parse_add_op(ParseContext *pc, int *token_index, bool manda
1076/*1076/*
1077AdditionExpression : MultiplyExpression AdditionOperator AdditionExpression | MultiplyExpression1077AdditionExpression : MultiplyExpression AdditionOperator AdditionExpression | MultiplyExpression
1078*/1078*/
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) {
1080 AstNode *operand_1 = ast_parse_mult_expr(pc, token_index, mandatory);1080 AstNode *operand_1 = ast_parse_mult_expr(pc, token_index, mandatory);
1081 if (!operand_1)1081 if (!operand_1)
1082 return nullptr;1082 return nullptr;
...@@ -1111,7 +1111,7 @@ static BinOpType tok_to_bit_shift_op(Token *token) {...@@ -1111,7 +1111,7 @@ static BinOpType tok_to_bit_shift_op(Token *token) {
1111/*1111/*
1112BitShiftOperator = "<<" | ">>" | "<<%"1112BitShiftOperator = "<<" | ">>" | "<<%"
1113*/1113*/
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) {
1115 Token *token = &pc->tokens->at(*token_index);1115 Token *token = &pc->tokens->at(*token_index);
1116 BinOpType result = tok_to_bit_shift_op(token);1116 BinOpType result = tok_to_bit_shift_op(token);
1117 if (result == BinOpTypeInvalid) {1117 if (result == BinOpTypeInvalid) {
...@@ -1128,7 +1128,7 @@ static BinOpType ast_parse_bit_shift_op(ParseContext *pc, int *token_index, bool...@@ -1128,7 +1128,7 @@ static BinOpType ast_parse_bit_shift_op(ParseContext *pc, int *token_index, bool
1128/*1128/*
1129BitShiftExpression : AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression1129BitShiftExpression : AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression
1130*/1130*/
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) {
1132 AstNode *operand_1 = ast_parse_add_expr(pc, token_index, mandatory);1132 AstNode *operand_1 = ast_parse_add_expr(pc, token_index, mandatory);
1133 if (!operand_1)1133 if (!operand_1)
1134 return nullptr;1134 return nullptr;
...@@ -1155,7 +1155,7 @@ static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, int *token_index, boo...@@ -1155,7 +1155,7 @@ static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, int *token_index, boo
1155/*1155/*
1156BinaryAndExpression : BitShiftExpression token(Ampersand) BinaryAndExpression | BitShiftExpression1156BinaryAndExpression : BitShiftExpression token(Ampersand) BinaryAndExpression | BitShiftExpression
1157*/1157*/
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) {
1159 AstNode *operand_1 = ast_parse_bit_shift_expr(pc, token_index, mandatory);1159 AstNode *operand_1 = ast_parse_bit_shift_expr(pc, token_index, mandatory);
1160 if (!operand_1)1160 if (!operand_1)
1161 return nullptr;1161 return nullptr;
...@@ -1181,7 +1181,7 @@ static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool...@@ -1181,7 +1181,7 @@ static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool
1181/*1181/*
1182BinaryXorExpression : BinaryAndExpression token(BinXor) BinaryXorExpression | BinaryAndExpression1182BinaryXorExpression : BinaryAndExpression token(BinXor) BinaryXorExpression | BinaryAndExpression
1183*/1183*/
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) {
1185 AstNode *operand_1 = ast_parse_bin_and_expr(pc, token_index, mandatory);1185 AstNode *operand_1 = ast_parse_bin_and_expr(pc, token_index, mandatory);
1186 if (!operand_1)1186 if (!operand_1)
1187 return nullptr;1187 return nullptr;
...@@ -1207,7 +1207,7 @@ static AstNode *ast_parse_bin_xor_expr(ParseContext *pc, int *token_index, bool...@@ -1207,7 +1207,7 @@ static AstNode *ast_parse_bin_xor_expr(ParseContext *pc, int *token_index, bool
1207/*1207/*
1208BinaryOrExpression : BinaryXorExpression token(BinOr) BinaryOrExpression | BinaryXorExpression1208BinaryOrExpression : BinaryXorExpression token(BinOr) BinaryOrExpression | BinaryXorExpression
1209*/1209*/
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) {
1211 AstNode *operand_1 = ast_parse_bin_xor_expr(pc, token_index, mandatory);1211 AstNode *operand_1 = ast_parse_bin_xor_expr(pc, token_index, mandatory);
1212 if (!operand_1)1212 if (!operand_1)
1213 return nullptr;1213 return nullptr;
...@@ -1242,7 +1242,7 @@ static BinOpType tok_to_cmp_op(Token *token) {...@@ -1242,7 +1242,7 @@ static BinOpType tok_to_cmp_op(Token *token) {
1242 }1242 }
1243}1243}
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) {
1246 Token *token = &pc->tokens->at(*token_index);1246 Token *token = &pc->tokens->at(*token_index);
1247 BinOpType result = tok_to_cmp_op(token);1247 BinOpType result = tok_to_cmp_op(token);
1248 if (result == BinOpTypeInvalid) {1248 if (result == BinOpTypeInvalid) {
...@@ -1259,7 +1259,7 @@ static BinOpType ast_parse_comparison_operator(ParseContext *pc, int *token_inde...@@ -1259,7 +1259,7 @@ static BinOpType ast_parse_comparison_operator(ParseContext *pc, int *token_inde
1259/*1259/*
1260ComparisonExpression : BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression1260ComparisonExpression : BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression
1261*/1261*/
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) {
1263 AstNode *operand_1 = ast_parse_bin_or_expr(pc, token_index, mandatory);1263 AstNode *operand_1 = ast_parse_bin_or_expr(pc, token_index, mandatory);
1264 if (!operand_1)1264 if (!operand_1)
1265 return nullptr;1265 return nullptr;
...@@ -1283,7 +1283,7 @@ static AstNode *ast_parse_comparison_expr(ParseContext *pc, int *token_index, bo...@@ -1283,7 +1283,7 @@ static AstNode *ast_parse_comparison_expr(ParseContext *pc, int *token_index, bo
1283/*1283/*
1284BoolAndExpression : ComparisonExpression token(BoolAnd) BoolAndExpression | ComparisonExpression1284BoolAndExpression : ComparisonExpression token(BoolAnd) BoolAndExpression | ComparisonExpression
1285 */1285 */
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) {
1287 AstNode *operand_1 = ast_parse_comparison_expr(pc, token_index, mandatory);1287 AstNode *operand_1 = ast_parse_comparison_expr(pc, token_index, mandatory);
1288 if (!operand_1)1288 if (!operand_1)
1289 return nullptr;1289 return nullptr;
...@@ -1309,7 +1309,7 @@ static AstNode *ast_parse_bool_and_expr(ParseContext *pc, int *token_index, bool...@@ -1309,7 +1309,7 @@ static AstNode *ast_parse_bool_and_expr(ParseContext *pc, int *token_index, bool
1309/*1309/*
1310Else : token(Else) Expression1310Else : token(Else) Expression
1311*/1311*/
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) {
1313 Token *else_token = &pc->tokens->at(*token_index);1313 Token *else_token = &pc->tokens->at(*token_index);
13141314
1315 if (else_token->id != TokenIdKeywordElse) {1315 if (else_token->id != TokenIdKeywordElse) {
...@@ -1329,7 +1329,7 @@ IfExpression : IfVarExpression | IfBoolExpression...@@ -1329,7 +1329,7 @@ IfExpression : IfVarExpression | IfBoolExpression
1329IfBoolExpression : token(If) token(LParen) Expression token(RParen) Expression option(Else)1329IfBoolExpression : token(If) token(LParen) Expression token(RParen) Expression option(Else)
1330IfVarExpression = "if" "(" ("const" | "var") option("*") "Symbol" option(":" TypeExpr) "?=" Expression ")" Expression Option(Else)1330IfVarExpression = "if" "(" ("const" | "var") option("*") "Symbol" option(":" TypeExpr) "?=" Expression ")" Expression Option(Else)
1331*/1331*/
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) {
1333 Token *if_tok = &pc->tokens->at(*token_index);1333 Token *if_tok = &pc->tokens->at(*token_index);
1334 if (if_tok->id != TokenIdKeywordIf) {1334 if (if_tok->id != TokenIdKeywordIf) {
1335 if (mandatory) {1335 if (mandatory) {
...@@ -1396,7 +1396,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool manda...@@ -1396,7 +1396,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool manda
1396/*1396/*
1397ReturnExpression : option("%" | "?") "return" option(Expression)1397ReturnExpression : option("%" | "?") "return" option(Expression)
1398*/1398*/
1399static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index) {1399static AstNode *ast_parse_return_expr(ParseContext *pc, size_t *token_index) {
1400 Token *token = &pc->tokens->at(*token_index);1400 Token *token = &pc->tokens->at(*token_index);
14011401
1402 NodeType node_type;1402 NodeType node_type;
...@@ -1439,7 +1439,7 @@ static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index) {...@@ -1439,7 +1439,7 @@ static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index) {
1439/*1439/*
1440Defer = option("%" | "?") "defer" option(Expression)1440Defer = option("%" | "?") "defer" option(Expression)
1441*/1441*/
1442static AstNode *ast_parse_defer_expr(ParseContext *pc, int *token_index) {1442static AstNode *ast_parse_defer_expr(ParseContext *pc, size_t *token_index) {
1443 Token *token = &pc->tokens->at(*token_index);1443 Token *token = &pc->tokens->at(*token_index);
14441444
1445 NodeType node_type;1445 NodeType node_type;
...@@ -1482,7 +1482,7 @@ static AstNode *ast_parse_defer_expr(ParseContext *pc, int *token_index) {...@@ -1482,7 +1482,7 @@ static AstNode *ast_parse_defer_expr(ParseContext *pc, int *token_index) {
1482/*1482/*
1483VariableDeclaration : ("var" | "const") "Symbol" ("=" Expression | ":" PrefixOpExpression option("=" Expression))1483VariableDeclaration : ("var" | "const") "Symbol" ("=" Expression | ":" PrefixOpExpression option("=" Expression))
1484*/1484*/
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,
1486 ZigList<AstNode*> *directives, VisibMod visib_mod)1486 ZigList<AstNode*> *directives, VisibMod visib_mod)
1487{1487{
1488 Token *first_token = &pc->tokens->at(*token_index);1488 Token *first_token = &pc->tokens->at(*token_index);
...@@ -1536,7 +1536,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token...@@ -1536,7 +1536,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token
1536/*1536/*
1537BoolOrExpression : BoolAndExpression token(BoolOr) BoolOrExpression | BoolAndExpression1537BoolOrExpression : BoolAndExpression token(BoolOr) BoolOrExpression | BoolAndExpression
1538*/1538*/
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) {
1540 AstNode *operand_1 = ast_parse_bool_and_expr(pc, token_index, mandatory);1540 AstNode *operand_1 = ast_parse_bool_and_expr(pc, token_index, mandatory);
1541 if (!operand_1)1541 if (!operand_1)
1542 return nullptr;1542 return nullptr;
...@@ -1562,7 +1562,7 @@ static AstNode *ast_parse_bool_or_expr(ParseContext *pc, int *token_index, bool...@@ -1562,7 +1562,7 @@ static AstNode *ast_parse_bool_or_expr(ParseContext *pc, int *token_index, bool
1562/*1562/*
1563WhileExpression = "while" "(" Expression option(";" Expression) ")" Expression1563WhileExpression = "while" "(" Expression option(";" Expression) ")" Expression
1564*/1564*/
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) {
1566 Token *token = &pc->tokens->at(*token_index);1566 Token *token = &pc->tokens->at(*token_index);
15671567
1568 if (token->id != TokenIdKeywordWhile) {1568 if (token->id != TokenIdKeywordWhile) {
...@@ -1598,7 +1598,7 @@ static AstNode *ast_parse_while_expr(ParseContext *pc, int *token_index, bool ma...@@ -1598,7 +1598,7 @@ static AstNode *ast_parse_while_expr(ParseContext *pc, int *token_index, bool ma
1598 return node;1598 return node;
1599}1599}
16001600
1601static AstNode *ast_parse_symbol(ParseContext *pc, int *token_index) {1601static AstNode *ast_parse_symbol(ParseContext *pc, size_t *token_index) {
1602 Token *token = ast_eat_token(pc, token_index, TokenIdSymbol);1602 Token *token = ast_eat_token(pc, token_index, TokenIdSymbol);
1603 AstNode *node = ast_create_node(pc, NodeTypeSymbol, token);1603 AstNode *node = ast_create_node(pc, NodeTypeSymbol, token);
1604 node->data.symbol_expr.symbol = token_buf(token);1604 node->data.symbol_expr.symbol = token_buf(token);
...@@ -1608,7 +1608,7 @@ static AstNode *ast_parse_symbol(ParseContext *pc, int *token_index) {...@@ -1608,7 +1608,7 @@ static AstNode *ast_parse_symbol(ParseContext *pc, int *token_index) {
1608/*1608/*
1609ForExpression = "for" "(" Expression ")" option("|" option("*") "Symbol" option("," "Symbol") "|") Expression1609ForExpression = "for" "(" Expression ")" option("|" option("*") "Symbol" option("," "Symbol") "|") Expression
1610*/1610*/
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) {
1612 Token *token = &pc->tokens->at(*token_index);1612 Token *token = &pc->tokens->at(*token_index);
16131613
1614 if (token->id != TokenIdKeywordFor) {1614 if (token->id != TokenIdKeywordFor) {
...@@ -1659,7 +1659,7 @@ SwitchExpression : "switch" "(" Expression ")" "{" many(SwitchProng) "}"...@@ -1659,7 +1659,7 @@ SwitchExpression : "switch" "(" Expression ")" "{" many(SwitchProng) "}"
1659SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" "Symbol" "|") Expression ","1659SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" "Symbol" "|") Expression ","
1660SwitchItem : Expression | (Expression "..." Expression)1660SwitchItem : Expression | (Expression "..." Expression)
1661*/1661*/
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) {
1663 Token *token = &pc->tokens->at(*token_index);1663 Token *token = &pc->tokens->at(*token_index);
16641664
1665 if (token->id != TokenIdKeywordSwitch) {1665 if (token->id != TokenIdKeywordSwitch) {
...@@ -1736,7 +1736,7 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, int *token_index, bool m...@@ -1736,7 +1736,7 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, int *token_index, bool m
1736/*1736/*
1737BlockExpression : IfExpression | Block | WhileExpression | ForExpression | SwitchExpression1737BlockExpression : IfExpression | Block | WhileExpression | ForExpression | SwitchExpression
1738*/1738*/
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) {
1740 Token *token = &pc->tokens->at(*token_index);1740 Token *token = &pc->tokens->at(*token_index);
17411741
1742 AstNode *if_expr = ast_parse_if_expr(pc, token_index, false);1742 AstNode *if_expr = ast_parse_if_expr(pc, token_index, false);
...@@ -1791,7 +1791,7 @@ static BinOpType tok_to_ass_op(Token *token) {...@@ -1791,7 +1791,7 @@ static BinOpType tok_to_ass_op(Token *token) {
1791/*1791/*
1792AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "&&=" | "||=" | "*%=" | "+%=" | "-%=" | "<<%="1792AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "&&=" | "||=" | "*%=" | "+%=" | "-%=" | "<<%="
1793*/1793*/
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) {
1795 Token *token = &pc->tokens->at(*token_index);1795 Token *token = &pc->tokens->at(*token_index);
1796 BinOpType result = tok_to_ass_op(token);1796 BinOpType result = tok_to_ass_op(token);
1797 if (result == BinOpTypeInvalid) {1797 if (result == BinOpTypeInvalid) {
...@@ -1810,7 +1810,7 @@ UnwrapExpression : BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpressi...@@ -1810,7 +1810,7 @@ UnwrapExpression : BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpressi
1810UnwrapMaybe : "??" BoolOrExpression1810UnwrapMaybe : "??" BoolOrExpression
1811UnwrapError : "%%" option("|" "Symbol" "|") BoolOrExpression1811UnwrapError : "%%" option("|" "Symbol" "|") BoolOrExpression
1812*/1812*/
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) {
1814 AstNode *lhs = ast_parse_bool_or_expr(pc, token_index, mandatory);1814 AstNode *lhs = ast_parse_bool_or_expr(pc, token_index, mandatory);
1815 if (!lhs)1815 if (!lhs)
1816 return nullptr;1816 return nullptr;
...@@ -1853,7 +1853,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, int *token_index, bool m...@@ -1853,7 +1853,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, int *token_index, bool m
1853/*1853/*
1854AssignmentExpression : UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression1854AssignmentExpression : UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression
1855*/1855*/
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) {
1857 AstNode *lhs = ast_parse_unwrap_expr(pc, token_index, mandatory);1857 AstNode *lhs = ast_parse_unwrap_expr(pc, token_index, mandatory);
1858 if (!lhs)1858 if (!lhs)
1859 return nullptr;1859 return nullptr;
...@@ -1877,7 +1877,7 @@ static AstNode *ast_parse_ass_expr(ParseContext *pc, int *token_index, bool mand...@@ -1877,7 +1877,7 @@ static AstNode *ast_parse_ass_expr(ParseContext *pc, int *token_index, bool mand
1877/*1877/*
1878NonBlockExpression : ReturnExpression | AssignmentExpression1878NonBlockExpression : ReturnExpression | AssignmentExpression
1879*/1879*/
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) {
1881 Token *token = &pc->tokens->at(*token_index);1881 Token *token = &pc->tokens->at(*token_index);
18821882
1883 AstNode *return_expr = ast_parse_return_expr(pc, token_index);1883 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...@@ -1897,7 +1897,7 @@ static AstNode *ast_parse_non_block_expr(ParseContext *pc, int *token_index, boo
1897/*1897/*
1898Expression : BlockExpression | NonBlockExpression1898Expression : BlockExpression | NonBlockExpression
1899*/1899*/
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) {
1901 Token *token = &pc->tokens->at(*token_index);1901 Token *token = &pc->tokens->at(*token_index);
19021902
1903 AstNode *block_expr = ast_parse_block_expr(pc, token_index, false);1903 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...@@ -1917,7 +1917,7 @@ static AstNode *ast_parse_expression(ParseContext *pc, int *token_index, bool ma
1917/*1917/*
1918Label: token(Symbol) token(Colon)1918Label: token(Symbol) token(Colon)
1919*/1919*/
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) {
1921 Token *symbol_token = &pc->tokens->at(*token_index);1921 Token *symbol_token = &pc->tokens->at(*token_index);
1922 if (symbol_token->id != TokenIdSymbol) {1922 if (symbol_token->id != TokenIdSymbol) {
1923 if (mandatory) {1923 if (mandatory) {
...@@ -1956,7 +1956,7 @@ static AstNode *ast_create_void_expr(ParseContext *pc, Token *token) {...@@ -1956,7 +1956,7 @@ static AstNode *ast_create_void_expr(ParseContext *pc, Token *token) {
1956Block : token(LBrace) list(option(Statement), token(Semicolon)) token(RBrace)1956Block : token(LBrace) list(option(Statement), token(Semicolon)) token(RBrace)
1957Statement = Label | VariableDeclaration ";" | Defer ";" | NonBlockExpression ";" | BlockExpression1957Statement = Label | VariableDeclaration ";" | Defer ";" | NonBlockExpression ";" | BlockExpression
1958*/1958*/
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) {
1960 Token *last_token = &pc->tokens->at(*token_index);1960 Token *last_token = &pc->tokens->at(*token_index);
19611961
1962 if (last_token->id != TokenIdLBrace) {1962 if (last_token->id != TokenIdLBrace) {
...@@ -2021,7 +2021,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato...@@ -2021,7 +2021,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato
2021/*2021/*
2022FnProto = "fn" option("Symbol") ParamDeclList option("->" TypeExpr)2022FnProto = "fn" option("Symbol") ParamDeclList option("->" TypeExpr)
2023*/2023*/
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,
2025 ZigList<AstNode*> *directives, VisibMod visib_mod)2025 ZigList<AstNode*> *directives, VisibMod visib_mod)
2026{2026{
2027 Token *first_token = &pc->tokens->at(*token_index);2027 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...@@ -2064,7 +2064,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand
2064/*2064/*
2065FnDef = option("inline" | "extern") FnProto Block2065FnDef = option("inline" | "extern") FnProto Block
2066*/2066*/
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,
2068 ZigList<AstNode*> *directives, VisibMod visib_mod)2068 ZigList<AstNode*> *directives, VisibMod visib_mod)
2069{2069{
2070 Token *first_token = &pc->tokens->at(*token_index);2070 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...@@ -2111,7 +2111,7 @@ static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandat
2111/*2111/*
2112ExternDecl = "extern" (FnProto | VariableDeclaration) ";"2112ExternDecl = "extern" (FnProto | VariableDeclaration) ";"
2113*/2113*/
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,
2115 ZigList<AstNode *> *directives, VisibMod visib_mod)2115 ZigList<AstNode *> *directives, VisibMod visib_mod)
2116{2116{
2117 Token *extern_kw = &pc->tokens->at(*token_index);2117 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...@@ -2151,7 +2151,7 @@ static AstNode *ast_parse_extern_decl(ParseContext *pc, int *token_index, bool m
2151/*2151/*
2152UseDecl = "use" Expression ";"2152UseDecl = "use" Expression ";"
2153*/2153*/
2154static AstNode *ast_parse_use(ParseContext *pc, int *token_index,2154static AstNode *ast_parse_use(ParseContext *pc, size_t *token_index,
2155 ZigList<AstNode*> *directives, VisibMod visib_mod)2155 ZigList<AstNode*> *directives, VisibMod visib_mod)
2156{2156{
2157 Token *use_kw = &pc->tokens->at(*token_index);2157 Token *use_kw = &pc->tokens->at(*token_index);
...@@ -2175,7 +2175,7 @@ ContainerDecl = ("struct" | "enum" | "union") "Symbol" option(ParamDeclList) "{"...@@ -2175,7 +2175,7 @@ ContainerDecl = ("struct" | "enum" | "union") "Symbol" option(ParamDeclList) "{"
2175StructMember = many(Directive) option(VisibleMod) (StructField | FnDef | GlobalVarDecl | ContainerDecl)2175StructMember = many(Directive) option(VisibleMod) (StructField | FnDef | GlobalVarDecl | ContainerDecl)
2176StructField : "Symbol" option(":" Expression) ",")2176StructField : "Symbol" option(":" Expression) ",")
2177*/2177*/
2178static AstNode *ast_parse_container_decl(ParseContext *pc, int *token_index,2178static AstNode *ast_parse_container_decl(ParseContext *pc, size_t *token_index,
2179 ZigList<AstNode*> *directives, VisibMod visib_mod)2179 ZigList<AstNode*> *directives, VisibMod visib_mod)
2180{2180{
2181 Token *first_token = &pc->tokens->at(*token_index);2181 Token *first_token = &pc->tokens->at(*token_index);
...@@ -2289,7 +2289,7 @@ static AstNode *ast_parse_container_decl(ParseContext *pc, int *token_index,...@@ -2289,7 +2289,7 @@ static AstNode *ast_parse_container_decl(ParseContext *pc, int *token_index,
2289/*2289/*
2290ErrorValueDecl : "error" "Symbol" ";"2290ErrorValueDecl : "error" "Symbol" ";"
2291*/2291*/
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,
2293 ZigList<AstNode*> *directives, VisibMod visib_mod)2293 ZigList<AstNode*> *directives, VisibMod visib_mod)
2294{2294{
2295 Token *first_token = &pc->tokens->at(*token_index);2295 Token *first_token = &pc->tokens->at(*token_index);
...@@ -2314,7 +2314,7 @@ static AstNode *ast_parse_error_value_decl(ParseContext *pc, int *token_index,...@@ -2314,7 +2314,7 @@ static AstNode *ast_parse_error_value_decl(ParseContext *pc, int *token_index,
2314/*2314/*
2315TypeDecl = "type" "Symbol" "=" TypeExpr ";"2315TypeDecl = "type" "Symbol" "=" TypeExpr ";"
2316*/2316*/
2317static AstNode *ast_parse_type_decl(ParseContext *pc, int *token_index,2317static AstNode *ast_parse_type_decl(ParseContext *pc, size_t *token_index,
2318 ZigList<AstNode*> *directives, VisibMod visib_mod)2318 ZigList<AstNode*> *directives, VisibMod visib_mod)
2319{2319{
2320 Token *first_token = &pc->tokens->at(*token_index);2320 Token *first_token = &pc->tokens->at(*token_index);
...@@ -2343,7 +2343,7 @@ static AstNode *ast_parse_type_decl(ParseContext *pc, int *token_index,...@@ -2343,7 +2343,7 @@ static AstNode *ast_parse_type_decl(ParseContext *pc, int *token_index,
2343/*2343/*
2344TopLevelDecl = many(Directive) option(VisibleMod) (FnDef | ExternDecl | Import | ContainerDecl | GlobalVarDecl | ErrorValueDecl | CImportDecl | TypeDecl)2344TopLevelDecl = many(Directive) option(VisibleMod) (FnDef | ExternDecl | Import | ContainerDecl | GlobalVarDecl | ErrorValueDecl | CImportDecl | TypeDecl)
2345*/2345*/
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) {
2347 for (;;) {2347 for (;;) {
2348 Token *directive_token = &pc->tokens->at(*token_index);2348 Token *directive_token = &pc->tokens->at(*token_index);
2349 ZigList<AstNode *> *directives = allocate<ZigList<AstNode*>>(1);2349 ZigList<AstNode *> *directives = allocate<ZigList<AstNode*>>(1);
...@@ -2417,7 +2417,7 @@ static void ast_parse_top_level_decls(ParseContext *pc, int *token_index, ZigLis...@@ -2417,7 +2417,7 @@ static void ast_parse_top_level_decls(ParseContext *pc, int *token_index, ZigLis
2417/*2417/*
2418Root : many(TopLevelDecl) token(EOF)2418Root : many(TopLevelDecl) token(EOF)
2419 */2419 */
2420static AstNode *ast_parse_root(ParseContext *pc, int *token_index) {2420static AstNode *ast_parse_root(ParseContext *pc, size_t *token_index) {
2421 AstNode *node = ast_create_node(pc, NodeTypeRoot, &pc->tokens->at(*token_index));2421 AstNode *node = ast_create_node(pc, NodeTypeRoot, &pc->tokens->at(*token_index));
24222422
2423 ast_parse_top_level_decls(pc, token_index, &node->data.root.top_level_decls);2423 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,...@@ -2441,7 +2441,7 @@ AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner,
2441 pc.buf = buf;2441 pc.buf = buf;
2442 pc.tokens = tokens;2442 pc.tokens = tokens;
2443 pc.next_node_index = next_node_index;2443 pc.next_node_index = next_node_index;
2444 int token_index = 0;2444 size_t token_index = 0;
2445 pc.root = ast_parse_root(&pc, &token_index);2445 pc.root = ast_parse_root(&pc, &token_index);
2446 return pc.root;2446 return pc.root;
2447}2447}
...@@ -2454,7 +2454,7 @@ static void visit_field(AstNode **node, void (*visit)(AstNode **, void *context)...@@ -2454,7 +2454,7 @@ static void visit_field(AstNode **node, void (*visit)(AstNode **, void *context)
24542454
2455static void visit_node_list(ZigList<AstNode *> *list, void (*visit)(AstNode **, void *context), void *context) {2455static void visit_node_list(ZigList<AstNode *> *list, void (*visit)(AstNode **, void *context), void *context) {
2456 if (list) {2456 if (list) {
2457 for (int i = 0; i < list->length; i += 1) {2457 for (size_t i = 0; i < list->length; i += 1) {
2458 visit(&list->at(i), context);2458 visit(&list->at(i), context);
2459 }2459 }
2460 }2460 }
...@@ -2607,11 +2607,11 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont...@@ -2607,11 +2607,11 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
2607 // none2607 // none
2608 break;2608 break;
2609 case NodeTypeAsmExpr:2609 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) {
2611 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);2611 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
2612 visit_field(&asm_input->expr, visit, context);2612 visit_field(&asm_input->expr, visit, context);
2613 }2613 }
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) {
2615 AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);2615 AsmOutput *asm_output = node->data.asm_expr.output_list.at(i);
2616 visit_field(&asm_output->return_type, visit, context);2616 visit_field(&asm_output->return_type, visit, context);
2617 }2617 }
...@@ -2659,7 +2659,7 @@ void normalize_parent_ptrs(AstNode *node) {...@@ -2659,7 +2659,7 @@ void normalize_parent_ptrs(AstNode *node) {
2659static void clone_subtree_list(ZigList<AstNode *> *dest, ZigList<AstNode *> *src, uint32_t *next_node_index) {2659static void clone_subtree_list(ZigList<AstNode *> *dest, ZigList<AstNode *> *src, uint32_t *next_node_index) {
2660 memset(dest, 0, sizeof(ZigList<AstNode *>));2660 memset(dest, 0, sizeof(ZigList<AstNode *>));
2661 dest->resize(src->length);2661 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) {
2663 dest->at(i) = ast_clone_subtree(src->at(i), next_node_index);2663 dest->at(i) = ast_clone_subtree(src->at(i), next_node_index);
2664 dest->at(i)->parent_field = &dest->at(i);2664 dest->at(i)->parent_field = &dest->at(i);
2665 }2665 }
...@@ -2670,7 +2670,7 @@ static void clone_subtree_list_omit_inline_params(ZigList<AstNode *> *dest, ZigL...@@ -2670,7 +2670,7 @@ static void clone_subtree_list_omit_inline_params(ZigList<AstNode *> *dest, ZigL
2670{2670{
2671 memset(dest, 0, sizeof(ZigList<AstNode *>));2671 memset(dest, 0, sizeof(ZigList<AstNode *>));
2672 dest->ensure_capacity(src->length);2672 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) {
2674 AstNode *src_node = src->at(i);2674 AstNode *src_node = src->at(i);
2675 assert(src_node->type == NodeTypeParamDecl);2675 assert(src_node->type == NodeTypeParamDecl);
2676 if (src_node->data.param_decl.is_inline) {2676 if (src_node->data.param_decl.is_inline) {
...@@ -2712,7 +2712,7 @@ static void clone_subtree_tld(TopLevelDecl *dest, TopLevelDecl *src, uint32_t *n...@@ -2712,7 +2712,7 @@ static void clone_subtree_tld(TopLevelDecl *dest, TopLevelDecl *src, uint32_t *n
27122712
2713AstNode *ast_clone_subtree_special(AstNode *old_node, uint32_t *next_node_index, enum AstCloneSpecial special) {2713AstNode *ast_clone_subtree_special(AstNode *old_node, uint32_t *next_node_index, enum AstCloneSpecial special) {
2714 AstNode *new_node = allocate_nonzero<AstNode>(1);2714 AstNode *new_node = allocate_nonzero<AstNode>(1);
2715 memcpy(new_node, old_node, sizeof(AstNode));2715 safe_memcpy(new_node, old_node, 1);
2716 new_node->create_index = *next_node_index;2716 new_node->create_index = *next_node_index;
2717 *next_node_index += 1;2717 *next_node_index += 1;
2718 new_node->parent_field = nullptr;2718 new_node->parent_field = nullptr;
src/target.cpp+8-8
...@@ -156,7 +156,7 @@ static const ZigLLVM_ObjectFormatType oformat_list[] = {...@@ -156,7 +156,7 @@ static const ZigLLVM_ObjectFormatType oformat_list[] = {
156 ZigLLVM_MachO,156 ZigLLVM_MachO,
157};157};
158158
159int target_oformat_count(void) {159size_t target_oformat_count(void) {
160 return array_length(oformat_list);160 return array_length(oformat_list);
161}161}
162162
...@@ -174,7 +174,7 @@ const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat) {...@@ -174,7 +174,7 @@ const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat) {
174 zig_unreachable();174 zig_unreachable();
175}175}
176176
177int target_arch_count(void) {177size_t target_arch_count(void) {
178 return array_length(arch_list);178 return array_length(arch_list);
179}179}
180180
...@@ -182,7 +182,7 @@ const ArchType *get_target_arch(int index) {...@@ -182,7 +182,7 @@ const ArchType *get_target_arch(int index) {
182 return &arch_list[index];182 return &arch_list[index];
183}183}
184184
185int target_vendor_count(void) {185size_t target_vendor_count(void) {
186 return array_length(vendor_list);186 return array_length(vendor_list);
187}187}
188188
...@@ -190,7 +190,7 @@ ZigLLVM_VendorType get_target_vendor(int index) {...@@ -190,7 +190,7 @@ ZigLLVM_VendorType get_target_vendor(int index) {
190 return vendor_list[index];190 return vendor_list[index];
191}191}
192192
193int target_os_count(void) {193size_t target_os_count(void) {
194 return array_length(os_list);194 return array_length(os_list);
195}195}
196ZigLLVM_OSType get_target_os(int index) {196ZigLLVM_OSType get_target_os(int index) {
...@@ -201,7 +201,7 @@ const char *get_target_os_name(ZigLLVM_OSType os_type) {...@@ -201,7 +201,7 @@ const char *get_target_os_name(ZigLLVM_OSType os_type) {
201 return (os_type == ZigLLVM_UnknownOS) ? "freestanding" : ZigLLVMGetOSTypeName(os_type);201 return (os_type == ZigLLVM_UnknownOS) ? "freestanding" : ZigLLVMGetOSTypeName(os_type);
202}202}
203203
204int target_environ_count(void) {204size_t target_environ_count(void) {
205 return array_length(environ_list);205 return array_length(environ_list);
206}206}
207ZigLLVM_EnvironmentType get_target_environ(int index) {207ZigLLVM_EnvironmentType get_target_environ(int index) {
...@@ -237,7 +237,7 @@ void get_arch_name(char *out_str, const ArchType *arch) {...@@ -237,7 +237,7 @@ void get_arch_name(char *out_str, const ArchType *arch) {
237}237}
238238
239int parse_target_arch(const char *str, ArchType *out_arch) {239int 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) {
241 const ArchType *arch = &arch_list[i];241 const ArchType *arch = &arch_list[i];
242 char arch_name[50];242 char arch_name[50];
243 get_arch_name_raw(arch_name, arch->arch, arch->sub_arch);243 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) {...@@ -250,7 +250,7 @@ int parse_target_arch(const char *str, ArchType *out_arch) {
250}250}
251251
252int parse_target_os(const char *str, ZigLLVM_OSType *out_os) {252int 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) {
254 ZigLLVM_OSType os = os_list[i];254 ZigLLVM_OSType os = os_list[i];
255 const char *os_name = get_target_os_name(os);255 const char *os_name = get_target_os_name(os);
256 if (strcmp(os_name, str) == 0) {256 if (strcmp(os_name, str) == 0) {
...@@ -262,7 +262,7 @@ int parse_target_os(const char *str, ZigLLVM_OSType *out_os) {...@@ -262,7 +262,7 @@ int parse_target_os(const char *str, ZigLLVM_OSType *out_os) {
262}262}
263263
264int parse_target_environ(const char *str, ZigLLVM_EnvironmentType *out_environ) {264int 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) {
266 ZigLLVM_EnvironmentType env_type = environ_list[i];266 ZigLLVM_EnvironmentType env_type = environ_list[i];
267 const char *environ_name = ZigLLVMGetEnvironmentTypeName(env_type);267 const char *environ_name = ZigLLVMGetEnvironmentTypeName(env_type);
268 if (strcmp(environ_name, str) == 0) {268 if (strcmp(environ_name, str) == 0) {
src/target.hpp+5-5
...@@ -38,22 +38,22 @@ enum CIntType {...@@ -38,22 +38,22 @@ enum CIntType {
38 CIntTypeCount,38 CIntTypeCount,
39};39};
4040
41int target_arch_count(void);41size_t target_arch_count(void);
42const ArchType *get_target_arch(int index);42const ArchType *get_target_arch(int index);
43void get_arch_name(char *out_str, const ArchType *arch);43void get_arch_name(char *out_str, const ArchType *arch);
4444
45int target_vendor_count(void);45size_t target_vendor_count(void);
46ZigLLVM_VendorType get_target_vendor(int index);46ZigLLVM_VendorType get_target_vendor(int index);
4747
48int target_os_count(void);48size_t target_os_count(void);
49ZigLLVM_OSType get_target_os(int index);49ZigLLVM_OSType get_target_os(int index);
50const char *get_target_os_name(ZigLLVM_OSType os_type);50const char *get_target_os_name(ZigLLVM_OSType os_type);
5151
52int target_environ_count(void);52size_t target_environ_count(void);
53ZigLLVM_EnvironmentType get_target_environ(int index);53ZigLLVM_EnvironmentType get_target_environ(int index);
5454
5555
56int target_oformat_count(void);56size_t target_oformat_count(void);
57const ZigLLVM_ObjectFormatType get_target_oformat(int index);57const ZigLLVM_ObjectFormatType get_target_oformat(int index);
58const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat);58const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat);
5959
src/tokenizer.cpp+6-6
...@@ -141,7 +141,7 @@ static const struct ZigKeyword zig_keywords[] = {...@@ -141,7 +141,7 @@ static const struct ZigKeyword zig_keywords[] = {
141};141};
142142
143bool is_zig_keyword(Buf *buf) {143bool 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) {
145 if (buf_eql_str(buf, zig_keywords[i].text)) {145 if (buf_eql_str(buf, zig_keywords[i].text)) {
146 return true;146 return true;
147 }147 }
...@@ -209,7 +209,7 @@ enum TokenizeState {...@@ -209,7 +209,7 @@ enum TokenizeState {
209209
210struct Tokenize {210struct Tokenize {
211 Buf *buf;211 Buf *buf;
212 int pos;212 size_t pos;
213 TokenizeState state;213 TokenizeState state;
214 ZigList<Token> *tokens;214 ZigList<Token> *tokens;
215 int line;215 int line;
...@@ -329,7 +329,7 @@ static void end_float_token(Tokenize *t) {...@@ -329,7 +329,7 @@ static void end_float_token(Tokenize *t) {
329 }329 }
330 }330 }
331 uint64_t double_bits = (exponent_bits << 52) | significand_bits;331 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);
333}333}
334334
335static void end_token(Tokenize *t) {335static void end_token(Tokenize *t) {
...@@ -397,7 +397,7 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -397,7 +397,7 @@ void tokenize(Buf *buf, Tokenization *out) {
397 t.tokens = out->tokens = allocate<ZigList<Token>>(1);397 t.tokens = out->tokens = allocate<ZigList<Token>>(1);
398 t.buf = buf;398 t.buf = buf;
399399
400 out->line_offsets = allocate<ZigList<int>>(1);400 out->line_offsets = allocate<ZigList<size_t>>(1);
401401
402 out->line_offsets->append(0);402 out->line_offsets->append(0);
403 for (t.pos = 0; t.pos < buf_len(t.buf); t.pos += 1) {403 for (t.pos = 0; t.pos < buf_len(t.buf); t.pos += 1) {
...@@ -1545,10 +1545,10 @@ const char * token_name(TokenId id) {...@@ -1545,10 +1545,10 @@ const char * token_name(TokenId id) {
1545}1545}
15461546
1547void print_tokens(Buf *buf, ZigList<Token> *tokens) {1547void 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) {
1549 Token *token = &tokens->at(i);1549 Token *token = &tokens->at(i);
1550 fprintf(stderr, "%s ", token_name(token->id));1550 fprintf(stderr, "%s ", token_name(token->id));
1551 if (token->start_pos >= 0) {1551 if (token->start_pos != SIZE_MAX) {
1552 fwrite(buf_ptr(buf) + token->start_pos, 1, token->end_pos - token->start_pos, stderr);1552 fwrite(buf_ptr(buf) + token->start_pos, 1, token->end_pos - token->start_pos, stderr);
1553 }1553 }
1554 fprintf(stderr, "\n");1554 fprintf(stderr, "\n");
src/tokenizer.hpp+7-7
...@@ -131,10 +131,10 @@ struct TokenCharLit {...@@ -131,10 +131,10 @@ struct TokenCharLit {
131131
132struct Token {132struct Token {
133 TokenId id;133 TokenId id;
134 int start_pos;134 size_t start_pos;
135 int end_pos;135 size_t end_pos;
136 int start_line;136 size_t start_line;
137 int start_column;137 size_t start_column;
138138
139 union {139 union {
140 // TokenIdNumberLiteral140 // TokenIdNumberLiteral
...@@ -150,12 +150,12 @@ struct Token {...@@ -150,12 +150,12 @@ struct Token {
150150
151struct Tokenization {151struct Tokenization {
152 ZigList<Token> *tokens;152 ZigList<Token> *tokens;
153 ZigList<int> *line_offsets;153 ZigList<size_t> *line_offsets;
154154
155 // if an error occurred155 // if an error occurred
156 Buf *err;156 Buf *err;
157 int err_line;157 size_t err_line;
158 int err_column;158 size_t err_column;
159};159};
160160
161void tokenize(Buf *buf, Tokenization *out_tokenization);161void tokenize(Buf *buf, Tokenization *out_tokenization);
src/util.hpp+23-3
...@@ -45,15 +45,35 @@ __attribute__((malloc)) static inline T *allocate(size_t count) {...@@ -45,15 +45,35 @@ __attribute__((malloc)) static inline T *allocate(size_t count) {
45}45}
4646
47template<typename T>47template<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
49 T *ptr = reinterpret_cast<T*>(realloc(old, new_count * sizeof(T)));62 T *ptr = reinterpret_cast<T*>(realloc(old, new_count * sizeof(T)));
50 if (!ptr)63 if (!ptr)
51 zig_panic("allocation failed");64 zig_panic("allocation failed");
52 return ptr;65 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
53}73}
5474
55template <typename T, long n>75template <typename T, size_t n>
56constexpr long array_length(const T (&)[n]) {76constexpr size_t array_length(const T (&)[n]) {
57 return n;77 return n;
58}78}
5979
std/list.zig+3-4
...@@ -42,15 +42,14 @@ pub struct SmallList(T: type, static_size: usize) {...@@ -42,15 +42,14 @@ pub struct SmallList(T: type, static_size: usize) {
42 }42 }
4343
44 pub fn ensureCapacity(l: &Self, new_capacity: usize) -> %void {44 pub fn ensureCapacity(l: &Self, new_capacity: usize) -> %void {
45 const old_capacity = l.items.len;45 var better_capacity = l.items.len;
46 var better_capacity = old_capacity;
47 while (better_capacity < new_capacity) {46 while (better_capacity < new_capacity) {
48 better_capacity *= 2;47 better_capacity *= 2;
49 }48 }
50 if (better_capacity != old_capacity) {49 if (better_capacity != l.items.len) {
51 if (l.items.ptr == &l.prealloc_items[0]) {50 if (l.items.ptr == &l.prealloc_items[0]) {
52 l.items = %return l.allocator.alloc(T, better_capacity);51 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]);
54 } else {53 } else {
55 l.items = %return l.allocator.realloc(T, l.items, better_capacity);54 l.items = %return l.allocator.realloc(T, l.items, better_capacity);
56 }55 }
test/run_tests.cpp+18-16
...@@ -93,7 +93,7 @@ static TestCase *add_simple_case_libc(const char *case_name, const char *source,...@@ -93,7 +93,7 @@ static TestCase *add_simple_case_libc(const char *case_name, const char *source,
93 return tc;93 return tc;
94}94}
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, ...) {
97 va_list ap;97 va_list ap;
98 va_start(ap, count);98 va_start(ap, count);
9999
...@@ -103,7 +103,7 @@ static TestCase *add_compile_fail_case(const char *case_name, const char *source...@@ -103,7 +103,7 @@ static TestCase *add_compile_fail_case(const char *case_name, const char *source
103 test_case->source_files.at(0).relative_path = tmp_source_path;103 test_case->source_files.at(0).relative_path = tmp_source_path;
104 test_case->source_files.at(0).source_code = source;104 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) {
107 const char *arg = va_arg(ap, const char *);107 const char *arg = va_arg(ap, const char *);
108 test_case->compile_errors.append(arg);108 test_case->compile_errors.append(arg);
109 }109 }
...@@ -181,7 +181,7 @@ static void add_debug_safety_case(const char *case_name, const char *source) {...@@ -181,7 +181,7 @@ static void add_debug_safety_case(const char *case_name, const char *source) {
181}181}
182182
183static TestCase *add_parseh_case(const char *case_name, AllowWarnings allow_warnings,183static TestCase *add_parseh_case(const char *case_name, AllowWarnings allow_warnings,
184 const char *source, int count, ...)184 const char *source, size_t count, ...)
185{185{
186 va_list ap;186 va_list ap;
187 va_start(ap, count);187 va_start(ap, count);
...@@ -195,7 +195,7 @@ static TestCase *add_parseh_case(const char *case_name, AllowWarnings allow_warn...@@ -195,7 +195,7 @@ static TestCase *add_parseh_case(const char *case_name, AllowWarnings allow_warn
195 test_case->source_files.at(0).relative_path = tmp_h_path;195 test_case->source_files.at(0).relative_path = tmp_h_path;
196 test_case->source_files.at(0).source_code = source;196 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) {
199 const char *arg = va_arg(ap, const char *);199 const char *arg = va_arg(ap, const char *);
200 test_case->compile_errors.append(arg);200 test_case->compile_errors.append(arg);
201 }201 }
...@@ -1854,7 +1854,7 @@ static void run_self_hosted_test(bool is_release_mode) {...@@ -1854,7 +1854,7 @@ static void run_self_hosted_test(bool is_release_mode) {
1854 if (term.how != TerminationIdClean || term.code != 0) {1854 if (term.how != TerminationIdClean || term.code != 0) {
1855 printf("\nSelf-hosted tests failed:\n");1855 printf("\nSelf-hosted tests failed:\n");
1856 printf("./zig");1856 printf("./zig");
1857 for (int i = 0; i < args.length; i += 1) {1857 for (size_t i = 0; i < args.length; i += 1) {
1858 printf(" %s", args.at(i));1858 printf(" %s", args.at(i));
1859 }1859 }
1860 printf("\n%s\n", buf_ptr(&zig_stderr));1860 printf("\n%s\n", buf_ptr(&zig_stderr));
...@@ -1881,7 +1881,7 @@ static void add_self_hosted_tests(void) {...@@ -1881,7 +1881,7 @@ static void add_self_hosted_tests(void) {
18811881
1882static void print_compiler_invocation(TestCase *test_case) {1882static void print_compiler_invocation(TestCase *test_case) {
1883 printf("%s", zig_exe);1883 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) {
1885 printf(" %s", test_case->compiler_args.at(i));1885 printf(" %s", test_case->compiler_args.at(i));
1886 }1886 }
1887 printf("\n");1887 printf("\n");
...@@ -1889,7 +1889,7 @@ static void print_compiler_invocation(TestCase *test_case) {...@@ -1889,7 +1889,7 @@ static void print_compiler_invocation(TestCase *test_case) {
18891889
1890static void print_exe_invocation(TestCase *test_case) {1890static void print_exe_invocation(TestCase *test_case) {
1891 printf("%s", tmp_exe_path);1891 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) {
1893 printf(" %s", test_case->program_args.at(i));1893 printf(" %s", test_case->program_args.at(i));
1894 }1894 }
1895 printf("\n");1895 printf("\n");
...@@ -1900,7 +1900,7 @@ static void run_test(TestCase *test_case) {...@@ -1900,7 +1900,7 @@ static void run_test(TestCase *test_case) {
1900 return run_self_hosted_test(test_case->is_release_mode);1900 return run_self_hosted_test(test_case->is_release_mode);
1901 }1901 }
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) {
1904 TestSourceFile *test_source = &test_case->source_files.at(i);1904 TestSourceFile *test_source = &test_case->source_files.at(i);
1905 os_write_file(1905 os_write_file(
1906 buf_create_from_str(test_source->relative_path),1906 buf_create_from_str(test_source->relative_path),
...@@ -1917,7 +1917,7 @@ static void run_test(TestCase *test_case) {...@@ -1917,7 +1917,7 @@ static void run_test(TestCase *test_case) {
19171917
1918 if (!test_case->is_parseh && test_case->compile_errors.length) {1918 if (!test_case->is_parseh && test_case->compile_errors.length) {
1919 if (term.how != TerminationIdClean || term.code != 0) {1919 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) {
1921 const char *err_text = test_case->compile_errors.at(i);1921 const char *err_text = test_case->compile_errors.at(i);
1922 if (!strstr(buf_ptr(&zig_stderr), err_text)) {1922 if (!strstr(buf_ptr(&zig_stderr), err_text)) {
1923 printf("\n");1923 printf("\n");
...@@ -1957,7 +1957,7 @@ static void run_test(TestCase *test_case) {...@@ -1957,7 +1957,7 @@ static void run_test(TestCase *test_case) {
1957 }1957 }
1958 }1958 }
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) {
1961 const char *output = test_case->compile_errors.at(i);1961 const char *output = test_case->compile_errors.at(i);
19621962
1963 if (!strstr(buf_ptr(&zig_stdout), output)) {1963 if (!strstr(buf_ptr(&zig_stdout), output)) {
...@@ -2015,7 +2015,7 @@ static void run_test(TestCase *test_case) {...@@ -2015,7 +2015,7 @@ static void run_test(TestCase *test_case) {
2015 }2015 }
2016 }2016 }
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) {
2019 TestSourceFile *test_source = &test_case->source_files.at(i);2019 TestSourceFile *test_source = &test_case->source_files.at(i);
2020 remove(test_source->relative_path);2020 remove(test_source->relative_path);
2021 }2021 }
...@@ -2023,21 +2023,23 @@ static void run_test(TestCase *test_case) {...@@ -2023,21 +2023,23 @@ static void run_test(TestCase *test_case) {
20232023
2024static void run_all_tests(bool reverse) {2024static void run_all_tests(bool reverse) {
2025 if (reverse) {2025 if (reverse) {
2026 for (int i = test_cases.length - 1; i >= 0; i -= 1) {2026 for (size_t i = test_cases.length;;) {
2027 TestCase *test_case = test_cases.at(i);2027 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);
2029 run_test(test_case);2029 run_test(test_case);
2030 printf("OK\n");2030 printf("OK\n");
2031 if (i == 0) break;
2032 i -= 1;
2031 }2033 }
2032 } else {2034 } else {
2033 for (int i = 0; i < test_cases.length; i += 1) {2035 for (size_t i = 0; i < test_cases.length; i += 1) {
2034 TestCase *test_case = test_cases.at(i);2036 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);
2036 run_test(test_case);2038 run_test(test_case);
2037 printf("OK\n");2039 printf("OK\n");
2038 }2040 }
2039 }2041 }
2040 printf("%d tests passed.\n", test_cases.length);2042 printf("%zu tests passed.\n", test_cases.length);
2041}2043}
20422044
2043static void cleanup(void) {2045static void cleanup(void) {