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 |
|
438018 |
ANN static Type resolve(const Env env, Type_Decl* td) { |
10 |
✓✓ |
438018 |
DECL_OO(const Type, base, = find_type(env, td)) |
11 |
✓✓✗✓
|
437991 |
if(base->e->ctx && base->e->ctx->error) |
12 |
|
|
ERR_O(td_pos(td), _("type '%s' is invalid"), base->name) |
13 |
✓✓ |
437991 |
DECL_OO(const Type, t, = scan_type(env, base, td)) |
14 |
✓✓ |
437983 |
const Type ret = !td->array ? t : array_type(env, t, td->array->depth); |
15 |
✓✓ |
437983 |
if(GET_FLAG(td, nonnull)) { |
16 |
✓✓ |
17835 |
if(isa(ret, env->gwion->type[et_void]) > 0) |
17 |
|
1 |
ERR_O(td_pos(td), _("void types can't be nonnull.")) |
18 |
✓✓✗✓
|
17834 |
if(isa(ret, env->gwion->type[et_object]) < 0 && isa(ret, env->gwion->type[et_fptr]) < 0) |
19 |
|
|
return ret; |
20 |
|
17834 |
return nonnul_type(env, ret); |
21 |
|
|
} |
22 |
|
420148 |
return ret; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
struct td_info { |
26 |
|
|
Type_List tl; |
27 |
|
|
GwText text; |
28 |
|
|
}; |
29 |
|
|
|
30 |
|
151 |
ANN static m_bool td_info_run(const Env env, struct td_info* info) { |
31 |
|
151 |
Type_List tl = info->tl; |
32 |
|
|
do { |
33 |
✓✓ |
157 |
DECL_OB(const Type, t, = known_type(env, tl->td)) |
34 |
|
156 |
text_add(&info->text, t->name); |
35 |
✓✓ |
156 |
if(tl->next) |
36 |
|
6 |
text_add(&info->text, ","); |
37 |
✓✓ |
156 |
} while((tl = tl->next)); |
38 |
|
150 |
return GW_OK; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
151 |
ANEW ANN m_str tl2str(const Env env, Type_List tl) { |
42 |
|
151 |
struct td_info info = { .tl=tl, { .mp=env->gwion->mp} }; |
43 |
✓✓ |
151 |
CHECK_BO(td_info_run(env, &info)) |
44 |
|
150 |
return info.text.str; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
36 |
ANN static inline void* type_unknown(const Env env, const Type_Decl* td) { |
48 |
|
36 |
env_err(env, td->pos, _("unknown type '%s'"), s_name(td->xid)); |
49 |
|
36 |
return NULL; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
438028 |
ANN Type known_type(const Env env, Type_Decl* td) { |
53 |
✓✓ |
438028 |
if(!td->xid) |
54 |
|
10 |
return env->gwion->type[et_undefined]; |
55 |
✓✓ |
438018 |
return resolve(env, td) ?:type_unknown(env, td); |
56 |
|
|
} |