dmd.dcast
Semantic analysis for cast-expressions.
License
Source: dcast.d
Documentation: https://dlang.org/phobos/dmd_dcast.html
-
Declaration
Expression
implicitCastTo
(Expressione
, Scope*sc
, Typet
);Attempt to implicitly cast the expression into type
.t
Discussion
This routine will change
. To check the matching level, usee
implicitConvTo
.Parameters
Expression
e
Expression that is to be casted
Scope*
sc
Current scope
Type
t
Expected resulting type
Return Value
The resulting casted expression (mutating
), ore
ErrorExp
if such an implicit conversion is not possible. -
Declaration
MATCH
implicitConvTo
(Expressione
, Typet
);Checks whether or not an expression can be implicitly converted to type
.t
Discussion
Unlike
implicitCastTo
, this routine does not perform the actual cast, but only checks up to whatMATCH
level the conversion would be possible.Parameters
Expression
e
Expression that is to be casted
Type
t
Expected resulting type
Return Value
The
MATCH
level between
ande
.type
.t
-
Declaration
MATCH
cimplicitConvTo
(Expressione
, Typet
);Same as implicitConvTo(); except follow C11 rules, which are quite a bit more permissive than D. C11 6.3 and 6.5.16.1
Parameters
Expression
e
Expression that is to be casted
Type
t
Expected resulting type
Return Value
The
MATCH
level between
ande
.type
.t
-
Declaration
Type
toStaticArrayType
(SliceExpe
); -
Declaration
Expression
castTo
(Expressione
, Scope*sc
, Typet
, Typeatt
= null);Do an explicit cast. Assume that the expression
does not have any indirections. (Parameter 'e
att
' is used to stop 'alias this' recursion) -
Declaration
Expression
inferType
(Expressione
, Typet
, intflag
= 0);Set type inference target
t
Target typeflag
1: don't
put an error when inference fails -
Declaration
Expression
scaleFactor
(BinExpbe
, Scope*sc
);Scale addition/subtraction to/from pointer.
-
Declaration
Type
typeMerge
(Scope*sc
, EXPop
, ref Expressionpe1
, ref Expressionpe2
);Merge types of
e1
ande2
into a common subsetDiscussion
Parameters
e1
ande2
will be rewritten in place as needed.Parameters
Scope*
sc
Current scope
EXP
op
Operator such as
e1
. In practice, either EXP.question or one of the binary operator.op
e2Expression
pe1
The LHS of the operation, will be rewritten
Expression
pe2
The RHS of the operation, will be rewritten
Return Value
The resulting type in case of success,
null
in case of error -
Declaration
Expression
typeCombine
(BinExpbe
, Scope*sc
);Bring leaves to common type.
Return Value
null
on success, ErrorExp if error occurs -
Declaration
Expression
integralPromotions
(Expressione
, Scope*sc
);Do integral promotions (convertchk). Don't convert
to -
Declaration
void
fix16997
(Scope*sc
, UnaExpue
);This provides a transition from the non-promoting behavior of unary + - ~ to the C-like integral promotion behavior.
Parameters
Scope*
sc
context
UnaExp
ue
NegExp, UAddExp, or ComExp which is revised per rules
References: https://issues.dlang.org/show_bug.cgi?id=16997
-
Declaration
bool
arrayTypeCompatibleWithoutCasting
(Typet1
, Typet2
);See if both types are arrays that can be compared for equality without any casting. Return
true
if so. This is to enable comparing things like an immutable array with a mutable one. -
Declaration
@trusted IntRange
getIntRange
(Expressione
); -
Declaration
Expression
specialNoreturnCast
(ExpressiontoBeCasted
, Typeto
);A helper function
to
"cast" from expressions of type noreturnto
any other type - noreturn is implicitly convertibleto
any other type. However, the dmd backend does not like a naive cast from a noreturn expression (particularly anassert(0)
) so this function generates:Discussion
(assert(0), value)
instead ofcast(
.to
)(assert(0))
value
is currently
however it cannot be read so could be made simpler.to
.initParameters
Expression
toBeCasted
Expression of type noreturn
to
castType
to
Type
to
cast the expressionto
.Return Value
A CommaExp, upon any failure ErrorExp will be returned.