void PrefixMatchImpl::advance(Iterator& i) { if (i.m_entry == nullptr) { if (i.m_ref == nullptr) { // empty enumerable i = Iterator(); return; } i.m_entry = i.m_ref; if (m_pred(*i.m_entry)) { // visit starting node return; } } // traverse up the tree while ((i.m_entry = i.m_entry->getParent()) != nullptr) { if (m_pred(*i.m_entry)) { return; } } // reach the end i = Iterator(); }
bool ConditionVariable::CvarAwaiter::await_ready() const noexcept { // Note that predicate does not need to be checked in await_suspend because it's protected by the mutex. if (m_pred) { return m_pred(); } return false; }
void check_pred::visit(expr* e) { ptr_vector<expr> todo; todo.push_back(e); while (!todo.empty()) { e = todo.back(); if (m_pred(e)) { m_pred_holds.mark(e, true); } if (m_visited.is_marked(e)) { todo.pop_back(); continue; } switch(e->get_kind()) { case AST_APP: { app* a = to_app(e); bool all_visited = true; unsigned num_args = a->get_num_args(); for (unsigned i = 0; i < num_args; ++i) { expr* arg = a->get_arg(i); if (!m_visited.is_marked(arg)) { todo.push_back(arg); all_visited = false; } else if (m_pred_holds.is_marked(arg)) { m_pred_holds.mark(e, true); } } if (all_visited) { m_visited.mark(e, true); todo.pop_back(); } break; } case AST_QUANTIFIER: { quantifier* q = to_quantifier(e); expr* arg = q->get_expr(); if (m_visited.is_marked(arg)) { todo.pop_back(); if (m_pred_holds.is_marked(arg)) { m_pred_holds.mark(e, true); } m_visited.mark(e, true); } else { todo.push_back(arg); } break; } case AST_VAR: todo.pop_back(); m_visited.mark(e, true); break; default: UNREACHABLE(); break; } } }
void FullEnumerationImpl::advance(Iterator& i) { // find first entry if (i.m_entry == nullptr) { for (size_t bucket = 0; bucket < ht.getNBuckets(); ++bucket) { const Node* node = ht.getBucket(bucket); if (node != nullptr) { i.m_entry = &node->entry; break; } } if (i.m_entry == nullptr) { // empty enumerable i = Iterator(); return; } if (m_pred(*i.m_entry)) { // visit first entry return; } } // process entries in same bucket for (const Node* node = getNode(*i.m_entry)->next; node != nullptr; node = node->next) { if (m_pred(node->entry)) { i.m_entry = &node->entry; return; } } // process other buckets size_t currentBucket = ht.computeBucketIndex(getNode(*i.m_entry)->hash); for (size_t bucket = currentBucket + 1; bucket < ht.getNBuckets(); ++bucket) { for (const Node* node = ht.getBucket(bucket); node != nullptr; node = node->next) { if (m_pred(node->entry)) { i.m_entry = &node->entry; return; } } } // reach the end i = Iterator(); }
void PartialEnumerationImpl::advance(Iterator& i) { bool wantSelf = false; bool wantChildren = false; // initialize: start from root if (i.m_entry == nullptr) { if (i.m_ref == nullptr) { // root does not exist i = Iterator(); return; } i.m_entry = i.m_ref; std::tie(wantSelf, wantChildren) = m_pred(*i.m_entry); if (wantSelf) { // visit root i.m_state = wantChildren; return; } } else { wantChildren = static_cast<bool>(i.m_state); } BOOST_ASSERT(i.m_ref != nullptr); // pre-order traversal while (i.m_entry != i.m_ref || (wantChildren && i.m_entry->hasChildren())) { if (wantChildren && i.m_entry->hasChildren()) { // process children of m_entry i.m_entry = i.m_entry->getChildren().front(); std::tie(wantSelf, wantChildren) = m_pred(*i.m_entry); if (wantSelf) { // visit first child i.m_state = wantChildren; return; } // first child rejected, let while loop process other children (siblings of new m_entry) } else { // process siblings of m_entry const Entry* parent = i.m_entry->getParent(); const std::vector<Entry*>& siblings = parent->getChildren(); auto sibling = std::find(siblings.begin(), siblings.end(), i.m_entry); BOOST_ASSERT(sibling != siblings.end()); while (++sibling != siblings.end()) { i.m_entry = *sibling; std::tie(wantSelf, wantChildren) = m_pred(*i.m_entry); if (wantSelf) { // visit sibling i.m_state = wantChildren; return; } if (wantChildren) { break; // let outer while loop process children of m_entry } // process next sibling } if (sibling == siblings.end()) { // no more sibling i.m_entry = parent; wantChildren = false; } } } // reach the end i = Iterator(); }
bool test(entity const & e) const { return m_pred(e); }
bool operator()(Iterator it) { return m_pred(read(it)); }
const Value& operator()(const Value& x) const { return m_pred(x) ? m_to : x; }