Skip to content

Commit

Permalink
match analysis switching to resolve_type_ref to handle matches on gen…
Browse files Browse the repository at this point in the history
…eric fields
  • Loading branch information
chrisosaurus committed Nov 12, 2017
1 parent 5382ea6 commit 06ba1e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/analyse/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1121,12 +1121,12 @@ unsigned int ic_analyse_body(char *unit, char *unit_name, struct ic_kludge *klud

match_cases += 1;

field_type = ic_kludge_get_decl_type_from_typeref(kludge, field->type);
field_type = ic_analyse_resolve_type_ref(kludge, "field type check", field_name_char, &(fdecl->type_params), field->type);
if (!field_type) {
printf("ERROR: match case: unable to find type for field '%s' with declared type '", ic_symbol_contents(&(field->name)));
ic_type_ref_print(stdout, field->type);
puts("'");
puts("ic_analyse_body: match: call to ic_kludge_get_decl_type_from_typeref failed");
puts("ic_analyse_body: match: call to ic_analyse_resolve_type_ref failed");
goto ERROR;
}

Expand Down
16 changes: 8 additions & 8 deletions src/backends/2c/tir.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ unsigned int ic_b2c_compile_stmt_match(struct ic_kludge *input_kludge, struct ic
struct ic_symbol *type_mangled_name = 0;
char *type_mangled_name_ch = 0;
char *field_name_ch = 0;
struct ic_symbol *field_type_sym = 0;
char *field_type_ch = 0;
struct ic_symbol *field_mangled_type_sym = 0;
char *field_mangled_type_ch = 0;

if (!input_kludge) {
puts("ic_b2c_compile_stmt_match: input_kludge was null");
Expand Down Expand Up @@ -440,20 +440,20 @@ unsigned int ic_b2c_compile_stmt_match(struct ic_kludge *input_kludge, struct ic

field_name_ch = ic_symbol_contents(&(tcase->field->name));

field_type_sym = ic_type_ref_get_symbol(tcase->field->type);
if (!field_type_sym) {
puts("ic_b2c_compile_stmt_match: call to ic_type_ref_get_symbol failed");
field_mangled_type_sym = ic_type_ref_mangled_name(tcase->field->type);
if (!field_mangled_type_sym) {
puts("ic_b2c_compile_stmt_match: call to ic_type_ref_mangled_name failed");
return 0;
}

field_type_ch = ic_symbol_contents(field_type_sym);
field_mangled_type_ch = ic_symbol_contents(field_mangled_type_sym);

/* insert case */
fprintf(out, " case %s_tag_%s_%s:\n", type_mangled_name_ch, field_type_ch, field_name_ch);
fprintf(out, " case %s_tag_%s_%s:\n", type_mangled_name_ch, field_mangled_type_ch, field_name_ch);
fputs(" {\n", out);

/* insert var to unpack */
fprintf(out, " %s %s = %s->u.%s;\n", field_type_ch, field_name_ch, sym_char, field_name_ch);
fprintf(out, " %s %s = %s->u.%s;\n", field_mangled_type_ch, field_name_ch, sym_char, field_name_ch);

if (!ic_b2c_compile_body(input_kludge, tcase->tbody, out)) {
puts("ic_b2c_compile_stmt_match: call to ic_b2c_compile_body failed for case body");
Expand Down
8 changes: 4 additions & 4 deletions t/custom/test_generics_progress.pl
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@
end
',
expected => '
Maybe[Maybe[Sint]]{6}
Maybe[Sint]{4}
Maybe[Maybe[Sint]]{Maybe[Sint]{6}}
Maybe[Sint]{6}
My Maybe contained: 6s
Maybe[String]{"Hello Maybe world"}
My Maybe contained: 6
Maybe[String]{Hello Maybe world}
',
failure => 1,
},
{
input => '
Expand Down

0 comments on commit 06ba1e7

Please sign in to comment.