Gwion coverage report


Directory: src/
File: src/parse/spread.c
Date: 2023-01-30 18:32:28
Exec Total Coverage
Lines: 82 84 97.6%
Functions: 3 3 100.0%
Branches: 49 66 74.2%

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 "template.h"
7 #include "parse.h"
8 #include "gwion.h"
9 #include "object.h"
10 #include "instr.h"
11 #include "operator.h"
12 #include "import.h"
13
14 5 ANN m_bool spread_ast(const Env env, const Spread_Def spread, const Tmpl *tmpl) {
15 5 const m_str data = spread->data;
16 char c[256];
17
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
5 DECL_OB(FILE *,f, = fmemopen(data, strlen(data), "r"));
18
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 4 times.
11 for(uint32_t i = tmpl->list->len - 1; i < tmpl->call->len; i++) {
19 7 fseek(f, 0, SEEK_SET);
20 7 Type_Decl* td = *mp_vector_at(tmpl->call, Type_Decl*, i);
21
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
8 DECL_OB(const Type, t, = known_type(env, td));
22 7 struct AstGetter_ arg = {env->name, f, env->gwion->st, .ppa = env->gwion->ppa};
23 7 const m_str type = type2str(env->gwion, t, td->pos);
24 7 sprintf(c, "%s=%s", s_name(spread->xid), type);
25 7 free_mstr(env->gwion->mp, type);
26 7 pparg_add(env->gwion->ppa, c);
27
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
14 for(uint32_t j = 0; j < spread->list->len; j++) {
28 7 const Symbol sym = *mp_vector_at(spread->list, Symbol, j);
29 7 m_str name = s_name(sym);
30 7 sprintf(c, "%s=%s%u", name, name, i);
31 7 pparg_add(env->gwion->ppa, c);
32 }
33 7 Ast ast = parse_pos(&arg, spread->pos);
34 7 pparg_rem(env->gwion->ppa, s_name(spread->xid));
35
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
14 for(uint32_t j = 0; j < spread->list->len;j++) {
36 7 const Symbol sym = *mp_vector_at(spread->list, Symbol, j);
37 7 m_str name = s_name(sym);
38 7 pparg_rem(env->gwion->ppa, name);
39 }
40
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if(!ast) return GW_ERROR;
41
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 CHECK_BB(scan0_ast(env, &ast));
42
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for(uint32_t i = 0; i < ast->len; i++) {
43 6 const Section section = *mp_vector_at(ast, Section, i);
44
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 mp_vector_add(env->gwion->mp, &env->context->extend, Section, section);
45 }
46 6 free_mp_vector(env->gwion->mp, Section , ast);
47 }
48 4 fclose(f);
49
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 mp_vector_add(env->gwion->mp, &env->context->extend, Section, MK_SECTION(stmt, stmt_list, NULL));
50 4 return GW_OK;
51 }
52
53 2 ANN Ast spread_class(const Env env, const Ast body) {
54 2 const Ast extend = env->context->extend;
55 2 Ast new_body = new_mp_vector(env->gwion->mp, Section, 0);
56 2 uint32_t offset = 0;
57
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for(uint32_t i = 0; i < body->len; i++) {
58 2 const Section section = *mp_vector_at(body, Section, i);
59
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(section.section_type == ae_section_stmt) {
60 2 Stmt_List list = section.d.stmt_list;
61 2 Stmt_List acc = NULL;
62
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
9 for(uint32_t j = 0; j < list->len; j++) {
63 7 const struct Stmt_ stmt = *mp_vector_at(list, struct Stmt_, j);
64
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
7 if(stmt.stmt_type == ae_stmt_spread) {
65
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if(acc) {
66
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 mp_vector_add(env->gwion->mp, &new_body, Section, MK_SECTION(stmt, stmt_list, acc));
67 2 acc = NULL;
68 }
69 4 const Ast extend = env->context->extend;
70
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for(; offset < extend->len; offset++) {
71 6 const Section section = *mp_vector_at(extend, Section, offset);
72
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 4 times.
6 if(section.section_type == ae_section_stmt && !section.d.stmt_list)
73 {
74 2 ++offset;
75 2 break;
76 }
77
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 mp_vector_add(env->gwion->mp, &new_body, Section, section);
78 }
79 } else {
80
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!acc)
81 3 acc = new_mp_vector(env->gwion->mp, struct Stmt_, 0);
82
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 mp_vector_add(env->gwion->mp, &acc, struct Stmt_, stmt);
83 }
84 }
85
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if(acc) {
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 mp_vector_add(env->gwion->mp, &new_body, Section, MK_SECTION(stmt, stmt_list, acc));
87 }
88 }
89 }
90 2 free_mp_vector(env->gwion->mp, Section, body);
91 2 free_mp_vector(env->gwion->mp, Section, extend);
92 2 return new_body;
93 }
94
95 2 ANN Stmt_List spread_func(const Env env, const Stmt_List body) {
96 2 const Ast extend = env->context->extend;
97 2 Ast new_body = new_mp_vector(env->gwion->mp, struct Stmt_, 0);
98 2 uint32_t offset = 0;
99
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for(uint32_t i = 0; i < body->len; i++) {
100 2 const struct Stmt_ stmt = *mp_vector_at(body, struct Stmt_, i);
101
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(stmt.stmt_type == ae_stmt_spread) {
102
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 for(; offset < extend->len; offset++) {
103 2 const Section section = *mp_vector_at(extend, Section, offset);
104
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if(section.section_type == ae_section_stmt && !section.d.stmt_list)
105 2 break;
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(section.section_type != ae_section_stmt)
107 ERR_O(stmt.pos, "invalid section in variadic func");
108 2 const Stmt_List list = section.d.stmt_list;
109
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for(uint32_t j = 0; j < list->len; j++) {
110 2 const struct Stmt_ stmt = *mp_vector_at(list, struct Stmt_, j);
111
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 mp_vector_add(env->gwion->mp, &new_body, struct Stmt_, stmt);
112 }
113 2 break;
114 }
115 } else {
116 mp_vector_add(env->gwion->mp, &new_body, struct Stmt_, stmt);
117 }
118 }
119 2 free_mp_vector(env->gwion->mp, Stmt_List, body);
120 2 free_mp_vector(env->gwion->mp, Section, extend);
121 2 return new_body;
122 }
123