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

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