Search in sources :

Example 6 with TupleType

use of dyvilx.tools.compiler.ast.type.compound.TupleType 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)

Aggregations

TupleType (dyvilx.tools.compiler.ast.type.compound.TupleType)6 TypeList (dyvilx.tools.compiler.ast.type.TypeList)5 IType (dyvilx.tools.compiler.ast.type.IType)2 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)1 AbstractPattern (dyvilx.tools.compiler.ast.pattern.AbstractPattern)1 Pattern (dyvilx.tools.compiler.ast.pattern.Pattern)1 ReferenceType (dyvilx.tools.compiler.ast.reference.ReferenceType)1 LambdaType (dyvilx.tools.compiler.ast.type.compound.LambdaType)1 Marker (dyvilx.tools.parsing.marker.Marker)1