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 : Andrew Beach |
---|
12 | // Last Modified On : Wed Jul 14 15:40:00 2021 |
---|
13 | // Update Count : 171 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include <strings.h> // for ffs |
---|
19 | #include <cassert> // for assert, assertf |
---|
20 | #include <list> // for list, _List_iterator |
---|
21 | #include <ostream> // for ostream, operator<<, basic_ostream |
---|
22 | #include <string> // for string |
---|
23 | |
---|
24 | #include "BaseSyntaxNode.h" // for BaseSyntaxNode |
---|
25 | #include "Common/utility.h" // for operator+ |
---|
26 | #include "Mutator.h" // for Mutator |
---|
27 | #include "SynTree.h" // for AST nodes |
---|
28 | #include "Visitor.h" // for Visitor |
---|
29 | |
---|
30 | class Type : public BaseSyntaxNode { |
---|
31 | public: |
---|
32 | // Simulate inheritance because union does not allow it. |
---|
33 | // Bug in g++-4.9 prevents static field in union |
---|
34 | //static const char * Names[]; |
---|
35 | #define BFCommon( BFType, N ) \ |
---|
36 | bool operator[]( unsigned int i ) const { return val & (1 << i); } \ |
---|
37 | bool any() const { return val != 0; } \ |
---|
38 | void reset() { val = 0; } \ |
---|
39 | int ffs() { return ::ffs( val ) - 1; } \ |
---|
40 | BFType operator&=( BFType other ) { \ |
---|
41 | val &= other.val; return *this; \ |
---|
42 | } \ |
---|
43 | BFType operator&( BFType other ) const { \ |
---|
44 | BFType q = other; \ |
---|
45 | q &= *this; \ |
---|
46 | return q; \ |
---|
47 | } \ |
---|
48 | BFType operator|=( BFType other ) { \ |
---|
49 | val |= other.val; return *this; \ |
---|
50 | } \ |
---|
51 | BFType operator|( BFType other ) const { \ |
---|
52 | BFType q = other; \ |
---|
53 | q |= *this; \ |
---|
54 | return q; \ |
---|
55 | } \ |
---|
56 | BFType operator-=( BFType other ) { \ |
---|
57 | val &= ~other.val; return *this; \ |
---|
58 | } \ |
---|
59 | void print( std::ostream & os ) const { \ |
---|
60 | if ( (*this).any() ) { \ |
---|
61 | for ( unsigned int i = 0; i < N; i += 1 ) { \ |
---|
62 | if ( (*this)[i] ) { \ |
---|
63 | os << BFType##Names[i] << ' '; \ |
---|
64 | } \ |
---|
65 | } \ |
---|
66 | } \ |
---|
67 | } |
---|
68 | |
---|
69 | // enum must remain in the same order as the corresponding bit fields. |
---|
70 | |
---|
71 | enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NumFuncSpecifier = 3 }; |
---|
72 | static const char * FuncSpecifiersNames[]; |
---|
73 | union FuncSpecifiers { |
---|
74 | unsigned int val; |
---|
75 | struct { |
---|
76 | bool is_inline : 1; |
---|
77 | bool is_noreturn : 1; |
---|
78 | bool is_fortran : 1; |
---|
79 | }; |
---|
80 | FuncSpecifiers() : val( 0 ) {} |
---|
81 | FuncSpecifiers( unsigned int val ) : val( val ) {} |
---|
82 | // equality (==, !=) works implicitly on first field "val", relational operations are undefined. |
---|
83 | BFCommon( FuncSpecifiers, NumFuncSpecifier ) |
---|
84 | }; // FuncSpecifiers |
---|
85 | |
---|
86 | enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NumStorageClass = 5 }; |
---|
87 | static const char * StorageClassesNames[]; |
---|
88 | union StorageClasses { |
---|
89 | unsigned int val; |
---|
90 | struct { |
---|
91 | bool is_extern : 1; |
---|
92 | bool is_static : 1; |
---|
93 | bool is_auto : 1; |
---|
94 | bool is_register : 1; |
---|
95 | bool is_threadlocal : 1; |
---|
96 | }; |
---|
97 | |
---|
98 | StorageClasses() : val( 0 ) {} |
---|
99 | StorageClasses( unsigned int val ) : val( val ) {} |
---|
100 | // equality (==, !=) works implicitly on first field "val", relational operations are undefined. |
---|
101 | BFCommon( StorageClasses, NumStorageClass ) |
---|
102 | }; // StorageClasses |
---|
103 | |
---|
104 | enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Mutex = 1 << 3, Atomic = 1 << 4, NumTypeQualifier = 5 }; |
---|
105 | static const char * QualifiersNames[]; |
---|
106 | union Qualifiers { |
---|
107 | enum { Mask = ~Restrict }; |
---|
108 | unsigned int val; |
---|
109 | struct { |
---|
110 | bool is_const : 1; |
---|
111 | bool is_restrict : 1; |
---|
112 | bool is_volatile : 1; |
---|
113 | bool is_mutex : 1; |
---|
114 | bool is_atomic : 1; |
---|
115 | }; |
---|
116 | |
---|
117 | Qualifiers() : val( 0 ) {} |
---|
118 | Qualifiers( unsigned int val ) : val( val ) {} |
---|
119 | // Complex comparisons provide implicit qualifier downcasting, e.g., T downcast to const T. |
---|
120 | bool operator==( Qualifiers other ) const { return (val & Mask) == (other.val & Mask); } |
---|
121 | bool operator!=( Qualifiers other ) const { return (val & Mask) != (other.val & Mask); } |
---|
122 | bool operator<=( Qualifiers other ) const { |
---|
123 | return is_const <= other.is_const //Any non-const converts to const without cost |
---|
124 | && is_volatile <= other.is_volatile //Any non-volatile converts to volatile without cost |
---|
125 | && is_mutex >= other.is_mutex //Any mutex converts to non-mutex without cost |
---|
126 | && is_atomic == other.is_atomic; //No conversion from atomic to non atomic is free |
---|
127 | } |
---|
128 | bool operator<( Qualifiers other ) const { return *this != other && *this <= other; } |
---|
129 | bool operator>=( Qualifiers other ) const { return ! (*this < other); } |
---|
130 | bool operator>( Qualifiers other ) const { return *this != other && *this >= other; } |
---|
131 | BFCommon( Qualifiers, NumTypeQualifier ) |
---|
132 | |
---|
133 | Qualifiers unify( Qualifiers const & other ) const { |
---|
134 | int or_flags = Mask & (val | other.val); |
---|
135 | int and_flags = val & other.val; |
---|
136 | return Qualifiers( or_flags | and_flags ); |
---|
137 | } |
---|
138 | }; // Qualifiers |
---|
139 | |
---|
140 | typedef std::list<TypeDecl *> ForallList; |
---|
141 | |
---|
142 | Qualifiers tq; |
---|
143 | ForallList forall; |
---|
144 | std::list< Attribute * > attributes; |
---|
145 | |
---|
146 | Type( const Qualifiers & tq, const std::list< Attribute * > & attributes ); |
---|
147 | Type( const Type & other ); |
---|
148 | virtual ~Type(); |
---|
149 | |
---|
150 | Qualifiers & get_qualifiers() { return tq; } |
---|
151 | bool get_const() const { return tq.is_const; } |
---|
152 | bool get_volatile() const { return tq.is_volatile; } |
---|
153 | bool get_restrict() const { return tq.is_restrict; } |
---|
154 | bool get_mutex() const { return tq.is_mutex; } |
---|
155 | bool get_atomic() const { return tq.is_atomic; } |
---|
156 | void set_const( bool newValue ) { tq.is_const = newValue; } |
---|
157 | void set_volatile( bool newValue ) { tq.is_volatile = newValue; } |
---|
158 | void set_restrict( bool newValue ) { tq.is_restrict = newValue; } |
---|
159 | void set_mutex( bool newValue ) { tq.is_mutex = newValue; } |
---|
160 | void set_atomic( bool newValue ) { tq.is_atomic = newValue; } |
---|
161 | |
---|
162 | ForallList& get_forall() { return forall; } |
---|
163 | |
---|
164 | std::list< Attribute * >& get_attributes() { return attributes; } |
---|
165 | const std::list< Attribute * >& get_attributes() const { return attributes; } |
---|
166 | |
---|
167 | /// How many elemental types are represented by this type |
---|
168 | virtual unsigned size() const { return 1; }; |
---|
169 | virtual bool isVoid() const { return size() == 0; } |
---|
170 | 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; } |
---|
171 | |
---|
172 | /// return type without outer pointers and arrays |
---|
173 | Type * stripDeclarator(); |
---|
174 | |
---|
175 | /// return type without outer references |
---|
176 | Type * stripReferences(); |
---|
177 | const Type * stripReferences() const; |
---|
178 | |
---|
179 | /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types) |
---|
180 | virtual int referenceDepth() const; |
---|
181 | |
---|
182 | virtual bool isComplete() const { return true; } |
---|
183 | |
---|
184 | virtual AggregateDecl * getAggr() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); } |
---|
185 | |
---|
186 | virtual TypeSubstitution genericSubstitution() const; |
---|
187 | |
---|
188 | virtual Type *clone() const = 0; |
---|
189 | virtual void accept( Visitor & v ) = 0; |
---|
190 | virtual void accept( Visitor & v ) const = 0; |
---|
191 | virtual Type *acceptMutator( Mutator & m ) = 0; |
---|
192 | virtual void print( std::ostream & os, Indenter indent = {} ) const; |
---|
193 | }; |
---|
194 | |
---|
195 | extern const Type::FuncSpecifiers noFuncSpecifiers; |
---|
196 | extern const Type::StorageClasses noStorageClasses; |
---|
197 | extern const Type::Qualifiers noQualifiers; // no qualifiers on constants |
---|
198 | |
---|
199 | class VoidType : public Type { |
---|
200 | public: |
---|
201 | VoidType( const Type::Qualifiers & tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
202 | |
---|
203 | virtual unsigned size() const override { return 0; }; |
---|
204 | virtual bool isComplete() const override { return false; } |
---|
205 | |
---|
206 | virtual VoidType *clone() const override { return new VoidType( *this ); } |
---|
207 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
208 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
209 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
210 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
211 | }; |
---|
212 | |
---|
213 | class BasicType : public Type { |
---|
214 | public: |
---|
215 | // GENERATED START, DO NOT EDIT |
---|
216 | // GENERATED BY BasicTypes-gen.cc |
---|
217 | enum Kind { |
---|
218 | Bool, |
---|
219 | Char, |
---|
220 | SignedChar, |
---|
221 | UnsignedChar, |
---|
222 | ShortSignedInt, |
---|
223 | ShortUnsignedInt, |
---|
224 | SignedInt, |
---|
225 | UnsignedInt, |
---|
226 | LongSignedInt, |
---|
227 | LongUnsignedInt, |
---|
228 | LongLongSignedInt, |
---|
229 | LongLongUnsignedInt, |
---|
230 | SignedInt128, |
---|
231 | UnsignedInt128, |
---|
232 | uFloat16, |
---|
233 | uFloat16Complex, |
---|
234 | uFloat32, |
---|
235 | uFloat32Complex, |
---|
236 | Float, |
---|
237 | FloatComplex, |
---|
238 | uFloat32x, |
---|
239 | uFloat32xComplex, |
---|
240 | uFloat64, |
---|
241 | uFloat64Complex, |
---|
242 | Double, |
---|
243 | DoubleComplex, |
---|
244 | uFloat64x, |
---|
245 | uFloat64xComplex, |
---|
246 | uuFloat80, |
---|
247 | uFloat128, |
---|
248 | uFloat128Complex, |
---|
249 | uuFloat128, |
---|
250 | LongDouble, |
---|
251 | LongDoubleComplex, |
---|
252 | uFloat128x, |
---|
253 | uFloat128xComplex, |
---|
254 | NUMBER_OF_BASIC_TYPES |
---|
255 | } kind; |
---|
256 | // GENERATED END |
---|
257 | |
---|
258 | static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind |
---|
259 | |
---|
260 | BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
261 | |
---|
262 | Kind get_kind() const { return kind; } |
---|
263 | void set_kind( Kind newValue ) { kind = newValue; } |
---|
264 | |
---|
265 | virtual BasicType *clone() const override { return new BasicType( *this ); } |
---|
266 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
267 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
268 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
269 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
270 | bool isWholeNumber() const; |
---|
271 | bool isInteger() const; |
---|
272 | }; |
---|
273 | |
---|
274 | class PointerType : public Type { |
---|
275 | public: |
---|
276 | Type * base; |
---|
277 | |
---|
278 | // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] ) |
---|
279 | Expression *dimension; |
---|
280 | bool isVarLen; |
---|
281 | bool isStatic; |
---|
282 | |
---|
283 | PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
284 | PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
285 | PointerType( const PointerType& ); |
---|
286 | virtual ~PointerType(); |
---|
287 | |
---|
288 | Type *get_base() { return base; } |
---|
289 | void set_base( Type *newValue ) { base = newValue; } |
---|
290 | Expression *get_dimension() { return dimension; } |
---|
291 | void set_dimension( Expression *newValue ) { dimension = newValue; } |
---|
292 | bool get_isVarLen() { return isVarLen; } |
---|
293 | void set_isVarLen( bool newValue ) { isVarLen = newValue; } |
---|
294 | bool get_isStatic() { return isStatic; } |
---|
295 | void set_isStatic( bool newValue ) { isStatic = newValue; } |
---|
296 | |
---|
297 | bool is_array() const { return isStatic || isVarLen || dimension; } |
---|
298 | |
---|
299 | virtual bool isComplete() const override { return ! isVarLen; } |
---|
300 | |
---|
301 | virtual PointerType *clone() const override { return new PointerType( *this ); } |
---|
302 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
303 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
304 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
305 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
306 | }; |
---|
307 | |
---|
308 | class ArrayType : public Type { |
---|
309 | public: |
---|
310 | Type *base; |
---|
311 | Expression *dimension; |
---|
312 | bool isVarLen; |
---|
313 | bool isStatic; |
---|
314 | |
---|
315 | ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
316 | ArrayType( const ArrayType& ); |
---|
317 | virtual ~ArrayType(); |
---|
318 | |
---|
319 | Type *get_base() { return base; } |
---|
320 | void set_base( Type *newValue ) { base = newValue; } |
---|
321 | Expression *get_dimension() { return dimension; } |
---|
322 | void set_dimension( Expression *newValue ) { dimension = newValue; } |
---|
323 | bool get_isVarLen() { return isVarLen; } |
---|
324 | void set_isVarLen( bool newValue ) { isVarLen = newValue; } |
---|
325 | bool get_isStatic() { return isStatic; } |
---|
326 | void set_isStatic( bool newValue ) { isStatic = newValue; } |
---|
327 | |
---|
328 | // array types are complete if they have a dimension expression or are |
---|
329 | // VLAs ('*' in parameter declaration), and incomplete otherwise. |
---|
330 | // See 6.7.6.2 |
---|
331 | virtual bool isComplete() const override { return dimension || isVarLen; } |
---|
332 | |
---|
333 | virtual ArrayType *clone() const override { return new ArrayType( *this ); } |
---|
334 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
335 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
336 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
337 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
338 | }; |
---|
339 | |
---|
340 | class QualifiedType : public Type { |
---|
341 | public: |
---|
342 | Type * parent; |
---|
343 | Type * child; |
---|
344 | |
---|
345 | QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ); |
---|
346 | QualifiedType( const QualifiedType & tq ); |
---|
347 | virtual ~QualifiedType(); |
---|
348 | |
---|
349 | virtual QualifiedType *clone() const override { return new QualifiedType( *this ); } |
---|
350 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
351 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
352 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
353 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
354 | }; |
---|
355 | |
---|
356 | class ReferenceType : public Type { |
---|
357 | public: |
---|
358 | Type *base; |
---|
359 | |
---|
360 | ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
361 | ReferenceType( const ReferenceType & ); |
---|
362 | virtual ~ReferenceType(); |
---|
363 | |
---|
364 | Type *get_base() { return base; } |
---|
365 | void set_base( Type *newValue ) { base = newValue; } |
---|
366 | |
---|
367 | virtual int referenceDepth() const override; |
---|
368 | |
---|
369 | // Since reference types act like value types, their size is the size of the base. |
---|
370 | // This makes it simple to cast the empty tuple to a reference type, since casts that increase |
---|
371 | // the number of values are disallowed. |
---|
372 | virtual unsigned size() const override { return base->size(); } |
---|
373 | |
---|
374 | virtual TypeSubstitution genericSubstitution() const override; |
---|
375 | |
---|
376 | virtual ReferenceType *clone() const override { return new ReferenceType( *this ); } |
---|
377 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
378 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
379 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
380 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
381 | }; |
---|
382 | |
---|
383 | class FunctionType : public Type { |
---|
384 | public: |
---|
385 | std::list<DeclarationWithType*> returnVals; |
---|
386 | std::list<DeclarationWithType*> parameters; |
---|
387 | |
---|
388 | // Does the function accept a variable number of arguments following the arguments specified in the parameters list. |
---|
389 | // This could be because of |
---|
390 | // - an ellipsis in a prototype declaration |
---|
391 | // - an unprototyped declaration |
---|
392 | bool isVarArgs; |
---|
393 | |
---|
394 | FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
395 | FunctionType( const FunctionType& ); |
---|
396 | virtual ~FunctionType(); |
---|
397 | |
---|
398 | std::list<DeclarationWithType*> & get_returnVals() { return returnVals; } |
---|
399 | std::list<DeclarationWithType*> & get_parameters() { return parameters; } |
---|
400 | bool get_isVarArgs() const { return isVarArgs; } |
---|
401 | void set_isVarArgs( bool newValue ) { isVarArgs = newValue; } |
---|
402 | bool isTtype() const; |
---|
403 | |
---|
404 | bool isUnprototyped() const { return isVarArgs && parameters.size() == 0; } |
---|
405 | |
---|
406 | virtual FunctionType *clone() const override { return new FunctionType( *this ); } |
---|
407 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
408 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
409 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
410 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
411 | }; |
---|
412 | |
---|
413 | class ReferenceToType : public Type { |
---|
414 | public: |
---|
415 | std::list< Expression* > parameters; |
---|
416 | std::string name; |
---|
417 | bool hoistType; |
---|
418 | |
---|
419 | ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes ); |
---|
420 | ReferenceToType( const ReferenceToType & other ); |
---|
421 | virtual ~ReferenceToType(); |
---|
422 | |
---|
423 | const std::string & get_name() const { return name; } |
---|
424 | void set_name( std::string newValue ) { name = newValue; } |
---|
425 | std::list< Expression* >& get_parameters() { return parameters; } |
---|
426 | bool get_hoistType() const { return hoistType; } |
---|
427 | void set_hoistType( bool newValue ) { hoistType = newValue; } |
---|
428 | |
---|
429 | virtual ReferenceToType *clone() const override = 0; |
---|
430 | virtual void accept( Visitor & v ) override = 0; |
---|
431 | virtual Type *acceptMutator( Mutator & m ) override = 0; |
---|
432 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
433 | |
---|
434 | virtual void lookup( __attribute__((unused)) const std::string & name, __attribute__((unused)) std::list< Declaration* > & foundDecls ) const {} |
---|
435 | protected: |
---|
436 | virtual std::string typeString() const = 0; |
---|
437 | }; |
---|
438 | |
---|
439 | class StructInstType : public ReferenceToType { |
---|
440 | typedef ReferenceToType Parent; |
---|
441 | public: |
---|
442 | // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree, |
---|
443 | // where the structure used in this type is actually defined |
---|
444 | StructDecl *baseStruct; |
---|
445 | |
---|
446 | StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseStruct( 0 ) {} |
---|
447 | StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
448 | StructInstType( const StructInstType & other ) : Parent( other ), baseStruct( other.baseStruct ) {} |
---|
449 | |
---|
450 | StructDecl *get_baseStruct() const { return baseStruct; } |
---|
451 | void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; } |
---|
452 | |
---|
453 | /// Accesses generic parameters of base struct (NULL if none such) |
---|
454 | std::list<TypeDecl*> * get_baseParameters(); |
---|
455 | const std::list<TypeDecl*> * get_baseParameters() const; |
---|
456 | |
---|
457 | virtual bool isComplete() const override; |
---|
458 | |
---|
459 | virtual AggregateDecl * getAggr() const override; |
---|
460 | |
---|
461 | virtual TypeSubstitution genericSubstitution() const override; |
---|
462 | |
---|
463 | /// Looks up the members of this struct named "name" and places them into "foundDecls". |
---|
464 | /// Clones declarations into "foundDecls", caller responsible for freeing |
---|
465 | void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override; |
---|
466 | |
---|
467 | virtual StructInstType *clone() const override { return new StructInstType( *this ); } |
---|
468 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
469 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
470 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
471 | |
---|
472 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
473 | private: |
---|
474 | virtual std::string typeString() const override; |
---|
475 | }; |
---|
476 | |
---|
477 | class UnionInstType : public ReferenceToType { |
---|
478 | typedef ReferenceToType Parent; |
---|
479 | public: |
---|
480 | // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree, |
---|
481 | // where the union used in this type is actually defined |
---|
482 | UnionDecl *baseUnion; |
---|
483 | |
---|
484 | UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseUnion( 0 ) {} |
---|
485 | UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
486 | UnionInstType( const UnionInstType & other ) : Parent( other ), baseUnion( other.baseUnion ) {} |
---|
487 | |
---|
488 | UnionDecl *get_baseUnion() const { return baseUnion; } |
---|
489 | void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; } |
---|
490 | |
---|
491 | /// Accesses generic parameters of base union (NULL if none such) |
---|
492 | std::list<TypeDecl*> * get_baseParameters(); |
---|
493 | const std::list<TypeDecl*> * get_baseParameters() const; |
---|
494 | |
---|
495 | virtual bool isComplete() const override; |
---|
496 | |
---|
497 | virtual AggregateDecl * getAggr() const override; |
---|
498 | |
---|
499 | virtual TypeSubstitution genericSubstitution() const override; |
---|
500 | |
---|
501 | /// looks up the members of this union named "name" and places them into "foundDecls" |
---|
502 | /// Clones declarations into "foundDecls", caller responsible for freeing |
---|
503 | void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override; |
---|
504 | |
---|
505 | virtual UnionInstType *clone() const override { return new UnionInstType( *this ); } |
---|
506 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
507 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
508 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
509 | |
---|
510 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
511 | private: |
---|
512 | virtual std::string typeString() const override; |
---|
513 | }; |
---|
514 | |
---|
515 | class EnumInstType : public ReferenceToType { |
---|
516 | typedef ReferenceToType Parent; |
---|
517 | public: |
---|
518 | // this decl is not "owned" by the enum inst; it is merely a pointer to elsewhere in the tree, |
---|
519 | // where the enum used in this type is actually defined |
---|
520 | EnumDecl *baseEnum = nullptr; |
---|
521 | |
---|
522 | EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {} |
---|
523 | EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
524 | EnumInstType( const EnumInstType & other ) : Parent( other ), baseEnum( other.baseEnum ) {} |
---|
525 | |
---|
526 | EnumDecl *get_baseEnum() const { return baseEnum; } |
---|
527 | void set_baseEnum( EnumDecl *newValue ) { baseEnum = newValue; } |
---|
528 | |
---|
529 | virtual bool isComplete() const override; |
---|
530 | |
---|
531 | virtual AggregateDecl * getAggr() const override; |
---|
532 | |
---|
533 | virtual EnumInstType *clone() const override { return new EnumInstType( *this ); } |
---|
534 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
535 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
536 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
537 | |
---|
538 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
539 | private: |
---|
540 | virtual std::string typeString() const override; |
---|
541 | }; |
---|
542 | |
---|
543 | class TraitInstType : public ReferenceToType { |
---|
544 | typedef ReferenceToType Parent; |
---|
545 | public: |
---|
546 | // this decl is not "owned" by the trait inst; it is merely a pointer to elsewhere in the tree, |
---|
547 | // where the trait used in this type is actually defined |
---|
548 | TraitDecl * baseTrait = nullptr; |
---|
549 | |
---|
550 | TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {} |
---|
551 | TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
552 | TraitInstType( const TraitInstType & other ); |
---|
553 | ~TraitInstType(); |
---|
554 | |
---|
555 | virtual bool isComplete() const override; |
---|
556 | |
---|
557 | virtual TraitInstType *clone() const override { return new TraitInstType( *this ); } |
---|
558 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
559 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
560 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
561 | private: |
---|
562 | virtual std::string typeString() const override; |
---|
563 | }; |
---|
564 | |
---|
565 | class TypeInstType : public ReferenceToType { |
---|
566 | typedef ReferenceToType Parent; |
---|
567 | public: |
---|
568 | // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree, |
---|
569 | // where the type used here is actually defined |
---|
570 | TypeDecl *baseType; |
---|
571 | bool isFtype; |
---|
572 | |
---|
573 | TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
574 | TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
575 | TypeInstType( const TypeInstType & other ); |
---|
576 | ~TypeInstType(); |
---|
577 | |
---|
578 | TypeDecl *get_baseType() const { return baseType; } |
---|
579 | void set_baseType( TypeDecl *newValue ); |
---|
580 | bool get_isFtype() const { return isFtype; } |
---|
581 | void set_isFtype( bool newValue ) { isFtype = newValue; } |
---|
582 | |
---|
583 | virtual bool isComplete() const override; |
---|
584 | |
---|
585 | virtual TypeInstType *clone() const override { return new TypeInstType( *this ); } |
---|
586 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
587 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
588 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
589 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
590 | private: |
---|
591 | virtual std::string typeString() const override; |
---|
592 | }; |
---|
593 | |
---|
594 | class TupleType : public Type { |
---|
595 | public: |
---|
596 | std::list<Type *> types; |
---|
597 | std::list<Declaration *> members; |
---|
598 | |
---|
599 | TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
600 | TupleType( const TupleType& ); |
---|
601 | virtual ~TupleType(); |
---|
602 | |
---|
603 | typedef std::list<Type*> value_type; |
---|
604 | typedef value_type::iterator iterator; |
---|
605 | |
---|
606 | std::list<Type *> & get_types() { return types; } |
---|
607 | virtual unsigned size() const override { return types.size(); }; |
---|
608 | |
---|
609 | // For now, this is entirely synthetic -- tuple types always have unnamed members. |
---|
610 | // Eventually, we may allow named tuples, in which case members should subsume types |
---|
611 | std::list<Declaration *> & get_members() { return members; } |
---|
612 | |
---|
613 | iterator begin() { return types.begin(); } |
---|
614 | iterator end() { return types.end(); } |
---|
615 | |
---|
616 | virtual Type * getComponent( unsigned i ) override { |
---|
617 | assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() ); |
---|
618 | return *(begin()+i); |
---|
619 | } |
---|
620 | |
---|
621 | // virtual bool isComplete() const override { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness |
---|
622 | |
---|
623 | virtual TupleType *clone() const override { return new TupleType( *this ); } |
---|
624 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
625 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
626 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
627 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
628 | }; |
---|
629 | |
---|
630 | class TypeofType : public Type { |
---|
631 | public: |
---|
632 | Expression *expr; ///< expression to take the type of |
---|
633 | bool is_basetypeof; ///< true iff is basetypeof type |
---|
634 | |
---|
635 | TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
636 | TypeofType( const Type::Qualifiers & tq, Expression *expr, bool is_basetypeof, |
---|
637 | const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
638 | TypeofType( const TypeofType& ); |
---|
639 | virtual ~TypeofType(); |
---|
640 | |
---|
641 | Expression *get_expr() const { return expr; } |
---|
642 | void set_expr( Expression *newValue ) { expr = newValue; } |
---|
643 | |
---|
644 | virtual bool isComplete() const override { assert( false ); return false; } |
---|
645 | |
---|
646 | virtual TypeofType *clone() const override { return new TypeofType( *this ); } |
---|
647 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
648 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
649 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
650 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
651 | }; |
---|
652 | |
---|
653 | class VTableType : public Type { |
---|
654 | public: |
---|
655 | Type *base; |
---|
656 | |
---|
657 | VTableType( const Type::Qualifiers & tq, Type *base, |
---|
658 | const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
659 | VTableType( const VTableType & ); |
---|
660 | virtual ~VTableType(); |
---|
661 | |
---|
662 | Type *get_base() { return base; } |
---|
663 | void set_base( Type *newValue ) { base = newValue; } |
---|
664 | |
---|
665 | virtual VTableType *clone() const override { return new VTableType( *this ); } |
---|
666 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
667 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
668 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
669 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
670 | }; |
---|
671 | |
---|
672 | class AttrType : public Type { |
---|
673 | public: |
---|
674 | std::string name; |
---|
675 | Expression *expr; |
---|
676 | Type *type; |
---|
677 | bool isType; |
---|
678 | |
---|
679 | AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
680 | AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
681 | AttrType( const AttrType& ); |
---|
682 | virtual ~AttrType(); |
---|
683 | |
---|
684 | const std::string & get_name() const { return name; } |
---|
685 | void set_name( const std::string & newValue ) { name = newValue; } |
---|
686 | Expression *get_expr() const { return expr; } |
---|
687 | void set_expr( Expression *newValue ) { expr = newValue; } |
---|
688 | Type *get_type() const { return type; } |
---|
689 | void set_type( Type *newValue ) { type = newValue; } |
---|
690 | bool get_isType() const { return isType; } |
---|
691 | void set_isType( bool newValue ) { isType = newValue; } |
---|
692 | |
---|
693 | virtual bool isComplete() const override { assert( false ); } // xxx - not sure what to do here |
---|
694 | |
---|
695 | virtual AttrType *clone() const override { return new AttrType( *this ); } |
---|
696 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
697 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
698 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
699 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
700 | }; |
---|
701 | |
---|
702 | /// Represents the GCC built-in varargs type |
---|
703 | class VarArgsType : public Type { |
---|
704 | public: |
---|
705 | VarArgsType(); |
---|
706 | VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
707 | |
---|
708 | virtual bool isComplete() const override{ return true; } // xxx - is this right? |
---|
709 | |
---|
710 | virtual VarArgsType *clone() const override { return new VarArgsType( *this ); } |
---|
711 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
712 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
713 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
714 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
715 | }; |
---|
716 | |
---|
717 | /// Represents a zero constant |
---|
718 | class ZeroType : public Type { |
---|
719 | public: |
---|
720 | ZeroType(); |
---|
721 | ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
722 | |
---|
723 | virtual ZeroType *clone() const override { return new ZeroType( *this ); } |
---|
724 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
725 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
726 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
727 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
728 | }; |
---|
729 | |
---|
730 | /// Represents a one constant |
---|
731 | class OneType : public Type { |
---|
732 | public: |
---|
733 | OneType(); |
---|
734 | OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
735 | |
---|
736 | virtual OneType *clone() const override { return new OneType( *this ); } |
---|
737 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
738 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
739 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
740 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
741 | }; |
---|
742 | |
---|
743 | class GlobalScopeType : public Type { |
---|
744 | public: |
---|
745 | GlobalScopeType(); |
---|
746 | |
---|
747 | virtual GlobalScopeType *clone() const override { return new GlobalScopeType( *this ); } |
---|
748 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
749 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
750 | virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
751 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
752 | }; |
---|
753 | |
---|
754 | |
---|
755 | bool isUnboundType(const Type * type); |
---|
756 | bool isUnboundType(const std::string & tname); |
---|
757 | |
---|
758 | // Local Variables: // |
---|
759 | // tab-width: 4 // |
---|
760 | // mode: c++ // |
---|
761 | // compile-command: "make install" // |
---|
762 | // End: // |
---|