Search in sources :

Example 1 with Marker

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

the class NamedGenericType method checkCount.

private IType checkCount(MarkerList markers, ITypeParametric generic, String kind, IType type) {
    final int genericArity = generic.typeArity();
    if (genericArity <= 0) {
        markers.add(Markers.semanticError(this.position, "type.generic." + kind + ".not_generic", type));
        return type.atPosition(this.position);
    }
    if (genericArity != this.arguments.size()) {
        final Marker marker = Markers.semanticError(this.position, "type.generic." + kind + ".count_mismatch", type);
        marker.addInfo(Markers.getSemantic("type.generic.argument_count", this.arguments.size()));
        marker.addInfo(Markers.getSemantic("type.generic.parameter_count", genericArity));
        markers.add(marker);
    }
    return type.getConcreteType(typeParameter -> this.arguments.get(typeParameter.getIndex())).atPosition(this.position);
}
Also used : DataOutput(java.io.DataOutput) IContext(dyvilx.tools.compiler.ast.context.IContext) Package(dyvilx.tools.compiler.ast.structure.Package) Name(dyvil.lang.Name) ResolvedTypeVarType(dyvilx.tools.compiler.ast.type.typevar.ResolvedTypeVarType) IType(dyvilx.tools.compiler.ast.type.IType) IOException(java.io.IOException) Types(dyvilx.tools.compiler.ast.type.builtin.Types) PackageType(dyvilx.tools.compiler.ast.type.raw.PackageType) Marker(dyvilx.tools.parsing.marker.Marker) ITypeAlias(dyvilx.tools.compiler.ast.type.alias.ITypeAlias) ITypeParametric(dyvilx.tools.compiler.ast.generic.ITypeParametric) Markers(dyvilx.tools.compiler.util.Markers) SourcePosition(dyvil.source.position.SourcePosition) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) TypeList(dyvilx.tools.compiler.ast.type.TypeList) MarkerList(dyvilx.tools.parsing.marker.MarkerList) DataInput(java.io.DataInput) MatchList(dyvilx.tools.compiler.ast.method.MatchList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IUnresolvedType(dyvilx.tools.compiler.ast.type.raw.IUnresolvedType) Marker(dyvilx.tools.parsing.marker.Marker)

Example 2 with Marker

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

the class CatchBlock method check.

@Override
public void check(MarkerList markers, IContext context) {
    this.variable.check(markers, context);
    final IType type = this.variable.getType();
    if (!Types.isSuperType(Types.THROWABLE, type)) {
        final Marker marker = Markers.semanticError(this.variable.getPosition(), "try.catch.type.not_throwable");
        marker.addInfo(Markers.getSemantic("exception.type", type));
        markers.add(marker);
    }
    context = context.push(this);
    this.action.check(markers, context);
    context.pop();
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 3 with Marker

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

the class ForEachStatement method resolve.

@Override
public IValue resolve(MarkerList markers, IContext context) {
    IType varType = this.variable.getType();
    final IValue value = this.resolveValue(markers, context);
    final IType valueType = value.getType();
    if (value.valueTag() == IValue.METHOD_CALL) {
        final MethodCall rangeOperator = (MethodCall) value;
        if (RangeForStatement.isRangeOperator(rangeOperator)) {
            final IType elementType = RangeForStatement.getElementType(rangeOperator);
            if (varType == Types.UNKNOWN) {
                this.inferVariableType(markers, elementType);
            } else if (!Types.isAssignable(varType, elementType)) {
                final Marker marker = Markers.semanticError(value.getPosition(), "for.range.type");
                marker.addInfo(Markers.getSemantic("range.type", valueType));
                marker.addInfo(Markers.getSemantic("variable.type", varType));
                markers.add(marker);
            }
            final RangeForStatement rangeForStatement = new RangeForStatement(this.position, this.variable, elementType);
            rangeForStatement.resolveAction(this.action, markers, context);
            return rangeForStatement;
        }
    }
    final ArrayType arrayType = valueType.extract(ArrayType.class);
    if (arrayType != null) {
        if (varType == Types.UNKNOWN) {
            this.inferVariableType(markers, arrayType.getElementType());
        } else if (!Types.isAssignable(varType, arrayType.getElementType())) {
            final Marker marker = Markers.semanticError(value.getPosition(), "for.array.type");
            marker.addInfo(Markers.getSemantic("array.type", valueType));
            marker.addInfo(Markers.getSemantic("variable.type", varType));
            markers.add(marker);
        }
        final ArrayForStatement arrayForStatement = new ArrayForStatement(this.position, this.variable, arrayType);
        arrayForStatement.resolveAction(this.action, markers, context);
        return arrayForStatement;
    }
    if (Types.isAssignable(IterableForStatement.LazyFields.ITERATOR, valueType)) {
        return this.toIteratorLoop(markers, context, varType, value, valueType);
    }
    if (Types.isAssignable(IterableForStatement.LazyFields.ITERABLE, valueType)) {
        return this.toIterable(markers, context, varType, value, valueType);
    }
    if (Types.isAssignable(Types.STRING, valueType)) {
        return this.toStringLoop(markers, context, varType, value);
    }
    final Marker marker = Markers.semanticError(this.variable.getPosition(), "for.each.invalid");
    marker.addInfo(Markers.getSemantic("value.type", valueType));
    markers.add(marker);
    this.resolveAction(this.action, markers, context);
    return this;
}
Also used : ArrayType(dyvilx.tools.compiler.ast.type.compound.ArrayType) IValue(dyvilx.tools.compiler.ast.expression.IValue) Marker(dyvilx.tools.parsing.marker.Marker) MethodCall(dyvilx.tools.compiler.ast.expression.access.MethodCall) IType(dyvilx.tools.compiler.ast.type.IType)

Example 4 with Marker

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

the class ResolvedGenericType method checkType.

@Override
public void checkType(MarkerList markers, IContext context, int position) {
    ModifierUtil.checkVisibility(this.theClass, this.position, markers, context);
    // Check if the Type Variable Bounds accept the supplied Type Arguments
    final int count = Math.min(this.arguments.size(), this.theClass.typeArity());
    final TypeParameterList classTypeParams = this.theClass.getTypeParameters();
    for (int i = 0; i < count; i++) {
        final ITypeParameter typeParameter = classTypeParams.get(i);
        final IType typeArgument = this.resolveType(typeParameter);
        if (typeArgument.isResolved() && !typeParameter.isAssignableFrom(typeArgument, null)) {
            final Marker marker = Markers.semanticError(typeArgument.getPosition(), "type.generic.incompatible", typeParameter.getName().qualified, this.theClass.getFullName());
            marker.addInfo(Markers.getSemantic("type.generic.argument", typeArgument));
            marker.addInfo(Markers.getSemantic("type_parameter.declaration", typeParameter));
            markers.add(marker);
        }
    }
    if ((position & TypePosition.GENERIC_FLAG) == 0) {
        markers.add(Markers.semanticError(this.position, "type.generic.class"));
    }
    super.checkType(markers, context, position);
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 5 with Marker

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

the class IValue method toAnnotationConstant.

static IValue toAnnotationConstant(IValue value, MarkerList markers, IContext context) {
    final int depth = context.getCompilationContext().config.getMaxConstantDepth();
    final IValue constant = value.toAnnotationConstant(markers, context, depth);
    if (constant != null) {
        return constant;
    }
    final Marker marker = value.getAnnotationError();
    marker.addInfo(Markers.getSemantic("value.constant.depth", depth));
    markers.add(marker);
    return value;
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker)

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