File: vocab_macros.hh

package info (click to toggle)
monotone 0.48-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 20,096 kB
  • ctags: 8,077
  • sloc: cpp: 81,000; sh: 6,402; perl: 1,241; lisp: 1,045; makefile: 655; python: 566; sql: 112; ansic: 52
file content (308 lines) | stat: -rw-r--r-- 14,556 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
//
// This program is made available under the GNU GPL version 2.0 or
// greater. See the accompanying file COPYING for details.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.

//HH

#define hh_ENCODING(enc)                               \
                                                       \
template<typename INNER>                               \
class enc;                                             \
                                                       \
template <typename INNER>                              \
std::ostream & operator<<(std::ostream &,              \
                          enc<INNER> const &);         \
                                                       \
template <typename INNER>                              \
void dump(enc<INNER> const &, std::string &);          \
                                                       \
template<typename INNER>                               \
class enc : public origin_aware {                      \
  immutable_string s;                                  \
public:                                                \
  enc() {}                                             \
  explicit enc(char const * const s);                  \
  enc(std::string const & s, origin::type m);          \
  enc(enc<INNER> const & other);                       \
  enc<INNER> const &                                   \
  operator=(enc<INNER> const & other);                 \
  std::string const & operator()() const               \
    { return s.get(); }                                \
  bool operator<(enc<INNER> const & x) const           \
    { return s.get() < x.s.get(); }                    \
  bool operator==(enc<INNER> const & x) const          \
    { return s.get() == x.s.get(); }                   \
  bool operator!=(enc<INNER> const & x) const          \
    { return s.get() != x.s.get(); }                   \
  friend std::ostream & operator<< <>(std::ostream &,  \
                                 enc<INNER> const &);  \
};

#define hh_ENCODING_NOVERIFY(enc) hh_ENCODING(enc)


#define hh_DECORATE(dec)                               \
                                                       \
template<typename INNER>                               \
class dec;                                             \
                                                       \
template <typename INNER>                              \
std::ostream & operator<<(std::ostream &,              \
                          dec<INNER> const &);         \
                                                       \
template <typename INNER>                              \
void dump(dec<INNER> const &, std::string &);          \
                                                       \
template<typename INNER>                               \
class dec {                                            \
  INNER i;                                             \
public:                                                \
  dec() {}                                             \
  explicit dec(char const * const s);                  \
  dec(std::string const & s, origin::type m);          \
  explicit dec(INNER const & inner);                   \
  dec(dec<INNER> const & other);                       \
  bool operator<(dec<INNER> const & x) const           \
    { return i < x.i; }                                \
  INNER const & inner() const                          \
    { return i; }                                      \
  dec<INNER> const &                                   \
  operator=(dec<INNER> const & other);                 \
  bool operator==(dec<INNER> const & x) const          \
    { return i == x.i; }                               \
  bool operator!=(dec<INNER> const & x) const          \
    { return !(i == x.i); }                            \
  friend std::ostream & operator<< <>(std::ostream &,  \
                                 dec<INNER> const &);  \
};


#define hh_ATOMIC_HOOKED(ty, hook)                     \
class ty;                                              \
                                                       \
std::ostream & operator<<(std::ostream &, ty const &); \
                                                       \
template <>                                            \
void dump(ty const &, std::string &);                  \
                                                       \
class ty : public origin_aware {                       \
  immutable_string s;                                  \
public:                                                \
  ty() {}                                              \
  explicit ty(char const * const str);                 \
  ty(std::string const & str, origin::type m);         \
  ty(ty const & other);                                \
  ty const & operator=(ty const & other);              \
  std::string const & operator()() const               \
    { return s.get(); }                                \
  bool operator<(ty const & x) const                   \
    { return s.get() < x.s.get(); }                    \
  bool operator==(ty const & x) const                  \
    { return s.get() == x.s.get(); }                   \
  bool operator!=(ty const & x) const                  \
    { return s.get() != x.s.get(); }                   \
  friend std::ostream & operator<<(std::ostream &,     \
                                   ty const &);        \
  hook                                                 \
  struct symtab                                        \
  {                                                    \
    symtab();                                          \
    ~symtab();                                         \
  };                                                   \
};

#define hh_ATOMIC(ty) hh_ATOMIC_HOOKED(ty,)
#define hh_ATOMIC_NOVERIFY(ty) hh_ATOMIC(ty)
#define hh_ATOMIC_BINARY(ty) hh_ATOMIC(ty)

//CC


#define cc_ATOMIC(ty)                        \
                                             \
static symtab_impl ty ## _tab;               \
static size_t ty ## _tab_active = 0;         \
                                             \
