Gwion coverage report


Directory: src/
File: src/import/import_type.c
Date: 2023-01-30 18:32:28
Exec Total Coverage
Lines: 22 30 73.3%
Functions: 4 4 100.0%
Branches: 15 22 68.2%

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 11484 ANN2(1) static Type get_parent(const Gwi gwi, const m_str parent_name) {
18
2/2
✓ Branch 0 taken 3828 times.
✓ Branch 1 taken 7656 times.
11484 Type_Decl *td = parent_name ? gwi_str2td(gwi, parent_name) : NULL;
19
2/2
✓ Branch 0 taken 3828 times.
✓ Branch 1 taken 7656 times.
11484 if (td) {
20
2/4
✓ Branch 0 taken 3828 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3828 times.
3828 if (td->array || td->types) {
21 const m_str str = td->array ? "array" : "template";
22 free_type_decl(gwi->gwion->mp, td);
23 GWI_ERR_O(_("can't use gwi_mk_type to extend %s types"), str)
24 }
25 }
26
2/2
✓ Branch 0 taken 3828 times.
✓ Branch 1 taken 7656 times.
11484 const Type parent = td ? known_type(gwi->gwion->env, td) : NULL;
27
2/2
✓ Branch 0 taken 3828 times.
✓ Branch 1 taken 7656 times.
11484 if (td) free_type_decl(gwi->gwion->mp, td);
28 11484 return parent;
29 }
30
31 ANN2(1, 2)
32 11488 Type gwi_mk_type(const Gwi gwi, const m_str name, const m_uint size,
33 const m_str parent_name) {
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11488 times.
11488 if (gwi->gwion->data->cdoc) {
35 gwfmt_indent(gwi->gwfmt);
36 gwfmt_util(gwi->gwfmt, "{+C}primitive{0} {+}%s{0}", name);
37 if (parent_name) gwfmt_util(gwi->gwfmt, " {+C}extends{0} {+}%s{0}", parent_name);
38 gwfmt_sc(gwi->gwfmt);
39 gwfmt_nl(gwi->gwfmt);
40 }
41
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 11484 times.
11488 CHECK_OO(gwi_str2sym(gwi, name));
42 11484 const Type parent = get_parent(gwi, parent_name);
43 11484 const Type t = new_type(gwi->gwion->mp, name, parent);
44 11484 t->size = size;
45
2/2
✓ Branch 1 taken 638 times.
✓ Branch 2 taken 10846 times.
11484 if(safe_tflag(parent, tflag_float))
46 638 set_tflag(t, tflag_float);
47 11484 return t;
48 }
49
50 24882 ANN void gwi_add_type(const Gwi gwi, const Type type) {
51 24882 return env_add_type(gwi->gwion->env, type, gwi->loc);
52 }
53
54 10208 ANN void gwi_set_global_type(const Gwi gwi, const Type type,
55 const type_enum te) {
56 10208 gwi->gwion->type[te] = type;
57 10208 gwi_add_type(gwi, type);
58 10208 }
59