void CNFMgr::scanTerm(const ASTNode& varphi) { CNFInfo* x; //######################################## // step 1, get the info associated with this node //######################################## if (info.find(varphi) == info.end()) { x = new CNFInfo(); info[varphi] = x; } else { x = info[varphi]; } //######################################## // step 2, need two hits because of term ITEs. //######################################## if (sharesPos(*x) == 2) { return; } //######################################## // step 3, set appropriate data fields, always rename // term ITEs //######################################## incrementSharesPos(*x); setIsTerm(*x); //######################################## // step 4, recurse over children //######################################## if (varphi.isAtom()) { return; } else if (varphi.isITE()) { scanFormula(varphi[0], true, false); scanFormula(varphi[0], false, false); scanTerm(varphi[1]); scanTerm(varphi[2]); } else { for (unsigned int i = 0; i < varphi.GetChildren().size(); i++) { scanTerm(varphi[i]); } } }//End of scanterm()
std::unique_ptr<const Expression> Parser::next(const Lex& lex) { switch (lex.lexType) { case LexType::EOFF: return std::unique_ptr<const Expression>(); case LexType::STR: return nextString(); case LexType::LEX: return scanTerm(static_cast<const StrLex&>(lex).str); case LexType::LST_START: return nextCol<List>(LexType::LST_END); case LexType::VEC_START: return nextCol<Vector>(LexType::VEC_END); case LexType::SET_START: return nextCol<Set>(LexType::SET_END); case LexType::CHR: return std::unique_ptr<const Expression>(new Quote(next())); case LexType::HSH: return std::unique_ptr<const Expression>(new Unquote(_lexer.expectAtom())); default: return std::unique_ptr<const Expression>(new Nil); } }
void CNFMgr::scanFormula(const ASTNode& varphi, bool isPos, bool isXorChild) { CNFInfo* x; Kind k = varphi.GetKind(); //######################################## // step 1, get the info associated with this node //######################################## if (info.find(varphi) == info.end()) { x = new CNFInfo(); info[varphi] = x; } else { x = info[varphi]; } #if defined CRYPTOMINISAT__2 if(isXorChild) { setDoRenamePos(*x); } #endif //######################################## // step 2, we only need to know if shares >= 2 //######################################## if (isPos && sharesPos(*x) == 2) { return; } if (!isPos && sharesNeg(*x) == 2) { return; } //######################################## // step 3, set appropriate information fields //######################################## if (isPos) { incrementSharesPos(*x); } if (!isPos) { incrementSharesNeg(*x); } //######################################## // step 4, recurse over children //######################################## if (varphi.isAtom()) { return; } else if (varphi.isPred()) { for (unsigned int i = 0; i < varphi.GetChildren().size(); i++) { scanTerm(varphi[i]); } } else { for (unsigned int i = 0; i < varphi.GetChildren().size(); i++) { if (onChildDoPos(varphi, i)) { scanFormula(varphi[i], isPos, k == XOR); } if (onChildDoNeg(varphi, i)) { scanFormula(varphi[i], !isPos, false); } } } } //End of ScanFormula()