ty::ty(char const * const str) :             \
  origin_aware(),                            \
  s((ty ## _tab_active > 0)                  \
    ? (ty ## _tab.unique(str))               \
    : str)                                   \
{ verify(*this); }                           \
                                             \
ty::ty(string const & str,                   \
       origin::type m) :                     \
  origin_aware(m),                           \
  s((ty ## _tab_active > 0)                  \
    ? (ty ## _tab.unique(str))               \
    : str)                                   \
{ verify(*this); }                           \
                                             \
ty::ty(ty const & other) :                   \
  origin_aware(other), s(other.s) {}         \
                                             \
ty const & ty::operator=(ty const & other)   \
{                                            \
  s = other.s;                               \
  made_from = other.made_from;               \
  return *this;                              \
}                                            \
                                             \
std::ostream & operator<<(std::ostream & o,  \
                          ty const & a)      \
{ return (o << a.s.get()); }                 \
                                             \
template <>                                  \
void dump(ty const & obj, std::string & out) \
{ out = obj(); }                             \
                                             \
ty::symtab::symtab()                         \
{ ty ## _tab_active++; }                     \
                                             \
ty::symtab::~symtab()                        \
{                                            \
  I(ty ## _tab_active > 0);                  \
  ty ## _tab_active--;                       \
  if (ty ## _tab_active == 0)                \
    ty ## _tab.clear();                      \
}


#define cc_ATOMIC_NOVERIFY(ty)               \
inline void verify(ty const &) {}            \
cc_ATOMIC(ty)


#define cc_ATOMIC_BINARY(ty)                 \
                                             \
static symtab_impl ty ## _tab;               \
static size_t ty ## _tab_active = 0;         \
                                             \
ty::ty(char const * const str) :             \
  origin_aware(),                            \
  s((ty ## _tab_active > 0)                  \
    ? (ty ## _tab.unique(str))               \
    : str)                                   \
{ verify(*this); }                           \
                                             \
ty::ty(string const & str,                   \
       origin::type m) :                     \
  origin_aware(m),                           \
  s((ty ## _tab_active > 0)                  \
    ? (ty ## _tab.unique(str))               \
    : str)                                   \
{ verify(*this); }                           \
                                             \
ty::ty(ty const & other) :                   \
  origin_aware(other), s(other.s) {}         \
                                             \
ty const & ty::operator=(ty const & other)   \
{                                            \
  s = other.s;                               \
  made_from = other.made_from;               \
  return *this;                              \
}                                            \
                                             \
std::ostream & operator<<(std::ostream & o,  \
                          ty const & a)      \
{ return (o << encode_hexenc(a(), a.made_from)); }      \
                                             \
ty::symtab::symtab()                         \
{ ty ## _tab_active++; }                     \
                                             \
ty::symtab::~symtab()                        \
{                                            \
  I(ty ## _tab_active > 0);                  \
  ty ## _tab_active--;                       \
  if (ty ## _tab_active == 0)                \
    ty ## _tab.clear();                      \
}



#define cc_ENCODING(enc)                                 \
                                                         \
template<typename INNER>                                 \
enc<INNER>::enc(char const * const s) :                  \
  origin_aware(), s(s)                                   \
  { verify(*this); }                                     \
                                                         \
template<typename INNER>                                 \
enc<INNER>::enc(string const & s, origin::type m) :      \
  origin_aware(m), s(s)                                  \
  { verify(*this); }                                     \
                                                         \
template<typename INNER>                                 \
enc<INNER>::enc(enc<INNER> const & other)                \
  : origin_aware(other), s(other.s) {}                   \
                                                         \
template<typename INNER>                                 \
enc<INNER> const &                                       \
enc<INNER>::operator=(enc<INNER> const & other)          \
{                                                        \
  s = other.s;                                           \
  made_from = other.made_from;                           \
  return *this;                                          \
}                                                        \
                                                         \
template <typename INNER>                                \
std::ostream & operator<<(std::ostream & o,              \
                          enc<INNER> const & e)          \
{ return (o << e.s.get()); }                             \
                                                         \
template <typename INNER>                                \
void dump(enc<INNER> const & obj, std::string & out)     \
{ out = obj(); }

#define cc_ENCODING_NOVERIFY(enc)               \
template<typename INNER>                        \
inline void verify(enc<INNER> const &) {}       \
cc_ENCODING(enc)



#define cc_DECORATE(dec)                                 \
                                                         \
template<typename INNER>                                 \
dec<INNER>::dec(dec<INNER> const & other)                \
  : i(other.i) {}                                        \
                                                         \
template<typename INNER>                                 \
dec<INNER>::dec(char const * const s)                    \
  : i(s) { verify(i); }                                  \
                                                         \
template<typename INNER>                                 \
dec<INNER>::dec(std::string const & s,                   \
                origin::type m)                          \
  : i(s, m) { verify(i); }                               \
                                                         \
template<typename INNER>                                 \
dec<INNER>::dec(INNER const & inner)                     \
  : i(inner) {}                                          \
                                                         \
template<typename INNER>                                 \
dec<INNER> const &                                       \
dec<INNER>::operator=(dec<INNER> const & other)          \
  { i = other.i; return *this; }                         \
                                                         \
template <typename INNER>                                \
std::ostream & operator<<(std::ostream & o,              \
                          dec<INNER> const & d)          \
{ return (o << d.i); }                                   \
                                                         \
template <typename INNER>                                \
void dump(dec<INNER> const & obj, std::string & out)     \
{ dump(obj.inner(), out); }

// Local Variables:
// mode: C++
// fill-column: 76
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: