souffle  2.0.2-371-g6315b36
LambdaNodeMapper.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 LambdaNodeMapper.h
12  *
13  * Defines lambda node mappers class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/utility/NodeMapper.h"
20 #include <memory>
21 #include <utility>
22 
23 namespace souffle::ast {
24 
25 namespace detail {
26 
27 /**
28  * A special NodeMapper wrapping a lambda conducting node transformations.
29  */
30 template <typename Lambda>
31 class LambdaNodeMapper : public NodeMapper {
32  const Lambda& lambda;
33 
34 public:
35  LambdaNodeMapper(const Lambda& lambda) : lambda(lambda) {}
36 
37  Own<Node> operator()(Own<Node> node) const override {
38  return lambda(std::move(node));
39  }
40 };
41 } // namespace detail
42 
43 /**
44  * Creates a node mapper based on a corresponding lambda expression.
45  */
46 template <typename Lambda>
48  return detail::LambdaNodeMapper<Lambda>(lambda);
49 }
50 
51 } // namespace souffle::ast
souffle::ast::detail::LambdaNodeMapper::LambdaNodeMapper
LambdaNodeMapper(const Lambda &lambda)
Definition: LambdaNodeMapper.h:53
souffle::ast::NodeMapper
An abstract class for manipulating AST Nodes by substitution.
Definition: NodeMapper.h:36
souffle::ast::detail::LambdaNodeMapper::lambda
const Lambda & lambda
Definition: LambdaNodeMapper.h:50
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::ast::makeLambdaAstMapper
detail::LambdaNodeMapper< Lambda > makeLambdaAstMapper(const Lambda &lambda)
Creates a node mapper based on a corresponding lambda expression.
Definition: LambdaNodeMapper.h:53
souffle::ast::detail::LambdaNodeMapper::operator()
Own< Node > operator()(Own< Node > node) const override
Abstract replacement method for a node.
Definition: LambdaNodeMapper.h:55
NodeMapper.h
souffle::ast
Definition: Aggregator.h:35
souffle::ast::detail::LambdaNodeMapper
A special NodeMapper wrapping a lambda conducting node transformations.
Definition: LambdaNodeMapper.h:43