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;
}
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();
}
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);
}
}
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);
}
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);
}
Aggregations