Class SanitizeInstrAsmGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.SanitizeInstrAsmGenerator
- All Implemented Interfaces:
Consumer<SanitizeInstr>
final class SanitizeInstrAsmGenerator
extends AbstractAsmGenerator
implements Consumer<SanitizeInstr>
Specialized ASM generator for SanitizeInstr processing.
Generates JVM bytecode to sanitize a String value and store the result. The sanitization uses InputSanitizer.sanitize() which:
- Returns an unset String if dangerous patterns are detected
- Returns the original String if safe (no threats detected)
Includes null-safety check: if source is null, creates an unset String directly without calling sanitize. This provides defense-in-depth even though EK9 variables should never be null (they may be unset but are always allocated).
Pattern: SANITIZE destination = source
JVM Bytecode generated (with null check):
ALOAD source_slot IFNONNULL notNull NEW org/ek9/lang/String DUP INVOKESPECIAL org/ek9/lang/String.<init>()V ASTORE dest_slot GOTO end notNull: NEW org/ek9/lang/InputSanitizer DUP INVOKESPECIAL org/ek9/lang/InputSanitizer.<init>()V ALOAD source_slot INVOKEVIRTUAL org/ek9/lang/InputSanitizer.sanitize(Lorg/ek9/lang/String;)Lorg/ek9/lang/String; ASTORE dest_slot end:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractAsmGenerator
AbstractAsmGenerator.LocalVariableInfo, AbstractAsmGenerator.MethodContext, AbstractAsmGenerator.ScopeInfo, AbstractAsmGenerator.TempVariableSource -
Field Summary
Fields inherited from class AbstractAsmGenerator
classWriter, constructTargetTuple, outputVisitor -
Constructor Summary
ConstructorsConstructorDescriptionSanitizeInstrAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(SanitizeInstr sanitizeInstr) Generate JVM bytecode for a SANITIZE instruction.Methods inherited from class AbstractAsmGenerator
convertToJvmDescriptor, convertToJvmName, extractFieldName, generateBooleanLiteral, generateCharacterLiteral, generateDebugInfo, generateFloatLiteral, generateIntegerLiteral, generateLoadVariable, generateLocalVariableTable, generateMethodDescriptor, generateObjectLiteral, generateStackOperation, generateStoreVariable, generateStringLiteral, getCurrentMethodVisitor, getFieldDescriptor, getMethodContext, getOrCreateLabel, getOwnerClassName, getVariableIndex, isFieldAccess, isVariableAllocated, isVariableFieldAccess, setCurrentMethodVisitor, setSharedMethodContext, trackTempVariableFromLiteral, trackTempVariableFromLoad
-
Constructor Details
-
SanitizeInstrAsmGenerator
SanitizeInstrAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter)
-
-
Method Details
-
accept
Generate JVM bytecode for a SANITIZE instruction.Includes null-safety check: if source is null, creates an unset String directly. Otherwise, creates InputSanitizer and calls sanitize on the source.
- Specified by:
acceptin interfaceConsumer<SanitizeInstr>
-