Class CastInstr
java.lang.Object
org.ek9lang.compiler.ir.instructions.IRInstr
org.ek9lang.compiler.ir.instructions.CastInstr
- All Implemented Interfaces:
INode
IR instruction for explicit type casting.
Used when the value on the stack needs to be cast to a different type, particularly in Scenario 2 wrapper delegation where the delegate method returns Any but the wrapper method returns a more specific type.
Format: CAST result = source, targetType
Backend translation:
- JVM: CHECKCAST target_type
- LLVM: bitcast or no-op (depending on representation)
-
Method Summary
Modifier and TypeMethodDescriptionstatic CastInstrCreate instruction to cast source to target type and store in result (no debug info).static CastInstrCreate instruction to cast source to target type and store in result.Get the source variable name being casted.Get the fully qualified target type to cast to.Methods inherited from class IRInstr
accept, addOperand, addOperands, equals, getDebugInfo, getEscapeMetaData, getOpcode, getOperands, getResult, hasEscapeMetaData, hashCode, hasResult, isControlFlow, isLabel, isMemoryManagement, isMethodCall, setEscapeMetaData, toString
-
Method Details
-
cast
Create instruction to cast source to target type and store in result.Pattern: CAST result = source, targetType
- Parameters:
result- The variable to store the casted resultsource- The variable containing the value to casttargetType- The fully qualified type to cast todebugInfo- Debug information for source mapping (can be null)- Returns:
- CAST instruction
-
cast
Create instruction to cast source to target type and store in result (no debug info).- Parameters:
result- The variable to store the casted resultsource- The variable containing the value to casttargetType- The fully qualified type to cast to- Returns:
- CAST instruction
-
getSource
Get the source variable name being casted. -
getTargetType
Get the fully qualified target type to cast to.
-