Search in sources :

Example 36 with Marker

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

the class CodeMethod method checkDuplicates.

private void checkDuplicates(MarkerList markers) {
    final Collection<IMethod> candidates = new ArrayList<>();
    this.enclosingClass.addMethods(candidates);
    if (candidates.isEmpty()) {
        return;
    }
    final String internalName = this.getInternalName();
    final String descriptor = this.getDescriptor();
    final int parameterCount = this.parameters.size();
    for (IMethod method : candidates) {
        if (// exclude this method
        method != this && // optimization
        method.getParameters().size() == parameterCount && method.getInternalName().equals(internalName) && method.getDescriptor().equals(descriptor)) {
            final Marker marker = Markers.semanticError(this.position, "method.duplicate", this.name, this.internalName, descriptor);
            markers.add(marker);
        }
    }
}
Also used : ArrayList(dyvil.collection.mutable.ArrayList) Marker(dyvilx.tools.parsing.marker.Marker)

Example 37 with Marker

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

the class CodeMethod method check.

@Override
public void check(MarkerList markers, IContext context) {
    context = context.push(this);
    super.check(markers, context);
    if (this.typeParameters != null) {
        this.typeParameters.check(markers, context);
    }
    if (this.thisType != null) {
        this.thisType.check(markers, context);
    }
    this.parameters.check(markers, context);
    if (this.exceptions != null) {
        for (int i = 0; i < this.exceptions.size(); i++) {
            final IType exceptionType = this.exceptions.get(i);
            exceptionType.check(markers, this);
            if (!Types.isSuperType(Types.THROWABLE, exceptionType)) {
                Marker marker = Markers.semanticError(exceptionType.getPosition(), "method.exception.type");
                marker.addInfo(Markers.getSemantic("exception.type", exceptionType));
                markers.add(marker);
            }
        }
    }
    if (this.value != null) {
        this.value.check(markers, this);
    }
    ModifierUtil.checkMethodModifiers(markers, this);
    context.pop();
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 38 with Marker

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

the class BindingIfStatement method checkCondition.

@Override
protected void checkCondition(MarkerList markers, IContext context) {
    final int size = this.variables.size();
    for (int i = 0; i < size; i++) {
        final IVariable var = this.variables.get(i);
        var.check(markers, this.varContext(i, context));
        final IValue value = getOptionalValue(var);
        final IType type = value.getType();
        if (value.isResolved() && type.isResolved() && !NullableType.isNullable(type)) {
            final Marker marker = Markers.semanticError(value.getPosition(), "if.binding.nonnull");
            marker.addInfo(Markers.getSemantic("value.type", type));
            markers.add(marker);
        }
    }
    super.checkCondition(markers, this.varContext(size, context));
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) IVariable(dyvilx.tools.compiler.ast.field.IVariable) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 39 with Marker

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

the class IStatement method checkStatement.

static IValue checkStatement(MarkerList markers, IContext context, IValue resolvedValue, String key) {
    final IValue typedValue = resolvedValue.withType(Types.VOID, Types.VOID, markers, context);
    if (typedValue != null && typedValue.isUsableAsStatement()) {
        return typedValue;
    }
    // Create an error
    final Marker marker = Markers.semantic(resolvedValue.getPosition(), key);
    marker.addInfo(Markers.getSemantic("expression.type", resolvedValue.getType()));
    markers.add(marker);
    return resolvedValue;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) Marker(dyvilx.tools.parsing.marker.Marker)

Example 40 with Marker

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

the class TupleSurrogate method withType.

@Override
public Pattern withType(IType type, MarkerList markers) {
    final IClass tupleClass = TupleType.getTupleClass(this.patternCount);
    if (tupleClass == null) {
        return null;
    }
    final IType tupleType = tupleClass.getClassType();
    if (!Types.isSuperClass(type, tupleType)) {
        return null;
    }
    // reset type to recompute it later
    this.tupleType = null;
    final TypeParameterList typeParameters = tupleClass.getTypeParameters();
    for (int i = 0; i < this.patternCount; i++) {
        final IType elementType = Types.resolveTypeSafely(type, typeParameters.get(i));
        final Pattern pattern = this.patterns[i];
        final Pattern typedPattern = pattern.withType(elementType, markers);
        if (typedPattern == null) {
            final Marker marker = Markers.semanticError(pattern.getPosition(), "pattern.tuple.element.type");
            marker.addInfo(Markers.getSemantic("pattern.type", pattern.getType()));
            marker.addInfo(Markers.getSemantic("tuple.element.type", elementType));
            markers.add(marker);
        } else {
            this.patterns[i] = typedPattern;
        }
    }
    if (!Types.isSuperClass(tupleType, type)) {
        return new TypeCheckPattern(this, type, tupleType);
    }
    return this;
}
Also used : TypeCheckPattern(dyvilx.tools.compiler.ast.pattern.TypeCheckPattern) AbstractPattern(dyvilx.tools.compiler.ast.pattern.AbstractPattern) TypeCheckPattern(dyvilx.tools.compiler.ast.pattern.TypeCheckPattern) Pattern(dyvilx.tools.compiler.ast.pattern.Pattern) TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) 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