source: src/SynTree/Type.h@ 888339e

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 888339e was e149f77, checked in by Thierry Delisle <tdelisle@…>, 8 years ago
  • moved print routine to base syntax node and implementated in code gen.
  • added virtual and override where needed in the syntree.
  • Property mode set to 100644
File size: 25.7 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 : Andrew Beach
12// Last Modified On : Wed Aug 9 14:25:00 2017
13// Update Count : 152
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
30class 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, Lvalue = 1 << 3, Mutex = 1 << 4, Atomic = 1 << 5, NumTypeQualifier = 6 };
105 static const char * QualifiersNames[];
106 union Qualifiers {
107 enum { Mask = ~(Restrict | Lvalue) };
108 unsigned int val;
109 struct {
110 bool is_const : 1;
111 bool is_restrict : 1;
112 bool is_volatile : 1;
113 bool is_lvalue : 1;
114 bool is_mutex : 1;
115 bool is_atomic : 1;
116 };
117
118 Qualifiers() : val( 0 ) {}
119 Qualifiers( unsigned int val ) : val( val ) {}
120 // Complex comparisons provide implicit qualifier downcasting, e.g., T downcast to const T.
121 bool operator==( Qualifiers other ) const { return (val & Mask) == (other.val & Mask); }
122 bool operator!=( Qualifiers other ) const { return (val & Mask) != (other.val & Mask); }
123 bool operator<=( Qualifiers other ) const {
124 return is_const <= other.is_const //Any non-const converts to const without cost
125 && is_volatile <= other.is_volatile //Any non-volatile converts to volatile without cost
126 && is_mutex >= other.is_mutex //Any mutex converts to non-mutex without cost
127 && is_atomic == other.is_atomic; //No conversion from atomic to non atomic is free
128 }
129 bool operator<( Qualifiers other ) const { return *this != other && *this <= other; }
130 bool operator>=( Qualifiers other ) const { return ! (*this < other); }
131 bool operator>( Qualifiers other ) const { return *this != other && *this >= other; }
132 BFCommon( Qualifiers, NumTypeQualifier )
133 }; // Qualifiers
134
135 typedef std::list<TypeDecl *> ForallList;
136
137 Qualifiers tq;
138 ForallList forall;
139 std::list< Attribute * > attributes;
140
141 Type( const Qualifiers & tq, const std::list< Attribute * > & attributes );
142 Type( const Type & other );
143 virtual ~Type();
144
145 Qualifiers & get_qualifiers() { return tq; }
146 bool get_const() { return tq.is_const; }
147 bool get_volatile() { return tq.is_volatile; }
148 bool get_restrict() { return tq.is_restrict; }
149 bool get_lvalue() { return tq.is_lvalue; }
150 bool get_mutex() { return tq.is_mutex; }
151 bool get_atomic() { return tq.is_atomic; }
152 void set_const( bool newValue ) { tq.is_const = newValue; }
153 void set_volatile( bool newValue ) { tq.is_volatile = newValue; }
154 void set_restrict( bool newValue ) { tq.is_restrict = newValue; }
155 void set_lvalue( bool newValue ) { tq.is_lvalue = newValue; }
156 void set_mutex( bool newValue ) { tq.is_mutex = newValue; }
157 void set_atomic( bool newValue ) { tq.is_atomic = newValue; }
158
159 ForallList& get_forall() { return forall; }
160
161 std::list< Attribute * >& get_attributes() { return attributes; }
162 const std::list< Attribute * >& get_attributes() const { return attributes; }
163
164 /// How many elemental types are represented by this type
165 virtual unsigned size() const { return 1; };
166 virtual bool isVoid() const { return size() == 0; }
167 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; }
168
169 /// return type without outer pointers and arrays
170 Type * stripDeclarator();
171
172 /// return type without outer references
173 Type * stripReferences();
174
175 /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types)
176 virtual int referenceDepth() const;
177
178 virtual bool isComplete() const { return true; }
179
180 virtual Type *clone() const = 0;
181 virtual void accept( Visitor & v ) = 0;
182 virtual Type *acceptMutator( Mutator & m ) = 0;
183 virtual void print( std::ostream & os, int indent = 0 ) const;
184};
185
186extern const Type::FuncSpecifiers noFuncSpecifiers;
187extern const Type::StorageClasses noStorageClasses;
188extern const Type::Qualifiers noQualifiers; // no qualifiers on constants
189
190class VoidType : public Type {
191 public:
192 VoidType( const Type::Qualifiers & tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
193
194 virtual unsigned size() const override { return 0; };
195 virtual bool isComplete() const override { return false; }
196
197 virtual VoidType *clone() const override { return new VoidType( *this ); }
198 virtual void accept( Visitor & v ) override { v.visit( this ); }
199 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
200 virtual void print( std::ostream & os, int indent = 0 ) const override;
201};
202
203class BasicType : public Type {
204 public:
205 enum Kind {
206 Bool,
207 Char,
208 SignedChar,
209 UnsignedChar,
210 ShortSignedInt,
211 ShortUnsignedInt,
212 SignedInt,
213 UnsignedInt,
214 LongSignedInt,
215 LongUnsignedInt,
216 LongLongSignedInt,
217 LongLongUnsignedInt,
218 Float,
219 Double,
220 LongDouble,
221 FloatComplex,
222 DoubleComplex,
223 LongDoubleComplex,
224 FloatImaginary,
225 DoubleImaginary,
226 LongDoubleImaginary,
227 NUMBER_OF_BASIC_TYPES
228 } kind;
229
230 static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind
231
232 BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
233
234 Kind get_kind() { return kind; }
235 void set_kind( Kind newValue ) { kind = newValue; }
236
237 virtual BasicType *clone() const override { return new BasicType( *this ); }
238 virtual void accept( Visitor & v ) override { v.visit( this ); }
239 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
240 virtual void print( std::ostream & os, int indent = 0 ) const override;
241
242 bool isInteger() const;
243};
244
245class PointerType : public Type {
246 public:
247 Type *base;
248
249 // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
250 Expression *dimension;
251 bool isVarLen;
252 bool isStatic;
253
254 PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
255 PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
256 PointerType( const PointerType& );
257 virtual ~PointerType();
258
259 Type *get_base() { return base; }
260 void set_base( Type *newValue ) { base = newValue; }
261 Expression *get_dimension() { return dimension; }
262 void set_dimension( Expression *newValue ) { dimension = newValue; }
263 bool get_isVarLen() { return isVarLen; }
264 void set_isVarLen( bool newValue ) { isVarLen = newValue; }
265 bool get_isStatic() { return isStatic; }
266 void set_isStatic( bool newValue ) { isStatic = newValue; }
267
268 bool is_array() const { return isStatic || isVarLen || dimension; }
269
270 virtual bool isComplete() const override { return ! isVarLen; }
271
272 virtual PointerType *clone() const override { return new PointerType( *this ); }
273 virtual void accept( Visitor & v ) override { v.visit( this ); }
274 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
275 virtual void print( std::ostream & os, int indent = 0 ) const override;
276};
277
278class ArrayType : public Type {
279 public:
280 Type *base;
281 Expression *dimension;
282 bool isVarLen;
283 bool isStatic;
284
285 ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
286 ArrayType( const ArrayType& );
287 virtual ~ArrayType();
288
289 Type *get_base() { return base; }
290 void set_base( Type *newValue ) { base = newValue; }
291 Expression *get_dimension() { return dimension; }
292 void set_dimension( Expression *newValue ) { dimension = newValue; }
293 bool get_isVarLen() { return isVarLen; }
294 void set_isVarLen( bool newValue ) { isVarLen = newValue; }
295 bool get_isStatic() { return isStatic; }
296 void set_isStatic( bool newValue ) { isStatic = newValue; }
297
298 virtual bool isComplete() const override { return ! isVarLen; }
299
300 virtual ArrayType *clone() const override { return new ArrayType( *this ); }
301 virtual void accept( Visitor & v ) override { v.visit( this ); }
302 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
303 virtual void print( std::ostream & os, int indent = 0 ) const override;
304};
305
306class ReferenceType : public Type {
307public:
308 Type *base;
309
310 ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
311 ReferenceType( const ReferenceType & );
312 virtual ~ReferenceType();
313
314 Type *get_base() { return base; }
315 void set_base( Type *newValue ) { base = newValue; }
316
317 virtual int referenceDepth() const override;
318
319 // Since reference types act like value types, their size is the size of the base.
320 // This makes it simple to cast the empty tuple to a reference type, since casts that increase
321 // the number of values are disallowed.
322 virtual unsigned size() const override { return base->size(); }
323
324 virtual ReferenceType *clone() const override { return new ReferenceType( *this ); }
325 virtual void accept( Visitor & v ) override { v.visit( this ); }
326 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
327 virtual void print( std::ostream & os, int indent = 0 ) const override;
328};
329
330class FunctionType : public Type {
331 public:
332 std::list<DeclarationWithType*> returnVals;
333 std::list<DeclarationWithType*> parameters;
334
335 // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
336 // This could be because of
337 // - an ellipsis in a prototype declaration
338 // - an unprototyped declaration
339 bool isVarArgs;
340
341 FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
342 FunctionType( const FunctionType& );
343 virtual ~FunctionType();
344
345 std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
346 std::list<DeclarationWithType*> & get_parameters() { return parameters; }
347 bool get_isVarArgs() const { return isVarArgs; }
348 void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
349 bool isTtype() const;
350
351 virtual FunctionType *clone() const override { return new FunctionType( *this ); }
352 virtual void accept( Visitor & v ) override { v.visit( this ); }
353 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
354 virtual void print( std::ostream & os, int indent = 0 ) const override;
355};
356
357class ReferenceToType : public Type {
358 public:
359 std::list< Expression* > parameters;
360 std::string name;
361 bool hoistType;
362
363 ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes );
364 ReferenceToType( const ReferenceToType & other );
365 virtual ~ReferenceToType();
366
367 const std::string & get_name() const { return name; }
368 void set_name( std::string newValue ) { name = newValue; }
369 std::list< Expression* >& get_parameters() { return parameters; }
370 bool get_hoistType() const { return hoistType; }
371 void set_hoistType( bool newValue ) { hoistType = newValue; }
372
373 virtual ReferenceToType *clone() const override = 0;
374 virtual void accept( Visitor & v ) override = 0;
375 virtual Type *acceptMutator( Mutator & m ) override = 0;
376 virtual void print( std::ostream & os, int indent = 0 ) const override;
377
378 virtual void lookup( __attribute__((unused)) const std::string & name, __attribute__((unused)) std::list< Declaration* > & foundDecls ) const {}
379 protected:
380 virtual std::string typeString() const = 0;
381};
382
383class StructInstType : public ReferenceToType {
384 typedef ReferenceToType Parent;
385 public:
386 // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
387 // where the structure used in this type is actually defined
388 StructDecl *baseStruct;
389
390 StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseStruct( 0 ) {}
391 StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
392 StructInstType( const StructInstType & other ) : Parent( other ), baseStruct( other.baseStruct ) {}
393
394 StructDecl *get_baseStruct() const { return baseStruct; }
395 void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; }
396
397 /// Accesses generic parameters of base struct (NULL if none such)
398 std::list<TypeDecl*> * get_baseParameters();
399
400 virtual bool isComplete() const override;
401
402 /// Looks up the members of this struct named "name" and places them into "foundDecls".
403 /// Clones declarations into "foundDecls", caller responsible for freeing
404 void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
405
406 virtual StructInstType *clone() const override { return new StructInstType( *this ); }
407 virtual void accept( Visitor & v ) override { v.visit( this ); }
408 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
409
410 virtual void print( std::ostream & os, int indent = 0 ) const override;
411 private:
412 virtual std::string typeString() const override;
413};
414
415class UnionInstType : public ReferenceToType {
416 typedef ReferenceToType Parent;
417 public:
418 // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
419 // where the union used in this type is actually defined
420 UnionDecl *baseUnion;
421
422 UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseUnion( 0 ) {}
423 UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
424 UnionInstType( const UnionInstType & other ) : Parent( other ), baseUnion( other.baseUnion ) {}
425
426 UnionDecl *get_baseUnion() const { return baseUnion; }
427 void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; }
428
429 /// Accesses generic parameters of base union (NULL if none such)
430 std::list< TypeDecl * > * get_baseParameters();
431
432 virtual bool isComplete() const override;
433
434 /// looks up the members of this union named "name" and places them into "foundDecls"
435 /// Clones declarations into "foundDecls", caller responsible for freeing
436 void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override;
437
438 virtual UnionInstType *clone() const override { return new UnionInstType( *this ); }
439 virtual void accept( Visitor & v ) override { v.visit( this ); }
440 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
441
442 virtual void print( std::ostream & os, int indent = 0 ) const override;
443 private:
444 virtual std::string typeString() const override;
445};
446
447class EnumInstType : public ReferenceToType {
448 typedef ReferenceToType Parent;
449 public:
450 // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
451 // where the union used in this type is actually defined
452 EnumDecl *baseEnum = nullptr;
453
454 EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {}
455 EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
456 EnumInstType( const EnumInstType & other ) : Parent( other ), baseEnum( other.baseEnum ) {}
457
458 EnumDecl *get_baseEnum() const { return baseEnum; }
459 void set_baseEnum( EnumDecl *newValue ) { baseEnum = newValue; }
460
461 virtual bool isComplete() const override;
462
463 virtual EnumInstType *clone() const override { return new EnumInstType( *this ); }
464 virtual void accept( Visitor & v ) override { v.visit( this ); }
465 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
466 private:
467 virtual std::string typeString() const override;
468};
469
470class TraitInstType : public ReferenceToType {
471 typedef ReferenceToType Parent;
472 public:
473 // this decl is not "owned" by the trait inst; it is merely a pointer to elsewhere in the tree,
474 // where the trait used in this type is actually defined
475 TraitDecl * baseTrait = nullptr;
476
477 TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {}
478 TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
479 TraitInstType( const TraitInstType & other );
480 ~TraitInstType();
481
482 virtual bool isComplete() const override;
483
484 virtual TraitInstType *clone() const override { return new TraitInstType( *this ); }
485 virtual void accept( Visitor & v ) override { v.visit( this ); }
486 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
487 private:
488 virtual std::string typeString() const override;
489};
490
491class TypeInstType : public ReferenceToType {
492 typedef ReferenceToType Parent;
493 public:
494 // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
495 // where the type used here is actually defined
496 TypeDecl *baseType;
497 bool isFtype;
498
499 TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
500 TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
501 TypeInstType( const TypeInstType & other );
502 ~TypeInstType();
503
504 TypeDecl *get_baseType() const { return baseType; }
505 void set_baseType( TypeDecl *newValue );
506 bool get_isFtype() const { return isFtype; }
507 void set_isFtype( bool newValue ) { isFtype = newValue; }
508
509 virtual bool isComplete() const override;
510
511 virtual TypeInstType *clone() const override { return new TypeInstType( *this ); }
512 virtual void accept( Visitor & v ) override { v.visit( this ); }
513 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
514 virtual void print( std::ostream & os, int indent = 0 ) const override;
515 private:
516 virtual std::string typeString() const override;
517};
518
519class TupleType : public Type {
520 public:
521 std::list<Type *> types;
522 std::list<Declaration *> members;
523
524 TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
525 TupleType( const TupleType& );
526 virtual ~TupleType();
527
528 typedef std::list<Type*> value_type;
529 typedef value_type::iterator iterator;
530
531 std::list<Type *> & get_types() { return types; }
532 virtual unsigned size() const override { return types.size(); };
533
534 // For now, this is entirely synthetic -- tuple types always have unnamed members.
535 // Eventually, we may allow named tuples, in which case members should subsume types
536 std::list<Declaration *> & get_members() { return members; }
537
538 iterator begin() { return types.begin(); }
539 iterator end() { return types.end(); }
540
541 virtual Type * getComponent( unsigned i ) override {
542 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() );
543 return *(begin()+i);
544 }
545
546 // virtual bool isComplete() const override { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness
547
548 virtual TupleType *clone() const override { return new TupleType( *this ); }
549 virtual void accept( Visitor & v ) override { v.visit( this ); }
550 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
551 virtual void print( std::ostream & os, int indent = 0 ) const override;
552};
553
554class TypeofType : public Type {
555 public:
556 Expression *expr;
557
558 TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
559 TypeofType( const TypeofType& );
560 virtual ~TypeofType();
561
562 Expression *get_expr() const { return expr; }
563 void set_expr( Expression *newValue ) { expr = newValue; }
564
565 virtual bool isComplete() const override { assert( false ); return false; }
566
567 virtual TypeofType *clone() const override { return new TypeofType( *this ); }
568 virtual void accept( Visitor & v ) override { v.visit( this ); }
569 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
570 virtual void print( std::ostream & os, int indent = 0 ) const override;
571};
572
573class AttrType : public Type {
574 public:
575 std::string name;
576 Expression *expr;
577 Type *type;
578 bool isType;
579
580 AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
581 AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
582 AttrType( const AttrType& );
583 virtual ~AttrType();
584
585 const std::string & get_name() const { return name; }
586 void set_name( const std::string & newValue ) { name = newValue; }
587 Expression *get_expr() const { return expr; }
588 void set_expr( Expression *newValue ) { expr = newValue; }
589 Type *get_type() const { return type; }
590 void set_type( Type *newValue ) { type = newValue; }
591 bool get_isType() const { return isType; }
592 void set_isType( bool newValue ) { isType = newValue; }
593
594 virtual bool isComplete() const override { assert( false ); } // xxx - not sure what to do here
595
596 virtual AttrType *clone() const override { return new AttrType( *this ); }
597 virtual void accept( Visitor & v ) override { v.visit( this ); }
598 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
599 virtual void print( std::ostream & os, int indent = 0 ) const override;
600};
601
602/// Represents the GCC built-in varargs type
603class VarArgsType : public Type {
604 public:
605 VarArgsType();
606 VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
607
608 virtual bool isComplete() const override{ return true; } // xxx - is this right?
609
610 virtual VarArgsType *clone() const override { return new VarArgsType( *this ); }
611 virtual void accept( Visitor & v ) override { v.visit( this ); }
612 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
613 virtual void print( std::ostream & os, int indent = 0 ) const override;
614};
615
616/// Represents a zero constant
617class ZeroType : public Type {
618 public:
619 ZeroType();
620 ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
621
622 virtual ZeroType *clone() const override { return new ZeroType( *this ); }
623 virtual void accept( Visitor & v ) override { v.visit( this ); }
624 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
625 virtual void print( std::ostream & os, int indent = 0 ) const override;
626};
627
628/// Represents a one constant
629class OneType : public Type {
630 public:
631 OneType();
632 OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
633
634 virtual OneType *clone() const override { return new OneType( *this ); }
635 virtual void accept( Visitor & v ) override { v.visit( this ); }
636 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
637 virtual void print( std::ostream & os, int indent = 0 ) const override;
638};
639
640// Local Variables: //
641// tab-width: 4 //
642// mode: c++ //
643// compile-command: "make install" //
644// End: //
Note: See TracBrowser for help on using the repository browser.