Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
type-ast.hh
Go to the documentation of this file.
1 #ifndef VCSN_DYN_TYPE_AST_HH
2 # define VCSN_DYN_TYPE_AST_HH
3 
4 # include <iostream>
5 # include <memory>
6 # include <vector>
7 
9 
11 # include <vcsn/dyn/fwd.hh>
12 
13 
14 namespace vcsn
15 {
16  namespace ast
17  {
18 
19 # define ACCEPT() \
20  virtual void accept(context_visitor &v) const \
21  { \
22  v.visit(*this); \
23  }
24 
25  class ast_node
26  {
27  public:
28 #ifndef COVERAGE
29  virtual ~ast_node() = default;
30 #endif
31 
32  virtual void accept(context_visitor &v) const = 0;
33 
34  virtual bool has_one() const { return false; }
35  };
36 
37  class context: public ast_node
38  {
39  public:
40  context(std::shared_ptr<ast_node> ls, std::shared_ptr<ast_node> ws)
41  : ls_(ls), ws_(ws)
42  {}
43 
44  const std::shared_ptr<ast_node> get_labelset() const
45  {
46  return ls_;
47  }
48 
49  const std::shared_ptr<ast_node> get_weightset() const
50  {
51  return ws_;
52  }
53 
55 
56  private:
57  std::shared_ptr<ast_node> ls_;
58  std::shared_ptr<ast_node> ws_;
59  };
60 
61  class tupleset: public ast_node
62  {
63  public:
64  using value_t = std::vector<std::shared_ptr<ast_node>>;
65 
66  tupleset(const value_t& sets)
67  : sets_(sets)
68  {}
69 
70  const value_t get_sets() const
71  {
72  return sets_;
73  }
74 
76  virtual bool has_one() const
77  {
78  for (auto s : get_sets())
79  if (!s->has_one())
80  return false;
81  return true;
82  }
83 
84  private:
86  };
87 
88  class nullableset : public ast_node
89  {
90  public:
91  nullableset(std::shared_ptr<ast_node> ls)
92  : ls_(ls)
93  {}
94 
95  const std::shared_ptr<ast_node> get_labelset() const
96  {
97  return ls_;
98  }
99 
101 
102  virtual bool has_one() const { return true; }
103 
104  private:
105  std::shared_ptr<ast_node> ls_;
106  };
107 
108  class oneset : public ast_node
109  {
110  public:
112  {}
113 
115  virtual bool has_one() const { return true; }
116  };
117 
121  class genset: public ast_node
122  {
123  public:
124  genset(const std::string& letter_type, const std::string& gens)
125  : letter_type_(letter_type)
126  , generators_(gens)
127  {}
128 
130 
131 
132  const std::string& letter_type() const
133  {
134  return letter_type_;
135  }
136 
138  const std::string& generators() const
139  {
140  return generators_;
141  }
142 
143  private:
144  const std::string letter_type_;
145  const std::string generators_;
146  };
147 
149  class letterset: public ast_node
150  {
151  public:
152  letterset(const std::shared_ptr<const ast_node>& gs)
153  : gs_(gs)
154  {}
155 
157  std::shared_ptr<const ast_node> genset() const
158  {
159  return gs_;
160  }
161 
163  virtual bool has_one() const { return false; }
164 
165  private:
166  const std::shared_ptr<const ast_node> gs_;
167  };
168 
170  class wordset: public ast_node
171  {
172  public:
173  wordset(const std::shared_ptr<const ast_node>& gs)
174  : gs_(gs)
175  {}
176 
178  std::shared_ptr<const ast_node> genset() const
179  {
180  return gs_;
181  }
182 
184  virtual bool has_one() const { return true; }
185 
186  private:
187  const std::shared_ptr<const ast_node> gs_;
188  };
189 
190  class ratexpset: public ast_node
191  {
192  public:
193  ratexpset(std::shared_ptr<context> ctx,
194  rat::identities ids)
195  : ctx_(ctx)
196  , identities_(ids)
197  {}
198 
199  const std::shared_ptr<context> get_context() const
200  {
201  return ctx_;
202  }
203 
205  {
206  return identities_;
207  }
208 
210  virtual bool has_one() const { return true; }
211 
212  private:
213  std::shared_ptr<context> ctx_;
215  };
216 
217  class weightset: public ast_node
218  {
219  public:
220  weightset(const std::string& type)
221  : type_(type)
222  {}
223 
224  const std::string& get_type() const
225  {
226  return type_;
227  }
228 
230  private:
231  std::string type_;
232  };
233 
234  class other : public ast_node
235  {
236  public:
237  other(const std::string& type)
238  : type_(type)
239  {}
240 
241  const std::string& get_type() const
242  {
243  return type_;
244  }
245 
247  private:
248  std::string type_;
249  };
250 
251  class automaton: public ast_node
252  {
253  public:
254  using node_t = std::shared_ptr<ast_node>;
255  using nodes_t = std::vector<node_t>;
256  automaton(const std::string& type, const node_t& child)
257  : type_(type)
258  , children_{child}
259  {}
260 
261  automaton(const std::string& type, const nodes_t& children)
262  : type_(type)
263  , children_(children)
264  {}
265 
266  const std::string& get_type() const
267  {
268  return type_;
269  }
270 
271  const nodes_t& get_content() const
272  {
273  return children_;
274  }
275 
277  {
278  return children_;
279  }
280 
282 
283  private:
284  std::string type_;
285  nodes_t children_;
286  };
287 
288  class polynomialset : public ast_node
289  {
290  public:
291  polynomialset(std::shared_ptr<ast_node> child)
292  : child_(child)
293  {}
294 
295  const std::shared_ptr<ast_node>& get_content() const
296  {
297  return child_;
298  }
299 
301 
302  private:
303  std::shared_ptr<ast_node> child_;
304  };
305 # undef ACCEPT
306  }
307 }
308 
309 
310 
311 #endif // !VCSN_DYN_TYPE_AST_HH
std::shared_ptr< ast_node > ls_
Definition: type-ast.hh:105
context(std::shared_ptr< ast_node > ls, std::shared_ptr< ast_node > ws)
Definition: type-ast.hh:40
const std::shared_ptr< ast_node > get_labelset() const
Definition: type-ast.hh:44
tupleset(const value_t &sets)
Definition: type-ast.hh:66
std::shared_ptr< context > ctx_
Definition: type-ast.hh:213
polynomialset(std::shared_ptr< ast_node > child)
Definition: type-ast.hh:291
std::shared_ptr< ast_node > ws_
Definition: type-ast.hh:58
const std::shared_ptr< const ast_node > gs_
Definition: type-ast.hh:187
virtual ~ast_node()=default
nullableset(std::shared_ptr< ast_node > ls)
Definition: type-ast.hh:91
const std::string & generators() const
The generators.
Definition: type-ast.hh:138
Support for letterset.
Definition: type-ast.hh:149
rat::identities get_identities() const
Definition: type-ast.hh:204
Support for wordset.
Definition: type-ast.hh:170
const std::shared_ptr< const ast_node > gs_
Definition: type-ast.hh:166
std::shared_ptr< const ast_node > genset() const
The generator set.
Definition: type-ast.hh:157
const nodes_t & get_content() const
Definition: type-ast.hh:271
wordset(const std::shared_ptr< const ast_node > &gs)
Definition: type-ast.hh:173
const std::string & get_type() const
Definition: type-ast.hh:266
const std::shared_ptr< ast_node > & get_content() const
Definition: type-ast.hh:295
const std::shared_ptr< ast_node > get_weightset() const
Definition: type-ast.hh:49
letterset(const std::shared_ptr< const ast_node > &gs)
Definition: type-ast.hh:152
std::shared_ptr< ast_node > ls_
Definition: type-ast.hh:57
rat::identities identities_
Definition: type-ast.hh:214
other(const std::string &type)
Definition: type-ast.hh:237
virtual void accept(context_visitor &v) const =0
automaton(const std::string &type, const node_t &child)
Definition: type-ast.hh:256
std::shared_ptr< const ast_node > genset() const
The generator set.
Definition: type-ast.hh:178
const value_t get_sets() const
Definition: type-ast.hh:70
const std::string letter_type_
Definition: type-ast.hh:144
const std::shared_ptr< context > get_context() const
Definition: type-ast.hh:199
weightset(const std::string &type)
Definition: type-ast.hh:220
automaton(const std::string &type, const nodes_t &children)
Definition: type-ast.hh:261
std::vector< node_t > nodes_t
Definition: type-ast.hh:255
std::vector< std::shared_ptr< ast_node >> value_t
Definition: type-ast.hh:64
Represents the "alphabets", or "generator set".
Definition: type-ast.hh:121
const std::shared_ptr< ast_node > get_labelset() const
Definition: type-ast.hh:95
genset(const std::string &letter_type, const std::string &gens)
Definition: type-ast.hh:124
nodes_t & get_content()
Definition: type-ast.hh:276
virtual bool has_one() const
Definition: type-ast.hh:34
const std::string & get_type() const
Definition: type-ast.hh:224
#define ACCEPT()
Definition: type-ast.hh:19
identities
A ratexpset can implement several different sets of identities on expressions.
Definition: identities.hh:17
const std::string generators_
Definition: type-ast.hh:145
std::shared_ptr< ast_node > node_t
Definition: type-ast.hh:254
ratexpset(std::shared_ptr< context > ctx, rat::identities ids)
Definition: type-ast.hh:193
const std::string & get_type() const
Definition: type-ast.hh:241