| author | |
| committer | |
| log | bf57d8a7e3beb8d69dec38e131a3717f008f6c5e |
| tree | 1559356eda32fa631d1bac1de5efb5dcf7be0d48 |
| parent | bf67427c67dac00ca10ed7423ae8d99e2901262f |
closes #31414 files changed, 334 insertions(+), 620 deletions(-)
doc/langref.md+2-4| ... | ... | @@ -9,9 +9,7 @@ TopLevelItem = ErrorValueDecl | CompTimeExpression(Block) | TopLevelDecl | TestD |
| 9 | 9 | |
| 10 | 10 | TestDecl = "test" String Block |
| 11 | 11 | |
| 12 | TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | TypeDecl | UseDecl) | |
| 13 | ||
| 14 | TypeDecl = "type" Symbol "=" TypeExpr ";" | |
| 12 | TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | UseDecl) | |
| 15 | 13 | |
| 16 | 14 | ErrorValueDecl = "error" Symbol ";" |
| 17 | 15 | |
| ... | ... | @@ -155,7 +153,7 @@ GotoExpression = "goto" Symbol |
| 155 | 153 | |
| 156 | 154 | GroupedExpression = "(" Expression ")" |
| 157 | 155 | |
| 158 | KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this" | "unreachable" | |
| 156 | KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "this" | "unreachable" | |
| 159 | 157 | |
| 160 | 158 | ContainerDecl = option("extern" | "packed") ("struct" | "enum" | "union") "{" many(ContainerMember) "}" |
| 161 | 159 | ``` |
src/all_types.hpp+1-27| ... | ... | @@ -254,7 +254,6 @@ enum TldId { |
| 254 | 254 | TldIdVar, |
| 255 | 255 | TldIdFn, |
| 256 | 256 | TldIdContainer, |
| 257 | TldIdTypeDef, | |
| 258 | 257 | TldIdCompTime, |
| 259 | 258 | }; |
| 260 | 259 | |
| ... | ... | @@ -303,12 +302,6 @@ struct TldContainer { |
| 303 | 302 | TypeTableEntry *type_entry; |
| 304 | 303 | }; |
| 305 | 304 | |
| 306 | struct TldTypeDef { | |
| 307 | Tld base; | |
| 308 | ||
| 309 | TypeTableEntry *type_entry; | |
| 310 | }; | |
| 311 | ||
| 312 | 305 | struct TldCompTime { |
| 313 | 306 | Tld base; |
| 314 | 307 | }; |
| ... | ... | @@ -330,7 +323,6 @@ enum NodeType { |
| 330 | 323 | NodeTypeReturnExpr, |
| 331 | 324 | NodeTypeDefer, |
| 332 | 325 | NodeTypeVariableDeclaration, |
| 333 | NodeTypeTypeDecl, | |
| 334 | 326 | NodeTypeErrorValueDecl, |
| 335 | 327 | NodeTypeTestDecl, |
| 336 | 328 | NodeTypeBinOpExpr, |
| ... | ... | @@ -369,7 +361,6 @@ enum NodeType { |
| 369 | 361 | NodeTypeStructValueField, |
| 370 | 362 | NodeTypeArrayType, |
| 371 | 363 | NodeTypeErrorType, |
| 372 | NodeTypeTypeLiteral, | |
| 373 | 364 | NodeTypeVarLiteral, |
| 374 | 365 | NodeTypeTryExpr, |
| 375 | 366 | NodeTypeInlineExpr, |
| ... | ... | @@ -448,12 +439,6 @@ struct AstNodeVariableDeclaration { |
| 448 | 439 | AstNode *expr; |
| 449 | 440 | }; |
| 450 | 441 | |
| 451 | struct AstNodeTypeDecl { | |
| 452 | VisibMod visib_mod; | |
| 453 | Buf *symbol; | |
| 454 | AstNode *child_type; | |
| 455 | }; | |
| 456 | ||
| 457 | 442 | struct AstNodeErrorValueDecl { |
| 458 | 443 | Buf *name; |
| 459 | 444 | |
| ... | ... | @@ -790,9 +775,6 @@ struct AstNodeArrayType { |
| 790 | 775 | struct AstNodeErrorType { |
| 791 | 776 | }; |
| 792 | 777 | |
| 793 | struct AstNodeTypeLiteral { | |
| 794 | }; | |
| 795 | ||
| 796 | 778 | struct AstNodeVarLiteral { |
| 797 | 779 | }; |
| 798 | 780 | |
| ... | ... | @@ -816,7 +798,6 @@ struct AstNode { |
| 816 | 798 | AstNodeReturnExpr return_expr; |
| 817 | 799 | AstNodeDefer defer; |
| 818 | 800 | AstNodeVariableDeclaration variable_declaration; |
| 819 | AstNodeTypeDecl type_decl; | |
| 820 | 801 | AstNodeErrorValueDecl error_value_decl; |
| 821 | 802 | AstNodeTestDecl test_decl; |
| 822 | 803 | AstNodeBinOpExpr bin_op_expr; |
| ... | ... | @@ -856,7 +837,6 @@ struct AstNode { |
| 856 | 837 | AstNodeUnreachableExpr unreachable_expr; |
| 857 | 838 | AstNodeArrayType array_type; |
| 858 | 839 | AstNodeErrorType error_type; |
| 859 | AstNodeTypeLiteral type_literal; | |
| 860 | 840 | AstNodeVarLiteral var_literal; |
| 861 | 841 | AstNodeInlineExpr inline_expr; |
| 862 | 842 | } data; |
| ... | ... | @@ -1026,11 +1006,6 @@ struct TypeTableEntryBoundFn { |
| 1026 | 1006 | TypeTableEntry *fn_type; |
| 1027 | 1007 | }; |
| 1028 | 1008 | |
| 1029 | struct TypeTableEntryTypeDecl { | |
| 1030 | TypeTableEntry *child_type; | |
| 1031 | TypeTableEntry *canonical_type; | |
| 1032 | }; | |
| 1033 | ||
| 1034 | 1009 | enum TypeTableEntryId { |
| 1035 | 1010 | TypeTableEntryIdInvalid, |
| 1036 | 1011 | TypeTableEntryIdVar, |
| ... | ... | @@ -1054,11 +1029,11 @@ enum TypeTableEntryId { |
| 1054 | 1029 | TypeTableEntryIdEnumTag, |
| 1055 | 1030 | TypeTableEntryIdUnion, |
| 1056 | 1031 | TypeTableEntryIdFn, |
| 1057 | TypeTableEntryIdTypeDecl, | |
| 1058 | 1032 | TypeTableEntryIdNamespace, |
| 1059 | 1033 | TypeTableEntryIdBlock, |
| 1060 | 1034 | TypeTableEntryIdBoundFn, |
| 1061 | 1035 | TypeTableEntryIdArgTuple, |
| 1036 | TypeTableEntryIdOpaque, | |
| 1062 | 1037 | }; |
| 1063 | 1038 | |
| 1064 | 1039 | struct TypeTableEntry { |
| ... | ... | @@ -1083,7 +1058,6 @@ struct TypeTableEntry { |
| 1083 | 1058 | TypeTableEntryEnumTag enum_tag; |
| 1084 | 1059 | TypeTableEntryUnion unionation; |
| 1085 | 1060 | TypeTableEntryFn fn; |
| 1086 | TypeTableEntryTypeDecl type_decl; | |
| 1087 | 1061 | TypeTableEntryBoundFn bound_fn; |
| 1088 | 1062 | } data; |
| 1089 | 1063 |
src/analyze.cpp+76-114| ... | ... | @@ -186,6 +186,8 @@ bool type_is_complete(TypeTableEntry *type_entry) { |
| 186 | 186 | return type_entry->data.enumeration.complete; |
| 187 | 187 | case TypeTableEntryIdUnion: |
| 188 | 188 | return type_entry->data.unionation.complete; |
| 189 | case TypeTableEntryIdOpaque: | |
| 190 | return false; | |
| 189 | 191 | case TypeTableEntryIdMetaType: |
| 190 | 192 | case TypeTableEntryIdVoid: |
| 191 | 193 | case TypeTableEntryIdBool: |
| ... | ... | @@ -202,7 +204,6 @@ bool type_is_complete(TypeTableEntry *type_entry) { |
| 202 | 204 | case TypeTableEntryIdErrorUnion: |
| 203 | 205 | case TypeTableEntryIdPureError: |
| 204 | 206 | case TypeTableEntryIdFn: |
| 205 | case TypeTableEntryIdTypeDecl: | |
| 206 | 207 | case TypeTableEntryIdNamespace: |
| 207 | 208 | case TypeTableEntryIdBlock: |
| 208 | 209 | case TypeTableEntryIdBoundFn: |
| ... | ... | @@ -240,12 +241,12 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) { |
| 240 | 241 | case TypeTableEntryIdErrorUnion: |
| 241 | 242 | case TypeTableEntryIdPureError: |
| 242 | 243 | case TypeTableEntryIdFn: |
| 243 | case TypeTableEntryIdTypeDecl: | |
| 244 | 244 | case TypeTableEntryIdNamespace: |
| 245 | 245 | case TypeTableEntryIdBlock: |
| 246 | 246 | case TypeTableEntryIdBoundFn: |
| 247 | 247 | case TypeTableEntryIdEnumTag: |
| 248 | 248 | case TypeTableEntryIdArgTuple: |
| 249 | case TypeTableEntryIdOpaque: | |
| 249 | 250 | return true; |
| 250 | 251 | } |
| 251 | 252 | zig_unreachable(); |
| ... | ... | @@ -254,18 +255,17 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) { |
| 254 | 255 | |
| 255 | 256 | uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) { |
| 256 | 257 | assert(type_is_complete(type_entry)); |
| 257 | TypeTableEntry *canon_type = get_underlying_type(type_entry); | |
| 258 | 258 | |
| 259 | 259 | if (!type_has_bits(type_entry)) |
| 260 | 260 | return 0; |
| 261 | 261 | |
| 262 | if (canon_type->id == TypeTableEntryIdStruct && canon_type->data.structure.layout == ContainerLayoutPacked) { | |
| 262 | if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) { | |
| 263 | 263 | uint64_t size_in_bits = type_size_bits(g, type_entry); |
| 264 | 264 | return (size_in_bits + 7) / 8; |
| 265 | } else if (canon_type->id == TypeTableEntryIdArray) { | |
| 266 | TypeTableEntry *canon_child_type = get_underlying_type(canon_type->data.array.child_type); | |
| 267 | if (canon_child_type->id == TypeTableEntryIdStruct && | |
| 268 | canon_child_type->data.structure.layout == ContainerLayoutPacked) | |
| 265 | } else if (type_entry->id == TypeTableEntryIdArray) { | |
| 266 | TypeTableEntry *child_type = type_entry->data.array.child_type; | |
| 267 | if (child_type->id == TypeTableEntryIdStruct && | |
| 268 | child_type->data.structure.layout == ContainerLayoutPacked) | |
| 269 | 269 | { |
| 270 | 270 | uint64_t size_in_bits = type_size_bits(g, type_entry); |
| 271 | 271 | return (size_in_bits + 7) / 8; |
| ... | ... | @@ -277,27 +277,26 @@ uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) { |
| 277 | 277 | |
| 278 | 278 | uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) { |
| 279 | 279 | assert(type_is_complete(type_entry)); |
| 280 | TypeTableEntry *canon_type = get_underlying_type(type_entry); | |
| 281 | 280 | |
| 282 | 281 | if (!type_has_bits(type_entry)) |
| 283 | 282 | return 0; |
| 284 | 283 | |
| 285 | if (canon_type->id == TypeTableEntryIdStruct && canon_type->data.structure.layout == ContainerLayoutPacked) { | |
| 284 | if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) { | |
| 286 | 285 | uint64_t result = 0; |
| 287 | for (size_t i = 0; i < canon_type->data.structure.src_field_count; i += 1) { | |
| 288 | result += type_size_bits(g, canon_type->data.structure.fields[i].type_entry); | |
| 286 | for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { | |
| 287 | result += type_size_bits(g, type_entry->data.structure.fields[i].type_entry); | |
| 289 | 288 | } |
| 290 | 289 | return result; |
| 291 | } else if (canon_type->id == TypeTableEntryIdArray) { | |
| 292 | TypeTableEntry *canon_child_type = get_underlying_type(canon_type->data.array.child_type); | |
| 293 | if (canon_child_type->id == TypeTableEntryIdStruct && | |
| 294 | canon_child_type->data.structure.layout == ContainerLayoutPacked) | |
| 290 | } else if (type_entry->id == TypeTableEntryIdArray) { | |
| 291 | TypeTableEntry *child_type = type_entry->data.array.child_type; | |
| 292 | if (child_type->id == TypeTableEntryIdStruct && | |
| 293 | child_type->data.structure.layout == ContainerLayoutPacked) | |
| 295 | 294 | { |
| 296 | return canon_type->data.array.len * type_size_bits(g, canon_child_type); | |
| 295 | return type_entry->data.array.len * type_size_bits(g, child_type); | |
| 297 | 296 | } |
| 298 | 297 | } |
| 299 | 298 | |
| 300 | return LLVMSizeOfTypeInBits(g->target_data_ref, canon_type->type_ref); | |
| 299 | return LLVMSizeOfTypeInBits(g->target_data_ref, type_entry->type_ref); | |
| 301 | 300 | } |
| 302 | 301 | |
| 303 | 302 | static bool type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) { |
| ... | ... | @@ -360,10 +359,9 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type |
| 360 | 359 | bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name)); |
| 361 | 360 | } |
| 362 | 361 | |
| 363 | TypeTableEntry *canon_child_type = get_underlying_type(child_type); | |
| 364 | assert(canon_child_type->id != TypeTableEntryIdInvalid); | |
| 362 | assert(child_type->id != TypeTableEntryIdInvalid); | |
| 365 | 363 | |
| 366 | entry->zero_bits = !type_has_bits(canon_child_type); | |
| 364 | entry->zero_bits = !type_has_bits(child_type); | |
| 367 | 365 | |
| 368 | 366 | if (!entry->zero_bits) { |
| 369 | 367 | entry->type_ref = LLVMPointerType(child_type->type_ref, 0); |
| ... | ... | @@ -766,17 +764,22 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c |
| 766 | 764 | } |
| 767 | 765 | } |
| 768 | 766 | |
| 769 | TypeTableEntry *get_typedecl_type(CodeGen *g, const char *name, TypeTableEntry *child_type) { | |
| 770 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdTypeDecl); | |
| 767 | TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) { | |
| 768 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOpaque); | |
| 771 | 769 | |
| 772 | 770 | buf_init_from_str(&entry->name, name); |
| 773 | 771 | |
| 774 | entry->is_copyable = type_is_copyable(g, child_type); | |
| 775 | entry->type_ref = child_type->type_ref; | |
| 776 | entry->di_type = child_type->di_type; | |
| 777 | entry->zero_bits = child_type->zero_bits; | |
| 778 | entry->data.type_decl.child_type = child_type; | |
| 779 | entry->data.type_decl.canonical_type = get_underlying_type(child_type); | |
| 772 | ImportTableEntry *import = scope ? get_scope_import(scope) : nullptr; | |
| 773 | unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0; | |
| 774 | ||
| 775 | entry->is_copyable = false; | |
| 776 | entry->type_ref = LLVMInt8Type(); | |
| 777 | entry->di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder, | |
| 778 | ZigLLVMTag_DW_structure_type(), buf_ptr(&entry->name), | |
| 779 | import ? ZigLLVMFileToScope(import->di_file) : nullptr, | |
| 780 | import ? import->di_file : nullptr, | |
| 781 | line); | |
| 782 | entry->zero_bits = false; | |
| 780 | 783 | |
| 781 | 784 | return entry; |
| 782 | 785 | } |
| ... | ... | @@ -968,14 +971,6 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKi |
| 968 | 971 | return entry; |
| 969 | 972 | } |
| 970 | 973 | |
| 971 | TypeTableEntry *get_underlying_type(TypeTableEntry *type_entry) { | |
| 972 | if (type_entry->id == TypeTableEntryIdTypeDecl) { | |
| 973 | return type_entry->data.type_decl.canonical_type; | |
| 974 | } else { | |
| 975 | return type_entry; | |
| 976 | } | |
| 977 | } | |
| 978 | ||
| 979 | 974 | static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, TypeTableEntry *type_entry, Buf *type_name) { |
| 980 | 975 | size_t backward_branch_count = 0; |
| 981 | 976 | return ir_eval_const_value(g, scope, node, type_entry, |
| ... | ... | @@ -1066,6 +1061,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1066 | 1061 | case TypeTableEntryIdUndefLit: |
| 1067 | 1062 | case TypeTableEntryIdNullLit: |
| 1068 | 1063 | case TypeTableEntryIdArgTuple: |
| 1064 | case TypeTableEntryIdOpaque: | |
| 1069 | 1065 | add_node_error(g, param_node->data.param_decl.type, |
| 1070 | 1066 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); |
| 1071 | 1067 | return g->builtin_types.entry_invalid; |
| ... | ... | @@ -1099,7 +1095,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1099 | 1095 | case TypeTableEntryIdEnum: |
| 1100 | 1096 | case TypeTableEntryIdUnion: |
| 1101 | 1097 | case TypeTableEntryIdFn: |
| 1102 | case TypeTableEntryIdTypeDecl: | |
| 1103 | 1098 | case TypeTableEntryIdEnumTag: |
| 1104 | 1099 | ensure_complete_type(g, type_entry); |
| 1105 | 1100 | if (!fn_type_id.is_extern && !type_is_copyable(g, type_entry)) { |
| ... | ... | @@ -1123,6 +1118,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1123 | 1118 | case TypeTableEntryIdUndefLit: |
| 1124 | 1119 | case TypeTableEntryIdNullLit: |
| 1125 | 1120 | case TypeTableEntryIdArgTuple: |
| 1121 | case TypeTableEntryIdOpaque: | |
| 1126 | 1122 | add_node_error(g, fn_proto->return_type, |
| 1127 | 1123 | buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name))); |
| 1128 | 1124 | return g->builtin_types.entry_invalid; |
| ... | ... | @@ -1155,7 +1151,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1155 | 1151 | case TypeTableEntryIdEnum: |
| 1156 | 1152 | case TypeTableEntryIdUnion: |
| 1157 | 1153 | case TypeTableEntryIdFn: |
| 1158 | case TypeTableEntryIdTypeDecl: | |
| 1159 | 1154 | case TypeTableEntryIdEnumTag: |
| 1160 | 1155 | break; |
| 1161 | 1156 | } |
| ... | ... | @@ -1173,8 +1168,6 @@ bool type_is_invalid(TypeTableEntry *type_entry) { |
| 1173 | 1168 | return type_entry->data.enumeration.is_invalid; |
| 1174 | 1169 | case TypeTableEntryIdUnion: |
| 1175 | 1170 | return type_entry->data.unionation.is_invalid; |
| 1176 | case TypeTableEntryIdTypeDecl: | |
| 1177 | return type_is_invalid(type_entry->data.type_decl.canonical_type); | |
| 1178 | 1171 | default: |
| 1179 | 1172 | return false; |
| 1180 | 1173 | } |
| ... | ... | @@ -1380,8 +1373,7 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) { |
| 1380 | 1373 | } |
| 1381 | 1374 | |
| 1382 | 1375 | static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { |
| 1383 | TypeTableEntry *canon_type = get_underlying_type(type_entry); | |
| 1384 | switch (canon_type->id) { | |
| 1376 | switch (type_entry->id) { | |
| 1385 | 1377 | case TypeTableEntryIdInvalid: |
| 1386 | 1378 | case TypeTableEntryIdVar: |
| 1387 | 1379 | zig_unreachable(); |
| ... | ... | @@ -1395,11 +1387,11 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { |
| 1395 | 1387 | case TypeTableEntryIdPureError: |
| 1396 | 1388 | case TypeTableEntryIdEnum: |
| 1397 | 1389 | case TypeTableEntryIdEnumTag: |
| 1398 | case TypeTableEntryIdTypeDecl: | |
| 1399 | 1390 | case TypeTableEntryIdNamespace: |
| 1400 | 1391 | case TypeTableEntryIdBlock: |
| 1401 | 1392 | case TypeTableEntryIdBoundFn: |
| 1402 | 1393 | case TypeTableEntryIdArgTuple: |
| 1394 | case TypeTableEntryIdOpaque: | |
| 1403 | 1395 | return false; |
| 1404 | 1396 | case TypeTableEntryIdVoid: |
| 1405 | 1397 | case TypeTableEntryIdBool: |
| ... | ... | @@ -1411,11 +1403,11 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { |
| 1411 | 1403 | case TypeTableEntryIdFn: |
| 1412 | 1404 | return true; |
| 1413 | 1405 | case TypeTableEntryIdStruct: |
| 1414 | return canon_type->data.structure.layout == ContainerLayoutPacked; | |
| 1406 | return type_entry->data.structure.layout == ContainerLayoutPacked; | |
| 1415 | 1407 | case TypeTableEntryIdMaybe: |
| 1416 | 1408 | { |
| 1417 | TypeTableEntry *canon_child_type = get_underlying_type(canon_type->data.maybe.child_type); | |
| 1418 | return canon_child_type->id == TypeTableEntryIdPointer || canon_child_type->id == TypeTableEntryIdFn; | |
| 1409 | TypeTableEntry *child_type = type_entry->data.maybe.child_type; | |
| 1410 | return child_type->id == TypeTableEntryIdPointer || child_type->id == TypeTableEntryIdFn; | |
| 1419 | 1411 | } |
| 1420 | 1412 | } |
| 1421 | 1413 | zig_unreachable(); |
| ... | ... | @@ -2037,15 +2029,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 2037 | 2029 | add_top_level_decl(g, decls_scope, &tld_var->base); |
| 2038 | 2030 | break; |
| 2039 | 2031 | } |
| 2040 | case NodeTypeTypeDecl: | |
| 2041 | { | |
| 2042 | Buf *name = node->data.type_decl.symbol; | |
| 2043 | VisibMod visib_mod = node->data.type_decl.visib_mod; | |
| 2044 | TldTypeDef *tld_typedef = allocate<TldTypeDef>(1); | |
| 2045 | init_tld(&tld_typedef->base, TldIdTypeDef, name, visib_mod, node, &decls_scope->base); | |
| 2046 | add_top_level_decl(g, decls_scope, &tld_typedef->base); | |
| 2047 | break; | |
| 2048 | } | |
| 2049 | 2032 | case NodeTypeFnProto: |
| 2050 | 2033 | { |
| 2051 | 2034 | // if the name is missing, we immediately announce an error |
| ... | ... | @@ -2126,7 +2109,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 2126 | 2109 | case NodeTypeStructValueField: |
| 2127 | 2110 | case NodeTypeArrayType: |
| 2128 | 2111 | case NodeTypeErrorType: |
| 2129 | case NodeTypeTypeLiteral: | |
| 2130 | 2112 | case NodeTypeVarLiteral: |
| 2131 | 2113 | case NodeTypeTryExpr: |
| 2132 | 2114 | case NodeTypeInlineExpr: |
| ... | ... | @@ -2154,10 +2136,7 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) { |
| 2154 | 2136 | } |
| 2155 | 2137 | |
| 2156 | 2138 | TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry) { |
| 2157 | TypeTableEntry *underlying_type = get_underlying_type(type_entry); | |
| 2158 | switch (underlying_type->id) { | |
| 2159 | case TypeTableEntryIdTypeDecl: | |
| 2160 | zig_unreachable(); | |
| 2139 | switch (type_entry->id) { | |
| 2161 | 2140 | case TypeTableEntryIdInvalid: |
| 2162 | 2141 | return g->builtin_types.entry_invalid; |
| 2163 | 2142 | case TypeTableEntryIdUnreachable: |
| ... | ... | @@ -2168,8 +2147,9 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt |
| 2168 | 2147 | case TypeTableEntryIdNullLit: |
| 2169 | 2148 | case TypeTableEntryIdBlock: |
| 2170 | 2149 | case TypeTableEntryIdArgTuple: |
| 2150 | case TypeTableEntryIdOpaque: | |
| 2171 | 2151 | add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed", |
| 2172 | buf_ptr(&underlying_type->name))); | |
| 2152 | buf_ptr(&type_entry->name))); | |
| 2173 | 2153 | return g->builtin_types.entry_invalid; |
| 2174 | 2154 | case TypeTableEntryIdNamespace: |
| 2175 | 2155 | case TypeTableEntryIdMetaType: |
| ... | ... | @@ -2328,17 +2308,6 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) { |
| 2328 | 2308 | g->global_vars.append(tld_var); |
| 2329 | 2309 | } |
| 2330 | 2310 | |
| 2331 | static void resolve_decl_typedef(CodeGen *g, TldTypeDef *tld_typedef) { | |
| 2332 | AstNode *typedef_node = tld_typedef->base.source_node; | |
| 2333 | assert(typedef_node->type == NodeTypeTypeDecl); | |
| 2334 | AstNode *type_node = typedef_node->data.type_decl.child_type; | |
| 2335 | Buf *decl_name = typedef_node->data.type_decl.symbol; | |
| 2336 | ||
| 2337 | TypeTableEntry *child_type = analyze_type_expr(g, tld_typedef->base.parent_scope, type_node); | |
| 2338 | tld_typedef->type_entry = (child_type->id == TypeTableEntryIdInvalid) ? | |
| 2339 | child_type : get_typedecl_type(g, buf_ptr(decl_name), child_type); | |
| 2340 | } | |
| 2341 | ||
| 2342 | 2311 | void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only) { |
| 2343 | 2312 | if (tld->resolution != TldResolutionUnresolved) |
| 2344 | 2313 | return; |
| ... | ... | @@ -2370,12 +2339,6 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only) { |
| 2370 | 2339 | resolve_decl_container(g, tld_container); |
| 2371 | 2340 | break; |
| 2372 | 2341 | } |
| 2373 | case TldIdTypeDef: | |
| 2374 | { | |
| 2375 | TldTypeDef *tld_typedef = (TldTypeDef *)tld; | |
| 2376 | resolve_decl_typedef(g, tld_typedef); | |
| 2377 | break; | |
| 2378 | } | |
| 2379 | 2342 | case TldIdCompTime: |
| 2380 | 2343 | { |
| 2381 | 2344 | TldCompTime *tld_comptime = (TldCompTime *)tld; |
| ... | ... | @@ -2589,6 +2552,7 @@ static bool is_container(TypeTableEntry *type_entry) { |
| 2589 | 2552 | switch (type_entry->id) { |
| 2590 | 2553 | case TypeTableEntryIdInvalid: |
| 2591 | 2554 | case TypeTableEntryIdVar: |
| 2555 | case TypeTableEntryIdOpaque: | |
| 2592 | 2556 | zig_unreachable(); |
| 2593 | 2557 | case TypeTableEntryIdStruct: |
| 2594 | 2558 | case TypeTableEntryIdEnum: |
| ... | ... | @@ -2610,7 +2574,6 @@ static bool is_container(TypeTableEntry *type_entry) { |
| 2610 | 2574 | case TypeTableEntryIdErrorUnion: |
| 2611 | 2575 | case TypeTableEntryIdPureError: |
| 2612 | 2576 | case TypeTableEntryIdFn: |
| 2613 | case TypeTableEntryIdTypeDecl: | |
| 2614 | 2577 | case TypeTableEntryIdNamespace: |
| 2615 | 2578 | case TypeTableEntryIdBlock: |
| 2616 | 2579 | case TypeTableEntryIdBoundFn: |
| ... | ... | @@ -2659,7 +2622,6 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) { |
| 2659 | 2622 | case TypeTableEntryIdErrorUnion: |
| 2660 | 2623 | case TypeTableEntryIdPureError: |
| 2661 | 2624 | case TypeTableEntryIdFn: |
| 2662 | case TypeTableEntryIdTypeDecl: | |
| 2663 | 2625 | case TypeTableEntryIdNamespace: |
| 2664 | 2626 | case TypeTableEntryIdBlock: |
| 2665 | 2627 | case TypeTableEntryIdBoundFn: |
| ... | ... | @@ -2667,6 +2629,7 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) { |
| 2667 | 2629 | case TypeTableEntryIdVar: |
| 2668 | 2630 | case TypeTableEntryIdEnumTag: |
| 2669 | 2631 | case TypeTableEntryIdArgTuple: |
| 2632 | case TypeTableEntryIdOpaque: | |
| 2670 | 2633 | zig_unreachable(); |
| 2671 | 2634 | } |
| 2672 | 2635 | } |
| ... | ... | @@ -3062,6 +3025,7 @@ bool handle_is_ptr(TypeTableEntry *type_entry) { |
| 3062 | 3025 | case TypeTableEntryIdBoundFn: |
| 3063 | 3026 | case TypeTableEntryIdVar: |
| 3064 | 3027 | case TypeTableEntryIdArgTuple: |
| 3028 | case TypeTableEntryIdOpaque: | |
| 3065 | 3029 | zig_unreachable(); |
| 3066 | 3030 | case TypeTableEntryIdUnreachable: |
| 3067 | 3031 | case TypeTableEntryIdVoid: |
| ... | ... | @@ -3086,8 +3050,6 @@ bool handle_is_ptr(TypeTableEntry *type_entry) { |
| 3086 | 3050 | return type_has_bits(type_entry->data.maybe.child_type) && |
| 3087 | 3051 | type_entry->data.maybe.child_type->id != TypeTableEntryIdPointer && |
| 3088 | 3052 | type_entry->data.maybe.child_type->id != TypeTableEntryIdFn; |
| 3089 | case TypeTableEntryIdTypeDecl: | |
| 3090 | return handle_is_ptr(type_entry->data.type_decl.canonical_type); | |
| 3091 | 3053 | } |
| 3092 | 3054 | zig_unreachable(); |
| 3093 | 3055 | } |
| ... | ... | @@ -3165,6 +3127,8 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) { |
| 3165 | 3127 | static uint32_t hash_const_val(ConstExprValue *const_val) { |
| 3166 | 3128 | assert(const_val->special == ConstValSpecialStatic); |
| 3167 | 3129 | switch (const_val->type->id) { |
| 3130 | case TypeTableEntryIdOpaque: | |
| 3131 | zig_unreachable(); | |
| 3168 | 3132 | case TypeTableEntryIdBool: |
| 3169 | 3133 | return const_val->data.x_bool ? (uint32_t)127863866 : (uint32_t)215080464; |
| 3170 | 3134 | case TypeTableEntryIdMetaType: |
| ... | ... | @@ -3254,8 +3218,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { |
| 3254 | 3218 | case TypeTableEntryIdFn: |
| 3255 | 3219 | return hash_ptr(const_val->data.x_fn.fn_entry) + |
| 3256 | 3220 | (const_val->data.x_fn.is_inline ? 4133894920 : 3983484790); |
| 3257 | case TypeTableEntryIdTypeDecl: | |
| 3258 | return hash_ptr(const_val->data.x_type); | |
| 3259 | 3221 | case TypeTableEntryIdNamespace: |
| 3260 | 3222 | return hash_ptr(const_val->data.x_import); |
| 3261 | 3223 | case TypeTableEntryIdBlock: |
| ... | ... | @@ -3359,10 +3321,10 @@ bool type_has_bits(TypeTableEntry *type_entry) { |
| 3359 | 3321 | } |
| 3360 | 3322 | |
| 3361 | 3323 | bool type_requires_comptime(TypeTableEntry *type_entry) { |
| 3362 | switch (get_underlying_type(type_entry)->id) { | |
| 3324 | switch (type_entry->id) { | |
| 3363 | 3325 | case TypeTableEntryIdInvalid: |
| 3364 | 3326 | case TypeTableEntryIdVar: |
| 3365 | case TypeTableEntryIdTypeDecl: | |
| 3327 | case TypeTableEntryIdOpaque: | |
| 3366 | 3328 | zig_unreachable(); |
| 3367 | 3329 | case TypeTableEntryIdNumLitFloat: |
| 3368 | 3330 | case TypeTableEntryIdNumLitInt: |
| ... | ... | @@ -3603,14 +3565,14 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_ |
| 3603 | 3565 | |
| 3604 | 3566 | |
| 3605 | 3567 | void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { |
| 3606 | TypeTableEntry *canon_wanted_type = get_underlying_type(const_val->type); | |
| 3607 | if (canon_wanted_type->id == TypeTableEntryIdArray) { | |
| 3568 | TypeTableEntry *wanted_type = const_val->type; | |
| 3569 | if (wanted_type->id == TypeTableEntryIdArray) { | |
| 3608 | 3570 | const_val->special = ConstValSpecialStatic; |
| 3609 | size_t elem_count = canon_wanted_type->data.array.len; | |
| 3571 | size_t elem_count = wanted_type->data.array.len; | |
| 3610 | 3572 | const_val->data.x_array.elements = allocate<ConstExprValue>(elem_count); |
| 3611 | 3573 | for (size_t i = 0; i < elem_count; i += 1) { |
| 3612 | 3574 | ConstExprValue *element_val = &const_val->data.x_array.elements[i]; |
| 3613 | element_val->type = canon_wanted_type->data.array.child_type; | |
| 3575 | element_val->type = wanted_type->data.array.child_type; | |
| 3614 | 3576 | init_const_undefined(g, element_val); |
| 3615 | 3577 | ConstParent *parent = get_const_val_parent(element_val); |
| 3616 | 3578 | if (parent != nullptr) { |
| ... | ... | @@ -3619,15 +3581,15 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { |
| 3619 | 3581 | parent->data.p_array.elem_index = i; |
| 3620 | 3582 | } |
| 3621 | 3583 | } |
| 3622 | } else if (canon_wanted_type->id == TypeTableEntryIdStruct) { | |
| 3623 | ensure_complete_type(g, canon_wanted_type); | |
| 3584 | } else if (wanted_type->id == TypeTableEntryIdStruct) { | |
| 3585 | ensure_complete_type(g, wanted_type); | |
| 3624 | 3586 | |
| 3625 | 3587 | const_val->special = ConstValSpecialStatic; |
| 3626 | size_t field_count = canon_wanted_type->data.structure.src_field_count; | |
| 3588 | size_t field_count = wanted_type->data.structure.src_field_count; | |
| 3627 | 3589 | const_val->data.x_struct.fields = allocate<ConstExprValue>(field_count); |
| 3628 | 3590 | for (size_t i = 0; i < field_count; i += 1) { |
| 3629 | 3591 | ConstExprValue *field_val = &const_val->data.x_struct.fields[i]; |
| 3630 | field_val->type = canon_wanted_type->data.structure.fields[i].type_entry; | |
| 3592 | field_val->type = wanted_type->data.structure.fields[i].type_entry; | |
| 3631 | 3593 | assert(field_val->type); |
| 3632 | 3594 | init_const_undefined(g, field_val); |
| 3633 | 3595 | ConstParent *parent = get_const_val_parent(field_val); |
| ... | ... | @@ -3678,6 +3640,8 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { |
| 3678 | 3640 | assert(a->special == ConstValSpecialStatic); |
| 3679 | 3641 | assert(b->special == ConstValSpecialStatic); |
| 3680 | 3642 | switch (a->type->id) { |
| 3643 | case TypeTableEntryIdOpaque: | |
| 3644 | zig_unreachable(); | |
| 3681 | 3645 | case TypeTableEntryIdEnum: |
| 3682 | 3646 | { |
| 3683 | 3647 | ConstEnumValue *enum1 = &a->data.x_enum; |
| ... | ... | @@ -3767,8 +3731,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { |
| 3767 | 3731 | } |
| 3768 | 3732 | case TypeTableEntryIdErrorUnion: |
| 3769 | 3733 | zig_panic("TODO"); |
| 3770 | case TypeTableEntryIdTypeDecl: | |
| 3771 | zig_panic("TODO"); | |
| 3772 | 3734 | case TypeTableEntryIdNamespace: |
| 3773 | 3735 | return a->data.x_import == b->data.x_import; |
| 3774 | 3736 | case TypeTableEntryIdBlock: |
| ... | ... | @@ -3857,9 +3819,9 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { |
| 3857 | 3819 | } |
| 3858 | 3820 | assert(const_val->type); |
| 3859 | 3821 | |
| 3860 | TypeTableEntry *canon_type = get_underlying_type(const_val->type); | |
| 3861 | switch (canon_type->id) { | |
| 3862 | case TypeTableEntryIdTypeDecl: | |
| 3822 | TypeTableEntry *type_entry = const_val->type; | |
| 3823 | switch (type_entry->id) { | |
| 3824 | case TypeTableEntryIdOpaque: | |
| 3863 | 3825 | zig_unreachable(); |
| 3864 | 3826 | case TypeTableEntryIdInvalid: |
| 3865 | 3827 | buf_appendf(buf, "(invalid)"); |
| ... | ... | @@ -3926,7 +3888,7 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { |
| 3926 | 3888 | return; |
| 3927 | 3889 | } |
| 3928 | 3890 | case ConstPtrSpecialHardCodedAddr: |
| 3929 | buf_appendf(buf, "(&%s)(%" PRIx64 ")", buf_ptr(&canon_type->data.pointer.child_type->name), | |
| 3891 | buf_appendf(buf, "(&%s)(%" PRIx64 ")", buf_ptr(&type_entry->data.pointer.child_type->name), | |
| 3930 | 3892 | const_val->data.x_ptr.data.hard_coded_addr.addr); |
| 3931 | 3893 | return; |
| 3932 | 3894 | case ConstPtrSpecialDiscard: |
| ... | ... | @@ -3949,8 +3911,8 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { |
| 3949 | 3911 | } |
| 3950 | 3912 | case TypeTableEntryIdArray: |
| 3951 | 3913 | { |
| 3952 | TypeTableEntry *child_type = canon_type->data.array.child_type; | |
| 3953 | uint64_t len = canon_type->data.array.len; | |
| 3914 | TypeTableEntry *child_type = type_entry->data.array.child_type; | |
| 3915 | uint64_t len = type_entry->data.array.len; | |
| 3954 | 3916 | |
| 3955 | 3917 | // if it's []u8, assume UTF-8 and output a string |
| 3956 | 3918 | if (child_type->id == TypeTableEntryIdInt && |
| ... | ... | @@ -3973,7 +3935,7 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { |
| 3973 | 3935 | return; |
| 3974 | 3936 | } |
| 3975 | 3937 | |
| 3976 | buf_appendf(buf, "%s{", buf_ptr(&canon_type->name)); | |
| 3938 | buf_appendf(buf, "%s{", buf_ptr(&type_entry->name)); | |
| 3977 | 3939 | for (uint64_t i = 0; i < len; i += 1) { |
| 3978 | 3940 | if (i != 0) |
| 3979 | 3941 | buf_appendf(buf, ","); |
| ... | ... | @@ -4021,22 +3983,22 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { |
| 4021 | 3983 | } |
| 4022 | 3984 | case TypeTableEntryIdStruct: |
| 4023 | 3985 | { |
| 4024 | buf_appendf(buf, "(struct %s constant)", buf_ptr(&canon_type->name)); | |
| 3986 | buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name)); | |
| 4025 | 3987 | return; |
| 4026 | 3988 | } |
| 4027 | 3989 | case TypeTableEntryIdEnum: |
| 4028 | 3990 | { |
| 4029 | buf_appendf(buf, "(enum %s constant)", buf_ptr(&canon_type->name)); | |
| 3991 | buf_appendf(buf, "(enum %s constant)", buf_ptr(&type_entry->name)); | |
| 4030 | 3992 | return; |
| 4031 | 3993 | } |
| 4032 | 3994 | case TypeTableEntryIdErrorUnion: |
| 4033 | 3995 | { |
| 4034 | buf_appendf(buf, "(error union %s constant)", buf_ptr(&canon_type->name)); | |
| 3996 | buf_appendf(buf, "(error union %s constant)", buf_ptr(&type_entry->name)); | |
| 4035 | 3997 | return; |
| 4036 | 3998 | } |
| 4037 | 3999 | case TypeTableEntryIdUnion: |
| 4038 | 4000 | { |
| 4039 | buf_appendf(buf, "(union %s constant)", buf_ptr(&canon_type->name)); | |
| 4001 | buf_appendf(buf, "(union %s constant)", buf_ptr(&type_entry->name)); | |
| 4040 | 4002 | return; |
| 4041 | 4003 | } |
| 4042 | 4004 | case TypeTableEntryIdPureError: |
| ... | ... | @@ -4046,7 +4008,7 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { |
| 4046 | 4008 | } |
| 4047 | 4009 | case TypeTableEntryIdEnumTag: |
| 4048 | 4010 | { |
| 4049 | TypeTableEntry *enum_type = canon_type->data.enum_tag.enum_type; | |
| 4011 | TypeTableEntry *enum_type = type_entry->data.enum_tag.enum_type; | |
| 4050 | 4012 | TypeEnumField *field = &enum_type->data.enumeration.fields[const_val->data.x_bignum.data.x_uint]; |
| 4051 | 4013 | buf_appendf(buf, "%s.%s", buf_ptr(&enum_type->name), buf_ptr(field->name)); |
| 4052 | 4014 | return; |
| ... | ... | @@ -4095,6 +4057,7 @@ uint32_t type_id_hash(TypeId x) { |
| 4095 | 4057 | switch (x.id) { |
| 4096 | 4058 | case TypeTableEntryIdInvalid: |
| 4097 | 4059 | case TypeTableEntryIdVar: |
| 4060 | case TypeTableEntryIdOpaque: | |
| 4098 | 4061 | case TypeTableEntryIdMetaType: |
| 4099 | 4062 | case TypeTableEntryIdVoid: |
| 4100 | 4063 | case TypeTableEntryIdBool: |
| ... | ... | @@ -4112,7 +4075,6 @@ uint32_t type_id_hash(TypeId x) { |
| 4112 | 4075 | case TypeTableEntryIdEnumTag: |
| 4113 | 4076 | case TypeTableEntryIdUnion: |
| 4114 | 4077 | case TypeTableEntryIdFn: |
| 4115 | case TypeTableEntryIdTypeDecl: | |
| 4116 | 4078 | case TypeTableEntryIdNamespace: |
| 4117 | 4079 | case TypeTableEntryIdBlock: |
| 4118 | 4080 | case TypeTableEntryIdBoundFn: |
| ... | ... | @@ -4157,11 +4119,11 @@ bool type_id_eql(TypeId a, TypeId b) { |
| 4157 | 4119 | case TypeTableEntryIdEnumTag: |
| 4158 | 4120 | case TypeTableEntryIdUnion: |
| 4159 | 4121 | case TypeTableEntryIdFn: |
| 4160 | case TypeTableEntryIdTypeDecl: | |
| 4161 | 4122 | case TypeTableEntryIdNamespace: |
| 4162 | 4123 | case TypeTableEntryIdBlock: |
| 4163 | 4124 | case TypeTableEntryIdBoundFn: |
| 4164 | 4125 | case TypeTableEntryIdArgTuple: |
| 4126 | case TypeTableEntryIdOpaque: | |
| 4165 | 4127 | zig_unreachable(); |
| 4166 | 4128 | case TypeTableEntryIdPointer: |
| 4167 | 4129 | return a.data.pointer.child_type == b.data.pointer.child_type && |
| ... | ... | @@ -4211,10 +4173,10 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) { |
| 4211 | 4173 | |
| 4212 | 4174 | ConstParent *get_const_val_parent(ConstExprValue *value) { |
| 4213 | 4175 | assert(value->type); |
| 4214 | TypeTableEntry *canon_type = get_underlying_type(value->type); | |
| 4215 | if (canon_type->id == TypeTableEntryIdArray) { | |
| 4176 | TypeTableEntry *type_entry = value->type; | |
| 4177 | if (type_entry->id == TypeTableEntryIdArray) { | |
| 4216 | 4178 | return &value->data.x_array.parent; |
| 4217 | } else if (canon_type->id == TypeTableEntryIdStruct) { | |
| 4179 | } else if (type_entry->id == TypeTableEntryIdStruct) { | |
| 4218 | 4180 | return &value->data.x_struct.parent; |
| 4219 | 4181 | } |
| 4220 | 4182 | return nullptr; |
src/analyze.hpp+1-2| ... | ... | @@ -24,7 +24,6 @@ TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_b |
| 24 | 24 | TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); |
| 25 | 25 | TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type); |
| 26 | 26 | TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type); |
| 27 | TypeTableEntry *get_typedecl_type(CodeGen *g, const char *name, TypeTableEntry *child_type); | |
| 28 | 27 | TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id); |
| 29 | 28 | TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type); |
| 30 | 29 | TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size); |
| ... | ... | @@ -34,11 +33,11 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKi |
| 34 | 33 | TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x); |
| 35 | 34 | TypeTableEntry *get_error_type(CodeGen *g, TypeTableEntry *child_type); |
| 36 | 35 | TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry); |
| 36 | TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name); | |
| 37 | 37 | bool handle_is_ptr(TypeTableEntry *type_entry); |
| 38 | 38 | void find_libc_include_path(CodeGen *g); |
| 39 | 39 | void find_libc_lib_path(CodeGen *g); |
| 40 | 40 | |
| 41 | TypeTableEntry *get_underlying_type(TypeTableEntry *type_entry); | |
| 42 | 41 | bool type_has_bits(TypeTableEntry *type_entry); |
| 43 | 42 | |
| 44 | 43 |
src/ast_render.cpp+6-28| ... | ... | @@ -166,8 +166,6 @@ static const char *node_type_str(NodeType node_type) { |
| 166 | 166 | return "Defer"; |
| 167 | 167 | case NodeTypeVariableDeclaration: |
| 168 | 168 | return "VariableDeclaration"; |
| 169 | case NodeTypeTypeDecl: | |
| 170 | return "TypeDecl"; | |
| 171 | 169 | case NodeTypeErrorValueDecl: |
| 172 | 170 | return "ErrorValueDecl"; |
| 173 | 171 | case NodeTypeTestDecl: |
| ... | ... | @@ -234,8 +232,6 @@ static const char *node_type_str(NodeType node_type) { |
| 234 | 232 | return "ArrayType"; |
| 235 | 233 | case NodeTypeErrorType: |
| 236 | 234 | return "ErrorType"; |
| 237 | case NodeTypeTypeLiteral: | |
| 238 | return "TypeLiteral"; | |
| 239 | 235 | case NodeTypeVarLiteral: |
| 240 | 236 | return "VarLiteral"; |
| 241 | 237 | case NodeTypeTryExpr: |
| ... | ... | @@ -394,7 +390,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 394 | 390 | |
| 395 | 391 | if (child->type == NodeTypeUse || |
| 396 | 392 | child->type == NodeTypeVariableDeclaration || |
| 397 | child->type == NodeTypeTypeDecl || | |
| 398 | 393 | child->type == NodeTypeErrorValueDecl || |
| 399 | 394 | child->type == NodeTypeFnProto) |
| 400 | 395 | { |
| ... | ... | @@ -507,14 +502,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 507 | 502 | } |
| 508 | 503 | break; |
| 509 | 504 | } |
| 510 | case NodeTypeTypeDecl: | |
| 511 | { | |
| 512 | const char *pub_str = visib_mod_string(node->data.type_decl.visib_mod); | |
| 513 | const char *var_name = buf_ptr(node->data.type_decl.symbol); | |
| 514 | fprintf(ar->f, "%stype %s = ", pub_str, var_name); | |
| 515 | render_node_grouped(ar, node->data.type_decl.child_type); | |
| 516 | break; | |
| 517 | } | |
| 518 | 505 | case NodeTypeBinOpExpr: |
| 519 | 506 | if (!grouped) fprintf(ar->f, "("); |
| 520 | 507 | render_node_ungrouped(ar, node->data.bin_op_expr.op1); |
| ... | ... | @@ -668,9 +655,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 668 | 655 | case NodeTypeErrorType: |
| 669 | 656 | fprintf(ar->f, "error"); |
| 670 | 657 | break; |
| 671 | case NodeTypeTypeLiteral: | |
| 672 | fprintf(ar->f, "type"); | |
| 673 | break; | |
| 674 | 658 | case NodeTypeVarLiteral: |
| 675 | 659 | fprintf(ar->f, "var"); |
| 676 | 660 | break; |
| ... | ... | @@ -1034,6 +1018,12 @@ static void ast_render_tld_var(AstRender *ar, Buf *name, TldVar *tld_var) { |
| 1034 | 1018 | fprintf(ar->f, "union {"); |
| 1035 | 1019 | fprintf(ar->f, "TODO"); |
| 1036 | 1020 | fprintf(ar->f, "}"); |
| 1021 | } else if (type_entry->id == TypeTableEntryIdOpaque) { | |
| 1022 | if (buf_eql_buf(&type_entry->name, name)) { | |
| 1023 | fprintf(ar->f, "@OpaqueType()"); | |
| 1024 | } else { | |
| 1025 | fprintf(ar->f, "%s", buf_ptr(&type_entry->name)); | |
| 1026 | } | |
| 1037 | 1027 | } else { |
| 1038 | 1028 | fprintf(ar->f, "%s", buf_ptr(&type_entry->name)); |
| 1039 | 1029 | } |
| ... | ... | @@ -1047,15 +1037,6 @@ static void ast_render_tld_var(AstRender *ar, Buf *name, TldVar *tld_var) { |
| 1047 | 1037 | fprintf(ar->f, ";\n"); |
| 1048 | 1038 | } |
| 1049 | 1039 | |
| 1050 | static void ast_render_tld_typedef(AstRender *ar, Buf *name, TldTypeDef *tld_typedef) { | |
| 1051 | TypeTableEntry *type_entry = tld_typedef->type_entry; | |
| 1052 | TypeTableEntry *canon_type = get_underlying_type(type_entry); | |
| 1053 | ||
| 1054 | fprintf(ar->f, "pub type "); | |
| 1055 | print_symbol(ar, name); | |
| 1056 | fprintf(ar->f, " = %s;\n", buf_ptr(&canon_type->name)); | |
| 1057 | } | |
| 1058 | ||
| 1059 | 1040 | void ast_render_decls(FILE *f, int indent_size, ImportTableEntry *import) { |
| 1060 | 1041 | AstRender ar = {0}; |
| 1061 | 1042 | ar.f = f; |
| ... | ... | @@ -1087,9 +1068,6 @@ void ast_render_decls(FILE *f, int indent_size, ImportTableEntry *import) { |
| 1087 | 1068 | case TldIdContainer: |
| 1088 | 1069 | fprintf(stdout, "container\n"); |
| 1089 | 1070 | break; |
| 1090 | case TldIdTypeDef: | |
| 1091 | ast_render_tld_typedef(&ar, entry->key, (TldTypeDef *)tld); | |
| 1092 | break; | |
| 1093 | 1071 | case TldIdCompTime: |
| 1094 | 1072 | fprintf(stdout, "comptime\n"); |
| 1095 | 1073 | break; |
src/codegen.cpp+85-89| ... | ... | @@ -649,12 +649,9 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val, |
| 649 | 649 | LLVMPositionBuilderAtEnd(g->builder, ok_block); |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, TypeTableEntry *actual_type_non_canon, | |
| 653 | TypeTableEntry *wanted_type_non_canon, LLVMValueRef expr_val) | |
| 652 | static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, TypeTableEntry *actual_type, | |
| 653 | TypeTableEntry *wanted_type, LLVMValueRef expr_val) | |
| 654 | 654 | { |
| 655 | TypeTableEntry *actual_type = get_underlying_type(actual_type_non_canon); | |
| 656 | TypeTableEntry *wanted_type = get_underlying_type(wanted_type_non_canon); | |
| 657 | ||
| 658 | 655 | assert(actual_type->id == wanted_type->id); |
| 659 | 656 | |
| 660 | 657 | uint64_t actual_bits; |
| ... | ... | @@ -852,7 +849,7 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, LLVMValueRef src, LLVMValueRef |
| 852 | 849 | static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *ptr_type, |
| 853 | 850 | LLVMValueRef value) |
| 854 | 851 | { |
| 855 | TypeTableEntry *child_type = get_underlying_type(ptr_type->data.pointer.child_type); | |
| 852 | TypeTableEntry *child_type = ptr_type->data.pointer.child_type; | |
| 856 | 853 | |
| 857 | 854 | if (!type_has_bits(child_type)) |
| 858 | 855 | return nullptr; |
| ... | ... | @@ -1111,7 +1108,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, |
| 1111 | 1108 | IrInstruction *op2 = bin_op_instruction->op2; |
| 1112 | 1109 | |
| 1113 | 1110 | assert(op1->value.type == op2->value.type); |
| 1114 | TypeTableEntry *canon_type = get_underlying_type(op1->value.type); | |
| 1111 | TypeTableEntry *type_entry = op1->value.type; | |
| 1115 | 1112 | |
| 1116 | 1113 | bool want_debug_safety = bin_op_instruction->safety_check_on && |
| 1117 | 1114 | ir_want_debug_safety(g, &bin_op_instruction->base); |
| ... | ... | @@ -1133,22 +1130,22 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, |
| 1133 | 1130 | case IrBinOpCmpGreaterThan: |
| 1134 | 1131 | case IrBinOpCmpLessOrEq: |
| 1135 | 1132 | case IrBinOpCmpGreaterOrEq: |
| 1136 | if (canon_type->id == TypeTableEntryIdFloat) { | |
| 1133 | if (type_entry->id == TypeTableEntryIdFloat) { | |
| 1137 | 1134 | LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id); |
| 1138 | 1135 | return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, ""); |
| 1139 | } else if (canon_type->id == TypeTableEntryIdInt) { | |
| 1140 | LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, canon_type->data.integral.is_signed); | |
| 1136 | } else if (type_entry->id == TypeTableEntryIdInt) { | |
| 1137 | LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, type_entry->data.integral.is_signed); | |
| 1141 | 1138 | return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, ""); |
| 1142 | } else if (canon_type->id == TypeTableEntryIdEnum) { | |
| 1143 | if (canon_type->data.enumeration.gen_field_count == 0) { | |
| 1139 | } else if (type_entry->id == TypeTableEntryIdEnum) { | |
| 1140 | if (type_entry->data.enumeration.gen_field_count == 0) { | |
| 1144 | 1141 | LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false); |
| 1145 | 1142 | return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, ""); |
| 1146 | 1143 | } else { |
| 1147 | 1144 | zig_unreachable(); |
| 1148 | 1145 | } |
| 1149 | } else if (canon_type->id == TypeTableEntryIdPureError || | |
| 1150 | canon_type->id == TypeTableEntryIdPointer || | |
| 1151 | canon_type->id == TypeTableEntryIdBool) | |
| 1146 | } else if (type_entry->id == TypeTableEntryIdPureError || | |
| 1147 | type_entry->id == TypeTableEntryIdPointer || | |
| 1148 | type_entry->id == TypeTableEntryIdBool) | |
| 1152 | 1149 | { |
| 1153 | 1150 | LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false); |
| 1154 | 1151 | return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, ""); |
| ... | ... | @@ -1157,15 +1154,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, |
| 1157 | 1154 | } |
| 1158 | 1155 | case IrBinOpAdd: |
| 1159 | 1156 | case IrBinOpAddWrap: |
| 1160 | if (canon_type->id == TypeTableEntryIdFloat) { | |
| 1157 | if (type_entry->id == TypeTableEntryIdFloat) { | |
| 1161 | 1158 | return LLVMBuildFAdd(g->builder, op1_value, op2_value, ""); |
| 1162 | } else if (canon_type->id == TypeTableEntryIdInt) { | |
| 1159 | } else if (type_entry->id == TypeTableEntryIdInt) { | |
| 1163 | 1160 | bool is_wrapping = (op_id == IrBinOpAddWrap); |
| 1164 | 1161 | if (is_wrapping) { |
| 1165 | 1162 | return LLVMBuildAdd(g->builder, op1_value, op2_value, ""); |
| 1166 | 1163 | } else if (want_debug_safety) { |
| 1167 | return gen_overflow_op(g, canon_type, AddSubMulAdd, op1_value, op2_value); | |
| 1168 | } else if (canon_type->data.integral.is_signed) { | |
| 1164 | return gen_overflow_op(g, type_entry, AddSubMulAdd, op1_value, op2_value); | |
| 1165 | } else if (type_entry->data.integral.is_signed) { | |
| 1169 | 1166 | return LLVMBuildNSWAdd(g->builder, op1_value, op2_value, ""); |
| 1170 | 1167 | } else { |
| 1171 | 1168 | return LLVMBuildNUWAdd(g->builder, op1_value, op2_value, ""); |
| ... | ... | @@ -1182,36 +1179,36 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, |
| 1182 | 1179 | case IrBinOpBitShiftLeft: |
| 1183 | 1180 | case IrBinOpBitShiftLeftWrap: |
| 1184 | 1181 | { |
| 1185 | assert(canon_type->id == TypeTableEntryIdInt); | |
| 1182 | assert(type_entry->id == TypeTableEntryIdInt); | |
| 1186 | 1183 | bool is_wrapping = (op_id == IrBinOpBitShiftLeftWrap); |
| 1187 | 1184 | if (is_wrapping) { |
| 1188 | 1185 | return LLVMBuildShl(g->builder, op1_value, op2_value, ""); |
| 1189 | 1186 | } else if (want_debug_safety) { |
| 1190 | return gen_overflow_shl_op(g, canon_type, op1_value, op2_value); | |
| 1191 | } else if (canon_type->data.integral.is_signed) { | |
| 1187 | return gen_overflow_shl_op(g, type_entry, op1_value, op2_value); | |
| 1188 | } else if (type_entry->data.integral.is_signed) { | |
| 1192 | 1189 | return ZigLLVMBuildNSWShl(g->builder, op1_value, op2_value, ""); |
| 1193 | 1190 | } else { |
| 1194 | 1191 | return ZigLLVMBuildNUWShl(g->builder, op1_value, op2_value, ""); |
| 1195 | 1192 | } |
| 1196 | 1193 | } |
| 1197 | 1194 | case IrBinOpBitShiftRight: |
| 1198 | assert(canon_type->id == TypeTableEntryIdInt); | |
| 1199 | if (canon_type->data.integral.is_signed) { | |
| 1195 | assert(type_entry->id == TypeTableEntryIdInt); | |
| 1196 | if (type_entry->data.integral.is_signed) { | |
| 1200 | 1197 | return LLVMBuildAShr(g->builder, op1_value, op2_value, ""); |
| 1201 | 1198 | } else { |
| 1202 | 1199 | return LLVMBuildLShr(g->builder, op1_value, op2_value, ""); |
| 1203 | 1200 | } |
| 1204 | 1201 | case IrBinOpSub: |
| 1205 | 1202 | case IrBinOpSubWrap: |
| 1206 | if (canon_type->id == TypeTableEntryIdFloat) { | |
| 1203 | if (type_entry->id == TypeTableEntryIdFloat) { | |
| 1207 | 1204 | return LLVMBuildFSub(g->builder, op1_value, op2_value, ""); |
| 1208 | } else if (canon_type->id == TypeTableEntryIdInt) { | |
| 1205 | } else if (type_entry->id == TypeTableEntryIdInt) { | |
| 1209 | 1206 | bool is_wrapping = (op_id == IrBinOpSubWrap); |
| 1210 | 1207 | if (is_wrapping) { |
| 1211 | 1208 | return LLVMBuildSub(g->builder, op1_value, op2_value, ""); |
| 1212 | 1209 | } else if (want_debug_safety) { |
| 1213 | return gen_overflow_op(g, canon_type, AddSubMulSub, op1_value, op2_value); | |
| 1214 | } else if (canon_type->data.integral.is_signed) { | |
| 1210 | return gen_overflow_op(g, type_entry, AddSubMulSub, op1_value, op2_value); | |
| 1211 | } else if (type_entry->data.integral.is_signed) { | |
| 1215 | 1212 | return LLVMBuildNSWSub(g->builder, op1_value, op2_value, ""); |
| 1216 | 1213 | } else { |
| 1217 | 1214 | return LLVMBuildNUWSub(g->builder, op1_value, op2_value, ""); |
| ... | ... | @@ -1221,15 +1218,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, |
| 1221 | 1218 | } |
| 1222 | 1219 | case IrBinOpMult: |
| 1223 | 1220 | case IrBinOpMultWrap: |
| 1224 | if (canon_type->id == TypeTableEntryIdFloat) { | |
| 1221 | if (type_entry->id == TypeTableEntryIdFloat) { | |
| 1225 | 1222 | return LLVMBuildFMul(g->builder, op1_value, op2_value, ""); |
| 1226 | } else if (canon_type->id == TypeTableEntryIdInt) { | |
| 1223 | } else if (type_entry->id == TypeTableEntryIdInt) { | |
| 1227 | 1224 | bool is_wrapping = (op_id == IrBinOpMultWrap); |
| 1228 | 1225 | if (is_wrapping) { |
| 1229 | 1226 | return LLVMBuildMul(g->builder, op1_value, op2_value, ""); |
| 1230 | 1227 | } else if (want_debug_safety) { |
| 1231 | return gen_overflow_op(g, canon_type, AddSubMulMul, op1_value, op2_value); | |
| 1232 | } else if (canon_type->data.integral.is_signed) { | |
| 1228 | return gen_overflow_op(g, type_entry, AddSubMulMul, op1_value, op2_value); | |
| 1229 | } else if (type_entry->data.integral.is_signed) { | |
| 1233 | 1230 | return LLVMBuildNSWMul(g->builder, op1_value, op2_value, ""); |
| 1234 | 1231 | } else { |
| 1235 | 1232 | return LLVMBuildNUWMul(g->builder, op1_value, op2_value, ""); |
| ... | ... | @@ -1238,9 +1235,9 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, |
| 1238 | 1235 | zig_unreachable(); |
| 1239 | 1236 | } |
| 1240 | 1237 | case IrBinOpDiv: |
| 1241 | return gen_div(g, want_debug_safety, op1_value, op2_value, canon_type, false); | |
| 1238 | return gen_div(g, want_debug_safety, op1_value, op2_value, type_entry, false); | |
| 1242 | 1239 | case IrBinOpRem: |
| 1243 | return gen_rem(g, want_debug_safety, op1_value, op2_value, canon_type); | |
| 1240 | return gen_rem(g, want_debug_safety, op1_value, op2_value, type_entry); | |
| 1244 | 1241 | } |
| 1245 | 1242 | zig_unreachable(); |
| 1246 | 1243 | } |
| ... | ... | @@ -1644,7 +1641,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir |
| 1644 | 1641 | LLVMValueRef value = ir_llvm_value(g, instruction->value); |
| 1645 | 1642 | |
| 1646 | 1643 | assert(instruction->ptr->value.type->id == TypeTableEntryIdPointer); |
| 1647 | TypeTableEntry *ptr_type = get_underlying_type(instruction->ptr->value.type); | |
| 1644 | TypeTableEntry *ptr_type = instruction->ptr->value.type; | |
| 1648 | 1645 | |
| 1649 | 1646 | gen_assign_raw(g, ptr, ptr_type, value); |
| 1650 | 1647 | |
| ... | ... | @@ -1685,9 +1682,9 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI |
| 1685 | 1682 | if (array_ptr_type->data.pointer.unaligned_bit_count != 0) { |
| 1686 | 1683 | return array_ptr_ptr; |
| 1687 | 1684 | } |
| 1688 | TypeTableEntry *canon_child_type = get_underlying_type(array_type->data.array.child_type); | |
| 1689 | if (canon_child_type->id == TypeTableEntryIdStruct && | |
| 1690 | canon_child_type->data.structure.layout == ContainerLayoutPacked) | |
| 1685 | TypeTableEntry *child_type = array_type->data.array.child_type; | |
| 1686 | if (child_type->id == TypeTableEntryIdStruct && | |
| 1687 | child_type->data.structure.layout == ContainerLayoutPacked) | |
| 1691 | 1688 | { |
| 1692 | 1689 | size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count; |
| 1693 | 1690 | if (unaligned_bit_count != 0) { |
| ... | ... | @@ -1701,7 +1698,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI |
| 1701 | 1698 | byte_offset |
| 1702 | 1699 | }; |
| 1703 | 1700 | LLVMValueRef elem_byte_ptr = LLVMBuildInBoundsGEP(g->builder, u8_array_ptr, indices, 1, ""); |
| 1704 | return LLVMBuildBitCast(g->builder, elem_byte_ptr, LLVMPointerType(canon_child_type->type_ref, 0), ""); | |
| 1701 | return LLVMBuildBitCast(g->builder, elem_byte_ptr, LLVMPointerType(child_type->type_ref, 0), ""); | |
| 1705 | 1702 | } |
| 1706 | 1703 | } |
| 1707 | 1704 | LLVMValueRef indices[] = { |
| ... | ... | @@ -2206,8 +2203,8 @@ static LLVMValueRef ir_render_div_exact(CodeGen *g, IrExecutable *executable, Ir |
| 2206 | 2203 | |
| 2207 | 2204 | static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) { |
| 2208 | 2205 | LLVMValueRef target_val = ir_llvm_value(g, instruction->target); |
| 2209 | TypeTableEntry *dest_type = get_underlying_type(instruction->base.value.type); | |
| 2210 | TypeTableEntry *src_type = get_underlying_type(instruction->target->value.type); | |
| 2206 | TypeTableEntry *dest_type = instruction->base.value.type; | |
| 2207 | TypeTableEntry *src_type = instruction->target->value.type; | |
| 2211 | 2208 | if (dest_type == src_type) { |
| 2212 | 2209 | // no-op |
| 2213 | 2210 | return target_val; |
| ... | ... | @@ -2228,7 +2225,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns |
| 2228 | 2225 | |
| 2229 | 2226 | LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); |
| 2230 | 2227 | |
| 2231 | TypeTableEntry *ptr_type = get_underlying_type(instruction->dest_ptr->value.type); | |
| 2228 | TypeTableEntry *ptr_type = instruction->dest_ptr->value.type; | |
| 2232 | 2229 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 2233 | 2230 | |
| 2234 | 2231 | LLVMValueRef is_volatile = ptr_type->data.pointer.is_volatile ? |
| ... | ... | @@ -2256,8 +2253,8 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns |
| 2256 | 2253 | LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); |
| 2257 | 2254 | LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, ""); |
| 2258 | 2255 | |
| 2259 | TypeTableEntry *dest_ptr_type = get_underlying_type(instruction->dest_ptr->value.type); | |
| 2260 | TypeTableEntry *src_ptr_type = get_underlying_type(instruction->src_ptr->value.type); | |
| 2256 | TypeTableEntry *dest_ptr_type = instruction->dest_ptr->value.type; | |
| 2257 | TypeTableEntry *src_ptr_type = instruction->src_ptr->value.type; | |
| 2261 | 2258 | |
| 2262 | 2259 | assert(dest_ptr_type->id == TypeTableEntryIdPointer); |
| 2263 | 2260 | assert(src_ptr_type->id == TypeTableEntryIdPointer); |
| ... | ... | @@ -2407,7 +2404,7 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable |
| 2407 | 2404 | } |
| 2408 | 2405 | |
| 2409 | 2406 | static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) { |
| 2410 | TypeTableEntry *int_type = get_underlying_type(instruction->result_ptr_type); | |
| 2407 | TypeTableEntry *int_type = instruction->result_ptr_type; | |
| 2411 | 2408 | assert(int_type->id == TypeTableEntryIdInt); |
| 2412 | 2409 | |
| 2413 | 2410 | LLVMValueRef op1 = ir_llvm_value(g, instruction->op1); |
| ... | ... | @@ -2444,7 +2441,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable, |
| 2444 | 2441 | return render_shl_with_overflow(g, instruction); |
| 2445 | 2442 | } |
| 2446 | 2443 | |
| 2447 | TypeTableEntry *int_type = get_underlying_type(instruction->result_ptr_type); | |
| 2444 | TypeTableEntry *int_type = instruction->result_ptr_type; | |
| 2448 | 2445 | assert(int_type->id == TypeTableEntryIdInt); |
| 2449 | 2446 | |
| 2450 | 2447 | LLVMValueRef fn_val = get_int_overflow_fn(g, int_type, add_sub_mul); |
| ... | ... | @@ -2467,8 +2464,8 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable, |
| 2467 | 2464 | } |
| 2468 | 2465 | |
| 2469 | 2466 | static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErr *instruction) { |
| 2470 | TypeTableEntry *err_union_type = get_underlying_type(instruction->value->value.type); | |
| 2471 | TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type); | |
| 2467 | TypeTableEntry *err_union_type = instruction->value->value.type; | |
| 2468 | TypeTableEntry *child_type = err_union_type->data.error.child_type; | |
| 2472 | 2469 | LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->value); |
| 2473 | 2470 | |
| 2474 | 2471 | LLVMValueRef err_val; |
| ... | ... | @@ -2484,11 +2481,11 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI |
| 2484 | 2481 | } |
| 2485 | 2482 | |
| 2486 | 2483 | static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) { |
| 2487 | TypeTableEntry *ptr_type = get_underlying_type(instruction->value->value.type); | |
| 2484 | TypeTableEntry *ptr_type = instruction->value->value.type; | |
| 2488 | 2485 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 2489 | 2486 | bool is_volatile = ptr_type->data.pointer.is_volatile; |
| 2490 | TypeTableEntry *err_union_type = get_underlying_type(ptr_type->data.pointer.child_type); | |
| 2491 | TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type); | |
| 2487 | TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type; | |
| 2488 | TypeTableEntry *child_type = err_union_type->data.error.child_type; | |
| 2492 | 2489 | LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value); |
| 2493 | 2490 | LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, is_volatile); |
| 2494 | 2491 | |
| ... | ... | @@ -2501,11 +2498,11 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab |
| 2501 | 2498 | } |
| 2502 | 2499 | |
| 2503 | 2500 | static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) { |
| 2504 | TypeTableEntry *ptr_type = get_underlying_type(instruction->value->value.type); | |
| 2501 | TypeTableEntry *ptr_type = instruction->value->value.type; | |
| 2505 | 2502 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 2506 | 2503 | bool is_volatile = ptr_type->data.pointer.is_volatile; |
| 2507 | TypeTableEntry *err_union_type = get_underlying_type(ptr_type->data.pointer.child_type); | |
| 2508 | TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type); | |
| 2504 | TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type; | |
| 2505 | TypeTableEntry *child_type = err_union_type->data.error.child_type; | |
| 2509 | 2506 | LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value); |
| 2510 | 2507 | LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, is_volatile); |
| 2511 | 2508 | |
| ... | ... | @@ -2941,9 +2938,9 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 2941 | 2938 | break; |
| 2942 | 2939 | } |
| 2943 | 2940 | |
| 2944 | TypeTableEntry *canon_type = get_underlying_type(const_val->type); | |
| 2945 | assert(!canon_type->zero_bits); | |
| 2946 | switch (canon_type->id) { | |
| 2941 | TypeTableEntry *type_entry = const_val->type; | |
| 2942 | assert(!type_entry->zero_bits); | |
| 2943 | switch (type_entry->id) { | |
| 2947 | 2944 | case TypeTableEntryIdInvalid: |
| 2948 | 2945 | case TypeTableEntryIdVar: |
| 2949 | 2946 | case TypeTableEntryIdMetaType: |
| ... | ... | @@ -2956,12 +2953,12 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 2956 | 2953 | case TypeTableEntryIdPureError: |
| 2957 | 2954 | case TypeTableEntryIdEnum: |
| 2958 | 2955 | case TypeTableEntryIdEnumTag: |
| 2959 | case TypeTableEntryIdTypeDecl: | |
| 2960 | 2956 | case TypeTableEntryIdNamespace: |
| 2961 | 2957 | case TypeTableEntryIdBlock: |
| 2962 | 2958 | case TypeTableEntryIdBoundFn: |
| 2963 | 2959 | case TypeTableEntryIdArgTuple: |
| 2964 | 2960 | case TypeTableEntryIdVoid: |
| 2961 | case TypeTableEntryIdOpaque: | |
| 2965 | 2962 | zig_unreachable(); |
| 2966 | 2963 | case TypeTableEntryIdBool: |
| 2967 | 2964 | return LLVMConstInt(big_int_type_ref, const_val->data.x_bool ? 1 : 0, false); |
| ... | ... | @@ -2975,7 +2972,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 2975 | 2972 | { |
| 2976 | 2973 | LLVMValueRef float_val = gen_const_val(g, const_val); |
| 2977 | 2974 | LLVMValueRef int_val = LLVMConstFPToUI(float_val, |
| 2978 | LLVMIntType((unsigned)canon_type->data.floating.bit_count)); | |
| 2975 | LLVMIntType((unsigned)type_entry->data.floating.bit_count)); | |
| 2979 | 2976 | return LLVMConstZExt(int_val, big_int_type_ref); |
| 2980 | 2977 | } |
| 2981 | 2978 | case TypeTableEntryIdPointer: |
| ... | ... | @@ -2992,11 +2989,11 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 2992 | 2989 | zig_panic("TODO bit pack a union"); |
| 2993 | 2990 | case TypeTableEntryIdStruct: |
| 2994 | 2991 | { |
| 2995 | assert(canon_type->data.structure.layout == ContainerLayoutPacked); | |
| 2992 | assert(type_entry->data.structure.layout == ContainerLayoutPacked); | |
| 2996 | 2993 | |
| 2997 | 2994 | LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false); |
| 2998 | for (size_t i = 0; i < canon_type->data.structure.src_field_count; i += 1) { | |
| 2999 | TypeStructField *field = &canon_type->data.structure.fields[i]; | |
| 2995 | for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { | |
| 2996 | TypeStructField *field = &type_entry->data.structure.fields[i]; | |
| 3000 | 2997 | if (field->gen_index == SIZE_MAX) { |
| 3001 | 2998 | continue; |
| 3002 | 2999 | } |
| ... | ... | @@ -3012,37 +3009,35 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 3012 | 3009 | } |
| 3013 | 3010 | |
| 3014 | 3011 | static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3015 | TypeTableEntry *canon_type = get_underlying_type(const_val->type); | |
| 3016 | assert(!canon_type->zero_bits); | |
| 3012 | TypeTableEntry *type_entry = const_val->type; | |
| 3013 | assert(!type_entry->zero_bits); | |
| 3017 | 3014 | |
| 3018 | 3015 | switch (const_val->special) { |
| 3019 | 3016 | case ConstValSpecialRuntime: |
| 3020 | 3017 | zig_unreachable(); |
| 3021 | 3018 | case ConstValSpecialUndef: |
| 3022 | return LLVMGetUndef(canon_type->type_ref); | |
| 3019 | return LLVMGetUndef(type_entry->type_ref); | |
| 3023 | 3020 | case ConstValSpecialStatic: |
| 3024 | 3021 | break; |
| 3025 | 3022 | } |
| 3026 | 3023 | |
| 3027 | switch (canon_type->id) { | |
| 3028 | case TypeTableEntryIdTypeDecl: | |
| 3029 | zig_unreachable(); | |
| 3024 | switch (type_entry->id) { | |
| 3030 | 3025 | case TypeTableEntryIdInt: |
| 3031 | 3026 | case TypeTableEntryIdEnumTag: |
| 3032 | return LLVMConstInt(canon_type->type_ref, bignum_to_twos_complement(&const_val->data.x_bignum), false); | |
| 3027 | return LLVMConstInt(type_entry->type_ref, bignum_to_twos_complement(&const_val->data.x_bignum), false); | |
| 3033 | 3028 | case TypeTableEntryIdPureError: |
| 3034 | 3029 | assert(const_val->data.x_pure_err); |
| 3035 | 3030 | return LLVMConstInt(g->builtin_types.entry_pure_error->type_ref, |
| 3036 | 3031 | const_val->data.x_pure_err->value, false); |
| 3037 | 3032 | case TypeTableEntryIdFloat: |
| 3038 | 3033 | if (const_val->data.x_bignum.kind == BigNumKindFloat) { |
| 3039 | return LLVMConstReal(canon_type->type_ref, const_val->data.x_bignum.data.x_float); | |
| 3034 | return LLVMConstReal(type_entry->type_ref, const_val->data.x_bignum.data.x_float); | |
| 3040 | 3035 | } else { |
| 3041 | 3036 | double x = (double)const_val->data.x_bignum.data.x_uint; |
| 3042 | 3037 | if (const_val->data.x_bignum.is_negative) { |
| 3043 | 3038 | x = -x; |
| 3044 | 3039 | } |
| 3045 | return LLVMConstReal(canon_type->type_ref, x); | |
| 3040 | return LLVMConstReal(type_entry->type_ref, x); | |
| 3046 | 3041 | } |
| 3047 | 3042 | case TypeTableEntryIdBool: |
| 3048 | 3043 | if (const_val->data.x_bool) { |
| ... | ... | @@ -3052,7 +3047,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3052 | 3047 | } |
| 3053 | 3048 | case TypeTableEntryIdMaybe: |
| 3054 | 3049 | { |
| 3055 | TypeTableEntry *child_type = canon_type->data.maybe.child_type; | |
| 3050 | TypeTableEntry *child_type = type_entry->data.maybe.child_type; | |
| 3056 | 3051 | if (child_type->zero_bits) { |
| 3057 | 3052 | return LLVMConstInt(LLVMInt1Type(), const_val->data.x_maybe ? 1 : 0, false); |
| 3058 | 3053 | } else if (child_type->id == TypeTableEntryIdPointer || |
| ... | ... | @@ -3082,12 +3077,12 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3082 | 3077 | } |
| 3083 | 3078 | case TypeTableEntryIdStruct: |
| 3084 | 3079 | { |
| 3085 | LLVMValueRef *fields = allocate<LLVMValueRef>(canon_type->data.structure.gen_field_count); | |
| 3086 | size_t src_field_count = canon_type->data.structure.src_field_count; | |
| 3087 | if (canon_type->data.structure.layout == ContainerLayoutPacked) { | |
| 3080 | LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count); | |
| 3081 | size_t src_field_count = type_entry->data.structure.src_field_count; | |
| 3082 | if (type_entry->data.structure.layout == ContainerLayoutPacked) { | |
| 3088 | 3083 | size_t src_field_index = 0; |
| 3089 | 3084 | while (src_field_index < src_field_count) { |
| 3090 | TypeStructField *type_struct_field = &canon_type->data.structure.fields[src_field_index]; | |
| 3085 | TypeStructField *type_struct_field = &type_entry->data.structure.fields[src_field_index]; | |
| 3091 | 3086 | if (type_struct_field->gen_index == SIZE_MAX) { |
| 3092 | 3087 | src_field_index += 1; |
| 3093 | 3088 | continue; |
| ... | ... | @@ -3095,7 +3090,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3095 | 3090 | |
| 3096 | 3091 | size_t src_field_index_end = src_field_index + 1; |
| 3097 | 3092 | for (; src_field_index_end < src_field_count; src_field_index_end += 1) { |
| 3098 | TypeStructField *it_field = &canon_type->data.structure.fields[src_field_index_end]; | |
| 3093 | TypeStructField *it_field = &type_entry->data.structure.fields[src_field_index_end]; | |
| 3099 | 3094 | if (it_field->gen_index != type_struct_field->gen_index) |
| 3100 | 3095 | break; |
| 3101 | 3096 | } |
| ... | ... | @@ -3104,11 +3099,11 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3104 | 3099 | fields[type_struct_field->gen_index] = |
| 3105 | 3100 | gen_const_val(g, &const_val->data.x_struct.fields[src_field_index]); |
| 3106 | 3101 | } else { |
| 3107 | LLVMTypeRef big_int_type_ref = LLVMStructGetTypeAtIndex(canon_type->type_ref, | |
| 3102 | LLVMTypeRef big_int_type_ref = LLVMStructGetTypeAtIndex(type_entry->type_ref, | |
| 3108 | 3103 | (unsigned)type_struct_field->gen_index); |
| 3109 | 3104 | LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false); |
| 3110 | 3105 | for (size_t i = src_field_index; i < src_field_index_end; i += 1) { |
| 3111 | TypeStructField *it_field = &canon_type->data.structure.fields[i]; | |
| 3106 | TypeStructField *it_field = &type_entry->data.structure.fields[i]; | |
| 3112 | 3107 | if (it_field->gen_index == SIZE_MAX) { |
| 3113 | 3108 | continue; |
| 3114 | 3109 | } |
| ... | ... | @@ -3126,14 +3121,14 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3126 | 3121 | } |
| 3127 | 3122 | } else { |
| 3128 | 3123 | for (uint32_t i = 0; i < src_field_count; i += 1) { |
| 3129 | TypeStructField *type_struct_field = &canon_type->data.structure.fields[i]; | |
| 3124 | TypeStructField *type_struct_field = &type_entry->data.structure.fields[i]; | |
| 3130 | 3125 | if (type_struct_field->gen_index == SIZE_MAX) { |
| 3131 | 3126 | continue; |
| 3132 | 3127 | } |
| 3133 | 3128 | fields[type_struct_field->gen_index] = gen_const_val(g, &const_val->data.x_struct.fields[i]); |
| 3134 | 3129 | } |
| 3135 | 3130 | } |
| 3136 | return LLVMConstNamedStruct(canon_type->type_ref, fields, canon_type->data.structure.gen_field_count); | |
| 3131 | return LLVMConstNamedStruct(type_entry->type_ref, fields, type_entry->data.structure.gen_field_count); | |
| 3137 | 3132 | } |
| 3138 | 3133 | case TypeTableEntryIdUnion: |
| 3139 | 3134 | { |
| ... | ... | @@ -3141,7 +3136,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3141 | 3136 | } |
| 3142 | 3137 | case TypeTableEntryIdArray: |
| 3143 | 3138 | { |
| 3144 | uint64_t len = canon_type->data.array.len; | |
| 3139 | uint64_t len = type_entry->data.array.len; | |
| 3145 | 3140 | LLVMValueRef *values = allocate<LLVMValueRef>(len); |
| 3146 | 3141 | for (uint64_t i = 0; i < len; i += 1) { |
| 3147 | 3142 | ConstExprValue *elem_value = &const_val->data.x_array.elements[i]; |
| ... | ... | @@ -3151,13 +3146,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3151 | 3146 | } |
| 3152 | 3147 | case TypeTableEntryIdEnum: |
| 3153 | 3148 | { |
| 3154 | LLVMTypeRef tag_type_ref = canon_type->data.enumeration.tag_type->type_ref; | |
| 3149 | LLVMTypeRef tag_type_ref = type_entry->data.enumeration.tag_type->type_ref; | |
| 3155 | 3150 | LLVMValueRef tag_value = LLVMConstInt(tag_type_ref, const_val->data.x_enum.tag, false); |
| 3156 | if (canon_type->data.enumeration.gen_field_count == 0) { | |
| 3151 | if (type_entry->data.enumeration.gen_field_count == 0) { | |
| 3157 | 3152 | return tag_value; |
| 3158 | 3153 | } else { |
| 3159 | TypeTableEntry *union_type = canon_type->data.enumeration.union_type; | |
| 3160 | TypeEnumField *enum_field = &canon_type->data.enumeration.fields[const_val->data.x_enum.tag]; | |
| 3154 | TypeTableEntry *union_type = type_entry->data.enumeration.union_type; | |
| 3155 | TypeEnumField *enum_field = &type_entry->data.enumeration.fields[const_val->data.x_enum.tag]; | |
| 3161 | 3156 | assert(enum_field->value == const_val->data.x_enum.tag); |
| 3162 | 3157 | LLVMValueRef union_value; |
| 3163 | 3158 | if (type_has_bits(enum_field->type_entry)) { |
| ... | ... | @@ -3261,7 +3256,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3261 | 3256 | } |
| 3262 | 3257 | case TypeTableEntryIdErrorUnion: |
| 3263 | 3258 | { |
| 3264 | TypeTableEntry *child_type = canon_type->data.error.child_type; | |
| 3259 | TypeTableEntry *child_type = type_entry->data.error.child_type; | |
| 3265 | 3260 | if (!type_has_bits(child_type)) { |
| 3266 | 3261 | uint64_t value = const_val->data.x_err_union.err ? const_val->data.x_err_union.err->value : 0; |
| 3267 | 3262 | return LLVMConstInt(g->err_tag_type->type_ref, value, false); |
| ... | ... | @@ -3296,6 +3291,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 3296 | 3291 | case TypeTableEntryIdBoundFn: |
| 3297 | 3292 | case TypeTableEntryIdVar: |
| 3298 | 3293 | case TypeTableEntryIdArgTuple: |
| 3294 | case TypeTableEntryIdOpaque: | |
| 3299 | 3295 | zig_unreachable(); |
| 3300 | 3296 | |
| 3301 | 3297 | } |
| ... | ... | @@ -4107,7 +4103,7 @@ static void define_builtin_types(CodeGen *g) { |
| 4107 | 4103 | g->builtin_types.entry_i64 = get_int_type(g, true, 64); |
| 4108 | 4104 | |
| 4109 | 4105 | { |
| 4110 | g->builtin_types.entry_c_void = get_typedecl_type(g, "c_void", g->builtin_types.entry_u8); | |
| 4106 | g->builtin_types.entry_c_void = get_opaque_type(g, nullptr, nullptr, "c_void"); | |
| 4111 | 4107 | g->primitive_type_table.put(&g->builtin_types.entry_c_void->name, g->builtin_types.entry_c_void); |
| 4112 | 4108 | } |
| 4113 | 4109 | |
| ... | ... | @@ -4747,6 +4743,7 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) { |
| 4747 | 4743 | zig_unreachable(); |
| 4748 | 4744 | } |
| 4749 | 4745 | } |
| 4746 | case TypeTableEntryIdOpaque: | |
| 4750 | 4747 | case TypeTableEntryIdArray: |
| 4751 | 4748 | case TypeTableEntryIdStruct: |
| 4752 | 4749 | case TypeTableEntryIdErrorUnion: |
| ... | ... | @@ -4754,7 +4751,6 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) { |
| 4754 | 4751 | case TypeTableEntryIdEnum: |
| 4755 | 4752 | case TypeTableEntryIdUnion: |
| 4756 | 4753 | case TypeTableEntryIdFn: |
| 4757 | case TypeTableEntryIdTypeDecl: | |
| 4758 | 4754 | case TypeTableEntryIdEnumTag: |
| 4759 | 4755 | zig_panic("TODO implement get_c_type for more types"); |
| 4760 | 4756 | case TypeTableEntryIdInvalid: |
src/ir.cpp+141-238| ... | ... | @@ -5323,11 +5323,6 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5323 | 5323 | return ir_build_br(irb, scope, node, dest_block, is_comptime); |
| 5324 | 5324 | } |
| 5325 | 5325 | |
| 5326 | static IrInstruction *ir_gen_type_literal(IrBuilder *irb, Scope *scope, AstNode *node) { | |
| 5327 | assert(node->type == NodeTypeTypeLiteral); | |
| 5328 | return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_type); | |
| 5329 | } | |
| 5330 | ||
| 5331 | 5326 | static IrInstruction *ir_gen_error_type(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5332 | 5327 | assert(node->type == NodeTypeErrorType); |
| 5333 | 5328 | return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_pure_error); |
| ... | ... | @@ -5600,8 +5595,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 5600 | 5595 | return ir_lval_wrap(irb, scope, ir_gen_goto(irb, scope, node), lval); |
| 5601 | 5596 | case NodeTypeCompTime: |
| 5602 | 5597 | return ir_gen_comptime(irb, scope, node, lval); |
| 5603 | case NodeTypeTypeLiteral: | |
| 5604 | return ir_lval_wrap(irb, scope, ir_gen_type_literal(irb, scope, node), lval); | |
| 5605 | 5598 | case NodeTypeErrorType: |
| 5606 | 5599 | return ir_lval_wrap(irb, scope, ir_gen_error_type(irb, scope, node), lval); |
| 5607 | 5600 | case NodeTypeBreak: |
| ... | ... | @@ -5628,8 +5621,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 5628 | 5621 | zig_panic("TODO IR gen NodeTypeFnDecl"); |
| 5629 | 5622 | case NodeTypeErrorValueDecl: |
| 5630 | 5623 | zig_panic("TODO IR gen NodeTypeErrorValueDecl"); |
| 5631 | case NodeTypeTypeDecl: | |
| 5632 | zig_panic("TODO IR gen NodeTypeTypeDecl"); | |
| 5633 | 5624 | case NodeTypeTestDecl: |
| 5634 | 5625 | zig_panic("TODO IR gen NodeTypeTestDecl"); |
| 5635 | 5626 | } |
| ... | ... | @@ -5753,13 +5744,6 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, |
| 5753 | 5744 | return ir_add_error_node(ira, source_instruction->source_node, msg); |
| 5754 | 5745 | } |
| 5755 | 5746 | |
| 5756 | static void ir_add_typedef_err_note(IrAnalyze *ira, ErrorMsg *msg, TypeTableEntry *type_entry) { | |
| 5757 | if (type_entry->id == TypeTableEntryIdTypeDecl) { | |
| 5758 | // requires tracking source_node in the typedecl type | |
| 5759 | zig_panic("TODO add error note about typedecls"); | |
| 5760 | } | |
| 5761 | } | |
| 5762 | ||
| 5763 | 5747 | static IrInstruction *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 5764 | 5748 | IrBasicBlock *bb = exec->basic_block_list.at(0); |
| 5765 | 5749 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { |
| ... | ... | @@ -5791,27 +5775,25 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so |
| 5791 | 5775 | } |
| 5792 | 5776 | |
| 5793 | 5777 | static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *other_type) { |
| 5794 | TypeTableEntry *other_type_underlying = get_underlying_type(other_type); | |
| 5795 | ||
| 5796 | if (type_is_invalid(other_type_underlying)) { | |
| 5778 | if (type_is_invalid(other_type)) { | |
| 5797 | 5779 | return false; |
| 5798 | 5780 | } |
| 5799 | 5781 | |
| 5800 | 5782 | ConstExprValue *const_val = &instruction->value; |
| 5801 | 5783 | assert(const_val->special != ConstValSpecialRuntime); |
| 5802 | if (other_type_underlying->id == TypeTableEntryIdFloat) { | |
| 5784 | if (other_type->id == TypeTableEntryIdFloat) { | |
| 5803 | 5785 | return true; |
| 5804 | } else if (other_type_underlying->id == TypeTableEntryIdInt && | |
| 5786 | } else if (other_type->id == TypeTableEntryIdInt && | |
| 5805 | 5787 | const_val->data.x_bignum.kind == BigNumKindInt) |
| 5806 | 5788 | { |
| 5807 | if (bignum_fits_in_bits(&const_val->data.x_bignum, other_type_underlying->data.integral.bit_count, | |
| 5808 | other_type_underlying->data.integral.is_signed)) | |
| 5789 | if (bignum_fits_in_bits(&const_val->data.x_bignum, other_type->data.integral.bit_count, | |
| 5790 | other_type->data.integral.is_signed)) | |
| 5809 | 5791 | { |
| 5810 | 5792 | return true; |
| 5811 | 5793 | } |
| 5812 | } else if ((other_type_underlying->id == TypeTableEntryIdNumLitFloat && | |
| 5794 | } else if ((other_type->id == TypeTableEntryIdNumLitFloat && | |
| 5813 | 5795 | const_val->data.x_bignum.kind == BigNumKindFloat) || |
| 5814 | (other_type_underlying->id == TypeTableEntryIdNumLitInt && | |
| 5796 | (other_type->id == TypeTableEntryIdNumLitInt && | |
| 5815 | 5797 | const_val->data.x_bignum.kind == BigNumKindInt)) |
| 5816 | 5798 | { |
| 5817 | 5799 | return true; |
| ... | ... | @@ -6890,12 +6872,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 6890 | 6872 | TypeTableEntry *wanted_type, IrInstruction *value) |
| 6891 | 6873 | { |
| 6892 | 6874 | TypeTableEntry *actual_type = value->value.type; |
| 6893 | TypeTableEntry *wanted_type_canon = get_underlying_type(wanted_type); | |
| 6894 | TypeTableEntry *actual_type_canon = get_underlying_type(actual_type); | |
| 6895 | ||
| 6896 | 6875 | TypeTableEntry *usize_type = ira->codegen->builtin_types.entry_usize; |
| 6897 | 6876 | |
| 6898 | if (type_is_invalid(wanted_type_canon) || type_is_invalid(actual_type_canon)) { | |
| 6877 | if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { | |
| 6899 | 6878 | return ira->codegen->invalid_instruction; |
| 6900 | 6879 | } |
| 6901 | 6880 | |
| ... | ... | @@ -6908,36 +6887,36 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 6908 | 6887 | } |
| 6909 | 6888 | |
| 6910 | 6889 | // explicit cast from bool to int |
| 6911 | if (wanted_type_canon->id == TypeTableEntryIdInt && | |
| 6912 | actual_type_canon->id == TypeTableEntryIdBool) | |
| 6890 | if (wanted_type->id == TypeTableEntryIdInt && | |
| 6891 | actual_type->id == TypeTableEntryIdBool) | |
| 6913 | 6892 | { |
| 6914 | 6893 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpBoolToInt, false); |
| 6915 | 6894 | } |
| 6916 | 6895 | |
| 6917 | 6896 | // explicit cast from pointer to usize |
| 6918 | if (wanted_type_canon == usize_type && type_is_codegen_pointer(actual_type_canon)) { | |
| 6897 | if (wanted_type == usize_type && type_is_codegen_pointer(actual_type)) { | |
| 6919 | 6898 | return ir_analyze_ptr_to_int(ira, source_instr, value, wanted_type); |
| 6920 | 6899 | } |
| 6921 | 6900 | |
| 6922 | 6901 | // explicit widening or shortening cast |
| 6923 | if ((wanted_type_canon->id == TypeTableEntryIdInt && | |
| 6924 | actual_type_canon->id == TypeTableEntryIdInt) || | |
| 6925 | (wanted_type_canon->id == TypeTableEntryIdFloat && | |
| 6926 | actual_type_canon->id == TypeTableEntryIdFloat)) | |
| 6902 | if ((wanted_type->id == TypeTableEntryIdInt && | |
| 6903 | actual_type->id == TypeTableEntryIdInt) || | |
| 6904 | (wanted_type->id == TypeTableEntryIdFloat && | |
| 6905 | actual_type->id == TypeTableEntryIdFloat)) | |
| 6927 | 6906 | { |
| 6928 | 6907 | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); |
| 6929 | 6908 | } |
| 6930 | 6909 | |
| 6931 | 6910 | // explicit cast from int to float |
| 6932 | if (wanted_type_canon->id == TypeTableEntryIdFloat && | |
| 6933 | actual_type_canon->id == TypeTableEntryIdInt) | |
| 6911 | if (wanted_type->id == TypeTableEntryIdFloat && | |
| 6912 | actual_type->id == TypeTableEntryIdInt) | |
| 6934 | 6913 | { |
| 6935 | 6914 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpIntToFloat, false); |
| 6936 | 6915 | } |
| 6937 | 6916 | |
| 6938 | 6917 | // explicit cast from float to int |
| 6939 | if (wanted_type_canon->id == TypeTableEntryIdInt && | |
| 6940 | actual_type_canon->id == TypeTableEntryIdFloat) | |
| 6918 | if (wanted_type->id == TypeTableEntryIdInt && | |
| 6919 | actual_type->id == TypeTableEntryIdFloat) | |
| 6941 | 6920 | { |
| 6942 | 6921 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpFloatToInt, false); |
| 6943 | 6922 | } |
| ... | ... | @@ -7070,17 +7049,17 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 7070 | 7049 | return ira->codegen->invalid_instruction; |
| 7071 | 7050 | |
| 7072 | 7051 | return cast2; |
| 7073 | } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type_canon)) { | |
| 7052 | } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type)) { | |
| 7074 | 7053 | CastOp op; |
| 7075 | 7054 | if ((actual_type->id == TypeTableEntryIdNumLitFloat && |
| 7076 | wanted_type_canon->id == TypeTableEntryIdFloat) || | |
| 7055 | wanted_type->id == TypeTableEntryIdFloat) || | |
| 7077 | 7056 | (actual_type->id == TypeTableEntryIdNumLitInt && |
| 7078 | wanted_type_canon->id == TypeTableEntryIdInt)) | |
| 7057 | wanted_type->id == TypeTableEntryIdInt)) | |
| 7079 | 7058 | { |
| 7080 | 7059 | op = CastOpNoop; |
| 7081 | } else if (wanted_type_canon->id == TypeTableEntryIdInt) { | |
| 7060 | } else if (wanted_type->id == TypeTableEntryIdInt) { | |
| 7082 | 7061 | op = CastOpFloatToInt; |
| 7083 | } else if (wanted_type_canon->id == TypeTableEntryIdFloat) { | |
| 7062 | } else if (wanted_type->id == TypeTableEntryIdFloat) { | |
| 7084 | 7063 | op = CastOpIntToFloat; |
| 7085 | 7064 | } else { |
| 7086 | 7065 | zig_unreachable(); |
| ... | ... | @@ -7475,7 +7454,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 7475 | 7454 | case TypeTableEntryIdPointer: |
| 7476 | 7455 | case TypeTableEntryIdPureError: |
| 7477 | 7456 | case TypeTableEntryIdFn: |
| 7478 | case TypeTableEntryIdTypeDecl: | |
| 7457 | case TypeTableEntryIdOpaque: | |
| 7479 | 7458 | case TypeTableEntryIdNamespace: |
| 7480 | 7459 | case TypeTableEntryIdBlock: |
| 7481 | 7460 | case TypeTableEntryIdBoundFn: |
| ... | ... | @@ -7709,15 +7688,14 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 7709 | 7688 | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, instructions, 2); |
| 7710 | 7689 | if (type_is_invalid(resolved_type)) |
| 7711 | 7690 | return resolved_type; |
| 7712 | TypeTableEntry *canon_resolved_type = get_underlying_type(resolved_type); | |
| 7713 | 7691 | IrBinOp op_id = bin_op_instruction->op_id; |
| 7714 | 7692 | |
| 7715 | if (canon_resolved_type->id == TypeTableEntryIdInt || | |
| 7716 | canon_resolved_type->id == TypeTableEntryIdNumLitInt) | |
| 7693 | if (resolved_type->id == TypeTableEntryIdInt || | |
| 7694 | resolved_type->id == TypeTableEntryIdNumLitInt) | |
| 7717 | 7695 | { |
| 7718 | 7696 | // int |
| 7719 | } else if ((canon_resolved_type->id == TypeTableEntryIdFloat || | |
| 7720 | canon_resolved_type->id == TypeTableEntryIdNumLitFloat) && | |
| 7697 | } else if ((resolved_type->id == TypeTableEntryIdFloat || | |
| 7698 | resolved_type->id == TypeTableEntryIdNumLitFloat) && | |
| 7721 | 7699 | (op_id == IrBinOpAdd || |
| 7722 | 7700 | op_id == IrBinOpSub || |
| 7723 | 7701 | op_id == IrBinOpMult || |
| ... | ... | @@ -7751,7 +7729,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 7751 | 7729 | bin_op_instruction->base.other = &bin_op_instruction->base; |
| 7752 | 7730 | |
| 7753 | 7731 | int err; |
| 7754 | if ((err = ir_eval_math_op(canon_resolved_type, op1_val, op_id, op2_val, out_val))) { | |
| 7732 | if ((err = ir_eval_math_op(resolved_type, op1_val, op_id, op2_val, out_val))) { | |
| 7755 | 7733 | if (err == ErrorDivByZero) { |
| 7756 | 7734 | ir_add_error_node(ira, bin_op_instruction->base.source_node, |
| 7757 | 7735 | buf_sprintf("division by zero is undefined")); |
| ... | ... | @@ -7776,13 +7754,13 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 7776 | 7754 | |
| 7777 | 7755 | static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 7778 | 7756 | IrInstruction *op1 = instruction->op1->other; |
| 7779 | TypeTableEntry *op1_canon_type = get_underlying_type(op1->value.type); | |
| 7780 | if (type_is_invalid(op1_canon_type)) | |
| 7757 | TypeTableEntry *op1_type = op1->value.type; | |
| 7758 | if (type_is_invalid(op1_type)) | |
| 7781 | 7759 | return ira->codegen->builtin_types.entry_invalid; |
| 7782 | 7760 | |
| 7783 | 7761 | IrInstruction *op2 = instruction->op2->other; |
| 7784 | TypeTableEntry *op2_canon_type = get_underlying_type(op2->value.type); | |
| 7785 | if (type_is_invalid(op2_canon_type)) | |
| 7762 | TypeTableEntry *op2_type = op2->value.type; | |
| 7763 | if (type_is_invalid(op2_type)) | |
| 7786 | 7764 | return ira->codegen->builtin_types.entry_invalid; |
| 7787 | 7765 | |
| 7788 | 7766 | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| ... | ... | @@ -7797,22 +7775,22 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 7797 | 7775 | size_t op1_array_index; |
| 7798 | 7776 | size_t op1_array_end; |
| 7799 | 7777 | TypeTableEntry *child_type; |
| 7800 | if (op1_canon_type->id == TypeTableEntryIdArray) { | |
| 7801 | child_type = op1_canon_type->data.array.child_type; | |
| 7778 | if (op1_type->id == TypeTableEntryIdArray) { | |
| 7779 | child_type = op1_type->data.array.child_type; | |
| 7802 | 7780 | op1_array_val = op1_val; |
| 7803 | 7781 | op1_array_index = 0; |
| 7804 | op1_array_end = op1_canon_type->data.array.len; | |
| 7805 | } else if (op1_canon_type->id == TypeTableEntryIdPointer && | |
| 7806 | op1_canon_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && | |
| 7782 | op1_array_end = op1_type->data.array.len; | |
| 7783 | } else if (op1_type->id == TypeTableEntryIdPointer && | |
| 7784 | op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && | |
| 7807 | 7785 | op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray && |
| 7808 | 7786 | op1_val->data.x_ptr.data.base_array.is_cstr) |
| 7809 | 7787 | { |
| 7810 | child_type = op1_canon_type->data.pointer.child_type; | |
| 7788 | child_type = op1_type->data.pointer.child_type; | |
| 7811 | 7789 | op1_array_val = op1_val->data.x_ptr.data.base_array.array_val; |
| 7812 | 7790 | op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index; |
| 7813 | 7791 | op1_array_end = op1_array_val->type->data.array.len - 1; |
| 7814 | } else if (is_slice(op1_canon_type)) { | |
| 7815 | TypeTableEntry *ptr_type = op1_canon_type->data.structure.fields[slice_ptr_index].type_entry; | |
| 7792 | } else if (is_slice(op1_type)) { | |
| 7793 | TypeTableEntry *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry; | |
| 7816 | 7794 | child_type = ptr_type->data.pointer.child_type; |
| 7817 | 7795 | ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index]; |
| 7818 | 7796 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); |
| ... | ... | @@ -7822,15 +7800,14 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 7822 | 7800 | } else { |
| 7823 | 7801 | ir_add_error(ira, op1, |
| 7824 | 7802 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name))); |
| 7825 | // TODO if meta_type is type decl, add note pointing to type decl declaration | |
| 7826 | 7803 | return ira->codegen->builtin_types.entry_invalid; |
| 7827 | 7804 | } |
| 7828 | 7805 | |
| 7829 | 7806 | ConstExprValue *op2_array_val; |
| 7830 | 7807 | size_t op2_array_index; |
| 7831 | 7808 | size_t op2_array_end; |
| 7832 | if (op2_canon_type->id == TypeTableEntryIdArray) { | |
| 7833 | if (op2_canon_type->data.array.child_type != child_type) { | |
| 7809 | if (op2_type->id == TypeTableEntryIdArray) { | |
| 7810 | if (op2_type->data.array.child_type != child_type) { | |
| 7834 | 7811 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 7835 | 7812 | buf_ptr(&child_type->name), |
| 7836 | 7813 | buf_ptr(&op2->value.type->name))); |
| ... | ... | @@ -7839,8 +7816,8 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 7839 | 7816 | op2_array_val = op2_val; |
| 7840 | 7817 | op2_array_index = 0; |
| 7841 | 7818 | op2_array_end = op2_array_val->type->data.array.len; |
| 7842 | } else if (op2_canon_type->id == TypeTableEntryIdPointer && | |
| 7843 | op2_canon_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && | |
| 7819 | } else if (op2_type->id == TypeTableEntryIdPointer && | |
| 7820 | op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && | |
| 7844 | 7821 | op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray && |
| 7845 | 7822 | op2_val->data.x_ptr.data.base_array.is_cstr) |
| 7846 | 7823 | { |
| ... | ... | @@ -7853,8 +7830,8 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 7853 | 7830 | op2_array_val = op2_val->data.x_ptr.data.base_array.array_val; |
| 7854 | 7831 | op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index; |
| 7855 | 7832 | op2_array_end = op2_array_val->type->data.array.len - 1; |
| 7856 | } else if (is_slice(op2_canon_type)) { | |
| 7857 | TypeTableEntry *ptr_type = op2_canon_type->data.structure.fields[slice_ptr_index].type_entry; | |
| 7833 | } else if (is_slice(op2_type)) { | |
| 7834 | TypeTableEntry *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry; | |
| 7858 | 7835 | if (ptr_type->data.pointer.child_type != child_type) { |
| 7859 | 7836 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 7860 | 7837 | buf_ptr(&child_type->name), |
| ... | ... | @@ -7869,7 +7846,6 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 7869 | 7846 | } else { |
| 7870 | 7847 | ir_add_error(ira, op2, |
| 7871 | 7848 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name))); |
| 7872 | // TODO if meta_type is type decl, add note pointing to type decl declaration | |
| 7873 | 7849 | return ira->codegen->builtin_types.entry_invalid; |
| 7874 | 7850 | } |
| 7875 | 7851 | |
| ... | ... | @@ -7878,7 +7854,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 7878 | 7854 | TypeTableEntry *result_type; |
| 7879 | 7855 | ConstExprValue *out_array_val; |
| 7880 | 7856 | size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); |
| 7881 | if (op1_canon_type->id == TypeTableEntryIdArray || op2_canon_type->id == TypeTableEntryIdArray) { | |
| 7857 | if (op1_type->id == TypeTableEntryIdArray || op2_type->id == TypeTableEntryIdArray) { | |
| 7882 | 7858 | result_type = get_array_type(ira->codegen, child_type, new_len); |
| 7883 | 7859 | |
| 7884 | 7860 | out_array_val = out_val; |
| ... | ... | @@ -7931,14 +7907,13 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp |
| 7931 | 7907 | if (!ir_resolve_usize(ira, op2, &mult_amt)) |
| 7932 | 7908 | return ira->codegen->builtin_types.entry_invalid; |
| 7933 | 7909 | |
| 7934 | TypeTableEntry *array_canon_type = get_underlying_type(op1->value.type); | |
| 7935 | if (array_canon_type->id != TypeTableEntryIdArray) { | |
| 7910 | TypeTableEntry *array_type = op1->value.type; | |
| 7911 | if (array_type->id != TypeTableEntryIdArray) { | |
| 7936 | 7912 | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); |
| 7937 | // TODO if meta_type is type decl, add note pointing to type decl declaration | |
| 7938 | 7913 | return ira->codegen->builtin_types.entry_invalid; |
| 7939 | 7914 | } |
| 7940 | 7915 | |
| 7941 | uint64_t old_array_len = array_canon_type->data.array.len; | |
| 7916 | uint64_t old_array_len = array_type->data.array.len; | |
| 7942 | 7917 | |
| 7943 | 7918 | BigNum array_len; |
| 7944 | 7919 | bignum_init_unsigned(&array_len, old_array_len); |
| ... | ... | @@ -7961,7 +7936,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp |
| 7961 | 7936 | } |
| 7962 | 7937 | assert(i == new_array_len); |
| 7963 | 7938 | |
| 7964 | TypeTableEntry *child_type = array_canon_type->data.array.child_type; | |
| 7939 | TypeTableEntry *child_type = array_type->data.array.child_type; | |
| 7965 | 7940 | return get_array_type(ira->codegen, child_type, new_array_len); |
| 7966 | 7941 | } |
| 7967 | 7942 | |
| ... | ... | @@ -8033,7 +8008,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 8033 | 8008 | AstNode *source_node = decl_var_instruction->base.source_node; |
| 8034 | 8009 | |
| 8035 | 8010 | IrInstruction *casted_init_value = ir_implicit_cast(ira, init_value, explicit_type); |
| 8036 | TypeTableEntry *result_type = get_underlying_type(casted_init_value->value.type); | |
| 8011 | TypeTableEntry *result_type = casted_init_value->value.type; | |
| 8037 | 8012 | if (type_is_invalid(result_type)) { |
| 8038 | 8013 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 8039 | 8014 | } |
| ... | ... | @@ -8041,8 +8016,6 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 8041 | 8016 | bool is_comptime_var = ir_get_var_is_comptime(var); |
| 8042 | 8017 | |
| 8043 | 8018 | switch (result_type->id) { |
| 8044 | case TypeTableEntryIdTypeDecl: | |
| 8045 | zig_unreachable(); | |
| 8046 | 8019 | case TypeTableEntryIdInvalid: |
| 8047 | 8020 | break; // handled above |
| 8048 | 8021 | case TypeTableEntryIdNumLitFloat: |
| ... | ... | @@ -8057,6 +8030,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 8057 | 8030 | case TypeTableEntryIdVar: |
| 8058 | 8031 | case TypeTableEntryIdBlock: |
| 8059 | 8032 | case TypeTableEntryIdNullLit: |
| 8033 | case TypeTableEntryIdOpaque: | |
| 8060 | 8034 | ir_add_error_node(ira, source_node, |
| 8061 | 8035 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name))); |
| 8062 | 8036 | result_type = ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -8670,14 +8644,11 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct |
| 8670 | 8644 | IrInstruction *value = un_op_instruction->value->other; |
| 8671 | 8645 | |
| 8672 | 8646 | TypeTableEntry *meta_type = ir_resolve_type(ira, value); |
| 8673 | TypeTableEntry *underlying_meta_type = get_underlying_type(meta_type); | |
| 8674 | ||
| 8675 | if (type_is_invalid(underlying_meta_type)) | |
| 8647 | if (type_is_invalid(meta_type)) | |
| 8676 | 8648 | return ira->codegen->builtin_types.entry_invalid; |
| 8677 | 8649 | |
| 8678 | 8650 | |
| 8679 | switch (underlying_meta_type->id) { | |
| 8680 | case TypeTableEntryIdTypeDecl: | |
| 8651 | switch (meta_type->id) { | |
| 8681 | 8652 | case TypeTableEntryIdInvalid: // handled above |
| 8682 | 8653 | zig_unreachable(); |
| 8683 | 8654 | |
| ... | ... | @@ -8712,9 +8683,9 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct |
| 8712 | 8683 | case TypeTableEntryIdUnreachable: |
| 8713 | 8684 | case TypeTableEntryIdVar: |
| 8714 | 8685 | case TypeTableEntryIdArgTuple: |
| 8686 | case TypeTableEntryIdOpaque: | |
| 8715 | 8687 | ir_add_error_node(ira, un_op_instruction->base.source_node, |
| 8716 | 8688 | buf_sprintf("unable to wrap type '%s' in error type", buf_ptr(&meta_type->name))); |
| 8717 | // TODO if meta_type is type decl, add note pointing to type decl declaration | |
| 8718 | 8689 | return ira->codegen->builtin_types.entry_invalid; |
| 8719 | 8690 | } |
| 8720 | 8691 | zig_unreachable(); |
| ... | ... | @@ -8756,13 +8727,11 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp |
| 8756 | 8727 | static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 8757 | 8728 | IrInstruction *value = un_op_instruction->value->other; |
| 8758 | 8729 | TypeTableEntry *type_entry = ir_resolve_type(ira, value); |
| 8759 | TypeTableEntry *canon_type = get_underlying_type(type_entry); | |
| 8760 | if (type_is_invalid(canon_type)) | |
| 8730 | if (type_is_invalid(type_entry)) | |
| 8761 | 8731 | return ira->codegen->builtin_types.entry_invalid; |
| 8762 | switch (canon_type->id) { | |
| 8732 | switch (type_entry->id) { | |
| 8763 | 8733 | case TypeTableEntryIdInvalid: |
| 8764 | 8734 | case TypeTableEntryIdVar: |
| 8765 | case TypeTableEntryIdTypeDecl: | |
| 8766 | 8735 | zig_unreachable(); |
| 8767 | 8736 | case TypeTableEntryIdMetaType: |
| 8768 | 8737 | case TypeTableEntryIdVoid: |
| ... | ... | @@ -8793,9 +8762,9 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op |
| 8793 | 8762 | return ira->codegen->builtin_types.entry_type; |
| 8794 | 8763 | } |
| 8795 | 8764 | case TypeTableEntryIdUnreachable: |
| 8765 | case TypeTableEntryIdOpaque: | |
| 8796 | 8766 | ir_add_error_node(ira, un_op_instruction->base.source_node, |
| 8797 | 8767 | buf_sprintf("type '%s' not nullable", buf_ptr(&type_entry->name))); |
| 8798 | // TODO if it's a type decl, put an error note here pointing to the decl | |
| 8799 | 8768 | return ira->codegen->builtin_types.entry_invalid; |
| 8800 | 8769 | } |
| 8801 | 8770 | zig_unreachable(); |
| ... | ... | @@ -9406,23 +9375,6 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 9406 | 9375 | return ir_analyze_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry, |
| 9407 | 9376 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 9408 | 9377 | } |
| 9409 | case TldIdTypeDef: | |
| 9410 | { | |
| 9411 | TldTypeDef *tld_typedef = (TldTypeDef *)tld; | |
| 9412 | assert(tld_typedef->type_entry); | |
| 9413 | ||
| 9414 | // TODO instead of allocating this every time, put it in the tld value and we can reference | |
| 9415 | // the same one every time | |
| 9416 | ConstExprValue *const_val = allocate<ConstExprValue>(1); | |
| 9417 | const_val->special = ConstValSpecialStatic; | |
| 9418 | const_val->type = ira->codegen->builtin_types.entry_type; | |
| 9419 | const_val->data.x_type = tld_typedef->type_entry; | |
| 9420 | ||
| 9421 | bool ptr_is_const = true; | |
| 9422 | bool ptr_is_volatile = false; | |
| 9423 | return ir_analyze_const_ptr(ira, source_instruction, const_val, ira->codegen->builtin_types.entry_type, | |
| 9424 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); | |
| 9425 | } | |
| 9426 | 9378 | } |
| 9427 | 9379 | zig_unreachable(); |
| 9428 | 9380 | } |
| ... | ... | @@ -9726,9 +9678,9 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi |
| 9726 | 9678 | case TypeTableEntryIdEnum: |
| 9727 | 9679 | case TypeTableEntryIdUnion: |
| 9728 | 9680 | case TypeTableEntryIdFn: |
| 9729 | case TypeTableEntryIdTypeDecl: | |
| 9730 | 9681 | case TypeTableEntryIdEnumTag: |
| 9731 | 9682 | case TypeTableEntryIdArgTuple: |
| 9683 | case TypeTableEntryIdOpaque: | |
| 9732 | 9684 | { |
| 9733 | 9685 | ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base); |
| 9734 | 9686 | out_val->data.x_type = type_entry; |
| ... | ... | @@ -9990,12 +9942,10 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 9990 | 9942 | bool is_const = slice_type_instruction->is_const; |
| 9991 | 9943 | |
| 9992 | 9944 | TypeTableEntry *resolved_child_type = ir_resolve_type(ira, child_type); |
| 9993 | TypeTableEntry *canon_child_type = get_underlying_type(resolved_child_type); | |
| 9994 | if (type_is_invalid(canon_child_type)) | |
| 9945 | if (type_is_invalid(resolved_child_type)) | |
| 9995 | 9946 | return ira->codegen->builtin_types.entry_invalid; |
| 9996 | 9947 | |
| 9997 | switch (canon_child_type->id) { | |
| 9998 | case TypeTableEntryIdTypeDecl: | |
| 9948 | switch (resolved_child_type->id) { | |
| 9999 | 9949 | case TypeTableEntryIdInvalid: // handled above |
| 10000 | 9950 | zig_unreachable(); |
| 10001 | 9951 | case TypeTableEntryIdVar: |
| ... | ... | @@ -10004,9 +9954,9 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 10004 | 9954 | case TypeTableEntryIdNullLit: |
| 10005 | 9955 | case TypeTableEntryIdBlock: |
| 10006 | 9956 | case TypeTableEntryIdArgTuple: |
| 9957 | case TypeTableEntryIdOpaque: | |
| 10007 | 9958 | ir_add_error_node(ira, slice_type_instruction->base.source_node, |
| 10008 | 9959 | buf_sprintf("slice of type '%s' not allowed", buf_ptr(&resolved_child_type->name))); |
| 10009 | // TODO if this is a typedecl, add error note showing the declaration of the type decl | |
| 10010 | 9960 | return ira->codegen->builtin_types.entry_invalid; |
| 10011 | 9961 | case TypeTableEntryIdMetaType: |
| 10012 | 9962 | case TypeTableEntryIdVoid: |
| ... | ... | @@ -10100,11 +10050,9 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 10100 | 10050 | |
| 10101 | 10051 | IrInstruction *child_type_value = array_type_instruction->child_type->other; |
| 10102 | 10052 | TypeTableEntry *child_type = ir_resolve_type(ira, child_type_value); |
| 10103 | TypeTableEntry *canon_child_type = get_underlying_type(child_type); | |
| 10104 | if (type_is_invalid(canon_child_type)) | |
| 10053 | if (type_is_invalid(child_type)) | |
| 10105 | 10054 | return ira->codegen->builtin_types.entry_invalid; |
| 10106 | switch (canon_child_type->id) { | |
| 10107 | case TypeTableEntryIdTypeDecl: | |
| 10055 | switch (child_type->id) { | |
| 10108 | 10056 | case TypeTableEntryIdInvalid: // handled above |
| 10109 | 10057 | zig_unreachable(); |
| 10110 | 10058 | case TypeTableEntryIdVar: |
| ... | ... | @@ -10113,9 +10061,9 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 10113 | 10061 | case TypeTableEntryIdNullLit: |
| 10114 | 10062 | case TypeTableEntryIdBlock: |
| 10115 | 10063 | case TypeTableEntryIdArgTuple: |
| 10064 | case TypeTableEntryIdOpaque: | |
| 10116 | 10065 | ir_add_error_node(ira, array_type_instruction->base.source_node, |
| 10117 | 10066 | buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name))); |
| 10118 | // TODO if this is a typedecl, add error note showing the declaration of the type decl | |
| 10119 | 10067 | return ira->codegen->builtin_types.entry_invalid; |
| 10120 | 10068 | case TypeTableEntryIdMetaType: |
| 10121 | 10069 | case TypeTableEntryIdVoid: |
| ... | ... | @@ -10172,15 +10120,13 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 10172 | 10120 | { |
| 10173 | 10121 | IrInstruction *type_value = size_of_instruction->type_value->other; |
| 10174 | 10122 | TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); |
| 10175 | TypeTableEntry *canon_type_entry = get_underlying_type(type_entry); | |
| 10176 | 10123 | |
| 10177 | 10124 | ensure_complete_type(ira->codegen, type_entry); |
| 10178 | if (type_is_invalid(canon_type_entry)) | |
| 10125 | if (type_is_invalid(type_entry)) | |
| 10179 | 10126 | return ira->codegen->builtin_types.entry_invalid; |
| 10180 | 10127 | |
| 10181 | switch (canon_type_entry->id) { | |
| 10128 | switch (type_entry->id) { | |
| 10182 | 10129 | case TypeTableEntryIdInvalid: // handled above |
| 10183 | case TypeTableEntryIdTypeDecl: | |
| 10184 | 10130 | zig_unreachable(); |
| 10185 | 10131 | case TypeTableEntryIdVar: |
| 10186 | 10132 | case TypeTableEntryIdUnreachable: |
| ... | ... | @@ -10193,9 +10139,9 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 10193 | 10139 | case TypeTableEntryIdMetaType: |
| 10194 | 10140 | case TypeTableEntryIdNamespace: |
| 10195 | 10141 | case TypeTableEntryIdArgTuple: |
| 10142 | case TypeTableEntryIdOpaque: | |
| 10196 | 10143 | ir_add_error_node(ira, size_of_instruction->base.source_node, |
| 10197 | 10144 | buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name))); |
| 10198 | // TODO if this is a typedecl, add error note showing the declaration of the type decl | |
| 10199 | 10145 | return ira->codegen->builtin_types.entry_invalid; |
| 10200 | 10146 | case TypeTableEntryIdVoid: |
| 10201 | 10147 | case TypeTableEntryIdBool: |
| ... | ... | @@ -10516,15 +10462,13 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 10516 | 10462 | if (pointee_val->special == ConstValSpecialRuntime) |
| 10517 | 10463 | pointee_val = nullptr; |
| 10518 | 10464 | } |
| 10519 | TypeTableEntry *canon_target_type = get_underlying_type(target_type); | |
| 10520 | 10465 | ensure_complete_type(ira->codegen, target_type); |
| 10521 | if (type_is_invalid(canon_target_type)) | |
| 10466 | if (type_is_invalid(target_type)) | |
| 10522 | 10467 | return ira->codegen->builtin_types.entry_invalid; |
| 10523 | 10468 | |
| 10524 | switch (canon_target_type->id) { | |
| 10469 | switch (target_type->id) { | |
| 10525 | 10470 | case TypeTableEntryIdInvalid: |
| 10526 | 10471 | case TypeTableEntryIdVar: |
| 10527 | case TypeTableEntryIdTypeDecl: | |
| 10528 | 10472 | zig_unreachable(); |
| 10529 | 10473 | case TypeTableEntryIdMetaType: |
| 10530 | 10474 | case TypeTableEntryIdVoid: |
| ... | ... | @@ -10576,9 +10520,9 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 10576 | 10520 | case TypeTableEntryIdBlock: |
| 10577 | 10521 | case TypeTableEntryIdBoundFn: |
| 10578 | 10522 | case TypeTableEntryIdArgTuple: |
| 10523 | case TypeTableEntryIdOpaque: | |
| 10579 | 10524 | ir_add_error(ira, &switch_target_instruction->base, |
| 10580 | 10525 | buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); |
| 10581 | // TODO if this is a typedecl, add error note showing the declaration of the type decl | |
| 10582 | 10526 | return ira->codegen->builtin_types.entry_invalid; |
| 10583 | 10527 | } |
| 10584 | 10528 | zig_unreachable(); |
| ... | ... | @@ -10630,9 +10574,8 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr |
| 10630 | 10574 | return get_pointer_to_type(ira->codegen, field->type_entry, |
| 10631 | 10575 | target_value_ptr->value.type->data.pointer.is_const); |
| 10632 | 10576 | } else { |
| 10633 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, | |
| 10577 | ir_add_error(ira, &instruction->base, | |
| 10634 | 10578 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); |
| 10635 | ir_add_typedef_err_note(ira, msg, target_type); | |
| 10636 | 10579 | return ira->codegen->builtin_types.entry_invalid; |
| 10637 | 10580 | } |
| 10638 | 10581 | } |
| ... | ... | @@ -10743,13 +10686,13 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira, |
| 10743 | 10686 | IrInstructionArrayLen *array_len_instruction) |
| 10744 | 10687 | { |
| 10745 | 10688 | IrInstruction *array_value = array_len_instruction->array_value->other; |
| 10746 | TypeTableEntry *canon_type = get_underlying_type(array_value->value.type); | |
| 10747 | if (type_is_invalid(canon_type)) { | |
| 10689 | TypeTableEntry *type_entry = array_value->value.type; | |
| 10690 | if (type_is_invalid(type_entry)) { | |
| 10748 | 10691 | return ira->codegen->builtin_types.entry_invalid; |
| 10749 | } else if (canon_type->id == TypeTableEntryIdArray) { | |
| 10692 | } else if (type_entry->id == TypeTableEntryIdArray) { | |
| 10750 | 10693 | return ir_analyze_const_usize(ira, &array_len_instruction->base, |
| 10751 | canon_type->data.array.len); | |
| 10752 | } else if (is_slice(canon_type)) { | |
| 10694 | type_entry->data.array.len); | |
| 10695 | } else if (is_slice(type_entry)) { | |
| 10753 | 10696 | if (array_value->value.special != ConstValSpecialRuntime) { |
| 10754 | 10697 | ConstExprValue *len_val = &array_value->value.data.x_struct.fields[slice_len_index]; |
| 10755 | 10698 | if (len_val->special != ConstValSpecialRuntime) { |
| ... | ... | @@ -10757,7 +10700,7 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira, |
| 10757 | 10700 | len_val->data.x_bignum.data.x_uint); |
| 10758 | 10701 | } |
| 10759 | 10702 | } |
| 10760 | TypeStructField *field = &canon_type->data.structure.fields[slice_len_index]; | |
| 10703 | TypeStructField *field = &type_entry->data.structure.fields[slice_len_index]; | |
| 10761 | 10704 | IrInstruction *len_ptr = ir_build_struct_field_ptr(&ira->new_irb, array_len_instruction->base.scope, |
| 10762 | 10705 | array_len_instruction->base.source_node, array_value, field); |
| 10763 | 10706 | len_ptr->value.type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_usize, true); |
| ... | ... | @@ -10766,7 +10709,6 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira, |
| 10766 | 10709 | } else { |
| 10767 | 10710 | ir_add_error_node(ira, array_len_instruction->base.source_node, |
| 10768 | 10711 | buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->value.type->name))); |
| 10769 | // TODO if this is a typedecl, add error note showing the declaration of the type decl | |
| 10770 | 10712 | return ira->codegen->builtin_types.entry_invalid; |
| 10771 | 10713 | } |
| 10772 | 10714 | } |
| ... | ... | @@ -11049,29 +10991,28 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_ |
| 11049 | 10991 | IrInstruction *target_type_value, bool is_max) |
| 11050 | 10992 | { |
| 11051 | 10993 | TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value); |
| 11052 | TypeTableEntry *canon_type = get_underlying_type(target_type); | |
| 11053 | if (type_is_invalid(canon_type)) | |
| 10994 | if (type_is_invalid(target_type)) | |
| 11054 | 10995 | return ira->codegen->builtin_types.entry_invalid; |
| 11055 | switch (canon_type->id) { | |
| 10996 | switch (target_type->id) { | |
| 11056 | 10997 | case TypeTableEntryIdInvalid: |
| 11057 | 10998 | zig_unreachable(); |
| 11058 | 10999 | case TypeTableEntryIdInt: |
| 11059 | 11000 | { |
| 11060 | 11001 | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); |
| 11061 | eval_min_max_value(ira->codegen, canon_type, out_val, is_max); | |
| 11002 | eval_min_max_value(ira->codegen, target_type, out_val, is_max); | |
| 11062 | 11003 | return ira->codegen->builtin_types.entry_num_lit_int; |
| 11063 | 11004 | } |
| 11064 | 11005 | case TypeTableEntryIdFloat: |
| 11065 | 11006 | { |
| 11066 | 11007 | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); |
| 11067 | eval_min_max_value(ira->codegen, canon_type, out_val, is_max); | |
| 11008 | eval_min_max_value(ira->codegen, target_type, out_val, is_max); | |
| 11068 | 11009 | return ira->codegen->builtin_types.entry_num_lit_float; |
| 11069 | 11010 | } |
| 11070 | 11011 | case TypeTableEntryIdBool: |
| 11071 | 11012 | case TypeTableEntryIdVoid: |
| 11072 | 11013 | { |
| 11073 | 11014 | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); |
| 11074 | eval_min_max_value(ira->codegen, canon_type, out_val, is_max); | |
| 11015 | eval_min_max_value(ira->codegen, target_type, out_val, is_max); | |
| 11075 | 11016 | return target_type; |
| 11076 | 11017 | } |
| 11077 | 11018 | case TypeTableEntryIdEnumTag: |
| ... | ... | @@ -11092,18 +11033,17 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_ |
| 11092 | 11033 | case TypeTableEntryIdEnum: |
| 11093 | 11034 | case TypeTableEntryIdUnion: |
| 11094 | 11035 | case TypeTableEntryIdFn: |
| 11095 | case TypeTableEntryIdTypeDecl: | |
| 11096 | 11036 | case TypeTableEntryIdNamespace: |
| 11097 | 11037 | case TypeTableEntryIdBlock: |
| 11098 | 11038 | case TypeTableEntryIdBoundFn: |
| 11099 | 11039 | case TypeTableEntryIdArgTuple: |
| 11040 | case TypeTableEntryIdOpaque: | |
| 11100 | 11041 | { |
| 11101 | 11042 | const char *err_format = is_max ? |
| 11102 | 11043 | "no max value available for type '%s'" : |
| 11103 | 11044 | "no min value available for type '%s'"; |
| 11104 | 11045 | ir_add_error(ira, source_instruction, |
| 11105 | 11046 | buf_sprintf(err_format, buf_ptr(&target_type->name))); |
| 11106 | // TODO if this is a typedecl, add error note showing the declaration of the type decl | |
| 11107 | 11047 | return ira->codegen->builtin_types.entry_invalid; |
| 11108 | 11048 | } |
| 11109 | 11049 | } |
| ... | ... | @@ -11508,14 +11448,11 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru |
| 11508 | 11448 | if (type_is_invalid(result_type)) |
| 11509 | 11449 | return ira->codegen->builtin_types.entry_invalid; |
| 11510 | 11450 | |
| 11511 | TypeTableEntry *canon_type = get_underlying_type(result_type); | |
| 11512 | ||
| 11513 | if (canon_type->id != TypeTableEntryIdInt && | |
| 11514 | canon_type->id != TypeTableEntryIdNumLitInt) | |
| 11451 | if (result_type->id != TypeTableEntryIdInt && | |
| 11452 | result_type->id != TypeTableEntryIdNumLitInt) | |
| 11515 | 11453 | { |
| 11516 | 11454 | ir_add_error(ira, &instruction->base, |
| 11517 | 11455 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&result_type->name))); |
| 11518 | // TODO if meta_type is type decl, add note pointing to type decl declaration | |
| 11519 | 11456 | return ira->codegen->builtin_types.entry_invalid; |
| 11520 | 11457 | } |
| 11521 | 11458 | |
| ... | ... | @@ -11563,49 +11500,42 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru |
| 11563 | 11500 | static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) { |
| 11564 | 11501 | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 11565 | 11502 | TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); |
| 11566 | TypeTableEntry *canon_dest_type = get_underlying_type(dest_type); | |
| 11567 | ||
| 11568 | if (type_is_invalid(canon_dest_type)) | |
| 11503 | if (type_is_invalid(dest_type)) | |
| 11569 | 11504 | return ira->codegen->builtin_types.entry_invalid; |
| 11570 | 11505 | |
| 11571 | if (canon_dest_type->id != TypeTableEntryIdInt && | |
| 11572 | canon_dest_type->id != TypeTableEntryIdNumLitInt) | |
| 11506 | if (dest_type->id != TypeTableEntryIdInt && | |
| 11507 | dest_type->id != TypeTableEntryIdNumLitInt) | |
| 11573 | 11508 | { |
| 11574 | 11509 | ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 11575 | // TODO if meta_type is type decl, add note pointing to type decl declaration | |
| 11576 | 11510 | return ira->codegen->builtin_types.entry_invalid; |
| 11577 | 11511 | } |
| 11578 | 11512 | |
| 11579 | 11513 | IrInstruction *target = instruction->target->other; |
| 11580 | 11514 | TypeTableEntry *src_type = target->value.type; |
| 11581 | TypeTableEntry *canon_src_type = get_underlying_type(src_type); | |
| 11582 | if (type_is_invalid(canon_src_type)) | |
| 11515 | if (type_is_invalid(src_type)) | |
| 11583 | 11516 | return ira->codegen->builtin_types.entry_invalid; |
| 11584 | 11517 | |
| 11585 | if (canon_src_type->id != TypeTableEntryIdInt && | |
| 11586 | canon_src_type->id != TypeTableEntryIdNumLitInt) | |
| 11518 | if (src_type->id != TypeTableEntryIdInt && | |
| 11519 | src_type->id != TypeTableEntryIdNumLitInt) | |
| 11587 | 11520 | { |
| 11588 | 11521 | ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); |
| 11589 | // TODO if meta_type is type decl, add note pointing to type decl declaration | |
| 11590 | 11522 | return ira->codegen->builtin_types.entry_invalid; |
| 11591 | 11523 | } |
| 11592 | 11524 | |
| 11593 | if (canon_src_type->data.integral.is_signed != canon_dest_type->data.integral.is_signed) { | |
| 11594 | const char *sign_str = canon_dest_type->data.integral.is_signed ? "signed" : "unsigned"; | |
| 11525 | if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) { | |
| 11526 | const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned"; | |
| 11595 | 11527 | ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name))); |
| 11596 | // TODO if meta_type is type decl, add note pointing to type decl declaration | |
| 11597 | 11528 | return ira->codegen->builtin_types.entry_invalid; |
| 11598 | } else if (canon_src_type->data.integral.bit_count < canon_dest_type->data.integral.bit_count) { | |
| 11529 | } else if (src_type->data.integral.bit_count < dest_type->data.integral.bit_count) { | |
| 11599 | 11530 | ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'", |
| 11600 | 11531 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); |
| 11601 | // TODO if meta_type is type decl, add note pointing to type decl declaration | |
| 11602 | 11532 | return ira->codegen->builtin_types.entry_invalid; |
| 11603 | 11533 | } |
| 11604 | 11534 | |
| 11605 | 11535 | if (target->value.special == ConstValSpecialStatic) { |
| 11606 | 11536 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 11607 | 11537 | bignum_init_bignum(&out_val->data.x_bignum, &target->value.data.x_bignum); |
| 11608 | bignum_truncate(&out_val->data.x_bignum, canon_dest_type->data.integral.bit_count); | |
| 11538 | bignum_truncate(&out_val->data.x_bignum, dest_type->data.integral.bit_count); | |
| 11609 | 11539 | return dest_type; |
| 11610 | 11540 | } |
| 11611 | 11541 | |
| ... | ... | @@ -11663,7 +11593,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi |
| 11663 | 11593 | if (type_is_invalid(count_value->value.type)) |
| 11664 | 11594 | return ira->codegen->builtin_types.entry_invalid; |
| 11665 | 11595 | |
| 11666 | TypeTableEntry *dest_uncasted_type = get_underlying_type(dest_ptr->value.type); | |
| 11596 | TypeTableEntry *dest_uncasted_type = dest_ptr->value.type; | |
| 11667 | 11597 | bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) && |
| 11668 | 11598 | dest_uncasted_type->data.pointer.is_volatile; |
| 11669 | 11599 | |
| ... | ... | @@ -11749,8 +11679,8 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi |
| 11749 | 11679 | if (type_is_invalid(count_value->value.type)) |
| 11750 | 11680 | return ira->codegen->builtin_types.entry_invalid; |
| 11751 | 11681 | |
| 11752 | TypeTableEntry *dest_uncasted_type = get_underlying_type(dest_ptr->value.type); | |
| 11753 | TypeTableEntry *src_uncasted_type = get_underlying_type(src_ptr->value.type); | |
| 11682 | TypeTableEntry *dest_uncasted_type = dest_ptr->value.type; | |
| 11683 | TypeTableEntry *src_uncasted_type = src_ptr->value.type; | |
| 11754 | 11684 | bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) && |
| 11755 | 11685 | dest_uncasted_type->data.pointer.is_volatile; |
| 11756 | 11686 | bool src_is_volatile = (src_uncasted_type->id == TypeTableEntryIdPointer) && |
| ... | ... | @@ -11866,8 +11796,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 11866 | 11796 | |
| 11867 | 11797 | TypeTableEntry *ptr_type = ptr_ptr->value.type; |
| 11868 | 11798 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 11869 | TypeTableEntry *non_canon_array_type = ptr_type->data.pointer.child_type; | |
| 11870 | TypeTableEntry *canon_array_type = get_underlying_type(non_canon_array_type); | |
| 11799 | TypeTableEntry *array_type = ptr_type->data.pointer.child_type; | |
| 11871 | 11800 | |
| 11872 | 11801 | IrInstruction *start = instruction->start->other; |
| 11873 | 11802 | if (type_is_invalid(start->value.type)) |
| ... | ... | @@ -11892,22 +11821,21 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 11892 | 11821 | |
| 11893 | 11822 | TypeTableEntry *return_type; |
| 11894 | 11823 | |
| 11895 | if (canon_array_type->id == TypeTableEntryIdArray) { | |
| 11896 | return_type = get_slice_type(ira->codegen, canon_array_type->data.array.child_type, instruction->is_const); | |
| 11897 | } else if (canon_array_type->id == TypeTableEntryIdPointer) { | |
| 11898 | return_type = get_slice_type(ira->codegen, canon_array_type->data.pointer.child_type, instruction->is_const); | |
| 11824 | if (array_type->id == TypeTableEntryIdArray) { | |
| 11825 | return_type = get_slice_type(ira->codegen, array_type->data.array.child_type, instruction->is_const); | |
| 11826 | } else if (array_type->id == TypeTableEntryIdPointer) { | |
| 11827 | return_type = get_slice_type(ira->codegen, array_type->data.pointer.child_type, instruction->is_const); | |
| 11899 | 11828 | if (!end) { |
| 11900 | 11829 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value")); |
| 11901 | 11830 | return ira->codegen->builtin_types.entry_invalid; |
| 11902 | 11831 | } |
| 11903 | } else if (is_slice(canon_array_type)) { | |
| 11832 | } else if (is_slice(array_type)) { | |
| 11904 | 11833 | return_type = get_slice_type(ira->codegen, |
| 11905 | canon_array_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, | |
| 11834 | array_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, | |
| 11906 | 11835 | instruction->is_const); |
| 11907 | 11836 | } else { |
| 11908 | 11837 | ir_add_error(ira, &instruction->base, |
| 11909 | buf_sprintf("slice of non-array type '%s'", buf_ptr(&non_canon_array_type->name))); | |
| 11910 | // TODO if this is a typedecl, add error note showing the declaration of the type decl | |
| 11838 | buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name))); | |
| 11911 | 11839 | return ira->codegen->builtin_types.entry_invalid; |
| 11912 | 11840 | } |
| 11913 | 11841 | |
| ... | ... | @@ -11919,12 +11847,12 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 11919 | 11847 | ConstExprValue *parent_ptr; |
| 11920 | 11848 | size_t abs_offset; |
| 11921 | 11849 | size_t rel_end; |
| 11922 | if (canon_array_type->id == TypeTableEntryIdArray) { | |
| 11850 | if (array_type->id == TypeTableEntryIdArray) { | |
| 11923 | 11851 | array_val = const_ptr_pointee(&ptr_ptr->value); |
| 11924 | 11852 | abs_offset = 0; |
| 11925 | rel_end = canon_array_type->data.array.len; | |
| 11853 | rel_end = array_type->data.array.len; | |
| 11926 | 11854 | parent_ptr = nullptr; |
| 11927 | } else if (canon_array_type->id == TypeTableEntryIdPointer) { | |
| 11855 | } else if (array_type->id == TypeTableEntryIdPointer) { | |
| 11928 | 11856 | parent_ptr = const_ptr_pointee(&ptr_ptr->value); |
| 11929 | 11857 | switch (parent_ptr->data.x_ptr.special) { |
| 11930 | 11858 | case ConstPtrSpecialInvalid: |
| ... | ... | @@ -11946,7 +11874,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 11946 | 11874 | array_val = nullptr; |
| 11947 | 11875 | break; |
| 11948 | 11876 | } |
| 11949 | } else if (is_slice(canon_array_type)) { | |
| 11877 | } else if (is_slice(array_type)) { | |
| 11950 | 11878 | ConstExprValue *slice_ptr = const_ptr_pointee(&ptr_ptr->value); |
| 11951 | 11879 | parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index]; |
| 11952 | 11880 | ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index]; |
| ... | ... | @@ -12005,7 +11933,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 12005 | 11933 | if (array_val) { |
| 12006 | 11934 | size_t index = abs_offset + start_scalar; |
| 12007 | 11935 | init_const_ptr_array(ira->codegen, ptr_val, array_val, index, instruction->is_const); |
| 12008 | if (canon_array_type->id == TypeTableEntryIdArray) { | |
| 11936 | if (array_type->id == TypeTableEntryIdArray) { | |
| 12009 | 11937 | ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut; |
| 12010 | 11938 | } |
| 12011 | 11939 | } else { |
| ... | ... | @@ -12045,17 +11973,16 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns |
| 12045 | 11973 | if (type_is_invalid(container->value.type)) |
| 12046 | 11974 | return ira->codegen->builtin_types.entry_invalid; |
| 12047 | 11975 | TypeTableEntry *container_type = ir_resolve_type(ira, container); |
| 12048 | TypeTableEntry *canon_type = get_underlying_type(container_type); | |
| 12049 | 11976 | |
| 12050 | 11977 | uint64_t result; |
| 12051 | if (type_is_invalid(canon_type)) { | |
| 12052 | return ira->codegen->builtin_types.entry_invalid; | |
| 12053 | } else if (canon_type->id == TypeTableEntryIdEnum) { | |
| 12054 | result = canon_type->data.enumeration.src_field_count; | |
| 12055 | } else if (canon_type->id == TypeTableEntryIdStruct) { | |
| 12056 | result = canon_type->data.structure.src_field_count; | |
| 12057 | } else if (canon_type->id == TypeTableEntryIdUnion) { | |
| 12058 | result = canon_type->data.unionation.src_field_count; | |
| 11978 | if (type_is_invalid(container_type)) { | |
| 11979 | return ira->codegen->builtin_types.entry_invalid; | |
| 11980 | } else if (container_type->id == TypeTableEntryIdEnum) { | |
| 11981 | result = container_type->data.enumeration.src_field_count; | |
| 11982 | } else if (container_type->id == TypeTableEntryIdStruct) { | |
| 11983 | result = container_type->data.structure.src_field_count; | |
| 11984 | } else if (container_type->id == TypeTableEntryIdUnion) { | |
| 11985 | result = container_type->data.unionation.src_field_count; | |
| 12059 | 11986 | } else { |
| 12060 | 11987 | ir_add_error(ira, &instruction->base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name))); |
| 12061 | 11988 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -12112,14 +12039,12 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 12112 | 12039 | if (type_is_invalid(type_value->value.type)) |
| 12113 | 12040 | return ira->codegen->builtin_types.entry_invalid; |
| 12114 | 12041 | TypeTableEntry *dest_type = ir_resolve_type(ira, type_value); |
| 12115 | TypeTableEntry *canon_type = get_underlying_type(dest_type); | |
| 12116 | if (type_is_invalid(canon_type)) | |
| 12042 | if (type_is_invalid(dest_type)) | |
| 12117 | 12043 | return ira->codegen->builtin_types.entry_invalid; |
| 12118 | 12044 | |
| 12119 | if (canon_type->id != TypeTableEntryIdInt) { | |
| 12045 | if (dest_type->id != TypeTableEntryIdInt) { | |
| 12120 | 12046 | ir_add_error(ira, type_value, |
| 12121 | 12047 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 12122 | // TODO if this is a typedecl, add error note showing the declaration of the type decl | |
| 12123 | 12048 | return ira->codegen->builtin_types.entry_invalid; |
| 12124 | 12049 | } |
| 12125 | 12050 | |
| ... | ... | @@ -12171,11 +12096,11 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 12171 | 12096 | out_val->data.x_bool = bignum_shl(dest_bignum, op1_bignum, op2_bignum); |
| 12172 | 12097 | break; |
| 12173 | 12098 | } |
| 12174 | if (!bignum_fits_in_bits(dest_bignum, canon_type->data.integral.bit_count, | |
| 12175 | canon_type->data.integral.is_signed)) | |
| 12099 | if (!bignum_fits_in_bits(dest_bignum, dest_type->data.integral.bit_count, | |
| 12100 | dest_type->data.integral.is_signed)) | |
| 12176 | 12101 | { |
| 12177 | 12102 | out_val->data.x_bool = true; |
| 12178 | bignum_truncate(dest_bignum, canon_type->data.integral.bit_count); | |
| 12103 | bignum_truncate(dest_bignum, dest_type->data.integral.bit_count); | |
| 12179 | 12104 | } |
| 12180 | 12105 | pointee_val->special = ConstValSpecialStatic; |
| 12181 | 12106 | return ira->codegen->builtin_types.entry_bool; |
| ... | ... | @@ -12191,12 +12116,10 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc |
| 12191 | 12116 | if (type_is_invalid(value->value.type)) |
| 12192 | 12117 | return ira->codegen->builtin_types.entry_invalid; |
| 12193 | 12118 | |
| 12194 | TypeTableEntry *non_canon_type = value->value.type; | |
| 12195 | ||
| 12196 | TypeTableEntry *canon_type = get_underlying_type(non_canon_type); | |
| 12197 | if (type_is_invalid(canon_type)) { | |
| 12119 | TypeTableEntry *type_entry = value->value.type; | |
| 12120 | if (type_is_invalid(type_entry)) { | |
| 12198 | 12121 | return ira->codegen->builtin_types.entry_invalid; |
| 12199 | } else if (canon_type->id == TypeTableEntryIdErrorUnion) { | |
| 12122 | } else if (type_entry->id == TypeTableEntryIdErrorUnion) { | |
| 12200 | 12123 | if (instr_is_comptime(value)) { |
| 12201 | 12124 | ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad); |
| 12202 | 12125 | if (!err_union_val) |
| ... | ... | @@ -12211,7 +12134,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc |
| 12211 | 12134 | |
| 12212 | 12135 | ir_build_test_err_from(&ira->new_irb, &instruction->base, value); |
| 12213 | 12136 | return ira->codegen->builtin_types.entry_bool; |
| 12214 | } else if (canon_type->id == TypeTableEntryIdPureError) { | |
| 12137 | } else if (type_entry->id == TypeTableEntryIdPureError) { | |
| 12215 | 12138 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12216 | 12139 | out_val->data.x_bool = true; |
| 12217 | 12140 | return ira->codegen->builtin_types.entry_bool; |
| ... | ... | @@ -12233,11 +12156,10 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 12233 | 12156 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 12234 | 12157 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 12235 | 12158 | |
| 12236 | TypeTableEntry *non_canon_type = ptr_type->data.pointer.child_type; | |
| 12237 | TypeTableEntry *canon_type = get_underlying_type(non_canon_type); | |
| 12238 | if (type_is_invalid(canon_type)) { | |
| 12159 | TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; | |
| 12160 | if (type_is_invalid(type_entry)) { | |
| 12239 | 12161 | return ira->codegen->builtin_types.entry_invalid; |
| 12240 | } else if (canon_type->id == TypeTableEntryIdErrorUnion) { | |
| 12162 | } else if (type_entry->id == TypeTableEntryIdErrorUnion) { | |
| 12241 | 12163 | if (instr_is_comptime(value)) { |
| 12242 | 12164 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); |
| 12243 | 12165 | if (!ptr_val) |
| ... | ... | @@ -12257,8 +12179,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 12257 | 12179 | return ira->codegen->builtin_types.entry_pure_error; |
| 12258 | 12180 | } else { |
| 12259 | 12181 | ir_add_error(ira, value, |
| 12260 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&non_canon_type->name))); | |
| 12261 | // TODO if this is a typedecl, add error note showing the declaration of the type decl | |
| 12182 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name))); | |
| 12262 | 12183 | return ira->codegen->builtin_types.entry_invalid; |
| 12263 | 12184 | } |
| 12264 | 12185 | } |
| ... | ... | @@ -12275,12 +12196,11 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 12275 | 12196 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 12276 | 12197 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 12277 | 12198 | |
| 12278 | TypeTableEntry *non_canon_type = ptr_type->data.pointer.child_type; | |
| 12279 | TypeTableEntry *canon_type = get_underlying_type(non_canon_type); | |
| 12280 | if (type_is_invalid(canon_type)) { | |
| 12199 | TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; | |
| 12200 | if (type_is_invalid(type_entry)) { | |
| 12281 | 12201 | return ira->codegen->builtin_types.entry_invalid; |
| 12282 | } else if (canon_type->id == TypeTableEntryIdErrorUnion) { | |
| 12283 | TypeTableEntry *child_type = canon_type->data.error.child_type; | |
| 12202 | } else if (type_entry->id == TypeTableEntryIdErrorUnion) { | |
| 12203 | TypeTableEntry *child_type = type_entry->data.error.child_type; | |
| 12284 | 12204 | TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 12285 | 12205 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, 0, 0); |
| 12286 | 12206 | if (instr_is_comptime(value)) { |
| ... | ... | @@ -12307,8 +12227,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 12307 | 12227 | return result_type; |
| 12308 | 12228 | } else { |
| 12309 | 12229 | ir_add_error(ira, value, |
| 12310 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&non_canon_type->name))); | |
| 12311 | // TODO if this is a typedecl, add error note showing the declaration of the type decl | |
| 12230 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name))); | |
| 12312 | 12231 | return ira->codegen->builtin_types.entry_invalid; |
| 12313 | 12232 | } |
| 12314 | 12233 | |
| ... | ... | @@ -12594,22 +12513,6 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 12594 | 12513 | return ref_instruction->value.type; |
| 12595 | 12514 | } |
| 12596 | 12515 | } |
| 12597 | case TldIdTypeDef: | |
| 12598 | { | |
| 12599 | TldTypeDef *tld_typedef = (TldTypeDef *)tld; | |
| 12600 | TypeTableEntry *typedef_type = tld_typedef->type_entry; | |
| 12601 | ||
| 12602 | IrInstruction *ref_instruction = ir_create_const_type(&ira->new_irb, instruction->base.scope, | |
| 12603 | instruction->base.source_node, typedef_type); | |
| 12604 | if (lval.is_ptr) { | |
| 12605 | IrInstruction *ptr_inst = ir_get_ref(ira, &instruction->base, ref_instruction, true, false); | |
| 12606 | ir_link_new_instruction(ptr_inst, &instruction->base); | |
| 12607 | return ptr_inst->value.type; | |
| 12608 | } else { | |
| 12609 | ir_link_new_instruction(ref_instruction, &instruction->base); | |
| 12610 | return ref_instruction->value.type; | |
| 12611 | } | |
| 12612 | } | |
| 12613 | 12516 | } |
| 12614 | 12517 | zig_unreachable(); |
| 12615 | 12518 | } |
src/parseh.cpp+16-57| ... | ... | @@ -219,28 +219,8 @@ static Tld *add_container_tld(Context *c, TypeTableEntry *type_entry) { |
| 219 | 219 | return add_const_type(c, &type_entry->name, type_entry); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | static Tld *add_typedef_tld(Context *c, TypeTableEntry *type_decl) { | |
| 223 | assert(type_decl); | |
| 224 | assert(type_decl->id == TypeTableEntryIdTypeDecl); | |
| 225 | ||
| 226 | TldTypeDef *tld_typedef = allocate<TldTypeDef>(1); | |
| 227 | parseh_init_tld(c, &tld_typedef->base, TldIdTypeDef, &type_decl->name); | |
| 228 | tld_typedef->type_entry = type_decl; | |
| 229 | ||
| 230 | add_global(c, &tld_typedef->base); | |
| 231 | c->global_type_table.put(&type_decl->name, type_decl); | |
| 232 | ||
| 233 | return &tld_typedef->base; | |
| 234 | } | |
| 235 | ||
| 236 | 222 | static bool is_c_void_type(Context *c, TypeTableEntry *type_entry) { |
| 237 | while (type_entry->id == TypeTableEntryIdTypeDecl) { | |
| 238 | if (type_entry == c->codegen->builtin_types.entry_c_void) { | |
| 239 | return true; | |
| 240 | } | |
| 241 | type_entry = type_entry->data.type_decl.child_type; | |
| 242 | } | |
| 243 | return false; | |
| 223 | return (type_entry == c->codegen->builtin_types.entry_c_void); | |
| 244 | 224 | } |
| 245 | 225 | |
| 246 | 226 | static bool qual_type_child_is_fn_proto(const QualType &qt) { |
| ... | ... | @@ -369,7 +349,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 369 | 349 | const PointerType *pointer_ty = static_cast<const PointerType*>(ty); |
| 370 | 350 | QualType child_qt = pointer_ty->getPointeeType(); |
| 371 | 351 | TypeTableEntry *child_type = resolve_qual_type(c, child_qt, decl); |
| 372 | if (get_underlying_type(child_type)->id == TypeTableEntryIdInvalid) { | |
| 352 | if (type_is_invalid(child_type)) { | |
| 373 | 353 | emit_warning(c, decl, "pointer to unresolved type"); |
| 374 | 354 | return c->codegen->builtin_types.entry_invalid; |
| 375 | 355 | } |
| ... | ... | @@ -410,7 +390,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 410 | 390 | } else { |
| 411 | 391 | auto entry = type_table->maybe_get(type_name); |
| 412 | 392 | if (entry) { |
| 413 | if (get_underlying_type(entry->value)->id == TypeTableEntryIdInvalid) { | |
| 393 | if (type_is_invalid(entry->value)) { | |
| 414 | 394 | return c->codegen->builtin_types.entry_invalid; |
| 415 | 395 | } else { |
| 416 | 396 | return entry->value; |
| ... | ... | @@ -507,7 +487,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 507 | 487 | fn_type_id.return_type = c->codegen->builtin_types.entry_unreachable; |
| 508 | 488 | } else { |
| 509 | 489 | fn_type_id.return_type = resolve_qual_type(c, fn_proto_ty->getReturnType(), decl); |
| 510 | if (get_underlying_type(fn_type_id.return_type)->id == TypeTableEntryIdInvalid) { | |
| 490 | if (type_is_invalid(fn_type_id.return_type)) { | |
| 511 | 491 | emit_warning(c, decl, "unresolved function proto return type"); |
| 512 | 492 | return c->codegen->builtin_types.entry_invalid; |
| 513 | 493 | } |
| ... | ... | @@ -522,7 +502,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 522 | 502 | QualType qt = fn_proto_ty->getParamType(i); |
| 523 | 503 | TypeTableEntry *param_type = resolve_qual_type(c, qt, decl); |
| 524 | 504 | |
| 525 | if (get_underlying_type(param_type)->id == TypeTableEntryIdInvalid) { | |
| 505 | if (type_is_invalid(param_type)) { | |
| 526 | 506 | emit_warning(c, decl, "unresolved function proto parameter type"); |
| 527 | 507 | return c->codegen->builtin_types.entry_invalid; |
| 528 | 508 | } |
| ... | ... | @@ -702,6 +682,7 @@ static void replace_with_fwd_decl(Context *c, TypeTableEntry *struct_type, Buf * |
| 702 | 682 | |
| 703 | 683 | ZigLLVMReplaceTemporary(c->codegen->dbuilder, struct_type->di_type, replacement_di_type); |
| 704 | 684 | struct_type->di_type = replacement_di_type; |
| 685 | struct_type->id = TypeTableEntryIdOpaque; | |
| 705 | 686 | } |
| 706 | 687 | |
| 707 | 688 | static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) { |
| ... | ... | @@ -809,7 +790,9 @@ static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) |
| 809 | 790 | |
| 810 | 791 | return enum_type; |
| 811 | 792 | } else { |
| 812 | TypeTableEntry *enum_type = get_typedecl_type(c->codegen, buf_ptr(full_type_name), tag_type_entry); | |
| 793 | // TODO after issue #305 is solved, make this be an enum with tag_type_entry | |
| 794 | // as the integer type and set the custom enum values | |
| 795 | TypeTableEntry *enum_type = tag_type_entry; | |
| 813 | 796 | c->enum_type_table.put(bare_name, enum_type); |
| 814 | 797 | c->decl_table.put(enum_decl, enum_type); |
| 815 | 798 | |
| ... | ... | @@ -847,22 +830,8 @@ static void visit_enum_decl(Context *c, const EnumDecl *enum_decl) { |
| 847 | 830 | |
| 848 | 831 | Buf *bare_name = buf_create_from_str(decl_name(enum_decl)); |
| 849 | 832 | |
| 850 | if (enum_type->id == TypeTableEntryIdEnum) { | |
| 851 | if (enum_type->data.enumeration.complete) { | |
| 852 | Tld *tld = add_container_tld(c, enum_type); | |
| 853 | add_global_weak_alias(c, bare_name, tld); | |
| 854 | } else { | |
| 855 | TypeTableEntry *typedecl_type = get_typedecl_type(c->codegen, buf_ptr(&enum_type->name), | |
| 856 | c->codegen->builtin_types.entry_u8); | |
| 857 | Tld *tld = add_typedef_tld(c, typedecl_type); | |
| 858 | add_global_weak_alias(c, bare_name, tld); | |
| 859 | } | |
| 860 | } else if (enum_type->id == TypeTableEntryIdTypeDecl) { | |
| 861 | Tld *tld = add_typedef_tld(c, enum_type); | |
| 862 | add_global_weak_alias(c, bare_name, tld); | |
| 863 | } else { | |
| 864 | zig_unreachable(); | |
| 865 | } | |
| 833 | Tld *tld = add_container_tld(c, enum_type); | |
| 834 | add_global_weak_alias(c, bare_name, tld); | |
| 866 | 835 | } |
| 867 | 836 | |
| 868 | 837 | static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_decl) { |
| ... | ... | @@ -912,7 +881,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ |
| 912 | 881 | const FieldDecl *field_decl = *it; |
| 913 | 882 | |
| 914 | 883 | if (field_decl->isBitField()) { |
| 915 | emit_warning(c, field_decl, "struct %s demoted to typedef - has bitfield\n", buf_ptr(bare_name)); | |
| 884 | emit_warning(c, field_decl, "struct %s demoted to opaque type - has bitfield\n", buf_ptr(bare_name)); | |
| 916 | 885 | replace_with_fwd_decl(c, struct_type, full_type_name); |
| 917 | 886 | return struct_type; |
| 918 | 887 | } |
| ... | ... | @@ -939,7 +908,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ |
| 939 | 908 | type_struct_field->type_entry = field_type; |
| 940 | 909 | |
| 941 | 910 | if (type_is_invalid(field_type) || !type_is_complete(field_type)) { |
| 942 | emit_warning(c, field_decl, "struct %s demoted to typedef - unresolved type\n", buf_ptr(bare_name)); | |
| 911 | emit_warning(c, field_decl, "struct %s demoted to opaque type - unresolved type\n", buf_ptr(bare_name)); | |
| 943 | 912 | replace_with_fwd_decl(c, struct_type, full_type_name); |
| 944 | 913 | return struct_type; |
| 945 | 914 | } |
| ... | ... | @@ -1001,23 +970,14 @@ static void visit_record_decl(Context *c, const RecordDecl *record_decl) { |
| 1001 | 970 | return; |
| 1002 | 971 | } |
| 1003 | 972 | |
| 1004 | assert(struct_type->id == TypeTableEntryIdStruct); | |
| 1005 | ||
| 1006 | 973 | bool is_anonymous = (record_decl->isAnonymousStructOrUnion() || decl_name(record_decl)[0] == 0); |
| 1007 | 974 | if (is_anonymous) |
| 1008 | 975 | return; |
| 1009 | 976 | |
| 1010 | 977 | Buf *bare_name = buf_create_from_str(decl_name(record_decl)); |
| 1011 | 978 | |
| 1012 | if (struct_type->data.structure.complete) { | |
| 1013 | Tld *tld = add_container_tld(c, struct_type); | |
| 1014 | add_global_weak_alias(c, bare_name, tld); | |
| 1015 | } else { | |
| 1016 | TypeTableEntry *typedecl_type = get_typedecl_type(c->codegen, buf_ptr(&struct_type->name), | |
| 1017 | c->codegen->builtin_types.entry_u8); | |
| 1018 | Tld *tld = add_typedef_tld(c, typedecl_type); | |
| 1019 | add_global_weak_alias(c, bare_name, tld); | |
| 1020 | } | |
| 979 | Tld *tld = add_container_tld(c, struct_type); | |
| 980 | add_global_weak_alias(c, bare_name, tld); | |
| 1021 | 981 | } |
| 1022 | 982 | |
| 1023 | 983 | static void visit_var_decl(Context *c, const VarDecl *var_decl) { |
| ... | ... | @@ -1059,8 +1019,7 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) { |
| 1059 | 1019 | switch (ap_value->getKind()) { |
| 1060 | 1020 | case APValue::Int: |
| 1061 | 1021 | { |
| 1062 | TypeTableEntry *canon_type = get_underlying_type(var_type); | |
| 1063 | if (canon_type->id != TypeTableEntryIdInt) { | |
| 1022 | if (var_type->id != TypeTableEntryIdInt) { | |
| 1064 | 1023 | emit_warning(c, var_decl, |
| 1065 | 1024 | "ignoring variable '%s' - int initializer for non int type\n", buf_ptr(name)); |
| 1066 | 1025 | return; |
src/parser.cpp+2-43| ... | ... | @@ -710,7 +710,7 @@ static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool m |
| 710 | 710 | |
| 711 | 711 | /* |
| 712 | 712 | PrimaryExpression = Number | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." Symbol) | ContainerDecl |
| 713 | KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this" | "unreachable" | |
| 713 | KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "this" | "unreachable" | |
| 714 | 714 | */ |
| 715 | 715 | static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 716 | 716 | Token *token = &pc->tokens->at(*token_index); |
| ... | ... | @@ -766,10 +766,6 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo |
| 766 | 766 | AstNode *node = ast_create_node(pc, NodeTypeUnreachable, token); |
| 767 | 767 | *token_index += 1; |
| 768 | 768 | return node; |
| 769 | } else if (token->id == TokenIdKeywordType) { | |
| 770 | AstNode *node = ast_create_node(pc, NodeTypeTypeLiteral, token); | |
| 771 | *token_index += 1; | |
| 772 | return node; | |
| 773 | 769 | } else if (token->id == TokenIdKeywordError) { |
| 774 | 770 | AstNode *node = ast_create_node(pc, NodeTypeErrorType, token); |
| 775 | 771 | *token_index += 1; |
| ... | ... | @@ -2500,34 +2496,9 @@ static AstNode *ast_parse_test_decl_node(ParseContext *pc, size_t *token_index) |
| 2500 | 2496 | return node; |
| 2501 | 2497 | } |
| 2502 | 2498 | |
| 2503 | /* | |
| 2504 | TypeDecl = "type" "Symbol" "=" TypeExpr ";" | |
| 2505 | */ | |
| 2506 | static AstNode *ast_parse_type_decl(ParseContext *pc, size_t *token_index, VisibMod visib_mod) { | |
| 2507 | Token *first_token = &pc->tokens->at(*token_index); | |
| 2508 | ||
| 2509 | if (first_token->id != TokenIdKeywordType) { | |
| 2510 | return nullptr; | |
| 2511 | } | |
| 2512 | *token_index += 1; | |
| 2513 | ||
| 2514 | Token *name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); | |
| 2515 | ast_eat_token(pc, token_index, TokenIdEq); | |
| 2516 | ||
| 2517 | AstNode *node = ast_create_node(pc, NodeTypeTypeDecl, first_token); | |
| 2518 | node->data.type_decl.symbol = token_buf(name_tok); | |
| 2519 | node->data.type_decl.child_type = ast_parse_type_expr(pc, token_index, true); | |
| 2520 | ||
| 2521 | ast_eat_token(pc, token_index, TokenIdSemicolon); | |
| 2522 | ||
| 2523 | node->data.type_decl.visib_mod = visib_mod; | |
| 2524 | ||
| 2525 | return node; | |
| 2526 | } | |
| 2527 | ||
| 2528 | 2499 | /* |
| 2529 | 2500 | TopLevelItem = ErrorValueDecl | CompTimeExpression(Block) | TopLevelDecl | TestDecl |
| 2530 | TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | TypeDecl | UseDecl) | |
| 2501 | TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | UseDecl) | |
| 2531 | 2502 | */ |
| 2532 | 2503 | static void ast_parse_top_level_decls(ParseContext *pc, size_t *token_index, ZigList<AstNode *> *top_level_decls) { |
| 2533 | 2504 | for (;;) { |
| ... | ... | @@ -2586,12 +2557,6 @@ static void ast_parse_top_level_decls(ParseContext *pc, size_t *token_index, Zig |
| 2586 | 2557 | continue; |
| 2587 | 2558 | } |
| 2588 | 2559 | |
| 2589 | AstNode *type_decl_node = ast_parse_type_decl(pc, token_index, visib_mod); | |
| 2590 | if (type_decl_node) { | |
| 2591 | top_level_decls->append(type_decl_node); | |
| 2592 | continue; | |
| 2593 | } | |
| 2594 | ||
| 2595 | 2560 | return; |
| 2596 | 2561 | } |
| 2597 | 2562 | zig_unreachable(); |
| ... | ... | @@ -2674,9 +2639,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont |
| 2674 | 2639 | visit_field(&node->data.variable_declaration.type, visit, context); |
| 2675 | 2640 | visit_field(&node->data.variable_declaration.expr, visit, context); |
| 2676 | 2641 | break; |
| 2677 | case NodeTypeTypeDecl: | |
| 2678 | visit_field(&node->data.type_decl.child_type, visit, context); | |
| 2679 | break; | |
| 2680 | 2642 | case NodeTypeErrorValueDecl: |
| 2681 | 2643 | // none |
| 2682 | 2644 | break; |
| ... | ... | @@ -2826,9 +2788,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont |
| 2826 | 2788 | case NodeTypeErrorType: |
| 2827 | 2789 | // none |
| 2828 | 2790 | break; |
| 2829 | case NodeTypeTypeLiteral: | |
| 2830 | // none | |
| 2831 | break; | |
| 2832 | 2791 | case NodeTypeVarLiteral: |
| 2833 | 2792 | // none |
| 2834 | 2793 | break; |
src/tokenizer.cpp-2| ... | ... | @@ -139,7 +139,6 @@ static const struct ZigKeyword zig_keywords[] = { |
| 139 | 139 | {"this", TokenIdKeywordThis}, |
| 140 | 140 | {"true", TokenIdKeywordTrue}, |
| 141 | 141 | {"try", TokenIdKeywordTry}, |
| 142 | {"type", TokenIdKeywordType}, | |
| 143 | 142 | {"undefined", TokenIdKeywordUndefined}, |
| 144 | 143 | {"union", TokenIdKeywordUnion}, |
| 145 | 144 | {"unreachable", TokenIdKeywordUnreachable}, |
| ... | ... | @@ -1474,7 +1473,6 @@ const char * token_name(TokenId id) { |
| 1474 | 1473 | case TokenIdKeywordThis: return "this"; |
| 1475 | 1474 | case TokenIdKeywordTrue: return "true"; |
| 1476 | 1475 | case TokenIdKeywordTry: return "try"; |
| 1477 | case TokenIdKeywordType: return "type"; | |
| 1478 | 1476 | case TokenIdKeywordUndefined: return "undefined"; |
| 1479 | 1477 | case TokenIdKeywordUnion: return "union"; |
| 1480 | 1478 | case TokenIdKeywordUnreachable: return "unreachable"; |
src/tokenizer.hpp-1| ... | ... | @@ -76,7 +76,6 @@ enum TokenId { |
| 76 | 76 | TokenIdKeywordThis, |
| 77 | 77 | TokenIdKeywordTrue, |
| 78 | 78 | TokenIdKeywordTry, |
| 79 | TokenIdKeywordType, | |
| 80 | 79 | TokenIdKeywordUndefined, |
| 81 | 80 | TokenIdKeywordUnion, |
| 82 | 81 | TokenIdKeywordUnreachable, |
test/cases/typedef.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 3 | type int = u8; | |
| 4 | ||
| 5 | fn add(a: int, b: int) -> int { | |
| 6 | a + b | |
| 7 | } | |
| 8 | test "typedef" { | |
| 9 | assert(add(12, 34) == 46); | |
| 10 | } |
test/run_tests.cpp+4-4| ... | ... | @@ -2191,7 +2191,7 @@ struct Foo { |
| 2191 | 2191 | add_parseh_case("struct prototype used in func", AllowWarningsNo, R"SOURCE( |
| 2192 | 2192 | struct Foo; |
| 2193 | 2193 | struct Foo *some_func(struct Foo *foo, int x); |
| 2194 | )SOURCE", 3, R"OUTPUT(pub type struct_Foo = u8;)OUTPUT", | |
| 2194 | )SOURCE", 3, R"OUTPUT(pub const struct_Foo = @OpaqueType();)OUTPUT", | |
| 2195 | 2195 | R"OUTPUT(pub extern fn some_func(foo: ?&struct_Foo, x: c_int) -> ?&struct_Foo;)OUTPUT", |
| 2196 | 2196 | R"OUTPUT(pub const Foo = struct_Foo;)OUTPUT"); |
| 2197 | 2197 | |
| ... | ... | @@ -2277,12 +2277,12 @@ void foo(void (__cdecl *fn_ptr)(void)); |
| 2277 | 2277 | )SOURCE", 1, "pub const SDL_INIT_VIDEO = 32;"); |
| 2278 | 2278 | |
| 2279 | 2279 | add_parseh_case("zig keywords in C code", AllowWarningsNo, R"SOURCE( |
| 2280 | struct type { | |
| 2280 | struct comptime { | |
| 2281 | 2281 | int defer; |
| 2282 | 2282 | }; |
| 2283 | )SOURCE", 2, R"(pub const struct_type = extern struct { | |
| 2283 | )SOURCE", 2, R"(pub const struct_comptime = extern struct { | |
| 2284 | 2284 | @"defer": c_int, |
| 2285 | };)", R"(pub const @"type" = struct_type;)"); | |
| 2285 | };)", R"(pub const @"comptime" = struct_comptime;)"); | |
| 2286 | 2286 | |
| 2287 | 2287 | add_parseh_case("macro defines string literal with octal", AllowWarningsNo, R"SOURCE( |
| 2288 | 2288 | #define FOO "aoeu\023 derp" |
test/self_hosted.zig-1| ... | ... | @@ -31,7 +31,6 @@ comptime { |
| 31 | 31 | _ = @import("cases/switch_prong_implicit_cast.zig"); |
| 32 | 32 | _ = @import("cases/this.zig"); |
| 33 | 33 | _ = @import("cases/try.zig"); |
| 34 | _ = @import("cases/typedef.zig"); | |
| 35 | 34 | _ = @import("cases/undefined.zig"); |
| 36 | 35 | _ = @import("cases/var_args.zig"); |
| 37 | 36 | _ = @import("cases/void.zig"); |