diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-04-07 15:32:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-07 15:32:02 -0400 |
| commit | 6715c54cc641e61405bb72d286fe2cf560447b56 (patch) | |
| tree | 6b62ce5b82c65595a13f6cf93335a4bfaa73dc8e /src | |
| parent | 7c38651a65b48b8cc683bc31a40952d9b469ec4d (diff) | |
| parent | fae0c35195076c8bce9da3528ce8d1959902ca06 (diff) | |
| download | zig-6715c54cc641e61405bb72d286fe2cf560447b56.tar.gz zig-6715c54cc641e61405bb72d286fe2cf560447b56.zip | |
Merge pull request #2205 from kristate/zig-backport-issue532
stage1: create ir.cpp specific `analyze_type_expr`
Diffstat (limited to 'src')
| -rw-r--r-- | src/ir.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index c572e3c885..de4543df4e 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -356,6 +356,28 @@ static void ir_ref_var(ZigVar *var) { var->ref_count += 1; } +ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) { + ConstExprValue *result = ir_eval_const_value( ira->codegen + , scope + , node + , ira->codegen->builtin_types.entry_type + , ira->new_irb.exec->backward_branch_count + , ira->new_irb.exec->backward_branch_quota + , nullptr + , nullptr + , node + , nullptr + , ira->new_irb.exec + , nullptr + ); + + if (type_is_invalid(result->type)) + return ira->codegen->builtin_types.entry_invalid; + + assert(result->special != ConstValSpecialRuntime); + return result->data.x_type; +} + static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) { IrBasicBlock *result = allocate<IrBasicBlock>(1); result->scope = scope; @@ -13875,7 +13897,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node IrInstruction *casted_arg; if (param_decl_node->data.param_decl.var_token == nullptr) { AstNode *param_type_node = param_decl_node->data.param_decl.type; - ZigType *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node); + ZigType *param_type = ir_analyze_type_expr(ira, *exec_scope, param_type_node); if (type_is_invalid(param_type)) return false; @@ -13915,7 +13937,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod } else { if (param_decl_node->data.param_decl.var_token == nullptr) { AstNode *param_type_node = param_decl_node->data.param_decl.type; - ZigType *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node); + ZigType *param_type = ir_analyze_type_expr(ira, *child_scope, param_type_node); if (type_is_invalid(param_type)) return false; @@ -14296,7 +14318,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call } AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; - ZigType *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node); + ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node); if (type_is_invalid(specified_return_type)) return ira->codegen->invalid_instruction; ZigType *return_type; @@ -14532,7 +14554,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call if (fn_proto_node->data.fn_proto.return_var_token == nullptr) { AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; - ZigType *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node); + ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node); if (type_is_invalid(specified_return_type)) return ira->codegen->invalid_instruction; if (fn_proto_node->data.fn_proto.auto_err_set) { @@ -14559,7 +14581,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call if (call_instruction->is_async) { AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type; if (async_allocator_type_node != nullptr) { - ZigType *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node); + ZigType *async_allocator_type = ir_analyze_type_expr(ira, impl_fn->child_scope, async_allocator_type_node); if (type_is_invalid(async_allocator_type)) return ira->codegen->invalid_instruction; inst_fn_type_id.async_allocator_type = async_allocator_type; |
