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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
|
// This file is part of the AspectC++ compiler 'ac++'.
// Copyright (C) 1999-2003 The 'ac++' developers (see aspectc.org)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307 USA
#ifndef __MatchTypeInfos_h__
#define __MatchTypeInfos_h__
#include <iostream>
using std::ostream;
using std::endl;
#include <vector>
using std::vector;
#include "MatchType.h"
#include "MatchName.h"
// functions without result type (conversion operators) have this type
class MTUndefined : public MatchType {
static TID _tid;
protected:
virtual TID type () const;
public:
virtual MTUndefined *clone () const;
virtual void print (ostream &, const char* = 0, bool = false) const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// commonalities of all types made by declarators
class MTDeclarator : public MatchType {
MatchType *_base;
static TID _tid;
protected:
virtual TID type () const;
// only derived types may construct/destruct a declarator type
MTDeclarator (MatchType *b) : _base (b) {}
MTDeclarator (const MTDeclarator ©) { *this = copy; }
MTDeclarator &operator = (const MTDeclarator ©) {
_base = copy._base->clone ();
return *this;
}
~MTDeclarator () { delete _base; }
public:
// set and get the base type
virtual MatchType *base () const { return _base; }
// adjust the argument types according to �8.3.5.2 and �8.3.5.3 of ISO C++
virtual void adjust_args (bool &f, bool &a, bool &q, bool &v) {
_base->adjust_args (f, a, q, v);
}
};
// pointer types
class MTPointer : public MTDeclarator, public MTQual {
static TID _tid;
protected:
virtual TID type () const;
public:
MTPointer (MatchType *b = 0) : MTDeclarator (b) {}
// print the string representation of this type
virtual MTPointer *clone () const;
virtual void print (ostream &, const char* = 0, bool = false) const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
virtual MTQual *qualified () { return this; }
virtual const MTQual *qualified () const { return this; }
};
// member pointer types
class MTMembPointer : public MTPointer {
static TID _tid;
mutable MatchName _memb_ptr_scope;
protected:
virtual TID type () const;
public:
MTMembPointer (const MatchName &mps, MatchType *b = 0) :
MTPointer (b), _memb_ptr_scope (mps) {}
virtual MTMembPointer *clone () const;
// print the string representation of this type
virtual void print (ostream &, const char* = 0, bool = false) const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// reference types
class MTReference : public MTDeclarator {
static TID _tid;
protected:
virtual TID type () const;
public:
MTReference (MatchType *b = 0) : MTDeclarator (b) {}
virtual MTReference *clone () const;
// print the string representation of this type
virtual void print (ostream &, const char* = 0, bool = false) const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
virtual bool is_reference () { return true; }
};
// function types
class MTFunction : public MTDeclarator, public MTQual {
static TID _tid;
vector<MatchTypeRef> _arg_types;
bool _varargs;
protected:
virtual TID type () const;
public:
MTFunction (MatchType *b = 0) : MTDeclarator (b), _varargs (false) {}
MTFunction (const vector<MatchTypeRef> &args, bool va, MatchType *b) :
MTDeclarator (b), _arg_types (args), _varargs (va) {}
// virtual ~MTFunction ();
virtual MTFunction *clone () const;
// print the string representation of this type
virtual void print (ostream &, const char* = 0, bool = false) const;
virtual bool is_function () const { return true; }
void varargs () { _varargs = true; }
bool varargs () const { return _varargs; }
int args () const { return (int)_arg_types.size (); }
void arg (MatchTypeRef a) { _arg_types.push_back (a); }
const MatchTypeRef &arg (int index) const { return _arg_types[index]; }
// perform a type match
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
// adjust the argument types according to �8.3.5.2 and �8.3.5.3 of ISO C++
virtual void adjust_args (bool &f, bool &a, bool &q, bool &v);
virtual MTQual *qualified () { return this; }
virtual const MTQual *qualified () const { return this; }
};
// array types
class MTArray : public MTDeclarator {
static TID _tid;
unsigned long _dim;
bool _any_size;
protected:
virtual TID type () const;
public:
MTArray (MatchType *b) : MTDeclarator (b), _dim (0uL),
_any_size (true) {}
MTArray (unsigned long dim, MatchType *b) : MTDeclarator (b), _dim (dim),
_any_size (false) {}
virtual MTArray *clone () const;
// print the string representation of this type
virtual void print (ostream &, const char* = 0, bool = false) const;
void dimension (unsigned long d) { _dim = d; }
unsigned long dimension () const { return _dim; }
void any_size () { _any_size = true; }
bool any_size () const { return _any_size; }
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
virtual bool is_array () const { return true; }
};
// user-defined names types
class MTNamed : public MatchType, public MTQual {
mutable MatchName _name;
static TID _tid;
protected:
virtual TID type () const;
public:
MTNamed (const MatchName &mn) : _name (mn) {}
virtual MTNamed *clone () const;
// print the string representation of this type
virtual void print (ostream &, const char* = 0, bool = false) const;
const MatchName &name () const { return _name; }
// perform a type match
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
virtual MTQual *qualified () { return this; }
virtual const MTQual *qualified () const { return this; }
};
//! commonalities of all primitive types
class MTPrim : public MatchType, public MTQual {
public:
//! print the string representation of this type
virtual void print (ostream &, const char* = 0, bool = false) const;
virtual MTQual *qualified () { return this; }
virtual const MTQual *qualified () const { return this; }
virtual bool is_primitive () const { return true; }
};
// type <any> (used for matching types>
class MTAny : public MTPrim {
static TID _tid;
protected:
virtual TID type () const;
public:
virtual MTAny *clone () const;
// perform a type match
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type bool
class MTBool : public MTPrim {
static TID _tid;
protected:
virtual MTBool *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type signed char
class MTSignedChar : public MTPrim {
static TID _tid;
protected:
virtual MTSignedChar *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type ungined char
class MTUnsignedChar : public MTPrim {
static TID _tid;
protected:
virtual MTUnsignedChar *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type char
class MTChar : public MTPrim {
static TID _tid;
protected:
virtual MTChar *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type unsigned short
class MTUnsignedShort : public MTPrim {
static TID _tid;
protected:
virtual MTUnsignedShort *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type short
class MTShort : public MTPrim {
static TID _tid;
protected:
virtual MTShort *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type unsigned int
class MTUnsignedInt : public MTPrim {
static TID _tid;
protected:
virtual MTUnsignedInt *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type int
class MTInt : public MTPrim {
static TID _tid;
protected:
virtual MTInt *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type wchar_t
class MTWCharT : public MTPrim {
static TID _tid;
protected:
virtual MTWCharT *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type unsigned long
class MTUnsignedLong : public MTPrim {
static TID _tid;
protected:
virtual MTUnsignedLong *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type long
class MTLong : public MTPrim {
static TID _tid;
protected:
virtual MTLong *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type unsigned long long
class MTUnsignedLongLong : public MTPrim {
static TID _tid;
protected:
virtual MTUnsignedLongLong *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type long long
class MTLongLong : public MTPrim {
static TID _tid;
protected:
virtual MTLongLong *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type float
class MTFloat : public MTPrim {
static TID _tid;
protected:
virtual MTFloat *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type double
class MTDouble : public MTPrim {
static TID _tid;
protected:
virtual MTDouble *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type long double
class MTLongDouble : public MTPrim {
static TID _tid;
protected:
virtual MTLongDouble *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
};
// type void
class MTVoid : public MTPrim {
static TID _tid;
protected:
virtual MTVoid *clone () const;
virtual TID type () const;
virtual bool matches (CTypeInfo *ctype) const;
virtual bool matches (const MatchType &type) const;
virtual bool is_void () const { return true; }
};
#endif // __MatchTypeInfos_h__
|