
Go to the source code of this file.
Defines | |
| #define | STACK_NULL ((stack) NULL) |
| defines for empty values | |
| #define | STACK_NULL_P(s) ((s)==STACK_NULL) |
| #define | stack_undefined ((stack)-14) |
| #define | stack_undefined_p(s) ((s)==stack_undefined) |
| #define | STACK_CHECK(s) |
| #define | STACK_MAP_X(_item, _itemtype, _code, _stack, _downwards) |
| not needed | |
| #define | STACK_MAP(_item, _itemtype, _code, _stack) STACK_MAP_X(_item, _itemtype, _code, _stack, true) |
Typedefs | |
| typedef struct __stack_head * | stack |
| STACK MANAGEMENT -- headers. | |
| typedef struct __stack_iterator * | stack_iterator |
Functions | |
| stack | stack_make (int, int, int) |
| allocation | |
| void | stack_free (stack *) |
| type, bucket_size, policy | |
| stack | stack_copy (const stack) |
| duplicate a stack with its contents. | |
| int | stack_size (const stack) |
| observers | |
| int | stack_type (const stack) |
| int | stack_bsize (const stack) |
| int | stack_policy (const stack) |
| int | stack_max_extent (const stack) |
| int | stack_consistent_p (const stack) |
| miscellaneous | |
| bool | stack_empty_p (const stack) |
| void | stack_info (FILE *, const stack) |
| void | stack_map (const stack, gen_iter_func_t) |
| APPLY f to all items of stack s;. | |
| void | stack_push (void *, stack) |
| stack use | |
| void * | stack_pop (stack) |
| POPs one item from stack s. | |
| void * | stack_head (const stack) |
| returns the item on top of stack s | |
| void * | stack_nth (const stack, int) |
| returns the nth item starting from the head and counting from 1, when possible, or NULL, elsewhere. | |
| void * | stack_replace (void *, stack) |
| REPLACEs the item on top of stack s, and returns the old item. | |
| stack_iterator | stack_iterator_init (const stack, bool) |
| stack iterator | |
| bool | stack_iterator_next_and_go (stack_iterator, void **) |
| X-ward. | |
| void | stack_iterator_end (stack_iterator *) |
| bool | stack_iterator_end_p (stack_iterator) |
| #define STACK_CHECK | ( | s | ) |
message_assert("stack null or undefined", \ !STACK_NULL_P(s) && !stack_undefined_p(s))
Definition at line 58 of file newgen_stack.h.
Referenced by stack_iterator_internal_init(), stack_map(), and STACK_OBSERVER().
| #define STACK_MAP | ( | _item, | |||
| _itemtype, | |||||
| _code, | |||||
| _stack | ) | STACK_MAP_X(_item, _itemtype, _code, _stack, true) |
Definition at line 116 of file newgen_stack.h.
| #define STACK_MAP_X | ( | _item, | |||
| _itemtype, | |||||
| _code, | |||||
| _stack, | |||||
| _downwards | ) |
{ \
stack_iterator _i = stack_iterator_init(_stack, _downwards); \
void * _vs_item; \
while (stack_iterator_next_and_go(_i, &_vs_item)) \
{ \
_itemtype _item = (_itemtype) _vs_item; \
_code; \
} \
stack_iterator_end(&_i); \
}
not needed
applies _code on the items of _stack downward , with _item of _itemtype.
Definition at line 104 of file newgen_stack.h.
Referenced by claire_loop(), claire_tiling(), stack_copy(), string_buffer_append_sb(), string_buffer_free(), string_buffer_size(), string_buffer_to_file(), string_buffer_to_string_internal(), xml_loop(), xml_Loops(), and xml_tiling().
defines for empty values
Definition at line 52 of file newgen_stack.h.
Referenced by stack_free(), and xml_Loops().
Definition at line 53 of file newgen_stack.h.
Referenced by init_C_comment(), and stack_info().
| #define stack_undefined ((stack)-14) |
Definition at line 55 of file newgen_stack.h.
Referenced by actual_c_parser(), CParserError(), effects_private_current_context_stack_initialized_p(), get_from_entity_type_stack_table(), perform_icm_association(), ResetCurrentModule(), and ResetTypedefStack().
Definition at line 56 of file newgen_stack.h.
Referenced by c_parse(), CParserError(), FindOrCreateCurrentEntity(), init_C_comment(), MakeTypedefStack(), put_to_entity_type_stack_table(), remove_entity_type_stacks(), stack_info(), step_make_new_directive_module_name(), UpdateEntity(), UseFormalArguments(), and yyparse().
| typedef struct __stack_head* stack |
STACK MANAGEMENT -- headers.
newgen_assert should be included before.
Fabien COELHO 05/12/1994 encapsulated types
Definition at line 47 of file newgen_stack.h.
| typedef struct __stack_iterator* stack_iterator |
Definition at line 48 of file newgen_stack.h.
| int stack_bsize | ( | const | stack | ) |
| int stack_consistent_p | ( | const | stack | ) |
miscellaneous
duplicate a stack with its contents.
Definition at line 255 of file stack.c.
References __stack_head::bucket_size, n, __stack_head::policy, stack_make(), STACK_MAP_X, stack_push(), and __stack_head::type.
Referenced by RenameFunctionEntity(), and store_call_context().
00256 { 00257 stack n = stack_make(s->type, s->bucket_size, s->policy); 00258 STACK_MAP_X(i, void*, stack_push(i, n), s, 0); 00259 return n; 00260 }


