souffle  2.0.2-371-g6315b36
Namespaces | Data Structures | Typedefs | Enumerations | Functions
souffle::ast Namespace Reference

Namespaces

 analysis
 
 detail
 
 test
 
 transform
 

Data Structures

class  Aggregator
 Defines the aggregator class. More...
 
class  AlgebraicDataType
 Combination of types using sums and products. More...
 
class  AllBoundSips
 Goal: Prioritise atoms with all arguments bound. More...
 
class  Argument
 An abstract class for arguments. More...
 
struct  ast_visitor_tag
 A tag type required for the is_ast_visitor type trait to identify AstVisitors. More...
 
class  Atom
 An atom class. More...
 
class  Attribute
 Attribute class. More...
 
class  BinaryConstraint
 Binary constraint class. More...
 
class  BindingStore
 
class  BooleanConstraint
 Boolean constraint class. More...
 
class  BranchDeclaration
 Wrapper for the single branch declaration (product type) inside ADT declaration. More...
 
class  BranchInit
 Initialization of ADT instance. More...
 
class  Clause
 Intermediate representation of a horn clause. More...
 
class  Component
 Component class. More...
 
class  ComponentInit
 Component initialization class. More...
 
class  ComponentType
 Component type of a component. More...
 
class  Constant
 Abstract constant class. More...
 
class  Constraint
 Abstract class for AST constraints. More...
 
class  Counter
 counter functor (incrementing a value after each invocation) More...
 
class  DeltaInputSips
 Goal: prioritise (1) all-bound, then (2) deltas, then (3) input, and then (4) left-most. More...
 
class  DeltaSips
 Goal: prioritise (1) all-bound, then (2) deltas, and then (3) left-most. More...
 
class  Directive
 a directive has a type (e.g. input/output/printsize/limitsize), qualified relation name, and a key value map for storing parameters of the directive. More...
 
class  ExecutionOrder
 An execution order for atoms within a clause; one or more execution orders form a plan. More...
 
class  ExecutionPlan
 
class  Functor
 Abstract functor class. More...
 
class  FunctorDeclaration
 User-defined functor declaration. More...
 
class  InputSips
 Goal: prioritise (1) all-bound, then (2) input, and then (3) left-most. More...
 
class  IntrinsicFunctor
 Intrinsic Functor class for functors are in-built. More...
 
class  LeastFreeSips
 Goal: choose the atom with the least number of unbound arguments. More...
 
class  LeastFreeVarsSips
 Goal: choose the atom with the least amount of unbound variables. More...
 
class  Literal
 Defines an abstract class for literals in a horn clause. More...
 
class  MaxBoundSips
 Goal: prioritise (1) all-bound, then (2) max number of bound vars, then (3) left-most. More...
 
class  MaxRatioSips
 Goal: prioritise max ratio of bound args. More...
 
class  NaiveSips
 Goal: Prioritise (1) all bound, then (2) atoms with at least one bound argument, then (3) left-most. More...
 
class  NameComparison
 Comparator for relations. More...
 
class  Negation
 Negation of an atom negated atom. More...
 
class  NilConstant
 Defines the nil constant. More...
 
class  Node
 Abstract class for syntactic elements in an input program. More...
 
class  NodeMapper
 An abstract class for manipulating AST Nodes by substitution. More...
 
class  NumericConstant
 Numeric Constant. More...
 
class  Pragma
 Representation of a global option. More...
 
class  ProfileUseSips
 Goal: reorder based on the given profiling information Metric: cost(atom_R) = log(|atom_R|) * #free/#args. More...
 
class  Program
 The program class consists of relations, clauses and types. More...
 
class  ProvenanceNegation
 Subclass of Literal that represents a negated atom, * e.g., !parent(x,y). More...
 
class  QualifiedName
 Qualified Name class defines fully/partially qualified names to identify objects in components. More...
 
class  RecordInit
 Defines a record initialization class. More...
 
class  RecordType
 Record type class for record type declarations. More...
 
class  Relation
 Defines a relation with a name, attributes, qualifiers, and internal representation. More...
 
class  SipsMetric
 Class for SIPS cost-metric functions Each subclass represents a different heuristic used for evaluating the cost of choosing an atom next in the schedule. More...
 
class  StrictSips
 Goal: Always choose the left-most atom. More...
 
class  StringConstant
 String constant class. More...
 
class  SubroutineArgument
 Defines the argument class for subrountines. More...
 
class  SubsetType
 Defines subset type class. More...
 
class  Term
 Defines an abstract term class used for functors and other constructors. More...
 
class  TranslationUnit
 Translation unit class for the translation pipeline. More...
 
class  Type
 An abstract base class for types. More...
 
class  TypeCast
 Defines a type cast class for expressions. More...
 
class  UnionType
 The union type class. More...
 
class  UnnamedVariable
 Unnamed variable class. More...
 
class  UserDefinedFunctor
 User-Defined functor class. More...
 
class  Variable
 Named variable class. More...
 
struct  Visitor
 The generic base type of all AstVisitors realizing the dispatching of visitor calls. More...
 

