CommandParserbase.h
1 // Generated by Bisonc++ V4.09.02 on Fri, 20 May 2016 16:54:44 -0400
2 
3 #ifndef pfp_cpCommandParserBase_h_included
4 #define pfp_cpCommandParserBase_h_included
5 
6 #include <exception>
7 #include <vector>
8 #include <iostream>
9 
10 // $insert preincludes
11 #include <memory>
12 
13 namespace // anonymous
14 {
15  struct PI__;
16 }
17 
18 // $insert namespace-open
19 namespace pfp_cp
20 {
21 
22 // $insert polymorphic
23 enum class Tag__
24 {
25  DELETE_COMMAND,
26  MODIFY_COMMAND,
27  INSERT_COMMAND,
28  BYTES,
29  EXACT_KEY_PARAM,
30  INTEGER,
31  STRING,
32  ACTION_SPEC,
33  LPM_KEY_PARAM,
34  MATCH_KEY,
35  TERNARY_KEY_PARAM,
36  MATCH_KEYS,
37  COMMAND,
38 };
39 
40 namespace Meta__
41 {
42  template <Tag__ tag>
43  struct TypeOf;
44 
45  template <typename Tp_>
46  struct TagOf;
47 
48 // $insert polymorphicSpecializations
49  template <>
50  struct TagOf<DeleteCommand *>
51  {
52  static Tag__ const tag = Tag__::DELETE_COMMAND;
53  };
54 
55  template <>
56  struct TagOf<ModifyCommand *>
57  {
58  static Tag__ const tag = Tag__::MODIFY_COMMAND;
59  };
60 
61  template <>
62  struct TagOf<InsertCommand *>
63  {
64  static Tag__ const tag = Tag__::INSERT_COMMAND;
65  };
66 
67  template <>
68  struct TagOf<Bytes>
69  {
70  static Tag__ const tag = Tag__::BYTES;
71  };
72 
73  template <>
74  struct TagOf<ExactKey *>
75  {
76  static Tag__ const tag = Tag__::EXACT_KEY_PARAM;
77  };
78 
79  template <>
80  struct TagOf<unsigned long long>
81  {
82  static Tag__ const tag = Tag__::INTEGER;
83  };
84 
85  template <>
86  struct TagOf<std::string>
87  {
88  static Tag__ const tag = Tag__::STRING;
89  };
90 
91  template <>
92  struct TagOf<Action *>
93  {
94  static Tag__ const tag = Tag__::ACTION_SPEC;
95  };
96 
97  template <>
98  struct TagOf<LpmKey *>
99  {
100  static Tag__ const tag = Tag__::LPM_KEY_PARAM;
101  };
102 
103  template <>
104  struct TagOf<MatchKey *>
105  {
106  static Tag__ const tag = Tag__::MATCH_KEY;
107  };
108 
109  template <>
110  struct TagOf<TernaryKey *>
111  {
112  static Tag__ const tag = Tag__::TERNARY_KEY_PARAM;
113  };
114 
115  template <>
116  struct TagOf<MatchKeyContainer *>
117  {
118  static Tag__ const tag = Tag__::MATCH_KEYS;
119  };
120 
121  template <>
122  struct TagOf<Command *>
123  {
124  static Tag__ const tag = Tag__::COMMAND;
125  };
126 
127  template <>
128  struct TypeOf<Tag__::DELETE_COMMAND>
129  {
130  typedef DeleteCommand * type;
131  };
132 
133  template <>
134  struct TypeOf<Tag__::MODIFY_COMMAND>
135  {
136  typedef ModifyCommand * type;
137  };
138 
139  template <>
140  struct TypeOf<Tag__::INSERT_COMMAND>
141  {
142  typedef InsertCommand * type;
143  };
144 
145  template <>
146  struct TypeOf<Tag__::BYTES>
147  {
148  typedef Bytes type;
149  };
150 
151  template <>
152  struct TypeOf<Tag__::EXACT_KEY_PARAM>
153  {
154  typedef ExactKey * type;
155  };
156 
157  template <>
158  struct TypeOf<Tag__::INTEGER>
159  {
160  typedef unsigned long long type;
161  };
162 
163  template <>
164  struct TypeOf<Tag__::STRING>
165  {
166  typedef std::string type;
167  };
168 
169  template <>
170  struct TypeOf<Tag__::ACTION_SPEC>
171  {
172  typedef Action * type;
173  };
174 
175  template <>
176  struct TypeOf<Tag__::LPM_KEY_PARAM>
177  {
178  typedef LpmKey * type;
179  };
180 
181  template <>
182  struct TypeOf<Tag__::MATCH_KEY>
183  {
184  typedef MatchKey * type;
185  };
186 
187  template <>
188  struct TypeOf<Tag__::TERNARY_KEY_PARAM>
189  {
190  typedef TernaryKey * type;
191  };
192 
193  template <>
194  struct TypeOf<Tag__::MATCH_KEYS>
195  {
196  typedef MatchKeyContainer * type;
197  };
198 
199  template <>
200  struct TypeOf<Tag__::COMMAND>
201  {
202  typedef Command * type;
203  };
204 
205 
206  // The Base class:
207  // Individual semantic value classes are derived from this class.
208  // This class offers a member returning the value's Tag__
209  // and two member templates get() offering const/non-const access to
210  // the actual semantic value type.
211  class Base
212  {
213  Tag__ d_tag;
214 
215  protected:
216  Base(Tag__ tag);
217 
218  public:
219  Base(Base const &other) = delete;
220 
221  Tag__ tag() const;
222 
223  template <Tag__ tg_>
224  typename TypeOf<tg_>::type &get();
225  };
226 
227  // The class Semantic is derived from Base. It stores a particular
228  // semantic value type.
229  template <Tag__ tg_>
230  class Semantic: public Base
231  {
232  typedef typename TypeOf<tg_>::type DataType;
233 
234  DataType d_data;
235 
236  public:
237  // The default constructor and constructors for
238  // defined data types are available
239  Semantic();
240  Semantic(DataType const &data);
241  Semantic(DataType &&tmp);
242 
243  DataType &data();
244  };
245 
246  // The class Stype wraps the shared_ptr holding a pointer to Base.
247  // It becomes the polymorphic STYPE__
248  // It also wraps Base's get members, allowing constructions like
249  // $$.get<INT> to be used, rather than $$->get<INT>.
250  // Its operator= can be used to assign a Semantic *
251  // directly to the SType object. The free functions (in the parser's
252  // namespace (if defined)) semantic__ can be used to obtain a
253  // Semantic *.
254  struct SType: public std::shared_ptr<Base>
255  {
256  template <typename Tp_>
257  SType &operator=(Tp_ &&value);
258 
259  Tag__ tag() const;
260 
261  // this get()-member checks for 0-pointer and correct tag
262  // in shared_ptr<Base>, and resets the shared_ptr's Base *
263  // to point to Meta::__Semantic<tg_>() if not
264  template <Tag__ tg_>
265  typename TypeOf<tg_>::type &get();
266 
267  // the data()-member does not check, and may result in a
268  // segfault if used incorrectly
269  template <Tag__ tg_>
270  typename TypeOf<tg_>::type &data();
271  };
272 
273 } // namespace Meta__
274 
275 class CommandParserBase
276 {
277  public:
278 // $insert tokens
279 
280  // Symbolic tokens:
281  enum Tokens__
282  {
283  IDENTIFIER = 271,
284  INSERT_ENTRY,
285  MODIFY_ENTRY,
286  DELETE_ENTRY,
287  DECIMAL,
288  HEXADECIMAL,
289  __,
290  EOL,
291  COMMENT,
292  };
293 
294 // $insert STYPE
295  typedef Meta__::SType STYPE__;
296 
297 
298  private:
299  int d_stackIdx__;
300  std::vector<size_t> d_stateStack__;
301  std::vector<STYPE__> d_valueStack__;
302 
303  protected:
304  enum Return__
305  {
306  PARSE_ACCEPT__ = 0, // values used as parse()'s return values
307  PARSE_ABORT__ = 1
308  };
309  enum ErrorRecovery__
310  {
311  DEFAULT_RECOVERY_MODE__,
312  UNEXPECTED_TOKEN__,
313  };
314  bool d_debug__;
315  size_t d_nErrors__;
316  size_t d_requiredTokens__;
317  size_t d_acceptedTokens__;
318  int d_token__;
319  int d_nextToken__;
320  size_t d_state__;
321  STYPE__ *d_vsp__;
322  STYPE__ d_val__;
323  STYPE__ d_nextVal__;
324 
325  CommandParserBase();
326 
327  void ABORT() const;
328  void ACCEPT() const;
329  void ERROR() const;
330  void clearin();
331  bool debug() const;
332  void pop__(size_t count = 1);
333  void push__(size_t nextState);
334  void popToken__();
335  void pushToken__(int token);
336  void reduce__(PI__ const &productionInfo);
337  void errorVerbose__();
338  size_t top__() const;
339 
340  public:
341  void setDebug(bool mode);
342 };
343 
344 inline bool CommandParserBase::debug() const
345 {
346  return d_debug__;
347 }
348 
349 inline void CommandParserBase::setDebug(bool mode)
350 {
351  d_debug__ = mode;
352 }
353 
354 inline void CommandParserBase::ABORT() const
355 {
356  throw PARSE_ABORT__;
357 }
358 
359 inline void CommandParserBase::ACCEPT() const
360 {
361  throw PARSE_ACCEPT__;
362 }
363 
364 inline void CommandParserBase::ERROR() const
365 {
366  throw UNEXPECTED_TOKEN__;
367 }
368 
369 // $insert polymorphicInline
370 namespace Meta__
371 {
372 
373 inline Base::Base(Tag__ tag)
374 :
375  d_tag(tag)
376 {}
377 
378 inline Tag__ Base::tag() const
379 {
380  return d_tag;
381 }
382 
383 template <Tag__ tg_>
384 inline Semantic<tg_>::Semantic()
385 :
386  Base(tg_),
387  d_data(typename TypeOf<tg_>::type())
388 {}
389 
390 template <Tag__ tg_>
391 inline Semantic<tg_>::Semantic(typename TypeOf<tg_>::type const &data)
392 :
393  Base(tg_),
394  d_data(data)
395 {}
396 
397 template <Tag__ tg_>
398 inline Semantic<tg_>::Semantic(typename TypeOf<tg_>::type &&tmp)
399 :
400  Base(tg_),
401  d_data(std::move(tmp))
402 {}
403 
404 template <Tag__ tg_>
405 inline typename TypeOf<tg_>::type &Semantic<tg_>::data()
406 {
407  return d_data;
408 }
409 
410 template <Tag__ tg_>
411 inline typename TypeOf<tg_>::type &Base::get()
412 {
413  return static_cast<Semantic<tg_> *>(this)->data();
414 }
415 
416 inline Tag__ SType::tag() const
417 {
418  return std::shared_ptr<Base>::get()->tag();
419 }
420 
421 template <Tag__ tg_>
422 inline typename TypeOf<tg_>::type &SType::get()
423 {
424  // if we're not yet holding a (tg_) value, initialize to
425  // a Semantic<tg_> holding a default value
426  if (std::shared_ptr<Base>::get() == 0 || tag() != tg_)
427  reset(new Semantic<tg_>());
428 
429  return std::shared_ptr<Base>::get()->get<tg_>();
430 }
431 
432 template <Tag__ tg_>
433 inline typename TypeOf<tg_>::type &SType::data()
434 {
435  return std::shared_ptr<Base>::get()->get<tg_>();
436 }
437 
438 template <bool, typename Tp_>
439 struct Assign;
440 
441 template <typename Tp_>
442 struct Assign<true, Tp_>
443 {
444  static SType &assign(SType *lhs, Tp_ &&tp);
445 };
446 
447 template <typename Tp_>
448 struct Assign<false, Tp_>
449 {
450  static SType &assign(SType *lhs, Tp_ const &tp);
451 };
452 
453 template <>
454 struct Assign<false, SType>
455 {
456  static SType &assign(SType *lhs, SType const &tp);
457 };
458 
459 template <typename Tp_>
460 inline SType &Assign<true, Tp_>::assign(SType *lhs, Tp_ &&tp)
461 {
462  lhs->reset(new Semantic<TagOf<Tp_>::tag>(std::move(tp)));
463  return *lhs;
464 }
465 
466 template <typename Tp_>
467 inline SType &Assign<false, Tp_>::assign(SType *lhs, Tp_ const &tp)
468 {
469  lhs->reset(new Semantic<TagOf<Tp_>::tag>(tp));
470  return *lhs;
471 }
472 
473 inline SType &Assign<false, SType>::assign(SType *lhs, SType const &tp)
474 {
475  return lhs->operator=(tp);
476 }
477 
478 template <typename Tp_>
479 inline SType &SType::operator=(Tp_ &&rhs)
480 {
481  return Assign<
482  std::is_rvalue_reference<Tp_ &&>::value,
483  typename std::remove_reference<Tp_>::type
484  >::assign(this, std::forward<Tp_>(rhs));
485 }
486 
487 } // namespace Meta__
488 
489 // As a convenience, when including ParserBase.h its symbols are available as
490 // symbols in the class Parser, too.
491 #define CommandParser CommandParserBase
492 
493 // $insert namespace-close
494 }
495 
496 #endif
497 
498 
Definition: json.hpp:8681
Definition: CommandParser.h:50