Class CastInstr
- All Implemented Interfaces:
INode
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.getKind()Get the kind discriminator for INSTANCEOF instructions; null for CAST.Get the source variable name being casted.Get the fully qualified target type to cast to.static CastInstrinstanceOf(String result, String source, String targetType, InstanceOfKind kind, DebugInfo debugInfo) Create instruction to check if source is instance of target type with explicit kind.booleanCheck if this is an INSTANCEOF instruction.toString()Methods inherited from class IRInstr
accept, addOperand, addOperands, equals, getDebugInfo, getEscapeMetaData, getOpcode, getOperands, getResult, hasEscapeMetaData, hashCode, hasResult, isControlFlow, isLabel, isMemoryManagement, isMethodCall, setEscapeMetaData
-
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. -
instanceOf
public static CastInstr instanceOf(String result, String source, String targetType, InstanceOfKind kind, DebugInfo debugInfo) Create instruction to check if source is instance of target type with explicit kind.Pattern: INSTANCEOF result = source, targetType [KIND]
Result is a primitive boolean (JVM int 0/1) indicating whether source is an instance of targetType under the semantics named by
kind. SeeInstanceOfKindfor the kind contract — backends must dispatch on it. The kind is mandatory because the JVM's native subtype-aware INSTANCEOF and an LLVM type-hash compare are NOT interchangeable, and the producer is the only party that knows which it wants.- Parameters:
result- The variable to store the boolean resultsource- The variable containing the value to checktargetType- The fully qualified type to check againstkind- The semantic kind (EXACT, SUBTYPE, TRAIT) — not nulldebugInfo- Debug information for source mapping (can be null)- Returns:
- INSTANCEOF instruction
-
isInstanceOf
public boolean isInstanceOf()Check if this is an INSTANCEOF instruction. -
getKind
Get the kind discriminator for INSTANCEOF instructions; null for CAST. -
toString
-