OPAL (Object Oriented Parallel Accelerator Library)
2024.2
OPAL
optimizer
Expression
Parser
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
24
namespace
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>
32
struct
annotation
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
48
void
operator()
(
ast::function_call
& x)
const
49
{
50
x.
function_name
.
id
=
id
;
51
}
52
53
void
operator()
(
ast::identifier
& x)
const
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
client
Definition
annotation.hpp:25
client::ast::apply_visitor
decltype(auto) apply_visitor(Visitor &&vis, Variant &&var)
Definition
ast.hpp:76
client::ast::operand
std::variant< nil, bool, unsigned int, double, identifier, recursive_wrapper< unary >, recursive_wrapper< function_call >, recursive_wrapper< expression > > operand
Definition
ast.hpp:124
client::annotation
Definition
annotation.hpp:33
client::annotation::operator()
void operator()(ast::operand &ast, Iterator pos) const
Definition
annotation.hpp:65
client::annotation::operator()
void operator()(ast::identifier &ast, Iterator pos) const
Definition
annotation.hpp:72
client::annotation::iters
std::vector< Iterator > & iters
Definition
annotation.hpp:37
client::annotation::annotation
annotation(std::vector< Iterator > &iters)
Definition
annotation.hpp:38
client::annotation::result
Definition
annotation.hpp:35
client::annotation::result::type
void type
Definition
annotation.hpp:35
client::annotation::set_id
Definition
annotation.hpp:42
client::annotation::set_id::result_type
void result_type
Definition
annotation.hpp:43
client::annotation::set_id::operator()
void operator()(ast::identifier &x) const
Definition
annotation.hpp:53
client::annotation::set_id::set_id
set_id(int id)
Definition
annotation.hpp:46
client::annotation::set_id::id
int id
Definition
annotation.hpp:45
client::annotation::set_id::operator()
void operator()(T &) const
Definition
annotation.hpp:59
client::annotation::set_id::operator()
void operator()(ast::function_call &x) const
Definition
annotation.hpp:48
client::ast::tagged::id
int id
Definition
ast.hpp:92
client::ast::identifier
Definition
ast.hpp:103
client::ast::function_call
Definition
ast.hpp:164
client::ast::function_call::function_name
identifier function_name
Definition
ast.hpp:165
ast.hpp
Generated on Wed Sep 30 2026 07:14:50 for OPAL (Object Oriented Parallel Accelerator Library) by
1.9.8