GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/env/envset.c Lines: 41 44 93.2 %
Date: 2020-10-03 11:19:27 Branches: 27 40 67.5 %

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
281
ANN static void check(struct EnvSet *es, const Type t) {
9
281
  const Vector v = &es->env->scope->class_stack;
10
281
  Type owner = t->e->owner_class;
11

562
  for(vtype i = vector_size(v) + 1; owner && --i;) {
12
8
    if(owner != (Type)vector_at(v, i - 1)) {
13
8
      es->run = 1;
14
8
      return;
15
    }
16
    owner = owner->e->owner_class;
17
  }
18
}
19
20
8
ANN static m_bool push(struct EnvSet *es, const Type t) {
21
8
  if(t->e->owner_class)
22
    CHECK_BB(push(es, t->e->owner_class))
23
  else
24
8
    env_push(es->env, NULL, t->e->ctx->nspc);
25

8
  if(es->func && !(t->flag & es->flag))
26
4
    CHECK_BB(es->func((void*)es->data, t->e->def))
27
8
  if(GET_FLAG(t, template))
28
8
    CHECK_BB(template_push_types(es->env, t->e->def->base.tmpl))
29
8
  env_push_type((void*)es->env, t);
30
8
  return GW_OK;
31
}
32
33
269
ANN2(1,3) m_bool envset_push(struct EnvSet *es, const Type t, const Nspc nspc) {
34
269
  if(t) {
35
151
    check(es, t);
36
151
    return es->run ? push(es, t) : GW_OK;
37
  }
38
118
  if(nspc != es->env->curr) {
39
32
    env_push(es->env, NULL, nspc);
40
32
    es->run = 1;
41
  }
42
118
  return GW_OK;
43
}
44
45
40
ANN2(1) void envset_pop(struct EnvSet *es, const Type t) {
46
40
  env_pop(es->env, es->scope);
47
40
  if(!t)
48
32
    return;
49
8
  if(GET_FLAG(t, template))
50
8
    nspc_pop_type(es->env->gwion->mp, es->env->curr);
51
8
  if(t->e->owner_class)
52
    envset_pop(es, t->e->owner_class);
53
  else
54
8
    env_pop(es->env, es->scope);
55
}
56
57
130
ANN m_bool envset_run(struct EnvSet *es, const Type t) {
58
130
  check(es, t);
59
130
  if(es->run)
60
8
    CHECK_BB(push(es, t->e->owner_class))
61
260
  const m_bool ret = !(t->flag & es->flag) ?
62
130
    es->func(es->data, t->e->def) : GW_OK;
63
130
  if(es->run)
64
8
    envset_pop(es, t->e->owner_class);
65
130
  return ret;
66
}