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.dcast

Semantic analysis for cast-expressions.
Authors:

Source dcast.d

Expression implicitCastTo(Expression e, Scope* sc, Type t);
Attempt to implicitly cast the expression into type t.
This routine will change e. To check the matching level, use implicitConvTo.
Parameters:
Expression e Expression that is to be casted
Scope* sc Current scope
Type t Expected resulting type
Returns:
The resulting casted expression (mutating e), or ErrorExp if such an implicit conversion is not possible.
MATCH implicitConvTo(Expression e, Type t);
Checks whether or not an expression can be implicitly converted to type t.
Unlike implicitCastTo, this routine does not perform the actual cast, but only checks up to what MATCH level the conversion would be possible.
Parameters:
Expression e Expression that is to be casted
Type t Expected resulting type
Returns:
The MATCH level between e.type and t.
MATCH cimplicitConvTo(Expression e, Type t);
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
Returns:
The MATCH level between e.type and t.
Type toStaticArrayType(SliceExp e);
Expression castTo(Expression e, Scope* sc, Type t, Type att = null);
Do an explicit cast. Assume that the expression e does not have any indirections. (Parameter 'att' is used to stop 'alias this' recursion)
Expression inferType(Expression e, Type t, int flag = 0);
Set type inference target t Target type flag 1: don't put an error when inference fails
Expression scaleFactor(BinExp be, Scope* sc);
Scale addition/subtraction to/from pointer.
Type typeMerge(Scope* sc, EXP op, ref Expression pe1, ref Expression pe2);
Merge types of e1 and e2 into a common subset
Parameters e1 and e2 will be rewritten in place as needed.
Parameters:
Scope* sc Current scope
EXP op Operator such as e1 op e2. In practice, either EXP.question or one of the binary operator.
Expression pe1 The LHS of the operation, will be rewritten
Expression pe2 The RHS of the operation, will be rewritten
Returns:
The resulting type in case of success, null in case of error
Expression typeCombine(BinExp be, Scope* sc);
Bring leaves to common type.
Returns:
null on success, ErrorExp if error occurs
Expression integralPromotions(Expression e, Scope* sc);
Do integral promotions (convertchk). Don't convert to
void fix16997(Scope* sc, UnaExp ue);
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
bool arrayTypeCompatibleWithoutCasting(Type t1, Type t2);
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.
@trusted IntRange getIntRange(Expression e);
Expression specialNoreturnCast(Expression toBeCasted, Type to);
A helper function to "cast" from expressions of type noreturn to any other type - noreturn is implicitly convertible to any other type. However, the dmd backend does not like a naive cast from a noreturn expression (particularly an assert(0)) so this function generates:
(assert(0), value) instead of cast(to)(assert(0)).
value is currently to.init however it cannot be read so could be made simpler.
Parameters:
Expression toBeCasted Expression of type noreturn to cast
Type to Type to cast the expression to.
Returns:
A CommaExp, upon any failure ErrorExp will be returned.