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
13 #include "root/root.h"
14 #include "root/stringtable.h"
15 #include "root/dcompat.h" // for d_size_t
17 #include "arraytypes.h"
19 #include "expression.h"
25 class StructDeclaration
;
26 class ClassDeclaration
;
27 class EnumDeclaration
;
28 class TypeInfoDeclaration
;
30 class TemplateInstance
;
31 class TemplateDeclaration
;
39 typedef union tree_node type
;
41 typedef struct TYPE type
;
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
);
50 Tarray
, // slice array, aka T[]
51 Tsarray
, // static array, aka T[dimension]
52 Taarray
, // associative array, aka T[type]
101 typedef unsigned char TY
; // ENUMTY
103 #define SIZE_INVALID (~(d_uns64)0) // error return from size() functions
108 * pick this order of numbers so switch statements work better
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)
119 typedef unsigned char MOD
;
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
];
127 // If !=0, give warning on implicit conversion
128 extern unsigned char impcnvWarn
[TMAX
][TMAX
];
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
138 class Type
: public ASTNode
142 MOD mod
; // modifiers MODxxxx
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
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
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
166 type
*ctype
; // for back end
177 static Type
*tint128
;
178 static Type
*tuns128
;
179 static Type
*tfloat32
;
180 static Type
*tfloat64
;
181 static Type
*tfloat80
;
183 static Type
*timaginary32
;
184 static Type
*timaginary64
;
185 static Type
*timaginary80
;
187 static Type
*tcomplex32
;
188 static Type
*tcomplex64
;
189 static Type
*tcomplex80
;
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
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
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
;
227 static TemplateDeclaration
*rtinfo
;
229 static Type
*basic
[TMAX
];
230 static unsigned char sizeTy
[TMAX
];
231 static StringTable stringtable
;
234 virtual const char *kind();
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);
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
);
253 void modToBuffer(OutBuffer
*buf
);
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 *));
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();
286 Type
*sharedConstOf();
290 Type
*sharedWildOf();
291 Type
*sharedWildConstOf();
294 Type
*addSTC(StorageClass stc
);
295 Type
*castMod(MOD mod
);
296 Type
*addMod(MOD mod
);
297 virtual Type
*addStorageClass(StorageClass stc
);
301 Type
*sarrayOf(dinteger_t dim
);
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
);
321 Type
*unqualify(unsigned m
);
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();
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();
347 static void error(Loc loc
, const char *format
, ...);
348 static void warning(Loc loc
, const char *format
, ...);
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();
373 void accept(Visitor
*v
) { v
->visit(this); }
376 class TypeError
: public Type
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); }
390 class TypeNext
: public Type
395 TypeNext(TY ty
, Type
*next
);
396 void checkDeprecated(Loc loc
, Scope
*sc
);
400 Type
*makeImmutable();
402 Type
*makeSharedConst();
404 Type
*makeWildConst();
405 Type
*makeSharedWild();
406 Type
*makeSharedWildConst();
408 MATCH
constConv(Type
*to
);
409 unsigned char deduceWild(Type
*t
, bool isRef
);
411 void accept(Visitor
*v
) { v
->visit(this); }
414 class TypeBasic
: public Type
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
);
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*/;
438 // For eliminating dynamic_cast
439 TypeBasic
*isTypeBasic();
440 void accept(Visitor
*v
) { v
->visit(this); }
443 class TypeVector
: public Type
448 TypeVector(Type
*basetype
);
449 static TypeVector
*create(Type
*basetype
);
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
);
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
);
468 void accept(Visitor
*v
) { v
->visit(this); }
471 class TypeArray
: public TypeNext
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); }
479 // Static array, one with a fixed dimension
480 class TypeSArray
: public TypeArray
485 TypeSArray(Type
*t
, Expression
*dim
);
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
);
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
);
501 bool needsDestruction();
504 void accept(Visitor
*v
) { v
->visit(this); }
507 // Dynamic array, no dimension
508 class TypeDArray
: public TypeArray
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
);
520 bool isZeroInit(Loc loc
) /*const*/;
521 bool isBoolean() /*const*/;
522 MATCH
implicitConvTo(Type
*to
);
523 Expression
*defaultInit(Loc loc
);
524 bool hasPointers() /*const*/;
526 void accept(Visitor
*v
) { v
->visit(this); }
529 class TypeAArray
: public TypeArray
532 Type
*index
; // key type
536 TypeAArray(Type
*t
, Type
*index
);
537 static TypeAArray
*create(Type
*t
, Type
*index
);
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
);
551 void accept(Visitor
*v
) { v
->visit(this); }
554 class TypePointer
: public TypeNext
557 TypePointer(Type
*t
);
558 static TypePointer
*create(Type
*t
);
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*/;
570 void accept(Visitor
*v
) { v
->visit(this); }
573 class TypeReference
: public TypeNext
576 TypeReference(Type
*t
);
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); }
589 RETregs
= 1, // returned in registers
590 RETstack
= 2 // returned on stack
596 TRUSTsystem
= 1, // @system (same as TRUSTdefault)
597 TRUSTtrusted
= 2, // @trusted
598 TRUSTsafe
= 3 // @safe
602 void trustToBuffer(OutBuffer
*buf
, TRUST trust
);
603 const char *trustToChars(TRUST trust
);
607 TRUSTformatDefault
, // do not emit @system when trust == TRUSTdefault
608 TRUSTformatSystem
// emit @system when trust == TRUSTdefault
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
620 class Parameter
: public ASTNode
623 StorageClass storageClass
;
626 Expression
*defaultArg
;
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();
632 // kludge for template.isType()
633 int dyncast() const { return DYNCAST_PARAMETER
; }
634 void accept(Visitor
*v
) { v
->visit(this); }
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
);
646 Parameters
*parameters
;
649 ParameterList(Parameters
*parameters
= NULL
, VarArg varargs
= VARARGnone
);
652 Parameter
*operator[](size_t i
) { return Parameter::getNth(parameters
, i
); }
655 class TypeFunction
: public TypeNext
658 // .next is the return type
660 ParameterList parameterList
; // function parameters
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
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);
681 Type
*semantic(Loc loc
, Scope
*sc
);
683 bool hasLazyParameters();
684 bool isDstyleVariadic() const;
685 bool parameterEscapes(Parameter
*p
);
686 StorageClass
parameterStorageClass(Parameter
*p
);
687 Type
*addStorageClass(StorageClass stc
);
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
);
693 Type
*substWildTo(unsigned mod
);
694 MATCH
callMatch(Type
*tthis
, Expressions
*toargs
, int flag
= 0);
695 bool checkRetType(Loc loc
);
697 Expression
*defaultInit(Loc loc
) /*const*/;
698 void accept(Visitor
*v
) { v
->visit(this); }
701 class TypeDelegate
: public TypeNext
704 // .next is a TypeFunction
706 TypeDelegate(Type
*t
);
707 static TypeDelegate
*create(Type
*t
);
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*/;
721 void accept(Visitor
*v
) { v
->visit(this); }
724 class TypeTraits
: public Type
728 /// The expression to resolve as type or symbol.
730 /// The symbol when exp doesn't represent a type.
733 TypeTraits(const Loc
&loc
, TraitsExp
*exp
);
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); }
741 class TypeQualified
: public Type
745 // array of Identifier and TypeInstance,
746 // representing ident.ident!tiargs.ident. ... etc.
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
);
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);
761 void accept(Visitor
*v
) { v
->visit(this); }
764 class TypeIdentifier
: public TypeQualified
768 Dsymbol
*originalSymbol
; // The symbol representing this identifier, before alias resolution
770 TypeIdentifier(Loc loc
, Identifier
*ident
);
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); }
779 /* Similar to TypeIdentifier, but with a TemplateInstance as the root
781 class TypeInstance
: public TypeQualified
784 TemplateInstance
*tempinst
;
786 TypeInstance(Loc loc
, TemplateInstance
*tempinst
);
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); }
795 class TypeTypeof
: public TypeQualified
801 TypeTypeof(Loc loc
, Expression
*exp
);
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); }
811 class TypeReturn
: public TypeQualified
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); }
823 // Whether alias this dependency is recursive or not.
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
831 RECtracing
= 0x4, // mark in progress of implicitConvTo/deduceWild
832 RECtracingDT
= 0x8 // mark in progress of deduceType
835 class TypeStruct
: public Type
838 StructDeclaration
*sym
;
842 TypeStruct(StructDeclaration
*sym
);
843 static TypeStruct
*create(StructDeclaration
*sym
);
845 d_uns64
size(Loc loc
);
846 unsigned alignsize();
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*/;
856 bool isBoolean() /*const*/;
857 bool needsDestruction() /*const*/;
860 bool hasVoidInitPointers();
861 MATCH
implicitConvTo(Type
*to
);
862 MATCH
constConv(Type
*to
);
863 unsigned char deduceWild(Type
*t
, bool isRef
);
864 Type
*toHeadMutable();
866 void accept(Visitor
*v
) { v
->visit(this); }
869 class TypeEnum
: public Type
872 EnumDeclaration
*sym
;
874 TypeEnum(EnumDeclaration
*sym
);
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
);
893 bool needsDestruction();
895 MATCH
implicitConvTo(Type
*to
);
896 MATCH
constConv(Type
*to
);
898 Expression
*defaultInit(Loc loc
);
899 bool isZeroInit(Loc loc
);
901 bool hasVoidInitPointers();
904 void accept(Visitor
*v
) { v
->visit(this); }
907 class TypeClass
: public Type
910 ClassDeclaration
*sym
;
914 TypeClass(ClassDeclaration
*sym
);
916 d_uns64
size(Loc loc
) /*const*/;
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*/;
933 void accept(Visitor
*v
) { v
->visit(this); }
936 class TypeTuple
: public Type
939 Parameters
*arguments
; // types making up the tuple
941 TypeTuple(Parameters
*arguments
);
942 TypeTuple(Expressions
*exps
);
943 static TypeTuple
*create(Parameters
*arguments
);
946 TypeTuple(Type
*t1
, Type
*t2
);
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); }
956 class TypeSlice
: public TypeNext
962 TypeSlice(Type
*next
, Expression
*lwr
, Expression
*upr
);
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); }
970 class TypeNull
: public Type
977 MATCH
implicitConvTo(Type
*to
);
978 bool isBoolean() /*const*/;
980 d_uns64
size(Loc loc
) /*const*/;
981 Expression
*defaultInit(Loc loc
) /*const*/;
982 void accept(Visitor
*v
) { v
->visit(this); }
985 /**************************************************************/
987 bool arrayTypeCompatible(Loc loc
, Type
*t1
, Type
*t2
);
988 bool arrayTypeCompatibleWithoutCasting(Type
*t1
, Type
*t2
);