1 |
|
|
#include "gwion_util.h" |
2 |
|
|
#include "gwion_ast.h" |
3 |
|
|
#include "gwion_env.h" |
4 |
|
|
#include "vm.h" |
5 |
|
|
#include "traverse.h" |
6 |
|
|
#include "parse.h" |
7 |
|
|
|
8 |
|
|
|
9 |
|
436825 |
ANN static Type resolve(const Env env, Type_Decl* td) { |
10 |
✓✓ |
436825 |
DECL_OO(const Type, base, = find_type(env, td)) |
11 |
✓✓✗✓
|
436800 |
if(base->e->ctx && base->e->ctx->error) |
12 |
|
|
ERR_O(td_pos(td), _("type '%s' is invalid"), base->name) |
13 |
✓✓ |
436800 |
DECL_OO(const Type, t, = scan_type(env, base, td)) |
14 |
✓✓ |
436794 |
const Type ret = !td->array ? t : array_type(env, t, td->array->depth); |
15 |
✓✓ |
436794 |
if(GET_FLAG(td, nonnull)) { |
16 |
✓✓ |
17099 |
if(isa(ret, env->gwion->type[et_void]) > 0) |
17 |
|
1 |
ERR_O(td_pos(td), _("void types can't be nonnull.")) |
18 |
✓✓✗✓
|
17098 |
if(isa(ret, env->gwion->type[et_object]) < 0 && isa(ret, env->gwion->type[et_fptr]) < 0) |
19 |
|
|
return ret; |
20 |
|
17098 |
return nonnul_type(env, ret); |
21 |
|
|
} |
22 |
|
419695 |
return ret; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
struct td_info { |
26 |
|
|
Type_List tl; |
27 |
|
|
GwText text; |
28 |
|
|
}; |
29 |
|
|
|
30 |
|
153 |
ANN static m_bool td_info_run(const Env env, struct td_info* info) { |
31 |
|
153 |
Type_List tl = info->tl; |
32 |
|
|
do { |
33 |
✓✓ |
159 |
DECL_OB(const Type, t, = known_type(env, tl->td)) |
34 |
|
158 |
text_add(&info->text, t->name); |
35 |
✓✓ |
158 |
if(tl->next) |
36 |
|
6 |
text_add(&info->text, ","); |
37 |
✓✓ |
158 |
} while((tl = tl->next)); |
38 |
|
152 |
return GW_OK; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
153 |
ANEW ANN m_str tl2str(const Env env, Type_List tl) { |
42 |
|
153 |
struct td_info info = { .tl=tl, { .mp=env->gwion->mp} }; |
43 |
✓✓ |
153 |
CHECK_BO(td_info_run(env, &info)) |
44 |
|
152 |
return info.text.str; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
32 |
ANN static inline void* type_unknown(const Env env, const Type_Decl* td) { |
48 |
|
32 |
env_err(env, td->pos, _("unknown type '%s'"), s_name(td->xid)); |
49 |
|
32 |
return NULL; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
436835 |
ANN Type known_type(const Env env, Type_Decl* td) { |
53 |
✓✓ |
436835 |
if(!td->xid) |
54 |
|
10 |
return env->gwion->type[et_undefined]; |
55 |
✓✓ |
436825 |
return resolve(env, td) ?:type_unknown(env, td); |
56 |
|
|
} |