OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
annotation.hpp
Go to the documentation of this file.
1 /*=============================================================================
2  Copyright (c) 2001-2011 Joel de Guzman
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(ANNOTATION_HPP)
8 #define ANNOTATION_HPP
9 
10 #include <map>
11 #include <boost/variant/apply_visitor.hpp>
12 #include <boost/type_traits/is_base_of.hpp>
13 #include <boost/mpl/bool.hpp>
14 #include "ast.hpp"
15 
16 namespace client
17 {
19  // The annotation handler links the AST to a map of iterator positions
20  // for the purpose of subsequent semantic error handling when the
21  // program is being compiled.
23  template <typename Iterator>
24  struct annotation
25  {
26 #if BOOST_VERSION >= 106200
27  template <typename>
28 #else
29  template <typename, typename>
30 #endif
31  struct result { typedef void type; };
32 
33  std::vector<Iterator>& iters;
34  annotation(std::vector<Iterator>& iters)
35  : iters(iters) {}
36 
37  struct set_id
38  {
39  typedef void result_type;
40 
41  int id;
42  set_id(int id) : id(id) {}
43 
45  {
46  x.function_name.id = id;
47  }
48 
49  void operator()(ast::identifier& x) const
50  {
51  x.id = id;
52  }
53 
54  template <typename T>
55  void operator()(T& x) const
56  {
57  // no-op
58  }
59  };
60 
61  void operator()(ast::operand& ast, Iterator pos) const
62  {
63  int id = iters.size();
64  iters.push_back(pos);
65  boost::apply_visitor(set_id(id), ast);
66  }
67 
68  void operator()(ast::identifier& ast, Iterator pos) const
69  {
70  int id = iters.size();
71  iters.push_back(pos);
72  ast.id = id;
73  }
74  };
75 }
76 
77 #endif
void operator()(ast::function_call &x) const
Definition: annotation.hpp:44
Definition: rbendmap.h:8
annotation(std::vector< Iterator > &iters)
Definition: annotation.hpp:34
void operator()(ast::operand &ast, Iterator pos) const
Definition: annotation.hpp:61
void operator()(T &x) const
Definition: annotation.hpp:55
void operator()(ast::identifier &ast, Iterator pos) const
Definition: annotation.hpp:68
std::vector< Iterator > & iters
Definition: annotation.hpp:33
identifier function_name
Definition: ast.hpp:94
boost::variant< nil, bool, unsigned int, double, identifier, boost::recursive_wrapper< unary >, boost::recursive_wrapper< function_call >, boost::recursive_wrapper< expression > > operand
Definition: ast.hpp:53
void operator()(ast::identifier &x) const
Definition: annotation.hpp:49