PIPS
newgen_stack.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define STACK_NULL   ((stack) NULL)
 defines for empty values More...
 
#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 More...
 
#define STACK_MAP(_item, _itemtype, _code, _stack)    STACK_MAP_X(_item, _itemtype, _code, _stack, true)
 

Typedefs

typedef struct __stack_headstack
 STACK MANAGEMENT – headers. More...
 
typedef struct __stack_iteratorstack_iterator
 

Functions

stack stack_make (int, int, int)
 allocation More...
 
void stack_free (stack *)
 type, bucket_size, policy More...
 
stack stack_copy (const stack)
 duplicate a stack with its contents. More...
 
int stack_size (const stack)
 observers More...
 
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 More...
 
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;. More...
 
void stack_push (void *, stack)
 stack use More...
 
void * stack_pop (stack)
 POPs one item from stack s. More...
 
void * stack_head (const stack)
 returns the item on top of stack s More...
 
void * stack_nth (const stack, int)
 returns the nth item starting from the head and counting from 1, when possible, or NULL, elsewhere. More...
 
void * stack_replace (void *, stack)
 REPLACEs the item on top of stack s, and returns the old item. More...
 
stack_iterator stack_iterator_init (const stack, bool)
 stack iterator More...
 
bool stack_iterator_next_and_go (stack_iterator, void **)
 X-ward. More...
 
void stack_iterator_end (stack_iterator *)
 
bool stack_iterator_end_p (stack_iterator)
 

Macro Definition Documentation

◆ STACK_CHECK

#define STACK_CHECK (   s)
Value:
message_assert("stack null or undefined", \
#define message_assert(msg, ex)
Definition: newgen_assert.h:47
#define STACK_NULL_P(s)
Definition: newgen_stack.h:53
#define stack_undefined_p(s)
Definition: newgen_stack.h:56

Definition at line 58 of file newgen_stack.h.

◆ STACK_MAP

#define STACK_MAP (   _item,
  _itemtype,
  _code,
  _stack 
)     STACK_MAP_X(_item, _itemtype, _code, _stack, true)

Definition at line 116 of file newgen_stack.h.

◆ STACK_MAP_X

#define STACK_MAP_X (   _item,
  _itemtype,
  _code,
  _stack,
  _downwards 
)
Value:
{ \
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); \
}
stack_iterator stack_iterator_init(const stack, bool)
stack iterator
Definition: stack.c:157
bool stack_iterator_next_and_go(stack_iterator, void **)
X-ward.
Definition: stack.c:164

not needed

applies _code on the items of _stack downward , with _item of _itemtype.

Definition at line 104 of file newgen_stack.h.

◆ STACK_NULL

#define STACK_NULL   ((stack) NULL)

defines for empty values

Definition at line 52 of file newgen_stack.h.

◆ STACK_NULL_P

#define STACK_NULL_P (   s)    ((s)==STACK_NULL)

Definition at line 53 of file newgen_stack.h.

◆ stack_undefined

#define stack_undefined   ((stack)-14)

Definition at line 55 of file newgen_stack.h.

◆ stack_undefined_p

#define stack_undefined_p (   s)    ((s)==stack_undefined)

Definition at line 56 of file newgen_stack.h.

Typedef Documentation

◆ stack

typedef struct __stack_head* stack

STACK MANAGEMENT – headers.

  • a stack is declared with type stack (internals not visible from here!)
  • a stack_iterator allows to iterate over the items in a stack.
  • allocation with stack_make(newgen domain, bucket size)
  • free with stack_free(stack)
  • stack_size(stack) returns the number of elements stacked
  • stack_empty_p(stack) tells whether the stack is empty or not stack_empty_p(stack)==(stack_size(stack)==0)
  • stack_{push,pop,head,replace} do what you may expect from them
  • stack_info gives informations about the stack
  • stack_map applies the function on all the items in stack.
  • stack_iterator_{init,next_and_go,end} to iterate.
  • see STACK_MAP for instance.

newgen_assert should be included before.

Fabien COELHO 05/12/1994 encapsulated types

Definition at line 47 of file newgen_stack.h.

◆ stack_iterator

Definition at line 48 of file newgen_stack.h.

Function Documentation

◆ stack_bsize()

int stack_bsize ( const  stack)

◆ stack_consistent_p()

int stack_consistent_p ( const  stack)

miscellaneous

◆ stack_copy()

stack stack_copy ( const  stack)

duplicate a stack with its contents.

Definition at line 267 of file stack.c.

268 {
269  stack n = stack_make(s->type, s->bucket_size, s->policy);
270  STACK_MAP_X(i, void*, stack_push(i, n), s, 0);
271  return n;
272 }
#define STACK_MAP_X(_item, _itemtype, _code, _stack, _downwards)
not needed
Definition: newgen_stack.h:104
stack stack_make(int type, int bucket_size, int policy)
ALLOCATEs a new stack of type.
Definition: stack.c:246
void stack_push(void *item, stack s)
STACK USE.
Definition: stack.c:373
the stack head
Definition: stack.c:62

