cast_kind¶
Which conversion a Cast performs.
Declaration¶
Syntax¶
cast_kind
= RealToInteger
| IntegerToReal
| LogicalToReal
| RealToReal
| IntegerToInteger
| RealToComplex
| IntegerToComplex
| IntegerToLogical
| RealToLogical
| StringToLogical
| StringToInteger
| StringToList
| ComplexToLogical
| ComplexToComplex
| ComplexToReal
| ComplexToInteger
| LogicalToInteger
| LogicalToLogical
| RealToString
| IntegerToString
| LogicalToString
| StringToString
| UnsignedIntegerToInteger
| UnsignedIntegerToUnsignedInteger
| UnsignedIntegerToReal
| UnsignedIntegerToLogical
| IntegerToUnsignedInteger
| RealToUnsignedInteger
| CPtrToUnsignedInteger
| UnsignedIntegerToCPtr
| IntegerToSymbolicExpression
| ListToArray
| StringToArray
| PointerToInteger
| ClassToStruct
| ClassToClass
| ClassToIntrinsic
Values¶
Value |
Meaning |
|---|---|
|
truncates towards zero. |
|
exact for values the real type can represent. |
|
false becomes 0.0, true becomes 1.0. |
|
changes the real kind, rounding when it narrows. |
|
changes the integer kind, wrapping when it narrows. |
|
the value becomes the real part; the imaginary part is zero. |
|
the value becomes the real part. |
|
zero becomes false, anything else true. |
|
zero becomes false, anything else true. |
|
an LPython conversion: the empty string is false. |
|
parses the string as an integer. |
|
an LPython conversion to a list of characters. |
|
zero becomes false. |
|
changes the complex kind. |
|
takes the real part. |
|
takes the real part and truncates it. |
|
false becomes 0, true becomes 1. |
|
changes the logical kind. |
|
formats the value. |
|
formats the value. |
|
formats the value. |
|
changes the string kind. |
|
reinterprets the value as signed. |
|
changes the unsigned kind. |
|
exact for values the real type can represent. |
|
zero becomes false. |
|
reinterprets the value as unsigned. |
|
truncates towards zero. |
|
the address as a number. |
|
a number as an address. |
|
wraps an integer as a symbolic expression. |
|
an LPython conversion from a list to an array. |
|
a string as an array of characters. |
|
the address as a number. |
|
narrows a polymorphic value to a derived type. |
|
changes which class a polymorphic value is described as. |
|
narrows a polymorphic value to an intrinsic type. |
Return values¶
None. An enumeration value is not evaluated.
Description¶
Every implicit conversion is explicit in ASR, and this enumeration says which
conversion a Cast performs. The kind and the
type of the Cast agree: the kind names the pair of types, and the type
is the result.
Conversions that do not change the bits belong to ArrayPhysicalCast and StringPhysicalCast instead.
Examples¶
(Cast
:arg (Var
:v (SymbolRef 1 "i")
)
:kind :IntegerToReal
:type (Real
:kind 8
)
:value nil
:dest nil
)
It comes from this complete ASR text document:
(TranslationUnit
:symtab (SymbolTable
:id 0
:symbols {
"main" (Program
:symtab (SymbolTable
:id 1
:symbols {
"i" (Variable
:parent_symtab 1
:name "i"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Integer
:kind 4
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
"x" (Variable
:parent_symtab 1
:name "x"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Real
:kind 8
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
}
)
:name "main"
:dependencies []
:body [
(Assignment
:target (Var
:v (SymbolRef 1 "x")
)
:value (Cast
:arg (Var
:v (SymbolRef 1 "i")
)
:kind :IntegerToReal
:type (Real
:kind 8
)
:value nil
:dest nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "i")
)
:value (Cast
:arg (Var
:v (SymbolRef 1 "x")
)
:kind :RealToInteger
:type (Integer
:kind 4
)
:value nil
:dest nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
]
)
}
)
:items []
)