PIPS
stack.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include "genC.h"
#include "newgen_include.h"
+ Include dependency graph for stack.c:

Go to the source code of this file.

Data Structures

struct  __stack_bucket
 STACK STRUCTURES. More...
 
struct  __stack_head
 the stack head More...
 
struct  __stack_iterator
 STACK ITERATOR. More...
 

Macros

#define STACK_PTR_NULL   ((_stack_ptr) NULL)
 and also *stack (in headers) More...
 
#define STACK_PTR_NULL_P(x)   ((x)==STACK_PTR_NULL)
 
#define STACK_DEFAULT_SIZE   50
 
#define STACK_ITERATOR_END_P(i)   STACK_PTR_NULL_P(i->bucket)
 
#define DEFINE_ITERATOR(i, blk, idx, dwn, lst)
 
#define UPDATE_ITERATOR_DOWNWARD(i)
 
#define UPDATE_ITERATOR_UPWARD(i)
 
#define NEXT_ITERATION(i)
 
#define STACK_OBSERVER(name, what)    int stack_##name(const stack s) { STACK_CHECK(s); return(what); }
 STACK MISCELLANEOUS. More...
 

Typedefs

typedef struct __stack_bucket _stack_bucket
 STACK STRUCTURES. More...
 
typedef struct __stack_bucket_stack_ptr
 
typedef struct __stack_head _stack_head
 the stack head More...
 
typedef struct __stack_iterator _stack_iterator
 STACK ITERATOR. More...
 

Functions

static void update_iterator_upward (stack_iterator i)
 and also *stack_iterator (in headers) More...
 
static void stack_iterator_internal_init (const stack s, int down, stack_iterator i)
 
stack_iterator stack_iterator_init (const stack s, bool down)
 stack iterator More...
 
bool stack_iterator_next_and_go (stack_iterator i, void **pitem)
 X-ward. More...
 
bool stack_iterator_end_p (stack_iterator i)
 
void stack_iterator_end (stack_iterator *pi)
 
static _stack_ptr allocate_bucket (int size)
 allocates a bucket of size size More...
 
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 allocated More...
 
stack stack_make (int type, int bucket_size, int policy)
 ALLOCATEs a new stack of type. More...
 
stack stack_copy (const stack s)
 duplicate a stack with its contents. More...
 
static void free_bucket (_stack_ptr x)
 FREEs the stack. More...
 
static void free_buckets (_stack_ptr x)
 
void stack_free (stack *ps)
 type, bucket_size, policy More...
 
 STACK_OBSERVER (consistent_p, 1)
 Here we define stack_size(), stack_bsize(), stack_policy() and stack_max_extent(): More...
 
void stack_map (const stack s, gen_iter_func_t f)
 APPLY f to all items of stack s;. More...
 
static int number_of_buckets (_stack_ptr x)
 
void stack_info (FILE *f, const stack s)
 
void stack_push (void *item, stack s)
 STACK USE. More...
 
void * stack_pop (stack s)
 POPs one item from stack s. More...
 
void * stack_head (const stack s)
 returns the item on top of stack s More...
 
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. More...
 
void * stack_replace (void *item, stack s)
 REPLACEs the item on top of stack s, and returns the old item. More...
 

Macro Definition Documentation

◆ DEFINE_ITERATOR

#define DEFINE_ITERATOR (   i,
  blk,
  idx,
  dwn,
  lst 
)
Value:
{ \
i->bucket=(blk); \
i->index=(idx); \
i->list=lst; \
i->downward=dwn; \
}

Definition at line 106 of file stack.c.

◆ NEXT_ITERATION

#define NEXT_ITERATION (   i)
Value:
if (i->downward) \
{ \
i->index--; UPDATE_ITERATOR_DOWNWARD(i); \
} \
else \
{ \
i->index++; UPDATE_ITERATOR_UPWARD(i); \
}
#define UPDATE_ITERATOR_DOWNWARD(i)
Definition: stack.c:114
#define UPDATE_ITERATOR_UPWARD(i)
Definition: stack.c:121

Definition at line 125 of file stack.c.

◆ STACK_DEFAULT_SIZE

#define STACK_DEFAULT_SIZE   50

Definition at line 78 of file stack.c.

◆ STACK_ITERATOR_END_P

#define STACK_ITERATOR_END_P (   i)    STACK_PTR_NULL_P(i->bucket)

