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 |
|
1771 |
ANN static inline m_bool _body(const Env e, Ast b, const _exp_func f) { |
10 |
✓✓ |
1771 |
do CHECK_BB(f(e, b->section)) |
11 |
✓✓ |
1742 |
while((b = b->next)); |
12 |
|
978 |
return GW_OK; |
13 |
|
|
} |
14 |
|
|
|
15 |
|
302 |
ANN static inline int actual(const Tmpl *tmpl) { |
16 |
✓✓✓✗ ✓✗ |
302 |
return tmpl->call && tmpl->call != (Type_List)1 && tmpl->list; |
17 |
|
|
} |
18 |
|
|
|
19 |
|
151 |
ANN static inline m_bool tmpl_push(const Env env, const Tmpl* tmpl) { |
20 |
✓✓ |
151 |
return actual(tmpl) ? template_push_types(env, tmpl) : GW_ERROR; |
21 |
|
|
} |
22 |
|
|
|
23 |
|
1007 |
ANN static inline m_int _push(const Env env, const Class_Def c) { |
24 |
✗✓ |
1007 |
DECL_BB(const m_int, scope, = env_push_type(env, c->base.type)) |
25 |
✓✗ |
1158 |
return (!c->base.tmpl || tmpl_push(env, c->base.tmpl)) ? |
26 |
✓✓ |
2014 |
scope : GW_ERROR; |
27 |
|
|
} |
28 |
|
|
|
29 |
|
1007 |
ANN static inline void _pop(const Env e, const Class_Def c, const m_uint s) { |
30 |
✓✓✓✓ ✓✗ |
1007 |
if(c->base.tmpl && actual(c->base.tmpl) && c->base.tmpl->list) |
31 |
|
133 |
nspc_pop_type(e->gwion->mp, e->curr); |
32 |
|
1007 |
env_pop(e, s); |
33 |
|
1007 |
} |
34 |
|
|
|
35 |
|
|
// TODO: 'v' should be 2° argument |
36 |
|
|
ANN m_bool |
37 |
|
1007 |
scanx_body(const Env e, const Class_Def c, const _exp_func f, void* d) { |
38 |
✗✓ |
1007 |
DECL_BB(const m_int, scope, = _push(e, c)) |
39 |
|
1007 |
const m_bool ret = _body(d, c->body, f); |
40 |
|
1007 |
_pop(e, c, scope); |
41 |
|
1007 |
return ret; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
__attribute__((returns_nonnull)) |
45 |
|
94069 |
ANN Type unflag_type(const Type t) { |
46 |
✓✓ |
94069 |
const Type type = !GET_FLAG(t, nonnull) ? t : t->e->parent; |
47 |
✓✓ |
94069 |
return !GET_FLAG(type, force) ? type : type->e->parent; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
__attribute__((returns_nonnull)) |
51 |
|
89206 |
ANN Type get_type(const Type t) { |
52 |
✓✓ |
89206 |
const Type type = !t->array_depth ? t : array_base(t); |
53 |
|
89206 |
return unflag_type(type); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
138 |
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 |
|
138 |
const Type t = get_type(cdef->base.type); |
59 |
✓✓ |
138 |
if(t->e->parent != env->gwion->type[et_union]) |
60 |
|
126 |
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 |
|
127302 |
ANN m_bool scanx_fdef(const Env env, void *data, |
68 |
|
|
const Func_Def fdef, const _exp_func func) { |
69 |
✓✓ |
127302 |
if(fdef->base->tmpl) |
70 |
✓✓ |
334 |
CHECK_BB(template_push_types(env, fdef->base->tmpl)) |
71 |
|
127299 |
const m_bool ret = func(data, fdef); |
72 |
✓✓ |
127299 |
if(fdef->base->tmpl) |
73 |
|
331 |
nspc_pop_type(env->gwion->mp, env->curr); |
74 |
|
127299 |
return ret; |
75 |
|
|
} |