OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
requirements.hpp
Go to the documentation of this file.
1//
2// Namespace requirements
3//
4// Copyright (c) 2026, Paul Scherrer Institute, Villigen PSI, Switzerland
5// All rights reserved
6//
7// This file is part of OPAL.
8//
9// OPAL is free software: you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// You should have received a copy of the GNU General Public License
15// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
16//
17#ifndef REQUIREMENTS_HPP
18#define REQUIREMENTS_HPP
19
20#include "ast.hpp"
21
22#include <cassert>
23#include <set>
24
25namespace client { namespace code_gen
26{
28 {
29 typedef bool result_type;
30
31 template <typename ErrorHandler>
32 requirements(ErrorHandler&)
33 {
34 }
35
36 bool operator()(ast::nil) { assert(false); 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 (!ast::apply_visitor(*this, x.operand_))
44 return false;
45 return true;
46 }
47
48 bool operator()(ast::unary const& x) {
49 if (!ast::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 (!ast::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 (!ast::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 std::set<std::string> variables_;
90 std::set<std::string> functions_;
91 };
92}}
93
94#endif
arg(a))
decltype(auto) apply_visitor(Visitor &&vis, Variant &&var)
Definition ast.hpp:76
std::variant< expression, quoted_string > function_call_argument
Definition ast.hpp:130
std::string name
Definition ast.hpp:105
operand operand_
Definition ast.hpp:154
std::list< function_call_argument > args
Definition ast.hpp:166
identifier function_name
Definition ast.hpp:165
std::list< operation > rest
Definition ast.hpp:172
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_