GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/import/import_type.c Lines: 23 23 100.0 %
Date: 2020-10-03 09:50:08 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
12124
ANN2(1) static Type get_parent(const Gwi gwi, const m_str parent_name) {
18
12124
  Type_Decl* td = parent_name ? str2decl(gwi, parent_name) : NULL;
19
12124
  if(td) {
20

3566
    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
12123
  const Type parent = td ? known_type(gwi->gwion->env, td) : NULL;
27
12123
  if(td)
28
3565
    free_type_decl(gwi->gwion->mp, td);
29
12123
  return parent;
30
}
31
32
12128
ANN2(1,2) Type gwi_mk_type(const Gwi gwi, const m_str name, const m_uint size, const m_str parent_name) {
33
12128
  CHECK_OO(str2sym(gwi, name))
34
12124
  const Type parent = get_parent(gwi, parent_name);
35
12124
  const Type t = new_type(gwi->gwion->mp, 0, name, parent);
36
12124
  t->size = size;
37
12124
  return t;
38
}
39
40
27115
ANN m_int gwi_add_type(const Gwi gwi, const Type type) {
41
27115
  env_add_type(gwi->gwion->env, type);
42
27115
  return (m_int)type->xid;
43
}
44
45
11408
ANN m_int gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te) {
46
11408
  gwi->gwion->type[te] = type;
47
11408
  return gwi_add_type(gwi, type);
48
}