~ubuntu-branches/ubuntu/quantal/aspectc++/quantal

« back to all changes in this revision

Viewing changes to AspectC++/MatchTypeInfos.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
using std::string;
21
21
#include <sstream>
22
22
using std::ostringstream;
23
 
using std::ends;
24
23
 
25
24
#include "Puma/CRecord.h"
26
25
#include "Puma/CEnumInfo.h"
50
49
  // conversion operator might have an undefined result type
51
50
  return ctype->isUndefined ();
52
51
}
 
52
bool MTUndefined::matches (const MatchType &type) const {
 
53
  // conversion operator might have an undefined result type
 
54
  return type == *this; // true if both object types are equal
 
55
}
53
56
 
54
57
// print the string representation of this qualified type
55
58
void MTQual::print_qual (ostream &out) const {
74
77
  }
75
78
  return true;
76
79
}
 
80
bool MTQual::qual_matches (const MTQual *qual) const {
 
81
  if (!qual && is_qualified ())
 
82
    return false;
 
83
  if (qual) {
 
84
    if (_const && !qual->is_const ())
 
85
        return false;
 
86
    if (_volatile && !qual->is_volatile ())
 
87
        return false;
 
88
  }
 
89
  return true;
 
90
}
 
91
 
77
92
 
78
93
// print the string representation of this primitive type
79
94
// inner might be a name, prefix == true means that the name has prefix
113
128
  CTypeEnum *ectype = ctype->TypeEnum ();
114
129
  return ectype && _name.matches (ectype->EnumInfo ()) && qual_matches (qtype); 
115
130
}
 
131
bool MTNamed::matches (const MatchType &type) const {
 
132
  if (type != *this)
 
133
    return false;
 
134
  MTNamed &matched_type = (MTNamed&)type;
 
135
  return _name.matches (matched_type._name) &&
 
136
    qual_matches (matched_type.qualified ());
 
137
}
116
138
 
117
139
 
118
140
MTPointer *MTPointer::clone () const {
131
153
  }
132
154
  if (inner)
133
155
    declarator << inner;
134
 
  declarator << ends;
135
156
  if (base ())
136
157
    base ()->print (out, declarator.str ().c_str (), true);
137
158
  else
144
165
  return pctype && base ()->matches (pctype->BaseType ()) &&
145
166
         qual_matches (qtype);
146
167
}
 
168
bool MTPointer::matches (const MatchType &type) const {
 
169
  if (type != *this)
 
170
    return false;
 
171
  MTPointer &matched_type = (MTPointer&)type;
 
172
  return base ()->matches (*matched_type.base ()) &&
 
173
    qual_matches (matched_type.qualified ());
 
174
}
147
175
 
148
176
 
149
177
MTMembPointer *MTMembPointer::clone () const {
162
190
  }
163
191
  if (inner)
164
192
    declarator << inner;
165
 
  declarator << ends;
166
193
  if (base ())
167
194
    base ()->print (out, declarator.str ().c_str (), true);
168
195
  else
177
204
         qual_matches (qtype) && 
178
205
         _memb_ptr_scope.scope_matches (mpctype->Record ());
179
206
}
 
207
bool MTMembPointer::matches (const MatchType &type) const {
 
208
  if (type != *this)
 
209
    return false;
 
210
  MTMembPointer &matched_type = (MTMembPointer&)type;
 
211
  return base ()->matches (*matched_type.base ()) &&
 
212
    qual_matches (matched_type.qualified ()) &&
 
213
    _memb_ptr_scope.matches (matched_type._memb_ptr_scope);
 
214
}
180
215
 
181
216
MTReference *MTReference::clone () const {
182
217
  return new MTReference (*this);
189
224
  declarator << "&";
190
225
  if (inner)
191
226
    declarator << inner;
192
 
  declarator << ends;
193
227
  if (base ())
194
228
    base ()->print (out, declarator.str ().c_str (), true);
195
229
  else
199
233
bool MTReference::matches (CTypeInfo *ctype) const {
200
234
  return ctype->TypeAddress () && base ()->matches (ctype->BaseType ());
201
235
}
 
236
bool MTReference::matches (const MatchType &type) const {
 
237
  return type == *this && base ()->matches (*type.base ());
 
238
}
202
239
 
203
240
//MTFunction::~MTFunction () {
204
241
//  for (int a = 0; a < args (); a++)
229
266
    print_qual (declarator);
230
267
    declarator << " ";
231
268
  }
232
 
  declarator << ends;
233
269
  if (base ())
234
270
    base ()->print (out, declarator.str ().c_str (), false);
235
271
  else
255
291
  // finally check the result type
256
292
  return base ()->matches (cftype->ReturnType ());  
257
293
}
 
