41 TranslationUnit& tu,
const Clause& clause) {
42 std::map<std::string, const RecordInit*> variableRecordMap;
44 auto isVariable = [](
Node* node) ->
bool {
return isA<ast::Variable>(node); };
45 auto isRecord = [](
Node* node) ->
bool {
return isA<RecordInit>(node); };
50 for (
auto* literal : clause.getBodyLiterals()) {
56 auto left = constraint->getLHS();
57 auto right = constraint->getRHS();
59 if (!isVariable(left) && !isVariable(right)) {
63 if (!isRecord(left) && !isRecord(right)) {
70 if (!typeAnalysis.getTypes(left).isAll()) {
74 auto* variable =
static_cast<ast::Variable*
>(isVariable(left) ? left : right);
75 const auto& variableName = variable->getName();
77 if (!groundedTerms.find(variable)->second) {
82 if (variableRecordMap.find(variableName) != variableRecordMap.end()) {
86 auto* record =
static_cast<RecordInit*
>(isRecord(left) ? left : right);
88 variableRecordMap.insert({variableName, record});
92 return variableRecordMap;
96 struct ReplaceVariables :
public NodeMapper {
97 std::map<std::string, const RecordInit*> varToRecordMap;
99 ReplaceVariables(std::map<std::string, const RecordInit*> varToRecordMap)
100 : varToRecordMap(
std::move(varToRecordMap)){};
103 if (
auto variable =
dynamic_cast<ast::Variable*
>(node.get())) {
104 auto iteratorToRecord = varToRecordMap.find(variable->getName());
105 if (iteratorToRecord != varToRecordMap.end()) {
117 bool changed = variableToRecordMap.size() > 0;
119 ReplaceVariables update(std::move(variableToRecordMap));
120 clause.apply(update);
126 struct ReplaceUnnamed :
public NodeMapper {
127 mutable bool changed{
false};
128 ReplaceUnnamed() =
default;
131 auto isUnnamed = [](
Node* node) ->
bool {
return isA<UnnamedVariable>(node); };
132 auto isRecord = [](
Node* node) ->
bool {
return isA<RecordInit>(node); };
135 auto left = constraint->getLHS();
136 auto right = constraint->getRHS();
137 bool hasUnnamed = isUnnamed(left) || isUnnamed(right);
138 bool hasRecord = isRecord(left) || isRecord(right);
139 auto op = constraint->getBaseOperator();
141 return mk<BooleanConstraint>(
true);
151 ReplaceUnnamed update;
152 clause.apply(update);
154 return update.changed;
158 bool changed =
false;
159 Program& program = translationUnit.getProgram();
160 for (
auto* clause : program.getClauses()) {