~siretart/aspectc++/debian

« back to all changes in this revision

Viewing changes to AspectC++/ACModel/MatchTypeInfos.h

  • Committer: Reinhard Tartler
  • Date: 2013-10-13 18:20:07 UTC
  • mto: This revision was merged to the branch mainline in revision 101.
  • Revision ID: siretart@tauware.de-20131013182007-qc3ibv60inzzk8l4
Tags: upstream-1.2
Import upstream version 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of the AspectC++ compiler 'ac++'.
 
2
// Copyright (C) 1999-2003  The 'ac++' developers (see aspectc.org)
 
3
//                                                                
 
4
// This program is free software;  you can redistribute it and/or 
 
5
// modify it under the terms of the GNU General Public License as 
 
6
// published by the Free Software Foundation; either version 2 of 
 
7
// the License, or (at your option) any later version.            
 
8
//                                                                
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 
12
// GNU General Public License for more details.                   
 
13
//                                                                
 
14
// You should have received a copy of the GNU General Public      
 
15
// License along with this program; if not, write to the Free     
 
16
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 
17
// MA  02111-1307  USA                                            
 
18
 
 
19
#ifndef __MatchTypeInfos_h__
 
20
#define __MatchTypeInfos_h__
 
21
 
 
22
#include <iostream>
 
23
using std::ostream;
 
24
using std::endl;
 
25
#include <vector>
 
26
using std::vector;
 
27
 
 
28
#include "MatchType.h"
 
29
#include "MatchName.h"
 
30
 
 
31
// functions without result type (conversion operators) have this type
 
32
class MTUndefined : public MatchType {
 
33
  static TID _tid;
 
34
 
 
35
protected:
 
36
  virtual TID type () const;
 
37
public:
 
38
  virtual MTUndefined *clone () const;
 
39
  virtual void print (ostream &, const char* = 0, bool = false) const;
 
40
  virtual bool matches (const MatchType &type) const;
 
41
};
 
42
 
 
43
// commonalities of all types made by declarators
 
44
class MTDeclarator : public MatchType {
 
45
  MatchType *_base;
 
46
  static TID _tid;
 
47
 
 
48
protected:
 
49
  virtual TID type () const;
 
50
  // only derived types may construct/destruct a declarator type
 
51
  MTDeclarator (MatchType *b) : _base (b) {}
 
52
  MTDeclarator (const MTDeclarator &copy) { *this = copy; }
 
53
  MTDeclarator &operator = (const MTDeclarator &copy) {
 
54
    _base = copy._base->clone ();
 
55
    return *this;
 
56
  }
 
57
  ~MTDeclarator () { delete _base; }
 
58
  
 
59
public:
 
60
  // set and get the base type
 
61
  virtual MatchType *base () const { return _base; }
 
62
  // adjust the argument types according to �8.3.5.2 and �8.3.5.3 of ISO C++
 
63
  virtual void adjust_args (bool &f, bool &a, bool &q, bool &v) {
 
64
    _base->adjust_args (f, a, q, v);
 
65
  }
 
66
};
 
67
 
 
68
// pointer types
 
69
class MTPointer : public MTDeclarator, public MTQual {
 
70
  static TID _tid;
 
71
 
 
72
protected:
 
73
  virtual TID type () const;
 
74
 
 
75
public:
 
76
  MTPointer (MatchType *b = 0) : MTDeclarator (b) {}
 
77
  // print the string representation of this type
 
78
  virtual MTPointer *clone () const;
 
79
  virtual void print (ostream &, const char* = 0, bool = false) const;
 
80
  virtual void mangle (ostream &) const;
 
81
  virtual bool matches (const MatchType &type) const;
 
82
  virtual MTQual *qualified () { return this; }
 
83
  virtual const MTQual *qualified () const { return this; }
 
84
};
 
85
 
 
86
// member pointer types
 