Definition at line 104 of file stack.c.

◆ STACK_OBSERVER

#define STACK_OBSERVER (   name,
  what 
)     int stack_##name(const stack s) { STACK_CHECK(s); return(what); }

STACK MISCELLANEOUS.

Definition at line 302 of file stack.c.

◆ STACK_PTR_NULL

#define STACK_PTR_NULL   ((_stack_ptr) NULL)

and also *stack (in headers)

usefull defines

Definition at line 76 of file stack.c.

◆ STACK_PTR_NULL_P

#define STACK_PTR_NULL_P (   x)    ((x)==STACK_PTR_NULL)

Definition at line 77 of file stack.c.

◆ UPDATE_ITERATOR_DOWNWARD

#define UPDATE_ITERATOR_DOWNWARD (   i)
Value:
if (i->index == (size_t) -1) \
{ \
i->bucket = i->bucket->succ; \
i->index = (i->bucket) ? (i->bucket->n_item)-1 : (size_t) -1; \
}
size_t size_t
Definition: properties.c:413

Definition at line 114 of file stack.c.

◆ UPDATE_ITERATOR_UPWARD

#define UPDATE_ITERATOR_UPWARD (   i)
Value:
if (i->index==i->bucket->n_item) \
update_iterator_upward(i);

Definition at line 121 of file stack.c.

Typedef Documentation

◆ _stack_bucket

typedef struct __stack_bucket _stack_bucket

STACK STRUCTURES.

the stack buckets, i.e. arrays containing the elements

◆ _stack_head

typedef struct __stack_head _stack_head

the stack head

◆ _stack_iterator

STACK ITERATOR.

◆ _stack_ptr

typedef struct __stack_bucket * _stack_ptr

Function Documentation

◆ allocate_bucket()

static _stack_ptr allocate_bucket ( int  size)
static

allocates a bucket of size size

Definition at line 201 of file stack.c.

202 {
204  message_assert("pointer was allocated", x);
205 
206  x->n_item = 0;
207  x->max_items = size;
208  x->items = (void **) malloc(sizeof(void *)*size);
209  message_assert("pointer was allocated", x->items);
210  x->succ = STACK_PTR_NULL;
211 
212  return x;
213 }
void * malloc(YYSIZE_T)
#define message_assert(msg, ex)
Definition: newgen_assert.h:47
static char * x
Definition: split_file.c:159
struct __stack_bucket * _stack_ptr
#define STACK_PTR_NULL
and also *stack (in headers)
Definition: stack.c:76
STACK STRUCTURES.
Definition: stack.c:50

References malloc(), message_assert, STACK_PTR_NULL, and x.

Referenced by find_or_allocate(), and stack_make().

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

◆ find_or_allocate()

static _stack_ptr find_or_allocate ( stack  s)
static

search for a new bucket, first in the available list, if none are available, a new bucket is allocated

clean the bucket to be returned

may depend from the policy?

Definition at line 218 of file stack.c.

219 {
220  if (!STACK_PTR_NULL_P(s->avail))
221  {
222  _stack_ptr x = s->avail;
223  s->avail = (s->avail)->succ;
224  x->succ = STACK_PTR_NULL; /* clean the bucket to be returned */
225  return x;
226  }
227  else
228  {
229  s->n_buckets++;
230  /* may depend from the policy? */
231  return allocate_bucket(s->bucket_size);
232  }
233 }
static _stack_ptr allocate_bucket(int size)
allocates a bucket of size size
Definition: stack.c:201
#define STACK_PTR_NULL_P(x)
Definition: stack.c:77
_stack_ptr avail
buckets in use by the stack
Definition: stack.c:66
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, __stack_head::n_buckets, STACK_PTR_NULL, STACK_PTR_NULL_P, and x.

Referenced by stack_push().

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

◆ free_bucket()

static void free_bucket ( _stack_ptr  x)
static

FREEs the stack.

Definition at line 276 of file stack.c.

277 {
278  gen_free_area(x->items, x->max_items*sizeof(void*));
279  gen_free_area((void**) x, sizeof(_stack_bucket));
280 }
void gen_free_area(void **p, int size)
free an area.
Definition: list.c:775

References gen_free_area(), and x.

Referenced by free_buckets().

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

◆ free_buckets()

static void free_buckets ( _stack_ptr  x)
static

Definition at line 282 of file stack.c.

