tokenpos.h

filter: Statementstmt 92.3% 12 / 13 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 89.4% 17 / 19 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Parser.xs ↑ Summary util.c »
1 struct token_pos
2 {
3 char *beg;
4 char *end;
5 };
6 typedef struct token_pos token_pos_t;
7  
8 #define dTOKENS(init_lim) \
9 token_pos_t token_buf[init_lim]; \
10 int token_lim = init_lim; \
11 token_pos_t *tokens = token_buf; \
12 int num_tokens = 0
13  
14 #define PUSH_TOKEN(p_beg, p_end) \
15 STMT_START { \
16 ++num_tokens; \
17 if (num_tokens == token_lim) \
18 tokens_grow(&tokens, &token_lim, (bool)(tokens != token_buf)); \
19 tokens[num_tokens-1].beg = p_beg; \
20 tokens[num_tokens-1].end = p_end; \
21 } STMT_END
22  
23 #define FREE_TOKENS \
24 STMT_START { \
25 if (tokens != token_buf) \
26 Safefree(tokens); \
27 } STMT_END
28  
29 static void
30 2018 tokens_grow(token_pos_t **token_ptr, int *token_lim_ptr, bool tokens_on_heap)
31 {
32 2018 int new_lim = *token_lim_ptr;
33 2018 ▶ if (new_lim < 4)
Branch: 1 branch
BranchTrueFalseTotal
if (new_lim < 4) 0 2018 2018
34 0 new_lim = 4;
35 2018 new_lim *= 2;
36  
37 2018 ▶ if (tokens_on_heap) {
Branch: 1 branch
BranchTrueFalseTotal
if (tokens_on_heap) { 1073 945 2018
38 1073 Renew(*token_ptr, new_lim, token_pos_t);
39 }
40 else {
41 token_pos_t *new_tokens;
42 int i;
43 945 New(57, new_tokens, new_lim, token_pos_t);
44 14833 ▶ for (i = 0; i < *token_lim_ptr; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < *token_lim_ptr; i++) 13888 945 14833
45 13888 new_tokens[i] = (*token_ptr)[i];
46 945 *token_ptr = new_tokens;
47 }
48 2018 *token_lim_ptr = new_lim;
49 2018 }
« Parser.xs ↑ Summary util.c »