87
class MTMembPointer : public MTPointer {
 
88
  static TID _tid;
 
89
  mutable MatchName _memb_ptr_scope;
 
90
 
 
91
protected:
 
92
  virtual TID type () const;
 
93
 
 
94
public:
 
95
  MTMembPointer (const MatchName &mps, MatchType *b = 0) :
 
96
    MTPointer (b), _memb_ptr_scope (mps) {}
 
97
  virtual MTMembPointer *clone () const;
 
98
  // print the string representation of this type
 
99
  virtual void print (ostream &, const char* = 0, bool = false) const;
 
100
  virtual void mangle (ostream &) const;
 
101
  virtual bool matches (const MatchType &type) const;
 
102
};
 
103
 
 
104
 
 
105
// reference types
 
106
class MTReference : public MTDeclarator {
 
107
  static TID _tid;
 
108
 
 
109
protected:
 
110
  virtual TID type () const;
 
111
 
 
112
public:
 
113
  MTReference (MatchType *b = 0) : MTDeclarator (b) {}
 
114
  virtual MTReference *clone () const;
 
115
  // print the string representation of this type
 
116
  virtual void print (ostream &, const char* = 0, bool = false) const;
 
117
  virtual void mangle (ostream &) const;
 
118
  virtual bool matches (const MatchType &type) const;
 
119
  virtual bool is_reference () const { return true; }
 
120
};
 
121
 
 
122
// function types
 
123
class MTFunction : public MTDeclarator, public MTQual {
 
124
  static TID _tid;
 
125
  vector<MatchTypeRef> _arg_types;
 
126
  bool _varargs;
 
127
 
 
128
protected:
 
129
  virtual TID type () const;
 
130
 
 
131
public:
 
132
  MTFunction (MatchType *b = 0) : MTDeclarator (b), _varargs (false) {}
 
133
  MTFunction (const vector<MatchTypeRef> &args, bool va, MatchType *b) :
 
134
    MTDeclarator (b), _arg_types (args), _varargs (va) {}
 
135
//  virtual ~MTFunction ();
 
136
  virtual MTFunction *clone () const;
 
137
  // print the string representation of this type
 
138
  virtual void print (ostream &, const char* = 0, bool = false) const;
 
139
  // print the 'mangled' string representation of this type
 
140
  virtual void mangle (ostream &os) const;
 
141
  virtual bool is_function () const { return true; }
 
142
  void varargs () { _varargs = true; }
 
143
  bool varargs () const { return _varargs; }
 
144
  int args () const { return (int)_arg_types.size (); }
 
145
  void arg (MatchTypeRef a) { _arg_types.push_back (a); }
 
146
  const MatchTypeRef &arg (int index) const { return _arg_types[index]; }
 
147
  // perform a type match
 
148
  virtual bool matches (const MatchType &type) const;
 
149
  // adjust the argument types according to �8.3.5.2 and �8.3.5.3 of ISO C++
 
150
  virtual void adjust_args (bool &f, bool &a, bool &q, bool &v);
 
151
  virtual MTQual *qualified () { return this; }
 
152
  virtual const MTQual *qualified () const { return this; }
 
153
};
 
154
 
 
155
// array types
 
156
class MTArray : public MTDeclarator {
 
157
  static TID _tid;
 
158
  unsigned long _dim;
 
159
  bool _any_size;
 
160
  
 
161
protected:
 
162
  virtual TID type () const;
 
163
 
 
164
public:
 
165
  MTArray (MatchType *b) : MTDeclarator (b), _dim (0uL),
 
166
    _any_size (true) {}
 
167
  MTArray (unsigned long dim, MatchType *b) : MTDeclarator (b), _dim (dim),
 
168
    _any_size (false) {}
 
169
  virtual MTArray *clone () const;
 
170
  // print the string representation of this type
 
171
  virtual void print (ostream &, const char* = 0, bool = false) const;
 
172
  // print the 'mangled' string representation of this type
 
173
  virtual void mangle (ostream &os) const;
 
174
  void dimension (unsigned long d) { _dim = d; }
 
175
  unsigned long dimension () const { return _dim; }
 
176
  void any_size () { _any_size = true; }
 
177
  bool any_size () const { return _any_size; }
 
178
  virtual bool matches (const MatchType &type) const;
 
179
  virtual bool is_array () const { return true; }
 
180
};
 
181
 
 
182
// user-defined names types
 