Referenced by actual_c_parser(), c_parse(), EnterScope(), ExitScope(), FindOrCreateCurrentEntity(), GetContext(), GetParentScope(), GetScope(), PopContext(), ResetTypedefStack(), string_buffer_reset(), UpdateEntity(), and yyparse().

| void stack_free | ( | stack * | ) |
type, bucket_size, policy
Definition at line 280 of file stack.c.
References free_buckets(), gen_free_area(), stack_head(), STACK_NULL, and STACK_PTR_NULL.
Referenced by actual_c_parser(), bottom_up_abc_statement(), claire_tasks(), CParserError(), gen_internal_context_multi_recurse(), genread_parse(), initial_code_abc_statement(), interprocedural_abc_statement(), loop_statistics(), pips_code_abc_statement(), remove_entity_type_stacks(), ResetCurrentModule(), ResetTypedefStack(), string_buffer_free(), top_down_abc_statement(), typing_of_expressions(), xml_Boxes(), xml_Task(), and xml_tasks().
00281 { 00282 free_buckets((*ps)->stack), (*ps)->stack=STACK_PTR_NULL; 00283 free_buckets((*ps)->avail), (*ps)->avail=STACK_PTR_NULL; 00284 gen_free_area((void**) *ps, sizeof(stack_head)); 00285 *ps = STACK_NULL; 00286 }


| void* stack_head | ( | const | stack | ) |
returns the item on top of stack s
HEAD
Definition at line 406 of file stack.c.
References assert, __stack_bucket::items, __stack_bucket::n_item, __stack_head::stack, STACK_PTR_NULL_P, __stack_bucket::succ, and x.
Referenced by abc_instrumentation_insert_before_statement(), arguments_are_something(), bottom_up_abc_insert_before_statement(), c_parse(), call_rwt(), check_format(), check_io_list(), check_spec(), check_this_loop(), check_this_test(), check_this_whileloop(), EnterScope(), ExitScope(), FindOrCreateCurrentEntity(), gen_get_recurse_current_ancestor(), genread_parse(), GetContext(), GetContextCopy(), GetFunction(), GetScope(), interprocedural_abc_insert_before_statement(), is_integer_specifier(), is_label_integer_string_specifier(), is_label_specifier(), is_string_specifier(), is_unit_specifier(), is_varibale_array_element_specifier(), loop_flt(), loop_rwt(), MakeBreakStatement(), MakeCaseStatement(), MakeContinueStatement(), MakeDefaultStatement(), MakeForloop(), MakeParameterList(), MakeSwitchStatement(), MakeWhileLoop(), PopContext(), push_loop(), quick_multi_already_seen_p(), seq_rwt(), stack_free(), StackPop(), StackPush(), statement_with_at_most_one_expression_integer(), statement_with_at_most_one_integer_or_character(), statement_without_argument(), stmt_rwt(), store_call_context(), test_rwt(), top_down_abc_insert_before_statement(), type_this_entity_if_needed(), type_this_expression(), type_this_instruction(), typing_arguments_of_user_function(), typing_assign_substring(), typing_buffer_inout(), typing_function_argument_type_to_return_type(), typing_implied_do(), typing_of_assign(), typing_substring(), uns_rwt(), UpdateAbstractEntity(), UpdateDerivedEntity(), UpdateEntity(), wl_rwt(), and yyparse().
00407 { 00408 _stack_ptr x = s->stack; 00409 if (x->n_item==0) x = x->succ; 00410 assert(!STACK_PTR_NULL_P(x) && x->n_item>0); 00411 00412 /* HEAD 00413 */ 00414 return x->items[(x->n_item)-1]; 00415 }
| void stack_info | ( | FILE * | , | |
| const | stack | |||
| ) |
else
else
Definition at line 328 of file stack.c.
References __stack_head::avail, fprintf(), __stack_head::max_extent, number_of_buckets(), __stack_head::size, __stack_head::stack, STACK_NULL_P, stack_undefined_p, and __stack_head::type.
00329 { 00330 fprintf(f, "stack_info about stack %p\n", s); 00331 00332 if (STACK_NULL_P(s)) 00333 { 00334 fprintf(f, " - is null\n"); 00335 return; 00336 } 00337 /* else */ 00338 if (stack_undefined_p(s)) 00339 { 00340 fprintf(f, " - is undefined\n"); 00341 return; 00342 } 00343 /* else */ 00344 fprintf(f, " - type %d, size %zd, max extent %zd\n", 00345 s->type, s->size, s->max_extent); 00346 fprintf(f, " - buckets: %d in use, %d available\n", 00347 number_of_buckets(s->stack), number_of_buckets(s->avail)); 00348 }

