Search in sources :

Example 41 with Marker

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

the class UnapplyPattern method withMethod.

protected boolean withMethod(IType matchedType, IValue methodCall, MarkerList markers) {
    final IType type = NullableType.unapply(methodCall.getType());
    final String className = type.getInternalName();
    if (// return type must be a tuple type
    !className.startsWith("dyvil/tuple/Tuple$Of")) {
        return false;
    }
    final TupleType tupleType = type.extract(TupleType.class);
    final TypeList typeArguments = tupleType.getArguments();
    if (this.patternCount != typeArguments.size()) {
        final Marker marker = Markers.semanticError(this.position, "pattern.unapply.count", this.type.toString());
        marker.addInfo(Markers.getSemantic("pattern.unapply.count.pattern", this.patternCount));
        marker.addInfo(Markers.getSemantic("pattern.unapply.count.class", typeArguments.size()));
        markers.add(marker);
        return true;
    }
    this.unapplyCall = methodCall;
    for (int i = 0; i < this.patternCount; i++) {
        final IType subType = typeArguments.get(i);
        final Pattern pattern = this.patterns[i];
        final Pattern typedPattern = pattern.withType(subType, markers);
        if (typedPattern == null) {
            final Marker marker = Markers.semanticError(this.position, "pattern.unapply.type");
            marker.addInfo(Markers.getSemantic("pattern.type", pattern.getType()));
            marker.addInfo(Markers.getSemantic("classparameter.type", subType));
            markers.add(marker);
        } else {
            this.patterns[i] = typedPattern;
        }
    }
    this.switchValue = getSwitchValue(matchedType, this.type);
    return true;
}
Also used : AbstractPattern(dyvilx.tools.compiler.ast.pattern.AbstractPattern) Pattern(dyvilx.tools.compiler.ast.pattern.Pattern) TupleType(dyvilx.tools.compiler.ast.type.compound.TupleType) Marker(dyvilx.tools.parsing.marker.Marker) TypeList(dyvilx.tools.compiler.ast.type.TypeList) IType(dyvilx.tools.compiler.ast.type.IType)

Example 42 with Marker

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

the class ArgumentList method resolveMissing.

protected void resolveMissing(IParameter param, GenericData genericData, SourcePosition position, MarkerList markers, IContext context) {
    if (this == EMPTY) {
        // cannot infer missing arguments if the argument list is EMPTY (i.e. not denoted)
        final Marker marker = Markers.semanticError(position, "method.access.argument.empty", param.getName());
        marker.addInfo(Markers.getSemantic("method.access.argument.empty.info"));
        markers.add(marker);
        return;
    }
    if (param.isVarargs()) {
        // varargs parameter
        final IValue value = convertValue(new ArrayExpr(position, EMPTY), param, genericData, markers, context);
        this.add(param.getLabel(), value);
        return;
    }
    if (!param.isImplicit()) {
        if (this.resolveDefault(param, context)) {
            return;
        }
        markers.add(Markers.semanticError(position, "method.access.argument.missing", param.getName()));
        return;
    }
    // implicit parameter, possibly default
    final IType type;
    if (genericData != null) {
        genericData.lockAvailable();
        type = param.getCovariantType().getConcreteType(genericData);
    } else {
        type = param.getCovariantType();
    }
    final IValue implicit = context.resolveImplicit(type);
    if (implicit != null) {
        // make sure to resolve and type-check the implicit value
        // (implicit values should be only field accesses, but might need some capture or "this<Outer" resolution)
        final IValue value = convertValue(implicit.resolve(markers, context), param, genericData, markers, context);
        this.add(param.getLabel(), value);
        return;
    }
    // default resolution only if implicit resolution fails
    if (this.resolveDefault(param, context)) {
        return;
    }
    markers.add(Markers.semanticError(position, "method.access.argument.implicit", param.getName(), type));
    return;
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) IValue(dyvilx.tools.compiler.ast.expression.IValue) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 43 with Marker

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

the class HeaderDeclaration method check.

public void check(MarkerList markers) {
    Name headerName = this.header.getName();
    if (headerName != this.name) {
        Marker m = Markers.semantic(this.position, "header.name.mismatch");
        m.addInfo(Markers.getSemantic("header.name", headerName));
        m.addInfo(Markers.getSemantic("header.declaration.name", this.name));
        markers.add(m);
    }
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) Name(dyvil.lang.Name)

Example 44 with Marker

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

the class ForEachStatement method toIteratorLoop.

@NonNull
public IValue toIteratorLoop(MarkerList markers, IContext context, IType varType, IValue value, IType valueType) {
    final IType iteratorType = Types.resolveTypeSafely(valueType, IterableForStatement.LazyFields.ITERATOR_TYPE);
    if (varType == Types.UNKNOWN) {
        this.inferVariableType(markers, iteratorType);
    } else if (!Types.isAssignable(varType, iteratorType)) {
        final Marker marker = Markers.semanticError(value.getPosition(), "for.iterator.type");
        marker.addInfo(Markers.getSemantic("iterator.type", iteratorType));
        marker.addInfo(Markers.getSemantic("variable.type", varType));
        markers.add(marker);
    }
    this.variable.setValue(TypeChecker.convertValue(value, IterableForStatement.LazyFields.ITERATOR, null, markers, context, null));
    final IterableForStatement iterableForStatement = new IterableForStatement(this.position, this.variable, true);
    iterableForStatement.resolveAction(this.action, markers, context);
    return iterableForStatement;
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType) NonNull(dyvil.annotation.internal.NonNull)

Example 45 with Marker

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

the class ForEachStatement method toIterable.

@NonNull
public IValue toIterable(MarkerList markers, IContext context, IType varType, IValue value, IType valueType) {
    final IType iterableType = Types.resolveTypeSafely(valueType, IterableForStatement.LazyFields.ITERABLE_TYPE);
    if (varType == Types.UNKNOWN) {
        this.inferVariableType(markers, iterableType);
    } else if (!Types.isAssignable(varType, iterableType)) {
        final Marker marker = Markers.semanticError(value.getPosition(), "for.iterable.type");
        marker.addInfo(Markers.getSemantic("iterable.type", iterableType));
        marker.addInfo(Markers.getSemantic("variable.type", varType));
        markers.add(marker);
    }
    this.variable.setValue(TypeChecker.convertValue(value, IterableForStatement.LazyFields.ITERABLE, null, markers, context, null));
    final IterableForStatement iterableForStatement = new IterableForStatement(this.position, this.variable, false);
    iterableForStatement.resolveAction(this.action, markers, context);
    return iterableForStatement;
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType) NonNull(dyvil.annotation.internal.NonNull)

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