Semantic analysis for D types.
Determine if type t is copyable.
Returns:true if we can copy it
When T is mutable,
GivenT a, b; Can we bitwise assign: a = b; ?
int
mutabilityOfType(bool
isRef, Type
t);
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:boolisRef | if true, checkreft; otherwise, check justt |
Typet | the type that is being checked |
void
purityLevel(TypeFunction
typeFunction);
Set 'purity' field of 'typeFunction'. Do this lazily, as the parameter types might be forward referenced.
Expression
typeToExpression(Type
t);
We've mistakenly parsedt as a type. Redot as an Expression only if there are no type modifiers.
Returns:t redone as Expression, null if cannot
bool
checkComplexTransition(Type
type, Loc
loc, Scope*
sc);
Parameters:Typetype | type to check |
Locloc | The source location. |
Scope*sc | scope of the type |
Expressions*
resolveNamedArgs(TypeFunction
tf, ArgumentList
argumentList, OutBuffer*
buf);
Convert anargumentList, which may contain named arguments, into a list of arguments in the order of the parameter list.
Parameters:TypeFunctiontf | function type |
ArgumentListargumentList | array of function arguments |
OutBuffer*buf | if not null, append error message to it |
Returns:re-ordered argument list, ornull on error
MATCH
callMatch(FuncDeclaration
fd, TypeFunction
tf, Type
tthis, ArgumentList
argumentList, int
flag = 0, void delegate(const(char)*) scope
errorHelper = null, Scope*
sc = null);
'args' are being matched to function type 'tf' Determine match level.
Parameters:FuncDeclarationfd | function being called, if a symbol |
TypeFunctiontf | function type |
Typetthis | type ofthis pointer, null if not member function |
ArgumentListargumentList | arguments to function call |
intflag | 1: performing a partial ordering match |
void delegate(const(char)*) scopeerrorHelper | delegate to call for error messages |
Scope*sc | context |
void
determineTypeProperties(StructDeclaration
sd);
Compute cached type properties forTypeStruct
Return !=0 if type has pointers that need to be scanned by the GC during a collection cycle.
Type
getIndirection(Type
t);
Returns an indirect type one step from t.
MATCH
constConv(Type
from, Type
to);
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(Type
type, Loc
loc, Scope*
sc);
Perform semantic analysis on a type.
Parameters:Typetype | Type AST node |
Locloc | the location of the type |
Scope*sc | context |
Returns:Type with completed semantic analysis,Terror if errors were encountered
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:Typetype | Type to check against existing types |
Returns:the type that was merged
This version does a merge even if the deco is already computed. Necessary for types that have a deco, but are not merged.
Expression
defaultInitLiteral(Type
t, Loc
loc);
Use when we prefer the default initializer to be a literal, rather than a global immutable variable.
Expression
getProperty(Type
t, Scope*
scope_, Loc
loc, Identifier
ident, int
flag, Expression
src = null);
Calculate built-in properties which just the type is necessary.
Parameters:Typet | the type for which the property is calculated |
Scope*scope_ | the scope from which the property is being accessed. Used for visibility checks only. |
Locloc | the location where the property is encountered |
Identifierident | the identifier of the property |
intflag | if flag & 1, don't report "not a property" error and just return NULL. |
Expressionsrc | expression for typet or null. |
Returns:expression representing the property, or null if not a property and (flag & 1)
void
resolve(Type
mt, Loc
loc, Scope*
sc, out Expression
pe, out Type
pt, out Dsymbol
ps, bool
intypeid = false);
Resolve type 'mt' to either type, symbol, or expression. If errors happened, resolved to Type.terror.
Parameters:Typemt | type to be resolved |
Locloc | the location where the type is encountered |
Scope*sc | the scope of the type |
Expressionpe | is set if t is an expression |
Typept | is set if t is a type |
Dsymbolps | is set if t is a symbol |
boolintypeid | true if in type id |
Expression
dotExp(Type
mt, Scope*
sc, Expression
e, Identifier
ident, DotExpFlag
flag);
Access the members of the object e. This type is same as e.type.
Parameters:Typemt | type for which the dot expression is used |
Scope*sc | instantiating scope |
Expressione | expression to convert |
Identifierident | identifier being used |
DotExpFlagflag | DotExpFlag bit flags |
Returns:resulting expression with e.ident resolved
Expression
defaultInit(Type
mt, Loc
loc, const bool
isCfile = false);
Get the default initialization expression for a type.
Parameters:Typemt | the type for which the init expression is returned |
Locloc | the location where the expression needs to be evaluated |
boolisCfile | default initializers are different with C |
Returns:The initialization expression for the type.
Type
addStorageClass(Type
type, STC
stc);
Add storage class modifiers to type.
Type
getComplexLibraryType(Loc
loc, Scope*
sc, TY
ty);
Extract complex type from core.stdc.config
Parameters:Locloc | for error messages |
Scope*sc | context |
TYty | a complex or imaginary type |
Returns:Complex!float, Complex!double, Complex!real or null for error
Covariant
covariant(Type
src, Type
t, STC*
pstc = null, bool
cppCovariant = false);
Covariant means that 'src' can substitute for 't', i.e. a pure function is a match for an impure type.
Parameters:Typesrc | source type |
Typet | type 'src' is covariant with |
STC*pstc | if not null, store STCxxxx which would make it covariant |
boolcppCovariant | true if extern(C++) function types should follow C++ covariant rules |
Returns:An enum value of eitherCovariant.yes or a reason it's not covariant.
STC
parameterStorageClass(TypeFunction
tf, Type
tthis, Parameter
p, VarDeclarations*
outerVars = null, bool
indirect = 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:TypeFunctiontf | TypeFunction to use to get the signature from |
Typetthis | type ofthis parameter, null if none |
Parameterp | parameter to this function |
VarDeclarations*outerVars | context variables p could escape into, if any |
boolindirect | is this for an indirect or virtual function call? |
Returns:storage class with STC.scope_ or STC.return_ OR'd in
Convert to 'const'.
Type
immutableOf(Type
type);
Convert to 'immutable'.
Make type mutable.
Type
unSharedOf(Type
type);
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
Convert to 'wild'.
Type
toHeadMutable(const Type
t);
Return type with the top level of it being mutable.
Parameters:Typet | type for which the top level mutable version is being returned |
Returns:type version with mutable top level
Type
castMod(Type
type, MOD
mod);
Apply MODxxxx bits to existing type.
Type
addMod(Type
type, MOD
mod);
Add MODxxxx bits to existing type. We're adding, not replacing, so adding const to a shared type => "shared const"
bool
isRecursiveAliasThis(ref Type
att, Type
t);
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 returns
false, and a rewrite to
S1 can be tried.
S1 is a recursive alias this type, but since
att is 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 notice
att ==t, so we're back at the start of the loop, and this returns
true.
Parameters:Typeatt | type reference used to detect recursion. Should be initialized tonull. |
Typet | type of 'alias this' rewrite to attempt |
Returns:false if the rewrite is safe,true if it would loop back around
uint
numberOfElems(Type
t, Loc
loc);
Compute number of elements for a (possibly multidimensional) static array, or 1 for other types.
Parameters:Typet | static array type |
Locloc | for error message |
Returns:number of elements, uint.max on overflow
Returns:whethert is a struct/class/enum without a body