use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class CodeMethod method checkDuplicates.
private void checkDuplicates(MarkerList markers) {
final Collection<IMethod> candidates = new ArrayList<>();
this.enclosingClass.addMethods(candidates);
if (candidates.isEmpty()) {
return;
}
final String internalName = this.getInternalName();
final String descriptor = this.getDescriptor();
final int parameterCount = this.parameters.size();
for (IMethod method : candidates) {
if (// exclude this method
method != this && // optimization
method.getParameters().size() == parameterCount && method.getInternalName().equals(internalName) && method.getDescriptor().equals(descriptor)) {
final Marker marker = Markers.semanticError(this.position, "method.duplicate", this.name, this.internalName, descriptor);
markers.add(marker);
}
}
}
use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class CodeMethod method check.
@Override
public void check(MarkerList markers, IContext context) {
context = context.push(this);
super.check(markers, context);
if (this.typeParameters != null) {
this.typeParameters.check(markers, context);
}
if (this.thisType != null) {
this.thisType.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, this);
if (!Types.isSuperType(Types.THROWABLE, exceptionType)) {
Marker marker = Markers.semanticError(exceptionType.getPosition(), "method.exception.type");
marker.addInfo(Markers.getSemantic("exception.type", exceptionType));
markers.add(marker);
}
}
}
if (this.value != null) {
this.value.check(markers, this);
}
ModifierUtil.checkMethodModifiers(markers, this);
context.pop();
}
use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class BindingIfStatement method checkCondition.
@Override
protected void checkCondition(MarkerList markers, IContext context) {
final int size = this.variables.size();
for (int i = 0; i < size; i++) {
final IVariable var = this.variables.get(i);
var.check(markers, this.varContext(i, context));
final IValue value = getOptionalValue(var);
final IType type = value.getType();
if (value.isResolved() && type.isResolved() && !NullableType.isNullable(type)) {
final Marker marker = Markers.semanticError(value.getPosition(), "if.binding.nonnull");
marker.addInfo(Markers.getSemantic("value.type", type));
markers.add(marker);
}
}
super.checkCondition(markers, this.varContext(size, context));
}
use of dyvilx.tools.parsing.marker.Marker in project Dyvil by Dyvil.
the class IStatement method checkStatement.
static IValue checkStatement(MarkerList markers, IContext context, IValue resolvedValue, String key) {
final IValue typedValue = resolvedValue.withType(Types.VOID, Types.VOID, markers, context);
if (typedValue != null && typedValue.isUsableAsStatement()) {
return typedValue;
}
// Create an error
final Marker marker = Markers.semantic(resolvedValue.getPosition(), key);
marker.addInfo(Markers.getSemantic("expression.type", resolvedValue.getType()));
markers.add(marker);
return resolvedValue;
}
use of dyvilx.tools.parsing.marker.Marker 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