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 : public origin_aware { \
18 immutable_string s; \
19public: \
20 enc() {} \
21 explicit enc(std::string const & s); \
22 enc(std::string const & s, made_from_t m); \
23 enc(enc<INNER> const & other); \
24 enc<INNER> const & \
25 operator=(enc<INNER> const & other); \
26 std::string const & operator()() const \
27 { return s.get(); } \
28 bool operator<(enc<INNER> const & x) const \
29 { return s.get() < x.s.get(); } \
30 bool operator==(enc<INNER> const & x) const \
31 { return s.get() == x.s.get(); } \
32 bool operator!=(enc<INNER> const & x) const \
33 { return s.get() != x.s.get(); } \
34 friend std::ostream & operator<< <>(std::ostream &, \
35 enc<INNER> const &); \
36};
37
38#define hh_ENCODING_NOVERIFY(enc) hh_ENCODING(enc)
39
40
41#define hh_DECORATE(dec) \
42 \
43template<typename INNER> \
44class dec; \
45 \
46template <typename INNER> \
47std::ostream & operator<<(std::ostream &, \
48 dec<INNER> const &); \
49 \
50template <typename INNER> \
51void dump(dec<INNER> const &, std::string &); \
52 \
53template<typename INNER> \
54class dec { \
55 INNER i; \
56public: \
57 dec() {} \
58 explicit dec(std::string const & s); \
59 dec(std::string const & s, made_from_t m); \
60 explicit dec(INNER const & inner); \
61 dec(dec<INNER> const & other); \
62 bool operator<(dec<INNER> const & x) const \
63 { return i < x.i; } \
64 INNER const & inner() const \
65 { return i; } \
66 dec<INNER> const & \
67 operator=(dec<INNER> const & other); \
68 bool operator==(dec<INNER> const & x) const \
69 { return i == x.i; } \
70 bool operator!=(dec<INNER> const & x) const \
71 { return !(i == x.i); } \
72 friend std::ostream & operator<< <>(std::ostream &, \
73 dec<INNER> const &); \
74};
75
76
77#define hh_ATOMIC_HOOKED(ty, hook) \
78class ty; \
79 \
80std::ostream & operator<<(std::ostream &, ty const &); \
81 \
82template <> \
83void dump(ty const &, std::string &); \
84 \
85class ty : public origin_aware { \
86 immutable_string s; \
87public: \
88 ty() {} \
89 explicit ty(std::string const & str); \
90 ty(std::string const & str, made_from_t m); \
91 ty(ty const & other); \
92 ty const & operator=(ty const & other); \
93 std::string const & operator()() const \
94 { return s.get(); } \
95 bool operator<(ty const & x) const \
96 { return s.get() < x.s.get(); } \
97 bool operator==(ty const & x) const \
98 { return s.get() == x.s.get(); } \
99 bool operator!=(ty const & x) const \
100 { return s.get() != x.s.get(); } \
101 friend std::ostream & operator<<(std::ostream &, \
102 ty const &); \
103 hook \
104 struct symtab \
105 { \
106 symtab(); \
107 ~symtab(); \
108 }; \
109};
110
111#define hh_ATOMIC(ty) hh_ATOMIC_HOOKED(ty,)
112#define hh_ATOMIC_NOVERIFY(ty) hh_ATOMIC(ty)
113#define hh_ATOMIC_BINARY(ty) hh_ATOMIC(ty)
114
115//CC
116
117
118#define cc_ATOMIC(ty) \
119 \
120static symtab_impl ty ## _tab; \
121static size_t ty ## _tab_active = 0; \
122 \
123ty::ty(string const & str) : \
124 origin_aware(), \
125 s((ty ## _tab_active > 0) \
126 ? (ty ## _tab.unique(str)) \
127 : str) \
128{ verify(*this); } \
129 \
130ty::ty(string const & str, \
131 made_from_t m) : \
132 origin_aware(m), \
133 s((ty ## _tab_active > 0) \
134 ? (ty ## _tab.unique(str)) \
135 : str) \
136{ verify(*this); } \
137 \
138ty::ty(ty const & other) : \
139 origin_aware(other), s(other.s) {} \
140 \
141ty const & ty::operator=(ty const & other) \
142{ s = other.s; return *this; } \
143 \
144std::ostream & operator<<(std::ostream & o, \
145 ty const & a) \
146{ return (o << a.s.get()); } \
147 \
148template <> \
149void dump(ty const & obj, std::string & out) \
150{ out = obj(); } \
151 \
152ty::symtab::symtab() \
153{ ty ## _tab_active++; } \
154 \
155ty::symtab::~symtab() \
156{ \
157 made_from_t made_from(::made_from); \
158 I(ty ## _tab_active > 0); \
159 ty ## _tab_active--; \
160 if (ty ## _tab_active == 0) \
161 ty ## _tab.clear(); \
162}
163
164
165#define cc_ATOMIC_NOVERIFY(ty) \
166inline void verify(ty const &) {} \
167cc_ATOMIC(ty)
168
169
170#define cc_ATOMIC_BINARY(ty) \
171 \
172static symtab_impl ty ## _tab; \
173static size_t ty ## _tab_active = 0; \
174 \
175ty::ty(string const & str) : \
176 origin_aware(), \
177 s((ty ## _tab_active > 0) \
178 ? (ty ## _tab.unique(str)) \
179 : str) \
180{ verify(*this); } \
181 \
182ty::ty(string const & str, \
183 made_from_t m) : \
184 origin_aware(m), \
185 s((ty ## _tab_active > 0) \
186 ? (ty ## _tab.unique(str)) \
187 : str) \
188{ verify(*this); } \
189 \
190ty::ty(ty const & other) : \
191 origin_aware(other), s(other.s) {} \
192 \
193ty const & ty::operator=(ty const & other) \
194{ s = other.s; return *this; } \
195 \
196std::ostream & operator<<(std::ostream & o, \
197 ty const & a) \
198{ return (o << encode_hexenc(a.s.get())); } \
199 \
200ty::symtab::symtab() \
201{ ty ## _tab_active++; } \
202 \
203ty::symtab::~symtab() \
204{ \
205 made_from_t made_from(::made_from); \
206 I(ty ## _tab_active > 0); \
207 ty ## _tab_active--; \
208 if (ty ## _tab_active == 0) \
209 ty ## _tab.clear(); \
210}
211
212
213
214#define cc_ENCODING(enc) \
215 \
216template<typename INNER> \
217enc<INNER>::enc(string const & s) : \
218 origin_aware(), s(s) \
219 { verify(*this); } \
220 \
221template<typename INNER> \
222enc<INNER>::enc(string const & s, made_from_t m) : \
223 origin_aware(m), s(s) \
224 { verify(*this); } \
225 \
226template<typename INNER> \
227enc<INNER>::enc(enc<INNER> const & other) \
228 : origin_aware(other), s(other.s) {} \
229 \
230template<typename INNER> \
231enc<INNER> const & \
232enc<INNER>::operator=(enc<INNER> const & other) \
233 { s = other.s; return *this; } \
234 \
235template <typename INNER> \
236std::ostream & operator<<(std::ostream & o, \
237 enc<INNER> const & e) \
238{ return (o << e.s.get()); } \
239 \
240template <typename INNER> \
241void dump(enc<INNER> const & obj, std::string & out) \
242{ out = obj(); }
243
244#define cc_ENCODING_NOVERIFY(enc) \
245template<typename INNER> \
246inline void verify(enc<INNER> const &) {} \
247cc_ENCODING(enc)
248
249
250
251#define cc_DECORATE(dec) \
252 \
253template<typename INNER> \
254dec<INNER>::dec(dec<INNER> const & other) \
255 : i(other.i) {} \
256 \
257template<typename INNER> \
258dec<INNER>::dec(std::string const & s) \
259 : i(s) { verify(i); } \
260 \
261template<typename INNER> \
262dec<INNER>::dec(std::string const & s, \
263 made_from_t m) \
264 : i(s, m) { verify(i); } \
265 \
266template<typename INNER> \
267dec<INNER>::dec(INNER const & inner) \
268 : i(inner) {} \
269 \
270template<typename INNER> \
271dec<INNER> const & \
272dec<INNER>::operator=(dec<INNER> const & other) \
273 { i = other.i; return *this; } \
274 \
275template <typename INNER> \
276std::ostream & operator<<(std::ostream & o, \
277 dec<INNER> const & d) \
278{ return (o << d.i); } \
279 \
280template <typename INNER> \
281void dump(dec<INNER> const & obj, std::string & out) \
282{ dump(obj.inner(), out); }
283
284
285// Local Variables:
286// mode: C++
287// fill-column: 76
288// c-file-style: "gnu"
289// indent-tabs-mode: nil
290// End:
291// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
292

Archive Download this file

Branches

Tags

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