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
13 #include "root/root.h"
14 #include "root/stringtable.h"
15 #include "root/rmem.h" // for d_size_t
17 #include "arraytypes.h"
18 #include "expression.h"
24 class StructDeclaration
;
25 class ClassDeclaration
;
26 class EnumDeclaration
;
27 class TypeInfoDeclaration
;
29 class TemplateInstance
;
30 class TemplateDeclaration
;
38 typedef union tree_node type
;
40 typedef struct TYPE type
;
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
);
49 Tarray
, // slice array, aka T[]
50 Tsarray
, // static array, aka T[dimension]
51 Taarray
, // associative array, aka T[type]
100 typedef unsigned char TY
; // ENUMTY
103 extern int Tptrdiff_t
;
105 #define SIZE_INVALID (~(d_uns64)0) // error return from size() functions
110 * pick this order of numbers so switch statements work better
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)
121 typedef unsigned char MOD
;
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
];
129 // If !=0, give warning on implicit conversion
130 extern unsigned char impcnvWarn
[TMAX
][TMAX
];
132 class Type
: public RootObject
136 MOD mod
; // modifiers MODxxxx
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
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
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
160 type
*ctype
; // for back end
171 static Type
*tint128
;
172 static Type
*tuns128
;
173 static Type
*tfloat32
;
174 static Type
*tfloat64
;
175 static Type
*tfloat80
;
177 static Type
*timaginary32
;
178 static Type
*timaginary64
;
179 static Type
*timaginary80
;
181 static Type
*tcomplex32
;
182 static Type
*tcomplex64
;
183 static Type
*tcomplex80
;
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
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
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
;
222 static TemplateDeclaration
*rtinfo
;
224 static Type
*basic
[TMAX
];
225 static unsigned char sizeTy
[TMAX
];
226 static StringTable stringtable
;
229 virtual const char *kind();
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);
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
);
248 void modToBuffer(OutBuffer
*buf
);
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 *));
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();
281 Type
*sharedConstOf();
285 Type
*sharedWildOf();
286 Type
*sharedWildConstOf();
289 Type
*addSTC(StorageClass stc
);
290 Type
*castMod(MOD mod
);
291 Type
*addMod(MOD mod
);
292 virtual Type
*addStorageClass(StorageClass stc
);
296 Type
*sarrayOf(dinteger_t dim
);
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
);
316 Type
*unqualify(unsigned m
);
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();
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();
342 static void error(Loc loc
, const char *format
, ...);
343 static void warning(Loc loc
, const char *format
, ...);
345 // For eliminating dynamic_cast
346 virtual TypeBasic
*isTypeBasic();
347 virtual void accept(Visitor
*v
) { v
->visit(this); }
350 class TypeError
: public Type
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); }
364 class TypeNext
: public Type
369 TypeNext(TY ty
, Type
*next
);
370 void checkDeprecated(Loc loc
, Scope
*sc
);
374 Type
*makeImmutable();
376 Type
*makeSharedConst();
378 Type
*makeWildConst();
379 Type
*makeSharedWild();
380 Type
*makeSharedWildConst();
382 MATCH
constConv(Type
*to
);
383 unsigned char deduceWild(Type
*t
, bool isRef
);
385 void accept(Visitor
*v
) { v
->visit(this); }
388 class TypeBasic
: public Type
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
);
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*/;
412 // For eliminating dynamic_cast
413 TypeBasic
*isTypeBasic();
414 void accept(Visitor
*v
) { v
->visit(this); }
417 class TypeVector
: public Type
422 TypeVector(Type
*basetype
);
423 static TypeVector
*create(Loc loc
, Type
*basetype
);
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
);
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
);
442 void accept(Visitor
*v
) { v
->visit(this); }
445 class TypeArray
: public TypeNext
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); }
453 // Static array, one with a fixed dimension
454 class TypeSArray
: public TypeArray
459 TypeSArray(Type
*t
, Expression
*dim
);
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
);
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
);
475 bool needsDestruction();
478 void accept(Visitor
*v
) { v
->visit(this); }
481 // Dynamic array, no dimension
482 class TypeDArray
: public TypeArray
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
);
494 bool isZeroInit(Loc loc
) /*const*/;
495 bool isBoolean() /*const*/;
496 MATCH
implicitConvTo(Type
*to
);
497 Expression
*defaultInit(Loc loc
);
498 bool hasPointers() /*const*/;
500 void accept(Visitor
*v
) { v
->visit(this); }
503 class TypeAArray
: public TypeArray
506 Type
*index
; // key type
510 TypeAArray(Type
*t
, Type
*index
);
511 static TypeAArray
*create(Type
*t
, Type
*index
);
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
);
525 void accept(Visitor
*v
) { v
->visit(this); }
528 class TypePointer
: public TypeNext
531 TypePointer(Type
*t
);
532 static TypePointer
*create(Type
*t
);
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*/;
544 void accept(Visitor
*v
) { v
->visit(this); }
547 class TypeReference
: public TypeNext
550 TypeReference(Type
*t
);
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); }
563 RETregs
= 1, // returned in registers
564 RETstack
= 2 // returned on stack
570 TRUSTsystem
= 1, // @system (same as TRUSTdefault)
571 TRUSTtrusted
= 2, // @trusted
572 TRUSTsafe
= 3 // @safe
576 void trustToBuffer(OutBuffer
*buf
, TRUST trust
);
577 const char *trustToChars(TRUST trust
);
581 TRUSTformatDefault
, // do not emit @system when trust == TRUSTdefault
582 TRUSTformatSystem
// emit @system when trust == TRUSTdefault
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
594 class TypeFunction
: public TypeNext
597 // .next is the return type
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
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);
621 Type
*semantic(Loc loc
, Scope
*sc
);
623 bool hasLazyParameters();
624 bool parameterEscapes(Parameter
*p
);
625 StorageClass
parameterStorageClass(Parameter
*p
);
626 Type
*addStorageClass(StorageClass stc
);
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
);
632 Type
*substWildTo(unsigned mod
);
633 MATCH
callMatch(Type
*tthis
, Expressions
*toargs
, int flag
= 0);
634 bool checkRetType(Loc loc
);
636 Expression
*defaultInit(Loc loc
) /*const*/;
637 void accept(Visitor
*v
) { v
->visit(this); }
640 class TypeDelegate
: public TypeNext
643 // .next is a TypeFunction
645 TypeDelegate(Type
*t
);
646 static TypeDelegate
*create(Type
*t
);
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*/;
660 void accept(Visitor
*v
) { v
->visit(this); }
663 class TypeTraits
: public Type
667 /// The expression to resolve as type or symbol.
669 /// The symbol when exp doesn't represent a type.
672 TypeTraits(const Loc
&loc
, TraitsExp
*exp
);
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); }
680 class TypeQualified
: public Type
684 // array of Identifier and TypeInstance,
685 // representing ident.ident!tiargs.ident. ... etc.
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
);
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);
700 void accept(Visitor
*v
) { v
->visit(this); }
703 class TypeIdentifier
: public TypeQualified
707 Dsymbol
*originalSymbol
; // The symbol representing this identifier, before alias resolution
709 TypeIdentifier(Loc loc
, Identifier
*ident
);
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); }
718 /* Similar to TypeIdentifier, but with a TemplateInstance as the root
720 class TypeInstance
: public TypeQualified
723 TemplateInstance
*tempinst
;
725 TypeInstance(Loc loc
, TemplateInstance
*tempinst
);
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); }
734 class TypeTypeof
: public TypeQualified
740 TypeTypeof(Loc loc
, Expression
*exp
);
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); }
750 class TypeReturn
: public TypeQualified
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); }
762 // Whether alias this dependency is recursive or not.
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
770 RECtracing
= 0x4, // mark in progress of implicitConvTo/deduceWild
771 RECtracingDT
= 0x8 // mark in progress of deduceType
774 class TypeStruct
: public Type
777 StructDeclaration
*sym
;
781 TypeStruct(StructDeclaration
*sym
);
782 static TypeStruct
*create(StructDeclaration
*sym
);
784 d_uns64
size(Loc loc
);
785 unsigned alignsize();
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*/;
795 bool isBoolean() /*const*/;
796 bool needsDestruction() /*const*/;
799 bool hasVoidInitPointers();
800 MATCH
implicitConvTo(Type
*to
);
801 MATCH
constConv(Type
*to
);
802 unsigned char deduceWild(Type
*t
, bool isRef
);
803 Type
*toHeadMutable();
805 void accept(Visitor
*v
) { v
->visit(this); }
808 class TypeEnum
: public Type
811 EnumDeclaration
*sym
;
813 TypeEnum(EnumDeclaration
*sym
);
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
);
832 bool needsDestruction();
834 MATCH
implicitConvTo(Type
*to
);
835 MATCH
constConv(Type
*to
);
837 Expression
*defaultInit(Loc loc
);
838 bool isZeroInit(Loc loc
);
840 bool hasVoidInitPointers();
843 void accept(Visitor
*v
) { v
->visit(this); }
846 class TypeClass
: public Type
849 ClassDeclaration
*sym
;
853 TypeClass(ClassDeclaration
*sym
);
855 d_uns64
size(Loc loc
) /*const*/;
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*/;
872 void accept(Visitor
*v
) { v
->visit(this); }
875 class TypeTuple
: public Type
878 Parameters
*arguments
; // types making up the tuple
880 TypeTuple(Parameters
*arguments
);
881 TypeTuple(Expressions
*exps
);
882 static TypeTuple
*create(Parameters
*arguments
);
885 TypeTuple(Type
*t1
, Type
*t2
);
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); }
895 class TypeSlice
: public TypeNext
901 TypeSlice(Type
*next
, Expression
*lwr
, Expression
*upr
);
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); }
909 class TypeNull
: public Type
916 MATCH
implicitConvTo(Type
*to
);
917 bool isBoolean() /*const*/;
919 d_uns64
size(Loc loc
) /*const*/;
920 Expression
*defaultInit(Loc loc
) /*const*/;
921 void accept(Visitor
*v
) { v
->visit(this); }
924 /**************************************************************/
926 //enum InOut { None, In, Out, InOut, Lazy };
928 class Parameter
: public RootObject
932 StorageClass storageClass
;
935 Expression
*defaultArg
;
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();
941 // kludge for template.isType()
942 int dyncast() const { return DYNCAST_PARAMETER
; }
943 virtual void accept(Visitor
*v
) { v
->visit(this); }
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
);
953 bool arrayTypeCompatible(Loc loc
, Type
*t1
, Type
*t2
);
954 bool arrayTypeCompatibleWithoutCasting(Type
*t1
, Type
*t2
);