183
class MTNamed : public MatchType, public MTQual {
 
184
  mutable MatchName _name;
 
185
  static TID _tid;
 
186
protected:
 
187
  virtual TID type () const;
 
188
public:
 
189
  MTNamed (const MatchName &mn) : _name (mn) {}
 
190
  virtual MTNamed *clone () const;
 
191
  // print the string representation of this type
 
192
  virtual void print (ostream &, const char* = 0, bool = false) const;
 
193
  // print the 'mangled' string representation of this type
 
194
  virtual void mangle (ostream &os) const;
 
195
  const MatchName &name () const { return _name; }
 
196
  // perform a type match
 
197
  virtual bool matches (const MatchType &type) const;
 
198
  virtual MTQual *qualified () { return this; }
 
199
  virtual const MTQual *qualified () const { return this; }
 
200
  // check whether this type mattern can only match a single name type
 
201
  virtual bool is_trivial_match () const { return _name.is_trivial(); }
 
202
};
 
203
 
 
204
//! commonalities of all primitive types
 
205
class MTPrim : public MatchType, public MTQual {
 
206
public:
 
207
  //! print the string representation of this type
 
208
  virtual void print (ostream &, const char* = 0, bool = false) const;
 
209
  virtual MTQual *qualified () { return this; }
 
210
  virtual const MTQual *qualified () const { return this; }
 
211
  virtual bool is_primitive () const { return true; }
 
212
  // print the 'mangled' string representation of this type
 
213
  virtual void mangle (ostream &os) const;
 
214
};  
 
215
 
 
216
// type <any> (used for matching types>
 
217
class MTAny : public MTPrim {
 
218
  static TID _tid;
 
219
protected:
 
220
  virtual TID type () const;
 
221
public:
 
222
  virtual MTAny *clone () const;
 
223
  // perform a type match
 
224
  virtual bool matches (const MatchType &type) const;
 
225
  virtual void mangle (ostream &os) const;
 
226
};
 
227
 
 
228
// type bool
 
229
class MTBool : public MTPrim {
 
230
  static TID _tid;
 
231
protected:
 
232
  virtual MTBool *clone () const;
 
233
  virtual TID type () const;
 
234
  virtual bool matches (const MatchType &type) const;
 
235
  virtual void mangle (ostream &os) const;
 
236
};
 
237
 
 
238
// type signed char
 
239
class MTSignedChar : public MTPrim {
 
240
  static TID _tid;
 
241
protected:
 
242
  virtual MTSignedChar *clone () const;
 
243
  virtual TID type () const;
 
244
  virtual bool matches (const MatchType &type) const;
 
245
  virtual void mangle (ostream &os) const;
 
246
};
 
247
 
 
248
// type ungined char
 
249
class MTUnsignedChar : public MTPrim {
 
250
  static TID _tid;
 
251
protected:
 
252
  virtual MTUnsignedChar *clone () const;
 
253
  virtual TID type () const;
 
254
  virtual bool matches (const MatchType &type) const;
 
255
  virtual void mangle (ostream &os) const;
 
256
};
 
257
 
 
258
// type char
 
259
class MTChar : public MTPrim {
 
260
  static TID _tid;
 
261
protected:
 
262
  virtual MTChar *clone () const;
 
263
  virtual TID type () const;
 
264
  virtual bool matches (const MatchType &type) const;
 
265
  virtual void mangle (ostream &os) const;
 
266
};
 
267
 
 
268
// type unsigned short
 
269
class MTUnsignedShort : public MTPrim {
 
270
  static TID _tid;
 
271
protected:
 
272
  virtual MTUnsignedShort *clone () const;
 
273
  virtual TID type () const;
 
274
  virtual bool matches (const MatchType &type) const;
 
275
  virtual void mangle (ostream &os) const;
 
276
};
 
277
 
 
278
// type short
 
279
class MTShort : public MTPrim {
 
280
  static TID _tid;
 
281
protected:
 
282
  virtual MTShort *clone () const;
 
283
  virtual TID type () const;
 
284
  virtual bool matches (const MatchType &type) const;
 
285
  virtual void mangle (ostream &os) const;
 
286
};
 
