Search in sources :

Example 31 with Marker

use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.

the class FieldAssignment method capture.

@Override
protected void capture(MarkerList markers, IContext context) {
    this.field = this.field.capture(context);
    // in case the field was captured, this ensures reference capture takes place
    if (!this.field.setAssigned()) {
        final Marker marker = Markers.semanticError(this.position, "reference.variable.assignment", Util.memberNamed(this.field));
        markers.add(marker);
    }
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker)

Example 32 with Marker

use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.

the class SuperExpr method resolveTypes.

@Override
public void resolveTypes(MarkerList markers, IContext context) {
    if (!context.isThisAvailable()) {
        markers.add(Markers.semantic(this.position, "super.access.static"));
        return;
    }
    if (this.type != Types.UNKNOWN) {
        this.type = this.type.resolveType(markers, context);
        if (this.type.isResolved()) {
            this.checkSuperType(markers, context);
        }
        return;
    }
    final IClass enclosingClass = context.getThisClass();
    final IType superType = enclosingClass.getSuperType();
    if (superType == null) {
        final Marker marker = Markers.semanticError(this.position, "super.access.type");
        marker.addInfo(Markers.getSemantic("type.enclosing", enclosingClass.getClassType()));
        markers.add(marker);
        return;
    }
    this.type = superType;
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 33 with Marker

use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.

the class SuperExpr method checkSuperType.

private void checkSuperType(MarkerList markers, IContext context) {
    final IClass superClass = this.type.getTheClass();
    final IClass enclosingClass = context.getThisClass();
    final IType enclosingType = enclosingClass.getClassType();
    final String message;
    boolean indirectSuperInterface = false;
    if (superClass == enclosingClass) {
        // The specified type is the same as the enclosing type
        message = "super.type.enclosing";
    } else if (!Types.isSuperType(this.type, enclosingType)) {
        message = "super.type.invalid";
    } else {
        // Check if the specified type is either the direct super type or a direct super interface
        final IType superType = enclosingClass.getSuperType();
        if (superType.isSameClass(this.type)) {
            this.type = superType;
            return;
        }
        if (superClass.isInterface()) {
            final TypeList interfaces = enclosingClass.getInterfaces();
            if (interfaces != null) {
                for (int i = 0, count = interfaces.size(); i < count; i++) {
                    final IType interfaceType = interfaces.get(i);
                    if (interfaceType.isSameClass(this.type)) {
                        this.type = interfaceType;
                        return;
                    }
                }
            }
            indirectSuperInterface = true;
        }
        message = "super.type.indirect";
    }
    final Marker marker = Markers.semanticError(this.type.getPosition(), message);
    if (indirectSuperInterface) {
        marker.addInfo(Markers.getSemantic("super.type.interface.info", this.type, enclosingClass.getName()));
    }
    marker.addInfo(Markers.getSemantic("type.enclosing", enclosingType));
    marker.addInfo(Markers.getSemantic("super.type.requested", this.type));
    markers.add(marker);
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker) TypeList(dyvilx.tools.compiler.ast.type.TypeList) IType(dyvilx.tools.compiler.ast.type.IType)

Example 34 with Marker

use of dyvilx.tools.parsing.marker.Marker 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)

Example 35 with Marker

use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.

the class LiteralConversion method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    if (this.method == null) {
        final MatchList<IMethod> candidates = IContext.resolveMethods(type, null, this.name, this.arguments);
        if (candidates.isEmpty()) {
            this.type = type;
            this.reportResolve(markers, candidates);
            return this;
        } else if (candidates.isAmbigous()) {
            this.type = type;
            super.reportResolve(markers, candidates);
            return this;
        }
        return this.checkArguments(markers, context, candidates.getBestMember()).withType(type, typeContext, markers, // will probably recurse
        context);
    }
    final IType thisType = this.getType();
    if (Types.isSuperType(type, thisType)) {
        return this;
    }
    // T! -> T, if necessary
    final IValue value = thisType.convertTo(this, type, typeContext, markers, context);
    if (value != null) {
        return value;
    }
    final Marker marker = Markers.semanticError(this.position, "literal.type.incompatible");
    marker.addInfo(Markers.getSemantic("type.expected", type));
    marker.addInfo(Markers.getSemantic("literal.type.conversion", thisType));
    marker.addInfo(Markers.getSemantic("literal.type.method", Util.methodSignatureToString(this.method, typeContext)));
    markers.add(marker);
    return this;
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

Marker (dyvilx.tools.parsing.marker.Marker)46 IType (dyvilx.tools.compiler.ast.type.IType)23 IClass (dyvilx.tools.compiler.ast.classes.IClass)11 IValue (dyvilx.tools.compiler.ast.expression.IValue)7 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)4 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)4 NonNull (dyvil.annotation.internal.NonNull)3 Name (dyvil.lang.Name)3 MarkerLevel (dyvil.util.MarkerLevel)3 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)3 Pattern (dyvilx.tools.compiler.ast.pattern.Pattern)3 TypeList (dyvilx.tools.compiler.ast.type.TypeList)3 SourcePosition (dyvil.source.position.SourcePosition)2 IContext (dyvilx.tools.compiler.ast.context.IContext)2 ITypeContext (dyvilx.tools.compiler.ast.generic.ITypeContext)2 AbstractPattern (dyvilx.tools.compiler.ast.pattern.AbstractPattern)2 Types (dyvilx.tools.compiler.ast.type.builtin.Types)2 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)2 Markers (dyvilx.tools.compiler.util.Markers)2 MarkerList (dyvilx.tools.parsing.marker.MarkerList)2