Typedefs

using RelationSet = std::set< const Relation *, NameComparison >
 Relation set. More...
 

Enumerations

enum  DirectiveType { DirectiveType::input, DirectiveType::output, DirectiveType::printsize, DirectiveType::limitsize }
 

Functions

ClausecloneHead (const Clause *clause)
 Returns a clause which contains head of the given clause. More...
 
const RelationgetAtomRelation (const Atom *atom, const Program *program)
 Returns the relation referenced by the given atom. More...
 
template<typename T , typename C >
std::vector< T * > getBodyLiterals (const C &clause)
 Returns literals of a particular type in the body of a clause. More...
 
std::set< const Relation * > getBodyRelations (const Clause *clause, const Program *program)
 Returns the relations referenced in the body of the given clause. More...
 
size_t getClauseNum (const Program *program, const Clause *clause)
 Returns the index of a clause within its relation, ignoring facts. More...
 
std::vector< Clause * > getClauses (const Program &program, const QualifiedName &relationName)
 Returns a vector of clauses in the program describing the relation with the given name. More...
 
std::vector< Clause * > getClauses (const Program &program, const Relation &rel)
 Returns a vector of clauses in the program describing the given relation. More...
 
std::vector< Directive * > getDirectives (const Program &program, const QualifiedName &relationName)
 
const RelationgetHeadRelation (const Clause *clause, const Program *program)
 Returns the relation referenced by the head of the given clause. More...
 
std::vector< const RecordInit * > getRecords (const Node &root)
 Obtains a list of all records referenced within the AST rooted by the given root node. More...
 
RelationgetRelation (const Program &program, const QualifiedName &name)
 Returns the relation with the given name in the program. More...
 
std::vector< const Variable * > getVariables (const Node &root)
 Obtains a list of all variables referenced within the AST rooted by the given root node. More...
 
bool hasClauseWithAggregatedRelation (const Relation *relation, const Relation *aggRelation, const Program *program, const Literal *&foundLiteral)
 Returns whether the given relation has any clauses which contain an aggregation over of a specific relation. More...
 
bool hasClauseWithNegatedRelation (const Relation *relation, const Relation *negRelation, const Program *program, const Literal *&foundLiteral)
 Returns whether the given relation has any clauses which contain a negation of a specific relation. More...
 
bool isDeltaRelation (const QualifiedName &name)
 Returns whether the given atom is a delta relation. More...
 
bool isFact (const Clause &clause)
 Returns whether the given clause is a fact. More...
 
bool isProposition (const Atom *atom)
 Returns whether the given atom is a propositon. More...
 
bool isRecursiveClause (const Clause &clause)
 Returns whether the given clause is recursive. More...
 
bool isRule (const Clause &clause)
 Returns whether the given clause is a rule. More...
 
template<typename Lambda >
detail::LambdaNodeMapper< Lambda > makeLambdaAstMapper (const Lambda &lambda)
 Creates a node mapper based on a corresponding lambda expression. More...
 
void negateConstraintInPlace (Constraint &constraint)
 Negate an ast constraint. More...
 
QualifiedName operator+ (const std::string &name, const QualifiedName &id)
 
std::ostream & operator<< (std::ostream &os, DirectiveType e)
 
std::string pprint (const Node &node)
 
void removeRelation (TranslationUnit &tu, const QualifiedName &name)
 Remove relation and all its clauses from the program. More...
 
void removeRelationClauses (TranslationUnit &tu, const QualifiedName &name)
 Removes the set of clauses with the given relation name. More...
 
void removeRelationIOs (TranslationUnit &tu, const QualifiedName &name)
 Removes the set of IOs with the given relation name. More...
 
bool renameAtoms (Node &node, const std::map< QualifiedName, QualifiedName > &oldToNew)
 Rename all atoms hat appear in a node to a given name. More...
 
ClausereorderAtoms (const Clause *clause, const std::vector< unsigned int > &newOrder)
 Reorders the atoms of a clause to be in the given order. More...
 
IntrinsicFunctors validOverloads (const analysis::TypeAnalysis &, const IntrinsicFunctor &)
 Pick valid overloads for a functor, sorted by some measure of "preference". More...
 
template<typename Lambda , typename R = typename lambda_traits<Lambda>::result_type, typename N = typename lambda_traits<Lambda>::arg0_type>
std::enable_if<!detail::is_ast_visitor< Lambda >::value, void >::type visitDepthFirst (const Node &root, const Lambda &fun)
 A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first pre-order fashion applying the given function to each encountered node. More...
 
template<typename R , typename N >
void visitDepthFirst (const Node &root, const std::function< R(const N &)> &fun)
 A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first pre-order fashion applying the given function to each encountered node. More...
 
template<typename R , typename... Ps, typename... Args>
void visitDepthFirst (const Node &root, Visitor< R, Ps... > &visitor, Args &... args)
 A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first pre-order fashion applying the given visitor to each encountered node. More...
 