References __stack_head::bucket_size, __stack_head::policy, stack_make(), STACK_MAP_X, stack_push(), and __stack_head::type.

Referenced by RenameFunctionEntity(), store_call_context(), and SubstituteDummyParameters().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stack_empty_p()

◆ stack_free()

void stack_free ( stack ps)

type, bucket_size, policy

Definition at line 292 of file stack.c.

293 {
294  free_buckets((*ps)->stack), (*ps)->stack=STACK_PTR_NULL;
295  free_buckets((*ps)->avail), (*ps)->avail=STACK_PTR_NULL;
296  gen_free_area((void**) *ps, sizeof(stack_head));
297  *ps = STACK_NULL;
298 }
void gen_free_area(void **p, int size)
free an area.
Definition: list.c:775
#define STACK_NULL
defines for empty values
Definition: newgen_stack.h:52
static void free_buckets(_stack_ptr x)
Definition: stack.c:282
#define STACK_PTR_NULL
and also *stack (in headers)
Definition: stack.c:76
void * stack_head(const stack s)
returns the item on top of stack s
Definition: stack.c:420

References free_buckets(), gen_free_area(), stack_head(), STACK_NULL, and STACK_PTR_NULL.

Referenced by actual_c_parser(), bottom_up_abc_statement(), c_parser_error(), force_reset_c_parser_scope_stack(), force_reset_preprocessor_scope_stack(), ForceResetTypedefStack(), free_statement_global_stack(), gen_internal_context_multi_recurse(), initial_code_abc_statement(), interprocedural_abc_statement(), loop_statistics(), pips_code_abc_statement(), remove_entity_type_stack(), reset_c_parser_scope_stack(), reset_entity_type_stack_table(), reset_preprocessor_scope_stack(), reset_statement_points_to_context(), ResetCurrentModule(), ResetTypedefStack(), string_buffer_free(), top_down_abc_statement(), typing_of_expressions(), xml_Boxes(), xml_Task(), and xml_tasks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stack_head()

void* stack_head ( const  stack)

returns the item on top of stack s

HEAD

Definition at line 420 of file stack.c.

421 {
422  _stack_ptr x = s->stack;
423  if (x->n_item==0) x = x->succ;
424  assert(!STACK_PTR_NULL_P(x) && x->n_item>0);
425 
426  /* HEAD
427  */
428  return x->items[(x->n_item)-1];
429 }
#define assert(ex)
Definition: newgen_assert.h:41
static char * x
Definition: split_file.c:159
#define STACK_PTR_NULL_P(x)
Definition: stack.c:77
STACK STRUCTURES.
Definition: stack.c:50

References assert, __stack_head::stack, STACK_PTR_NULL_P, and x.

Referenced by abc_instrumentation_insert_before_statement(), add_arc_to_statement_points_to_context(), arguments_are_something(), bottom_up_abc_insert_before_statement(), call_rwt(), check_format(), check_io_list(), check_spec(), check_this_loop(), check_this_test(), check_this_whileloop(), EnterScope(), eov_stack_task_pop_task(), ExitScope(), FindOrCreateCurrentEntity(), gen_get_recurse_current_ancestor(), get_c_parser_current_scope(), get_current_statement_from_statement_global_stack(), get_preprocessor_current_scope(), 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(), points_to_context_statement_in(), PopContext(), push_if(), push_loop(), pv_context_statement_head(), 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(), update_statement_points_to_context_with_arc(), UpdateAbstractEntity(), UpdateDerivedEntity(), UpdateEntity(), and wl_rwt().

◆ stack_info()

void stack_info ( FILE *  f,
const  stack 
)

else

else

Definition at line 342 of file stack.c.

343 {
344  fprintf(f, "stack_info about stack %p\n", s);
345 
346  if (STACK_NULL_P(s))
347  {
348  fprintf(f, " - is null\n");
349  return;
350  }
351  /* else */
352  if (stack_undefined_p(s))
353  {
354  fprintf(f, " - is undefined\n");
355  return;
356  }
357  /* else */
358  fprintf(f, " - type %d, size %zd, max extent %zd\n",
359  s->type, s->size, s->max_extent);
360  fprintf(f, " - buckets: %d in use, %d available\n",
361  number_of_buckets(s->stack), number_of_buckets(s->avail));
362 }
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
static int number_of_buckets(_stack_ptr x)
Definition: stack.c:335

References __stack_head::avail, f(), fprintf(), __stack_head::max_extent, number_of_buckets(), __stack_head::size, __stack_head::stack, STACK_NULL_P, stack_undefined_p, and __stack_head::type.

