souffle  2.0.2-371-g6315b36
Break.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. 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 Break.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
18 #include "ram/Condition.h"
19 #include "ram/NestedOperation.h"
20 #include "ram/Node.h"
21 #include "ram/Operation.h"
24 #include <iosfwd>
25 #include <memory>
26 #include <ostream>
27 #include <string>
28 #include <utility>
29 
30 namespace souffle::ram {
31 
32 /**
33  * @class Break
34  * @brief Breaks out of the loop if a condition holds
35  *
36  * The following example will break out of the inner-most
37  * loop if the condition (t1.1 = 4) holds:
38  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
39  * FOR t0 in A
40  * FOR t1 in B
41  * IF t0.1 = 4 BREAK
42  * ...
43  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
44  */
45 class Break : public AbstractConditional {
46 public:
47  Break(Own<Condition> cond, Own<Operation> nested, std::string profileText = "")
48  : AbstractConditional(std::move(cond), std::move(nested), std::move(profileText)) {}
49 
50  Break* clone() const override {
52  }
53 
54 protected:
55  void print(std::ostream& os, int tabpos) const override {
56  os << times(" ", tabpos);
57  os << "IF " << getCondition() << " BREAK" << std::endl;
58  NestedOperation::print(os, tabpos + 1);
59  }
60 };
61 
62 } // namespace souffle::ram
souffle::ram::Break
Breaks out of the loop if a condition holds.
Definition: Break.h:49
souffle::ram::NestedOperation::profileText
const std::string profileText
Text used by the profiler.
Definition: NestedOperation.h:93
NestedOperation.h
souffle::ram::AbstractConditional::AbstractConditional
AbstractConditional(Own< Condition > cond, Own< Operation > nested, std::string profileText="")
Definition: AbstractConditional.h:41
souffle::ram::NestedOperation::getOperation
Operation & getOperation() const
Get nested operation.
Definition: NestedOperation.h:62
MiscUtil.h
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::Break::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: Break.h:59
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
souffle::ram::Break::clone
Break * clone() const override
Create a clone (i.e.
Definition: Break.h:54
souffle::times
detail::multiplying_printer< T > times(const T &value, unsigned num)
A utility printing a given value multiple times.
Definition: StreamUtil.h:322
souffle::ram::NestedOperation::getProfileText
const std::string & getProfileText() const
Get profile text.
Definition: NestedOperation.h:67
Condition.h
souffle::ram::AbstractConditional::getCondition
const Condition & getCondition() const
Get condition that must be satisfied.
Definition: AbstractConditional.h:49
souffle::ram::Break::Break
Break(Own< Condition > cond, Own< Operation > nested, std::string profileText="")
Definition: Break.h:51
Node.h
std
Definition: Brie.h:3053
Operation.h
StreamUtil.h
AbstractConditional.h
souffle::ram::AbstractConditional::condition
Own< Condition > condition
Condition.
Definition: AbstractConditional.h:72
souffle::ram::NestedOperation::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: NestedOperation.h:80