template<typename T , typename Lambda >
void visitDepthFirst (const std::vector< T * > &list, const Lambda &fun)
 A utility function visiting all nodes within a given list of AST root nodes recursively in a depth-first pre-order fashion applying the given function to each encountered node. More...
 
template<typename T , typename Lambda >
void visitDepthFirst (const VecOwn< T > &list, const Lambda &fun)
 A utility function visiting all nodes within a given list of AST root nodes recursively in a depth-first pre-order fashion applying the given function to each encountered node. More...
 
template<typename Lambda , typename R = typename lambda_traits<Lambda>::result_type, typename N = typename lambda_traits<Lambda>::arg0_type>
std::enable_if<!detail::is_ast_visitor< Lambda >::value, void >::type visitDepthFirstPostOrder (const Node &root, const Lambda &fun)
 A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first post-order fashion applying the given function to each encountered node. More...
 
template<typename R , typename N >
void visitDepthFirstPostOrder (const Node &root, const std::function< R(const N &)> &fun)
 A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first post-order fashion applying the given function to each encountered node. More...
 
template<typename R , typename... Ps, typename... Args>
void visitDepthFirstPostOrder (const Node &root, Visitor< R, Ps... > &visitor, Args &... args)
 A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first post-order fashion applying the given visitor to each encountered node. More...
 
template<typename R , typename... Ps, typename... Args>
void visitDepthFirstPreOrder (const Node &root, Visitor< R, Ps... > &visitor, Args &... args)
 A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first pre-order fashion applying the given visitor to each encountered node. More...
 

Typedef Documentation

◆ RelationSet

using souffle::ast::RelationSet = typedef std::set<const Relation*, NameComparison>

Relation set.

Definition at line 180 of file Relation.h.

Enumeration Type Documentation

◆ DirectiveType

Enumerator
input 
output 
printsize 
limitsize 

Definition at line 37 of file Directive.h.

37 : return os << "output";

Function Documentation

◆ cloneHead()

Clause * souffle::ast::cloneHead ( const Clause clause)

Returns a clause which contains head of the given clause.

Parameters
clausethe clause which head to be cloned
Returns
pointer to clause which has head cloned from given clause

Definition at line 254 of file Utils.cpp.