287
 
 
288
// type unsigned int
 
289
class MTUnsignedInt : public MTPrim {
 
290
  static TID _tid;
 
291
protected:
 
292
  virtual MTUnsignedInt *clone () const;
 
293
  virtual TID type () const;
 
294
  virtual bool matches (const MatchType &type) const;
 
295
  virtual void mangle (ostream &os) const;
 
296
};
 
297
 
 
298
// type int
 
299
class MTInt : public MTPrim {
 
300
  static TID _tid;
 
301
protected:
 
302
  virtual MTInt *clone () const;
 
303
  virtual TID type () const;
 
304
  virtual bool matches (const MatchType &type) const;
 
305
  virtual void mangle (ostream &os) const;
 
306
};
 
307
 
 
308
// type wchar_t
 
309
class MTWCharT : public MTPrim {
 
310
  static TID _tid;
 
311
protected:
 
312
  virtual MTWCharT *clone () const;
 
313
  virtual TID type () const;
 
314
  virtual bool matches (const MatchType &type) const;
 
315
  virtual void mangle (ostream &os) const;
 
316
};
 
317
 
 
318
// type unsigned long
 
319
class MTUnsignedLong : public MTPrim {
 
320
  static TID _tid;
 
321
protected:
 
322
  virtual MTUnsignedLong *clone () const;
 
323
  virtual TID type () const;
 
324
  virtual bool matches (const MatchType &type) const;
 
325
  virtual void mangle (ostream &os) const;
 
326
};
 
327
 
 
328
// type long
 
329
class MTLong : public MTPrim {
 
330
  static TID _tid;
 
331
protected:
 
332
  virtual MTLong *clone () const;
 
333
  virtual TID type () const;
 
334
  virtual bool matches (const MatchType &type) const;
 
335
  virtual void mangle (ostream &os) const;
 
336
};
 
337
 
 
338
// type unsigned long long
 
339
class MTUnsignedLongLong : public MTPrim {
 
340
  static TID _tid;
 
341
protected:
 
342
  virtual MTUnsignedLongLong *clone () const;
 
343
  virtual TID type () const;
 
344
  virtual bool matches (const MatchType &type) const;
 
345
  virtual void mangle (ostream &os) const;
 
346
};
 
347
 
 
348
// type long long
 
349
class MTLongLong : public MTPrim {
 
350
  static TID _tid;
 
351
protected:
 
352
  virtual MTLongLong *clone () const;
 
353
  virtual TID type () const;
 
354
  virtual bool matches (const MatchType &type) const;
 
355
  virtual void mangle (ostream &os) const;
 
356
};
 
357
 
 
358
// type float
 
359
class MTFloat : public MTPrim {
 
360
  static TID _tid;
 
361
protected:
 
362
  virtual MTFloat *clone () const;
 
363
  virtual TID type () const;
 
364
  virtual bool matches (const MatchType &type) const;
 
365
  virtual void mangle (ostream &os) const;
 
366
};
 
367
 
 
368
// type double
 
369
class MTDouble : public MTPrim {
 
370
  static TID _tid;
 
371
protected:
 
372
  virtual MTDouble *clone () const;
 
373
  virtual TID type () const;
 
374
  virtual bool matches (const MatchType &type) const;
 
375
  virtual void mangle (ostream &os) const;
 
376
};
 
377
 
 
378
// type long double
 
379
class MTLongDouble : public MTPrim {
 
380
  static TID _tid;
 
381
protected:
 
382
  virtual MTLongDouble *clone () const;
 
383
  virtual TID type () const;
 
384
  virtual bool matches (const MatchType &type) const;
 
385
  virtual void mangle (ostream &os) const;
 
386
};
 
387
 
 
388
// type void
 
389
class MTVoid : public MTPrim {
 
390
  static TID _tid;
 
391
protected:
 
392
  virtual MTVoid *clone () const;
 
393
  virtual TID type () const;
 
394
  virtual bool matches (const MatchType &type) const;
 
395
  virtual bool is_void () const { return true; }
 
396
  virtual void mangle (ostream &os) const;
 
397
};
 
398
 
 
399
#endif // __MatchTypeInfos_h__