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