bool subsumes(Context& cxt, Expr const& a, Expr const& c) { Cons& c1 = normalize(cxt, modify(a)); Cons& c2 = normalize(cxt, modify(c)); return subsumes(cxt, c1, c2); }
static BOOL subsumed_by_member(Clause c, Plist p) { if (p == NULL) return FALSE; else if (subsumes(p->v, c)) return TRUE; else return subsumed_by_member(c, p->next); } /* subsumed_by_member */
static Topform find_equivalent_hint(Topform c, Lindex idx) { Topform equiv_hint = NULL; Plist subsumees = back_subsume(c, idx); Plist p; for (p = subsumees; p && equiv_hint == NULL; p = p->next) { if (subsumes(p->v, c)) equiv_hint = p->v; } zap_plist(subsumees); return equiv_hint; } /* find_equivalent_hint */
static Topform find_matching_hint(Topform c, Lindex idx) { Topform hint = NULL; Plist subsumees = back_subsume(c, idx); Plist p; BOOL equivalent = FALSE; for (p = subsumees; p && !equivalent; p = p->next) { /* printf("subsumee: "); f_clause(p->v); */ hint = p->v; if (subsumes(p->v, c)) equivalent = TRUE; } zap_plist(subsumees); return hint; } /* find_matching_hint */
bool subsumesItself(const Clause* cl) // for debugging { // idiotic, but helps to check certain things resetSubst(); // assigning variables to themselves for (LiteralList::Iterator iter(cl->LitList());iter.notEnd();iter.next()) { _termTraversal2.reset(iter.currentElement()->literalRef()); _termTraversal2.next(); while (_termTraversal2) { if ((_termTraversal2.state() == TERM::Traversal::Var) && (!_subst.assigned(_termTraversal2.symbol().var()))) substPair(_termTraversal2.symbol().var(),_termTraversal2.symbol()); _termTraversal2.next(); }; }; return subsumes(cl,cl); }; // bool subsumesItself(const Clause* cl) // for debugging
// remove subsumed clauses int removedSubsumed(Clause &cl1, Clause &cl2, List<Clause> &cl2rmv) { // check if clause 1 subsumes clause 2. Substitutions s; Clause c1(cl1); Clause c2(cl2); statistics[AttemptedSubsumptionTests] += 1; totalstatistics[TotalAttemptedSubsumptionTests] += 1; if (subsumes(c1, c2, s) == OK) { statistics[SubsumedClausesRemoved] += 1; totalstatistics[TotalSubsumedClausesRemoved] += 1; if (cl2rmv.insertAtEnd(c2) != OK) { ERROR("insertAtEnd failed.", errno); return(NOTOK); } } return(OK); }
void order_concept_directive(Parser& p) { p.require(concept_tok); Concept_decl& c1 = cast<Concept_decl>(p.concept_name()); Concept_decl& c2 = cast<Concept_decl>(p.concept_name()); p.match(semicolon_tok); // TODO: Determine which subsumes the other by synthesizing // arguments to create check (and validate) check expressions, // normalize those, and then run the subsumption algorithm. Context& cxt = p.cxt; Builder build(cxt); Term_list a1 = synthesize_template_arguments(cxt, c1.parameters()); Term_list a2 = synthesize_template_arguments(cxt, c2.parameters()); Cons& con1 = build.get_concept_constraint(c1, a1); Cons& con2 = build.get_concept_constraint(c2, a2); bool result = subsumes(cxt, con1, con2); std::cout << std::boolalpha << result << '\n'; }
// remove subsumed clauses int removedSubsumed(List<Clause> &cl1, List<Clause> &cl2, List<Clause> &cl2rmv) { // check if any clauses in clause list 1 subsume any // clause in clause set 2. ListIterator<Clause> cl2Iter(cl2); for ( ; !cl2Iter.done(); cl2Iter++) { ListIterator<Clause> cl1Iter(cl1); for ( ; !cl1Iter.done(); cl1Iter++) { Substitutions s; Clause c1(cl1Iter()); Clause c2(cl2Iter()); if (subsumes(c1, c2, s) == OK) { if (cl2rmv.insertAtEnd(cl2Iter()) != OK) return(NOTOK); } } } return(OK); }
main(int argc, char **argv) { Clause c1, c2; int icl = 1; for (int arg = 1; arg < argc; arg++) { if (String(argv[arg]) == String("-")) { icl = 2; continue; } Literal l(argv[arg]); DUMP(l); switch (icl) { case 1: if (c1.insert(l) != OK) { cout << "unable to insert literal " << l << endl; return(2); } break; case 2: if (c2.insert(l) != OK) { cout << "unable to insert literal " << l << endl; return(2); } break; default: MustBeTrue(icl == 1 || icl == 2); } } DUMP(c1); DUMP(c2); cout << "rename all variables in clauses ..." << endl;; MustBeTrue(c1.renameVariables() == OK); MustBeTrue(c2.renameVariables() == OK); DUMP(c1); DUMP(c2); Substitutions s; switch (subsumes(c1, c2, s)) { case OK: cout << "====================================" << endl; cout << "c1 SUBSUMES c2 !!!" << endl; cout << "subs is ... " << s << endl; s.applyTo(c1); s.applyTo(c2); cout << "subs*c1 is ... " << c1 << endl; cout << "subs*c2 is ... " << c2 << endl; break; case NOMATCH: cout << "====================================" << endl; cout << "c1 DOES NOT SUBSUME c2 !!!" << endl; break; default: cout << "====================================" << endl; cout << "ERROR !!!" << endl; break; } return(0); }
bool AccessCheck::subsumes(JSObject* a, JSObject* b) { return subsumes(js::GetObjectCompartment(a), js::GetObjectCompartment(b)); }