Java Code Examples for org.objectweb.asm.MethodVisitor#visitMultiANewArrayInsn()

The following examples show how to use org.objectweb.asm.MethodVisitor#visitMultiANewArrayInsn() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void toCode(MethodVisitor visitor, BytecodeFrontend assembler) {
	for (int i = 0; i < bounds.length; i++) {
		bounds[i].toCode(visitor, assembler);
		int[] cast = TypeUtils.getPrimitiveCastOpcodes(bounds[i].getType(), Type.INT_TYPE);
		for (int a = 0; a < cast.length; a++)
			visitor.visitInsn(cast[a]);
	}

	if (type.getDimensions() != 1) {
		visitor.visitMultiANewArrayInsn(type.getDescriptor(), bounds.length);
	} else {
		Type element = type.getElementType();
		if (element.getSort() == Type.OBJECT || element.getSort() == Type.METHOD) {
			visitor.visitTypeInsn(Opcodes.ANEWARRAY, element.getInternalName());
		} else {
			visitor.visitIntInsn(Opcodes.NEWARRAY, TypeUtils.getPrimitiveArrayOpcode(type));
		}
	}
}
 
Example 2
Source Project: Despector   File: MethodTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testMultiNewArray() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "()V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    Label l1 = new Label();
    Label end = new Label();
    mv.visitLabel(start);
    mv.visitInsn(ICONST_5);
    mv.visitIntInsn(BIPUSH, 6);
    mv.visitMultiANewArrayInsn("[[I", 2);
    mv.visitVarInsn(ASTORE, 0);
    mv.visitLabel(l1);
    mv.visitInsn(RETURN);
    mv.visitLabel(end);
    mv.visitLocalVariable("a", "[[I", null, l1, end, 0);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "int[][] a = new int[5][6];";
    Assert.assertEquals(good, insn);
}
 
Example 3
@Override
public void accept(final MethodVisitor methodVisitor) {
	methodVisitor.visitMultiANewArrayInsn(desc, dims);
	acceptAnnotations(methodVisitor);
}
 
Example 4
Source Project: Concurnas   File: MultiANewArrayInsnNode.java    License: MIT License 4 votes vote down vote up
@Override
public void accept(final MethodVisitor methodVisitor) {
  methodVisitor.visitMultiANewArrayInsn(desc, dims);
  acceptAnnotations(methodVisitor);
}
 
Example 5
@Override
public void accept(MethodVisitor visitor)
{
	visitor.visitMultiANewArrayInsn(type.toString(), dimensions);
}
 
Example 6
@Override
public void accept(final MethodVisitor mv) {
  mv.visitMultiANewArrayInsn(desc, dims);
  acceptAnnotations(mv);
}
 
Example 7
Source Project: groovy   File: AsmClassGenerator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void visitArrayExpression(final ArrayExpression expression) {
    MethodVisitor mv = controller.getMethodVisitor();
    ClassNode elementType = expression.getElementType();
    String arrayTypeName = BytecodeHelper.getClassInternalName(elementType);
    List<Expression> sizeExpression = expression.getSizeExpression();

    int size = 0;
    int dimensions = 0;
    if (sizeExpression != null) {
        for (Expression element : sizeExpression) {
            if (element == ConstantExpression.EMPTY_EXPRESSION) break;
            dimensions += 1;
            // let's convert to an int
            element.visit(this);
            controller.getOperandStack().doGroovyCast(ClassHelper.int_TYPE);
        }
        controller.getOperandStack().remove(dimensions);
    } else {
        size = expression.getExpressions().size();
        BytecodeHelper.pushConstant(mv, size);
    }

    int storeIns = AASTORE;
    if (sizeExpression != null) {
        arrayTypeName = BytecodeHelper.getTypeDescription(expression.getType());
        mv.visitMultiANewArrayInsn(arrayTypeName, dimensions);
    } else if (ClassHelper.isPrimitiveType(elementType)) {
        int primType = 0;
        if (elementType == ClassHelper.boolean_TYPE) {
            primType = T_BOOLEAN;
            storeIns = BASTORE;
        } else if (elementType == ClassHelper.char_TYPE) {
            primType = T_CHAR;
            storeIns = CASTORE;
        } else if (elementType == ClassHelper.float_TYPE) {
            primType = T_FLOAT;
            storeIns = FASTORE;
        } else if (elementType == ClassHelper.double_TYPE) {
            primType = T_DOUBLE;
            storeIns = DASTORE;
        } else if (elementType == ClassHelper.byte_TYPE) {
            primType = T_BYTE;
            storeIns = BASTORE;
        } else if (elementType == ClassHelper.short_TYPE) {
            primType = T_SHORT;
            storeIns = SASTORE;
        } else if (elementType == ClassHelper.int_TYPE) {
            primType = T_INT;
            storeIns = IASTORE;
        } else if (elementType == ClassHelper.long_TYPE) {
            primType = T_LONG;
            storeIns = LASTORE;
        }
        mv.visitIntInsn(NEWARRAY, primType);
    } else {
        mv.visitTypeInsn(ANEWARRAY, arrayTypeName);
    }

    for (int i = 0; i < size; i += 1) {
        mv.visitInsn(DUP);
        BytecodeHelper.pushConstant(mv, i);
        Expression elementExpression = expression.getExpression(i);
        if (elementExpression == null) {
            ConstantExpression.NULL.visit(this);
        } else {
            elementExpression.visit(this);
            controller.getOperandStack().doGroovyCast(elementType);
        }
        mv.visitInsn(storeIns);
        controller.getOperandStack().remove(1);
    }

    controller.getOperandStack().push(expression.getType());
}
 
Example 8
Source Project: JReFrameworker   File: MultiANewArrayInsnNode.java    License: MIT License 4 votes vote down vote up
@Override
public void accept(final MethodVisitor methodVisitor) {
  methodVisitor.visitMultiANewArrayInsn(desc, dims);
  acceptAnnotations(methodVisitor);
}
 
Example 9
Source Project: JReFrameworker   File: MultiANewArrayInsnNode.java    License: MIT License 4 votes vote down vote up
@Override
public void accept(final MethodVisitor methodVisitor) {
  methodVisitor.visitMultiANewArrayInsn(desc, dims);
  acceptAnnotations(methodVisitor);
}