souffle  2.0.2-371-g6315b36
AbstractLog.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2017, 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 AbstractLog.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Node.h"
18 #include "ram/Statement.h"
19 #include "ram/utility/NodeMapper.h"
21 #include <cassert>
22 #include <memory>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 namespace souffle::ram {
28 
29 /**
30  * @class AbstractLog
31  * @brief Abstract class for logging
32  *
33  * Comprises a Statement and the message (string) to be logged
34  */
35 class AbstractLog {
36 public:
37  AbstractLog(Own<Statement> stmt, std::string msg) : statement(std::move(stmt)), message(std::move(msg)) {
38  assert(statement && "log statement is a nullptr");
39  }
40 
41  std::vector<const Node*> getChildNodes() const {
42  return {statement.get()};
43  }
44 
45  /** @brief Get logging message */
46  const std::string& getMessage() const {
47  return message;
48  }
49 
50  /** @brief Get logging statement */
51  const Statement& getStatement() const {
52  return *statement;
53  }
54 
55  void apply(const NodeMapper& map) {
56  statement = map(std::move(statement));
57  }
58 
59 protected:
60  bool equal(const Node& node) const {
61  const auto& other = dynamic_cast<const AbstractLog&>(node);
62  return equal_ptr(statement, other.statement) && message == other.message;
63  }
64 
65 protected:
66  /** Logging statement */
68 
69  /** Logging message */
70  const std::string message;
71 };
72 
73 } // namespace souffle::ram
souffle::ram::AbstractLog
Abstract class for logging.
Definition: AbstractLog.h:39
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::map
auto map(const std::vector< A > &xs, F &&f)
Applies a function to each element of a vector and returns the results.
Definition: ContainerUtil.h:158
souffle::ram::AbstractLog::apply
void apply(const NodeMapper &map)
Definition: AbstractLog.h:59
souffle::ram::AbstractLog::message
const std::string message
Logging message.
Definition: AbstractLog.h:74
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::AbstractLog::equal
bool equal(const Node &node) const
Definition: AbstractLog.h:64
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
NodeMapper.h
souffle::ram::NodeMapper
An abstract class for manipulating RAM Nodes by substitution.
Definition: NodeMapper.h:38
ContainerUtil.h
souffle::ram::AbstractLog::getStatement
const Statement & getStatement() const
Get logging statement.
Definition: AbstractLog.h:55
souffle::ram::AbstractLog::AbstractLog
AbstractLog(Own< Statement > stmt, std::string msg)
Definition: AbstractLog.h:41
souffle::equal_ptr
bool equal_ptr(const T *a, const T *b)
Compares two values referenced by a pointer where the case where both pointers are null is also consi...
Definition: MiscUtil.h:130
souffle::ram::Statement
Abstract class for RAM statements.
Definition: Statement.h:37
Node.h
std
Definition: Brie.h:3053
souffle::ram::AbstractLog::getMessage
const std::string & getMessage() const
Get logging message.
Definition: AbstractLog.h:50
Statement.h
souffle::ram::AbstractLog::getChildNodes
std::vector< const Node * > getChildNodes() const
Definition: AbstractLog.h:45
souffle::ram::AbstractLog::statement
Own< Statement > statement
Logging statement.
Definition: AbstractLog.h:71