| void stack_iterator_end | ( | stack_iterator * | ) |
| bool stack_iterator_end_p | ( | stack_iterator | ) |
Definition at line 176 of file stack.c.
References STACK_ITERATOR_END_P.
00177 { 00178 return STACK_ITERATOR_END_P(i); 00179 }
| stack_iterator stack_iterator_init | ( | const | stack, | |
| bool | ||||
| ) |
stack iterator
This way the stack type is fully encapsulated, but it is not very efficient, due to the many function calls. Consider "stack_map" first which has a very small overhead.
Definition at line 154 of file stack.c.
References malloc(), and stack_iterator_internal_init().
00155 { 00156 stack_iterator i = (stack_iterator) malloc(sizeof(_stack_iterator)); 00157 stack_iterator_internal_init(s, down, i); 00158 return i; 00159 }

| bool stack_iterator_next_and_go | ( | stack_iterator | , | |
| void ** | ||||
| ) |
X-ward.
Definition at line 161 of file stack.c.
References __stack_iterator::bucket, __stack_iterator::index, __stack_bucket::items, NEXT_ITERATION, NULL, and STACK_ITERATOR_END_P.
Referenced by stack_nth().
00162 { 00163 if (STACK_ITERATOR_END_P(i)) 00164 { 00165 *pitem = (void*) NULL; 00166 return false; 00167 } 00168 else 00169 { 00170 *pitem = (i->bucket->items)[i->index]; 00171 NEXT_ITERATION(i); 00172 return true; 00173 } 00174 }

| stack stack_make | ( | int | type, | |
| int | bucket_size, | |||
| int | policy | |||
| ) |
allocation
not too small
not used
Definition at line 234 of file stack.c.
References allocate_bucket(), __stack_head::avail, __stack_head::bucket_size, malloc(), __stack_head::max_extent, message_assert, __stack_head::n_buckets, __stack_head::policy, __stack_head::size, __stack_head::stack, STACK_DEFAULT_SIZE, STACK_PTR_NULL, and __stack_head::type.
Referenced by actual_c_parser(), bottom_up_abc_statement(), c_parse(), claire_tasks(), gen_internal_context_multi_recurse(), genread_parse(), guard_elimination(), if(), initial_code_abc_statement(), InitializeBlock(), interprocedural_abc_statement(), loop_statistics(), MakeCurrentModule(), MakeTypedefStack(), pips_code_abc_statement(), push_pips_context(), stack_copy(), string_buffer_make(), tiling_sequence(), top_down_abc_statement(), typing_of_expressions(), xml_Boxes(), xml_Task(), xml_tasks(), and yyparse().
00235 { 00236 stack s = (stack) malloc(sizeof(_stack_head)); 00237 message_assert("pointer was allocated", s); 00238 00239 if (bucket_size<10) bucket_size=STACK_DEFAULT_SIZE; /* not too small */ 00240 00241 s->size = 0; 00242 s->type = type; 00243 s->policy = policy; /* not used */ 00244 s->bucket_size = bucket_size; 00245 s->max_extent = 0; 00246 s->n_buckets = 0; 00247 s->stack = allocate_bucket(bucket_size); 00248 s->avail = STACK_PTR_NULL; 00249 00250 return s; 00251 }


