GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/parse/scanx.c Lines: 43 43 100.0 %
Date: 2020-09-14 00:22:58 Branches: 35 42 83.3 %

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 "template.h"
6
#include "traverse.h"
7
#include "parse.h"
8
9
1766
ANN static inline m_bool _body(const Env e, Ast b, const _exp_func f) {
10
1766
  do CHECK_BB(f(e, b->section))
11
1737
  while((b = b->next));
12
973
  return GW_OK;
13
}
14
15
292
ANN static inline int actual(const Tmpl *tmpl) {
16

292
  return tmpl->call && tmpl->call != (Type_List)1 && tmpl->list;
17
}
18
19
146
ANN static inline m_bool tmpl_push(const Env env, const Tmpl* tmpl) {
20
146
  return actual(tmpl) ? template_push_types(env, tmpl) : GW_ERROR;
21
}
22
23
1002
ANN static inline m_int _push(const Env env, const Class_Def c) {
24
1002
  DECL_BB(const m_int, scope, = env_push_type(env, c->base.type))
25
1148
  return (!c->base.tmpl || tmpl_push(env, c->base.tmpl)) ?
26
2004
    scope : GW_ERROR;
27
}
28
29
1002
ANN static inline void _pop(const Env e, const Class_Def c, const m_uint s) {
30

1002
  if(c->base.tmpl && actual(c->base.tmpl) && c->base.tmpl->list)
31
128
    nspc_pop_type(e->gwion->mp, e->curr);
32
1002
  env_pop(e, s);
33
1002
}
34
35
// TODO: 'v' should be 2° argument
36
ANN m_bool
37
1002
scanx_body(const Env e, const Class_Def c, const _exp_func f, void* d) {
38
1002
  DECL_BB(const m_int, scope, = _push(e, c))
39
1002
  const m_bool ret =  _body(d, c->body, f);
40
1002
  _pop(e, c, scope);
41
1002
  return ret;
42
}
43
44
__attribute__((returns_nonnull))
45
93911
ANN Type unflag_type(const Type t) {
46
93911
  const Type type = !GET_FLAG(t, nonnull) ? t : t->e->parent;
47
93911
  return !GET_FLAG(type, force) ? type : type->e->parent;
48
}
49
50
__attribute__((returns_nonnull))
51
89057
ANN Type get_type(const Type t) {
52
89057
  const Type type = !t->array_depth ? t : array_base(t);
53
89057
  return unflag_type(type);
54
}
55
56
134
ANN m_bool scanx_cdef(const Env env, void* opt, const Class_Def cdef,
57
    const _exp_func f_cdef, const _exp_func f_union) {
58
134
  const Type t = get_type(cdef->base.type);
59
134
  if(t->e->parent !=  env->gwion->type[et_union])
60
122
     return f_cdef(opt, t->e->def);
61
12
  CHECK_BB(template_push_types(env, t->e->def->base.tmpl))
62
12
  const m_bool ret = f_union(opt, t->e->def->union_def);
63
12
  nspc_pop_type(env->gwion->mp, env->curr);
64
12
  return ret;
65
}
66
67
127114
ANN m_bool scanx_fdef(const Env env, void *data,
68
    const Func_Def fdef, const _exp_func func) {
69
127114
  if(fdef->base->tmpl)
70
323
    CHECK_BB(template_push_types(env, fdef->base->tmpl))
71
127111
  const m_bool ret = func(data, fdef);
72
127111
  if(fdef->base->tmpl)
73
320
    nspc_pop_type(env->gwion->mp, env->curr);
74
127111
  return ret;
75
}