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