souffle  2.0.2-371-g6315b36
NodeMapper.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2015, 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 NodeMapper.h
12  *
13  * Declaration of RAM node and mappers for RAM nodes
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
21 #include <cassert>
22 #include <memory>
23 
24 namespace souffle::ram {
25 
26 class Node;
27 
28 /**
29  * @class NodeMapper
30  * @brief An abstract class for manipulating RAM Nodes by substitution
31  */
32 class NodeMapper {
33 public:
34  virtual ~NodeMapper() = default;
35 
36  /**
37  * @brief Abstract replacement method for a node.
38  *
39  * If the given nodes is to be replaced, the handed in node
40  * will be destroyed by the mapper and the returned node
41  * will become owned by the caller.
42  */
43  virtual Own<Node> operator()(Own<Node> node) const = 0;
44 
45  /**
46  * @brief Wrapper for any subclass of the RAM node hierarchy performing type casts.
47  */
48  template <typename T>
49  Own<T> operator()(Own<T> node) const {
50  Own<Node> resPtr = (*this)(Own<Node>(static_cast<Node*>(node.release())));
51  assert(isA<T>(resPtr.get()) && "Invalid target node!");
52  return Own<T>(dynamic_cast<T*>(resPtr.release()));
53  }
54 };
55 
56 } // namespace souffle::ram
souffle::ram::NodeMapper::operator()
virtual Own< Node > operator()(Own< Node > node) const =0
Abstract replacement method for a node.
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
MiscUtil.h
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
ContainerUtil.h
souffle::ram::NodeMapper::~NodeMapper
virtual ~NodeMapper()=default