GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/parse/scanx.c Lines: 43 43 100.0 %
Date: 2020-08-07 19:15:19 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
1757
ANN static inline m_bool _body(const Env e, Ast b, const _exp_func f) {
10
1757
  do CHECK_BB(f(e, b->section))
11
1725
  while((b = b->next));
12
962
  return GW_OK;
13
}
14
15
340
ANN static inline int actual(const Tmpl *tmpl) {
16

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

994
  if(c->base.tmpl && actual(c->base.tmpl) && c->base.tmpl->list)
31
152
    nspc_pop_type(e->gwion->mp, e->curr);
32
994
  env_pop(e, s);
33
994
}
34
35
// TODO: 'v' should be 2° argument
36
ANN m_bool
37
994
scanx_body(const Env e, const Class_Def c, const _exp_func f, void* d) {
38
994
  DECL_BB(const m_int, scope, = _push(e, c))
39
994
  const m_bool ret =  _body(d, c->body, f);
40
994
  _pop(e, c, scope);
41
994
  return ret;
42
}
43
44
__attribute__((returns_nonnull))
45
94322
ANN Type unflag_type(const Type t) {
46
94322
  const Type type = !GET_FLAG(t, nonnull) ? t : t->e->parent;
47
94322
  return !GET_FLAG(type, force) ? type : type->e->parent;
48
}
49
50
__attribute__((returns_nonnull))
51
93783
ANN Type get_type(const Type t) {
52
93783
  const Type type = !t->array_depth ? t : array_base(t);
53
93783
  return unflag_type(type);
54
}
55
56
152
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
152
  const Type t = get_type(cdef->base.type);
59
152
  if(t->e->parent !=  env->gwion->type[et_union])
60
140
     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
130412
ANN m_bool scanx_fdef(const Env env, void *data,
68
    const Func_Def fdef, const _exp_func func) {
69
130412
  if(fdef->base->tmpl)
70
305
    CHECK_BB(template_push_types(env, fdef->base->tmpl))
71
130409
  const m_bool ret = func(data, fdef);
72
130409
  if(fdef->base->tmpl)
73
302
    nspc_pop_type(env->gwion->mp, env->curr);
74
130409
  return ret;
75
}