OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
requirements.hpp
Go to the documentation of this file.
1/*=============================================================================
2 Adapted from boost spirit mini_c example.
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6=============================================================================*/
7#if !defined(REQUIREMENTS_HPP)
8#define REQUIREMENTS_HPP
9
10#include "ast.hpp"
11#include "error_handler.hpp"
12#include <set>
13#include <boost/function.hpp>
14#include <boost/shared_ptr.hpp>
15#include <boost/spirit/include/phoenix_core.hpp>
16#include <boost/spirit/include/phoenix_function.hpp>
17#include <boost/spirit/include/phoenix_operator.hpp>
18
19namespace client { namespace code_gen
20{
22 {
23 typedef bool result_type;
24
25 template <typename ErrorHandler>
26 requirements(ErrorHandler& error_handler_)
27 {
28 namespace phx = boost::phoenix;
30
31 error_handler = function<ErrorHandler>(error_handler_)
32 (std::string("Error! "),
33 phx::arg_names::_2,
34 phx::cref(error_handler_.iters)[phx::arg_names::_1]);
35 }
36
37 bool operator()(ast::nil) { BOOST_ASSERT(0); return false; }
38 bool operator()(unsigned int /*x*/) { return true; }
39 bool operator()(double /*x*/) { return true; }
40 bool operator()(bool /*x*/) { return true; }
41 bool operator()(ast::quoted_string const & /*x*/) { return true; }
42
43 bool operator()(ast::operation const& x) {
44 if (!boost::apply_visitor(*this, x.operand_))
45 return false;
46 return true;
47 }
48
49 bool operator()(ast::unary const& x) {
50 if (!boost::apply_visitor(*this, x.operand_))
51 return false;
52 return true;
53 }
54
55 bool operator()(ast::identifier const& x) {
56 variables_.insert(x.name);
57
58 return true;
59 }
60
63
64 for(ast::function_call_argument const& arg: x.args) {
65 if (!boost::apply_visitor(*this, arg))
66 return false;
67 //if (!(*this)(arg))
68 //return false;
69 }
70 return true;
71 }
72
73 bool operator()(ast::expression const& x) {
74
75 if (!boost::apply_visitor(*this, x.first))
76 return false;
77
78 for(ast::operation const& oper: x.rest) {
79 if (!(*this)(oper))
80 return false;
81 }
82
83 return true;
84 }
85
86 std::set<std::string> variables() { return variables_; }
87 std::set<std::string> functions() { return functions_; }
88
89 private:
90
92 void(int tag, std::string const& what)>
94
95 std::set<std::string> variables_;
96 std::set<std::string> functions_;
97 };
98}}
99
100#endif
101
arg(a))
py::list function(PolynomialPatch *patch, py::list point)
boost::variant< expression, quoted_string > function_call_argument
Definition: ast.hpp:59
std::string name
Definition: ast.hpp:34
operand operand_
Definition: ast.hpp:83
operand operand_
Definition: ast.hpp:89
std::list< function_call_argument > args
Definition: ast.hpp:95
identifier function_name
Definition: ast.hpp:94
std::list< operation > rest
Definition: ast.hpp:101
requirements(ErrorHandler &error_handler_)
std::set< std::string > variables()
bool operator()(ast::expression const &x)
bool operator()(ast::identifier const &x)
bool operator()(ast::operation const &x)
bool operator()(ast::quoted_string const &)
std::set< std::string > functions_
bool operator()(unsigned int)
bool operator()(ast::function_call const &x)
bool operator()(ast::unary const &x)
std::set< std::string > functions()
std::set< std::string > variables_
boost::function< void(int tag, std::string const &what)> error_handler