+ Here is the call graph for this function:

◆ stack_iterator_end()

void stack_iterator_end ( stack_iterator pi)

Definition at line 184 of file stack.c.

185 {
186  (*pi)->bucket = NEWGEN_FREED;
187  (*pi)->downward = 0;
188  (*pi)->index = 0;
189  (*pi)->list = NEWGEN_FREED;
190  free(*pi);
191  *pi=(stack_iterator) NULL;
192 }
void free(void *)
#define NEWGEN_FREED
struct __stack_iterator * stack_iterator
Definition: newgen_stack.h:48

References free(), and NEWGEN_FREED.

+ Here is the call graph for this function:

◆ stack_iterator_end_p()

bool stack_iterator_end_p ( stack_iterator  i)

Definition at line 179 of file stack.c.

180 {
181  return STACK_ITERATOR_END_P(i);
182 }
#define STACK_ITERATOR_END_P(i)
Definition: stack.c:104

References STACK_ITERATOR_END_P.

◆ stack_iterator_init()

stack_iterator stack_iterator_init ( const  stack,
bool  down 
)

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 157 of file stack.c.

158 {
160  stack_iterator_internal_init(s, down, i);
161  return i;
162 }
void * malloc(YYSIZE_T)
static void stack_iterator_internal_init(const stack s, int down, stack_iterator i)
Definition: stack.c:136
STACK ITERATOR.
Definition: stack.c:83

References malloc(), and stack_iterator_internal_init().

+ Here is the call graph for this function:

◆ stack_iterator_next_and_go()

bool stack_iterator_next_and_go ( stack_iterator  i,
void **  pitem 
)

X-ward.

Definition at line 164 of file stack.c.

165 {
166  if (STACK_ITERATOR_END_P(i))
167  {
168  *pitem = (void*) NULL;
169  return false;
170  }
171  else
172  {
173  *pitem = (i->bucket->items)[i->index];
174  NEXT_ITERATION(i);
175  return true;
176  }
177 }
#define NEXT_ITERATION(i)
Definition: stack.c:125
void ** items
the max number of items of this bucket
Definition: stack.c:53
size_t index
true if downward iterations
Definition: stack.c:86
_stack_ptr bucket
Definition: stack.c:84

References __stack_iterator::bucket, __stack_iterator::index, __stack_bucket::items, NEXT_ITERATION, and STACK_ITERATOR_END_P.

Referenced by stack_nth().

+ Here is the caller graph for this function:

◆ stack_make()

stack stack_make ( int  type,
int  bucket_size,
int  policy 
)

allocation

allocation

Parameters
typerecord newgen domain of stack contents. should be used to check the type of appended elements.
bucket_sizeis the number of elements in the elemental stack container. If you now you will have big stacks, try big numbers here to save memory.
policynot used, 0 is fine.

not too small

not used

Definition at line 246 of file stack.c.

247 {
248  stack s = (stack) malloc(sizeof(_stack_head));
249  message_assert("pointer was allocated", s);
250 
251  if (bucket_size<10) bucket_size=STACK_DEFAULT_SIZE; /* not too small */
252 
253  s->size = 0;
254  s->type = type;
255  s->policy = policy; /* not used */
256  s->bucket_size = bucket_size;
257  s->max_extent = 0;
258  s->n_buckets = 0;
259  s->stack = allocate_bucket(bucket_size);
260  s->avail = STACK_PTR_NULL;
261 
262  return s;
263 }
struct _newgen_struct_type_ * type
struct __stack_head * stack
STACK MANAGEMENT – headers.
Definition: newgen_stack.h:47
#define STACK_DEFAULT_SIZE
Definition: stack.c:78
static _stack_ptr allocate_bucket(int size)
allocates a bucket of size size
Definition: stack.c:201
int type
number of allocated buckets
Definition: stack.c:69
int policy
as BASIC, LIST, EXTERNAL, CHUNK, domain?
Definition: stack.c:70
size_t size
Definition: stack.c:63
_stack_ptr avail
buckets in use by the stack
Definition: stack.c:66
_stack_ptr stack
maximum extension of the stack
Definition: stack.c:65
size_t max_extent
current number of elements in stack
Definition: stack.c:64
size_t n_buckets
reference bucket size for allocation
Definition: stack.c:68
size_t bucket_size
allocated buckets not in use anymore
Definition: stack.c:67

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(), eov_make_ctx(), gen_internal_context_multi_recurse(), guard_elimination(), init_c_parser_scope_stack(), init_preprocessor_scope_stack(), init_statement_points_to_context(), initial_code_abc_statement(), InitializeBlock(), interprocedural_abc_statement(), loop_statistics(), make_simple_pv_context(), make_statement_global_stack(), 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(), and xml_tasks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stack_map()

void stack_map ( const  stack,
gen_iter_func_t  f 
)

