MyLang
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
myparser_pass.hpp
Go to the documentation of this file.
1 #ifndef MYPARSER_PASS_HPP
2 #define MYPARSER_PASS_HPP
3 
4 #include "myparser_common.hpp"
5 
6 namespace myparser {
7 
8 class PassBase {
9 private:
10  size_t id;
11 
12 protected:
13  inline PassBase(const size_t pass): id(pass) {}
14 
15  // virtual ~PassBase() {}
16 
17 public:
18  inline size_t getId() {
19  return id;
20  }
21 };
22 
23 template <size_t I>
24 class PassProto: public PassBase {
25 public:
26  inline PassProto(): PassBase(I) {}
27 
28  // virtual ~PassProto() {}
29 
30  // TODO: add run() with template, hold bad calls
31 
32  template <class T>
33  static MYPARSER_INLINE void call(
34  PassBase *pass, const size_t target, const T *node
35  ) {
36  if (target == I) {
37  ((Pass<I> *) pass)->run(node);
38  } else {
39  Pass<I + 1>::call(pass, target, node);
40  }
41  }
42 };
43 
44 template <size_t I = 0>
45 class Pass {
46 public:
47  template <class T>
48  static MYPARSER_INLINE void call(
49  PassBase *pass, const size_t target, const T *node
50  ) {
51  Pass<I + 1>::call(pass, target, node);
52  }
53 };
54 
55 template <>
56 class Pass<PASS_FIN> {
57 public:
58  template <class T>
59  static MYPARSER_INLINE void call(
60  PassBase *pass, const size_t target, const T *node
61  ) {
62  // never reach
63  (void) pass;
64  (void) target;
65  (void) node;
66  }
67 };
68 
69 }
70 
71 #endif
static MYPARSER_INLINE void call(PassBase *pass, const size_t target, const T *node)
Definition: myparser_pass.hpp:48
size_t getId()
Definition: myparser_pass.hpp:18
Definition: myparser_common.hpp:86
Definition: myparser_pass.hpp:8
Definition: myparser_pass.hpp:24
Definition: myparser_common.hpp:92
size_t id
Definition: myparser_pass.hpp:10
static MYPARSER_INLINE void call(PassBase *pass, const size_t target, const T *node)
Definition: myparser_pass.hpp:59
PassBase(const size_t pass)
Definition: myparser_pass.hpp:13
static MYPARSER_INLINE void call(PassBase *pass, const size_t target, const T *node)
Definition: myparser_pass.hpp:33
#define MYPARSER_INLINE
Definition: myparser_common.hpp:50
PassProto()
Definition: myparser_pass.hpp:26