Line | Branch | Exec | Source |
---|---|---|---|
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include <ctype.h> | ||
4 | #include "gwion_util.h" | ||
5 | #include "gwion_ast.h" | ||
6 | #include "gwion_env.h" | ||
7 | #include "vm.h" | ||
8 | #include "traverse.h" | ||
9 | #include "instr.h" | ||
10 | #include "emit.h" | ||
11 | #include "gwion.h" | ||
12 | #include "object.h" | ||
13 | #include "operator.h" | ||
14 | #include "import.h" | ||
15 | #include "gwi.h" | ||
16 | |||
17 | // move me | ||
18 | 12123 | ANN Exp make_exp(const Gwi gwi, const m_str type, const m_str name) { | |
19 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12123 times.
|
12123 | DECL_OO(Type_Decl *, td, = gwi_str2td(gwi, type)); |
20 | struct Var_Decl_ vd; | ||
21 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12123 times.
|
12123 | if(gwi_str2var(gwi, &vd, name) < 0) { |
22 | ✗ | free_type_decl(gwi->gwion->mp, td); | |
23 | ✗ | return NULL; | |
24 | } | ||
25 | 12123 | return new_exp_decl(gwi->gwion->mp, td, &vd, gwi->loc); | |
26 | } | ||
27 | |||
28 | 641 | ANN m_int gwi_union_ini(const Gwi gwi, const m_str name) { | |
29 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 640 times.
|
641 | CHECK_BB(ck_ini(gwi, ck_udef)); |
30 | 640 | gwi->ck->name = name; | |
31 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 640 times.
|
640 | CHECK_BB(check_typename_def(gwi, gwi->ck)); |
32 | 640 | gwi->ck->mpv = new_mp_vector(gwi->gwion->mp, Union_Member, 0); | |
33 | 640 | return GW_OK; | |
34 | } | ||
35 | |||
36 | 1279 | ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, | |
37 | const restrict m_str name) { | ||
38 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1279 times.
|
1279 | CHECK_BB(ck_ok(gwi, ck_udef)); |
39 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1279 times.
|
1279 | DECL_OB(Type_Decl *, td, = str2td(gwi->gwion, type, gwi->loc)); |
40 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1279 times.
|
1279 | DECL_OB(const Symbol, xid, = str2sym(gwi->gwion, name, gwi->loc)); |
41 | 1279 | Union_Member um = { .td = td, .vd = { .xid = xid, .pos = gwi->loc } }; | |
42 |
2/2✓ Branch 0 taken 1278 times.
✓ Branch 1 taken 1 times.
|
1279 | mp_vector_add(gwi->gwion->mp, &gwi->ck->list, Union_Member, um); |
43 | // const Union_List l = new_union_list(gwi->gwion->mp, td, xid, gwi->loc); | ||
44 | // l->next = gwi->ck->list; | ||
45 | // gwi->ck->list = l; | ||
46 | 1279 | return GW_OK; | |
47 | } | ||
48 | |||
49 | 638 | ANN static Type union_type(const Gwi gwi, const Union_Def udef) { | |
50 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 638 times.
|
638 | CHECK_BO(scan0_union_def(gwi->gwion->env, udef)); |
51 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 638 times.
|
638 | CHECK_BO(traverse_union_def(gwi->gwion->env, udef)); |
52 | // if(!udef->tmpl) | ||
53 | // emit_union_offset(udef->l, udef->o); | ||
54 | // if(gwi->gwion->env->class_def && !GET_FLAG(udef, static)) | ||
55 | // gwi->gwion->env->class_def->nspc->offset = | ||
56 | // udef->o + udef->s; | ||
57 | // set_vflag(udef->value, vflag_builtin); | ||
58 | // const M_Object o = new_object(gwi->gwion->mp, udef->value->type); | ||
59 | // udef->value->d.ptr = (m_uint*)o; | ||
60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | if (gwi->gwion->data->cdoc) { |
61 | ✗ | gwfmt_indent(gwi->gwfmt); | |
62 | ✗ | gwfmt_union_def(gwi->gwfmt, udef); | |
63 | } | ||
64 | 638 | return udef->type; | |
65 | } | ||
66 | |||
67 | 639 | ANN Type gwi_union_end(const Gwi gwi, const ae_flag flag) { | |
68 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 639 times.
|
639 | CHECK_BO(ck_ok(gwi, ck_udef)); |
69 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 638 times.
|
639 | if (!gwi->ck->mpv->len) GWI_ERR_O(_("union is empty")); |
70 | 638 | const Union_Def udef = new_union_def(gwi->gwion->mp, gwi->ck->mpv, gwi->loc); | |
71 | 638 | gwi->ck->list = NULL; | |
72 | 638 | udef->flag = flag; | |
73 | 638 | udef->xid = gwi->ck->sym; | |
74 |
1/2✓ Branch 0 taken 638 times.
✗ Branch 1 not taken.
|
638 | if (gwi->ck->tmpl) { |
75 | 638 | udef->tmpl = gwi_tmpl(gwi); | |
76 | 638 | gwi->ck->tmpl = NULL; | |
77 | } | ||
78 | 638 | const Type t = union_type(gwi, udef); | |
79 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 638 times.
|
638 | if (!safe_tflag(t, tflag_tmpl)) free_union_def(gwi->gwion->mp, udef); |
80 | 638 | ck_end(gwi); | |
81 | 638 | return t; | |
82 | } | ||
83 | |||
84 | 2 | ANN void ck_clean_udef(MemPool mp, ImportCK *ck) { | |
85 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ck->mpv) free_mp_vector(mp, Union_Member, ck->mpv); |
86 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (ck->tmpl) free_id_list(mp, ck->tmpl); |
87 | 2 | } | |
88 |