47 QualifiedName name(
"@min:head");
48 std::vector<std::string> headVars;
49 for (
const auto* arg : clause->getHead()->getArguments()) {
55 for (
const auto* lit : clause->getBodyLiterals()) {
61 const std::string& qualifier,
const std::string& scopeID,
const Atom* atom) {
62 QualifiedName name(atom->getQualifiedName());
63 name.prepend(qualifier);
65 std::vector<std::string> vars;
66 vars.push_back(scopeID);
67 for (
const auto* arg : atom->getArguments()) {
74 if (
const auto* atom =
dynamic_cast<const Atom*
>(lit)) {
76 }
else if (
const auto* neg =
dynamic_cast<const Negation*
>(lit)) {
78 }
else if (
const auto* bc =
dynamic_cast<const BinaryConstraint*
>(lit)) {
80 name.prepend(
"@min:operator");
81 std::vector<std::string> vars;
82 vars.push_back(scopeID);
87 assert(lit !=
nullptr &&
"unexpected nullptr lit");
89 std::stringstream qualifier;
90 qualifier <<
"@min:unhandled:lit:" << scopeID;
92 name.prepend(qualifier.str());
93 clauseElements.push_back({.name = name, .params = std::vector<std::string>()});
98 if (
auto* stringCst =
dynamic_cast<const StringConstant*
>(arg)) {
99 std::stringstream name;
100 name <<
"@min:cst:str" << *stringCst;
104 std::stringstream name;
105 name <<
"@min:cst:num:" << *numericCst;
108 }
else if (isA<NilConstant>(arg)) {
110 return "@min:cst:nil";
111 }
else if (
auto* var =
dynamic_cast<const ast::Variable*
>(arg)) {
112 auto name = var->getName();
115 }
else if (
dynamic_cast<const UnnamedVariable*
>(arg)) {
116 static size_t countUnnamed = 0;
117 std::stringstream name;
118 name <<
"@min:unnamed:" << countUnnamed++;
121 }
else if (
auto* aggr =
dynamic_cast<const Aggregator*
>(arg)) {
123 std::stringstream scopeID;
128 std::stringstream aggrTypeSignature;
129 aggrTypeSignature <<
"@min:aggrtype";
130 std::vector<std::string> aggrTypeSignatureComponents;
133 aggrTypeSignature <<
":" << aggr->getBaseOperator();
136 aggrTypeSignatureComponents.push_back(scopeID.str());
139 if (aggr->getTargetExpression() !=
nullptr) {
141 aggrTypeSignatureComponents.push_back(normalisedExpr);
145 clauseElements.push_back({.name = aggrTypeSignature.str(), .params = aggrTypeSignatureComponents});
148 for (
const auto* literal : aggr->getBodyLiterals()) {
153 return scopeID.str();
156 return "@min:unhandled:arg";
161 const auto& program = translationUnit.getProgram();
162 for (
const auto* clause : program.getClauses()) {
170 os <<
"Normalise(" << *clause <<
") = {";
171 const auto& els = norm.getElements();
172 for (
size_t i = 0;
i < els.size();
i++) {
176 os << els[
i].name <<
":" << els[
i].params;
178 os <<
"}" << std::endl;