GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/env/envset.c Lines: 41 44 93.2 %
Date: 2020-09-12 17:36:58 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
299
ANN static void check(struct EnvSet *es, const Type t) {
9
299
  const Vector v = &es->env->scope->class_stack;
10
299
  Type owner = t->e->owner_class;
11

598
  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
272
ANN2(1,3) m_bool envset_push(struct EnvSet *es, const Type t, const Nspc nspc) {
34
272
  if(t) {
35
151
    check(es, t);
36
151
    return es->run ? push(es, t) : GW_OK;
37
  }
38
121
  if(nspc != es->env->curr) {
39
30
    env_push(es->env, NULL, nspc);
40
30
    es->run = 1;
41
  }
42
121
  return GW_OK;
43
}
44
45
38
ANN2(1) void envset_pop(struct EnvSet *es, const Type t) {
46
38
  env_pop(es->env, es->scope);
47
38
  if(!t)
48
30
    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
148
ANN m_bool envset_run(struct EnvSet *es, const Type t) {
58
148
  check(es, t);
59
148
  if(es->run)
60
8
    CHECK_BB(push(es, t->e->owner_class))
61
296
  const m_bool ret = !(t->flag & es->flag) ?
62
148
    es->func(es->data, t->e->def) : GW_OK;
63
148
  if(es->run)
64
8
    envset_pop(es, t->e->owner_class);
65
148
  return ret;
66
}