use of dyvilx.tools.compiler.ast.generic.TypeParameterList in project Dyvil by Dyvil.
the class ClassGenericType method inferTypes.
@Override
public void inferTypes(IType concrete, ITypeContext typeContext) {
final TypeParameterList classTypeParams = this.getTheClass().getTypeParameters();
for (int i = 0, size = this.arguments.size(); i < size; i++) {
final ITypeParameter typeVar = classTypeParams.get(i);
final IType concreteType = concrete.resolveType(typeVar);
if (concreteType != null) {
this.arguments.get(i).inferTypes(concreteType, typeContext);
}
}
}
use of dyvilx.tools.compiler.ast.generic.TypeParameterList in project Dyvil by Dyvil.
the class TupleExpr method getTypeMatch.
@Override
public int getTypeMatch(IType type, IImplicitContext implicitContext) {
final int arity = this.values.size();
final IClass tupleClass = TupleType.getTupleClass(arity);
if (!Types.isSuperClass(type, tupleClass.getClassType())) {
if (type.getAnnotation(LazyFields.TUPLE_CONVERTIBLE) != null) {
return CONVERSION_MATCH;
}
return MISMATCH;
}
// reset type
this.tupleType = null;
final TypeParameterList typeParameters = typeParameters(tupleClass, arity);
int min = EXACT_MATCH;
for (int i = 0; i < arity; i++) {
final IType elementType = Types.resolveTypeSafely(type, typeParameters.get(i));
final int match = TypeChecker.getTypeMatch(this.values.get(i), elementType, implicitContext);
if (match == MISMATCH) {
return MISMATCH;
}
if (match < min) {
min = match;
}
}
return min;
}
use of dyvilx.tools.compiler.ast.generic.TypeParameterList in project Dyvil by Dyvil.
the class TupleExpr method withType.
@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
final Annotation annotation = type.getAnnotation(LazyFields.TUPLE_CONVERTIBLE);
if (annotation != null) {
return new LiteralConversion(this, annotation, this.values).withType(type, typeContext, markers, context);
}
final int arity = this.values.size();
final IClass tupleClass = TupleType.getTupleClass(arity);
if (!Types.isSuperClass(type, tupleClass.getClassType())) {
return null;
}
// reset type
this.tupleType = null;
final TypeParameterList typeParameters = typeParameters(tupleClass, arity);
for (int i = 0; i < arity; i++) {
final IType elementType = Types.resolveTypeSafely(type, typeParameters.get(i));
final IValue value = TypeChecker.convertValue(this.values.get(i), elementType, typeContext, markers, context, LazyFields.ELEMENT_MARKER_SUPPLIER);
this.values.set(i, value);
}
return this;
}
use of dyvilx.tools.compiler.ast.generic.TypeParameterList 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;
}
Aggregations