Line | Branch | Exec | Source |
---|---|---|---|
1 | /** @file: cleaner.c * | ||
2 | * \brief: functions to clean import module * | ||
3 | * */ | ||
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 | 76582 | ANN m_bool ck_ini(const Gwi gwi, const enum importck_type t) { | |
18 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 76578 times.
|
76582 | if (gwi->ck) // TODO: improve error message |
19 | 4 | GWI_ERR_B(_("already importing")) | |
20 | 76578 | gwi->ck = mp_calloc2(gwi->gwion->mp, sizeof(ImportCK)); | |
21 | 76578 | gwi->ck->type = t; | |
22 | 76578 | return GW_OK; | |
23 | } | ||
24 | |||
25 | 118076 | ANN m_bool ck_ok(const Gwi gwi, const enum importck_type t) { | |
26 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 118075 times.
|
118076 | if (!gwi->ck) GWI_ERR_B(_("import not started")) |
27 |
2/2✓ Branch 0 taken 118074 times.
✓ Branch 1 taken 1 times.
|
118075 | if (gwi->ck->type == t) return GW_OK; |
28 | // TODO: improve error message | ||
29 | 1 | GWI_ERR_B(_("already importing")) | |
30 | } | ||
31 | |||
32 | 75932 | ANN void ck_end(const Gwi gwi) { | |
33 | 75932 | mp_free2(gwi->gwion->mp, sizeof(ImportCK), gwi->ck); | |
34 | 75932 | gwi->ck = NULL; | |
35 | 75932 | } | |
36 | |||
37 | typedef void (*cleaner)(MemPool, ImportCK *); | ||
38 | static cleaner cleaners[] = {NULL, ck_clean_udef, ck_clean_tdef, | ||
39 | NULL, // ck_clean_oper, | ||
40 | ck_clean_item, ck_clean_fdef}; | ||
41 | |||
42 | 8 | ANN void ck_clean(const Gwi gwi) { | |
43 | 8 | const cleaner clean = cleaners[gwi->ck->type]; | |
44 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | if (clean) clean(gwi->gwion->mp, gwi->ck); |
45 | 8 | memset(gwi->ck, 0, sizeof(ImportCK)); | |
46 | 8 | } | |
47 |