| 1 |
|
| #include <stdlib.h> |
| 2 |
|
| #include <assert.h> |
| 3 |
|
| |
| 4 |
|
| #define INIT_ENV_DEPTH 256 |
| 5 |
|
| |
| 6 |
|
| static |
| 7 |
521 |
| void tagstack_init(struct tagstack* tagstack) { |
| 8 |
521 |
| tagstack->depth=INIT_ENV_DEPTH; |
| 9 |
521 |
| tagstack->pos=-1; |
| 10 |
521 |
| tagstack->entry=(struct tagstack_entry*) malloc (tagstack->depth * sizeof(struct tagstack_entry)); |
| 11 |
521 |
| } |
| 12 |
|
| |
| 13 |
|
| static |
| 14 |
521 |
| void tagstack_free(struct tagstack* tagstack) { |
| 15 |
521 |
| tagstack->depth=-1; |
| 16 |
521 |
| tagstack->pos=-1; |
| 17 |
521 |
| free(tagstack->entry); |
| 18 |
521 |
| } |
| 19 |
|
| |
| 20 |
|
| INLINE |
| 21 |
|
| static |
| 22 |
0 |
| int tagstack_notempty(const struct tagstack* tagstack) { |
| 23 |
0 |
| return tagstack->pos >= 0; |
| 24 |
|
| } |
| 25 |
|
| |
| 26 |
|
| /* |
| 27 |
|
| static |
| 28 |
|
| void tagstack_entry_debug(struct tagstack_entry item) { |
| 29 |
|
| tmpl_log(TMPL_LOG_DEBUG,"vcontext = %d value=%d\n",item.vcontext,item.value); |
| 30 |
|
| } |
| 31 |
|
| */ |
| 32 |
|
| |
| 33 |
|
| INLINE |
| 34 |
|
| static |
| 35 |
660 |
| struct tagstack_entry* tagstack_top(const struct tagstack* tagstack) { |
| 36 |
660 |
| return tagstack->entry+tagstack->pos; |
| 37 |
|
| } |
| 38 |
|
| |
| 39 |
|
| static |
| 40 |
678 |
| struct tagstack_entry tagstack_pop(struct tagstack* tagstack, int* is_underflow) { |
| 41 |
678 |
▶ | if (is_underflow != NULL) *is_underflow=0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_underflow != NULL) *is_underflow=0; |
678 |
0 |
678 |
|
| 42 |
678 |
▶ | if (tagstack->pos<0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tagstack->pos<0) { |
1 |
677 |
678 |
|
| 43 |
1 |
| tagstack->pos=0; |
| 44 |
1 |
▶ | if (is_underflow != NULL) *is_underflow=1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_underflow != NULL) *is_underflow=1; |
1 |
0 |
1 |
|
| 45 |
1 |
▶ | if (tagstack->depth<0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tagstack->depth<0) { |
0 |
1 |
1 |
|
| 46 |
0 |
| tmpl_log(TMPL_LOG_ERROR,"FATAL:stack error:tags stack is uninitialized\n"); |
| 47 |
0 |
| tagstack_init(tagstack); |
| 48 |
|
| } |
| 49 |
|
| } |
| 50 |
678 |
| return *(tagstack->entry+ tagstack->pos--); |
| 51 |
|
| } |
| 52 |
|
| |
| 53 |
|
| static |
| 54 |
678 |
| void tagstack_push(struct tagstack* tagstack, struct tagstack_entry item) { |
| 55 |
|
| /* overflow check */ |
| 56 |
678 |
▶ | if (++(tagstack->pos)>=tagstack->depth) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (++(tagstack->pos)>=tagstack->depth) { |
0 |
678 |
678 |
|
| 57 |
0 |
▶ | if (tagstack->depth<INIT_ENV_DEPTH) tagstack->depth=INIT_ENV_DEPTH; |
Branch: 1 branch
| Branch | True | False | Total |
| if (tagstack->depth<INIT_ENV_DEPTH) tagstack->depth=INIT_ENV_DEPTH; |
0 |
0 |
0 |
|
| 58 |
0 |
| tagstack->depth*=2; |
| 59 |
0 |
| tagstack->entry=(struct tagstack_entry*) realloc (tagstack->entry, tagstack->depth * sizeof(struct tagstack_entry)); |
| 60 |
|
| } |
| 61 |
678 |
| *(tagstack->entry+tagstack->pos)=item; |
| 62 |
678 |
| } |
| 63 |
|
| |
| 64 |
|
| /* |
| 65 |
|
| * Local Variables: |
| 66 |
|
| * mode: c |
| 67 |
|
| * End: |
| 68 |
|
| */ |