use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class FieldPattern method writeJumpOnMismatch.
@Override
public void writeJumpOnMismatch(MethodWriter writer, int varIndex, Label target) throws BytecodeException {
final IType matchedType = this.targetType;
final IType fieldType = this.dataMember.getType();
final int lineNumber = this.lineNumber();
final IType commonType;
if (matchedType.isPrimitive()) {
commonType = matchedType;
} else if (fieldType.isPrimitive()) {
commonType = fieldType;
if (matchedType != fieldType && Types.isSuperType(matchedType, fieldType)) {
varIndex = Pattern.ensureVar(writer, varIndex);
Pattern.loadVar(writer, varIndex);
writer.visitTypeInsn(Opcodes.INSTANCEOF, fieldType.getInternalName());
writer.visitJumpInsn(Opcodes.IFEQ, target);
}
} else {
commonType = Types.ANY;
}
Pattern.loadVar(writer, varIndex);
matchedType.writeCast(writer, commonType, lineNumber);
this.dataMember.writeGet(writer, null, lineNumber);
fieldType.writeCast(writer, commonType, lineNumber);
CaseClasses.writeIFNE(writer, commonType, target);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class TupleSurrogate method writeJumpOnMismatch.
@Override
public void writeJumpOnMismatch(MethodWriter writer, int varIndex, Label target) throws BytecodeException {
varIndex = Pattern.ensureVar(writer, varIndex);
final int lineNumber = this.lineNumber();
final IType tupleType = this.getType();
final IClass tupleClass = tupleType.getTheClass();
final TypeParameterList typeParameters = tupleClass.getTypeParameters();
final String internalTupleClassName = tupleType.getInternalName();
for (int i = 0; i < this.patternCount; i++) {
if (this.patterns[i].isWildcard()) {
// Skip wildcard patterns
continue;
}
writer.visitVarInsn(Opcodes.ALOAD, varIndex);
writer.visitFieldInsn(Opcodes.GETFIELD, internalTupleClassName, "_" + (i + 1), "Ljava/lang/Object;");
final IType targetType = Types.resolveTypeSafely(tupleType, typeParameters.get(i));
Types.OBJECT.writeCast(writer, targetType, lineNumber);
this.patterns[i].writeJumpOnMismatch(writer, -1, target);
}
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class PropertyReference method writeReference.
@Override
public void writeReference(MethodWriter writer, int lineNumber) throws BytecodeException {
StringBuilder desc = new StringBuilder().append('(');
if (this.receiver != null) {
this.receiver.writeExpression(writer, null);
this.receiver.getType().appendExtendedName(desc);
}
final IType methodType = this.getterMethod.getType();
final String getterName = this.getterMethod.getInternalName();
desc.append(')').append('L').append(ReferenceType.LazyFields.getInternalRef(methodType, "")).append(';');
final Handle getterHandle = this.getterMethod.toHandle();
final Handle setterHandle = this.setterMethod.toHandle();
writer.visitLineNumber(lineNumber);
writer.visitInvokeDynamicInsn(getterName, desc.toString(), BOOTSTRAP, getterHandle, setterHandle);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class ReferenceType method inferTypes.
@Override
public void inferTypes(IType concrete, ITypeContext typeContext) {
if (!this.theClass.isTypeParametric()) {
return;
}
final ITypeParameter typeVariable = this.theClass.getTypeParameters().get(0);
final IType concreteRefType = concrete.resolveType(typeVariable);
if (concreteRefType != null) {
this.type.inferTypes(concreteRefType, typeContext);
}
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class CodeClass method fillTraitClasses.
/**
* Fills the list of traits and returns a status. If {@code top} is true, the returned value represents whether or
* not the super type of the given class has traits
*
* @param currentClass
* the current class to process
* @param traitClasses
* the list of trait classes
* @param top
* {@code true} if this is the top call
*/
private static boolean fillTraitClasses(IClass currentClass, Set<IClass> traitClasses, boolean top) {
boolean traits = false;
final TypeList interfaces = currentClass.getInterfaces();
if (interfaces != null) {
for (IType type : interfaces) {
final IClass interfaceClass = type.getTheClass();
if (interfaceClass == null) {
continue;
}
if (interfaceClass.hasModifier(Modifiers.TRAIT_CLASS)) {
traitClasses.add(interfaceClass);
traits = true;
}
fillTraitClasses(interfaceClass, traitClasses, false);
}
}
final IType superType = currentClass.getSuperType();
final IClass superClass;
if (superType == null || (superClass = superType.getTheClass()) == null) {
return traits && !top;
}
return top ? fillTraitClasses(superClass, traitClasses, false) : traits || fillTraitClasses(superClass, traitClasses, false);
}
Aggregations