Class VariableAccessGenerator
java.lang.Object
org.ek9lang.compiler.backend.jvm.support.VariableAccessGenerator
Generates JVM bytecode for variable load and store operations.
Handles:
- Local variable access (ALOAD/ASTORE)
- Field access on 'this' (GETFIELD/PUTFIELD)
- Field access on other variables
- Variable slot allocation
- Label management
-
Constructor Summary
ConstructorsConstructorDescriptionVariableAccessGenerator(MethodContext methodContext, Supplier<String> ownerClassNameSupplier) -
Method Summary
Modifier and TypeMethodDescriptionextractFieldName(String variableName) Extract field name from variable name (with or without "this." prefix).voidgenerateLoadVariable(org.objectweb.asm.MethodVisitor mv, String variableName) Generate JVM instructions for loading a variable.voidgenerateStoreVariable(org.objectweb.asm.MethodVisitor mv, String variableName) Generate JVM instructions for storing to a variable.voidgenerateStoreVariableAsInt(org.objectweb.asm.MethodVisitor mv, String variableName) Generate JVM instructions for storing a primitive int to a variable.getFieldDescriptor(String variableName) Get field type descriptor for putfield/getfield instructions.org.objectweb.asm.LabelgetOrCreateLabel(String labelName) Get or create JVM Label for IR label name.Get owner class name for field access.intgetVariableIndex(String variableName) Get or assign local variable slot for a variable name.booleanisFieldAccess(String variableName) Check if variable name represents field access on 'this'.booleanisVariableAllocated(String variableName) Check if a variable has already been allocated a local variable slot.booleanisVariableFieldAccess(String variableName) Check if variable name represents field access on another variable.voidtrackTempVariableFromLiteral(String tempVar, String literalValue, String literalType) Track that a temp variable was created from a literal value.voidtrackTempVariableFromLoad(String tempVar, String sourceVar) Track that a temp variable was created from loading another variable.
-
Constructor Details
-
VariableAccessGenerator
public VariableAccessGenerator(MethodContext methodContext, Supplier<String> ownerClassNameSupplier)
-
-
Method Details
-
generateLoadVariable
Generate JVM instructions for loading a variable. Uses the appropriate load opcode based on variable type (ALOAD for objects, ILOAD for primitives). -
generateStoreVariable
Generate JVM instructions for storing to a variable. -
generateStoreVariableAsInt
Generate JVM instructions for storing a primitive int to a variable.Used for INSTANCEOF results which produce primitive int (0 or 1).
-
isFieldAccess
Check if variable name represents field access on 'this'. A variable explicitly prefixed with "this." is always a field access. An unqualified name is field access only if it matches a field AND is not already allocated as a local variable (e.g., a parameter with the same name as a field). -
isVariableFieldAccess
Check if variable name represents field access on another variable. -
extractFieldName
-
getFieldDescriptor
-
getOwnerClassName
Get owner class name for field access. -
getVariableIndex
Get or assign local variable slot for a variable name. -
isVariableAllocated
Check if a variable has already been allocated a local variable slot. -
getOrCreateLabel
Get or create JVM Label for IR label name. -
trackTempVariableFromLoad
-
trackTempVariableFromLiteral
-