Search in sources :

Example 61 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class AbstractConstructor method checkMatch.

@Override
public void checkMatch(MatchList<IConstructor> list, ArgumentList arguments) {
    final int parameterCount = this.parameters.size();
    if (arguments == null) {
        list.add(new Candidate<>(this));
        return;
    }
    final int argumentCount = arguments.size();
    if (argumentCount > parameterCount && !this.isVariadic()) {
        return;
    }
    final int[] matchValues = new int[argumentCount];
    final IType[] matchTypes = new IType[argumentCount];
    int defaults = 0;
    int varargs = 0;
    for (int i = 0; i < parameterCount; i++) {
        final IParameter parameter = this.parameters.get(i);
        final int partialVarargs = arguments.checkMatch(matchValues, matchTypes, 0, i, parameter, list);
        switch(partialVarargs) {
            case ArgumentList.MISMATCH:
                return;
            case ArgumentList.DEFAULT:
                defaults++;
                continue;
            default:
                varargs += partialVarargs;
        }
    }
    for (int matchValue : matchValues) {
        if (matchValue == IValue.MISMATCH) {
            return;
        }
    }
    list.add(new Candidate<>(this, matchValues, matchTypes, defaults, varargs));
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IType(dyvilx.tools.compiler.ast.type.IType)

Example 62 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class CodeConstructor method resolveInitCall.

private void resolveInitCall(MarkerList markers, IContext context) {
    if (this.initializerCall != null) {
        this.initializerCall.resolve(markers, context);
        return;
    }
    // No Super Type -> don't try to resolve a Super Constructor
    final IType superType = this.enclosingClass.getSuperType();
    if (superType == null) {
        return;
    }
    // Implicit Super Constructor
    final IConstructor match = IContext.resolveConstructor(context, superType, ArgumentList.EMPTY);
    if (match == null) {
        markers.add(Markers.semanticError(this.position, "constructor.super"));
        return;
    }
    this.initializerCall = new InitializerCall(this.position, true, ArgumentList.EMPTY, superType, match);
}
Also used : InitializerCall(dyvilx.tools.compiler.ast.expression.access.InitializerCall) IType(dyvilx.tools.compiler.ast.type.IType)

Example 63 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class CodeConstructor method check.

@Override
public void check(MarkerList markers, IContext context) {
    context = context.push(this);
    super.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, context);
            if (!Types.isSuperType(Types.THROWABLE, exceptionType)) {
                final Marker marker = Markers.semanticError(exceptionType.getPosition(), "method.exception.type");
                marker.addInfo(Markers.getSemantic("exception.type", exceptionType));
                markers.add(marker);
            }
        }
    }
    if (this.initializerCall != null) {
        this.initializerCall.check(markers, context);
    }
    if (this.value != null) {
        this.value.check(markers, this);
    } else if (this.initializerCall == null) {
        markers.add(Markers.semanticError(this.position, "constructor.abstract"));
    }
    if (this.isStatic()) {
        markers.add(Markers.semanticError(this.position, "constructor.static", this.name));
    }
    context.pop();
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 64 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class AttributeList method resolveTypes.

// Phases
public void resolveTypes(MarkerList markers, IContext context, Attributable annotated) {
    for (int i = 0; i < this.size; i++) {
        final Attribute attribute = this.data[i];
        attribute.resolveTypes(markers, context);
        final IType type = attribute.getType();
        if (type != null) {
            final String internalName = type.getInternalName();
            if (internalName != null && annotated.skipAnnotation(internalName, (Annotation) attribute)) {
                this.removeAt(i--);
            }
        }
    }
}
Also used : Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) IType(dyvilx.tools.compiler.ast.type.IType)

Example 65 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class Annotation method resolve.

@Override
public void resolve(MarkerList markers, IContext context) {
    this.arguments.resolve(markers, context);
    final IClass theClass;
    if (this.type == null || (theClass = this.type.getTheClass()) == null) {
        return;
    }
    final ParameterList parameterList = theClass.getParameters();
    for (int i = 0, count = parameterList.size(); i < count; i++) {
        final IParameter parameter = parameterList.get(i);
        final IType parameterType = parameter.getType();
        final IValue value = this.arguments.get(parameter);
        if (value == null) {
            if (parameter.getValue() == null) {
                markers.add(Markers.semanticError(this.getPosition(), "annotation.parameter.missing", this.type, parameter.getName()));
            }
            continue;
        }
        IValue typedValue = value.withType(parameterType, parameterType, markers, context);
        if (typedValue == null) {
            markers.add(TypeChecker.typeError(value, parameterType, parameterType, "annotation.parameter.type", parameter.getName()));
            continue;
        }
        typedValue = IValue.toAnnotationConstant(typedValue, markers, context);
        if (typedValue != value) {
            this.arguments.set(i, parameter.getLabel(), typedValue);
        }
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IType (dyvilx.tools.compiler.ast.type.IType)159 IClass (dyvilx.tools.compiler.ast.classes.IClass)26 Marker (dyvilx.tools.parsing.marker.Marker)23 IValue (dyvilx.tools.compiler.ast.expression.IValue)21 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)13 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)11 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)10 SourcePosition (dyvil.source.position.SourcePosition)9 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)9 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)9 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)9 TypeList (dyvilx.tools.compiler.ast.type.TypeList)7 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)6 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)6 IVariable (dyvilx.tools.compiler.ast.field.IVariable)6 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)6 MethodWriter (dyvilx.tools.compiler.backend.MethodWriter)6 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)5 Name (dyvil.lang.Name)4