protected Statement createGetterBlock(PropertyNode propertyNode, final FieldNode field) { return new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { if (field.isStatic()) { mv.visitFieldInsn(GETSTATIC, BytecodeHelper.getClassInternalName(classNode), field.getName(), BytecodeHelper.getTypeDescription(field.getType())); } else { mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, BytecodeHelper.getClassInternalName(classNode), field.getName(), BytecodeHelper.getTypeDescription(field.getType())); } BytecodeHelper.doReturn(mv, field.getType()); } }); }
public void visitBytecodeSequence(BytecodeSequence bytecodeSequence) { MethodVisitor mv = controller.getMethodVisitor(); List instructions = bytecodeSequence.getInstructions(); int mark = controller.getOperandStack().getStackLength(); for (Iterator iterator = instructions.iterator(); iterator.hasNext();) { Object part = iterator.next(); if (part == EmptyExpression.INSTANCE) { mv.visitInsn(ACONST_NULL); } else if (part instanceof Expression) { ((Expression) part).visit(this); } else if (part instanceof Statement) { Statement stm = (Statement) part; stm.visit(this); mv.visitInsn(ACONST_NULL); } else { BytecodeInstruction runner = (BytecodeInstruction) part; runner.visit(mv); } } controller.getOperandStack().remove(mark-controller.getOperandStack().getStackLength()); }
@Override public void visit(final GroovyCodeVisitor visitor) { if (visitor instanceof AsmClassGenerator) { AsmClassGenerator generator = (AsmClassGenerator) visitor; controller = generator.getController(); } super.visit(visitor); }
protected Statement createSetterBlock(PropertyNode propertyNode, final FieldNode field) { return new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { if (field.isStatic()) { BytecodeHelper.load(mv, field.getType(), 0); mv.visitFieldInsn(PUTSTATIC, BytecodeHelper.getClassInternalName(classNode), field.getName(), BytecodeHelper.getTypeDescription(field.getType())); } else { mv.visitVarInsn(ALOAD, 0); BytecodeHelper.load(mv, field.getType(), 1); mv.visitFieldInsn(PUTFIELD, BytecodeHelper.getClassInternalName(classNode), field.getName(), BytecodeHelper.getTypeDescription(field.getType())); } mv.visitInsn(RETURN); } }); }
if (code instanceof BytecodeSequence && ((BytecodeSequence)code).getInstructions().size() == 1 && ((BytecodeSequence)code).getInstructions().get(0) instanceof BytecodeInstruction) { ((BytecodeInstruction)((BytecodeSequence)code).getInstructions().get(0)).visit(mv); } else { visitStdMethod(node, isConstructor, parameters, code);
protected void addInitialization(final ClassNode node) { boolean addSwapInit = moveOptimizedConstantsInitialization(node); for (ConstructorNode cn : node.getDeclaredConstructors()) { addInitialization(node, cn); } if (addSwapInit) { BytecodeSequence seq = new BytecodeSequence( new BytecodeInstruction() { @Override public void visit(MethodVisitor mv) { mv.visitMethodInsn(INVOKESTATIC, BytecodeHelper.getClassInternalName(node), SWAP_INIT, "()V", false); } }); List<Statement> swapCall = new ArrayList<Statement>(1); swapCall.add(seq); node.addStaticInitializerStatements(swapCall, true); } }
public void visitBytecodeSequence(BytecodeSequence bytecodeSequence) { List instructions = bytecodeSequence.getInstructions(); for (Iterator iterator = instructions.iterator(); iterator.hasNext();) { Object part = iterator.next(); if (part == EmptyExpression.INSTANCE) { mv.visitInsn(ACONST_NULL); } else if (part instanceof Expression) { visitAndAutoboxBoolean((Expression) part); } else if (part instanceof Statement) { Statement stm = (Statement) part; stm.visit(this); mv.visitInsn(ACONST_NULL); } else { BytecodeInstruction runner = (BytecodeInstruction) part; runner.visit(mv); } } }
Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { mv.visitVarInsn(ALOAD, 0);
public void visitBytecodeSequence(BytecodeSequence bytecodeSequence) { List instructions = bytecodeSequence.getInstructions(); for (Iterator iterator = instructions.iterator(); iterator.hasNext();) { Object part = iterator.next(); if (part == EmptyExpression.INSTANCE) { mv.visitInsn(ACONST_NULL); } else if (part instanceof Expression) { visitAndAutoboxBoolean((Expression) part); } else if (part instanceof Statement) { Statement stm = (Statement) part; stm.visit(this); mv.visitInsn(ACONST_NULL); } else { BytecodeInstruction runner = (BytecodeInstruction) part; runner.visit(mv); } } }
Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { Label nullLabel = new Label(); setMetaClassCode = new BytecodeSequence(list); ClassHelper.OBJECT_TYPE, INVOKE_METHOD_PARAMS, ClassNode.EMPTY_ARRAY, new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { mv.visitVarInsn(ALOAD, 0); GET_PROPERTY_PARAMS, ClassNode.EMPTY_ARRAY, new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { mv.visitVarInsn(ALOAD, 0); SET_PROPERTY_PARAMS, ClassNode.EMPTY_ARRAY, new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { mv.visitVarInsn(ALOAD, 0);
public void visitBytecodeSequence(BytecodeSequence bytecodeSequence) { List instructions = bytecodeSequence.getInstructions(); for (Iterator iterator = instructions.iterator(); iterator.hasNext();) { Object part = iterator.next(); if (part == EmptyExpression.INSTANCE) { mv.visitInsn(ACONST_NULL); } else if (part instanceof Expression) { visitAndAutoboxBoolean((Expression) part); } else if (part instanceof Statement) { Statement stm = (Statement) part; stm.visit(this); mv.visitInsn(ACONST_NULL); } else { BytecodeInstruction runner = (BytecodeInstruction) part; runner.visit(mv); } } }
BytecodeSequence seq = new BytecodeSequence(instructions); BlockStatement bs = new BlockStatement(); bs.addStatement(seq);
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { Parameter[] parameters = node.getParameters(); String methodType = BytecodeHelper.getMethodDescriptor(node.getReturnType(), parameters); String signature = BytecodeHelper.getGenericsMethodSignature(node); int modifiers = node.getModifiers(); if (isVargs(node.getParameters())) modifiers |= Opcodes.ACC_VARARGS; mv = cv.visitMethod(modifiers, node.getName(), methodType, signature, buildExceptions(node.getExceptions())); mv = new MyMethodAdapter(); visitAnnotations(node, mv); for (int i = 0; i < parameters.length; i++) { visitParameterAnnotations(parameters[i], i, mv); } helper = new BytecodeHelper(mv); if (classNode.isAnnotationDefinition()) { visitAnnotationDefault(node, mv); } else if (!node.isAbstract()) { Statement code = node.getCode(); // fast path for getter/setters etc. if (code instanceof BytecodeSequence && ((BytecodeSequence)code).getInstructions().size() == 1 && ((BytecodeSequence)code).getInstructions().get(0) instanceof BytecodeInstruction) { ((BytecodeInstruction)((BytecodeSequence)code).getInstructions().get(0)).visit(mv); } else{ visitStdMethod(node, isConstructor, parameters, code); } mv.visitMaxs(0, 0); } mv.visitEnd(); }
} else { block.addStatement( new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { getThis(mv,classInternalName,outerClassDescriptor,outerClassInternalName); } else { block.addStatement( new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { getThis(mv,classInternalName,outerClassDescriptor,outerClassInternalName); } else { block.addStatement( new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { getThis(mv,classInternalName,outerClassDescriptor,outerClassInternalName);
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { lineNumber = -1; columnNumber = -1; Parameter[] parameters = node.getParameters(); String methodType = BytecodeHelper.getMethodDescriptor(node.getReturnType(), parameters); String signature = BytecodeHelper.getGenericsMethodSignature(node); int modifiers = node.getModifiers(); if (isVargs(node.getParameters())) modifiers |= Opcodes.ACC_VARARGS; mv = cv.visitMethod(modifiers, node.getName(), methodType, signature, buildExceptions(node.getExceptions())); mv = new MyMethodAdapter(); visitAnnotations(node, mv); for (int i = 0; i < parameters.length; i++) { visitParameterAnnotations(parameters[i], i, mv); } helper = new BytecodeHelper(mv); if (classNode.isAnnotationDefinition()) { visitAnnotationDefault(node, mv); } else if (!node.isAbstract()) { Statement code = node.getCode(); // fast path for getter/setters etc. if (code instanceof BytecodeSequence && ((BytecodeSequence)code).getInstructions().size() == 1 && ((BytecodeSequence)code).getInstructions().get(0) instanceof BytecodeInstruction) { ((BytecodeInstruction)((BytecodeSequence)code).getInstructions().get(0)).visit(mv); } else{ visitStdMethod(node, isConstructor, parameters, code); } mv.visitMaxs(0, 0); } mv.visitEnd(); }
newMethod.setCode(new BytecodeSequence(instructions)); return newMethod;
public void visitBytecodeSequence(BytecodeSequence bytecodeSequence) { MethodVisitor mv = controller.getMethodVisitor(); List instructions = bytecodeSequence.getInstructions(); int mark = controller.getOperandStack().getStackLength(); for (Iterator iterator = instructions.iterator(); iterator.hasNext();) { Object part = iterator.next(); if (part == EmptyExpression.INSTANCE) { mv.visitInsn(ACONST_NULL); } else if (part instanceof Expression) { ((Expression) part).visit(this); } else if (part instanceof Statement) { Statement stm = (Statement) part; stm.visit(this); mv.visitInsn(ACONST_NULL); } else { BytecodeInstruction runner = (BytecodeInstruction) part; runner.visit(mv); } } controller.getOperandStack().remove(mark-controller.getOperandStack().getStackLength()); }
protected Statement createGetterBlock(PropertyNode propertyNode, final FieldNode field) { return new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { if (field.isStatic()) { mv.visitFieldInsn(GETSTATIC, BytecodeHelper.getClassInternalName(classNode), field.getName(), BytecodeHelper.getTypeDescription(field.getType())); } else { mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, BytecodeHelper.getClassInternalName(classNode), field.getName(), BytecodeHelper.getTypeDescription(field.getType())); } BytecodeHelper.doReturn(mv, field.getType()); } }); }
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { controller.resetLineNumber(); Parameter[] parameters = node.getParameters(); String methodType = BytecodeHelper.getMethodDescriptor(node.getReturnType(), parameters); String signature = BytecodeHelper.getGenericsMethodSignature(node); int modifiers = node.getModifiers(); if (isVargs(node.getParameters())) modifiers |= Opcodes.ACC_VARARGS; MethodVisitor mv = cv.visitMethod(modifiers, node.getName(), methodType, signature, buildExceptions(node.getExceptions())); controller.setMethodVisitor(mv); visitAnnotations(node, mv); for (int i = 0; i < parameters.length; i++) { visitParameterAnnotations(parameters[i], i, mv); } if (controller.getClassNode().isAnnotationDefinition() && !node.isStaticConstructor()) { visitAnnotationDefault(node, mv); } else if (!node.isAbstract()) { Statement code = node.getCode(); mv.visitCode(); // fast path for getter/setters etc. if (code instanceof BytecodeSequence && ((BytecodeSequence)code).getInstructions().size() == 1 && ((BytecodeSequence)code).getInstructions().get(0) instanceof BytecodeInstruction) { ((BytecodeInstruction)((BytecodeSequence)code).getInstructions().get(0)).visit(mv); } else { visitStdMethod(node, isConstructor, parameters, code); } // we use this NOP to have a valid jump target for the various labels //mv.visitInsn(NOP); mv.visitMaxs(0, 0); } mv.visitEnd(); }
protected Statement createSetterBlock(PropertyNode propertyNode, final FieldNode field) { return new BytecodeSequence(new BytecodeInstruction() { public void visit(MethodVisitor mv) { if (field.isStatic()) { BytecodeHelper.load(mv, field.getType(), 0); mv.visitFieldInsn(PUTSTATIC, BytecodeHelper.getClassInternalName(classNode), field.getName(), BytecodeHelper.getTypeDescription(field.getType())); } else { mv.visitVarInsn(ALOAD, 0); BytecodeHelper.load(mv, field.getType(), 1); mv.visitFieldInsn(PUTFIELD, BytecodeHelper.getClassInternalName(classNode), field.getName(), BytecodeHelper.getTypeDescription(field.getType())); } mv.visitInsn(RETURN); } }); }