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

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