use of dyvilx.tools.parsing.marker.Marker 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;
}
use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class ArgumentList method resolveMissing.
protected void resolveMissing(IParameter param, GenericData genericData, SourcePosition position, MarkerList markers, IContext context) {
if (this == EMPTY) {
// cannot infer missing arguments if the argument list is EMPTY (i.e. not denoted)
final Marker marker = Markers.semanticError(position, "method.access.argument.empty", param.getName());
marker.addInfo(Markers.getSemantic("method.access.argument.empty.info"));
markers.add(marker);
return;
}
if (param.isVarargs()) {
// varargs parameter
final IValue value = convertValue(new ArrayExpr(position, EMPTY), param, genericData, markers, context);
this.add(param.getLabel(), value);
return;
}
if (!param.isImplicit()) {
if (this.resolveDefault(param, context)) {
return;
}
markers.add(Markers.semanticError(position, "method.access.argument.missing", param.getName()));
return;
}
// implicit parameter, possibly default
final IType type;
if (genericData != null) {
genericData.lockAvailable();
type = param.getCovariantType().getConcreteType(genericData);
} else {
type = param.getCovariantType();
}
final IValue implicit = context.resolveImplicit(type);
if (implicit != null) {
// make sure to resolve and type-check the implicit value
// (implicit values should be only field accesses, but might need some capture or "this<Outer" resolution)
final IValue value = convertValue(implicit.resolve(markers, context), param, genericData, markers, context);
this.add(param.getLabel(), value);
return;
}
// default resolution only if implicit resolution fails
if (this.resolveDefault(param, context)) {
return;
}
markers.add(Markers.semanticError(position, "method.access.argument.implicit", param.getName(), type));
return;
}
use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class HeaderDeclaration method check.
public void check(MarkerList markers) {
Name headerName = this.header.getName();
if (headerName != this.name) {
Marker m = Markers.semantic(this.position, "header.name.mismatch");
m.addInfo(Markers.getSemantic("header.name", headerName));
m.addInfo(Markers.getSemantic("header.declaration.name", this.name));
markers.add(m);
}
}
use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class ForEachStatement method toIteratorLoop.
@NonNull
public IValue toIteratorLoop(MarkerList markers, IContext context, IType varType, IValue value, IType valueType) {
final IType iteratorType = Types.resolveTypeSafely(valueType, IterableForStatement.LazyFields.ITERATOR_TYPE);
if (varType == Types.UNKNOWN) {
this.inferVariableType(markers, iteratorType);
} else if (!Types.isAssignable(varType, iteratorType)) {
final Marker marker = Markers.semanticError(value.getPosition(), "for.iterator.type");
marker.addInfo(Markers.getSemantic("iterator.type", iteratorType));
marker.addInfo(Markers.getSemantic("variable.type", varType));
markers.add(marker);
}
this.variable.setValue(TypeChecker.convertValue(value, IterableForStatement.LazyFields.ITERATOR, null, markers, context, null));
final IterableForStatement iterableForStatement = new IterableForStatement(this.position, this.variable, true);
iterableForStatement.resolveAction(this.action, markers, context);
return iterableForStatement;
}
use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class ForEachStatement method toIterable.
@NonNull
public IValue toIterable(MarkerList markers, IContext context, IType varType, IValue value, IType valueType) {
final IType iterableType = Types.resolveTypeSafely(valueType, IterableForStatement.LazyFields.ITERABLE_TYPE);
if (varType == Types.UNKNOWN) {
this.inferVariableType(markers, iterableType);
} else if (!Types.isAssignable(varType, iterableType)) {
final Marker marker = Markers.semanticError(value.getPosition(), "for.iterable.type");
marker.addInfo(Markers.getSemantic("iterable.type", iterableType));
marker.addInfo(Markers.getSemantic("variable.type", varType));
markers.add(marker);
}
this.variable.setValue(TypeChecker.convertValue(value, IterableForStatement.LazyFields.ITERABLE, null, markers, context, null));
final IterableForStatement iterableForStatement = new IterableForStatement(this.position, this.variable, false);
iterableForStatement.resolveAction(this.action, markers, context);
return iterableForStatement;
}
Aggregations