Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
ExpressionTree.h
Go to the documentation of this file.
1
19#ifndef PYSTON_EXPRESSIONTREE_H
20#define PYSTON_EXPRESSIONTREE_H
21
22#include "Pyston/Graph/Node.h"
23#include <functional>
24
25namespace Pyston {
26
27/*
28 * Declaration to allow for function-like templates
29 */
30template <typename Signature>
32
33template <typename R>
35public:
41 bool isCompiled() const {
42 return m_is_compiled;
43 }
44
49 const Exception* reason() const {
50 return m_reason.get();
51 }
52
58 return m_root;
59 }
60
61protected:
65
66 ExpressionTreeBase(bool compiled, const std::shared_ptr<Node<R>>& root, const std::shared_ptr<Exception>& reason_)
67 : m_is_compiled(compiled), m_root(root), m_reason(reason_) {}
68};
69
78template <typename R, typename T>
79class ExpressionTree<R(const std::vector<T>&)> : public ExpressionTreeBase<R> {
80public:
86 R operator()(const Context& context, const std::vector<T>& args) const {
87 Arguments converted;
88 std::copy(args.begin(), args.end(), std::back_inserter(converted));
89 return m_root->eval(context, converted);
90 }
91
97 R operator()(const std::vector<T>& args) const {
98 Arguments converted;
99 std::copy(args.begin(), args.end(), std::back_inserter(converted));
100 return m_root->eval({}, converted);
101 }
102
103private:
104 using ExpressionTreeBase<R>::m_root;
105
106 ExpressionTree(bool compiled, const std::shared_ptr<Node<R>>& root, const std::shared_ptr<Exception>& reason_)
107 : ExpressionTreeBase<R>(compiled, root, reason_) {}
108
110};
111
119template <typename R, typename... Args>
120class ExpressionTree<R(Args...)> : public ExpressionTreeBase<R> {
121public:
127 R operator()(const Context& context, const Args&... args) const {
128 return m_root->eval(context, args...);
129 }
130
136 R operator()(const Args&... args) const {
137 return m_root->eval(Context{}, args...);
138 }
139
140private:
141 using ExpressionTreeBase<R>::m_root;
142
143 ExpressionTree(bool compiled, const std::shared_ptr<Node<R>>& root, const std::shared_ptr<Exception>& reason_)
144 : ExpressionTreeBase<R>(compiled, root, reason_) {}
145
147};
148
149} // end of namespace Pyston
150
151#endif // PYSTON_EXPRESSIONTREE_H
T back_inserter(T... args)
T begin(T... args)
std::shared_ptr< Exception > m_reason
ExpressionTreeBase(bool compiled, const std::shared_ptr< Node< R > > &root, const std::shared_ptr< Exception > &reason_)
const std::shared_ptr< Node< R > > & getTree() const
const Exception * reason() const
std::shared_ptr< Node< R > > m_root
R operator()(const Context &context, const Args &... args) const
ExpressionTree(bool compiled, const std::shared_ptr< Node< R > > &root, const std::shared_ptr< Exception > &reason_)
R operator()(const Args &... args) const
ExpressionTree(bool compiled, const std::shared_ptr< Node< R > > &root, const std::shared_ptr< Exception > &reason_)
R operator()(const Context &context, const std::vector< T > &args) const
R operator()(const std::vector< T > &args) const
T copy(T... args)
T end(T... args)
STL namespace.