Ignore:
Timestamp:
Mar 9, 2018, 1:34:04 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
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, resolv-new, with_gc
Children:
860f19f
Parents:
b51e5fdb (diff), 3d8f2f8 (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

    rb51e5fdb re84382b  
    33
    44struct stack_node {
    5         void* value;
    6         struct stack_node* next;
     5        void * value;
     6        struct stack_node * next;
    77};
     8
     9void 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 );
     15        }
     16        s->head = NULL;
     17}
    818
    919struct stack new_stack() { return (struct stack){ NULL }; /***/ }
    1020
    11 void copy_stack(struct stack* s, const struct stack* t, void* (*copy)(const void*)) {
    12         struct stack_node** crnt = &s->head;
    13         for ( struct stack_node* next = t->head; next; next = next->next ) {
    14                 *crnt = malloc(sizeof(struct stack_node)); /***/
    15                 (*crnt)->value = copy(next->value);
     21void 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 );
    1626                crnt = &(*crnt)->next;
    1727        }
    1828        *crnt = NULL;
    1929}
    20 
    21 struct stack* assign_stack(struct stack* s, const struct stack* t,
    22                 void* (*copy_el)(const void*), void (*free_el)(void*)) {
     30struct stack * assign_stack( struct stack * s, const struct stack * t,
     31                void * (*copy_el)( const void * ), void (*free_el)( void * ) ) {
    2332        if ( s->head == t->head ) return s;
    2433        clear_stack( s, free_el ); /***/
     
    2736}
    2837
    29 void clear_stack(struct stack* s, void (*free_el)(void*)) {
    30     for ( struct stack_node* next = s->head; next; ) {
    31                 struct stack_node* crnt = next;
    32                 next = crnt->next;
    33                 free_el(crnt->value);
    34                 free(crnt);
    35         }
    36         s->head = NULL;
    37 }
     38_Bool stack_empty( const struct stack * s ) { return s->head == NULL; }
    3839
    39 _Bool stack_empty(const struct stack* s) { return s->head == NULL; }
    40 
    41 void push_stack(struct stack* s, void* value) {
    42         struct stack_node* n = malloc(sizeof(struct stack_node)); /***/
     40void push_stack( struct stack * s, void * value ) {
     41        struct stack_node * n = malloc( sizeof(struct stack_node) ); /***/
    4342        *n = (struct stack_node){ value, s->head }; /***/
    4443        s->head = n;
    4544}
    4645
    47 void* pop_stack(struct stack* s) {
    48         struct stack_node* n = s->head;
     46void * pop_stack( struct stack * s ) {
     47        struct stack_node * n = s->head;
    4948        s->head = n->next;
    50         void* x = n->value;
    51         free(n);
    52         return x;
     49        void * v = n->value;
     50        free( n );
     51        return v;
    5352}
Note: See TracChangeset for help on using the changeset viewer.