Search in sources :

Example 1 with GenericData

use of dyvilx.tools.compiler.ast.generic.GenericData in project Dyvil by Dyvil.

the class AbstractCall method checkArguments.

// every resolveCall implementation calls this
protected final IValue checkArguments(MarkerList markers, IContext context, IMethod method) {
    this.method = method;
    final IntrinsicData intrinsicData = method.getIntrinsicData();
    final int code;
    final IValue intrinsic;
    if (// Intrinsic annotation
    intrinsicData != null && // compilerCode argument
    (code = intrinsicData.getCompilerCode()) != 0 && // valid intrinsic
    (intrinsic = Intrinsics.getOperator(code, this.receiver, this.arguments)) != null) {
        Deprecation.checkAnnotations(method, this.position, markers);
        intrinsic.setPosition(this.position);
        return intrinsic;
    }
    final GenericData genericData;
    if (this.genericData != null) {
        genericData = this.genericData = method.getGenericData(this.genericData, this.receiver, this.arguments);
    } else {
        genericData = this.getGenericData();
    }
    this.receiver = method.checkArguments(markers, this.position, context, this.receiver, this.arguments, genericData);
    this.type = null;
    this.type = this.getType();
    return OptionalChainAware.transform(this);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) IntrinsicData(dyvilx.tools.compiler.ast.method.intrinsic.IntrinsicData) GenericData(dyvilx.tools.compiler.ast.generic.GenericData)

Example 2 with GenericData

use of dyvilx.tools.compiler.ast.generic.GenericData in project Dyvil by Dyvil.

the class AbstractConstructor method checkArguments.

@Override
public IType checkArguments(MarkerList markers, SourcePosition position, IContext context, IType type, ArgumentList arguments) {
    final IClass theClass = this.enclosingClass;
    if (!theClass.isTypeParametric()) {
        for (int i = 0, count = this.parameters.size(); i < count; i++) {
            arguments.checkValue(i, this.parameters.get(i), null, position, markers, context);
        }
        return type;
    }
    final IType classType = theClass.getThisType();
    final GenericData genericData = new GenericData(theClass);
    classType.inferTypes(type, genericData);
    genericData.lockAvailable();
    // Check Values and infer Types
    for (int i = 0, count = this.parameters.size(); i < count; i++) {
        arguments.checkValue(i, this.parameters.get(i), genericData, position, markers, context);
    }
    genericData.lockAvailable();
    // Check Type Var Inference and Compatibility
    final TypeParameterList typeParams = theClass.getTypeParameters();
    for (int i = 0, count = typeParams.size(); i < count; i++) {
        final ITypeParameter typeParameter = typeParams.get(i);
        final IType typeArgument = genericData.resolveType(typeParameter);
        if (typeArgument == null) {
            final IType inferredType = typeParameter.getUpperBound();
            markers.add(Markers.semantic(position, "constructor.typevar.infer", theClass.getName(), typeParameter.getName(), inferredType));
            genericData.addMapping(typeParameter, inferredType);
        } else if (!typeParameter.isAssignableFrom(typeArgument, genericData)) {
            final Marker marker = Markers.semanticError(position, "constructor.typevar.incompatible", theClass.getName(), typeParameter.getName());
            marker.addInfo(Markers.getSemantic("type.generic.argument", typeArgument));
            marker.addInfo(Markers.getSemantic("type_parameter.declaration", typeParameter));
            markers.add(marker);
        }
    }
    return classType.getConcreteType(genericData);
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker) GenericData(dyvilx.tools.compiler.ast.generic.GenericData) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

GenericData (dyvilx.tools.compiler.ast.generic.GenericData)2 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)1 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)1 IntrinsicData (dyvilx.tools.compiler.ast.method.intrinsic.IntrinsicData)1 IType (dyvilx.tools.compiler.ast.type.IType)1 Marker (dyvilx.tools.parsing.marker.Marker)1