int main() //@ requires emp; //@ ensures emp; { struct node *node0 = create_tree(); struct node *node = node0; node = tree_add_left(node); node = tree_add_right(node); node = tree_get_parent(node); node = tree_add_left(node); node = tree_get_parent(node); node = tree_get_parent(node); //@ assert(node == node0); tree_dispose(node); return 0; }
int rec_copy(tree* dest, tree* copying) { switch(copying -> type) { case TR_N: tree_save_double(dest, *(double*)(copying -> value)); break; case TR_SIGN: tree_save_int(dest, *(int*)(copying -> value)); break; case TR_F: case TR_V: tree_save_string(dest, (char*)(copying -> value)); break; case TR_PGM: case TR_NONE: break; default: VERIFY1(true, CPLR_BAD, "WRONG TYPE OF TREE: GOT [%d]", copying -> type); } dest -> type = copying -> type; int ret = 0; tree* temp_tree = NULL; if (copying -> left != NULL) { ret = tree_ctr(&temp_tree, dest -> head); assert(ret == TREE_OK); ret = tree_add_left(dest, temp_tree); assert(ret == TREE_OK); ret = rec_copy(dest -> left, copying -> left); } if (copying -> right != NULL) { ret = tree_ctr(&temp_tree, dest -> head); assert(ret == TREE_OK); ret = tree_add_right(dest, temp_tree); assert(ret == TREE_OK); ret = rec_copy(dest -> right, copying -> right); } return TREE_OK; }
int tree_init(tree** dest_save_tree_token, tree_head* head_ptr, tree* tree_to_stick_to, char* func_name, int tree_type, int add_side) { assert(dest_save_tree_token != NULL); assert(head_ptr != NULL); assert(tree_to_stick_to != NULL); assert(func_name != NULL); assert(add_side == LEFT || add_side == RIGHT); int ret = tree_ctr(dest_save_tree_token, head_ptr); VERIFY2(ret != TREE_OK, SNTX_CTR_FAILED, "%s: %s", func_name, sntx_errors[CTR_FAIL]); ret = tree_burn(*dest_save_tree_token, tree_type); VERIFY2(ret != TREE_OK, SNTX_BURN_FAILED,"%s: %s", func_name, sntx_errors[BURN_FAIL]); if (add_side == RIGHT) ret = tree_add_right(tree_to_stick_to, *dest_save_tree_token); else ret = tree_add_left (tree_to_stick_to, *dest_save_tree_token); VERIFY2(ret != TREE_OK, SNTX_ADD_FAILED, "%s: %s", func_name, sntx_errors[ADD_FAIL]); return TREE_OK; }