294
bool MTFunction::matches (const MatchType &type) const {
 
295
  // check if it's a function type
 
296
  if (type != *this)
 
297
    return false;
 
298
  const MTFunction &matched_type = (MTFunction&)type;
 
299
  // check the type qualifier
 
300
  if (!qual_matches (matched_type.qualified ()))
 
301
    return false;
 
302
  // check the argument types
 
303
  int matched_args = matched_type.args ();
 
304
  // TODO: what about matched functions with varargs?
 
305
  if ((!_varargs && args () != matched_args) || (args () > matched_args))
 
306
    return false;
 
307
  for (int a = 0; a < args (); a++)
 
308
    if (!arg (a).matches (matched_type.arg (a)))
 
309
      return false;
 
310
  // finally check the result type
 
311
  return base ()->matches (*matched_type.base ());  
 
312
}
258
313
 
259
314
// adjust the argument types according to �8.3.5.2 and �8.3.5.3 of ISO C++
260
315
void MTFunction::adjust_args (bool &f, bool &a, bool &q, bool &v) {
313
368
    declarator << "%";
314
369
  else
315
370
    declarator << _dim;
316
 
  declarator << "]" << ends;
 
371
  declarator << "]";
317
372
  if (base ())
318
373
    base ()->print (out, declarator.str ().c_str (), false);
319
374
  else
326
381
  return actype && base ()->matches (ctype->BaseType ()) &&
327
382
         (_any_size || actype->Dimension () == (long)_dim);
328
383
}
 
384
bool MTArray::matches (const MatchType &type) const {
 
385
  if (type != *this)
 
386
    return false;
 
387
  MTArray &matched_type = (MTArray&)type;
 
388
  return base ()->matches (*matched_type.base ()) &&
 
389
    (_any_size || _dim == matched_type._dim);
 
390
}
329
391
 
