1 | //
|
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
|
---|
3 | //
|
---|
4 | // The contents of this file are covered under the licence agreement in the
|
---|
5 | // file "LICENCE" distributed with Cforall.
|
---|
6 | //
|
---|
7 | // Type.h --
|
---|
8 | //
|
---|
9 | // Author : Richard C. Bilson
|
---|
10 | // Created On : Mon May 18 07:44:20 2015
|
---|
11 | // Last Modified By : Peter A. Buhr
|
---|
12 | // Last Modified On : Wed Jul 13 11:46:54 2016
|
---|
13 | // Update Count : 23
|
---|
14 | //
|
---|
15 |
|
---|
16 | #ifndef TYPE_H
|
---|
17 | #define TYPE_H
|
---|
18 |
|
---|
19 | #include "SynTree.h"
|
---|
20 | #include "Visitor.h"
|
---|
21 | #include "Mutator.h"
|
---|
22 | #include "Common/utility.h"
|
---|
23 |
|
---|
24 | class Type {
|
---|
25 | public:
|
---|
26 | struct Qualifiers {
|
---|
27 | Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {}
|
---|
28 | Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {}
|
---|
29 |
|
---|
30 | Qualifiers &operator&=( const Qualifiers &other );
|
---|
31 | Qualifiers &operator+=( const Qualifiers &other );
|
---|
32 | Qualifiers &operator-=( const Qualifiers &other );
|
---|
33 | Qualifiers operator+( const Type::Qualifiers &other );
|
---|
34 | bool operator==( const Qualifiers &other );
|
---|
35 | bool operator!=( const Qualifiers &other );
|
---|
36 | bool operator<=( const Qualifiers &other );
|
---|
37 | bool operator>=( const Qualifiers &other );
|
---|
38 | bool operator<( const Qualifiers &other );
|
---|
39 | bool operator>( const Qualifiers &other );
|
---|
40 | void print( std::ostream &os, int indent = 0 ) const;
|
---|
41 |
|
---|
42 | bool isConst;
|
---|
43 | bool isVolatile;
|
---|
44 | bool isRestrict;
|
---|
45 | bool isLvalue;
|
---|
46 | bool isAtomic;
|
---|
47 | bool isAttribute;
|
---|
48 | };
|
---|
49 |
|
---|
50 | Type( const Qualifiers &tq );
|
---|
51 | Type( const Type &other );
|
---|
52 | virtual ~Type();
|
---|
53 |
|
---|
54 | Qualifiers &get_qualifiers() { return tq; }
|
---|
55 | bool get_isConst() { return tq.isConst; }
|
---|
56 | bool get_isVolatile() { return tq.isVolatile; }
|
---|
57 | bool get_isRestrict() { return tq.isRestrict; }
|
---|
58 | bool get_isLvalue() { return tq.isLvalue; }
|
---|
59 | bool get_isAtomic() { return tq.isAtomic; }
|
---|
60 | bool get_isAttribute() { return tq.isAttribute; }
|
---|
61 | void set_isConst( bool newValue ) { tq.isConst = newValue; }
|
---|
62 | void set_isVolatile( bool newValue ) { tq.isVolatile = newValue; }
|
---|
63 | void set_isRestrict( bool newValue ) { tq.isRestrict = newValue; }
|
---|
64 | void set_isLvalue( bool newValue ) { tq.isLvalue = newValue; }
|
---|
65 | void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; }
|
---|
66 | void set_isAttribute( bool newValue ) { tq.isAttribute = newValue; }
|
---|
67 |
|
---|
68 | typedef std::list<TypeDecl *> ForallList;
|
---|
69 | ForallList& get_forall() { return forall; }
|
---|
70 |
|
---|
71 | /// How many elemental types are represented by this type
|
---|
72 | virtual unsigned size() const { return 1; };
|
---|
73 | virtual bool isVoid() const { return size() == 0; }
|
---|
74 |
|
---|
75 | virtual Type *clone() const = 0;
|
---|
76 | virtual void accept( Visitor &v ) = 0;
|
---|
77 | virtual Type *acceptMutator( Mutator &m ) = 0;
|
---|
78 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
79 | private:
|
---|
80 | Qualifiers tq;
|
---|
81 | ForallList forall;
|
---|
82 | };
|
---|
83 |
|
---|
84 | class VoidType : public Type {
|
---|
85 | public:
|
---|
86 | VoidType( const Type::Qualifiers &tq );
|
---|
87 |
|
---|
88 | virtual unsigned size() const { return 0; };
|
---|
89 |
|
---|
90 | virtual VoidType *clone() const { return new VoidType( *this ); }
|
---|
91 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
92 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
93 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
94 | };
|
---|
95 |
|
---|
96 | class BasicType : public Type {
|
---|
97 | public:
|
---|
98 | enum Kind {
|
---|
99 | Bool,
|
---|
100 | Char,
|
---|
101 | SignedChar,
|
---|
102 | UnsignedChar,
|
---|
103 | ShortSignedInt,
|
---|
104 | ShortUnsignedInt,
|
---|
105 | SignedInt,
|
---|
106 | UnsignedInt,
|
---|
107 | LongSignedInt,
|
---|
108 | LongUnsignedInt,
|
---|
109 | LongLongSignedInt,
|
---|
110 | LongLongUnsignedInt,
|
---|
111 | Float,
|
---|
112 | Double,
|
---|
113 | LongDouble,
|
---|
114 | FloatComplex,
|
---|
115 | DoubleComplex,
|
---|
116 | LongDoubleComplex,
|
---|
117 | FloatImaginary,
|
---|
118 | DoubleImaginary,
|
---|
119 | LongDoubleImaginary,
|
---|
120 | NUMBER_OF_BASIC_TYPES
|
---|
121 | };
|
---|
122 |
|
---|
123 | static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind
|
---|
124 |
|
---|
125 | BasicType( const Type::Qualifiers &tq, Kind bt );
|
---|
126 |
|
---|
127 | Kind get_kind() { return kind; }
|
---|
128 | void set_kind( Kind newValue ) { kind = newValue; }
|
---|
129 |
|
---|
130 | virtual BasicType *clone() const { return new BasicType( *this ); }
|
---|
131 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
132 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
133 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
134 |
|
---|
135 | bool isInteger() const;
|
---|
136 | private:
|
---|
137 | Kind kind;
|
---|
138 | };
|
---|
139 |
|
---|
140 | class PointerType : public Type {
|
---|
141 | public:
|
---|
142 | PointerType( const Type::Qualifiers &tq, Type *base );
|
---|
143 | PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
|
---|
144 | PointerType( const PointerType& );
|
---|
145 | virtual ~PointerType();
|
---|
146 |
|
---|
147 | Type *get_base() { return base; }
|
---|
148 | void set_base( Type *newValue ) { base = newValue; }
|
---|
149 | Expression *get_dimension() { return dimension; }
|
---|
150 | void set_dimension( Expression *newValue ) { dimension = newValue; }
|
---|
151 | bool get_isVarLen() { return isVarLen; }
|
---|
152 | void set_isVarLen( bool newValue ) { isVarLen = newValue; }
|
---|
153 | bool get_isStatic() { return isStatic; }
|
---|
154 | void set_isStatic( bool newValue ) { isStatic = newValue; }
|
---|
155 |
|
---|
156 | virtual PointerType *clone() const { return new PointerType( *this ); }
|
---|
157 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
158 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
159 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
160 | private:
|
---|
161 | Type *base;
|
---|
162 |
|
---|
163 | // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
|
---|
164 | Expression *dimension;
|
---|
165 | bool isVarLen;
|
---|
166 | bool isStatic;
|
---|
167 | };
|
---|
168 |
|
---|
169 | class ArrayType : public Type {
|
---|
170 | public:
|
---|
171 | ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
|
---|
172 | ArrayType( const ArrayType& );
|
---|
173 | virtual ~ArrayType();
|
---|
174 |
|
---|
175 | Type *get_base() { return base; }
|
---|
176 | void set_base( Type *newValue ) { base = newValue; }
|
---|
177 | Expression *get_dimension() { return dimension; }
|
---|
178 | void set_dimension( Expression *newValue ) { dimension = newValue; }
|
---|
179 | bool get_isVarLen() { return isVarLen; }
|
---|
180 | void set_isVarLen( bool newValue ) { isVarLen = newValue; }
|
---|
181 | bool get_isStatic() { return isStatic; }
|
---|
182 | void set_isStatic( bool newValue ) { isStatic = newValue; }
|
---|
183 |
|
---|
184 | virtual ArrayType *clone() const { return new ArrayType( *this ); }
|
---|
185 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
186 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
187 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
188 | private:
|
---|
189 | Type *base;
|
---|
190 | Expression *dimension;
|
---|
191 | bool isVarLen;
|
---|
192 | bool isStatic;
|
---|
193 | };
|
---|
194 |
|
---|
195 | class FunctionType : public Type {
|
---|
196 | public:
|
---|
197 | FunctionType( const Type::Qualifiers &tq, bool isVarArgs );
|
---|
198 | FunctionType( const FunctionType& );
|
---|
199 | virtual ~FunctionType();
|
---|
200 |
|
---|
201 | std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
|
---|
202 | std::list<DeclarationWithType*> & get_parameters() { return parameters; }
|
---|
203 | bool get_isVarArgs() { return isVarArgs; }
|
---|
204 | void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
|
---|
205 |
|
---|
206 | virtual FunctionType *clone() const { return new FunctionType( *this ); }
|
---|
207 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
208 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
209 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
210 | private:
|
---|
211 | std::list<DeclarationWithType*> returnVals;
|
---|
212 | std::list<DeclarationWithType*> parameters;
|
---|
213 |
|
---|
214 | // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
|
---|
215 | // This could be because of
|
---|
216 | // - an ellipsis in a prototype declaration
|
---|
217 | // - an unprototyped declaration
|
---|
218 | bool isVarArgs;
|
---|
219 | };
|
---|
220 |
|
---|
221 | class ReferenceToType : public Type {
|
---|
222 | public:
|
---|
223 | ReferenceToType( const Type::Qualifiers &tq, const std::string &name );
|
---|
224 | ReferenceToType( const ReferenceToType &other );
|
---|
225 | virtual ~ReferenceToType();
|
---|
226 |
|
---|
227 | const std::string &get_name() const { return name; }
|
---|
228 | void set_name( std::string newValue ) { name = newValue; }
|
---|
229 | std::list< Expression* >& get_parameters() { return parameters; }
|
---|
230 |
|
---|
231 | virtual ReferenceToType *clone() const = 0;
|
---|
232 | virtual void accept( Visitor &v ) = 0;
|
---|
233 | virtual Type *acceptMutator( Mutator &m ) = 0;
|
---|
234 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
235 | protected:
|
---|
236 | virtual std::string typeString() const = 0;
|
---|
237 | std::list< Expression* > parameters;
|
---|
238 | std::string name;
|
---|
239 | private:
|
---|
240 | };
|
---|
241 |
|
---|
242 | class StructInstType : public ReferenceToType {
|
---|
243 | typedef ReferenceToType Parent;
|
---|
244 | public:
|
---|
245 | StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {}
|
---|
246 | StructInstType( const Type::Qualifiers &tq, StructDecl * baseStruct );
|
---|
247 | StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {}
|
---|
248 |
|
---|
249 | StructDecl *get_baseStruct() const { return baseStruct; }
|
---|
250 | void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
|
---|
251 |
|
---|
252 | /// Accesses generic parameters of base struct (NULL if none such)
|
---|
253 | std::list<TypeDecl*> * get_baseParameters();
|
---|
254 |
|
---|
255 | /// Looks up the members of this struct named "name" and places them into "foundDecls".
|
---|
256 | /// Clones declarations into "foundDecls", caller responsible for freeing
|
---|
257 | void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
|
---|
258 |
|
---|
259 | virtual StructInstType *clone() const { return new StructInstType( *this ); }
|
---|
260 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
261 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
262 |
|
---|
263 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
264 | private:
|
---|
265 | virtual std::string typeString() const;
|
---|
266 |
|
---|
267 | // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
|
---|
268 | // where the structure used in this type is actually defined
|
---|
269 | StructDecl *baseStruct;
|
---|
270 | };
|
---|
271 |
|
---|
272 | class UnionInstType : public ReferenceToType {
|
---|
273 | typedef ReferenceToType Parent;
|
---|
274 | public:
|
---|
275 | UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {}
|
---|
276 | UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {}
|
---|
277 |
|
---|
278 | UnionDecl *get_baseUnion() const { return baseUnion; }
|
---|
279 | void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; }
|
---|
280 |
|
---|
281 | /// Accesses generic parameters of base union (NULL if none such)
|
---|
282 | std::list<TypeDecl*> * get_baseParameters();
|
---|
283 |
|
---|
284 | /// looks up the members of this union named "name" and places them into "foundDecls"
|
---|
285 | /// Clones declarations into "foundDecls", caller responsible for freeing
|
---|
286 | void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const;
|
---|
287 |
|
---|
288 | virtual UnionInstType *clone() const { return new UnionInstType( *this ); }
|
---|
289 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
290 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
291 |
|
---|
292 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
293 | private:
|
---|
294 | virtual std::string typeString() const;
|
---|
295 |
|
---|
296 | // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
|
---|
297 | // where the union used in this type is actually defined
|
---|
298 | UnionDecl *baseUnion;
|
---|
299 | };
|
---|
300 |
|
---|
301 | class EnumInstType : public ReferenceToType {
|
---|
302 | typedef ReferenceToType Parent;
|
---|
303 | public:
|
---|
304 | EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
|
---|
305 | EnumInstType( const EnumInstType &other ) : Parent( other ) {}
|
---|
306 |
|
---|
307 | virtual EnumInstType *clone() const { return new EnumInstType( *this ); }
|
---|
308 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
309 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
310 | private:
|
---|
311 | virtual std::string typeString() const;
|
---|
312 | };
|
---|
313 |
|
---|
314 | class TraitInstType : public ReferenceToType {
|
---|
315 | typedef ReferenceToType Parent;
|
---|
316 | public:
|
---|
317 | TraitInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
|
---|
318 | TraitInstType( const TraitInstType &other );
|
---|
319 | ~TraitInstType();
|
---|
320 |
|
---|
321 | std::list< Declaration* >& get_members() { return members; }
|
---|
322 |
|
---|
323 | virtual TraitInstType *clone() const { return new TraitInstType( *this ); }
|
---|
324 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
325 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
326 | private:
|
---|
327 | virtual std::string typeString() const;
|
---|
328 |
|
---|
329 | // this member is filled in by the validate pass, which instantiates the members of the correponding
|
---|
330 | // aggregate with the actual type parameters specified for this use of the context
|
---|
331 | std::list< Declaration* > members;
|
---|
332 | };
|
---|
333 |
|
---|
334 | class TypeInstType : public ReferenceToType {
|
---|
335 | typedef ReferenceToType Parent;
|
---|
336 | public:
|
---|
337 | TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType );
|
---|
338 | TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype );
|
---|
339 | TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {}
|
---|
340 | ~TypeInstType();
|
---|
341 |
|
---|
342 | TypeDecl *get_baseType() const { return baseType; }
|
---|
343 | void set_baseType( TypeDecl *newValue );
|
---|
344 | bool get_isFtype() const { return isFtype; }
|
---|
345 | void set_isFtype( bool newValue ) { isFtype = newValue; }
|
---|
346 |
|
---|
347 | virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
|
---|
348 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
349 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
350 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
351 | private:
|
---|
352 | virtual std::string typeString() const;
|
---|
353 | // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
|
---|
354 | // where the type used here is actually defined
|
---|
355 | TypeDecl *baseType;
|
---|
356 | bool isFtype;
|
---|
357 | };
|
---|
358 |
|
---|
359 | class TupleType : public Type {
|
---|
360 | public:
|
---|
361 | TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types = std::list< Type * >() );
|
---|
362 | TupleType( const TupleType& );
|
---|
363 | virtual ~TupleType();
|
---|
364 |
|
---|
365 | typedef std::list<Type*> value_type;
|
---|
366 | typedef value_type::iterator iterator;
|
---|
367 |
|
---|
368 | std::list<Type*>& get_types() { return types; }
|
---|
369 | virtual unsigned size() const { return types.size(); };
|
---|
370 |
|
---|
371 | iterator begin() { return types.begin(); }
|
---|
372 | iterator end() { return types.end(); }
|
---|
373 |
|
---|
374 | virtual TupleType *clone() const { return new TupleType( *this ); }
|
---|
375 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
376 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
377 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
378 | private:
|
---|
379 | std::list<Type*> types;
|
---|
380 | };
|
---|
381 |
|
---|
382 | class TypeofType : public Type {
|
---|
383 | public:
|
---|
384 | TypeofType( const Type::Qualifiers &tq, Expression *expr );
|
---|
385 | TypeofType( const TypeofType& );
|
---|
386 | virtual ~TypeofType();
|
---|
387 |
|
---|
388 | Expression *get_expr() const { return expr; }
|
---|
389 | void set_expr( Expression *newValue ) { expr = newValue; }
|
---|
390 |
|
---|
391 | virtual TypeofType *clone() const { return new TypeofType( *this ); }
|
---|
392 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
393 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
394 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
395 | private:
|
---|
396 | Expression *expr;
|
---|
397 | };
|
---|
398 |
|
---|
399 | class AttrType : public Type {
|
---|
400 | public:
|
---|
401 | AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr );
|
---|
402 | AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type );
|
---|
403 | AttrType( const AttrType& );
|
---|
404 | virtual ~AttrType();
|
---|
405 |
|
---|
406 | const std::string &get_name() const { return name; }
|
---|
407 | void set_name( const std::string &newValue ) { name = newValue; }
|
---|
408 | Expression *get_expr() const { return expr; }
|
---|
409 | void set_expr( Expression *newValue ) { expr = newValue; }
|
---|
410 | Type *get_type() const { return type; }
|
---|
411 | void set_type( Type *newValue ) { type = newValue; }
|
---|
412 | bool get_isType() const { return isType; }
|
---|
413 | void set_isType( bool newValue ) { isType = newValue; }
|
---|
414 |
|
---|
415 | virtual AttrType *clone() const { return new AttrType( *this ); }
|
---|
416 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
417 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
418 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
419 | private:
|
---|
420 | std::string name;
|
---|
421 | Expression *expr;
|
---|
422 | Type *type;
|
---|
423 | bool isType;
|
---|
424 | };
|
---|
425 |
|
---|
426 | /// Represents the GCC built-in varargs type
|
---|
427 | class VarArgsType : public Type {
|
---|
428 | public:
|
---|
429 | VarArgsType();
|
---|
430 | VarArgsType( Type::Qualifiers tq );
|
---|
431 |
|
---|
432 | virtual VarArgsType *clone() const { return new VarArgsType( *this ); }
|
---|
433 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
434 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
435 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
436 | };
|
---|
437 |
|
---|
438 | /// Represents a zero constant
|
---|
439 | class ZeroType : public Type {
|
---|
440 | public:
|
---|
441 | ZeroType();
|
---|
442 | ZeroType( Type::Qualifiers tq );
|
---|
443 |
|
---|
444 | virtual ZeroType *clone() const { return new ZeroType( *this ); }
|
---|
445 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
446 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
447 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
448 | };
|
---|
449 |
|
---|
450 | /// Represents a one constant
|
---|
451 | class OneType : public Type {
|
---|
452 | public:
|
---|
453 | OneType();
|
---|
454 | OneType( Type::Qualifiers tq );
|
---|
455 |
|
---|
456 | virtual OneType *clone() const { return new OneType( *this ); }
|
---|
457 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
458 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
459 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
460 | };
|
---|
461 |
|
---|
462 | inline Type::Qualifiers &Type::Qualifiers::operator&=( const Type::Qualifiers &other ) {
|
---|
463 | isConst &= other.isConst;
|
---|
464 | isVolatile &= other.isVolatile;
|
---|
465 | isRestrict &= other.isRestrict;
|
---|
466 | isLvalue &= other.isLvalue;
|
---|
467 | isAtomic &= other.isAtomic;
|
---|
468 | return *this;
|
---|
469 | }
|
---|
470 |
|
---|
471 | inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {
|
---|
472 | isConst |= other.isConst;
|
---|
473 | isVolatile |= other.isVolatile;
|
---|
474 | isRestrict |= other.isRestrict;
|
---|
475 | isLvalue |= other.isLvalue;
|
---|
476 | isAtomic |= other.isAtomic;
|
---|
477 | return *this;
|
---|
478 | }
|
---|
479 |
|
---|
480 | inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) {
|
---|
481 | if ( other.isConst ) isConst = 0;
|
---|
482 | if ( other.isVolatile ) isVolatile = 0;
|
---|
483 | if ( other.isRestrict ) isRestrict = 0;
|
---|
484 | if ( other.isAtomic ) isAtomic = 0;
|
---|
485 | return *this;
|
---|
486 | }
|
---|
487 |
|
---|
488 | inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) {
|
---|
489 | Qualifiers q = other;
|
---|
490 | q += *this;
|
---|
491 | return q;
|
---|
492 | }
|
---|
493 |
|
---|
494 | inline bool Type::Qualifiers::operator==( const Qualifiers &other ) {
|
---|
495 | return isConst == other.isConst
|
---|
496 | && isVolatile == other.isVolatile
|
---|
497 | // && isRestrict == other.isRestrict
|
---|
498 | // && isLvalue == other.isLvalue
|
---|
499 | && isAtomic == other.isAtomic;
|
---|
500 | }
|
---|
501 |
|
---|
502 | inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) {
|
---|
503 | return isConst != other.isConst
|
---|
504 | || isVolatile != other.isVolatile
|
---|
505 | // || isRestrict != other.isRestrict
|
---|
506 | // || isLvalue != other.isLvalue
|
---|
507 | || isAtomic != other.isAtomic;
|
---|
508 | }
|
---|
509 |
|
---|
510 | inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) {
|
---|
511 | return isConst <= other.isConst
|
---|
512 | && isVolatile <= other.isVolatile
|
---|
513 | // && isRestrict <= other.isRestrict
|
---|
514 | // && isLvalue >= other.isLvalue
|
---|
515 | && isAtomic == other.isAtomic;
|
---|
516 | }
|
---|
517 |
|
---|
518 | inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) {
|
---|
519 | return isConst >= other.isConst
|
---|
520 | && isVolatile >= other.isVolatile
|
---|
521 | // && isRestrict >= other.isRestrict
|
---|
522 | // && isLvalue <= other.isLvalue
|
---|
523 | && isAtomic == other.isAtomic;
|
---|
524 | }
|
---|
525 |
|
---|
526 | inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) {
|
---|
527 | return operator!=( other ) && operator<=( other );
|
---|
528 | }
|
---|
529 |
|
---|
530 | inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) {
|
---|
531 | return operator!=( other ) && operator>=( other );
|
---|
532 | }
|
---|
533 |
|
---|
534 | std::ostream & operator<<( std::ostream & out, const Type * type );
|
---|
535 |
|
---|
536 | #endif // TYPE_H
|
---|
537 |
|
---|
538 | // Local Variables: //
|
---|
539 | // tab-width: 4 //
|
---|
540 | // mode: c++ //
|
---|
541 | // compile-command: "make install" //
|
---|
542 | // End: //
|
---|