Ignore:
Timestamp:
Apr 30, 2018, 2:31:18 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
4c80a75
Parents:
5248789 (diff), 5e5dbc2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/evaluation/c-stack.c

    r5248789 r8a5bdf0  
    22#include "c-stack.h"
    33
    4 struct stack_node {
     4typedef struct node {
    55        void * value;
    6         struct stack_node * next;
    7 };
     6        struct node * next;
     7} node;
    88
    9 void clear_stack( struct stack * s, void (*free_el)( void * ) ) {
    10         for ( struct stack_node * next = s->head; next; ) {
    11                 struct stack_node * crnt = next;
    12                 next = crnt->next;
    13                 free_el( crnt->value );
    14                 free( crnt );
     9void copy_stack( stack * s, const stack * t, void * (*copy)( const void * ) ) {
     10        node ** cr = &s->head;
     11        for ( node * nx = t->head; nx; nx = nx->next ) {
     12                *cr = malloc( sizeof(node) ); /***/
     13                (*cr)->value = copy( nx->value );
     14                cr = &(*cr)->next;
     15        }
     16        *cr = NULL;
     17}
     18
     19void clear_stack( stack * s, void (* free_el)( void * ) ) {
     20        for ( node * nx = s->head; nx; ) {
     21                node * cr = nx;
     22                nx = cr->next;
     23                free_el( cr->value );
     24                free( cr );
    1525        }
    1626        s->head = NULL;
    1727}
    1828
    19 struct stack new_stack() { return (struct stack){ NULL }; /***/ }
     29stack new_stack() { return (stack){ NULL }; /***/ }
    2030
    21 void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) {
    22         struct stack_node ** crnt = &s->head;
    23         for ( struct stack_node * next = t->head; next; next = next->next ) {
    24                 *crnt = malloc( sizeof(struct stack_node) ); /***/
    25                 (*crnt)->value = copy( next->value );
    26                 crnt = &(*crnt)->next;
    27         }
    28         *crnt = NULL;
    29 }
    30 struct stack * assign_stack( struct stack * s, const struct stack * t,
     31stack * assign_stack( stack * s, const stack * t,
    3132                void * (*copy_el)( const void * ), void (*free_el)( void * ) ) {
    3233        if ( s->head == t->head ) return s;
     
    3637}
    3738
    38 _Bool stack_empty( const struct stack * s ) { return s->head == NULL; }
     39_Bool stack_empty( const stack * s ) { return s->head == NULL; }
    3940
    40 void push_stack( struct stack * s, void * v ) {
    41         struct stack_node * n = malloc( sizeof(struct stack_node) ); /***/
    42         *n = (struct stack_node){ v, s->head }; /***/
     41void push_stack( stack * s, void * v ) {
     42        node * n = malloc( sizeof(node) ); /***/
     43        *n = (node){ v, s->head }; /***/
    4344        s->head = n;
    4445}
    4546
    46 void * pop_stack( struct stack * s ) {
    47         struct stack_node * n = s->head;
     47void * pop_stack( stack * s ) {
     48        node * n = s->head;
    4849        s->head = n->next;
    4950        void * v = n->value;
Note: See TracChangeset for help on using the changeset viewer.