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 using
a local clone.
dmd.typesem
Semantic analysis for D types.
Authors:
License:
Source typesem.d
Documentation https://dlang.org/phobos/dmd_typesem.html
- bool
isCopyable(Typet); - Determine if type t is copyable.Parameters:
Type ttype to check Returns:true if we can copy it - int
mutabilityOfType(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:
bool isRefif true, check ref t; otherwise, check justtType tthe type that is being checked - void
purityLevel(TypeFunctiontypeFunction); - Set 'purity' field of 'typeFunction'. Do this lazily, as the parameter types might be forward referenced.
- Expression
typeToExpression(Typet); - We've mistakenly parsed
tas a type. Redotas an Expression only if there are no type modifiers.Parameters:Type tmistaken type Returns:t redone as Expression, null if cannot - bool
checkComplexTransition(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:
Type typetype to check Loc locThe source location. Scope* scscope of the type - MATCH
callMatch(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:
FuncDeclaration fdfunction being called, if a symbol TypeFunction tffunction type Type tthistype of this pointer, null if not member function ArgumentList argumentListarguments to function call int flag1: performing a partial ordering match void delegate(const(char)*) scope errorHelperdelegate to call for error messages Scope* sccontext Returns:MATCHxxxx - bool
hasPointers(Typet); - Return !=0 if type has pointers that need to be scanned by the GC during a collection cycle.
- Type
getIndirection(Typet); - Returns an indirect type one step from t.
- MATCH
constConv(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
- Type
typeSemantic(Typetype, Locloc, Scope*sc); - Perform semantic analysis on a type.Parameters:
Type typeType AST node Loc locthe location of the type Scope* sccontext Returns:Type with completed semantic analysis, Terror if errors were encountered - Type
merge(Typetype); - If an identical type to
typeis intype.stringtable, return the latter one. Otherwise, add it totype.stringtable. Some types don't get merged and are returned as-is.Parameters:Type typeType to check against existing types Returns:the type that was merged - Type
merge2(Typetype); - This version does a merge even if the deco is already computed. Necessary for types that have a deco, but are not merged.
- Expression
getProperty(Typet, Scope*scope_, Locloc, Identifierident, intflag, Expressionsrc= null); - Calculate built-in properties which just the type is necessary.Parameters:
Type tthe type for which the property is calculated Scope* scope_the scope from which the property is being accessed. Used for visibility checks only. Loc locthe location where the property is encountered Identifier identthe identifier of the property int flagif flag & 1, don't report "not a property" error and just return NULL. Expression srcexpression for type tor null.Returns:expression representing the property, or null if not a property and (flag & 1) - void
resolve(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:
Type mttype to be resolved Loc locthe location where the type is encountered Scope* scthe scope of the type Expression peis set if t is an expression Type ptis set if t is a type Dsymbol psis set if t is a symbol bool intypeidtrue if in type id - Expression
dotExp(Typemt, Scope*sc, Expressione, Identifierident, DotExpFlagflag); - Access the members of the object e. This type is same as e.type.Parameters:
Type mttype for which the dot expression is used Scope* scinstantiating scope Expression eexpression to convert Identifier identidentifier being used DotExpFlag flagDotExpFlag bit flags Returns:resulting expression with e.ident resolved - Expression
defaultInit(Typemt, Locloc, const boolisCfile= false); - Get the default initialization expression for a type.Parameters:
Type mtthe type for which the init expression is returned Loc locthe location where the expression needs to be evaluated bool isCfiledefault initializers are different with C Returns:The initialization expression for the type. - Type
addStorageClass(Typetype, STCstc); - Add storage class modifiers to type.
- Type
getComplexLibraryType(Locloc, Scope*sc, TYty); - Extract complex type from core.stdc.configParameters:
Loc locfor error messages Scope* sccontext TY tya complex or imaginary type Returns:Complex!float, Complex!double, Complex!real or null for error - Covariant
covariant(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:
Type srcsource type Type ttype 'src' is covariant with STC* pstcif not null, store STCxxxx which would make it covariant bool cppCovarianttrue if extern(C++) function types should follow C++ covariant rules Returns:An enum value of either Covariant.yes or a reason it's not covariant. - STC
parameterStorageClass(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:
TypeFunction tfTypeFunction to use to get the signature from Type tthistype of this parameter, null if none Parameter pparameter to this function VarDeclarations* outerVarscontext variables p could escape into, if any bool indirectis this for an indirect or virtual function call? Returns:storage class with STC.scope_ or STC.return_ OR'd in - Type
constOf(Typetype); - Convert to 'const'.
- Type
immutableOf(Typetype); - Convert to 'immutable'.
- Type
mutableOf(Typetype); - Make type mutable.
- Type
unSharedOf(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
- Type
wildOf(Typetype); - Convert to 'wild'.
- Type
toHeadMutable(const Typet); - Return type with the top level of it being mutable.Parameters:
Type ttype for which the top level mutable version is being returned Returns:type version with mutable top level - Type
castMod(Typetype, MODmod); - Apply MODxxxx bits to existing type.
- Type
addMod(Typetype, MODmod); - Add MODxxxx bits to existing type. We're adding, not replacing, so adding const to a shared type => "shared const"
- bool
isRecursiveAliasThis(ref Typeatt, Typet); - Check and set 'att' if 't' is a recursive 'alias this' typeThe goal is to prevent endless loops when there is a cycle in the alias this chain. Since there is no multiple alias this, the chain either ends in a leaf, or it loops back on itself as some point.
Example S0 -> (S1 -> S2 -> S3 -> S1)
S0 is not a recursive alias this, so this returns false, and a rewrite to S1 can be tried. S1 is a recursive alias this type, but sinceattis initialized to null, this still returns false, but att1 is set to S1. A rewrite to S2 and S3 can be tried, but when we want to try a rewrite to S1 again, we noticeatt==t, so we're back at the start of the loop, and this returns true.Parameters:Type atttype reference used to detect recursion. Should be initialized to null. Type ttype of 'alias this' rewrite to attempt Returns:false if the rewrite is safe, true if it would loop back around - uint
numberOfElems(Typet, Locloc); - Compute number of elements for a (possibly multidimensional) static array, or 1 for other types.Parameters:
Type tstatic array type Loc locfor error message Returns:number of elements, uint.max on overflow - bool
isOpaqueType(Typet); - Returns:whether
tis a struct/class/enum without a body
Copyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Mon Mar 31 10:28:04 2025