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