GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/import/import_item.c Lines: 33 33 100.0 %
Date: 2020-09-21 18:02:52 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
22091
ANN m_int gwi_item_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name) {
14
22091
  CHECK_BB(ck_ini(gwi, ck_item))
15
22091
  if((gwi->ck->exp = make_exp(gwi, type, name)))
16
22085
    return GW_OK;
17
6
  GWI_ERR_B(_("  ...  during var import '%s.%s'."), gwi->gwion->env->name, name)
18
}
19
20
1426
ANN static m_int gwi_item_tmpl(const Gwi gwi) {
21
1426
  const MemPool mp = gwi->gwion->mp;
22
1426
  const Stmt stmt = new_stmt_exp(mp, ae_stmt_exp, gwi->ck->exp);
23
1426
  const Stmt_List slist = new_stmt_list(mp, stmt, NULL);
24
1426
  Section* section = new_section_stmt_list(mp, slist);
25
1426
  const Ast body = new_ast(mp, section, NULL);
26
1426
  gwi_body(gwi, body);
27
1426
  mp_free2(gwi->gwion->mp, sizeof(ImportCK), gwi->ck);
28
1426
  gwi->ck = NULL;
29
1426
  return GW_OK;
30
}
31
32
#undef gwi_item_end
33
22085
ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, const m_uint* addr) {
34
22085
  CHECK_BB(ck_ok(gwi, ck_item))
35
22084
  const Env env = gwi->gwion->env;
36
22084
  gwi->ck->exp->d.exp_decl.list->self->addr = (m_uint*)addr;
37
22084
  gwi->ck->exp->d.exp_decl.td->flag = flag;
38

22084
  if(env->class_def && GET_FLAG(env->class_def, template))
39
1426
    return gwi_item_tmpl(gwi);
40
20658
  CHECK_BB(traverse_exp(env, gwi->ck->exp))
41
20657
  const Value value = gwi->ck->exp->d.exp_decl.list->self->value;
42
20657
  SET_FLAG(value, builtin);
43
20657
  const m_uint offset = value->from->offset;
44
20657
  free_exp(gwi->gwion->mp, gwi->ck->exp);
45
20657
  ck_end(gwi);
46
20657
  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
}