GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/import/import_item.c Lines: 33 33 100.0 %
Date: 2020-10-03 10:30:04 Branches: 13 14 92.9 %

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 "instr.h"
7
#include "object.h"
8
#include "gwion.h"
9
#include "operator.h"
10
#include "import.h"
11
#include "gwi.h"
12
13
22122
ANN m_int gwi_item_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name) {
14
22122
  CHECK_BB(ck_ini(gwi, ck_item))
15
22122
  if((gwi->ck->exp = make_exp(gwi, type, name)))
16
22116
    return GW_OK;
17
6
  GWI_ERR_B(_("  ...  during var import '%s.%s'."), gwi->gwion->env->name, name)
18
}
19
20
1428
ANN static m_int gwi_item_tmpl(const Gwi gwi) {
21
1428
  const MemPool mp = gwi->gwion->mp;
22
1428
  const Stmt stmt = new_stmt_exp(mp, ae_stmt_exp, gwi->ck->exp);
23
1428
  const Stmt_List slist = new_stmt_list(mp, stmt, NULL);
24
1428
  Section* section = new_section_stmt_list(mp, slist);
25
1428
  const Ast body = new_ast(mp, section, NULL);
26
1428
  gwi_body(gwi, body);
27
1428
  mp_free2(gwi->gwion->mp, sizeof(ImportCK), gwi->ck);
28
1428
  gwi->ck = NULL;
29
1428
  return GW_OK;
30
}
31
32
#undef gwi_item_end
33
22116
ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, const m_uint* addr) {
34
22116
  CHECK_BB(ck_ok(gwi, ck_item))
35
22115
  const Env env = gwi->gwion->env;
36
22115
  gwi->ck->exp->d.exp_decl.list->self->addr = (m_uint*)addr;
37
22115
  gwi->ck->exp->d.exp_decl.td->flag = flag;
38

22115
  if(env->class_def && GET_FLAG(env->class_def, template))
39
1428
    return gwi_item_tmpl(gwi);
40
20687
  CHECK_BB(traverse_exp(env, gwi->ck->exp))
41
20686
  const Value value = gwi->ck->exp->d.exp_decl.list->self->value;
42
20686
  SET_FLAG(value, builtin);
43
20686
  const m_uint offset = value->from->offset;
44
20686
  free_exp(gwi->gwion->mp, gwi->ck->exp);
45
20686
  ck_end(gwi);
46
20686
  return offset;
47
}
48
49
5
ANN void ck_clean_item(MemPool mp, ImportCK* ck) {
50
5
  if(ck->exp)
51
1
    free_exp(mp, ck->exp);
52
5
}