OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
annotation.hpp
Go to the documentation of this file.
1//
2// Namespace annotation
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 ANNOTATION_HPP
18#define ANNOTATION_HPP
19
20#include <vector>
21
22#include "ast.hpp"
23
24namespace client
25{
27 // The annotation handler links the AST to a map of iterator positions
28 // for the purpose of subsequent semantic error handling when the
29 // program is being compiled.
31 template <typename Iterator>
33 {
34 template <typename>
35 struct result { typedef void type; };
36
37 std::vector<Iterator>& iters;
38 annotation(std::vector<Iterator>& iters)
39 : iters(iters) {}
40
41 struct set_id
42 {
43 typedef void result_type;
44
45 int id;
46 set_id(int id) : id(id) {}
47
49 {
51 }
52
54 {
55 x.id = id;
56 }
57
58 template <typename T>
59 void operator()(T& /*x*/) const
60 {
61 // no-op
62 }
63 };
64
65 void operator()(ast::operand& ast, Iterator pos) const
66 {
67 int id = iters.size();
68 iters.push_back(pos);
69 ast::apply_visitor(set_id(id), ast);
70 }
71
72 void operator()(ast::identifier& ast, Iterator pos) const
73 {
74 int id = iters.size();
75 iters.push_back(pos);
76 ast.id = id;
77 }
78 };
79}
80
81#endif
decltype(auto) apply_visitor(Visitor &&vis, Variant &&var)
Definition ast.hpp:76
std::variant< nil, bool, unsigned int, double, identifier, recursive_wrapper< unary >, recursive_wrapper< function_call >, recursive_wrapper< expression > > operand
Definition ast.hpp:124
void operator()(ast::operand &ast, Iterator pos) const
void operator()(ast::identifier &ast, Iterator pos) const
std::vector< Iterator > & iters
annotation(std::vector< Iterator > &iters)
void operator()(ast::identifier &x) const
void operator()(T &) const
void operator()(ast::function_call &x) const
identifier function_name
Definition ast.hpp:165