monotone

monotone Mtn Source Tree

Root/vocab_macros.hh

1
2//HH
3
4#define hh_ENCODING(enc) \
5 \
6template<typename INNER> \
7class enc; \
8 \
9template <typename INNER> \
10std::ostream & operator<<(std::ostream &, \
11 enc<INNER> const &); \
12 \
13template <typename INNER> \
14void dump(enc<INNER> const &, std::string &); \
15 \
16template<typename INNER> \
17class enc { \
18 INNER i; \
19public: \
20 bool ok; \
21 enc() : ok(false) {} \
22 enc(std::string const & s); \
23 enc(INNER const & inner); \
24 enc(enc<INNER> const & other); \
25 std::string const & operator()() const \
26 { return i(); } \
27 bool operator<(enc<INNER> const & x) const \
28 { return i() < x(); } \
29 enc<INNER> const & \
30 operator=(enc<INNER> const & other); \
31 bool operator==(enc<INNER> const & x) const \
32 { return i() == x(); } \
33 friend std::ostream & operator<< <>(std::ostream &, \
34 enc<INNER> const &); \
35};
36
37
38#define hh_DECORATE(dec) \
39 \
40template<typename INNER> \
41class dec; \
42 \
43template <typename INNER> \
44std::ostream & operator<<(std::ostream &, \
45 dec<INNER> const &); \
46 \
47template <typename INNER> \
48void dump(dec<INNER> const &, std::string &); \
49 \
50template<typename INNER> \
51class dec { \
52 INNER i; \
53public: \
54 bool ok; \
55 dec() : ok(false) {} \
56 dec(INNER const & inner); \
57 dec(dec<INNER> const & other); \
58 bool operator<(dec<INNER> const & x) const \
59 { return i < x.i; } \
60 INNER const & inner() const \
61 { return i; } \
62 dec<INNER> const & \
63 operator=(dec<INNER> const & other); \
64 bool operator==(dec<INNER> const & x) const \
65 { return i == x.i; } \
66 friend std::ostream & operator<< <>(std::ostream &, \
67 dec<INNER> const &); \
68};
69
70
71#define hh_ATOMIC(ty) \
72class ty { \
73 std::string s; \
74public: \
75 bool ok; \
76 ty() : ok(false) {} \
77 ty(std::string const & str); \
78 ty(ty const & other); \
79 std::string const & operator()() const \
80 { return s; } \
81 bool operator<(ty const & other) const \
82 { return s < other(); } \
83 ty const & operator=(ty const & other); \
84 bool operator==(ty const & other) const \
85 { return s == other(); } \
86 bool operator!=(ty const & other) const \
87 { return s != other(); } \
88 friend void verify(ty &t); \
89 friend void verify_full(ty &); \
90 friend std::ostream & operator<<(std::ostream &, \
91 ty const &); \
92 struct symtab \
93 { \
94 symtab(); \
95 ~symtab(); \
96 }; \
97}; \
98std::ostream & operator<<(std::ostream &, ty const &); \
99template <> \
100void dump(ty const &, std::string &); \
101inline void verify(ty &t) { if(!t.ok) verify_full(t); }; \
102
103#define hh_ATOMIC_NOVERIFY(ty) \
104ATOMIC(ty) \
105inline void verify_full(ty &) {}
106
107
108//CC
109
110
111#define cc_ATOMIC(ty) \
112 \
113static symtab_impl ty ## _tab; \
114static size_t ty ## _tab_active = 0; \
115 \
116ty::ty(string const & str) : \
117 s((ty ## _tab_active > 0) \
118 ? (ty ## _tab.unique(str)) \
119 : str), \
120 ok(false) \
121{ verify(*this); } \
122 \
123ty::ty(ty const & other) : \
124 s(other.s), ok(other.ok) \
125{ verify(*this); } \
126 \
127ty const & ty::operator=(ty const & other) \
128{ s = other.s; ok = other.ok; \
129 verify(*this); return *this; } \
130 \
131 std::ostream & operator<<(std::ostream & o,\
132 ty const & a) \
133{ return (o << a.s); } \
134 \
135template <> \
136void dump(ty const & obj, std::string & out) \
137{ out = obj(); } \
138 \
139ty::symtab::symtab() \
140{ ty ## _tab_active++; } \
141 \
142ty::symtab::~symtab() \
143{ \
144 I(ty ## _tab_active > 0); \
145 ty ## _tab_active--; \
146 if (ty ## _tab_active == 0) \
147 ty ## _tab.clear(); \
148}
149
150
151#define cc_ATOMIC_NOVERIFY(ty) cc_ATOMIC(ty)
152
153
154
155#define cc_ENCODING(enc) \
156 \
157template<typename INNER> \
158enc<INNER>::enc(string const & s) : i(s), ok(false) \
159 { verify(*this); } \
160 \
161template<typename INNER> \
162enc<INNER>::enc(enc<INNER> const & other) \
163 : i(other.i()), ok(other.ok) { verify(*this); } \
164 \
165template<typename INNER> \
166enc<INNER>::enc(INNER const & inner) : \
167 i(inner), ok(false) \
168 { verify(*this); } \
169 \
170template<typename INNER> \
171enc<INNER> const & \
172enc<INNER>::operator=(enc<INNER> const & other) \
173 { i = other.i; ok = other.ok; \
174 verify(*this); return *this;} \
175 \
176template <typename INNER> \
177std::ostream & operator<<(std::ostream & o, \
178 enc<INNER> const & e) \
179{ return (o << e.i); } \
180 \
181template <typename INNER> \
182void dump(enc<INNER> const & obj, std::string & out) \
183{ out = obj(); }
184
185
186#define cc_DECORATE(dec) \
187 \
188template<typename INNER> \
189dec<INNER>::dec(dec<INNER> const & other) \
190 : i(other.i), ok(other.ok) { verify(*this); } \
191 \
192template<typename INNER> \
193dec<INNER>::dec(INNER const & inner) : \
194 i(inner), ok(false) \
195 { verify(*this); } \
196 \
197template<typename INNER> \
198dec<INNER> const & \
199dec<INNER>::operator=(dec<INNER> const & other) \
200 { i = other.i; ok = other.ok; \
201 verify(*this); return *this;} \
202 \
203template <typename INNER> \
204std::ostream & operator<<(std::ostream & o, \
205 dec<INNER> const & d) \
206{ return (o << d.i); } \
207 \
208template <typename INNER> \
209void dump(dec<INNER> const & obj, std::string & out) \
210{ dump(obj.inner(), out); }
211
212
213

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status