Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

dmd.typesem

Semantic analysis for D types.
Authors:
Walter Bright
License:
Boost License 1.0

Sourcetypesem.d

Documentationhttps://dlang.org/phobos/dmd_typesem.html

Coveragehttps://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/typesem.d

boolisCopyable(Typet);
Determine if type t is copyable.
Parameters:
Typettype to check
Returns:
true if we can copy it
boolisAssignable(Typet);
When T is mutable,

GivenT a, b; Can we bitwise assign: a = b; ?

intmutabilityOfType(boolisRef, Typet);
Determine mutability of indirections in (ref) t.
Returns:
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, checkreft; otherwise, check justt
Typetthe type that is being checked
voidpurityLevel(TypeFunctiontypeFunction);
Set 'purity' field of 'typeFunction'. Do this lazily, as the parameter types might be forward referenced.
ExpressiontypeToExpression(Typet);
We've mistakenly parsedt as a type. Redot as an Expression only if there are no type modifiers.
Parameters:
Typetmistaken type
Returns:
t redone as Expression, null if cannot
boolcheckComplexTransition(Typetype, 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:
Typetypetype to check
LoclocThe source location.
Scope*scscope of the type
Expressions*resolveNamedArgs(TypeFunctiontf, ArgumentListargumentList, OutBuffer*buf);
Convert anargumentList, which may contain named arguments, into a list of arguments in the order of the parameter list.
Parameters:
TypeFunctiontffunction type
ArgumentListargumentListarray of function arguments
OutBuffer*bufif not null, append error message to it
Returns:
re-ordered argument list, ornull on error
MATCHcallMatch(FuncDeclarationfd, TypeFunctiontf, Typetthis, ArgumentListargumentList, intflag = 0, void delegate(const(char)*) scopeerrorHelper = null, Scope*sc = null);
'args' are being matched to function type 'tf' Determine match level.
Parameters:
FuncDeclarationfdfunction being called, if a symbol
TypeFunctiontffunction type
Typetthistype ofthis pointer, null if not member function
ArgumentListargumentListarguments to function call
intflag1: performing a partial ordering match
void delegate(const(char)*) scopeerrorHelperdelegate to call for error messages
Scope*sccontext
Returns:
MATCHxxxx
voiddetermineTypeProperties(StructDeclarationsd);
Compute cached type properties forTypeStruct
boolhasPointers(Typet);
Return !=0 if type has pointers that need to be scanned by the GC during a collection cycle.
TypegetIndirection(Typet);
Returns an indirect type one step from t.
MATCHconstConv(Typefrom, Typeto);
Determine if converting 'this' to 'to' is an identity operation, a conversion to const operation, or the types aren't the same.
Returns:
MATCH.exact 'this' == 'to' MATCH.constant 'to' is const MATCH.nomatch conversion to mutable or invariant
TypetypeSemantic(Typetype, Locloc, Scope*sc);
Perform semantic analysis on a type.
Parameters:
TypetypeType AST node
Loclocthe location of the type
Scope*sccontext
Returns:
Type with completed semantic analysis,Terror if errors were encountered
Typemerge(Typetype);
If an identical type totype is intype.stringtable, return the latter one. Otherwise, add it totype.stringtable. Some types don't get merged and are returned as-is.
Parameters:
TypetypeType to check against existing types
Returns:
the type that was merged
Typemerge2(Typetype);
This version does a merge even if the deco is already computed. Necessary for types that have a deco, but are not merged.
ExpressiondefaultInitLiteral(Typet, Locloc);
Use when we prefer the default initializer to be a literal, rather than a global immutable variable.
ExpressiongetProperty(Typet, Scope*scope_, Locloc, Identifierident, intflag, Expressionsrc = null);
Calculate built-in properties which just the type is necessary.
Parameters:
Typetthe type for which the property is calculated
Scope*scope_the scope from which the property is being accessed. Used for visibility checks only.
Loclocthe location where the property is encountered
Identifieridentthe identifier of the property
intflagif flag & 1, don't report "not a property" error and just return NULL.
Expressionsrcexpression for typet or null.
Returns:
expression representing the property, or null if not a property and (flag & 1)
voidresolve(Typemt, Locloc, Scope*sc, out Expressionpe, out Typept, out Dsymbolps, boolintypeid = false);
Resolve type 'mt' to either type, symbol, or expression. If errors happened, resolved to Type.terror.
Parameters:
Typemttype to be resolved
Loclocthe location where the type is encountered
Scope*scthe scope of the type
Expressionpeis set if t is an expression
Typeptis set if t is a type
Dsymbolpsis set if t is a symbol
boolintypeidtrue if in type id
ExpressiondotExp(Typemt, Scope*sc, Expressione, Identifierident, DotExpFlagflag);
Access the members of the object e. This type is same as e.type.
Parameters:
Typemttype for which the dot expression is used
Scope*scinstantiating scope
Expressioneexpression to convert
Identifieridentidentifier being used
DotExpFlagflagDotExpFlag bit flags
Returns:
resulting expression with e.ident resolved
ExpressiondefaultInit(Typemt, Locloc, const boolisCfile = false);
Get the default initialization expression for a type.
Parameters:
Typemtthe type for which the init expression is returned
Loclocthe location where the expression needs to be evaluated
boolisCfiledefault initializers are different with C
Returns:
The initialization expression for the type.
TypeaddStorageClass(Typetype, STCstc);
Add storage class modifiers to type.
TypegetComplexLibraryType(Locloc, Scope*sc, TYty);
Extract complex type from core.stdc.config
Parameters:
Loclocfor error messages
Scope*sccontext
TYtya complex or imaginary type
Returns:
Complex!float, Complex!double, Complex!real or null for error
Covariantcovariant(Typesrc, Typet, STC*pstc = null, boolcppCovariant = false);
Covariant means that 'src' can substitute for 't', i.e. a pure function is a match for an impure type.
Parameters:
Typesrcsource type
Typettype 'src' is covariant with
STC*pstcif not null, store STCxxxx which would make it covariant
boolcppCovarianttrue if extern(C++) function types should follow C++ covariant rules
Returns:
An enum value of eitherCovariant.yes or a reason it's not covariant.
STCparameterStorageClass(TypeFunctiontf, Typetthis, Parameterp, VarDeclarations*outerVars = null, boolindirect = false);
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:
TypeFunctiontfTypeFunction to use to get the signature from
Typetthistype ofthis parameter, null if none
Parameterpparameter to this function
VarDeclarations*outerVarscontext variables p could escape into, if any
boolindirectis this for an indirect or virtual function call?
Returns:
storage class with STC.scope_ or STC.return_ OR'd in
TypeconstOf(Typetype);
Convert to 'const'.
TypeimmutableOf(Typetype);
Convert to 'immutable'.
TypemutableOf(Typetype);
Make type mutable.
TypeunSharedOf(Typetype);
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
TypewildOf(Typetype);
Convert to 'wild'.
TypetoHeadMutable(const Typet);
Return type with the top level of it being mutable.
Parameters:
Typettype for which the top level mutable version is being returned
Returns:
type version with mutable top level
TypecastMod(Typetype, MODmod);
Apply MODxxxx bits to existing type.
TypeaddMod(Typetype, MODmod);
Add MODxxxx bits to existing type. We're adding, not replacing, so adding const to a shared type => "shared const"
boolisRecursiveAliasThis(ref Typeatt, Typet);
Check and set 'att' if 't' is a recursive 'alias this' type
The goal is to prevent endless loops when there is a cycle in the alias this chain. Since there is no multiplealias this, the chain either ends in a leaf, or it loops back on itself as some point.

ExampleS0 -> (S1 -> S2 -> S3 -> S1)

S0 is not a recursive alias this, so this returnsfalse, and a rewrite toS1 can be tried.S1 is a recursive alias this type, but sinceatt is initialized tonull, this still returnsfalse, butatt1 is set toS1. A rewrite toS2 andS3 can be tried, but when we want to try a rewrite toS1 again, we noticeatt ==t, so we're back at the start of the loop, and this returnstrue.

Parameters:
Typeatttype reference used to detect recursion. Should be initialized tonull.
Typettype of 'alias this' rewrite to attempt
Returns:
false if the rewrite is safe,true if it would loop back around
uintnumberOfElems(Typet, Locloc);
Compute number of elements for a (possibly multidimensional) static array, or 1 for other types.
Parameters:
Typetstatic array type
Loclocfor error message
Returns:
number of elements, uint.max on overflow
boolisOpaqueType(Typet);
Returns:
whethert is a struct/class/enum without a body
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Sat Feb 21 00:05:06 2026

[8]ページ先頭

©2009-2026 Movatter.jp