GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/parse/type_decl.c Lines: 30 32 93.8 %
Date: 2020-09-14 09:03:05 Branches: 28 30 93.3 %

Line Branch Exec Source
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
436695
ANN static Type resolve(const Env env, Type_Decl* td) {
10
436695
  DECL_OO(const Type, base, = find_type(env, td))
11

436668
  if(base->e->ctx && base->e->ctx->error)
12
    ERR_O(td_pos(td), _("type '%s' is invalid"), base->name)
13
436668
  DECL_OO(const Type, t, = scan_type(env, base, td))
14
436660
  const Type ret = !td->array ? t : array_type(env, t, td->array->depth);
15
436660
  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
419561
  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
436705
ANN Type known_type(const Env env, Type_Decl* td) {
53
436705
  if(!td->xid)
54
10
    return env->gwion->type[et_undefined];
55
436695
  return resolve(env, td) ?:type_unknown(env, td);
56
}