diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-12-05 01:08:17 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-12-05 01:08:17 -0500 |
| commit | 363606d87b3f45c7f62969f85062e2a7b1b4b5dc (patch) | |
| tree | f530fc69be3905eb8577f6d8ff77c226ac07e371 /src/analyze.cpp | |
| parent | 25a89e7a362ab4876139fad7427a2193665cb042 (diff) | |
| download | zig-363606d87b3f45c7f62969f85062e2a7b1b4b5dc.tar.gz zig-363606d87b3f45c7f62969f85062e2a7b1b4b5dc.zip | |
IR: inline function evaluation works on generic functions
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 2619be5a3d..041fd93780 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -878,7 +878,7 @@ static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *nod return ir_eval_const_value(g, scope, node, type_entry, &backward_branch_count, default_backward_branch_quota); } -static TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { +TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { IrInstruction *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type); if (result->type_entry->id == TypeTableEntryIdInvalid) return g->builtin_types.entry_invalid; @@ -889,6 +889,19 @@ static TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node static TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { TypeTableEntry *fn_type = new_type_table_entry(TypeTableEntryIdFn); + buf_init_from_str(&fn_type->name, "fn("); + size_t i = 0; + for (; i < fn_type_id->next_param_index; i += 1) { + const char *comma_str = (i == 0) ? "" : ","; + buf_appendf(&fn_type->name, "%s%s", comma_str, + buf_ptr(&fn_type_id->param_info[i].type->name)); + } + for (; i < fn_type_id->param_count; i += 1) { + const char *comma_str = (i == 0) ? "" : ","; + buf_appendf(&fn_type->name, "%svar", comma_str); + } + buf_appendf(&fn_type->name, ")->var"); + fn_type->data.fn.fn_type_id = *fn_type_id; fn_type->data.fn.is_generic = true; return fn_type; |