258  {
259  // Find all atom positions
260  std::vector<unsigned int> atomPositions;
261  std::vector<Literal*> bodyLiterals = clause->getBodyLiterals();
262  for (unsigned int i = 0; i < bodyLiterals.size(); i++) {

◆ getAtomRelation()

const Relation * souffle::ast::getAtomRelation ( const Atom atom,
const Program program 
)

Returns the relation referenced by the given atom.

Parameters
atomthe atom
programthe program containing the relations
Returns
relation referenced by the atom

Definition at line 129 of file Utils.cpp.

131  {

Referenced by getBodyRelations(), getHeadRelation(), and souffle::ast::transform::ExecutionPlanChecker::transform().

◆ getBodyLiterals()

template<typename T , typename C >
std::vector<T*> souffle::ast::getBodyLiterals ( const C &  clause)

Returns literals of a particular type in the body of a clause.

Parameters
theclause
Returns
vector of body literals of the specified type

Definition at line 87 of file Utils.h.

◆ getBodyRelations()

std::set< const Relation * > souffle::ast::getBodyRelations ( const Clause clause,
const Program program 
)

Returns the relations referenced in the body of the given clause.

Parameters
clausethe clause
programthe program containing the relations
Returns
relation referenced in the clause body

Definition at line 137 of file Utils.cpp.

137  : clause->getHead()->getArguments()) {
139  *arg, [&](const Atom& atom) { bodyRelations.insert(getAtomRelation(&atom, program)); });
140  }
141  return bodyRelations;
142 }
143 
144 size_t getClauseNum(const Program* program, const Clause* clause) {
145  // TODO (azreika): This number might change between the provenance transformer and the AST->RAM
146  // translation. Might need a better way to assign IDs to clauses... (see PR #1288).
147  const Relation* rel = getRelation(*program, clause->getHead()->getQualifiedName());
148  assert(rel != nullptr && "clause relation does not exist");

References getAtomRelation(), and visitDepthFirst().

Here is the call graph for this function:

◆ getClauseNum()

size_t souffle::ast::getClauseNum ( const Program program,
const Clause clause 
)

Returns the index of a clause within its relation, ignoring facts.

Used in provenance as a unique ID for clauses within their relations.

Parameters
programthe program
clausethe clause to get the index of
Returns
the index of the clause ignoring facts; 0 for facts

Definition at line 150 of file Utils.cpp.

151  : getClauses(*program, *rel)) {
152  bool isFact = cur->getBodyLiterals().empty();
153  if (cur == clause) {
154  return isFact ? 0 : clauseNum;
155  }
156 
157  if (!isFact) {
158  clauseNum++;
159  }
160  }
161 
162  fatal("clause does not exist");
163 }
164 
165 bool hasClauseWithNegatedRelation(const Relation* relation, const Relation* negRelation,
166  const Program* program, const Literal*& foundLiteral) {
167  for (const Clause* cl : getClauses(*program, *relation)) {
168  for (const auto* neg : getBodyLiterals<Negation>(*cl)) {
169  if (negRelation == getAtomRelation(neg->getAtom(), program)) {

References isFact().

Here is the call graph for this function:

◆ getClauses() [1/2]

std::vector< Clause * > souffle::ast::getClauses ( const Program program,
const QualifiedName relationName 
)

Returns a vector of clauses in the program describing the relation with the given name.

Parameters
programthe program
namethe name of the relation to search for
Returns
vector of clauses describing the relation with the given name

Definition at line 77 of file Utils.cpp.

81  {
82  return getClauses(program, rel.getQualifiedName());
83 }
84 
85 std::vector<Directive*> getDirectives(const Program& program, const QualifiedName& relationName) {

Referenced by souffle::ast::transform::getInlinedLiteral(), souffle::ast::transform::MagicSetTransformer::getTriviallyIgnoredRelations(), souffle::ast::transform::MinimiseProgramTransformer::reduceLocallyEquivalentClauses(), souffle::ast::transform::MinimiseProgramTransformer::reduceSingletonRelations(), souffle::ast::transform::RemoveEmptyRelationsTransformer::removeEmptyRelations(), souffle::ast::transform::RemoveRelationCopiesTransformer::removeRelationCopies(), and souffle::ast::transform::ExecutionPlanChecker::transform().

◆ getClauses() [2/2]

std::vector< Clause * > souffle::ast::getClauses ( const Program program,
const Relation rel 
)

Returns a vector of clauses in the program describing the given relation.

Parameters
programthe program
relthe relation to search for
Returns
vector of clauses describing the given relation

Definition at line 87 of file Utils.cpp.

87  : program.getDirectives()) {
88  if (dir->getQualifiedName() == relationName) {
89  directives.push_back(dir);

References directives.

◆ getDirectives()

std::vector<Directive*> souffle::ast::getDirectives ( const Program program,
const QualifiedName relationName 
)

Definition at line 91 of file Utils.cpp.

95  {
96  return getIf(program.getRelations(), [&](const Relation* r) { return r->getQualifiedName() == name; });
97 }
98 
99 void removeRelation(TranslationUnit& tu, const QualifiedName& name) {

◆ getHeadRelation()

const Relation * souffle::ast::getHeadRelation ( const Clause clause,
const Program program 
)

Returns the relation referenced by the head of the given clause.

Parameters
clausethe clause
programthe program containing the relations
Returns
relation referenced by the clause head

Definition at line 133 of file Utils.cpp.

133  : clause->getBodyLiterals()) {
135  *lit, [&](const Atom& atom) { bodyRelations.insert(getAtomRelation(&atom, program)); });

References getAtomRelation(), and visitDepthFirst().

Here is the call graph for this function:

◆ getRecords()

std::vector< const RecordInit * > souffle::ast::getRecords ( const Node root)

Obtains a list of all records referenced within the AST rooted by the given root node.

Parameters
rootthe root of the AST to be searched
Returns
a list of all records referenced within

Definition at line 70 of file Utils.cpp.

71  {
72  std::vector<Clause*> clauses;
73  for (Clause* clause : program.getClauses()) {
74  if (clause->getHead()->getQualifiedName() == relationName) {
75  clauses.push_back(clause);

References clauses, and souffle::ast::Program::getClauses().

Here is the call graph for this function:

◆ getRelation()

Relation * souffle::ast::getRelation ( const Program program,
const QualifiedName name 
)

Returns the relation with the given name in the program.

Parameters
programthe program
namethe name of the relation to search for
Returns
the relation if it exists; nullptr otherwise

Definition at line 101 of file Utils.cpp.

101  {
102  removeRelationClauses(tu, name);
103  removeRelationIOs(tu, name);

References removeRelationClauses(), and removeRelationIOs().

Referenced by souffle::ParserDriver::addRelation(), souffle::ast::transform::getInlinedLiteral(), removeRelationIOs(), and souffle::ast::transform::IOAttributesTransformer::transform().

Here is the call graph for this function:

◆ getVariables()

std::vector< const Variable * > souffle::ast::getVariables ( const Node root)

Obtains a list of all variables referenced within the AST rooted by the given root node.

Parameters
rootthe root of the AST to be searched
Returns
a list of all variables referenced within

Definition at line 63 of file Utils.cpp.

64  {
65  // simply collect the list of all records by visiting all records
66  std::vector<const RecordInit*> recs;
67  visitDepthFirst(root, [&](const RecordInit& rec) { recs.push_back(&rec); });
68  return recs;

References visitDepthFirst().

Here is the call graph for this function:

◆ hasClauseWithAggregatedRelation()

bool souffle::ast::hasClauseWithAggregatedRelation ( const Relation relation,
const Relation aggRelation,
const Program program,
const Literal *&  foundLiteral 
)

Returns whether the given relation has any clauses which contain an aggregation over of a specific relation.

Parameters
relationthe relation to search the clauses of
aggRelationthe relation to search for in aggregations in clause bodies
programthe program containing the relations
foundLiteralset to the literal found in an aggregation

Definition at line 184 of file Utils.cpp.

184  {
185  foundLiteral = &atom;
186  hasAgg = true;
187  }
188  });
189  });
190  if (hasAgg) {
191  return true;
192  }
193  }
194  return false;
195 }
196 
197 bool isRecursiveClause(const Clause& clause) {
198  QualifiedName relationName = clause.getHead()->getQualifiedName();
199  bool recursive = false;
200  visitDepthFirst(clause.getBodyLiterals(), [&](const Atom& atom) {
201  if (atom.getQualifiedName() == relationName) {

◆ hasClauseWithNegatedRelation()

bool souffle::ast::hasClauseWithNegatedRelation ( const Relation relation,
const Relation negRelation,
const Program program,
const Literal *&  foundLiteral 
)

Returns whether the given relation has any clauses which contain a negation of a specific relation.

Parameters
relationthe relation to search the clauses of
negRelationthe relation to search for negations of in clause bodies
programthe program containing the relations
foundLiteralset to the negation literal that was found

Definition at line 171 of file Utils.cpp.

179  {
180  for (const Clause* cl : getClauses(*program, *relation)) {
181  bool hasAgg = false;
182  visitDepthFirst(*cl, [&](const Aggregator& cur) {

◆ isDeltaRelation()

bool souffle::ast::isDeltaRelation ( const QualifiedName name)

Returns whether the given atom is a delta relation.

Returns
true iff the atom is a delta relation

Definition at line 246 of file Utils.cpp.

248  {
249  auto* clone = new Clause();
250  clone->setSrcLoc(clause->getSrcLoc());
251  clone->setHead(souffle::clone(clause->getHead()));
252  if (clause->getExecutionPlan() != nullptr) {

◆ isFact()

bool souffle::ast::isFact ( const Clause clause)

Returns whether the given clause is a fact.

Returns
true iff the clause is a fact

Definition at line 214 of file Utils.cpp.

214  {
215  return false;
216  }
217 
218  // and there are no aggregates
219  bool hasAggregatesOrMultiResultFunctor = false;
220  visitDepthFirst(*clause.getHead(), [&](const Argument& arg) {
221  if (isA<Aggregator>(arg)) {
222  hasAggregatesOrMultiResultFunctor = true;
223  }
224 
225  auto* func = as<IntrinsicFunctor>(arg);
226  hasAggregatesOrMultiResultFunctor |=
227  (func != nullptr) && analysis::FunctorAnalysis::isMultiResult(*func);
228  });
229  return !hasAggregatesOrMultiResultFunctor;
230 }
231 
232 bool isRule(const Clause& clause) {
233  return (clause.getHead() != nullptr) && !isFact(clause);
234 }
235 
236 bool isProposition(const Atom* atom) {

Referenced by getClauseNum(), and souffle::ast::transform::RemoveRelationCopiesTransformer::removeRelationCopies().

◆ isProposition()

bool souffle::ast::isProposition ( const Atom atom)

Returns whether the given atom is a propositon.

Returns
true iff the atom has no arguments

Definition at line 242 of file Utils.cpp.

242  {
243  return false;
244  }

◆ isRecursiveClause()

bool souffle::ast::isRecursiveClause ( const Clause clause)

Returns whether the given clause is recursive.

Parameters
clausethe clause to check
Returns
true iff the clause is recursive

Definition at line 203 of file Utils.cpp.

208  {
209  // there must be a head
210  if (clause.getHead() == nullptr) {
211  return false;
212  }

◆ isRule()

bool souffle::ast::isRule ( const Clause clause)

Returns whether the given clause is a rule.

Returns
true iff the clause is a rule

Definition at line 238 of file Utils.cpp.

240  {

◆ makeLambdaAstMapper()

template<typename Lambda >
detail::LambdaNodeMapper<Lambda> souffle::ast::makeLambdaAstMapper ( const Lambda &  lambda)

Creates a node mapper based on a corresponding lambda expression.

Definition at line 53 of file LambdaNodeMapper.h.

◆ negateConstraintInPlace()

void souffle::ast::negateConstraintInPlace ( Constraint constraint)

Negate an ast constraint.

Parameters
constraintconstraint that will be negated

Definition at line 297 of file Utils.cpp.

301  {
302  struct rename_atoms : public NodeMapper {
303  mutable bool changed{false};
304  const std::map<QualifiedName, QualifiedName>& oldToNew;
305  rename_atoms(const std::map<QualifiedName, QualifiedName>& oldToNew) : oldToNew(oldToNew) {}

Referenced by souffle::RuleBody::toClauseBodies().

◆ operator+()

QualifiedName souffle::ast::operator+ ( const std::string &  name,
const QualifiedName id 
)
inline

Definition at line 105 of file QualifiedName.h.

◆ operator<<()

std::ostream& souffle::ast::operator<< ( std::ostream &  os,
DirectiveType  e 
)
inline

Definition at line 40 of file Directive.h.

50  : public Node {

◆ pprint()

std::string souffle::ast::pprint ( const Node node)

Definition at line 59 of file Utils.cpp.

60  { vars.push_back(&var); });
61  return vars;

◆ removeRelation()

void souffle::ast::removeRelation ( TranslationUnit tu,
const QualifiedName name 
)

Remove relation and all its clauses from the program.

Parameters
tuthe translation unit
namethe name of the relation to delete

Definition at line 105 of file Utils.cpp.

108  {
109  Program& program = tu.getProgram();
110  const auto& relDetail = *tu.getAnalysis<analysis::RelationDetailCacheAnalysis>();
111  for (const auto* clause : relDetail.getClauses(name)) {
112  program.removeClause(clause);

Referenced by souffle::ast::transform::RemoveRedundantRelationsTransformer::transform().

◆ removeRelationClauses()

void souffle::ast::removeRelationClauses ( TranslationUnit tu,
const QualifiedName name 
)

Removes the set of clauses with the given relation name.

Parameters
tuthe translation unit
namethe name of the relation to search for

Definition at line 114 of file Utils.cpp.

116  {
117  Program& program = tu.getProgram();
118  for (const auto* directive : getDirectives(program, name)) {
119  program.removeDirective(directive);
120  }

Referenced by getRelation().

◆ removeRelationIOs()

void souffle::ast::removeRelationIOs ( TranslationUnit tu,
const QualifiedName name 
)

Removes the set of IOs with the given relation name.

Parameters
tuthe translation unit
namethe name of the relation to search for

Definition at line 122 of file Utils.cpp.

123  {
124  return getRelation(*program, atom->getQualifiedName());
125 }
126 
127 const Relation* getHeadRelation(const Clause* clause, const Program* program) {

References souffle::ast::Atom::getQualifiedName(), and getRelation().

Referenced by getRelation().

Here is the call graph for this function:

◆ renameAtoms()

bool souffle::ast::renameAtoms ( Node node,
const std::map< QualifiedName, QualifiedName > &  oldToNew 
)

Rename all atoms hat appear in a node to a given name.

Parameters
nodenode to alter the children of
oldToNewmap from old atom names to new atom names
Returns
true if the node was changed

Definition at line 307 of file Utils.cpp.

308  {
309  if (contains(oldToNew, atom->getQualifiedName())) {
310  auto renamedAtom = souffle::clone(atom);
311  renamedAtom->setQualifiedName(oldToNew.at(atom->getQualifiedName()));
312  changed = true;
313  return renamedAtom;
314  }
315  }
316  return node;
317  }
318  };
319  rename_atoms update(oldToNew);
320  node.apply(update);
321  return update.changed;
322 }
323 
324 } // namespace souffle::ast

References souffle::clone(), and souffle::contains().

Here is the call graph for this function:

◆ reorderAtoms()

Clause * souffle::ast::reorderAtoms ( const Clause clause,
const std::vector< unsigned int > &  newOrder 
)

Reorders the atoms of a clause to be in the given order.

Remaining body literals remain in the same order.

E.g. if atoms are [a,b,c] and given order is [1,2,0], then the final atom order will be [b,c,a].

Parameters
clauseclause to reorder atoms in
newOrdernew order of atoms; atoms[i] = atoms[newOrder[i]]

Definition at line 264 of file Utils.cpp.

271  {
272  nopOrder.push_back(i);
273  }
274  assert(std::is_permutation(nopOrder.begin(), nopOrder.end(), newOrder.begin()));
275 
276  // Create a new clause with the given atom order, leaving the rest unchanged
277  Clause* newClause = cloneHead(clause);
278  unsigned int currentAtom = 0;
279  for (unsigned int currentLiteral = 0; currentLiteral < bodyLiterals.size(); currentLiteral++) {
280  Literal* literalToAdd = bodyLiterals[currentLiteral];
281  if (isA<Atom>(literalToAdd)) {
282  // Atoms should be reordered
283  literalToAdd = bodyLiterals[atomPositions[newOrder[currentAtom++]]];
284  }
285  newClause->addToBody(souffle::clone(literalToAdd));
286  }
287 
288  return newClause;
289 }
290 
291 void negateConstraintInPlace(Constraint& constraint) {
292  if (auto* bcstr = dynamic_cast<BooleanConstraint*>(&constraint)) {
293  bcstr->set(!bcstr->isTrue());
294  } else if (auto* cstr = dynamic_cast<BinaryConstraint*>(&constraint)) {
295  cstr->setBaseOperator(souffle::negatedConstraintOp(cstr->getBaseOperator()));

◆ validOverloads()

IntrinsicFunctors souffle::ast::validOverloads ( const analysis::TypeAnalysis ,
const IntrinsicFunctor  
)

Pick valid overloads for a functor, sorted by some measure of "preference".

◆ visitDepthFirst() [1/5]

template<typename Lambda , typename R = typename lambda_traits<Lambda>::result_type, typename N = typename lambda_traits<Lambda>::arg0_type>
std::enable_if<!detail::is_ast_visitor<Lambda>::value, void>::type souffle::ast::visitDepthFirst ( const Node root,
const Lambda &  fun 
)

A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first pre-order fashion applying the given function to each encountered node.

Parameters
rootthe root of the AST to be visited
funthe function to be applied
argsa list of extra parameters to be forwarded to the visitor

Definition at line 343 of file Visitor.h.

References visitDepthFirst().

Here is the call graph for this function:

◆ visitDepthFirst() [2/5]

template<typename R , typename N >
void souffle::ast::visitDepthFirst ( const Node root,
const std::function< R(const N &)> &  fun 
)

A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first pre-order fashion applying the given function to each encountered node.

Parameters
rootthe root of the AST to be visited
funthe function to be applied
argsa list of extra parameters to be forwarded to the visitor

Definition at line 327 of file Visitor.h.

References visitDepthFirst().

Here is the call graph for this function:

◆ visitDepthFirst() [3/5]

template<typename R , typename... Ps, typename... Args>
void souffle::ast::visitDepthFirst ( const Node root,
Visitor< R, Ps... > &  visitor,
Args &...  args 
)

A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first pre-order fashion applying the given visitor to each encountered node.

Parameters
rootthe root of the AST to be visited
visitorthe visitor to be applied on each node
argsa list of extra parameters to be forwarded to the visitor

Definition at line 273 of file Visitor.h.

278  : public Visitor<void> {

References souffle::ast::detail::LambdaVisitor< R, N >::lambda, souffle::ast::detail::LambdaVisitor< R, N >::LambdaVisitor(), n, and souffle::ast::detail::LambdaVisitor< R, N >::visit().

Referenced by souffle::ast::BindingStore::BindingStore(), souffle::ast::transform::SemanticCheckerImpl::checkComplexRule(), souffle::ast::transform::MagicSetTransformer::NormaliseDatabaseTransformer::extractIDB(), souffle::ast::transform::MagicSetTransformer::MagicSetCoreTransformer::getBindingEqualityConstraints(), getBodyRelations(), getHeadRelation(), souffle::ast::transform::MagicSetTransformer::getStronglyIgnoredRelations(), souffle::ast::transform::MagicSetTransformer::getTriviallyIgnoredRelations(), getVariables(), souffle::ast::transform::MaterializeAggregationQueriesTransformer::materializeAggregationQueries(), souffle::ast::transform::MagicSetTransformer::NormaliseDatabaseTransformer::querifyOutputRelations(), souffle::ast::transform::RemoveEmptyRelationsTransformer::removeEmptyRelations(), souffle::ast::transform::SimplifyAggregateTargetExpressionTransformer::transform(), souffle::ast::transform::MaterializeSingletonAggregationTransformer::transform(), souffle::ast::transform::PartitionBodyLiteralsTransformer::transform(), visitDepthFirst(), and souffle::interpreter::NodeGenerator::visitQuery().

Here is the call graph for this function:

◆ visitDepthFirst() [4/5]

template<typename T , typename Lambda >
void souffle::ast::visitDepthFirst ( const std::vector< T * > &  list,
const Lambda &  fun 
)

A utility function visiting all nodes within a given list of AST root nodes recursively in a depth-first pre-order fashion applying the given function to each encountered node.

Parameters
listthe list of roots of the ASTs to be visited
funthe function to be applied
argsa list of extra parameters to be forwarded to the visitor

Definition at line 358 of file Visitor.h.

368  {

References visitDepthFirst().

Here is the call graph for this function:

◆ visitDepthFirst() [5/5]

template<typename T , typename Lambda >
void souffle::ast::visitDepthFirst ( const VecOwn< T > &  list,
const Lambda &  fun 
)

A utility function visiting all nodes within a given list of AST root nodes recursively in a depth-first pre-order fashion applying the given function to each encountered node.

Parameters
listthe list of roots of the ASTs to be visited
funthe function to be applied
argsa list of extra parameters to be forwarded to the visitor

Definition at line 374 of file Visitor.h.

References souffle::ast::detail::makeLambdaVisitor().

Here is the call graph for this function:

◆ visitDepthFirstPostOrder() [1/3]

template<typename Lambda , typename R = typename lambda_traits<Lambda>::result_type, typename N = typename lambda_traits<Lambda>::arg0_type>
std::enable_if<!detail::is_ast_visitor<Lambda>::value, void>::type souffle::ast::visitDepthFirstPostOrder ( const Node root,
const Lambda &  fun 
)

A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first post-order fashion applying the given function to each encountered node.

Parameters
rootthe root of the AST to be visited
funthe function to be applied
argsa list of extra parameters to be forwarded to the visitor

Definition at line 406 of file Visitor.h.

◆ visitDepthFirstPostOrder() [2/3]

template<typename R , typename N >
void souffle::ast::visitDepthFirstPostOrder ( const Node root,
const std::function< R(const N &)> &  fun 
)

A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first post-order fashion applying the given function to each encountered node.

Parameters
rootthe root of the AST to be visited
funthe function to be applied
argsa list of extra parameters to be forwarded to the visitor

Definition at line 390 of file Visitor.h.

References visitDepthFirstPostOrder().

Here is the call graph for this function:

◆ visitDepthFirstPostOrder() [3/3]

template<typename R , typename... Ps, typename... Args>
void souffle::ast::visitDepthFirstPostOrder ( const Node root,
Visitor< R, Ps... > &  visitor,
Args &...  args 
)

A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first post-order fashion applying the given visitor to each encountered node.

Parameters
rootthe root of the AST to be visited
visitorthe visitor to be applied on each node
argsa list of extra parameters to be forwarded to the visitor

Definition at line 254 of file Visitor.h.

267  {

Referenced by visitDepthFirstPostOrder().

◆ visitDepthFirstPreOrder()

template<typename R , typename... Ps, typename... Args>
void souffle::ast::visitDepthFirstPreOrder ( const Node root,
Visitor< R, Ps... > &  visitor,
Args &...  args 
)

A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-first pre-order fashion applying the given visitor to each encountered node.

Parameters
rootthe root of the AST to be visited
visitorthe visitor to be applied on each node
argsa list of extra parameters to be forwarded to the visitor

Definition at line 235 of file Visitor.h.

248  {

Referenced by souffle::ast::Visitor< void >::visitNode().

souffle::ast::cloneHead
Clause * cloneHead(const Clause *clause)
Returns a clause which contains head of the given clause.
Definition: Utils.cpp:254
souffle::ast::removeRelation
void removeRelation(TranslationUnit &tu, const QualifiedName &name)
Remove relation and all its clauses from the program.
Definition: Utils.cpp:105
souffle::ast::removeRelationClauses
void removeRelationClauses(TranslationUnit &tu, const QualifiedName &name)
Removes the set of clauses with the given relation name.
Definition: Utils.cpp:114
souffle::contains
bool contains(const C &container, const typename C::value_type &element)
A utility to check generically whether a given element is contained in a given container.
Definition: ContainerUtil.h:75
souffle::ast::getClauseNum
size_t getClauseNum(const Program *program, const Clause *clause)
Returns the index of a clause within its relation, ignoring facts.
Definition: Utils.cpp:150
relation
Relation & relation
Definition: Reader.h:130
souffle::ast::isFact
bool isFact(const Clause &clause)
Returns whether the given clause is a fact.
Definition: Utils.cpp:214
souffle::ast::getClauses
std::vector< Clause * > getClauses(const Program &program, const Relation &rel)
Returns a vector of clauses in the program describing the given relation.
Definition: Utils.cpp:87
souffle::ast::isRecursiveClause
bool isRecursiveClause(const Clause &clause)
Returns whether the given clause is recursive.
Definition: Utils.cpp:203
souffle::ast::hasClauseWithNegatedRelation
bool hasClauseWithNegatedRelation(const Relation *relation, const Relation *negRelation, const Program *program, const Literal *&foundLiteral)
Returns whether the given relation has any clauses which contain a negation of a specific relation.
Definition: Utils.cpp:171
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
i
size_t i
Definition: json11.h:663
souffle::negatedConstraintOp
BinaryConstraintOp negatedConstraintOp(const BinaryConstraintOp op)
Negated Constraint Operator Each operator requires a negated operator which is necessary for the expa...
Definition: BinaryConstraintOps.h:297
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
clauses
std::vector< Own< Clause > > clauses
Definition: ComponentInstantiation.cpp:67
souffle::ast::getHeadRelation
const Relation * getHeadRelation(const Clause *clause, const Program *program)
Returns the relation referenced by the head of the given clause.
Definition: Utils.cpp:133
souffle::ast::isProposition
bool isProposition(const Atom *atom)
Returns whether the given atom is a propositon.
Definition: Utils.cpp:242
directives
std::vector< Own< Directive > > directives
Definition: ComponentInstantiation.cpp:66
souffle::getIf
C::value_type getIf(const C &container, std::function< bool(const typename C::value_type)> pred)
Returns the first element in a container that satisfies a given predicate, nullptr otherwise.
Definition: ContainerUtil.h:101
souffle::fatal
void fatal(const char *format, const Args &... args)
Definition: MiscUtil.h:198
souffle::ast::negateConstraintInPlace
void negateConstraintInPlace(Constraint &constraint)
Negate an ast constraint.
Definition: Utils.cpp:297
souffle::ast::getAtomRelation
const Relation * getAtomRelation(const Atom *atom, const Program *program)
Returns the relation referenced by the given atom.
Definition: Utils.cpp:129
souffle::ast::visitDepthFirst
void visitDepthFirst(const Node &root, Visitor< R, Ps... > &visitor, Args &... args)
A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-...
Definition: Visitor.h:273
souffle::ast::removeRelationIOs
void removeRelationIOs(TranslationUnit &tu, const QualifiedName &name)
Removes the set of IOs with the given relation name.
Definition: Utils.cpp:122
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ast::getDirectives
std::vector< Directive * > getDirectives(const Program &program, const QualifiedName &relationName)
Definition: Utils.cpp:91
souffle::ast::isRule
bool isRule(const Clause &clause)
Returns whether the given clause is a rule.
Definition: Utils.cpp:238