| 1 |
|
| 2 |
/* Compiler implementation of the D programming language |
| 3 |
* Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved |
| 4 |
* written by Walter Bright |
| 5 |
* https://www.digitalmars.com |
| 6 |
* Distributed under the Boost Software License, Version 1.0. |
| 7 |
* https://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/dcompat.h" // for d_size_t |
| 14 |
|
| 15 |
#include "arraytypes.h" |
| 16 |
#include "ast_node.h" |
| 17 |
#include "expression.h" |
| 18 |
#include "globals.h" |
| 19 |
#include "visitor.h" |
| 20 |
|
| 21 |
struct Scope; |
| 22 |
class AggregateDeclaration; |
| 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 |
|
| 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 |
namespace dmd |
| 44 |
{ |
| 45 |
Type *typeSemantic(Type *t, Loc loc, Scope *sc); |
| 46 |
Type *merge(Type *type); |
| 47 |
} |
| 48 |
|
| 49 |
enum class TY : uint8_t |
| 50 |
{ |
| 51 |
Tarray, // slice array, aka T[] |
| 52 |
Tsarray, // static array, aka T[dimension] |
| 53 |
Taarray, // associative array, aka T[type] |
| 54 |
Tpointer, |
| 55 |
Treference, |
| 56 |
Tfunction, |
| 57 |
Tident, |
| 58 |
Tclass, |
| 59 |
Tstruct, |
| 60 |
Tenum, |
| 61 |
|
| 62 |
Tdelegate, |
| 63 |
Tnone, |
| 64 |
Tvoid, |
| 65 |
Tint8, |
| 66 |
Tuns8, |
| 67 |
Tint16, |
| 68 |
Tuns16, |
| 69 |
Tint32, |
| 70 |
Tuns32, |
| 71 |
Tint64, |
| 72 |
|
| 73 |
Tuns64, |
| 74 |
Tfloat32, |
| 75 |
Tfloat64, |
| 76 |
Tfloat80, |
| 77 |
Timaginary32, |
| 78 |
Timaginary64, |
| 79 |
Timaginary80, |
| 80 |
Tcomplex32, |
| 81 |
Tcomplex64, |
| 82 |
Tcomplex80, |
| 83 |
|
| 84 |
Tbool, |
| 85 |
Tchar, |
| 86 |
Twchar, |
| 87 |
Tdchar, |
| 88 |
Terror, |
| 89 |
Tinstance, |
| 90 |
Ttypeof, |
| 91 |
Ttuple, |
| 92 |
Tslice, |
| 93 |
Treturn, |
| 94 |
|
| 95 |
Tnull, |
| 96 |
Tvector, |
| 97 |
Tint128, |
| 98 |
Tuns128, |
| 99 |
Ttraits, |
| 100 |
Tmixin, |
| 101 |
Tnoreturn, |
| 102 |
TMAX |
| 103 |
}; |
| 104 |
|
| 105 |
#define SIZE_INVALID (~(uinteger_t)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 |
MODnone = 0, // default (mutable) |
| 115 |
MODconst = 1, // type is const |
| 116 |
MODimmutable = 4, // type is immutable |
| 117 |
MODshared = 2, // type is shared |
| 118 |
MODwild = 8, // type is wild |
| 119 |
MODwildconst = (MODwild | MODconst), // type is wild const |
| 120 |
MODmutable = 0x10 // type is mutable (only used in wildcard matching) |
| 121 |
}; |
| 122 |
typedef unsigned char MOD; |
| 123 |
|
| 124 |
enum VarArgValues |
| 125 |
{ |
| 126 |
VARARGnone = 0, /// fixed number of arguments |
| 127 |
VARARGvariadic = 1, /// T t, ...) can be C-style (core.stdc.stdarg) or D-style (core.vararg) |
| 128 |
VARARGtypesafe = 2, /// T t ...) typesafe https://dlang.org/spec/function.html#typesafe_variadic_functions |
| 129 |
/// or https://dlang.org/spec/function.html#typesafe_variadic_functions |
| 130 |
VARARGKRvariadic = 3 /// K+R C style variadics (no function prototype) |
| 131 |
}; |
| 132 |
typedef unsigned char VarArg; |
| 133 |
|
| 134 |
enum class Covariant |
| 135 |
{ |
| 136 |
distinct = 0, /// types are distinct |
| 137 |
yes = 1, /// types are covariant |
| 138 |
no = 2, /// arguments match as far as overloading goes, but types are not covariant |
| 139 |
fwdref = 3, /// cannot determine covariance because of forward references |
| 140 |
}; |
| 141 |
|
| 142 |
class Type : public ASTNode |
| 143 |
{ |
| 144 |
public: |
| 145 |
TY ty; |
| 146 |
MOD mod; // modifiers MODxxxx |
| 147 |
char *deco; |
| 148 |
void* mcache; |
| 149 |
TypeInfoDeclaration *vtinfo; // TypeInfo object for this Type |
| 150 |
|
| 151 |
type *ctype; // for back end |
| 152 |
|
| 153 |
static Type *tvoid; |
| 154 |
static Type *tint8; |
| 155 |
static Type *tuns8; |
| 156 |
static Type *tint16; |
| 157 |
static Type *tuns16; |
| 158 |
static Type *tint32; |
| 159 |
static Type *tuns32; |
| 160 |
static Type *tint64; |
| 161 |
static Type *tuns64; |
| 162 |
static Type *tint128; |
| 163 |
static Type *tuns128; |
| 164 |
static Type *tfloat32; |
| 165 |
static Type *tfloat64; |
| 166 |
static Type *tfloat80; |
| 167 |
|
| 168 |
static Type *timaginary32; |
| 169 |
static Type *timaginary64; |
| 170 |
static Type *timaginary80; |
| 171 |
|
| 172 |
static Type *tcomplex32; |
| 173 |
static Type *tcomplex64; |
| 174 |
static Type *tcomplex80; |
| 175 |
|
| 176 |
static Type *tbool; |
| 177 |
static Type *tchar; |
| 178 |
static Type *twchar; |
| 179 |
static Type *tdchar; |
| 180 |
|
| 181 |
// Some special types |
| 182 |
static Type *tshiftcnt; |
| 183 |
static Type *tvoidptr; // void* |
| 184 |
static Type *tstring; // immutable(char)[] |
| 185 |
static Type *twstring; // immutable(wchar)[] |
| 186 |
static Type *tdstring; // immutable(dchar)[] |
| 187 |
static Type *terror; // for error recovery |
| 188 |
static Type *tnull; // for null type |
| 189 |
static Type *tnoreturn; // for bottom type typeof(*null) |
| 190 |
|
| 191 |
static Type *tsize_t; // matches size_t alias |
| 192 |
static Type *tptrdiff_t; // matches ptrdiff_t alias |
| 193 |
static Type *thash_t; // matches hash_t alias |
| 194 |
|
| 195 |
static ClassDeclaration *dtypeinfo; |
| 196 |
static ClassDeclaration *typeinfoclass; |
| 197 |
static ClassDeclaration *typeinfointerface; |
| 198 |
static ClassDeclaration *typeinfostruct; |
| 199 |
static ClassDeclaration *typeinfopointer; |
| 200 |
static ClassDeclaration *typeinfoarray; |
| 201 |
static ClassDeclaration *typeinfostaticarray; |
| 202 |
static ClassDeclaration *typeinfoassociativearray; |
| 203 |
static ClassDeclaration *typeinfovector; |
| 204 |
static ClassDeclaration *typeinfoenum; |
| 205 |
static ClassDeclaration *typeinfofunction; |
| 206 |
static ClassDeclaration *typeinfodelegate; |
| 207 |
static ClassDeclaration *typeinfotypelist; |
| 208 |
static ClassDeclaration *typeinfoconst; |
| 209 |
static ClassDeclaration *typeinfoinvariant; |
| 210 |
static ClassDeclaration *typeinfoshared; |
| 211 |
static ClassDeclaration *typeinfowild; |
| 212 |
|
| 213 |
static TemplateDeclaration *rtinfo; |
| 214 |
|
| 215 |
static Type *basic[(int)TY::TMAX]; |
| 216 |
|
| 217 |
virtual const char *kind(); |
| 218 |
Type *copy() const; |
| 219 |
virtual Type *syntaxCopy(); |
| 220 |
bool equals(const RootObject * const o) const override; |
| 221 |
// kludge for template.isType() |
| 222 |
DYNCAST dyncast() const override final { return DYNCAST_TYPE; } |
| 223 |
size_t getUniqueID() const; |
| 224 |
const char *toChars() const override; |
| 225 |
char *toPrettyChars(bool QualifyTypes = false); |
| 226 |
static void _init(); |
| 227 |
|
| 228 |
virtual unsigned alignsize(); |
| 229 |
void modToBuffer(OutBuffer& buf) const; |
| 230 |
char *modToChars() const; |
| 231 |
|
| 232 |
virtual bool isIntegral(); |
| 233 |
virtual bool isFloating(); // real, imaginary, or complex |
| 234 |
virtual bool isReal(); |
| 235 |
virtual bool isImaginary(); |
| 236 |
virtual bool isComplex(); |
| 237 |
virtual bool isScalar(); |
| 238 |
virtual bool isUnsigned(); |
| 239 |
virtual bool isScopeClass(); |
| 240 |
virtual bool isString(); |
| 241 |
virtual bool isAssignable(); |
| 242 |
virtual bool isBoolean(); |
| 243 |
bool isConst() const { return (mod & MODconst) != 0; } |
| 244 |
bool isImmutable() const { return (mod & MODimmutable) != 0; } |
| 245 |
bool isMutable() const { return (mod & (MODconst | MODimmutable | MODwild)) == 0; } |
| 246 |
bool isShared() const { return (mod & MODshared) != 0; } |
| 247 |
bool isSharedConst() const { return (mod & (MODshared | MODconst)) == (MODshared | MODconst); } |
| 248 |
bool isWild() const { return (mod & MODwild) != 0; } |
| 249 |
bool isWildConst() const { return (mod & MODwildconst) == MODwildconst; } |
| 250 |
bool isSharedWild() const { return (mod & (MODshared | MODwild)) == (MODshared | MODwild); } |
| 251 |
bool isNaked() const { return mod == 0; } |
| 252 |
Type *nullAttributes() const; |
| 253 |
bool hasDeprecatedAliasThis(); |
| 254 |
virtual Type *makeConst(); |
| 255 |
virtual Type *makeImmutable(); |
| 256 |
virtual Type *makeShared(); |
| 257 |
virtual Type *makeSharedConst(); |
| 258 |
virtual Type *makeWild(); |
| 259 |
virtual Type *makeWildConst(); |
| 260 |
virtual Type *makeSharedWild(); |
| 261 |
virtual Type *makeSharedWildConst(); |
| 262 |
virtual Type *makeMutable(); |
| 263 |
Type *toBasetype(); |
| 264 |
virtual unsigned char deduceWild(Type *t, bool isRef); |
| 265 |
|
| 266 |
virtual ClassDeclaration *isClassHandle(); |
| 267 |
virtual structalign_t alignment(); |
| 268 |
virtual Expression *defaultInitLiteral(Loc loc); |
| 269 |
virtual int hasWild() const; |
| 270 |
virtual bool hasVoidInitPointers(); |
| 271 |
virtual bool hasUnsafeBitpatterns(); |
| 272 |
virtual bool hasInvariant(); |
| 273 |
virtual Type *nextOf(); |
| 274 |
Type *baseElemOf(); |
| 275 |
virtual bool needsDestruction(); |
| 276 |
virtual bool needsCopyOrPostblit(); |
| 277 |
virtual bool needsNested(); |
| 278 |
|
| 279 |
TypeFunction *toTypeFunction(); |
| 280 |
|
| 281 |
// For eliminating dynamic_cast |
| 282 |
virtual TypeBasic *isTypeBasic(); |
| 283 |
TypeFunction *isPtrToFunction(); |
| 284 |
TypeFunction *isFunction_Delegate_PtrToFunction(); |
| 285 |
TypeError *isTypeError(); |
| 286 |
TypeVector *isTypeVector(); |
| 287 |
TypeSArray *isTypeSArray(); |
| 288 |
TypeDArray *isTypeDArray(); |
| 289 |
TypeAArray *isTypeAArray(); |
| 290 |
TypePointer *isTypePointer(); |
| 291 |
TypeReference *isTypeReference(); |
| 292 |
TypeFunction *isTypeFunction(); |
| 293 |
TypeDelegate *isTypeDelegate(); |
| 294 |
TypeIdentifier *isTypeIdentifier(); |
| 295 |
TypeInstance *isTypeInstance(); |
| 296 |
TypeTypeof *isTypeTypeof(); |
| 297 |
TypeReturn *isTypeReturn(); |
| 298 |
TypeStruct *isTypeStruct(); |
| 299 |
TypeEnum *isTypeEnum(); |
| 300 |
TypeClass *isTypeClass(); |
| 301 |
TypeTuple *isTypeTuple(); |
| 302 |
TypeSlice *isTypeSlice(); |
| 303 |
TypeNull *isTypeNull(); |
| 304 |
TypeMixin *isTypeMixin(); |
| 305 |
TypeTraits *isTypeTraits(); |
| 306 |
TypeNoreturn *isTypeNoreturn(); |
| 307 |
TypeTag *isTypeTag(); |
| 308 |
|
| 309 |
void accept(Visitor *v) override { v->visit(this); } |
| 310 |
}; |
| 311 |
|
| 312 |
class TypeError final : public Type |
| 313 |
{ |
| 314 |
public: |
| 315 |
const char *kind() override; |
| 316 |
TypeError *syntaxCopy() override; |
| 317 |
|
| 318 |
Expression *defaultInitLiteral(Loc loc) override; |
| 319 |
void accept(Visitor *v) override { v->visit(this); } |
| 320 |
}; |
| 321 |
|
| 322 |
class TypeNext : public Type |
| 323 |
{ |
| 324 |
public: |
| 325 |
Type *next; |
| 326 |
|
| 327 |
int hasWild() const override final; |
| 328 |
Type *nextOf() override final; |
| 329 |
Type *makeConst() override final; |
| 330 |
Type *makeImmutable() override final; |
| 331 |
Type *makeShared() override final; |
| 332 |
Type *makeSharedConst() override final; |
| 333 |
Type *makeWild() override final; |
| 334 |
Type *makeWildConst() override final; |
| 335 |
Type *makeSharedWild() override final; |
| 336 |
Type *makeSharedWildConst() override final; |
| 337 |
Type *makeMutable() override final; |
| 338 |
unsigned char deduceWild(Type *t, bool isRef) override final; |
| 339 |
void transitive(); |
| 340 |
void accept(Visitor *v) override { v->visit(this); } |
| 341 |
}; |
| 342 |
|
| 343 |
class TypeBasic final : public Type |
| 344 |
{ |
| 345 |
public: |
| 346 |
const char *dstring; |
| 347 |
unsigned flags; |
| 348 |
|
| 349 |
const char *kind() override; |
| 350 |
TypeBasic *syntaxCopy() override; |
| 351 |
unsigned alignsize() override; |
| 352 |
bool isIntegral() override; |
| 353 |
bool isFloating() override; |
| 354 |
bool isReal() override; |
| 355 |
bool isImaginary() override; |
| 356 |
bool isComplex() override; |
| 357 |
bool isScalar() override; |
| 358 |
bool isUnsigned() override; |
| 359 |
|
| 360 |
// For eliminating dynamic_cast |
| 361 |
TypeBasic *isTypeBasic() override; |
| 362 |
void accept(Visitor *v) override { v->visit(this); } |
| 363 |
}; |
| 364 |
|
| 365 |
class TypeVector final : public Type |
| 366 |
{ |
| 367 |
public: |
| 368 |
Type *basetype; |
| 369 |
|
| 370 |
static TypeVector *create(Type *basetype); |
| 371 |
const char *kind() override; |
| 372 |
TypeVector *syntaxCopy() override; |
| 373 |
unsigned alignsize() override; |
| 374 |
bool isIntegral() override; |
| 375 |
bool isFloating() override; |
| 376 |
bool isScalar() override; |
| 377 |
bool isUnsigned() override; |
| 378 |
bool isBoolean() override; |
| 379 |
Expression *defaultInitLiteral(Loc loc) override; |
| 380 |
TypeBasic *elementType(); |
| 381 |
|
| 382 |
void accept(Visitor *v) override { v->visit(this); } |
| 383 |
}; |
| 384 |
|
| 385 |
class TypeArray : public TypeNext |
| 386 |
{ |
| 387 |
public: |
| 388 |
void accept(Visitor *v) override { v->visit(this); } |
| 389 |
}; |
| 390 |
|
| 391 |
// Static array, one with a fixed dimension |
| 392 |
class TypeSArray final : public TypeArray |
| 393 |
{ |
| 394 |
public: |
| 395 |
Expression *dim; |
| 396 |
|
| 397 |
const char *kind() override; |
| 398 |
TypeSArray *syntaxCopy() override; |
| 399 |
bool isIncomplete(); |
| 400 |
unsigned alignsize() override; |
| 401 |
bool isString() override; |
| 402 |
structalign_t alignment() override; |
| 403 |
Expression *defaultInitLiteral(Loc loc) override; |
| 404 |
bool hasUnsafeBitpatterns() override; |
| 405 |
bool hasVoidInitPointers() override; |
| 406 |
bool hasInvariant() override; |
| 407 |
bool needsDestruction() override; |
| 408 |
bool needsCopyOrPostblit() override; |
| 409 |
bool needsNested() override; |
| 410 |
|
| 411 |
void accept(Visitor *v) override { v->visit(this); } |
| 412 |
}; |
| 413 |
|
| 414 |
// Dynamic array, no dimension |
| 415 |
class TypeDArray final : public TypeArray |
| 416 |
{ |
| 417 |
public: |
| 418 |
const char *kind() override; |
| 419 |
TypeDArray *syntaxCopy() override; |
| 420 |
unsigned alignsize() override; |
| 421 |
bool isString() override; |
| 422 |
bool isBoolean() override; |
| 423 |
|
| 424 |
void accept(Visitor *v) override { v->visit(this); } |
| 425 |
}; |
| 426 |
|
| 427 |
class TypeAArray final : public TypeArray |
| 428 |
{ |
| 429 |
public: |
| 430 |
Type *index; // key type |
| 431 |
Loc loc; |
| 432 |
|
| 433 |
static TypeAArray *create(Type *t, Type *index); |
| 434 |
const char *kind() override; |
| 435 |
TypeAArray *syntaxCopy() override; |
| 436 |
bool isBoolean() override; |
| 437 |
|
| 438 |
void accept(Visitor *v) override { v->visit(this); } |
| 439 |
}; |
| 440 |
|
| 441 |
class TypePointer final : public TypeNext |
| 442 |
{ |
| 443 |
public: |
| 444 |
static TypePointer *create(Type *t); |
| 445 |
const char *kind() override; |
| 446 |
TypePointer *syntaxCopy() override; |
| 447 |
bool isScalar() override; |
| 448 |
|
| 449 |
void accept(Visitor *v) override { v->visit(this); } |
| 450 |
}; |
| 451 |
|
| 452 |
class TypeReference final : public TypeNext |
| 453 |
{ |
| 454 |
public: |
| 455 |
const char *kind() override; |
| 456 |
TypeReference *syntaxCopy() override; |
| 457 |
void accept(Visitor *v) override { v->visit(this); } |
| 458 |
}; |
| 459 |
|
| 460 |
enum RET |
| 461 |
{ |
| 462 |
RETregs = 1, // returned in registers |
| 463 |
RETstack = 2 // returned on stack |
| 464 |
}; |
| 465 |
|
| 466 |
enum class TRUST : unsigned char |
| 467 |
{ |
| 468 |
default_ = 0, |
| 469 |
system = 1, // @system (same as TRUST.default_ unless feature "safer" is enabled) |
| 470 |
trusted = 2, // @trusted |
| 471 |
safe = 3 // @safe |
| 472 |
}; |
| 473 |
|
| 474 |
enum TRUSTformat |
| 475 |
{ |
| 476 |
TRUSTformatDefault, // do not emit @system when trust == TRUSTdefault |
| 477 |
TRUSTformatSystem // emit @system when trust == TRUSTdefault |
| 478 |
}; |
| 479 |
|
| 480 |
enum class PURE : unsigned char |
| 481 |
{ |
| 482 |
impure = 0, // not pure at all |
| 483 |
fwdref = 1, // it's pure, but not known which level yet |
| 484 |
weak = 2, // no mutable globals are read or written |
| 485 |
const_ = 3, // parameters are values or const |
| 486 |
}; |
| 487 |
|
| 488 |
class Parameter final : public ASTNode |
| 489 |
{ |
| 490 |
public: |
| 491 |
Loc loc; |
| 492 |
StorageClass storageClass; |
| 493 |
Type *type; |
| 494 |
Identifier *ident; |
| 495 |
Expression *defaultArg; |
| 496 |
UserAttributeDeclaration *userAttribDecl; // user defined attributes |
| 497 |
|
| 498 |
static Parameter *create(Loc loc, StorageClass storageClass, Type *type, Identifier *ident, |
| 499 |
Expression *defaultArg, UserAttributeDeclaration *userAttribDecl); |
| 500 |
Parameter *syntaxCopy(); |
| 501 |
Type *isLazyArray(); |
| 502 |
bool isLazy() const; |
| 503 |
bool isReference() const; |
| 504 |
// kludge for template.isType() |
| 505 |
DYNCAST dyncast() const override { return DYNCAST_PARAMETER; } |
| 506 |
void accept(Visitor *v) override { v->visit(this); } |
| 507 |
|
| 508 |
static size_t dim(Parameters *parameters); |
| 509 |
static Parameter *getNth(Parameters *parameters, d_size_t nth); |
| 510 |
const char *toChars() const override; |
| 511 |
bool isCovariant(bool returnByRef, const Parameter *p, bool previewIn) const; |
| 512 |
}; |
| 513 |
|
| 514 |
struct ParameterList |
| 515 |
{ |
| 516 |
Parameters* parameters; |
| 517 |
StorageClass stc; |
| 518 |
VarArg varargs; |
| 519 |
d_bool hasIdentifierList; // true if C identifier-list style |
| 520 |
|
| 521 |
size_t length(); |
| 522 |
Parameter *operator[](size_t i) { return Parameter::getNth(parameters, i); } |
| 523 |
}; |
| 524 |
|
| 525 |
class TypeFunction final : public TypeNext |
| 526 |
{ |
| 527 |
public: |
| 528 |
// .next is the return type |
| 529 |
|
| 530 |
ParameterList parameterList; // function parameters |
| 531 |
uint16_t bitFields; |
| 532 |
LINK linkage; // calling convention |
| 533 |
TRUST trust; // level of trust |
| 534 |
PURE purity; // PURExxxx |
| 535 |
char inuse; |
| 536 |
ArgumentList inferenceArguments; // function arguments |
| 537 |
|
| 538 |
static TypeFunction *create(Parameters *parameters, Type *treturn, VarArg varargs, LINK linkage, StorageClass stc = 0); |
| 539 |
const char *kind() override; |
| 540 |
TypeFunction *syntaxCopy() override; |
| 541 |
bool hasLazyParameters(); |
| 542 |
bool isDstyleVariadic() const; |
| 543 |
|
| 544 |
|
| 545 |
bool isNothrow() const; |
| 546 |
void isNothrow(bool v); |
| 547 |
bool isNogc() const; |
| 548 |
void isNogc(bool v); |
| 549 |
bool isProperty() const; |
| 550 |
void isProperty(bool v); |
| 551 |
bool isRef() const; |
| 552 |
void isRef(bool v); |
| 553 |
bool isReturn() const; |
| 554 |
void isReturn(bool v); |
| 555 |
bool isReturnScope() const; |
| 556 |
void isReturnScope(bool v); |
| 557 |
bool isScopeQual() const; |
| 558 |
void isScopeQual(bool v); |
| 559 |
bool isReturnInferred() const; |
| 560 |
void isReturnInferred(bool v); |
| 561 |
bool isScopeInferred() const; |
| 562 |
void isScopeInferred(bool v); |
| 563 |
bool isLive() const; |
| 564 |
void isLive(bool v); |
| 565 |
bool incomplete() const; |
| 566 |
void incomplete(bool v); |
| 567 |
bool isInOutParam() const; |
| 568 |
void isInOutParam(bool v); |
| 569 |
bool isInOutQual() const; |
| 570 |
void isInOutQual(bool v); |
| 571 |
bool iswild() const; |
| 572 |
|
| 573 |
void accept(Visitor *v) override { v->visit(this); } |
| 574 |
}; |
| 575 |
|
| 576 |
class TypeDelegate final : public TypeNext |
| 577 |
{ |
| 578 |
public: |
| 579 |
// .next is a TypeFunction |
| 580 |
|
| 581 |
static TypeDelegate *create(TypeFunction *t); |
| 582 |
const char *kind() override; |
| 583 |
TypeDelegate *syntaxCopy() override; |
| 584 |
unsigned alignsize() override; |
| 585 |
bool isBoolean() override; |
| 586 |
|
| 587 |
void accept(Visitor *v) override { v->visit(this); } |
| 588 |
}; |
| 589 |
|
| 590 |
class TypeTraits final : public Type |
| 591 |
{ |
| 592 |
Loc loc; |
| 593 |
/// The expression to resolve as type or symbol. |
| 594 |
TraitsExp *exp; |
| 595 |
/// Cached type/symbol after semantic analysis. |
| 596 |
RootObject *obj; |
| 597 |
|
| 598 |
const char *kind() override; |
| 599 |
TypeTraits *syntaxCopy() override; |
| 600 |
void accept(Visitor *v) override { v->visit(this); } |
| 601 |
}; |
| 602 |
|
| 603 |
class TypeMixin final : public Type |
| 604 |
{ |
| 605 |
Loc loc; |
| 606 |
Expressions *exps; |
| 607 |
RootObject *obj; |
| 608 |
|
| 609 |
const char *kind() override; |
| 610 |
TypeMixin *syntaxCopy() override; |
| 611 |
void accept(Visitor *v) override { v->visit(this); } |
| 612 |
}; |
| 613 |
|
| 614 |
class TypeQualified : public Type |
| 615 |
{ |
| 616 |
public: |
| 617 |
Loc loc; |
| 618 |
// array of Identifier and TypeInstance, |
| 619 |
// representing ident.ident!tiargs.ident. ... etc. |
| 620 |
Objects idents; |
| 621 |
|
| 622 |
|
| 623 |
void accept(Visitor *v) override { v->visit(this); } |
| 624 |
}; |
| 625 |
|
| 626 |
class TypeIdentifier final : public TypeQualified |
| 627 |
{ |
| 628 |
public: |
| 629 |
Identifier *ident; |
| 630 |
|
| 631 |
static TypeIdentifier *create(Loc loc, Identifier *ident); |
| 632 |
const char *kind() override; |
| 633 |
TypeIdentifier *syntaxCopy() override; |
| 634 |
void accept(Visitor *v) override { v->visit(this); } |
| 635 |
}; |
| 636 |
|
| 637 |
/* Similar to TypeIdentifier, but with a TemplateInstance as the root |
| 638 |
*/ |
| 639 |
class TypeInstance final : public TypeQualified |
| 640 |
{ |
| 641 |
public: |
| 642 |
TemplateInstance *tempinst; |
| 643 |
|
| 644 |
const char *kind() override; |
| 645 |
TypeInstance *syntaxCopy() override; |
| 646 |
void accept(Visitor *v) override { v->visit(this); } |
| 647 |
}; |
| 648 |
|
| 649 |
class TypeTypeof final : public TypeQualified |
| 650 |
{ |
| 651 |
public: |
| 652 |
Expression *exp; |
| 653 |
int inuse; |
| 654 |
|
| 655 |
const char *kind() override; |
| 656 |
TypeTypeof *syntaxCopy() override; |
| 657 |
void accept(Visitor *v) override { v->visit(this); } |
| 658 |
}; |
| 659 |
|
| 660 |
class TypeReturn final : public TypeQualified |
| 661 |
{ |
| 662 |
public: |
| 663 |
const char *kind() override; |
| 664 |
TypeReturn *syntaxCopy() override; |
| 665 |
void accept(Visitor *v) override { v->visit(this); } |
| 666 |
}; |
| 667 |
|
| 668 |
// Whether alias this dependency is recursive or not. |
| 669 |
enum AliasThisRec |
| 670 |
{ |
| 671 |
RECno = 0, // no alias this recursion |
| 672 |
RECyes = 1, // alias this has recursive dependency |
| 673 |
RECfwdref = 2, // not yet known |
| 674 |
RECtypeMask = 3,// mask to read no/yes/fwdref |
| 675 |
|
| 676 |
RECtracing = 0x4, // mark in progress of implicitConvTo/deduceWild |
| 677 |
RECtracingDT = 0x8 // mark in progress of deduceType |
| 678 |
}; |
| 679 |
|
| 680 |
class TypeStruct final : public Type |
| 681 |
{ |
| 682 |
public: |
| 683 |
StructDeclaration *sym; |
| 684 |
AliasThisRec att; |
| 685 |
d_bool inuse; |
| 686 |
|
| 687 |
static TypeStruct *create(StructDeclaration *sym); |
| 688 |
const char *kind() override; |
| 689 |
unsigned alignsize() override; |
| 690 |
TypeStruct *syntaxCopy() override; |
| 691 |
structalign_t alignment() override; |
| 692 |
Expression *defaultInitLiteral(Loc loc) override; |
| 693 |
bool isAssignable() override; |
| 694 |
bool isBoolean() override; |
| 695 |
bool needsDestruction() override; |
| 696 |
bool needsCopyOrPostblit() override; |
| 697 |
bool needsNested() override; |
| 698 |
bool hasVoidInitPointers() override; |
| 699 |
bool hasUnsafeBitpatterns() override; |
| 700 |
bool hasInvariant() override; |
| 701 |
unsigned char deduceWild(Type *t, bool isRef) override; |
| 702 |
|
| 703 |
void accept(Visitor *v) override { v->visit(this); } |
| 704 |
}; |
| 705 |
|
| 706 |
class TypeEnum final : public Type |
| 707 |
{ |
| 708 |
public: |
| 709 |
EnumDeclaration *sym; |
| 710 |
|
| 711 |
const char *kind() override; |
| 712 |
TypeEnum *syntaxCopy() override; |
| 713 |
unsigned alignsize() override; |
| 714 |
Type *memType(Loc loc); |
| 715 |
bool isIntegral() override; |
| 716 |
bool isFloating() override; |
| 717 |
bool isReal() override; |
| 718 |
bool isImaginary() override; |
| 719 |
bool isComplex() override; |
| 720 |
bool isScalar() override; |
| 721 |
bool isUnsigned() override; |
| 722 |
bool isBoolean() override; |
| 723 |
bool isString() override; |
| 724 |
bool isAssignable() override; |
| 725 |
bool needsDestruction() override; |
| 726 |
bool needsCopyOrPostblit() override; |
| 727 |
bool needsNested() override; |
| 728 |
bool hasVoidInitPointers() override; |
| 729 |
bool hasUnsafeBitpatterns() override; |
| 730 |
bool hasInvariant() override; |
| 731 |
Type *nextOf() override; |
| 732 |
|
| 733 |
void accept(Visitor *v) override { v->visit(this); } |
| 734 |
}; |
| 735 |
|
| 736 |
class TypeClass final : public Type |
| 737 |
{ |
| 738 |
public: |
| 739 |
ClassDeclaration *sym; |
| 740 |
AliasThisRec att; |
| 741 |
CPPMANGLE cppmangle; |
| 742 |
|
| 743 |
const char *kind() override; |
| 744 |
TypeClass *syntaxCopy() override; |
| 745 |
ClassDeclaration *isClassHandle() override; |
| 746 |
unsigned char deduceWild(Type *t, bool isRef) override; |
| 747 |
bool isScopeClass() override; |
| 748 |
bool isBoolean() override; |
| 749 |
|
| 750 |
void accept(Visitor *v) override { v->visit(this); } |
| 751 |
}; |
| 752 |
|
| 753 |
class TypeTuple final : public Type |
| 754 |
{ |
| 755 |
public: |
| 756 |
// 'logically immutable' cached global - don't modify (neither pointer nor pointee)! |
| 757 |
static TypeTuple *empty; |
| 758 |
|
| 759 |
Parameters *arguments; // types making up the tuple |
| 760 |
|
| 761 |
static TypeTuple *create(Parameters *arguments); |
| 762 |
static TypeTuple *create(); |
| 763 |
static TypeTuple *create(Type *t1); |
| 764 |
static TypeTuple *create(Type *t1, Type *t2); |
| 765 |
const char *kind() override; |
| 766 |
TypeTuple *syntaxCopy() override; |
| 767 |
bool equals(const RootObject * const o) const override; |
| 768 |
void accept(Visitor *v) override { v->visit(this); } |
| 769 |
}; |
| 770 |
|
| 771 |
class TypeSlice final : public TypeNext |
| 772 |
{ |
| 773 |
public: |
| 774 |
Expression *lwr; |
| 775 |
Expression *upr; |
| 776 |
|
| 777 |
const char *kind() override; |
| 778 |
TypeSlice *syntaxCopy() override; |
| 779 |
void accept(Visitor *v) override { v->visit(this); } |
| 780 |
}; |
| 781 |
|
| 782 |
class TypeNull final : public Type |
| 783 |
{ |
| 784 |
public: |
| 785 |
const char *kind() override; |
| 786 |
|
| 787 |
TypeNull *syntaxCopy() override; |
| 788 |
bool isBoolean() override; |
| 789 |
|
| 790 |
void accept(Visitor *v) override { v->visit(this); } |
| 791 |
}; |
| 792 |
|
| 793 |
class TypeNoreturn final : public Type |
| 794 |
{ |
| 795 |
public: |
| 796 |
const char *kind() override; |
| 797 |
TypeNoreturn *syntaxCopy() override; |
| 798 |
bool isBoolean() override; |
| 799 |
unsigned alignsize() override; |
| 800 |
|
| 801 |
void accept(Visitor *v) override { v->visit(this); } |
| 802 |
}; |
| 803 |
|
| 804 |
class TypeTag final : public Type |
| 805 |
{ |
| 806 |
public: |
| 807 |
TypeTag *syntaxCopy() override; |
| 808 |
|
| 809 |
void accept(Visitor *v) override { v->visit(this); } |
| 810 |
}; |
| 811 |
|
| 812 |
/**************************************************************/ |
| 813 |
|
| 814 |
namespace dmd |
| 815 |
{ |
| 816 |
// If the type is a class or struct, returns the symbol for it, else null. |
| 817 |
AggregateDeclaration *isAggregate(Type *t); |
| 818 |
bool hasPointers(Type *t); |
| 819 |
// return the symbol to which type t resolves |
| 820 |
Dsymbol *toDsymbol(Type *t, Scope *sc); |
| 821 |
bool equivalent(Type *src, Type *t); |
| 822 |
Covariant covariant(Type *, Type *, StorageClass * = nullptr, bool = false); |
| 823 |
bool isBaseOf(Type *tthis, Type *t, int *poffset); |
| 824 |
bool isZeroInit(Type *t, Loc loc = Loc()); |
| 825 |
Type *trySemantic(Type *type, Loc loc, Scope *sc); |
| 826 |
Type *pointerTo(Type *type); |
| 827 |
Type *referenceTo(Type *type); |
| 828 |
Type *merge2(Type *type); |
| 829 |
Type *sarrayOf(Type *type, dinteger_t dim); |
| 830 |
Type *arrayOf(Type *type); |
| 831 |
Type *constOf(Type *type); |
| 832 |
Type *immutableOf(Type *type); |
| 833 |
Type *mutableOf(Type *type); |
| 834 |
Type *sharedOf(Type *type); |
| 835 |
Type *sharedConstOf(Type *type); |
| 836 |
Type *unSharedOf(Type *type); |
| 837 |
Type *wildOf(Type *type); |
| 838 |
Type *wildConstOf(Type *type); |
| 839 |
Type *sharedWildOf(Type *type); |
| 840 |
Type *sharedWildConstOf(Type *type); |
| 841 |
Type *unqualify(Type *type, unsigned m); |
| 842 |
Type *toHeadMutable(Type *type); |
| 843 |
Type *aliasthisOf(Type *type); |
| 844 |
Type *castMod(Type *type, MOD mod); |
| 845 |
Type *addMod(Type *type, MOD mod); |
| 846 |
Type *addStorageClass(Type *type, StorageClass stc); |
| 847 |
Type *substWildTo(Type *type, unsigned mod); |
| 848 |
uinteger_t size(Type *type); |
| 849 |
uinteger_t size(Type *type, Loc loc); |
| 850 |
MATCH implicitConvTo(Type* from, Type* to); |
| 851 |
MATCH constConv(Type* from, Type* to); |
| 852 |
} |