souffle  2.0.2-371-g6315b36
Public Member Functions | Private Member Functions
souffle::ast::transform::AddNullariesToAtomlessAggregatesTransformer Class Reference

Transformation pass to add artificial nullary atom (+Tautology()) to aggregate bodies that have no atoms. More...

#include <AddNullariesToAtomlessAggregates.h>

Inheritance diagram for souffle::ast::transform::AddNullariesToAtomlessAggregatesTransformer:
Inheritance graph
Collaboration diagram for souffle::ast::transform::AddNullariesToAtomlessAggregatesTransformer:
Collaboration graph

Public Member Functions

AddNullariesToAtomlessAggregatesTransformerclone () const override
 
std::string getName () const override
 
- Public Member Functions inherited from souffle::ast::transform::Transformer
bool apply (TranslationUnit &translationUnit)
 
virtual ~Transformer ()=default
 

Private Member Functions

bool transform (TranslationUnit &translationUnit) override
 

Detailed Description

Transformation pass to add artificial nullary atom (+Tautology()) to aggregate bodies that have no atoms.

Definition at line 45 of file AddNullariesToAtomlessAggregates.h.

Member Function Documentation

◆ clone()

AddNullariesToAtomlessAggregatesTransformer* souffle::ast::transform::AddNullariesToAtomlessAggregatesTransformer::clone ( ) const
inlineoverridevirtual

◆ getName()

std::string souffle::ast::transform::AddNullariesToAtomlessAggregatesTransformer::getName ( ) const
inlineoverridevirtual

◆ transform()

bool souffle::ast::transform::AddNullariesToAtomlessAggregatesTransformer::transform ( TranslationUnit translationUnit)
overrideprivatevirtual

Implements souffle::ast::transform::Transformer.

Definition at line 38 of file AddNullariesToAtomlessAggregates.cpp.

38  {false};
39  for (const auto& literal : agg.getBodyLiterals()) {
40  if (isA<Atom>(literal)) {
41  seenAtom = true;
42  }
43  }
44  if (seenAtom) {
45  return;
46  }
47  // We will add in the Tautology atom to the body of this aggregate now
48  changed = true;
49  // +Tautology()
50  auto nullaryAtom = mk<Atom>();
51  std::string relName = "+Tautology";
52  nullaryAtom->setQualifiedName(relName);
53 
54  if (getRelation(program, relName) == nullptr) {
55  // +Tautology().
56  auto fact = mk<Clause>();
57  fact->setHead(souffle::clone(nullaryAtom));
58  // .decl +Tautology()
59  auto tautologyRel = mk<Relation>();
60  tautologyRel->setQualifiedName(relName);
61  program.addRelation(std::move(tautologyRel));
62  program.addClause(std::move(fact));
63  }
64  VecOwn<Literal> newBody;
65  for (const auto& lit : agg.getBodyLiterals()) {
66  newBody.push_back(souffle::clone(lit));
67  }
68  newBody.push_back(souffle::clone(nullaryAtom));
69  const_cast<Aggregator&>(agg).setBody(std::move(newBody));
70  });
71  return changed;
72 }
73 } // namespace souffle::ast::transform

The documentation for this class was generated from the following files:
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
souffle::ast::getRelation
Relation * getRelation(const Program &program, const QualifiedName &name)
Returns the relation with the given name in the program.
Definition: Utils.cpp:101