package visitor.codegeneration; import ast.definition.classes.VarDefinition; import ast.expression.classes.ArrayIndexing; import ast.expression.classes.FieldAccess; import ast.expression.classes.Variable; import ast.type.classes.RecordType; /** * Code function for Variable, ArrayIndexing and FieldAccess (expression l-values) */ public class AddressCGVisitor extends AbstractCGVisitor<Void, Void> { public AddressCGVisitor(CodeGenerator cg) { super(cg); } @Override public Void visit(ArrayIndexing ast, Void param) { ast.getArray().accept(addressCGVisitor, null); ast.getIndex().accept(valueCGVisitor, null); cg.arrayIndexingAddress(ast); return null; } @Override public Void visit(Variable ast, Void param) { cg.pushAddress((VarDefinition) ast.getDefinition()); return null; } @Override public Void visit(FieldAccess ast, Void param) { ast.getValue().accept(addressCGVisitor, null); cg.push("i", ((RecordType) ast.getValue().getType()).getField(ast.getField()).getOffset()); cg.write("addi"); return null; } }