Class StringInterpolationInstr
java.lang.Object
org.ek9lang.compiler.ir.instructions.IRInstr
org.ek9lang.compiler.ir.instructions.StringInterpolationInstr
- All Implemented Interfaces:
INode
IR instruction for string interpolation.
Contains structured data for building an interpolated string from literal text and pre-converted String variables. All expressions have been converted to String by Phase 7 before this instruction is created.
Backends can choose optimal concatenation strategy:
- JVM: invokedynamic StringConcatFactory or StringBuilder
- LLVM: single allocation with memcpy
-
Method Summary
Modifier and TypeMethodDescriptionlongGet count of literal parts.getParts()Get the interpolation parts.Get the scope ID for memory management.Get the setup instructions ($ operator calls for non-String expressions).longGet count of variable parts.booleanCheck if this interpolation has any setup instructions.booleanCheck if this interpolation has any variable parts.static StringInterpolationInstrinterpolate(String result, List<IRInstr> setupInstructions, List<StringInterpolationPart> parts, String scopeId, DebugInfo debugInfo) Create a string interpolation instruction.booleanCheck if this is a simple literal-only interpolation.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
-
interpolate
public static StringInterpolationInstr interpolate(String result, List<IRInstr> setupInstructions, List<StringInterpolationPart> parts, String scopeId, DebugInfo debugInfo) Create a string interpolation instruction.- Parameters:
result- Variable to store the resulting StringsetupInstructions- Instructions to convert expressions to String ($ calls)parts- The interpolation parts (literals and String variables)scopeId- Scope for memory managementdebugInfo- Source location information- Returns:
- StringInterpolationInstr
-
getSetupInstructions
-
getParts
Get the interpolation parts.- Returns:
- Immutable list of parts
-
getScopeId
-
hasVariableParts
public boolean hasVariableParts()Check if this interpolation has any variable parts.- Returns:
- true if at least one part is a variable reference
-
hasSetupInstructions
public boolean hasSetupInstructions()Check if this interpolation has any setup instructions.- Returns:
- true if there are setup instructions to execute
-
getLiteralPartCount
public long getLiteralPartCount()Get count of literal parts.- Returns:
- Number of literal parts
-
getVariablePartCount
public long getVariablePartCount()Get count of variable parts.- Returns:
- Number of variable parts
-
isLiteralOnly
public boolean isLiteralOnly()Check if this is a simple literal-only interpolation. Can be optimized to a single LOAD_LITERAL.- Returns:
- true if all parts are literals
-
toString
-