void test3() //@ requires true; //@ ensures true; { struct value* v2, v3; struct stack* s = create_stack(); //@ close foreach(nil, value_helper2(27)); //@ close stack_allClients3(s, nil, 27); //@ close stack_unsep(stack_inv3_unsep)(boxed_int(27), s, stack_inv3(s, 27), stack_inv3_sep, nil); //@ produce_lemma_function_pointer_chunk(stack_inv3_sep); //@ produce_lemma_function_pointer_chunk(stack_inv3_unsep); //@ share_stack(s); struct value* v = malloc(sizeof(struct value)); if(v == 0) abort(); v->val = 27; //@ close stack_push_context_pre(allClients3_push)(stack_inv3_unsep, s, v, boxed_int(27)); //@ produce_lemma_function_pointer_chunk(allClients3_push); stack_push(s, v); //@ leak is_stack_push_context(allClients3_push); //@ open stack_push_context_post(allClients3_push)(boxed_int(27)); //@ close stack_try_pop_context_pre(allClients3_try_pop)(stack_inv3_unsep, s, boxed_int(27)); //@ produce_lemma_function_pointer_chunk(allClients3_try_pop); bool result = stack_try_pop(s, &v2); //@ leak is_stack_try_pop_context(allClients3_try_pop); //@ open stack_try_pop_context_post(allClients3_try_pop)(_, _, boxed_int(27)); if(result) { //@ open value(v2, 27); free(v2); } //@ unshare_stack(s); //@ open stack_unsep(stack_inv3_unsep)(boxed_int(27), s, stack_inv3(s, 27), stack_inv3_sep, _); //@ leak is_stack_sep(stack_inv3_sep); //@ leak is_stack_unsep(stack_inv3_unsep); bool hasMore = true; while(hasMore) //@ invariant stack(s, ?remElems) &*& stack_allClients3(s, remElems, 27) &*& pointer(&v3, _) &*& (hasMore ? true: remElems == nil); { hasMore = stack_try_pop_sequential(s, &v3); if(hasMore) { //@ open stack_allClients3(s, remElems, 27); //@ open foreach(remElems, value_helper2(27)); //@ close stack_allClients3(s, tail(remElems), 27); //@ open value_helper2(27)(v3); //@ open value(v3, 27); free((struct value*)v3); } } //@ open stack_allClients3(s, remElems, 27); //@ open foreach(remElems, value_helper2(27)); dispose_stack(s); }
void test() //@ requires true; //@ ensures true; { struct value* v2, v3; struct stack* s = create_stack(); //@ close stack_allClients(s, nil, unit); //@ produce_lemma_function_pointer_chunk(stack_inv_sep); //@ produce_lemma_function_pointer_chunk(stack_inv_unsep); //@ close stack_unsep(stack_inv_unsep)(unit, s, stack_inv(s, unit), stack_inv_sep, nil); //@ share_stack(s); struct value* v = malloc(sizeof(struct value)); if(v == 0) abort(); v->val = 27; //@ close stack_push_context_pre(allClients_push)(stack_inv_unsep, s, v, unit); //@ produce_lemma_function_pointer_chunk(allClients_push); stack_push(s, v); //@ leak is_stack_push_context(allClients_push); //@ open stack_push_context_post(allClients_push)(unit); //@ close stack_try_pop_context_pre(allClients_try_pop)(stack_inv_unsep, s, unit); //@ produce_lemma_function_pointer_chunk(allClients_try_pop); bool result = stack_try_pop(s, &v2); //@ leak is_stack_try_pop_context(allClients_try_pop); //@ open stack_try_pop_context_post(allClients_try_pop)(_, _, unit); //@ unshare_stack(s); //@ open stack_unsep(stack_inv_unsep)(unit, s, stack_inv(s, unit), stack_inv_sep, _); //@ leak is_stack_sep(stack_inv_sep); //@ leak is_stack_unsep(stack_inv_unsep); bool hasMore = true; while(hasMore) //@ invariant stack(s, ?remElems) &*& stack_allClients(s, remElems, unit) &*& pointer(&v3, _) &*& (hasMore ? true: remElems == nil); { hasMore = stack_try_pop_sequential(s, &v3); //@ open stack_allClients(s, remElems, unit); //@ close stack_allClients(s, tail(remElems), unit); } //@ open stack_allClients(s, _, unit); dispose_stack(s); free(v); }
void save_stack( stack *trg_p, FILE *fp ) { stack *stack_p; stack_item *si_p; string_object s; if ( trg_p ) fprintf( fp, "\n{ " ); if ( NULL == (stack_p = make_stack()) ) { cprintf( ERROR, CONT, "unrecoverable @ show_stack (1)\n" ); exit ( 1 ); } stack_rcopy( stack_p, trg_p ); si_p = stack_p->stack_top_p; while ( si_p ) { if ( si_p->type == STACK ) { save_stack( *((stack **)si_p->item_p), fp ); } else { s = ui_stack_item_to_string( si_p, -1, STRING_WITH_QUOTE ); fprintf( fp, "%s ", s ); dispose_string_object( s ); } si_p = si_p->next; } dispose_stack( stack_p ); if ( trg_p ) fprintf( fp, "k}\n" ); }