Search in sources :

Example 16 with ParameterList

use of dyvilx.tools.compiler.ast.parameter.ParameterList in project Dyvil by Dyvil.

the class InlineIntrinsicData method preProcess.

private void preProcess() {
    final ParameterList parameterList = this.method.getParameters();
    int parameterSlots = 0;
    for (int i = 0, parameterCount = parameterList.size(); i < parameterCount; i++) {
        parameterSlots += parameterList.get(i).getCovariantType().getLocalSlots();
    }
    this.parameterSlots = parameterSlots;
    final int[] accessCounts = new int[this.maxLocals];
    int lastStoredIndex = -1;
    for (int i = 0; i < this.instructionCount; i++) {
        final IInstruction instruction = this.instructions[i];
        final int opcode = instruction.getOpcode();
        if (Opcodes.isLoadOpcode(opcode)) {
            final int varIndex = ((VarInstruction) instruction).getIndex();
            if (accessCounts[varIndex]++ == 0) {
                // Local Variable loaded for the first time -> might not need to store it
                continue;
            }
            // Local Variable loaded at least two times -> need to store it and all parameters before
            if (varIndex > lastStoredIndex && varIndex < parameterSlots) {
                lastStoredIndex = varIndex;
            }
        } else if (Opcodes.isReturnOpcode(opcode)) {
            this.returnIndex = i;
        }
    }
    this.storedParameters = lastStoredIndex + 1;
}
Also used : VarInstruction(dyvilx.tools.compiler.ast.bytecode.VarInstruction) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IInstruction(dyvilx.tools.compiler.ast.bytecode.IInstruction)

Example 17 with ParameterList

use of dyvilx.tools.compiler.ast.parameter.ParameterList in project Dyvil by Dyvil.

the class AnonymousClassMetadata method getConstructorDesc.

protected String getConstructorDesc() {
    if (this.constructorDesc != null) {
        return this.constructorDesc;
    }
    final ParameterList parameterList = this.constructor.getParameters();
    final StringBuilder buf = new StringBuilder();
    buf.append('(');
    for (int i = 0, count = parameterList.size(); i < count; i++) {
        parameterList.get(i).getType().appendExtendedName(buf);
    }
    FieldThis thisField = this.thisField;
    if (thisField != null) {
        buf.append(thisField.getDescriptor());
    }
    this.captureHelper.appendCaptureTypes(buf);
    return this.constructorDesc = buf.append(")V").toString();
}
Also used : ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList)

Example 18 with ParameterList

use of dyvilx.tools.compiler.ast.parameter.ParameterList in project Dyvil by Dyvil.

the class Util method classSignatureToString.

public static void classSignatureToString(IClass iClass, StringBuilder stringBuilder) {
    ModifierUtil.writeClassType(iClass.getAttributes().flags(), stringBuilder);
    stringBuilder.append(iClass.getName());
    if (iClass.isTypeParametric()) {
        iClass.getTypeParameters().toString("", stringBuilder);
    }
    final ParameterList parameterList = iClass.getParameters();
    if (!parameterList.isEmpty()) {
        parameterList.signatureToString(stringBuilder, null);
    }
}
Also used : ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList)

Example 19 with ParameterList

use of dyvilx.tools.compiler.ast.parameter.ParameterList in project Dyvil by Dyvil.

the class CaseClasses method writeEquals.

public static void writeEquals(MethodWriter writer, IClass theClass) throws BytecodeException {
    Label label;
    // Write check 'if (this == obj) return true'
    writer.visitVarInsn(ALOAD, 0);
    writer.visitVarInsn(ALOAD, 1);
    writer.visitJumpInsn(IF_ACMPNE, label = new Label());
    writer.visitLdcInsn(1);
    writer.visitInsn(IRETURN);
    writer.visitLabel(label);
    // if (obj == null) return false
    writer.visitVarInsn(ALOAD, 1);
    writer.visitJumpInsn(IFNONNULL, label = new Label());
    writer.visitLdcInsn(0);
    writer.visitInsn(IRETURN);
    writer.visitLabel(label);
    // if (this.getClass() != obj.getClass()) return false
    writer.visitVarInsn(ALOAD, 0);
    writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
    writer.visitVarInsn(ALOAD, 1);
    writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
    writer.visitJumpInsn(IF_ACMPEQ, label = new Label());
    writer.visitLdcInsn(0);
    writer.visitInsn(IRETURN);
    writer.visitLabel(label);
    // var = (ClassName) obj
    writer.visitVarInsn(ALOAD, 1);
    writer.visitTypeInsn(CHECKCAST, theClass.getInternalName());
    // 'var' variable that stores the casted 'obj' parameter
    writer.visitVarInsn(ASTORE, 2);
    label = new Label();
    final ParameterList parameters = theClass.getParameters();
    for (int i = 0, count = parameters.size(); i < count; i++) {
        writeEquals(writer, parameters.get(i), label);
    }
    writer.visitLdcInsn(1);
    writer.visitInsn(IRETURN);
    writer.visitLabel(label);
    writer.visitLdcInsn(0);
    writer.visitInsn(IRETURN);
}
Also used : Label(dyvilx.tools.asm.Label) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList)

Example 20 with ParameterList

use of dyvilx.tools.compiler.ast.parameter.ParameterList in project Dyvil by Dyvil.

the class CaseClasses method writeToString.

public static void writeToString(MethodWriter writer, IClass theClass) throws BytecodeException {
    // ----- StringBuilder Constructor -----
    writer.visitTypeInsn(NEW, "java/lang/StringBuilder");
    writer.visitInsn(DUP);
    // Call the StringBuilder(String) constructor with the "[ClassName]("
    // argument
    writer.visitLdcInsn(theClass.getName() + "(");
    writer.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
    // ----- Class Parameters -----
    final ParameterList parameters = theClass.getParameters();
    for (int i = 0, count = parameters.size(); i < count; i++) {
        final IDataMember parameter = parameters.get(i);
        IType type = parameter.getType();
        // Get the parameter value
        writer.visitVarInsn(ALOAD, 0);
        parameter.writeGet(writer, null, 0);
        writeStringAppend(writer, type);
        if (i + 1 < count) {
            // Separator Comma
            writer.visitLdcInsn(", ");
            writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
        }
    }
    // ----- Append Closing Parenthesis -----
    writer.visitLdcInsn(")");
    // Write the call to the StringBuilder#append(String) method
    writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
    // ----- ToString -----
    // Write the call to the StringBuilder#toString() method
    writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
    // Write the return
    writer.visitInsn(ARETURN);
}
Also used : ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IDataMember(dyvilx.tools.compiler.ast.field.IDataMember) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)27 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)12 IType (dyvilx.tools.compiler.ast.type.IType)11 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)7 IClass (dyvilx.tools.compiler.ast.classes.IClass)5 IValue (dyvilx.tools.compiler.ast.expression.IValue)5 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)3 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)3 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)3 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)3 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)2 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)2 IDataMember (dyvilx.tools.compiler.ast.field.IDataMember)2 Name (dyvil.lang.Name)1 SourcePosition (dyvil.source.position.SourcePosition)1 Label (dyvilx.tools.asm.Label)1 IInstruction (dyvilx.tools.compiler.ast.bytecode.IInstruction)1 VarInstruction (dyvilx.tools.compiler.ast.bytecode.VarInstruction)1 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 CodeConstructor (dyvilx.tools.compiler.ast.constructor.CodeConstructor)1