68 VecOwn<ram::Expression> values;
69 for (
auto& arg : head->getArguments()) {
87 for (
const auto& cur :
valueIndex->getVariableReferences()) {
89 const Location& first = *cur.second.begin();
91 for (
const Location& loc : cur.second) {
92 if (first != loc && !
valueIndex->isGenerator(loc.identifier)) {
103 for (
const auto& lit : clause.getBodyLiterals()) {
105 op = mk<ram::Filter>(std::move(condition), std::move(op));
112 const ast::Node* cur = *it;
114 if (
const auto* atom =
dynamic_cast<const ast::Atom*
>(cur)) {
117 for (
auto arg : atom->getArguments()) {
118 if (
auto* agg =
dynamic_cast<ast::Aggregator*
>(arg)) {
121 op = mk<ram::Filter>(
134 if (
auto agg =
dynamic_cast<const ast::Aggregator*
>(cur)) {
136 Own<ram::Condition> aggCond;
137 auto addAggCondition = [&](Own<ram::Condition> arg) {
138 aggCond = aggCond ? mk<ram::Conjunction>(std::move(aggCond), std::move(arg)) :
std::move(arg);
142 for (
auto&& lit : agg->getBodyLiterals()) {
144 addAggCondition(std::move(newCondition));
150 const ast::Atom* atom =
nullptr;
151 for (
auto&& lit : agg->getBodyLiterals()) {
152 if (atom ==
nullptr) {
153 atom =
dynamic_cast<const ast::Atom*
>(lit);
155 assert(!isA<ast::Atom>(lit) &&
"Unsupported complex aggregation body encountered!");
160 if (atom !=
nullptr) {
162 auto addAggEqCondition = [&](Own<ram::Expression> value) {
166 addAggCondition(mk<ram::Constraint>(
169 for (
auto* arg : atom->getArguments()) {
172 if (
auto* var =
dynamic_cast<const ast::Variable*
>(arg)) {
173 for (
auto&& loc :
valueIndex->getVariableReferences().find(var->getName())->second) {
174 if (
level != loc.identifier || (
int)pos != loc.element) {
180 addAggEqCondition(std::move(value));
190 op = mk<ram::Aggregate>(std::move(op), agg->getFinalType().value(),
192 aggCond ? std::move(aggCond) : mk<ram::True>(),
level);
193 }
else if (
const auto* func =
dynamic_cast<const ast::IntrinsicFunctor*
>(cur)) {
194 VecOwn<ram::Expression> args;
195 for (
auto&& x : func->getArguments()) {
200 switch (func->getFinalOpType().value()) {
205 default:
fatal(
"missing case handler or bad code-gen");
209 op = mk<ram::NestedIntrinsicOperator>(func_op(), std::move(args), std::move(op),
level);
224 if (
const auto* atom =
dynamic_cast<const ast::Atom*
>(cur)) {
230 bool isAllArgsUnnamed =
true;
231 for (
auto* argument : atom->getArguments()) {
232 if (!isA<ast::UnnamedVariable>(argument)) {
233 isAllArgsUnnamed =
false;
238 op = mk<ram::Filter>(
243 if (atom->getArity() != 0 && !isAllArgsUnnamed) {
244 if (head->getArity() == 0) {
250 std::stringstream
ss;
251 ss << head->getQualifiedName();
253 ss <<
"@frequency-atom" <<
';';
254 ss << originalClause.getHead()->getQualifiedName() <<
';';
255 ss << version <<
';';
267 }
else if (
const auto* rec =
dynamic_cast<const ast::RecordInit*
>(cur)) {
272 const Location& loc =
valueIndex->getDefinitionPoint(*rec);
273 op = mk<ram::UnpackRecord>(
276 fatal(
"Unsupported AST node for creation of scan-level!");
282 if (cond !=
nullptr) {
283 return mk<ram::Query>(mk<ram::Filter>(std::move(cond), std::move(op)));
285 return mk<ram::Query>(std::move(op));
290 const auto head = clause.getHead();
292 VecOwn<ram::Expression> values;
293 for (ast::Argument* arg : head->getArguments()) {