OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ast.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(AST_HPP)
8 #define AST_HPP
9 
10 #include <boost/config/warning_disable.hpp>
11 #include <boost/variant/recursive_variant.hpp>
12 #include <boost/fusion/include/adapt_struct.hpp>
13 #include <boost/fusion/include/io.hpp>
14 #include <boost/optional.hpp>
15 #include <list>
16 
17 namespace client { namespace ast
18 {
19  struct tagged
20  {
21  int id; // Used to annotate the AST with the iterator position.
22  // This id is used as a key to a map<int, Iterator>
23  // (not really part of the AST.)
24  };
25 
26  struct nil {};
27  struct unary;
28  struct function_call;
29  struct expression;
30 
31  struct identifier : tagged
32  {
33  identifier(std::string const& name = "") : name(name) {}
34  std::string name;
35  };
36 
38  {
39  quoted_string(std::string const& value = "") : value(value) {}
40  std::string value;
41  };
42 
43  typedef boost::variant<
44  nil
45  , bool
46  , unsigned int
47  , double
48  , identifier
49  , boost::recursive_wrapper<unary>
50  , boost::recursive_wrapper<function_call>
51  , boost::recursive_wrapper<expression>
52  >
54 
55  typedef boost::variant<
58  >
60 
61  enum optoken
62  {
78  };
79 
80  struct unary
81  {
84  };
85 
86  struct operation
87  {
90  };
91 
93  {
95  std::list<function_call_argument> args;
96  };
97 
98  struct expression
99  {
101  std::list<operation> rest;
102  };
103 
104  // print functions for debugging
105  inline std::ostream& operator<<(std::ostream& out, nil)
106  {
107  out << "nil"; return out;
108  }
109 
110  inline std::ostream& operator<<(std::ostream& out, identifier const& id)
111  {
112  out << id.name; return out;
113  }
114 }}
115 
118  (client::ast::optoken, operator_)
119  (client::ast::operand, operand_)
120 )
121 
123  client::ast::operation,
124  (client::ast::optoken, operator_)
125  (client::ast::operand, operand_)
126 )
127 
129  client::ast::function_call,
130  (client::ast::identifier, function_name)
131  (std::list<client::ast::function_call_argument>, args)
132 )
133 
135  client::ast::expression,
136  (client::ast::operand, first)
137  (std::list<client::ast::operation>, rest)
138 )
139 
140 #endif
std::list< function_call_argument > args
Definition: ast.hpp:95
boost::variant< expression, quoted_string > function_call_argument
Definition: ast.hpp:59
operand operand_
Definition: ast.hpp:83
std::list< operation > rest
Definition: ast.hpp:101
operand operand_
Definition: ast.hpp:89
optoken operator_
Definition: ast.hpp:82
std::ostream & operator<<(std::ostream &out, nil)
Definition: ast.hpp:105
quoted_string(std::string const &value="")
Definition: ast.hpp:39
std::string name
Definition: ast.hpp:34
BOOST_FUSION_ADAPT_STRUCT(SDDS::column,(boost::optional< std::string >, name_m)(boost::optional< SDDS::ast::datatype >, type_m)(boost::optional< std::string >, units_m)(boost::optional< std::string >, description_m)(SDDS::ast::variant_t, value_m)) namespace SDDS
Definition: column.hpp:173
std::string value
Definition: ast.hpp:40
optoken operator_
Definition: ast.hpp:88
identifier(std::string const &name="")
Definition: ast.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