APPLY f to all items of stack s;.

Definition at line 323 of file stack.c.

324 {
325  _stack_ptr x;
326  int i;
327 
328  STACK_CHECK(s);
329 
330  for(x=s->stack; x!=NULL; x=x->succ)
331  for(i=(x->n_item)-1; i>=0; i--)
332  (*f)(x->items[i]);
333 }
#define STACK_CHECK(s)
Definition: newgen_stack.h:58

References __stack_head::stack, STACK_CHECK, and x.

◆ stack_max_extent()

int stack_max_extent ( const  stack)

◆ stack_nth()

void* stack_nth ( const stack  s,
int  nskip 
)

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 436 of file stack.c.

437 {
438  void * value = NULL;
439  message_assert("positive nskip", nskip>=0);
440  // message_assert("deep enough stack", stack_size(s)>=nskip);
441  _stack_iterator si;
442  stack_iterator_internal_init(s, true, &si);
443  while (nskip && stack_iterator_next_and_go(&si, &value))
444  nskip--;
445  return value;
446 }
struct _newgen_struct_value_ * value
Definition: ri.h:455
bool stack_iterator_next_and_go(stack_iterator i, void **pitem)
X-ward.
Definition: stack.c:164

References message_assert, stack_iterator_internal_init(), and stack_iterator_next_and_go().

Referenced by get_c_parser_nth_scope(), get_preprocessor_nth_scope(), and GetParentScope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stack_policy()

int stack_policy ( const  stack)

◆ stack_pop()

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 399 of file stack.c.

400 {
401  _stack_ptr x = s->stack;
402 
403  if (x->n_item==0)
404  {
405  _stack_ptr saved = x->succ;
406  x->succ = s->avail, s->avail = x;
407  s->stack = saved, x = saved;
408  }
409 
410  assert(!STACK_PTR_NULL_P(x) && x->n_item>0);
411 
412  /* POP!
413  */
414  s->size--;
415  return x->items[--x->n_item];
416 }

References assert, __stack_head::avail, __stack_head::size, __stack_head::stack, STACK_PTR_NULL_P, and x.

Referenced by eov_stack_task_pop_task(), ExitScope(), gen_internal_context_multi_recurse(), MakeForloop(), NStackPop(), pop_c_parser_scope_stack(), pop_current_statement(), pop_if(), pop_loop(), pop_pips_context(), pop_preprocessor_scope(), pop_statement_global_stack(), pop_statement_points_to_context(), pop_uns(), PopContext(), PopFunction(), PopTypedef(), pv_context_statement_pop(), quick_multi_recurse_obj_out(), stmt_rwt(), string_buffer_reset(), UpdateAbstractEntity(), UpdateDerivedEntity(), and UpdateEntity().

+ Here is the caller graph for this function:

◆ stack_push()

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 373 of file stack.c.

374 {
375  _stack_ptr x = s->stack;
376 
378 
379  if (x->n_item == x->max_items)
380  {
381  _stack_ptr saved = x;
382  x = find_or_allocate(s);
383  x->succ = saved;
384  s->stack = x;
385  }
386 
387  /* PUSH!
388  */
389  s->size++;
390  if (s->size > s->max_extent) s->max_extent = s->size;
391  x->items[x->n_item++] = item;
392 }
static _stack_ptr find_or_allocate(stack s)
search for a new bucket, first in the available list, if none are available, a new bucket is allocate...
Definition: stack.c:218

References assert, find_or_allocate(), __stack_head::max_extent, __stack_head::size, __stack_head::stack, STACK_PTR_NULL_P, and x.

Referenced by EnterScope(), eov_stack_task_push_task(), gen_internal_context_multi_recurse(), push_current_statement(), push_if(), push_loop(), push_new_c_parser_scope(), push_new_preprocessor_scope(), push_pips_context(), push_statement_on_statement_global_stack(), push_statement_points_to_context(), push_uns(), PushContext(), PushFunction(), PushTypedef(), pv_context_statement_push(), quick_multi_recurse_obj_in(), stack_copy(), StackPush(), stmt_flt(), and string_buffer_append_internal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stack_replace()

void* stack_replace ( void *  item,
stack  s 
)

REPLACEs the item on top of stack s, and returns the old item.

REPLACE

Definition at line 450 of file stack.c.

451 {
452  _stack_ptr x = s->stack;
453  void *old;
454 
455  if (x->n_item==0) x = x->succ;
456  assert(!STACK_PTR_NULL_P(x) && x->n_item>0);
457 
458  /* REPLACE
459  */
460  old = x->items[(x->n_item)-1];
461  x->items[(x->n_item)-1] = item;
462 
463  return old;
464 }

References assert, __stack_head::stack, STACK_PTR_NULL_P, and x.

◆ stack_size()

◆ stack_type()

int stack_type ( const  stack)