Gwion coverage report


Directory: src/
File: src/env/envset.c
Date: 2023-01-30 18:32:28
Exec Total Coverage
Lines: 50 54 92.6%
Functions: 6 6 100.0%
Branches: 28 42 66.7%

Line Branch Exec Source
1 #include "gwion_util.h"
2 #include "gwion_ast.h"
3 #include "gwion_env.h"
4 #include "vm.h"
5 #include "gwion.h"
6 #include "template.h"
7
8 154 ANN static void check(struct EnvSet *es, const Type t) {
9 154 es->_ctx = es->env->context;
10 154 es->_filename = es->env->name;
11 154 const Vector v = &es->env->scope->class_stack;
12 154 Type owner = t->info->value->from->owner_class;
13
3/4
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
154 for (vtype i = vector_size(v) + 1; owner && --i;) {
14
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 if (owner != (Type)vector_at(v, i - 1)) {
15 4 es->run = 1;
16 4 return;
17 }
18 owner = owner->info->value->from->owner_class;
19 }
20 }
21
22 4 ANN static m_bool push(struct EnvSet *es, const Type t) {
23 4 es->env->scope->depth = 0;
24 4 const Type owner_class = t->info->value->from->owner_class;
25
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (owner_class)
26 CHECK_BB(push(es, owner_class));
27 else
28 4 env_push(es->env, NULL,
29
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 t->info->value->from->ctx ? t->info->value->from->ctx->nspc
30 : es->env->curr);
31 4 env_push_type((void *)es->env, t); // do not push if is a function?
32
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 if (tflag(t, tflag_tmpl))
33
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 CHECK_BB(template_push_types(
34 es->env, t->info->cdef->base.tmpl)); // incorrect templates?
35 4 return GW_OK;
36 }
37
38 ANN2(1, 3)
39 831 m_bool envset_push(struct EnvSet *es, const Type t, const Nspc nspc) {
40
2/2
✓ Branch 0 taken 97 times.
✓ Branch 1 taken 734 times.
831 if (t) {
41 97 check(es, t);
42 // if(es->run && type_global(es->env, t))
43 // env_push_global(es->env);
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 97 times.
97 return es->run ? push(es, t) : GW_OK;
45 }
46
2/2
✓ Branch 0 taken 644 times.
✓ Branch 1 taken 90 times.
734 if (nspc != es->env->curr) {
47 644 env_push(es->env, NULL, nspc);
48 644 es->run = 1;
49 }
50 734 return GW_OK;
51 }
52
53 648 ANN2(1) static void _envset_pop(struct EnvSet *es, const Type t) {
54
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 644 times.
648 if (safe_tflag(t, tflag_tmpl)) // might not be useful
55 4 nspc_pop_type(es->env->gwion->mp, es->env->curr);
56 648 env_pop(es->env, es->scope);
57
2/2
✓ Branch 0 taken 644 times.
✓ Branch 1 taken 4 times.
648 if (!t) return;
58 4 const Type owner_class = t->info->value->from->owner_class;
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (owner_class)
60 envset_pop(es, owner_class);
61 else
62 4 env_pop(es->env, es->scope);
63 }
64
65 888 ANN2(1) void envset_pop(struct EnvSet *es, const Type t) {
66
2/2
✓ Branch 0 taken 648 times.
✓ Branch 1 taken 240 times.
888 if(es->run) _envset_pop(es, t);
67 // if(t && type_global(es->env, t))
68 // env_pop(es->env, es->scope);
69
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 638 times.
888 if (es->_ctx) es->env->context = es->_ctx;
70
1/2
✓ Branch 0 taken 888 times.
✗ Branch 1 not taken.
888 if (es->_filename) es->env->name = es->_filename;
71 888 }
72
73 57 ANN m_bool envset_run(struct EnvSet *es, const Type t) {
74 57 check(es, t);
75 57 const Type owner_class = t->info->value->from->owner_class;
76
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 53 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
57 if (es->run) CHECK_BB(push(es, owner_class));
77 57 es->env->context = t->info->value->from->ctx;
78 57 es->env->name = t->info->value->from->filename;
79 57 const m_bool ret =
80
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 t->info->cdef && !(t->tflag & es->flag) ? es->func(es->data, t) : GW_OK;
81 57 envset_pop(es, owner_class);
82 57 return ret;
83 }
84