souffle  2.0.2-371-g6315b36
Fixpoint.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2018, The Souffle Developers. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file Fixpoint.h
12  *
13  * Transformer that repeatedly executes a sub-transformer until no changes are made
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/TranslationUnit.h"
21 #include "ast/transform/Meta.h"
22 #include "ast/transform/Null.h"
25 #include <memory>
26 #include <set>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 namespace souffle::ast::transform {
32 
33 /**
34  * Transformer that repeatedly executes a sub-transformer until no changes are made
35  */
36 class FixpointTransformer : public MetaTransformer {
37 public:
38  FixpointTransformer(Own<Transformer> transformer) : transformer(std::move(transformer)) {}
39 
40  void setDebugReport() override {
41  if (auto* mt = dynamic_cast<MetaTransformer*>(transformer.get())) {
42  mt->setDebugReport();
43  } else {
44  transformer = mk<DebugReporter>(std::move(transformer));
45  }
46  }
47 
48  std::vector<Transformer*> getSubtransformers() const override {
49  return {transformer.get()};
50  }
51 
52  void setVerbosity(bool verbose) override {
53  this->verbose = verbose;
54  if (auto* mt = dynamic_cast<MetaTransformer*>(transformer.get())) {
55  mt->setVerbosity(verbose);
56  }
57  }
58 
59  void disableTransformers(const std::set<std::string>& transforms) override {
60  if (auto* mt = dynamic_cast<MetaTransformer*>(transformer.get())) {
61  mt->disableTransformers(transforms);
62  } else if (transforms.find(transformer->getName()) != transforms.end()) {
63  transformer = mk<NullTransformer>();
64  }
65  }
66 
67  std::string getName() const override {
68  return "FixpointTransformer";
69  }
70 
71  FixpointTransformer* clone() const override {
73  }
74 
75 private:
77  bool transform(TranslationUnit& translationUnit) override {
78  bool changed = false;
79  while (applySubtransformer(translationUnit, transformer.get())) {
80  changed = true;
81  }
82  return changed;
83  }
84 };
85 
86 } // namespace souffle::ast::transform
TranslationUnit.h
souffle::ast::transform::MetaTransformer
Transformer that coordinates other sub-transformations.
Definition: Meta.h:36
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
MiscUtil.h
Transformer.h
souffle::ast::transform::FixpointTransformer::getName
std::string getName() const override
Definition: Fixpoint.h:79
Null.h
souffle::ast::transform::FixpointTransformer::setDebugReport
void setDebugReport() override
Definition: Fixpoint.h:52
souffle::ast::transform::FixpointTransformer::setVerbosity
void setVerbosity(bool verbose) override
Definition: Fixpoint.h:64
souffle::ast::transform::FixpointTransformer::disableTransformers
void disableTransformers(const std::set< std::string > &transforms) override
Definition: Fixpoint.h:71
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
souffle::ast::transform::MetaTransformer::verbose
bool verbose
Definition: Meta.h:44
souffle::ast::transform::FixpointTransformer::transformer
Own< Transformer > transformer
Definition: Fixpoint.h:88
souffle::ast::TranslationUnit
Translation unit class for the translation pipeline.
Definition: TranslationUnit.h:51
souffle::ast::transform
Definition: Program.h:45
souffle::ast::transform::FixpointTransformer::FixpointTransformer
FixpointTransformer(Own< Transformer > transformer)
Definition: Fixpoint.h:50
souffle::ast::transform::FixpointTransformer::getSubtransformers
std::vector< Transformer * > getSubtransformers() const override
Definition: Fixpoint.h:60
souffle::ast::transform::FixpointTransformer::clone
FixpointTransformer * clone() const override
Definition: Fixpoint.h:83
DebugReporter.h
std
Definition: Brie.h:3053
souffle::ast::transform::FixpointTransformer
Transformer that repeatedly executes a sub-transformer until no changes are made.
Definition: Fixpoint.h:42
souffle::ast::transform::FixpointTransformer::transform
bool transform(TranslationUnit &translationUnit) override
Definition: Fixpoint.h:89
souffle::ast::transform::MetaTransformer::applySubtransformer
bool applySubtransformer(TranslationUnit &translationUnit, Transformer *transformer)
Definition: Meta.cpp:30
Meta.h