26 Program& program = translationUnit.getProgram();
35 struct AggregateTESimplifier :
public NodeMapper {
36 mutable bool changed =
false;
38 const Clause* originatingClause;
45 std::unique_ptr<Node> operator()(std::unique_ptr<Node> node)
const override {
46 if (
auto* aggregate =
dynamic_cast<Aggregator*
>(node.get())) {
48 if (aggregate->getTargetExpression() !=
nullptr &&
49 dynamic_cast<const Variable*
>(aggregate->getTargetExpression()) ==
nullptr) {
60 auto newTargetExpression =
65 std::vector<std::unique_ptr<Literal>> newBody;
66 for (
Literal* literal : aggregate->getBodyLiterals()) {
69 newBody.push_back(std::move(equalityLiteral));
84 std::set<std::string> varsOutside =
87 std::set<std::string> varsGroundedOutside;
88 for (
auto& varName : varsOutside) {
89 if (witnesses.find(varName) == witnesses.end()) {
90 varsGroundedOutside.insert(varName);
99 if (varsGroundedOutside.find(v.getName()) != varsGroundedOutside.end()) {
101 std::string newVarName =
102 analysis::findUniqueVariableName(*originatingClause, v.getName());
103 for (auto& literal : newBody) {
104 visitDepthFirst(*literal, [&](const Variable& literalVar) {
105 if (literalVar == v) {
106 const_cast<Variable&>(literalVar).setName(newVarName);
114 auto newAggregate = mk<Aggregator>(
115 aggregate->getBaseOperator(), std::move(newTargetExpression), std::move(newBody));
125 bool changed =
false;
128 AggregateTESimplifier teSimplifier(&translationUnit, oldClause.get());
129 const_cast<Clause&
>(clause).apply(teSimplifier);
130 changed = changed || teSimplifier.causedChange();