souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions
souffle::ram::transform::TupleIdTransformer Class Reference

Ordering tupleIds in TupleOperation operations correctly. More...

#include <TupleId.h>

Inheritance diagram for souffle::ram::transform::TupleIdTransformer:
Inheritance graph
Collaboration diagram for souffle::ram::transform::TupleIdTransformer:
Collaboration graph

Public Member Functions

std::string getName () const override
 @Brief get name of the transformer More...
 
bool reorderOperations (Program &program)
 Apply tupleId reordering to the whole program. More...
 
- Public Member Functions inherited from souffle::ram::transform::Transformer
bool apply (TranslationUnit &translationUnit)
 @Brief apply the transformer to a translation unit @Param translationUnit that will be transformed. More...
 
virtual ~Transformer ()=default
 

Protected Member Functions

bool transform (TranslationUnit &translationUnit) override
 @Brief transform the translation unit / used by apply @Param translationUnit that will be transformed. More...
 

Detailed Description

Ordering tupleIds in TupleOperation operations correctly.

Transformations, like MakeIndex and IfConversion do not ensure that TupleOperations maintain an appropriate order with respect to their tupleId's

For example: SEARCH ... (tupleId = 2) ... SEARCH ... (tupleId = 1) ...

Will be converted to SEARCH ... (tupleId = 0) ... SEARCH ... (tupleId = 1) ...

Definition at line 49 of file TupleId.h.

Member Function Documentation

◆ getName()

std::string souffle::ram::transform::TupleIdTransformer::getName ( ) const
inlineoverridevirtual

@Brief get name of the transformer

Implements souffle::ram::transform::Transformer.

Definition at line 51 of file TupleId.h.

60  :
61  bool transform(TranslationUnit& translationUnit) override {

◆ reorderOperations()

bool souffle::ram::transform::TupleIdTransformer::reorderOperations ( Program program)

Apply tupleId reordering to the whole program.

Parameters
RAMprogram
Returns
A flag indicating whether the RAM program has been changed.

Search for TupleOperations and TupleElements and rewrite their tupleIds

Definition at line 33 of file TupleId.cpp.

36  {
37  if (ctr != search.getTupleId()) {
38  changed = true;
39  }
40  reorder[search.getTupleId()] = ctr;
41  const_cast<TupleOperation*>(&search)->setTupleId(ctr);
42  ctr++;
43  });
44 
45  std::function<Own<Node>(Own<Node>)> elementRewriter = [&](Own<Node> node) -> Own<Node> {
46  if (auto* element = dynamic_cast<TupleElement*>(node.get())) {
47  if (reorder[element->getTupleId()] != element->getTupleId()) {
48  changed = true;
49  node = mk<TupleElement>(reorder[element->getTupleId()], element->getElement());
50  }
51  }
52  node->apply(makeLambdaRamMapper(elementRewriter));
53  return node;
54  };
55  const_cast<Query*>(&query)->apply(makeLambdaRamMapper(elementRewriter));
56  });
57 
58  return changed;
59 }
60 
61 } // namespace souffle::ram::transform

References souffle::ram::TupleOperation::getTupleId(), and souffle::ram::TupleOperation::setTupleId().

Here is the call graph for this function:

◆ transform()

bool souffle::ram::transform::TupleIdTransformer::transform ( TranslationUnit translationUnit)
inlineoverrideprotectedvirtual

@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed.

@Return flag reporting whether the RAM program has changed

Implements souffle::ram::transform::Transformer.

Definition at line 65 of file TupleId.h.


The documentation for this class was generated from the following files:
souffle::ram::transform::Transformer::apply
bool apply(TranslationUnit &translationUnit)
@Brief apply the transformer to a translation unit @Param translationUnit that will be transformed.
Definition: Transformer.cpp:39
souffle::ram::transform::TupleIdTransformer::transform
bool transform(TranslationUnit &translationUnit) override
@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed...
Definition: TupleId.h:65
souffle::ram::makeLambdaRamMapper
LambdaNodeMapper< Lambda > makeLambdaRamMapper(const Lambda &lambda)
Creates a node mapper based on a corresponding lambda expression.
Definition: LambdaNodeMapper.h:67