| author | |
| committer | |
| log | bc6c33b1b64822b0667ab88b73f4b5c4b302154f |
| tree | ea1a904d61a65d57ae3e8df8f861d4eea71ae77c |
| parent | c8333d0cc9a2941ea35f1202073dabd9058beebc |
2 files changed, 61 insertions(+), 41 deletions(-)
src/analyze.cpp+2-39| ... | ... | @@ -2871,16 +2871,6 @@ static TypeTableEntry *resolve_expr_const_val_as_type(CodeGen *g, AstNode *node, |
| 2871 | 2871 | return g->builtin_types.entry_type; |
| 2872 | 2872 | } |
| 2873 | 2873 | |
| 2874 | static TypeTableEntry *resolve_expr_const_val_as_block(CodeGen *g, AstNode *node, BlockContext *block_context, | |
| 2875 | bool depends_on_compile_var) | |
| 2876 | { | |
| 2877 | Expr *expr = get_resolved_expr(node); | |
| 2878 | expr->const_val.ok = true; | |
| 2879 | expr->const_val.data.x_block = block_context; | |
| 2880 | expr->const_val.depends_on_compile_var = depends_on_compile_var; | |
| 2881 | return g->builtin_types.entry_block; | |
| 2882 | } | |
| 2883 | ||
| 2884 | 2874 | static TypeTableEntry *resolve_expr_const_val_as_other_expr(CodeGen *g, AstNode *node, AstNode *other, |
| 2885 | 2875 | bool depends_on_compile_var) |
| 2886 | 2876 | { |
| ... | ... | @@ -2999,13 +2989,6 @@ static TypeTableEntry *resolve_expr_const_val_as_unsigned_num_lit(CodeGen *g, As |
| 2999 | 2989 | return g->builtin_types.entry_num_lit_int; |
| 3000 | 2990 | } |
| 3001 | 2991 | |
| 3002 | static TypeTableEntry *resolve_expr_const_val_as_import(CodeGen *g, AstNode *node, ImportTableEntry *import) { | |
| 3003 | Expr *expr = get_resolved_expr(node); | |
| 3004 | expr->const_val.ok = true; | |
| 3005 | expr->const_val.data.x_import = import; | |
| 3006 | return g->builtin_types.entry_namespace; | |
| 3007 | } | |
| 3008 | ||
| 3009 | 2992 | static TypeTableEntry *analyze_error_literal_expr(CodeGen *g, ImportTableEntry *import, |
| 3010 | 2993 | BlockContext *context, AstNode *node, Buf *err_name) |
| 3011 | 2994 | { |
| ... | ... | @@ -3905,26 +3888,6 @@ static TypeTableEntry *analyze_zeroes_literal_expr(CodeGen *g, ImportTableEntry |
| 3905 | 3888 | return expected_type ? expected_type : g->builtin_types.entry_undef; |
| 3906 | 3889 | } |
| 3907 | 3890 | |
| 3908 | static TypeTableEntry *analyze_this_literal_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context, | |
| 3909 | TypeTableEntry *expected_type, AstNode *node) | |
| 3910 | { | |
| 3911 | if (!context->parent) { | |
| 3912 | return resolve_expr_const_val_as_import(g, node, import); | |
| 3913 | } | |
| 3914 | if (context->fn_entry && (!context->parent->fn_entry || | |
| 3915 | (context->parent->parent && !context->parent->parent->fn_entry))) | |
| 3916 | { | |
| 3917 | return resolve_expr_const_val_as_fn(g, node, context->fn_entry, false); | |
| 3918 | } | |
| 3919 | if (context->node->type == NodeTypeContainerDecl) { | |
| 3920 | return resolve_expr_const_val_as_type(g, node, context->node->data.struct_decl.type_entry, false); | |
| 3921 | } | |
| 3922 | if (context->node->type == NodeTypeBlock) { | |
| 3923 | return resolve_expr_const_val_as_block(g, node, context, false); | |
| 3924 | } | |
| 3925 | zig_unreachable(); | |
| 3926 | } | |
| 3927 | ||
| 3928 | 3891 | static TypeTableEntry *analyze_number_literal_expr(CodeGen *g, ImportTableEntry *import, |
| 3929 | 3892 | BlockContext *block_context, TypeTableEntry *expected_type, AstNode *node) |
| 3930 | 3893 | { |
| ... | ... | @@ -5202,7 +5165,7 @@ static TypeTableEntry *analyze_expression_pointer_only(CodeGen *g, ImportTableEn |
| 5202 | 5165 | node->data.char_literal.value, false); |
| 5203 | 5166 | break; |
| 5204 | 5167 | case NodeTypeBoolLiteral: |
| 5205 | return_type = resolve_expr_const_val_as_bool(g, node, node->data.bool_literal.value, false); | |
| 5168 | zig_panic("moved to ir.cpp"); | |
| 5206 | 5169 | break; |
| 5207 | 5170 | case NodeTypeNullLiteral: |
| 5208 | 5171 | return_type = analyze_null_literal_expr(g, import, context, expected_type, node); |
| ... | ... | @@ -5214,7 +5177,7 @@ static TypeTableEntry *analyze_expression_pointer_only(CodeGen *g, ImportTableEn |
| 5214 | 5177 | return_type = analyze_zeroes_literal_expr(g, import, context, expected_type, node); |
| 5215 | 5178 | break; |
| 5216 | 5179 | case NodeTypeThisLiteral: |
| 5217 | return_type = analyze_this_literal_expr(g, import, context, expected_type, node); | |
| 5180 | zig_panic("moved to ir.cpp"); | |
| 5218 | 5181 | break; |
| 5219 | 5182 | case NodeTypeSymbol: |
| 5220 | 5183 | return_type = analyze_symbol_expr(g, import, context, expected_type, node, pointer_only); |
src/ir.cpp+59-2| ... | ... | @@ -335,6 +335,30 @@ static IrInstruction *ir_build_const_generic_fn(IrBuilder *irb, AstNode *source_ |
| 335 | 335 | return &const_instruction->base; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | static IrInstruction *ir_build_const_import(IrBuilder *irb, AstNode *source_node, ImportTableEntry *import) { | |
| 339 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | |
| 340 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_namespace; | |
| 341 | const_instruction->base.static_value.ok = true; | |
| 342 | const_instruction->base.static_value.data.x_import = import; | |
| 343 | return &const_instruction->base; | |
| 344 | } | |
| 345 | ||
| 346 | static IrInstruction *ir_build_const_scope(IrBuilder *irb, AstNode *source_node, BlockContext *scope) { | |
| 347 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | |
| 348 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_block; | |
| 349 | const_instruction->base.static_value.ok = true; | |
| 350 | const_instruction->base.static_value.data.x_block = scope; | |
| 351 | return &const_instruction->base; | |
| 352 | } | |
| 353 | ||
| 354 | static IrInstruction *ir_build_const_bool(IrBuilder *irb, AstNode *source_node, bool value) { | |
| 355 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | |
| 356 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_block; | |
| 357 | const_instruction->base.static_value.ok = true; | |
| 358 | const_instruction->base.static_value.data.x_bool = value; | |
| 359 | return &const_instruction->base; | |
| 360 | } | |
| 361 | ||
| 338 | 362 | static IrInstruction *ir_build_bin_op(IrBuilder *irb, AstNode *source_node, IrBinOp op_id, |
| 339 | 363 | IrInstruction *op1, IrInstruction *op2) |
| 340 | 364 | { |
| ... | ... | @@ -1493,6 +1517,37 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) { |
| 1493 | 1517 | |
| 1494 | 1518 | } |
| 1495 | 1519 | |
| 1520 | static IrInstruction *ir_gen_this_literal(IrBuilder *irb, AstNode *node) { | |
| 1521 | assert(node->type == NodeTypeThisLiteral); | |
| 1522 | ||
| 1523 | BlockContext *scope = node->block_context; | |
| 1524 | ||
| 1525 | if (!scope->parent) | |
| 1526 | return ir_build_const_import(irb, node, node->owner); | |
| 1527 | ||
| 1528 | if (scope->fn_entry && (!scope->parent->fn_entry || | |
| 1529 | (scope->parent->parent && !scope->parent->parent->fn_entry))) | |
| 1530 | { | |
| 1531 | return ir_build_const_fn(irb, node, scope->fn_entry); | |
| 1532 | } | |
| 1533 | ||
| 1534 | if (scope->node->type == NodeTypeContainerDecl) { | |
| 1535 | TypeTableEntry *container_type = scope->node->data.struct_decl.type_entry; | |
| 1536 | assert(container_type); | |
| 1537 | return ir_build_const_type(irb, node, container_type); | |
| 1538 | } | |
| 1539 | ||
| 1540 | if (scope->node->type == NodeTypeBlock) | |
| 1541 | return ir_build_const_scope(irb, node, scope); | |
| 1542 | ||
| 1543 | zig_unreachable(); | |
| 1544 | } | |
| 1545 | ||
| 1546 | static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, AstNode *node) { | |
| 1547 | assert(node->type == NodeTypeBoolLiteral); | |
| 1548 | return ir_build_const_bool(irb, node, node->data.bool_literal.value); | |
| 1549 | } | |
| 1550 | ||
| 1496 | 1551 | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context, |
| 1497 | 1552 | LValPurpose lval) |
| 1498 | 1553 | { |
| ... | ... | @@ -1528,6 +1583,10 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont |
| 1528 | 1583 | return ir_gen_return(irb, node); |
| 1529 | 1584 | case NodeTypeFieldAccessExpr: |
| 1530 | 1585 | return ir_gen_field_access(irb, node, lval); |
| 1586 | case NodeTypeThisLiteral: | |
| 1587 | return ir_gen_this_literal(irb, node); | |
| 1588 | case NodeTypeBoolLiteral: | |
| 1589 | return ir_gen_bool_literal(irb, node); | |
| 1531 | 1590 | case NodeTypeUnwrapErrorExpr: |
| 1532 | 1591 | case NodeTypeDefer: |
| 1533 | 1592 | case NodeTypeSliceExpr: |
| ... | ... | @@ -1538,13 +1597,11 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont |
| 1538 | 1597 | case NodeTypeContinue: |
| 1539 | 1598 | case NodeTypeLabel: |
| 1540 | 1599 | case NodeTypeSwitchExpr: |
| 1541 | case NodeTypeBoolLiteral: | |
| 1542 | 1600 | case NodeTypeStringLiteral: |
| 1543 | 1601 | case NodeTypeCharLiteral: |
| 1544 | 1602 | case NodeTypeNullLiteral: |
| 1545 | 1603 | case NodeTypeUndefinedLiteral: |
| 1546 | 1604 | case NodeTypeZeroesLiteral: |
| 1547 | case NodeTypeThisLiteral: | |
| 1548 | 1605 | case NodeTypeErrorType: |
| 1549 | 1606 | case NodeTypeTypeLiteral: |
| 1550 | 1607 | case NodeTypeArrayType: |