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

Transformation pass to replace unnamed variables with singletons. More...

#include <NameUnnamedVariables.h>

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

Public Member Functions

NameUnnamedVariablesTransformerclone () 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 replace unnamed variables with singletons.

E.g.: a() :- b(_). -> a() :- b(x).

Definition at line 40 of file NameUnnamedVariables.h.

Member Function Documentation

◆ clone()

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

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

Definition at line 54 of file NameUnnamedVariables.h.

◆ getName()

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

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

Definition at line 50 of file NameUnnamedVariables.h.

◆ transform()

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

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

Definition at line 36 of file NameUnnamedVariables.cpp.

37  : public NodeMapper {
38  mutable bool changed = false;
39  nameVariables() = default;
40 
41  Own<Node> operator()(Own<Node> node) const override {
42  if (isA<UnnamedVariable>(node.get())) {
43  changed = true;
44  std::stringstream name;
45  name << boundPrefix << "_" << underscoreCount++;
46  return mk<ast::Variable>(name.str());
47  }
48  node->apply(*this);
49  return node;
50  }
51  };
52 
53  Program& program = translationUnit.getProgram();
54  for (Relation* rel : program.getRelations()) {
55  for (Clause* clause : getClauses(program, *rel)) {
56  nameVariables update;
57  clause->apply(update);
58  changed |= update.changed;
59  }
60  }
61 
62  return changed;
63 }
64 
65 } // namespace souffle::ast::transform

The documentation for this class was generated from the following files:
souffle::ast::getClauses
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.
Definition: Utils.cpp:77
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086