1 
2 /* Compiler implementation of the D programming language
3  * Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved
4  * written by Walter Bright
5  * http://www.digitalmars.com
6  * Distributed under the Boost Software License, Version 1.0.
7  * http://www.boost.org/LICENSE_1_0.txt
8  * https://github.com/dlang/dmd/blob/master/src/dmd/mtype.h
9  */
10 
11 #pragma once
12 
13 #include "root/root.h"
14 #include "root/stringtable.h"
15 #include "root/rmem.h" // for d_size_t
16 
17 #include "arraytypes.h"
18 #include "expression.h"
19 #include "visitor.h"
20 
21 struct Scope;
22 class Identifier;
23 class Expression;
24 class StructDeclaration;
25 class ClassDeclaration;
26 class EnumDeclaration;
27 class TypeInfoDeclaration;
28 class Dsymbol;
29 class TemplateInstance;
30 class TemplateDeclaration;
31 enum LINK;
32 
33 class TypeBasic;
34 class Parameter;
35 
36 // Back end
37 #ifdef IN_GCC
38 typedef union tree_node type;
39 #else
40 typedef struct TYPE type;
41 #endif
42 
43 void semanticTypeInfo(Scope *sc, Type *t);
44 MATCH deduceType(RootObject *o, Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes, unsigned *wm = NULL, size_t inferStart = 0);
45 StorageClass ModToStc(unsigned mod);
46 
47 enum ENUMTY
48 {
49     Tarray,             // slice array, aka T[]
50     Tsarray,            // static array, aka T[dimension]
51     Taarray,            // associative array, aka T[type]
52     Tpointer,
53     Treference,
54     Tfunction,
55     Tident,
56     Tclass,
57     Tstruct,
58     Tenum,
59 
60     Tdelegate,
61     Tnone,
62     Tvoid,
63     Tint8,
64     Tuns8,
65     Tint16,
66     Tuns16,
67     Tint32,
68     Tuns32,
69     Tint64,
70 
71     Tuns64,
72     Tfloat32,
73     Tfloat64,
74     Tfloat80,
75     Timaginary32,
76     Timaginary64,
77     Timaginary80,
78     Tcomplex32,
79     Tcomplex64,
80     Tcomplex80,
81 
82     Tbool,
83     Tchar,
84     Twchar,
85     Tdchar,
86     Terror,
87     Tinstance,
88     Ttypeof,
89     Ttuple,
90     Tslice,
91     Treturn,
92 
93     Tnull,
94     Tvector,
95     Tint128,
96     Tuns128,
97     TMAX
98 };
99 typedef unsigned char TY;       // ENUMTY
100 
101 extern int Tsize_t;
102 extern int Tptrdiff_t;
103 
104 #define SIZE_INVALID (~(d_uns64)0)   // error return from size() functions
105 
106 
107 /**
108  * type modifiers
109  * pick this order of numbers so switch statements work better
110  */
111 enum MODFlags
112 {
113     MODconst     = 1, // type is const
114     MODimmutable = 4, // type is immutable
115     MODshared    = 2, // type is shared
116     MODwild      = 8, // type is wild
117     MODwildconst = (MODwild | MODconst), // type is wild const
118     MODmutable   = 0x10       // type is mutable (only used in wildcard matching)
119 };
120 typedef unsigned char MOD;
121 
122 // These tables are for implicit conversion of binary ops;
123 // the indices are the type of operand one, followed by operand two.
124 extern unsigned char impcnvResult[TMAX][TMAX];
125 extern unsigned char impcnvType1[TMAX][TMAX];
126 extern unsigned char impcnvType2[TMAX][TMAX];
127 
128 // If !=0, give warning on implicit conversion
129 extern unsigned char impcnvWarn[TMAX][TMAX];
130 
131 class Type : public RootObject
132 {
133 public:
134     TY ty;
135     MOD mod;  // modifiers MODxxxx
136     char *deco;
137 
138     /* These are cached values that are lazily evaluated by constOf(), immutableOf(), etc.
139      * They should not be referenced by anybody but mtype.c.
140      * They can be NULL if not lazily evaluated yet.
141      * Note that there is no "shared immutable", because that is just immutable
142      * Naked == no MOD bits
143      */
144 
145     Type *cto;          // MODconst                 ? naked version of this type : const version
146     Type *ito;          // MODimmutable             ? naked version of this type : immutable version
147     Type *sto;          // MODshared                ? naked version of this type : shared mutable version
148     Type *scto;         // MODshared | MODconst     ? naked version of this type : shared const version
149     Type *wto;          // MODwild                  ? naked version of this type : wild version
150     Type *wcto;         // MODwildconst             ? naked version of this type : wild const version
151     Type *swto;         // MODshared | MODwild      ? naked version of this type : shared wild version
152     Type *swcto;        // MODshared | MODwildconst ? naked version of this type : shared wild const version
153 
154     Type *pto;          // merged pointer to this type
155     Type *rto;          // reference to this type
156     Type *arrayof;      // array of this type
157     TypeInfoDeclaration *vtinfo;        // TypeInfo object for this Type
158 
159     type *ctype;        // for back end
160 
161     static Type *tvoid;
162     static Type *tint8;
163     static Type *tuns8;
164     static Type *tint16;
165     static Type *tuns16;
166     static Type *tint32;
167     static Type *tuns32;
168     static Type *tint64;
169     static Type *tuns64;
170     static Type *tint128;
171     static Type *tuns128;
172     static Type *tfloat32;
173     static Type *tfloat64;
174     static Type *tfloat80;
175 
176     static Type *timaginary32;
177     static Type *timaginary64;
178     static Type *timaginary80;
179 
180     static Type *tcomplex32;
181     static Type *tcomplex64;
182     static Type *tcomplex80;
183 
184     static Type *tbool;
185     static Type *tchar;
186     static Type *twchar;
187     static Type *tdchar;
188 
189     // Some special types
190     static Type *tshiftcnt;
191     static Type *tvoidptr;              // void*
192     static Type *tstring;               // immutable(char)[]
193     static Type *twstring;              // immutable(wchar)[]
194     static Type *tdstring;              // immutable(dchar)[]
195     static Type *tvalist;               // va_list alias
196     static Type *terror;                // for error recovery
197     static Type *tnull;                 // for null type
198 
199     static Type *tsize_t;               // matches size_t alias
200     static Type *tptrdiff_t;            // matches ptrdiff_t alias
201     static Type *thash_t;               // matches hash_t alias
202 
203     static ClassDeclaration *dtypeinfo;
204     static ClassDeclaration *typeinfoclass;
205     static ClassDeclaration *typeinfointerface;
206     static ClassDeclaration *typeinfostruct;
207     static ClassDeclaration *typeinfopointer;
208     static ClassDeclaration *typeinfoarray;
209     static ClassDeclaration *typeinfostaticarray;
210     static ClassDeclaration *typeinfoassociativearray;
211     static ClassDeclaration *typeinfovector;
212     static ClassDeclaration *typeinfoenum;
213     static ClassDeclaration *typeinfofunction;
214     static ClassDeclaration *typeinfodelegate;
215     static ClassDeclaration *typeinfotypelist;
216     static ClassDeclaration *typeinfoconst;
217     static ClassDeclaration *typeinfoinvariant;
218     static ClassDeclaration *typeinfoshared;
219     static ClassDeclaration *typeinfowild;
220 
221     static TemplateDeclaration *rtinfo;
222 
223     static Type *basic[TMAX];
224     static unsigned char sizeTy[TMAX];
225     static StringTable stringtable;
226 
227     Type(TY ty);
228     virtual const char *kind();
229     Type *copy();
230     virtual Type *syntaxCopy();
231     bool equals(RootObject *o);
232     bool equivalent(Type *t);
233     // kludge for template.isType()
dyncast()234     int dyncast() const { return DYNCAST_TYPE; }
235     int covariant(Type *t, StorageClass *pstc = NULL, bool fix17349 = true);
236     const char *toChars();
237     char *toPrettyChars(bool QualifyTypes = false);
238     static void _init();
239 
240     d_uns64 size();
241     virtual d_uns64 size(Loc loc);
242     virtual unsigned alignsize();
243     virtual Type *semantic(Loc loc, Scope *sc);
244     Type *trySemantic(Loc loc, Scope *sc);
245     Type *merge();
246     Type *merge2();
247     void modToBuffer(OutBuffer *buf);
248     char *modToChars();
249 
250     /** For each active modifier (MODconst, MODimmutable, etc) call fp with a
251     void* for the work param and a string representation of the attribute. */
252     int modifiersApply(void *param, int (*fp)(void *, const char *));
253 
254     virtual bool isintegral();
255     virtual bool isfloating();   // real, imaginary, or complex
256     virtual bool isreal();
257     virtual bool isimaginary();
258     virtual bool iscomplex();
259     virtual bool isscalar();
260     virtual bool isunsigned();
261     virtual bool isscope();
262     virtual bool isString();
263     virtual bool isAssignable();
264     virtual bool isBoolean();
265     virtual void checkDeprecated(Loc loc, Scope *sc);
isConst()266     bool isConst() const       { return (mod & MODconst) != 0; }
isImmutable()267     bool isImmutable() const   { return (mod & MODimmutable) != 0; }
isMutable()268     bool isMutable() const     { return (mod & (MODconst | MODimmutable | MODwild)) == 0; }
isShared()269     bool isShared() const      { return (mod & MODshared) != 0; }
isSharedConst()270     bool isSharedConst() const { return (mod & (MODshared | MODconst)) == (MODshared | MODconst); }
isWild()271     bool isWild() const        { return (mod & MODwild) != 0; }
isWildConst()272     bool isWildConst() const   { return (mod & MODwildconst) == MODwildconst; }
isSharedWild()273     bool isSharedWild() const  { return (mod & (MODshared | MODwild)) == (MODshared | MODwild); }
isNaked()274     bool isNaked() const       { return mod == 0; }
275     Type *nullAttributes();
276     Type *constOf();
277     Type *immutableOf();
278     Type *mutableOf();
279     Type *sharedOf();
280     Type *sharedConstOf();
281     Type *unSharedOf();
282     Type *wildOf();
283     Type *wildConstOf();
284     Type *sharedWildOf();
285     Type *sharedWildConstOf();
286     void fixTo(Type *t);
287     void check();
288     Type *addSTC(StorageClass stc);
289     Type *castMod(MOD mod);
290     Type *addMod(MOD mod);
291     virtual Type *addStorageClass(StorageClass stc);
292     Type *pointerTo();
293     Type *referenceTo();
294     Type *arrayOf();
295     Type *sarrayOf(dinteger_t dim);
296     Type *aliasthisOf();
297     bool checkAliasThisRec();
298     virtual Type *makeConst();
299     virtual Type *makeImmutable();
300     virtual Type *makeShared();
301     virtual Type *makeSharedConst();
302     virtual Type *makeWild();
303     virtual Type *makeWildConst();
304     virtual Type *makeSharedWild();
305     virtual Type *makeSharedWildConst();
306     virtual Type *makeMutable();
307     virtual Dsymbol *toDsymbol(Scope *sc);
308     virtual Type *toBasetype();
309     virtual bool isBaseOf(Type *t, int *poffset);
310     virtual MATCH implicitConvTo(Type *to);
311     virtual MATCH constConv(Type *to);
312     virtual unsigned char deduceWild(Type *t, bool isRef);
313     virtual Type *substWildTo(unsigned mod);
314 
315     Type *unqualify(unsigned m);
316 
317     virtual Type *toHeadMutable();
318     virtual ClassDeclaration *isClassHandle();
319     virtual Expression *getProperty(Loc loc, Identifier *ident, int flag);
320     virtual Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
321     virtual structalign_t alignment();
322     Expression *noMember(Scope *sc, Expression *e, Identifier *ident, int flag);
323     virtual Expression *defaultInit(Loc loc = Loc());
324     virtual Expression *defaultInitLiteral(Loc loc);
325     virtual bool isZeroInit(Loc loc = Loc());                // if initializer is 0
326     Identifier *getTypeInfoIdent();
327     virtual void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps, bool intypeid = false);
328     void resolveExp(Expression *e, Type **pt, Expression **pe, Dsymbol **ps);
329     virtual int hasWild() const;
330     virtual bool hasPointers();
331     virtual bool hasVoidInitPointers();
332     virtual Type *nextOf();
333     Type *baseElemOf();
334     uinteger_t sizemask();
335     virtual bool needsDestruction();
336     virtual bool needsNested();
337     void checkComplexTransition(Loc loc);
338     TypeFunction *toTypeFunction();
339 
340     static void error(Loc loc, const char *format, ...);
341     static void warning(Loc loc, const char *format, ...);
342 
343     // For eliminating dynamic_cast
344     virtual TypeBasic *isTypeBasic();
accept(Visitor * v)345     virtual void accept(Visitor *v) { v->visit(this); }
346 };
347 
348 class TypeError : public Type
349 {
350 public:
351     TypeError();
352     Type *syntaxCopy();
353 
354     d_uns64 size(Loc loc);
355     Expression *getProperty(Loc loc, Identifier *ident, int flag);
356     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
357     Expression *defaultInit(Loc loc);
358     Expression *defaultInitLiteral(Loc loc);
accept(Visitor * v)359     void accept(Visitor *v) { v->visit(this); }
360 };
361 
362 class TypeNext : public Type
363 {
364 public:
365     Type *next;
366 
367     TypeNext(TY ty, Type *next);
368     void checkDeprecated(Loc loc, Scope *sc);
369     int hasWild() const;
370     Type *nextOf();
371     Type *makeConst();
372     Type *makeImmutable();
373     Type *makeShared();
374     Type *makeSharedConst();
375     Type *makeWild();
376     Type *makeWildConst();
377     Type *makeSharedWild();
378     Type *makeSharedWildConst();
379     Type *makeMutable();
380     MATCH constConv(Type *to);
381     unsigned char deduceWild(Type *t, bool isRef);
382     void transitive();
accept(Visitor * v)383     void accept(Visitor *v) { v->visit(this); }
384 };
385 
386 class TypeBasic : public Type
387 {
388 public:
389     const char *dstring;
390     unsigned flags;
391 
392     TypeBasic(TY ty);
393     const char *kind();
394     Type *syntaxCopy();
395     d_uns64 size(Loc loc) /*const*/;
396     unsigned alignsize();
397     Expression *getProperty(Loc loc, Identifier *ident, int flag);
398     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
399     bool isintegral();
400     bool isfloating() /*const*/;
401     bool isreal() /*const*/;
402     bool isimaginary() /*const*/;
403     bool iscomplex() /*const*/;
404     bool isscalar() /*const*/;
405     bool isunsigned() /*const*/;
406     MATCH implicitConvTo(Type *to);
407     Expression *defaultInit(Loc loc);
408     bool isZeroInit(Loc loc) /*const*/;
409 
410     // For eliminating dynamic_cast
411     TypeBasic *isTypeBasic();
accept(Visitor * v)412     void accept(Visitor *v) { v->visit(this); }
413 };
414 
415 class TypeVector : public Type
416 {
417 public:
418     Type *basetype;
419 
420     TypeVector(Type *basetype);
421     static TypeVector *create(Loc loc, Type *basetype);
422     const char *kind();
423     Type *syntaxCopy();
424     Type *semantic(Loc loc, Scope *sc);
425     d_uns64 size(Loc loc);
426     unsigned alignsize();
427     Expression *getProperty(Loc loc, Identifier *ident, int flag);
428     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
429     bool isintegral();
430     bool isfloating();
431     bool isscalar();
432     bool isunsigned();
433     bool isBoolean() /*const*/;
434     MATCH implicitConvTo(Type *to);
435     Expression *defaultInit(Loc loc);
436     Expression *defaultInitLiteral(Loc loc);
437     TypeBasic *elementType();
438     bool isZeroInit(Loc loc);
439 
accept(Visitor * v)440     void accept(Visitor *v) { v->visit(this); }
441 };
442 
443 class TypeArray : public TypeNext
444 {
445 public:
446     TypeArray(TY ty, Type *next);
447     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
accept(Visitor * v)448     void accept(Visitor *v) { v->visit(this); }
449 };
450 
451 // Static array, one with a fixed dimension
452 class TypeSArray : public TypeArray
453 {
454 public:
455     Expression *dim;
456 
457     TypeSArray(Type *t, Expression *dim);
458     const char *kind();
459     Type *syntaxCopy();
460     d_uns64 size(Loc loc);
461     unsigned alignsize();
462     Type *semantic(Loc loc, Scope *sc);
463     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps, bool intypeid = false);
464     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
465     bool isString();
466     bool isZeroInit(Loc loc);
467     structalign_t alignment();
468     MATCH constConv(Type *to);
469     MATCH implicitConvTo(Type *to);
470     Expression *defaultInit(Loc loc);
471     Expression *defaultInitLiteral(Loc loc);
472     bool hasPointers();
473     bool needsDestruction();
474     bool needsNested();
475 
accept(Visitor * v)476     void accept(Visitor *v) { v->visit(this); }
477 };
478 
479 // Dynamic array, no dimension
480 class TypeDArray : public TypeArray
481 {
482 public:
483     TypeDArray(Type *t);
484     const char *kind();
485     Type *syntaxCopy();
486     d_uns64 size(Loc loc) /*const*/;
487     unsigned alignsize() /*const*/;
488     Type *semantic(Loc loc, Scope *sc);
489     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps, bool intypeid = false);
490     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
491     bool isString();
492     bool isZeroInit(Loc loc) /*const*/;
493     bool isBoolean() /*const*/;
494     MATCH implicitConvTo(Type *to);
495     Expression *defaultInit(Loc loc);
496     bool hasPointers() /*const*/;
497 
accept(Visitor * v)498     void accept(Visitor *v) { v->visit(this); }
499 };
500 
501 class TypeAArray : public TypeArray
502 {
503 public:
504     Type *index;                // key type
505     Loc loc;
506     Scope *sc;
507 
508     TypeAArray(Type *t, Type *index);
509     static TypeAArray *create(Type *t, Type *index);
510     const char *kind();
511     Type *syntaxCopy();
512     d_uns64 size(Loc loc);
513     Type *semantic(Loc loc, Scope *sc);
514     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps, bool intypeid = false);
515     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
516     Expression *defaultInit(Loc loc);
517     bool isZeroInit(Loc loc) /*const*/;
518     bool isBoolean() /*const*/;
519     bool hasPointers() /*const*/;
520     MATCH implicitConvTo(Type *to);
521     MATCH constConv(Type *to);
522 
accept(Visitor * v)523     void accept(Visitor *v) { v->visit(this); }
524 };
525 
526 class TypePointer : public TypeNext
527 {
528 public:
529     TypePointer(Type *t);
530     static TypePointer *create(Type *t);
531     const char *kind();
532     Type *syntaxCopy();
533     Type *semantic(Loc loc, Scope *sc);
534     d_uns64 size(Loc loc) /*const*/;
535     MATCH implicitConvTo(Type *to);
536     MATCH constConv(Type *to);
537     bool isscalar() /*const*/;
538     Expression *defaultInit(Loc loc);
539     bool isZeroInit(Loc loc) /*const*/;
540     bool hasPointers() /*const*/;
541 
accept(Visitor * v)542     void accept(Visitor *v) { v->visit(this); }
543 };
544 
545 class TypeReference : public TypeNext
546 {
547 public:
548     TypeReference(Type *t);
549     const char *kind();
550     Type *syntaxCopy();
551     Type *semantic(Loc loc, Scope *sc);
552     d_uns64 size(Loc loc) /*const*/;
553     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
554     Expression *defaultInit(Loc loc);
555     bool isZeroInit(Loc loc) /*const*/;
accept(Visitor * v)556     void accept(Visitor *v) { v->visit(this); }
557 };
558 
559 enum RET
560 {
561     RETregs     = 1,    // returned in registers
562     RETstack    = 2     // returned on stack
563 };
564 
565 enum TRUST
566 {
567     TRUSTdefault = 0,
568     TRUSTsystem = 1,    // @system (same as TRUSTdefault)
569     TRUSTtrusted = 2,   // @trusted
570     TRUSTsafe = 3       // @safe
571 };
572 
573 // in hdrgen.c
574 void trustToBuffer(OutBuffer *buf, TRUST trust);
575 const char *trustToChars(TRUST trust);
576 
577 enum TRUSTformat
578 {
579     TRUSTformatDefault,  // do not emit @system when trust == TRUSTdefault
580     TRUSTformatSystem    // emit @system when trust == TRUSTdefault
581 };
582 
583 enum PURE
584 {
585     PUREimpure = 0,     // not pure at all
586     PUREfwdref = 1,     // it's pure, but not known which level yet
587     PUREweak = 2,       // no mutable globals are read or written
588     PUREconst = 3,      // parameters are values or const
589     PUREstrong = 4      // parameters are values or immutable
590 };
591 
592 class TypeFunction : public TypeNext
593 {
594 public:
595     // .next is the return type
596 
597     Parameters *parameters;     // function parameters
598     int varargs;        // 1: T t, ...) style for variable number of arguments
599                         // 2: T t ...) style for variable number of arguments
600     bool isnothrow;     // true: nothrow
601     bool isnogc;        // true: is @nogc
602     bool isproperty;    // can be called without parentheses
603     bool isref;         // true: returns a reference
604     bool isreturn;      // true: 'this' is returned by ref
605     bool isscope;       // true: 'this' is scope
606     bool isscopeinferred; // true: 'this' is scope from inference
607     LINK linkage;  // calling convention
608     TRUST trust;   // level of trust
609     PURE purity;   // PURExxxx
610     unsigned char iswild;   // bit0: inout on params, bit1: inout on qualifier
611     Expressions *fargs; // function arguments
612 
613     int inuse;
614 
615     TypeFunction(Parameters *parameters, Type *treturn, int varargs, LINK linkage, StorageClass stc = 0);
616     static TypeFunction *create(Parameters *parameters, Type *treturn, int varargs, LINK linkage, StorageClass stc = 0);
617     const char *kind();
618     Type *syntaxCopy();
619     Type *semantic(Loc loc, Scope *sc);
620     void purityLevel();
621     bool hasLazyParameters();
622     bool parameterEscapes(Parameter *p);
623     StorageClass parameterStorageClass(Parameter *p);
624     Type *addStorageClass(StorageClass stc);
625 
626     /** For each active attribute (ref/const/nogc/etc) call fp with a void* for the
627     work param and a string representation of the attribute. */
628     int attributesApply(void *param, int (*fp)(void *, const char *), TRUSTformat trustFormat = TRUSTformatDefault);
629 
630     Type *substWildTo(unsigned mod);
631     MATCH callMatch(Type *tthis, Expressions *toargs, int flag = 0);
632     bool checkRetType(Loc loc);
633 
634     Expression *defaultInit(Loc loc) /*const*/;
accept(Visitor * v)635     void accept(Visitor *v) { v->visit(this); }
636 };
637 
638 class TypeDelegate : public TypeNext
639 {
640 public:
641     // .next is a TypeFunction
642 
643     TypeDelegate(Type *t);
644     static TypeDelegate *create(Type *t);
645     const char *kind();
646     Type *syntaxCopy();
647     Type *semantic(Loc loc, Scope *sc);
648     Type *addStorageClass(StorageClass stc);
649     d_uns64 size(Loc loc) /*const*/;
650     unsigned alignsize() /*const*/;
651     MATCH implicitConvTo(Type *to);
652     Expression *defaultInit(Loc loc);
653     bool isZeroInit(Loc loc) /*const*/;
654     bool isBoolean() /*const*/;
655     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
656     bool hasPointers() /*const*/;
657 
accept(Visitor * v)658     void accept(Visitor *v) { v->visit(this); }
659 };
660 
661 class TypeQualified : public Type
662 {
663 public:
664     Loc loc;
665     // array of Identifier and TypeInstance,
666     // representing ident.ident!tiargs.ident. ... etc.
667     Objects idents;
668 
669     TypeQualified(TY ty, Loc loc);
670     void syntaxCopyHelper(TypeQualified *t);
671     void addIdent(Identifier *ident);
672     void addInst(TemplateInstance *inst);
673     void addIndex(RootObject *expr);
674     d_uns64 size(Loc loc);
675 
676     void resolveTupleIndex(Loc loc, Scope *sc, Dsymbol *s,
677         Expression **pe, Type **pt, Dsymbol **ps, RootObject *oindex);
678     void resolveHelper(Loc loc, Scope *sc, Dsymbol *s, Dsymbol *scopesym,
679         Expression **pe, Type **pt, Dsymbol **ps, bool intypeid = false);
680 
accept(Visitor * v)681     void accept(Visitor *v) { v->visit(this); }
682 };
683 
684 class TypeIdentifier : public TypeQualified
685 {
686 public:
687     Identifier *ident;
688     Dsymbol *originalSymbol; // The symbol representing this identifier, before alias resolution
689 
690     TypeIdentifier(Loc loc, Identifier *ident);
691     const char *kind();
692     Type *syntaxCopy();
693     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps, bool intypeid = false);
694     Dsymbol *toDsymbol(Scope *sc);
695     Type *semantic(Loc loc, Scope *sc);
accept(Visitor * v)696     void accept(Visitor *v) { v->visit(this); }
697 };
698 
699 /* Similar to TypeIdentifier, but with a TemplateInstance as the root
700  */
701 class TypeInstance : public TypeQualified
702 {
703 public:
704     TemplateInstance *tempinst;
705 
706     TypeInstance(Loc loc, TemplateInstance *tempinst);
707     const char *kind();
708     Type *syntaxCopy();
709     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps, bool intypeid = false);
710     Type *semantic(Loc loc, Scope *sc);
711     Dsymbol *toDsymbol(Scope *sc);
accept(Visitor * v)712     void accept(Visitor *v) { v->visit(this); }
713 };
714 
715 class TypeTypeof : public TypeQualified
716 {
717 public:
718     Expression *exp;
719     int inuse;
720 
721     TypeTypeof(Loc loc, Expression *exp);
722     const char *kind();
723     Type *syntaxCopy();
724     Dsymbol *toDsymbol(Scope *sc);
725     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps, bool intypeid = false);
726     Type *semantic(Loc loc, Scope *sc);
727     d_uns64 size(Loc loc);
accept(Visitor * v)728     void accept(Visitor *v) { v->visit(this); }
729 };
730 
731 class TypeReturn : public TypeQualified
732 {
733 public:
734     TypeReturn(Loc loc);
735     const char *kind();
736     Type *syntaxCopy();
737     Dsymbol *toDsymbol(Scope *sc);
738     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps, bool intypeid = false);
739     Type *semantic(Loc loc, Scope *sc);
accept(Visitor * v)740     void accept(Visitor *v) { v->visit(this); }
741 };
742 
743 // Whether alias this dependency is recursive or not.
744 enum AliasThisRec
745 {
746     RECno = 0,      // no alias this recursion
747     RECyes = 1,     // alias this has recursive dependency
748     RECfwdref = 2,  // not yet known
749     RECtypeMask = 3,// mask to read no/yes/fwdref
750 
751     RECtracing = 0x4, // mark in progress of implicitConvTo/deduceWild
752     RECtracingDT = 0x8  // mark in progress of deduceType
753 };
754 
755 class TypeStruct : public Type
756 {
757 public:
758     StructDeclaration *sym;
759     AliasThisRec att;
760     CPPMANGLE cppmangle;
761 
762     TypeStruct(StructDeclaration *sym);
763     static TypeStruct *create(StructDeclaration *sym);
764     const char *kind();
765     d_uns64 size(Loc loc);
766     unsigned alignsize();
767     Type *syntaxCopy();
768     Type *semantic(Loc loc, Scope *sc);
769     Dsymbol *toDsymbol(Scope *sc);
770     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
771     structalign_t alignment();
772     Expression *defaultInit(Loc loc);
773     Expression *defaultInitLiteral(Loc loc);
774     bool isZeroInit(Loc loc) /*const*/;
775     bool isAssignable();
776     bool isBoolean() /*const*/;
777     bool needsDestruction() /*const*/;
778     bool needsNested();
779     bool hasPointers();
780     bool hasVoidInitPointers();
781     MATCH implicitConvTo(Type *to);
782     MATCH constConv(Type *to);
783     unsigned char deduceWild(Type *t, bool isRef);
784     Type *toHeadMutable();
785 
accept(Visitor * v)786     void accept(Visitor *v) { v->visit(this); }
787 };
788 
789 class TypeEnum : public Type
790 {
791 public:
792     EnumDeclaration *sym;
793 
794     TypeEnum(EnumDeclaration *sym);
795     const char *kind();
796     Type *syntaxCopy();
797     d_uns64 size(Loc loc);
798     unsigned alignsize();
799     Type *semantic(Loc loc, Scope *sc);
800     Dsymbol *toDsymbol(Scope *sc);
801     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
802     Expression *getProperty(Loc loc, Identifier *ident, int flag);
803     bool isintegral();
804     bool isfloating();
805     bool isreal();
806     bool isimaginary();
807     bool iscomplex();
808     bool isscalar();
809     bool isunsigned();
810     bool isBoolean();
811     bool isString();
812     bool isAssignable();
813     bool needsDestruction();
814     bool needsNested();
815     MATCH implicitConvTo(Type *to);
816     MATCH constConv(Type *to);
817     Type *toBasetype();
818     Expression *defaultInit(Loc loc);
819     bool isZeroInit(Loc loc);
820     bool hasPointers();
821     bool hasVoidInitPointers();
822     Type *nextOf();
823 
accept(Visitor * v)824     void accept(Visitor *v) { v->visit(this); }
825 };
826 
827 class TypeClass : public Type
828 {
829 public:
830     ClassDeclaration *sym;
831     AliasThisRec att;
832     CPPMANGLE cppmangle;
833 
834     TypeClass(ClassDeclaration *sym);
835     const char *kind();
836     d_uns64 size(Loc loc) /*const*/;
837     Type *syntaxCopy();
838     Type *semantic(Loc loc, Scope *sc);
839     Dsymbol *toDsymbol(Scope *sc);
840     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident, int flag);
841     ClassDeclaration *isClassHandle();
842     bool isBaseOf(Type *t, int *poffset);
843     MATCH implicitConvTo(Type *to);
844     MATCH constConv(Type *to);
845     unsigned char deduceWild(Type *t, bool isRef);
846     Type *toHeadMutable();
847     Expression *defaultInit(Loc loc);
848     bool isZeroInit(Loc loc) /*const*/;
849     bool isscope() /*const*/;
850     bool isBoolean() /*const*/;
851     bool hasPointers() /*const*/;
852 
accept(Visitor * v)853     void accept(Visitor *v) { v->visit(this); }
854 };
855 
856 class TypeTuple : public Type
857 {
858 public:
859     Parameters *arguments;      // types making up the tuple
860 
861     TypeTuple(Parameters *arguments);
862     TypeTuple(Expressions *exps);
863     static TypeTuple *create(Parameters *arguments);
864     TypeTuple();
865     TypeTuple(Type *t1);
866     TypeTuple(Type *t1, Type *t2);
867     const char *kind();
868     Type *syntaxCopy();
869     Type *semantic(Loc loc, Scope *sc);
870     bool equals(RootObject *o);
871     Expression *getProperty(Loc loc, Identifier *ident, int flag);
872     Expression *defaultInit(Loc loc);
accept(Visitor * v)873     void accept(Visitor *v) { v->visit(this); }
874 };
875 
876 class TypeSlice : public TypeNext
877 {
878 public:
879     Expression *lwr;
880     Expression *upr;
881 
882     TypeSlice(Type *next, Expression *lwr, Expression *upr);
883     const char *kind();
884     Type *syntaxCopy();
885     Type *semantic(Loc loc, Scope *sc);
886     void resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps, bool intypeid = false);
accept(Visitor * v)887     void accept(Visitor *v) { v->visit(this); }
888 };
889 
890 class TypeNull : public Type
891 {
892 public:
893     TypeNull();
894     const char *kind();
895 
896     Type *syntaxCopy();
897     MATCH implicitConvTo(Type *to);
898     bool isBoolean() /*const*/;
899 
900     d_uns64 size(Loc loc) /*const*/;
901     Expression *defaultInit(Loc loc) /*const*/;
accept(Visitor * v)902     void accept(Visitor *v) { v->visit(this); }
903 };
904 
905 /**************************************************************/
906 
907 //enum InOut { None, In, Out, InOut, Lazy };
908 
909 class Parameter : public RootObject
910 {
911 public:
912     //enum InOut inout;
913     StorageClass storageClass;
914     Type *type;
915     Identifier *ident;
916     Expression *defaultArg;
917 
918     Parameter(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg);
919     static Parameter *create(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg);
920     Parameter *syntaxCopy();
921     Type *isLazyArray();
922     // kludge for template.isType()
dyncast()923     int dyncast() const { return DYNCAST_PARAMETER; }
accept(Visitor * v)924     virtual void accept(Visitor *v) { v->visit(this); }
925 
926     static Parameters *arraySyntaxCopy(Parameters *parameters);
927     static size_t dim(Parameters *parameters);
928     static Parameter *getNth(Parameters *parameters, d_size_t nth, d_size_t *pn = NULL);
929     const char *toChars();
930     bool isCovariant(bool returnByRef, const Parameter *p) const;
931     static bool isCovariantScope(bool returnByRef, StorageClass from, StorageClass to);
932 };
933 
934 bool arrayTypeCompatible(Loc loc, Type *t1, Type *t2);
935 bool arrayTypeCompatibleWithoutCasting(Type *t1, Type *t2);
936