OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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
18namespace client { namespace code_gen
19{
21 {
22 typedef bool result_type;
23
24 template <typename ErrorHandler>
25 requirements(ErrorHandler& error_handler_)
26 {
27 namespace phx = boost::phoenix;
28 using boost::phoenix::function;
29
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
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
90 boost::function<
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
arg(a))
std::list< function_call_argument > args
boost::variant< expression, quoted_string > function_call_argument
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()(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