330
392
MTAny *MTAny::clone () const {
331
393
  return new MTAny (*this);
334
396
bool MTAny::matches (CTypeInfo *ctype) const {
335
397
  return qual_matches (ctype->TypeQualified ());
336
398
}
 
399
bool MTAny::matches (const MatchType &type) const {
 
400
  return qual_matches (type.qualified ());
 
401
}
337
402
 
338
403
MTBool *MTBool::clone () const {
339
404
  return new MTBool (*this);
343
408
bool MTBool::matches (CTypeInfo *ctype) const {
344
409
  return ctype->UnqualType ()->is_bool () && qual_matches (ctype->TypeQualified ());
345
410
}
 
411
bool MTBool::matches (const MatchType &type) const {
 
412
  return type == *this && qual_matches (type.qualified ());
 
413
}
346
414
 
347
415
MTSignedChar *MTSignedChar::clone () const {
348
416
  return new MTSignedChar (*this);
351
419
bool MTSignedChar::matches (CTypeInfo *ctype) const {
352
420
  return ctype->UnqualType ()->is_signed_char () && qual_matches (ctype->TypeQualified ());
353
421
}
 
422
bool MTSignedChar::matches (const MatchType &type) const {
 
423
  return type == *this && qual_matches (type.qualified ());
 
424
}
354
425
 
355
426
MTUnsignedChar *MTUnsignedChar::clone () const {
356
427
  return new MTUnsignedChar (*this);
359
430
bool MTUnsignedChar::matches (CTypeInfo *ctype) const {
360
431
  return ctype->UnqualType ()->is_unsigned_char () && qual_matches (ctype->TypeQualified ());
361
432
}
 
433
bool MTUnsignedChar::matches (const MatchType &type) const {
 
434
  return type == *this && qual_matches (type.qualified ());
 
435
}
362
436
 
363
437
MTChar *MTChar::clone () const {
364
438
  return new MTChar (*this);
367
441
bool MTChar::matches (CTypeInfo *ctype) const {
368
442
  return ctype->UnqualType ()->is_char () && qual_matches (ctype->TypeQualified ());
369
443
}
 
444
bool MTChar::matches (const MatchType &type) const {
 
445
  return type == *this && qual_matches (type.qualified ());
 
446
}
370
447
 
371
448
MTUnsignedShort *MTUnsignedShort::clone () const {
372
449
  return new MTUnsignedShort (*this);
375
452
bool MTUnsignedShort::matches (CTypeInfo *ctype) const {
376
453
  return ctype->UnqualType ()->is_unsigned_short () && qual_matches (ctype->TypeQualified ());
377
454
}
 
455
bool MTUnsignedShort::matches (const MatchType &type) const {
 
456
  return type == *this && qual_matches (type.qualified ());
 
457
}
378
458
 
379
459
MTShort *MTShort::clone () const {
380
460
  return new MTShort (*this);
383
463
bool MTShort::matches (CTypeInfo *ctype) const {
384
464
  return ctype->UnqualType ()->is_short () && qual_matches (ctype->TypeQualified ());
385
465
}
 
466
bool MTShort::matches (const MatchType &type) const {
 
467
  return type == *this && qual_matches (type.qualified ());
 
468
}
386
469
 
387
470
MTUnsignedInt *MTUnsignedInt::clone () const {
388
471
  return new MTUnsignedInt (*this);
391
474
bool MTUnsignedInt::matches (CTypeInfo *ctype) const {
392
475
  return ctype->UnqualType ()->is_unsigned_int () && qual_matches (ctype->TypeQualified ());
393
476
}
 
477
bool MTUnsignedInt::matches (const MatchType &type) const {
 
478
  return type == *this && qual_matches (type.qualified ());
 
479
}
394
480
 
395
481
MTInt *MTInt::clone () const {
396
482
  return new MTInt (*this);
399
485
bool MTInt::matches (CTypeInfo *ctype) const {
400
486
  return ctype->UnqualType ()->is_int () && qual_matches (ctype->TypeQualified ());
401
487
}
 
488
bool MTInt::matches (const MatchType &type) const {
 
489
  return type == *this && qual_matches (type.qualified ());
 
490
}
402
491
 
403
492
MTWCharT *MTWCharT::clone () const {
404
493
  return new MTWCharT (*this);
407
496
bool MTWCharT::matches (CTypeInfo *ctype) const {
408
497
  return ctype->UnqualType ()->is_wchar_t () && qual_matches (ctype->TypeQualified ());
409
498
}
 
499
bool MTWCharT::matches (const MatchType &type) const {
 
500
  return type == *this && qual_matches (type.qualified ());
 
501
}
410
502
 
411
503
MTUnsignedLong *MTUnsignedLong::clone () const {
412
504
  return new MTUnsignedLong (*this);
415
507
bool MTUnsignedLong::matches (CTypeInfo *ctype) const {
416
508
  return ctype->UnqualType ()->is_unsigned_long () && qual_matches (ctype->TypeQualified ());
417
509
}
 
510
bool MTUnsignedLong::matches (const MatchType &type) const {
 
511
  return type == *this && qual_matches (type.qualified ());
 
512
}
418
513
 
419
514
MTLong *MTLong::clone () const {
420
515
  return new MTLong (*this);
423
518
bool MTLong::matches (CTypeInfo *ctype) const {
424
519
  return ctype->UnqualType ()->is_long () && qual_matches (ctype->TypeQualified ());
425
520
}
 
521
bool MTLong::matches (const MatchType &type) const {
 
522
  return type == *this && qual_matches (type.qualified ());
 
523
}
426
524
 
427
525
MTUnsignedLongLong *MTUnsignedLongLong::clone () const {
428
526
  return new MTUnsignedLongLong (*this);
431
529
bool MTUnsignedLongLong::matches (CTypeInfo *ctype) const {
432
530
  return ctype->UnqualType ()->is_unsigned_long_long () && qual_matches (ctype->TypeQualified ());
433
531
}
 
532
bool MTUnsignedLongLong::matches (const MatchType &type) const {
 
533
  return type == *this && qual_matches (type.qualified ());
 
534
}
434
535
 
435
536
MTLongLong *MTLongLong::clone () const {
436
537
  return new MTLongLong (*this);
439
540
bool MTLongLong::matches (CTypeInfo *ctype) const {
440
541
  return ctype->UnqualType ()->is_long_long () && qual_matches (ctype->TypeQualified ());
441
542
}
 
543
bool MTLongLong::matches (const MatchType &type) const {
 
544
  return type == *this && qual_matches (type.qualified ());
 
545
}
442
546
 
443
547
MTFloat *MTFloat::clone () const {
444
548
  return new MTFloat (*this);
447
551
bool MTFloat::matches (CTypeInfo *ctype) const {
448
552
  return ctype->UnqualType ()->is_float () && qual_matches (ctype->TypeQualified ());
449
553
}
 
554
bool MTFloat::matches (const MatchType &type) const {
 
555
  return type == *this && qual_matches (type.qualified ());
 
556
}
450
557
 
451
558
MTDouble *MTDouble::clone () const {
452
559
  return new MTDouble (*this);
455
562
bool MTDouble::matches (CTypeInfo *ctype) const {
456
563
  return ctype->UnqualType ()->is_double () && qual_matches (ctype->TypeQualified ());
457
564
}
 
565
bool MTDouble::matches (const MatchType &type) const {
 
566
  return type == *this && qual_matches (type.qualified ());
 
567
}
458
568
 
459
569
MTLongDouble *MTLongDouble::clone () const {
460
570
  return new MTLongDouble (*this);
463
573
bool MTLongDouble::matches (CTypeInfo *ctype) const {
464
574
  return ctype->UnqualType ()->is_long_double () && qual_matches (ctype->TypeQualified ());
465
575
}
 
576
bool MTLongDouble::matches (const MatchType &type) const {
 
577
  return type == *this && qual_matches (type.qualified ());
 
578
}
466
579
 
467
580
MTVoid *MTVoid::clone () const {
468
581
  return new MTVoid (*this);
471
584
bool MTVoid::matches (CTypeInfo *ctype) const {
472
585
  return ctype->UnqualType ()->is_void () && qual_matches (ctype->TypeQualified ());
473
586
}
 
587
bool MTVoid::matches (const MatchType &type) const {
 
588
  return type == *this && qual_matches (type.qualified ());
 
589
}
474
590
 
475
591
// type ids
476
592
MatchType::TID MTUndefined::_tid = "<undefined>";