Alexandria  2.27.0
SDC-CH common library for the Euclid project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
25 namespace Pyston {
26 
27 /*
28  * Declaration to allow for function-like templates
29  */
30 template <typename Signature>
32 
33 template <typename R>
35 public:
41  bool isCompiled() const {
42  return m_is_compiled;
43  }
44 
49  const Exception* reason() const {
50  return m_reason.get();
51  }
52 
57  const std::shared_ptr<Node<R>>& getTree() const {
58  return m_root;
59  }
60 
61 protected:
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 
78 template <typename R, typename T>
79 class ExpressionTree<R(const std::vector<T>&)> : public ExpressionTreeBase<R> {
80 public:
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 
103 private:
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 
109  friend class ExpressionTreeBuilder;
110 };
111 
119 template <typename R, typename... Args>
120 class ExpressionTree<R(Args...)> : public ExpressionTreeBase<R> {
121 public:
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 
140 private:
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 
146  friend class ExpressionTreeBuilder;
147 };
148 
149 } // end of namespace Pyston
150 
151 #endif // PYSTON_EXPRESSIONTREE_H
T copy(T...args)
R operator()(const Context &context, const Args &...args) const
const std::shared_ptr< Node< R > > & getTree() const
std::shared_ptr< Node< R > > m_root
T end(T...args)
STL class.
ExpressionTree(bool compiled, const std::shared_ptr< Node< R >> &root, const std::shared_ptr< Exception > &reason_)
R operator()(const std::vector< T > &args) const
R operator()(const Context &context, const std::vector< T > &args) const
ExpressionTreeBase(bool compiled, const std::shared_ptr< Node< R >> &root, const std::shared_ptr< Exception > &reason_)
STL class.
T begin(T...args)
T back_inserter(T...args)
R operator()(const Args &...args) const
std::shared_ptr< Exception > m_reason
const Exception * reason() const
ExpressionTree(bool compiled, const std::shared_ptr< Node< R >> &root, const std::shared_ptr< Exception > &reason_)