283 {
284  _stack_ptr tmp;
285  while(!STACK_PTR_NULL_P(x))
286  {
287  tmp=x, x=x->succ, tmp->succ=STACK_PTR_NULL;
288  free_bucket(tmp);
289  }
290 }
static void free_bucket(_stack_ptr x)
FREEs the stack.
Definition: stack.c:276
struct __stack_bucket * succ
the items (only pointers at the moment)
Definition: stack.c:54

References free_bucket(), STACK_PTR_NULL, STACK_PTR_NULL_P, __stack_bucket::succ, and x.

Referenced by stack_free().

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

◆ number_of_buckets()

static int number_of_buckets ( _stack_ptr  x)
static

Definition at line 335 of file stack.c.

336 {
337  int n=0;
338  for(; !STACK_PTR_NULL_P(x); x=x->succ, n++);
339  return n;
340 }

References STACK_PTR_NULL_P, and x.

Referenced by stack_info().

+ Here is the caller graph for this function:

◆ stack_copy()

stack stack_copy ( const stack  s)

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
int type
number of allocated buckets
Definition: stack.c:69
int policy
as BASIC, LIST, EXTERNAL, CHUNK, domain?
Definition: stack.c:70

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_free()

void stack_free ( stack ps)

◆ stack_head()

void* stack_head ( const stack  s)

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
_stack_ptr stack
maximum extension of the stack
Definition: stack.c:65

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  s 
)

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",
362 }
#define STACK_NULL_P(s)
Definition: newgen_stack.h:53
#define stack_undefined_p(s)
Definition: newgen_stack.h:56
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
size_t size
Definition: stack.c:63
size_t max_extent
current number of elements in stack
Definition: stack.c:64

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 }
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_internal_init()

static void stack_iterator_internal_init ( const stack  s,
int  down,
stack_iterator  i 
)
static

NOT the define!

Definition at line 135 of file stack.c.

137 {
138  STACK_CHECK(s);
139 
140  if ((s->size)==0)
142  else
143  {
144  if (down)
145  {
146  DEFINE_ITERATOR(i, s->stack, (s->stack->n_item)-1, down, s->stack);
148  }
149  else
150  {
151  DEFINE_ITERATOR(i, STACK_PTR_NULL, 0, down, s->stack);
152  update_iterator_upward(i); /* NOT the define! */
153  }
154  }
155 }
#define STACK_CHECK(s)
Definition: newgen_stack.h:58
static void update_iterator_upward(stack_iterator i)
and also *stack_iterator (in headers)
Definition: stack.c:91
#define DEFINE_ITERATOR(i, blk, idx, dwn, lst)
Definition: stack.c:106
size_t n_item
Definition: stack.c:51

References DEFINE_ITERATOR, __stack_bucket::n_item, __stack_head::size, __stack_head::stack, STACK_CHECK, STACK_PTR_NULL, UPDATE_ITERATOR_DOWNWARD, and update_iterator_upward().

Referenced by stack_iterator_init(), and stack_nth().

+ Here is the call graph for this function:
+ Here is the caller 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 
)

ALLOCATEs a new stack of type.

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

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  s,
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 }

References __stack_head::stack, STACK_CHECK, and x.

◆ 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_OBSERVER()

STACK_OBSERVER ( consistent_p  ,
 
)

Here we define stack_size(), stack_bsize(), stack_policy() and stack_max_extent():

well, it is not implemented

Definition at line 311 of file stack.c.

314 {
315  STACK_CHECK(s);
316  return s->size==0;
317 }

References STACK_CHECK.

◆ 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.

◆ update_iterator_upward()

static void update_iterator_upward ( stack_iterator  i)
static

and also *stack_iterator (in headers)

Definition at line 91 of file stack.c.

92 {
93  _stack_ptr x=i->list;
94 
95  while(!STACK_PTR_NULL_P(x) && x->succ!=i->bucket)
96  x=x->succ;
97 
98  i->bucket=x, i->index=0;
99 
100  if (x && i->bucket->n_item==0)
101  i->bucket = STACK_PTR_NULL;
102 }
_stack_ptr list
current index in bucket
Definition: stack.c:87

References __stack_iterator::bucket, __stack_iterator::index, __stack_iterator::list, __stack_bucket::n_item, STACK_PTR_NULL, STACK_PTR_NULL_P, and x.

Referenced by stack_iterator_internal_init().

+ Here is the caller graph for this function: