| 1 |
|
| /* -*- c -*- |
| 2 |
|
| * File: proscope.c |
| 3 |
|
| * Author: Igor Vlasenko <vlasenko@imath.kiev.ua> |
| 4 |
|
| * Created: Thu May 26 15:25:57 2005 |
| 5 |
|
| * |
| 6 |
|
| * $Id$ |
| 7 |
|
| */ |
| 8 |
|
| |
| 9 |
|
| #include <stdlib.h> |
| 10 |
|
| #include "proscope.h" |
| 11 |
|
| #include "tmpllog.h" |
| 12 |
|
| |
| 13 |
|
| #define START_NUMBER_OF_NESTED_LOOPS 64 |
| 14 |
|
| |
| 15 |
|
| static |
| 16 |
|
| void |
| 17 |
448 |
| Scope_init(struct scope_stack* scopestack) { |
| 18 |
448 |
| scopestack->max=START_NUMBER_OF_NESTED_LOOPS; |
| 19 |
448 |
| scopestack->root=(struct ProScopeEntry*) malloc ((scopestack->max) * sizeof(struct ProScopeEntry)); |
| 20 |
448 |
▶ | if (NULL==scopestack->root) tmpl_log(TMPL_LOG_ERROR, "DIE:_Scope_init:internal error:not enough memory\n"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL==scopestack->root) tmpl_log(TMPL_LOG_ERROR, "DIE:_Scope_init:internal error:not enough memory\n"); |
0 |
448 |
448 |
|
| 21 |
448 |
| scopestack->level=-1; |
| 22 |
448 |
| } |
| 23 |
|
| |
| 24 |
|
| static |
| 25 |
|
| void |
| 26 |
448 |
| Scope_free(struct scope_stack* scopestack) { |
| 27 |
448 |
| free(scopestack->root); |
| 28 |
448 |
| scopestack->max=-1; |
| 29 |
448 |
| scopestack->level=-1; |
| 30 |
448 |
| } |
| 31 |
|
| |
| 32 |
|
| INLINE |
| 33 |
|
| static |
| 34 |
1392 |
| int curScopeLevel(const struct scope_stack* scopestack) { |
| 35 |
1392 |
| return scopestack->level; |
| 36 |
|
| } |
| 37 |
|
| |
| 38 |
|
| INLINE |
| 39 |
|
| static |
| 40 |
1242 |
| struct ProScopeEntry* getCurrentScope(const struct scope_stack* scopestack) { |
| 41 |
1242 |
| return scopestack->root+scopestack->level; |
| 42 |
|
| } |
| 43 |
|
| |
| 44 |
|
| INLINE |
| 45 |
|
| static |
| 46 |
|
| struct ProScopeEntry* |
| 47 |
1729 |
| getScope(const struct scope_stack* scopestack, int depth) { |
| 48 |
1729 |
| return &(scopestack->root)[depth]; |
| 49 |
|
| } |
| 50 |
|
| |
| 51 |
|
| static |
| 52 |
|
| void |
| 53 |
67 |
| popScope(struct scope_stack* scopestack) { |
| 54 |
67 |
▶ | if (scopestack->level>0) scopestack->level--; |
Branch: 1 branch
| Branch | True | False | Total |
| if (scopestack->level>0) scopestack->level--; |
67 |
0 |
67 |
|
| 55 |
0 |
| else tmpl_log(TMPL_LOG_ERROR, "WARN:PopScope:internal error:scope is exhausted\n"); |
| 56 |
67 |
| } |
| 57 |
|
| |
| 58 |
|
| static |
| 59 |
|
| void |
| 60 |
516 |
| _pushScope(struct scope_stack* scopestack) { |
| 61 |
516 |
▶ | if (scopestack->max<0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (scopestack->max<0) { |
0 |
516 |
516 |
|
| 62 |
0 |
| tmpl_log(TMPL_LOG_ERROR, "WARN:PushScope:internal warning:why scope is empty?\n"); |
| 63 |
0 |
| Scope_init(scopestack); |
| 64 |
|
| } |
| 65 |
516 |
| ++scopestack->level; |
| 66 |
516 |
▶ | if (scopestack->level>scopestack->max) |
Branch: 1 branch
| Branch | True | False | Total |
| if (scopestack->level>scopestack->max) |
0 |
516 |
516 |
|
| 67 |
|
| { |
| 68 |
0 |
▶ | if (scopestack->max<START_NUMBER_OF_NESTED_LOOPS) scopestack->max=START_NUMBER_OF_NESTED_LOOPS; |
Branch: 1 branch
| Branch | True | False | Total |
| if (scopestack->max<START_NUMBER_OF_NESTED_LOOPS) scopestack->max=START_NUMBER_OF_NESTED_LOOPS; |
0 |
0 |
0 |
|
| 69 |
0 |
| scopestack->max*=2; |
| 70 |
0 |
| scopestack->root=(struct ProScopeEntry*) realloc (scopestack->root, (scopestack->max) * sizeof(struct ProScopeEntry)); |
| 71 |
|
| } |
| 72 |
516 |
| } |
| 73 |
|
| |
| 74 |
|
| static |
| 75 |
|
| void |
| 76 |
67 |
| pushScopeLoop(struct scope_stack* scopestack, int loop_count, void *loops_AV) { |
| 77 |
|
| struct ProScopeEntry* CurrentScope; |
| 78 |
67 |
| _pushScope(scopestack); |
| 79 |
67 |
| CurrentScope=scopestack->root+scopestack->level; |
| 80 |
67 |
| CurrentScope->loop=-1; |
| 81 |
67 |
| CurrentScope->loop_count = loop_count; |
| 82 |
67 |
| CurrentScope->flags=0; |
| 83 |
67 |
| CurrentScope->loops_AV=loops_AV; |
| 84 |
67 |
| CurrentScope->param_HV=NULL; |
| 85 |
67 |
| } |
| 86 |
|
| |
| 87 |
|
| static |
| 88 |
|
| void |
| 89 |
449 |
| pushScopeMap(struct scope_stack* scopestack, void *param_HV, int flags) { |
| 90 |
|
| struct ProScopeEntry* CurrentScope; |
| 91 |
449 |
| _pushScope(scopestack); |
| 92 |
449 |
| CurrentScope=scopestack->root+scopestack->level; |
| 93 |
449 |
| CurrentScope->flags=flags; |
| 94 |
449 |
| CurrentScope->loops_AV=NULL; |
| 95 |
449 |
| CurrentScope->param_HV=param_HV; |
| 96 |
449 |
| } |
| 97 |
|
| |
| 98 |
|
| static |
| 99 |
|
| void |
| 100 |
896 |
| Scope_reset(struct scope_stack* scopestack, int keep_count) { |
| 101 |
896 |
| int init_level=-1; |
| 102 |
|
| // TODO; find out scope level |
| 103 |
896 |
▶ | if (scopestack->max<0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (scopestack->max<0) { |
0 |
896 |
896 |
|
| 104 |
0 |
| tmpl_log(TMPL_LOG_ERROR, "ERROR:Scope_reset:internal error:scope is empty.\n"); |
| 105 |
0 |
| Scope_init(scopestack); |
| 106 |
0 |
| scopestack->level=init_level; |
| 107 |
|
| } else { |
| 108 |
896 |
| scopestack->level=keep_count+init_level; |
| 109 |
|
| } |
| 110 |
896 |
| } |