dmd.mtype
Defines a D type.
License
Source: mtype.d
Documentation: https://dlang.org/phobos/dmd_mtype.html
-
Declaration
pure nothrow @nogc @safe boolMODimplicitConv(MODmodfrom, MODmodto);Return !=0 if
modfromcan be implicitly converted tomodto -
Declaration
pure nothrow @nogc @safe MATCHMODmethodConv(MODmodfrom, MODmodto);Return MATCH.exact or MATCH.constant if a method of type '()
modfrom' can call a method of type '()modto'. -
Declaration
pure nothrow @nogc @safe MODMODmerge(MODmod1, MODmod2);Merge mod bits to form common mod.
-
Declaration
nothrow voidMODtoBuffer(OutBuffer*buf, MODmod);Store modifier name into
buf. -
Declaration
pure nothrow const(char)*MODtoChars(MODmod);
pure nothrow stringMODtoString(MODmod);Return Value
a human readable representation of
, which is the tokenmodcorresponds tomod -
Declaration
pure nothrow @nogc @safe stringtrustToString(TRUSTtrust);Pick off one of the
trustflags fromtrust, and return a string representation of it. -
Declaration
pure nothrow @nogc @safe StorageClassModToStc(uintmod);Convert MODxxxx to STCxxx
-
Declaration
pure nothrow @nogc @safe boolisSomeChar(TYty);Returns
trueiftyis char, wchar, or dchar -
Declaration
intmutabilityOfType(boolisref, Typet);Determine mutability of indirections in (ref)
t.Return Value
When the type has any mutable indirections, returns 0. When all indirections are immutable, returns 2. Otherwise, when the type has const/inout indirections, returns 1.
Parameters
boolisrefif
true, checkref; otherwise, check justttTypetthe type that is being checked
-
Declaration
enumDotExpFlag: int;dotExp() bit flags
-
Declaration
enumCovariant: int;Result of a check whether two types are covariant
-
Declaration
distincttypes are
distinct -
Declaration
yestypes are covariant
-
Declaration
noarguments match as far as overloading goes, but types are not covariant
-
Declaration
fwdrefcannot determine covariance because of forward references
-
-
Declaration
abstract classType: dmd.ast_node.ASTNode;-
Declaration
final const size_tgetUniqueID();Returns a non-zero unique ID for this Type, or returns 0 if the Type does not (yet) have a unique ID. If
semantic()has not been run, 0 is returned. -
Declaration
final Covariantcovariant(Typet, StorageClass*pstc= null, boolcppCovariant= false);Covariant means that 'this' can substitute for '
t', i.e. a pure function is a match for an impure type.Parameters
Typettype 'this' is
covariantwithStorageClass*pstcif not
null, store STCxxxx which would make itcovariantboolcppCovarianttrueif extern(C++) function types should follow C++covariantrulesReturn Value
An enum value of either
Covariant.yesor a reason it's notcovariant. -
Declaration
final const const(char)*toChars();
final char*toPrettyChars(boolQualifyTypes= false);For pretty-printing a type.
-
Declaration
static voiddeinitialize();Deinitializes the global state of the compiler.
Discussion
This can be used to restore the state set by
_initto its original state. -
Declaration
final Typemerge2();This version does a merge even if the deco is already computed. Necessary for types that have a deco, but are not merged.
-
Declaration
final const nothrow voidmodToBuffer(OutBuffer*buf);Store this type's modifier name into
buf. -
Declaration
final const nothrow char*modToChars();Return this type's modifier name.
-
Declaration
boolisAssignable();When T is mutable,
Given: T a, b; Can we bitwise assign: a = b; ?
-
Declaration
boolisBoolean();Returns
trueif T can be converted to boolean value. -
Declaration
voidcheckDeprecated(const ref Locloc, Scope*sc);Check type to see if it is based on a deprecated symbol.
-
Declaration
final const nothrow TypenullAttributes();Return a copy of this type with all attributes
null-initialized. Useful for creating a type with different modifiers. -
Declaration
final TypeconstOf();Convert to 'const'.
-
Declaration
final TypeimmutableOf();Convert to 'immutable'.
-
Declaration
final TypemutableOf();Make type mutable.
-
Declaration
final TypeunSharedOf();Make type unshared. 0 => 0 const => const immutable => immutable shared => 0 shared const => const wild => wild wild const => wild const shared wild => wild shared wild const => wild const
-
Declaration
final TypewildOf();Convert to 'wild'.
-
Declaration
final voidfixTo(Typet);For our new type 'this', which is type-constructed from
t, fill in the cto, ito, sto, scto, wto shortcuts. -
Declaration
final voidcheck();Look for bugs in constructing types.
-
Declaration
final TypeaddSTC(StorageClassstc);Apply STCxxxx bits to existing type. Use before semantic analysis is run.
-
Declaration
final TypecastMod(MODmod);Apply MODxxxx bits to existing type.
-
Declaration
final TypeaddMod(MODmod);Add MODxxxx bits to existing type. We're adding, not replacing, so adding const to a shared type => "shared const"
-
Declaration
TypeaddStorageClass(StorageClassstc);Add storage class modifiers to type.
-
Declaration
final boolcheckAliasThisRec();Check whether this type has endless
alias thisrecursion.Return Value
trueif this type has analias thisthat can be implicitly converted back to this type itself. -
Declaration
final TypetoBasetype();If this is a shell around another type, get that other type.
-
Declaration
MATCHimplicitConvTo(Typeto);Determine if 'this' can be implicitly converted
totype 'to'.Return Value
MATCH.nomatch, MATCH.convert, MATCH.constant, MATCH.exact
-
Declaration
MATCHconstConv(Typeto);Determine if converting 'this'
to'to' is an identity operation, a conversiontoconst operation, or the types aren't the same.Return Value
MATCH.exact 'this' == '
to' MATCH.constant 'to' is const MATCH.nomatch conversiontomutable or invariant -
Declaration
MODdeduceWild(Typet, boolisRef);Compute MOD bits matching
thisargument type to wild parameter type.Parameters
Typetcorresponding parameter type
boolisRefparameter is
reforoutReturn Value
MOD bits
-
Declaration
inout inout(Type)toHeadMutable();Return type with the top level of it being mutable.
-
Declaration
structalign_talignment();Return
alignmentto use for this type. -
Declaration
ExpressiondefaultInitLiteral(const ref Locloc);Use when we prefer the default initializer to be a literal, rather than a global immutable variable.
-
Declaration
const inthasWild();Return !=0 if the type or any of its subtypes is wild.
-
Declaration
boolhasPointers();Return !=0 if type has pointers that need to be scanned by the GC during a collection cycle.
-
Declaration
boolhasVoidInitPointers();Detect if type has pointer fields that are initialized to void. Local stack variables with such void fields can remain uninitialized, leading to pointer bugs.
Return Value
trueif so -
Declaration
boolhasSystemFields();Detect if this is an unsafe type because of the presence of
@systemmembersReturn Value
trueif so -
Declaration
boolhasInvariant();Return Value
trueif type has any invariants -
Declaration
TypenextOf();If this is a type of something, return that something.
-
Declaration
final TypebaseElemOf();If this is a type of static array, return its base element type.
-
Declaration
final uintnumberOfElems(const ref Locloc);Compute number of elements for a (possibly multidimensional) static array, or 1 for other types.
Parameters
Loclocfor error message
Return Value
number of elements, uint.max on overflow
-
Declaration
final uinteger_tsizemask();Return the mask that an integral type will fit into.
-
Declaration
boolneedsDestruction();trueif when type goes out of scope, it needs a destructor applied. Only applies to value types, not ref types. -
Declaration
boolneedsCopyOrPostblit();trueif when type is copied, it needs a copy constructor or postblit applied. Only applies to value types, not ref types. -
Declaration
boolneedsNested(); -
Declaration
final boolcheckComplexTransition(const ref Locloc, Scope*sc);https://issues.dlang.org/show_bug.cgi?id=14488 Check if the inner most base type is complex or imaginary. Should only give alerts when set to emit transitional messages.
Parameters
LoclocThe source location.
Scope*scscope of the type
-
Declaration
final inout pure nothrow @nogc inout(TypeFunction)isPtrToFunction();Is this type a pointer to a function?
Return Value
the function type if it is
-
Declaration
final inout pure nothrow @nogc inout(TypeFunction)isFunction_Delegate_PtrToFunction();Is this type a function, delegate, or pointer to a function?
Return Value
the function type if it is
-
-
Declaration
classTypeError: dmd.mtype.Type; -
Declaration
abstract classTypeNext: dmd.mtype.Type;-
Declaration
final TypenextOf();For TypeFunction,
nextOf() can return NULL if the function return type is meant to be inferred, and semantic() hasn't yet ben run on the function. After semantic(), it must no longer be NULL.
-
-
Declaration
classTypeBasic: dmd.mtype.Type; -
Declaration
classTypeVector: dmd.mtype.Type;The basetype must be one of: byte[16],ubyte[16],short[8],ushort[8],int[4],uint[4],long[2],ulong[2],float[4],double[2] For AVX: byte[32],ubyte[32],short[16],ushort[16],int[8],uint[8],long[4],ulong[4],float[8],double[4]
-
Declaration
abstract classTypeArray: dmd.mtype.TypeNext; -
Declaration
classTypeSArray: dmd.mtype.TypeArray;Static array, one with a fixed dimension
-
Declaration
boolisIncomplete();C11 6.7.6.2-4 incomplete array type
Return Value
trueif incomplete type -
Declaration
boolneedsNested();
-
-
Declaration
classTypeDArray: dmd.mtype.TypeArray;Dynamic array, no dimension
-
Declaration
classTypeAArray: dmd.mtype.TypeArray; -
Declaration
classTypePointer: dmd.mtype.TypeNext; -
Declaration
classTypeReference: dmd.mtype.TypeNext; -
Declaration
classTypeFunction: dmd.mtype.TypeNext;-
Declaration
voidpurityLevel();Set 'purity' field of 'this'. Do this lazily, as the parameter types might be forward referenced.
-
Declaration
boolhasLazyParameters();Return
trueif there are lazy parameters. -
Declaration
const pure nothrow boolisDstyleVariadic();Check for
extern (D) U func(T t, ...)variadic function type, which has_arguments[]added as the first argument.Return Value
trueif D-style variadic -
Declaration
StorageClassparameterStorageClass(Typetthis, Parameterp);Take the specified storage class for
p, and use the function signature to infer whether STC.scope_ and STC.return_ should be OR'd in. (This will not affect the name mangling.)Parameters
Typetthistype of
thisparameter,nullif noneParameterpparameter to this function
Return Value
storage class with STC.scope_ or STC.return_ OR'd in
-
Declaration
MATCHcallMatch(Typetthis, ArgumentListargumentList, intflag= 0, const(char)**pMessage= null, Scope*sc= null);'args' are being matched to function 'this' Determine match level.
Parameters
Typetthistype of
thispointer,nullif not member functionArgumentListargumentListarguments to function call
intflag1: performing a partial ordering match
const(char)**pMessageaddress to store error message, or
nullScope*sccontext
Return Value
MATCHxxxx
-
Declaration
Expressions*resolveNamedArgs(ArgumentListargumentList, const(char)**pMessage);Convert an
, which may contain named arguments, into a list of arguments in the order of the parameter list.argumentListParameters
ArgumentListargumentListarray of function arguments
const(char)**pMessageaddress to store error message, or
nullReturn Value
re-ordered argument list, or
nullon error -
Declaration
MATCHconstConv(Typeto);Extends TypeNext.
constConvby also checking for matching attributes -
Declaration
const pure nothrow @nogc @safe booliswild();Return Value
truethe function isisInOutQualorisInOutParam,falseotherwise. -
Declaration
const pure nothrow @nogc @safe boolattributesEqual(scope const TypeFunctionother, booltrustSystemEqualsDefault= true);Return Value
whether
thisfunction type has the same attributes (@safe,...) asother
-
-
Declaration
classTypeDelegate: dmd.mtype.TypeNext; -
Declaration
classTypeTraits: dmd.mtype.Type;This is a shell containing a TraitsExp that can be either resolved to a type or to a symbol.
Discussion
The point is to allow AliasDeclarationY to use
__traits(), see issue 7804.-
Declaration
TraitsExpexp;The expression to resolve as type or symbol.
-
Declaration
RootObjectobj;Cached type/symbol after semantic analysis.
-
-
Declaration
classTypeMixin: dmd.mtype.Type;Implements mixin types.
Discussion
Semantic analysis will convert it to a real type.
-
Declaration
abstract classTypeQualified: dmd.mtype.Type; -
Declaration
classTypeIdentifier: dmd.mtype.TypeQualified;-
Declaration
DsymboltoDsymbol(Scope*sc);See if type resolves to a symbol, if so, return that symbol.
-
-
Declaration
classTypeInstance: dmd.mtype.TypeQualified;Similar to TypeIdentifier, but with a TemplateInstance as the root
-
Declaration
classTypeTypeof: dmd.mtype.TypeQualified; -
Declaration
classTypeReturn: dmd.mtype.TypeQualified; -
Declaration
classTypeStruct: dmd.mtype.Type;-
Declaration
ExpressiondefaultInitLiteral(const ref Locloc);Use when we prefer the default initializer to be a literal, rather than a global immutable variable.
-
-
Declaration
classTypeEnum: dmd.mtype.Type; -
Declaration
classTypeClass: dmd.mtype.Type; -
Declaration
classTypeTuple: dmd.mtype.Type; -
Declaration
classTypeSlice: dmd.mtype.TypeNext;This is so we can slice a TypeTuple
-
Declaration
classTypeNull: dmd.mtype.Type; -
Declaration
classTypeNoreturn: dmd.mtype.Type; -
Declaration
classTypeTag: dmd.mtype.Type;Unlike D, C can declare/define struct/union/enum tag names inside Declarators, instead of separately as in D. The order these appear in the symbol table must be in lexical order. There isn't enough info at the parsing stage to determine if it's a declaration or a reference to an existing name, so this Type collects the necessary info and defers it to semantic().
-
Declaration
Locloc;location of declaration
-
Declaration
TOKtok;TOK.struct_, TOK.union_, TOK.enum_
-
Declaration
structalign_tpackalign;alignment of struct/union fields
-
Declaration
Identifierid;tag name identifier
-
Declaration
Typebase;basetype for enums otherwisenull -
Declaration
Dsymbols*members;membersof struct,nullif none -
Declaration
Typeresolved;type after semantic() in case there are more others
-
Declaration
MODmod;pointing to this instance, which can happen with struct S { int a; } s1, *s2;
Discussion
modifiers to apply after type is resolved (only MODFlags.const_ at the moment)
-
-
Declaration
structParameterList;Represents a function's formal parameters + variadics info. Length, indexing and iteration are based on a depth-first tuple expansion. https://dlang.org/spec/function.html#ParameterList
-
Declaration
Parameters*parameters;The raw (unexpanded) formal
parameters, possibly containing tuples. -
Declaration
size_tlength();Returns the number of expanded parameters. Complexity: O(N).
-
Declaration
ParameteropIndex(size_ti);Returns the expanded parameter at the given index, or
nullif out of bounds. Complexity: O(i). -
Declaration
intopApply(scope Parameter.ForeachDgdg);Iterates over the expanded parameters. Complexity: O(N). Prefer this to avoid the O(N + N^2/2) complexity of calculating length and calling N times opIndex.
-
Declaration
intopApply(scope Parameter.SemanticForeachDgdg);Iterates over the expanded parameters, matching them with the unexpanded ones, for semantic processing
-
Declaration
const boolopEquals(ref scope ParameterListother);Compares this to another ParameterList (and expands tuples if necessary)
-
Declaration
boolhasDefaultArgs();Return Value
trueif any parameter has a default argument
-
-
Declaration
classParameter: dmd.ast_node.ASTNode;-
Declaration
TypeisLazyArray();Determine if parameter is a lazy array of delegates. If so, return the return type of those delegates. If not, return NULL.
Discussion
Returns T if the type is one of the following forms: T delegate()[] T delegate()
dim -
Declaration
const pure nothrow @nogc @safe boolisLazy();Return Value
Whether the function parameter is lazy
-
Declaration
const pure nothrow @nogc @safe boolisReference();Return Value
Whether the function parameter is a reference (out / ref)
-
Declaration
static size_tdim(Parameters*parameters);Determine number of arguments, folding in tuples.
-
Declaration
static ParametergetNth(Parameters*parameters, size_tnth);Get
nthParameter, folding in tuples.Discussion
Since
can include tuples, which would increase its length, this function allows to get theparametersparameter as if all tuples transitively contained innthwere flattened.parametersParameters
Parameters*parametersArray of
Parameterto iterate oversize_tnthIndex of the desired parameter.
Return Value
The parameter at index
(taking tuples into account), ornthnullif out of bound. -
Declaration
aliasForeachDg= int delegate(ulong paramidx, Parameter param);Type of delegate when iterating solely on the parameters
-
Declaration
aliasSemanticForeachDg= int delegate(ulong oidx, Parameter oparam, ulong eidx, Parameter eparam);Type of delegate when iterating on both the original set of parameters, and the type tuple. Useful for semantic analysis. 'o' stands for 'original' and 'e' stands for 'expanded'.
-
Declaration
static int_foreach(Parameters*parameters, scope ForeachDgdg);
static int_foreach(Parameters*parameters, scope SemanticForeachDgdg);Expands tuples in args in depth first order. Calls
dg(void *ctx, size_t argidx, Parameter *arg) for each Parameter. Ifdgreturns !=0, stops and returns that value else returns 0. Use this function to avoid the O(N + N^2/2) complexity of calculating dim and calling N times getNth. -
Declaration
const pure nothrow @nogc @safe boolisCovariant(boolreturnByRef, const Parameterp, boolpreviewIn= global.params.previewIn);Compute covariance of parameters
thisandas determined by the storage classes of both.pParameters
boolreturnByReftrueif the function returns by refParameterpParameter to compare with
boolpreviewInWhether
-preview=inis being used, and thus ifinmeansscope [ref].Return Value
true=thiscan be used in place ofpfalse= nope
-
-
Declaration
const(char*)[2]toAutoQualChars(Typet1, Typet2);For printing two types with qualification when necessary.
Parameters
Typet1The first type to receive the type name for
Typet2The second type to receive the type name for
Return Value
The fully-qualified names of both types if the two type names are not the same, or the unqualified names of both types if the two type names are the same.
-
Declaration
voidmodifiersApply(const TypeFunctiontf, void delegate(string)dg);For each active modifier (MODFlags.const_, MODFlags.immutable_, etc) call
fpwith a void* for the work param and a string representation of the attribute. -
Declaration
voidattributesApply(const TypeFunctiontf, void delegate(string)dg, TRUSTformattrustFormat= TRUSTformatDefault);For each active attribute (ref/const/nogc/etc) call
fpwith a void* for the work param and a string representation of the attribute. -
Declaration
AggregateDeclarationisAggregate(Typet);If the type is a class or struct, returns the symbol for it, else
null. -
Declaration
boolisIndexableNonAggregate(Typet);Determine if type
tcan be indexed or sliced given that it is not an aggregate with operator overloads.Parameters
Typettype to check
Return Value
trueif an expression of typetcan be e1 in an array expression -
Declaration
boolisCopyable(Typet);Determine if type
tis copyable.Parameters
Typettype to check
Return Value
trueif we can copy it -
Declaration
pure nothrow @nogc @safe ScopeRefbuildScopeRef(StorageClassstc);Computes how a parameter may be returned. Shrinking the representation is necessary because StorageClass is so wide
Parameters
StorageClassstcstorage class of parameter
Return Value
value from enum ScopeRef
-
Declaration
enumScopeRef: int;Classification of 'scope-return-ref' possibilities
-
Declaration
pure nothrow @nogc @safe const(char)*toChars(ScopeRefsr);Give us a nice string for debugging purposes.
Parameters
ScopeRefsrvalue
Return Value
corresponding string
-
Declaration
TypeVectortoBooleanVector(TypeVectortv);Creates an appropriate vector type for
that will hold one boolean result for each element of the vector type. The result of vector comparisons is a single or doubleword mask of all 1s (comparisontvtrue) or all 0s (comparisonfalse). This SIMD mask type does not have an equivalent D type, however its closest equivalent would be an integer vector of the same unit size and length.Parameters
TypeVectortvThe
TypeVectorto build a vector from.Return Value
A vector type suitable for the result of a vector comparison operation.
-
Declaration
ResultVisitType(Result)(Typet);Dispatch to function based on static type of Type.
-
Declaration
pure stringvisitTYCase(stringhandler);CTFE-only helper function for VisitInitializer.
Parameters
stringhandlerstring for the name of the visit
handlerReturn Value
boilerplate code for a case