1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
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(BOOST_SPIRIT_CALC8_ANNOTATION_HPP)
8 #define BOOST_SPIRIT_CALC8_ANNOTATION_HPP
11 #include <boost/variant/apply_visitor.hpp>
12 #include <boost/type_traits/is_base_of.hpp>
13 #include <boost/mpl/bool.hpp>
18 ///////////////////////////////////////////////////////////////////////////////
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.
22 ///////////////////////////////////////////////////////////////////////////////
23 template <typename Iterator>
26 template <typename, typename>
27 struct result { typedef void type; };
29 std::vector<Iterator>& iters;
30 annotation(std::vector<Iterator>& iters)
35 typedef void result_type;
38 set_id(int id) : id(id) {}
41 void operator()(T& x) const
43 this->dispatch(x, boost::is_base_of<ast::tagged, T>());
46 // This will catch all nodes except those inheriting from ast::tagged
48 void dispatch(T& x, boost::mpl::false_) const
50 // (no-op) no need for tags
53 // This will catch all nodes inheriting from ast::tagged
55 void dispatch(T& x, boost::mpl::true_) const
61 void operator()(ast::operand& ast, Iterator pos) const
63 int id = iters.size();
65 boost::apply_visitor(set_id(id), ast);
68 void operator()(ast::assignment& ast, Iterator pos) const
70 int id = iters.size();