OPAL (Object Oriented Parallel Accelerator Library)  2024.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/phoenix/core.hpp>
15 #include <boost/phoenix/function.hpp>
16 #include <boost/phoenix/operator.hpp>
17 
18 namespace client { namespace code_gen
19 {
20  struct requirements
21  {
22  typedef bool result_type;
23 
24  template <typename ErrorHandler>
25  requirements(ErrorHandler& error_handler_)
26  {
27  namespace phx = boost::phoenix;
29 
30  error_handler = function<ErrorHandler>(error_handler_)
31  (std::string("Error! "),
32  phx::arg_names::_2,
33  phx::cref(error_handler_.iters)[phx::arg_names::_1]);
34  }
35 
36  bool operator()(ast::nil) { BOOST_ASSERT(0); return false; }
37  bool operator()(unsigned int /*x*/) { return true; }
38  bool operator()(double /*x*/) { return true; }
39  bool operator()(bool /*x*/) { return true; }
40  bool operator()(ast::quoted_string const & /*x*/) { return true; }
41 
42  bool operator()(ast::operation const& x) {
43  if (!boost::apply_visitor(*this, x.operand_))
44  return false;
45  return true;
46  }
47 
48  bool operator()(ast::unary const& x) {
49  if (!boost::apply_visitor(*this, x.operand_))
50  return false;
51  return true;
52  }
53 
54  bool operator()(ast::identifier const& x) {
55  variables_.insert(x.name);
56 
57  return true;
58  }
59 
60  bool operator()(ast::function_call const& x) {
61  functions_.insert(x.function_name.name);
62 
63  for(ast::function_call_argument const& arg: x.args) {
64  if (!boost::apply_visitor(*this, arg))
65  return false;
66  //if (!(*this)(arg))
67  //return false;
68  }
69  return true;
70  }
71 
72  bool operator()(ast::expression const& x) {
73 
74  if (!boost::apply_visitor(*this, x.first))
75  return false;
76 
77  for(ast::operation const& oper: x.rest) {
78  if (!(*this)(oper))
79  return false;
80  }
81 
82  return true;
83  }
84 
85  std::set<std::string> variables() { return variables_; }
86  std::set<std::string> functions() { return functions_; }
87 
88  private:
89 
91  void(int tag, std::string const& what)>
93 
94  std::set<std::string> variables_;
95  std::set<std::string> functions_;
96  };
97 }}
98 
99 #endif
100 
bool operator()(unsigned int)
arg(a))
boost::function< void(int tag, std::string const &what)> error_handler
std::set< std::string > functions()
operand operand_
Definition: ast.hpp:83
bool operator()(ast::quoted_string const &)
bool operator()(ast::function_call const &x)
bool operator()(ast::identifier const &x)
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE:162
std::set< std::string > variables_
bool operator()(ast::unary const &x)
boost::variant< expression, quoted_string > function_call_argument
Definition: ast.hpp:59
identifier function_name
Definition: ast.hpp:94
double function(PyOpalObjectNS::PyOpalObject< C > pyobject, double t)
bool operator()(ast::expression const &x)
bool operator()(ast::operation const &x)
std::set< std::string > functions_
std::set< std::string > variables()
requirements(ErrorHandler &error_handler_)
std::list< function_call_argument > args
Definition: ast.hpp:95
std::string name
Definition: ast.hpp:34
std::list< operation > rest
Definition: ast.hpp:101
operand operand_
Definition: ast.hpp:89