GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/import/type.c Lines: 23 23 100.0 %
Date: 2020-08-07 19:15:19 Branches: 14 16 87.5 %

Line Branch Exec Source
1
#include <stdlib.h>
2
#include <string.h>
3
#include <ctype.h>
4
#include "gwion_util.h"
5
#include "gwion_ast.h"
6
#include "gwion_env.h"
7
#include "vm.h"
8
#include "traverse.h"
9
#include "instr.h"
10
#include "object.h"
11
#include "emit.h"
12
#include "gwion.h"
13
#include "operator.h"
14
#include "import.h"
15
#include "gwi.h"
16
17
12412
ANN2(1) static Type get_parent(const Gwi gwi, const m_str parent_name) {
18
12412
  Type_Decl* td = parent_name ? str2decl(gwi, parent_name) : NULL;
19
12412
  if(td) {
20

4381
    if(td->array || td->types) {
21
1
      const m_str str = td->array ? "array" : "template";
22
1
      free_type_decl(gwi->gwion->mp, td);
23
1
      GWI_ERR_O(_("can't use gwi_mk_type to extend %s types"), str)
24
    }
25
  }
26
12411
  const Type parent = td ? known_type(gwi->gwion->env, td) : NULL;
27
12411
  if(td)
28
4380
    free_type_decl(gwi->gwion->mp, td);
29
12411
  return parent;
30
}
31
32
12417
ANN2(1,2) Type gwi_mk_type(const Gwi gwi, const m_str name, const m_uint size, const m_str parent_name) {
33
12417
  CHECK_OO(str2sym(gwi, name))
34
12412
  const Type parent = get_parent(gwi, parent_name);
35
12412
  const Type t = new_type(gwi->gwion->mp, 0, name, parent);
36
12412
  t->size = size;
37
12412
  return t;
38
}
39
40
26302
ANN m_int gwi_add_type(const Gwi gwi, const Type type) {
41
26302
  env_add_type(gwi->gwion->env, type);
42
26302
  return (m_int)type->xid;
43
}
44
45
10950
ANN m_int gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te) {
46
10950
  gwi->gwion->type[te] = type;
47
10950
  return gwi_add_type(gwi, type);
48
}