source: src/SynTree/Type.h@ bbbc067

no_list
Last change on this file since bbbc067 was 70a1c3ae, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Starting to remove std::list to see if it affects performance, started with List of attributes

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