dmd.dcast

Semantic analysis for cast-expressions.

Authors

Walter Bright

Source: dcast.d

  • Declaration

    Expression implicitCastTo(Expression e, Scope* sc, Type t);

    Attempt to implicitly cast the expression into type t.

    Discussion

    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

    Return Value

    The resulting casted expression (mutating e), or ErrorExp if such an implicit conversion is not possible.

  • Declaration

    MATCH implicitConvTo(Expression e, Type t);

    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 what MATCH 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 e.type and t.

  • Declaration

    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

    Return Value

    The MATCH level between e.type and t.

  • Declaration

    Type toStaticArrayType(SliceExp e);

  • Declaration

    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)

  • Declaration

    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

  • Declaration

    Expression scaleFactor(BinExp be, Scope* sc);

    Scale addition/subtraction to/from pointer.

  • Declaration

    Type typeMerge(Scope* sc, EXP op, ref Expression pe1, ref Expression pe2);

    Merge types of e1 and e2 into a common subset

    Discussion

    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

    Return Value

    The resulting type in case of success, null in case of error

  • Declaration

    Expression typeCombine(BinExp be, Scope* sc);

    Bring leaves to common type.

    Return Value

    null on success, ErrorExp if error occurs

  • Declaration

    Expression integralPromotions(Expression e, Scope* sc);

    Do integral promotions (convertchk). Don't convert to

  • Declaration

    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

  • Declaration

    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.

  • Declaration

    @trusted IntRange getIntRange(Expression e);

  • Declaration

    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:

    Discussion

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

    Return Value

    A CommaExp, upon any failure ErrorExp will be returned.