Search in sources :

Example 81 with IType

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);
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Example 82 with IType

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);
    }
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IType(dyvilx.tools.compiler.ast.type.IType)

Example 83 with IType

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);
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType) Handle(dyvilx.tools.asm.Handle)

Example 84 with IType

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);
    }
}
Also used : ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) IType(dyvilx.tools.compiler.ast.type.IType)

Example 85 with IType

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);
}
Also used : TypeList(dyvilx.tools.compiler.ast.type.TypeList) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IType (dyvilx.tools.compiler.ast.type.IType)159 IClass (dyvilx.tools.compiler.ast.classes.IClass)26 Marker (dyvilx.tools.parsing.marker.Marker)23 IValue (dyvilx.tools.compiler.ast.expression.IValue)21 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)13 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)11 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)10 SourcePosition (dyvil.source.position.SourcePosition)9 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)9 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)9 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)9 TypeList (dyvilx.tools.compiler.ast.type.TypeList)7 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)6 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)6 IVariable (dyvilx.tools.compiler.ast.field.IVariable)6 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)6 MethodWriter (dyvilx.tools.compiler.backend.MethodWriter)6 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)5 Name (dyvil.lang.Name)4