void Block::setNull(int index) { ca_assert(index <= length()); Term* term = _terms[index]; if (term != NULL) erase_term(term); }
void clear_block(Block* block) { block->names.clear(); block->inProgress = false; // Iterate through the block and tear down any term references, so that we // don't have to worry about stale pointers later. for (BlockIterator it(block); it; ++it) { if (*it == NULL) continue; pre_erase_term(*it); set_inputs(*it, TermList()); remove_from_any_user_lists(*it); change_function(*it, NULL); } for (int i= block->_terms.length() - 1; i >= 0; i--) { Term* term = block->get(i); if (term == NULL) continue; if (term->nestedContents) clear_block(term->nestedContents); } for (int i = block->_terms.length() - 1; i >= 0; i--) { Term* term = block->get(i); if (term == NULL) continue; // Delete any leftover users, mark them as repairable. for (int userIndex = 0; userIndex < term->users.length(); userIndex++) { Term* user = term->users[userIndex]; for (int depIndex = 0; depIndex < user->numDependencies(); depIndex++) { if (user->dependency(depIndex) == term) { // mark_repairable_link(user, term->name, depIndex); user->setDependency(depIndex, NULL); } } } erase_term(term); } block->_terms.clear(); }
void test_erase_term() { Block block; block.compile("a = 1"); block.compile("b = 2"); block.compile("c = 3"); test_equals(block.get(0)->nameStr(), "a"); test_equals(block.get(1)->nameStr(), "b"); test_equals(block.get(2)->nameStr(), "c"); erase_term(block.get(1)); test_equals(block.get(0)->nameStr(), "a"); test_assert(block.get(1) == NULL); test_equals(block.get(2)->nameStr(), "c"); remove_nulls(&block); test_equals(block.get(0)->nameStr(), "a"); test_equals(block.get(1)->nameStr(), "c"); }