Search in sources :

Example 1 with ITypeContext

use of dyvilx.tools.compiler.ast.generic.ITypeContext in project Dyvil by Dyvil.

the class LambdaExpr method inferReturnType.

public void inferReturnType(IType type, IType valueType) {
    if (this.hasImplicitReturnType()) {
        this.returnType = valueType;
    }
    if ((this.flags & LAMBDA_TYPE_INFERRED) != 0 || type.canExtract(LambdaType.class)) {
        this.type = this.makeType();
        return;
    }
    final ITypeContext tempContext = new MapTypeContext();
    final ParameterList methodParams = this.method.getParameters();
    final int size = Math.min(this.parameters.size(), methodParams.size());
    for (int i = 0; i < size; i++) {
        final IParameter lambdaParam = this.parameters.get(i);
        final IParameter methodParam = methodParams.get(i);
        methodParam.getType().inferTypes(lambdaParam.getType(), tempContext);
    }
    this.method.getType().inferTypes(valueType, tempContext);
    final IType classType = this.method.getEnclosingClass().getThisType();
    this.type = classType.getConcreteType(tempContext);
}
Also used : LambdaType(dyvilx.tools.compiler.ast.type.compound.LambdaType) MapTypeContext(dyvilx.tools.compiler.ast.generic.MapTypeContext) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IType(dyvilx.tools.compiler.ast.type.IType)

Example 2 with ITypeContext

use of dyvilx.tools.compiler.ast.generic.ITypeContext in project Dyvil by Dyvil.

the class CodeMethod method checkOverrideMethods.

private void checkOverrideMethods(MarkerList markers) {
    if (this.checkNoOverride(markers)) {
        return;
    }
    final ITypeContext typeContext = this.enclosingClass.getThisType();
    this.filterOverrides(markers, typeContext);
    if (this.checkNoOverride(markers)) {
        return;
    }
    if (!this.isOverride() && !this.attributes.hasFlag(Modifiers.GENERATED)) {
        markers.add(Markers.semantic(this.position, "method.overrides", this.name));
    }
    final boolean thisTypeResolved = this.type.isResolved();
    for (IMethod overrideMethod : this.overrideMethods) {
        ModifierUtil.checkOverride(this, overrideMethod, markers);
        if (!thisTypeResolved) {
            continue;
        }
        final IType superReturnType = overrideMethod.getType().getConcreteType(typeContext);
        if (// avoid extra error
        superReturnType != this.type && superReturnType.isResolved() && !Types.isSuperType(superReturnType.asParameterType(), this.type)) {
            final Marker marker = Markers.semanticError(this.position, "method.override.type.incompatible", this.name);
            marker.addInfo(Markers.getSemantic("method.type", this.type));
            marker.addInfo(Markers.getSemantic("method.override.type", superReturnType));
            addOverrideInfo(typeContext, overrideMethod, marker);
            markers.add(marker);
        }
    }
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IType(dyvilx.tools.compiler.ast.type.IType)

Example 3 with ITypeContext

use of dyvilx.tools.compiler.ast.generic.ITypeContext in project Dyvil by Dyvil.

the class IDataMember method checkAssign.

default IValue checkAssign(MarkerList markers, IContext context, SourcePosition position, IValue receiver, IValue newValue) {
    if (this.hasModifier(Modifiers.FINAL) && !context.isConstructor()) {
        markers.add(Markers.semanticError(position, this.getKind().getName() + ".assign.final", this.getName()));
    }
    final IType type = this.getType();
    final ITypeContext typeContext = receiver == null ? ITypeContext.NULL : receiver.getType();
    final TypeChecker.MarkerSupplier markerSupplier = (errorPosition, expected, actual) -> {
        final String kindName = this.getKind().getName();
        final Marker marker = Markers.semanticError(errorPosition, kindName + ".assign.type", this.getName());
        marker.addInfo(Markers.getSemantic(kindName + ".type", expected));
        marker.addInfo(Markers.getSemantic("value.type", actual));
        return marker;
    };
    return TypeChecker.convertValue(newValue, type, typeContext, markers, context, markerSupplier);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IValueConsumer(dyvilx.tools.compiler.ast.consumer.IValueConsumer) IContext(dyvilx.tools.compiler.ast.context.IContext) TypeChecker(dyvilx.tools.compiler.transform.TypeChecker) IType(dyvilx.tools.compiler.ast.type.IType) MemberKind(dyvilx.tools.compiler.ast.member.MemberKind) WriteableExpression(dyvilx.tools.compiler.ast.expression.WriteableExpression) IMember(dyvilx.tools.compiler.ast.member.IMember) Types(dyvilx.tools.compiler.ast.type.builtin.Types) Formatting(dyvilx.tools.compiler.config.Formatting) Marker(dyvilx.tools.parsing.marker.Marker) SourcePosition(dyvil.source.position.SourcePosition) Markers(dyvilx.tools.compiler.util.Markers) BytecodeException(dyvilx.tools.compiler.backend.exception.BytecodeException) MarkerList(dyvilx.tools.parsing.marker.MarkerList) NonNull(dyvil.annotation.internal.NonNull) Modifiers(dyvil.reflect.Modifiers) MethodWriter(dyvilx.tools.compiler.backend.MethodWriter) IClass(dyvilx.tools.compiler.ast.classes.IClass) TypeChecker(dyvilx.tools.compiler.transform.TypeChecker) Marker(dyvilx.tools.parsing.marker.Marker) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

ITypeContext (dyvilx.tools.compiler.ast.generic.ITypeContext)3 IType (dyvilx.tools.compiler.ast.type.IType)3 Marker (dyvilx.tools.parsing.marker.Marker)2 NonNull (dyvil.annotation.internal.NonNull)1 Modifiers (dyvil.reflect.Modifiers)1 SourcePosition (dyvil.source.position.SourcePosition)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 IValueConsumer (dyvilx.tools.compiler.ast.consumer.IValueConsumer)1 IContext (dyvilx.tools.compiler.ast.context.IContext)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 WriteableExpression (dyvilx.tools.compiler.ast.expression.WriteableExpression)1 MapTypeContext (dyvilx.tools.compiler.ast.generic.MapTypeContext)1 IMember (dyvilx.tools.compiler.ast.member.IMember)1 MemberKind (dyvilx.tools.compiler.ast.member.MemberKind)1 Types (dyvilx.tools.compiler.ast.type.builtin.Types)1 LambdaType (dyvilx.tools.compiler.ast.type.compound.LambdaType)1 MethodWriter (dyvilx.tools.compiler.backend.MethodWriter)1 BytecodeException (dyvilx.tools.compiler.backend.exception.BytecodeException)1 Formatting (dyvilx.tools.compiler.config.Formatting)1 TypeChecker (dyvilx.tools.compiler.transform.TypeChecker)1