| void stack_map | ( | const | stack, | |
| gen_iter_func_t | ||||
| ) |
APPLY f to all items of stack s;.
Definition at line 309 of file stack.c.
References __stack_bucket::items, __stack_bucket::n_item, NULL, __stack_head::stack, STACK_CHECK, __stack_bucket::succ, and x.
00310 { 00311 _stack_ptr x; 00312 int i; 00313 00314 STACK_CHECK(s); 00315 00316 for(x=s->stack; x!=NULL; x=x->succ) 00317 for(i=(x->n_item)-1; i>=0; i--) 00318 (*f)(x->items[i]); 00319 }
| int stack_max_extent | ( | const | stack | ) |
returns the nth item starting from the head and counting from 1, when possible, or NULL, elsewhere.
stack_nth(stack,1)==stack_head(stack) if stack_size(stack)>=1.
Definition at line 422 of file stack.c.
References message_assert, NULL, stack_iterator_internal_init(), and stack_iterator_next_and_go().
Referenced by GetParentScope().
00423 { 00424 void * value = NULL; 00425 message_assert("positive nskip", nskip>=0); 00426 // message_assert("deep enough stack", stack_size(s)>=nskip); 00427 _stack_iterator si; 00428 stack_iterator_internal_init(s, true, &si); 00429 while (nskip && stack_iterator_next_and_go(&si, &value)) 00430 nskip--; 00431 return value; 00432 }


| int stack_policy | ( | const | stack | ) |
| void* stack_pop | ( | stack | s | ) |
POPs one item from stack s.
the empty buckets are not freed here. stack_free does the job.
POP!
Definition at line 385 of file stack.c.
References assert, __stack_head::avail, __stack_bucket::items, __stack_bucket::n_item, __stack_head::size, __stack_head::stack, STACK_PTR_NULL_P, __stack_bucket::succ, and x.
Referenced by c_parse(), ExitScope(), gen_internal_context_multi_recurse(), genread_parse(), NStackPop(), pop_current_statement(), pop_loop(), pop_pips_context(), pop_uns(), PopContext(), PopFunction(), PopTypedef(), quick_multi_recurse_obj_out(), stmt_rwt(), string_buffer_reset(), UpdateAbstractEntity(), UpdateDerivedEntity(), UpdateEntity(), and yyparse().
00386 { 00387 _stack_ptr x = s->stack; 00388 00389 if (x->n_item==0) 00390 { 00391 _stack_ptr saved = x->succ; 00392 x->succ = s->avail, s->avail = x; 00393 s->stack = saved, x = saved; 00394 } 00395 00396 assert(!STACK_PTR_NULL_P(x) && x->n_item>0); 00397 00398 /* POP! 00399 */ 00400 s->size--; 00401 return x->items[--x->n_item]; 00402 }

| void stack_push | ( | void * | item, | |
| stack | s | |||
| ) |
stack use
stack use
PUSHes the item on stack s a new bucket is allocated if necessary. the size it the same than the initial bucket size. Other policies may be considered.
PUSH!
Definition at line 359 of file stack.c.
References assert, find_or_allocate(), __stack_bucket::items, __stack_head::max_extent, __stack_bucket::max_items, __stack_bucket::n_item, __stack_head::size, __stack_head::stack, STACK_PTR_NULL_P, __stack_bucket::succ, and x.
00360 { 00361 _stack_ptr x = s->stack; 00362 00363 assert(!STACK_PTR_NULL_P(x)); 00364 00365 if (x->n_item == x->max_items) 00366 { 00367 _stack_ptr saved = x; 00368 x = find_or_allocate(s); 00369 x->succ = saved; 00370 s->stack = x; 00371 } 00372 00373 /* PUSH! 00374 */ 00375 s->size++; 00376 if (s->size > s->max_extent) s->max_extent = s->size; 00377 x->items[x->n_item++] = item; 00378 }

| void* stack_replace | ( | void * | , | |
| stack | ||||
| ) |
REPLACEs the item on top of stack s, and returns the old item.
REPLACE
Definition at line 436 of file stack.c.
References assert, __stack_bucket::items, __stack_bucket::n_item, __stack_head::stack, STACK_PTR_NULL_P, __stack_bucket::succ, and x.
| int stack_size | ( | const | stack | ) |
observers
Referenced by abc_instrumentation_insert_before_statement(), bottom_up_abc_insert_before_statement(), c_parse(), claire_loop(), claire_tiling(), gen_internal_context_multi_recurse(), genread_parse(), GetContext(), GetContextCopy(), GetParentScope(), interprocedural_abc_insert_before_statement(), PopContext(), PushContext(), ScopeStackSize(), top_down_abc_insert_before_statement(), UpdateAbstractEntity(), UpdateDerivedEntity(), UpdateEntity(), xml_tiling(), and yyparse().

| int stack_type | ( | const | stack | ) |
1.6.2-20100208