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