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