use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class NamedGenericType method checkCount.
private IType checkCount(MarkerList markers, ITypeParametric generic, String kind, IType type) {
final int genericArity = generic.typeArity();
if (genericArity <= 0) {
markers.add(Markers.semanticError(this.position, "type.generic." + kind + ".not_generic", type));
return type.atPosition(this.position);
}
if (genericArity != this.arguments.size()) {
final Marker marker = Markers.semanticError(this.position, "type.generic." + kind + ".count_mismatch", type);
marker.addInfo(Markers.getSemantic("type.generic.argument_count", this.arguments.size()));
marker.addInfo(Markers.getSemantic("type.generic.parameter_count", genericArity));
markers.add(marker);
}
return type.getConcreteType(typeParameter -> this.arguments.get(typeParameter.getIndex())).atPosition(this.position);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class NamedGenericType method resolveWithParent.
private IType resolveWithParent(MarkerList markers) {
final IClass theClass = this.parent.resolveClass(this.name);
if (theClass != null) {
final IType classType = theClass.getThisType();
return this.checkCount(markers, theClass, "class", classType);
}
final Package thePackage = this.parent.resolvePackage(this.name);
if (thePackage != null) {
markers.add(Markers.semanticError(this.position, "type.generic.package.not_generic", thePackage.getName()));
return new PackageType(thePackage).atPosition(this.position);
}
markers.add(Markers.semanticError(this.position, "resolve.type.package", this.name, this.parent));
return this;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class NamedGenericType method resolveTopLevelWith.
private IType resolveTopLevelWith(MarkerList markers, IContext context) {
final MatchList<ITypeAlias> typeAliases = IContext.resolveTypeAlias(context, null, this.name, this.arguments);
if (typeAliases.hasCandidate()) {
final ITypeAlias typeAlias = typeAliases.getBestMember();
final IType aliasType = typeAlias.getType();
if (!aliasType.isResolved()) {
markers.add(Markers.semanticError(this.position, "type.alias.unresolved", this.name));
return aliasType.atPosition(this.position);
}
return this.checkCount(markers, typeAlias, "type_alias", aliasType);
}
final IClass theClass = context.resolveClass(this.name);
if (theClass != null) {
final IType classType = theClass.getThisType();
return this.checkCount(markers, theClass, "class", classType);
}
final ITypeParameter typeParameter = context.resolveTypeParameter(this.name);
if (typeParameter != null) {
markers.add(Markers.semanticError(this.position, "type.generic.type_parameter.not_generic", typeParameter.getName()));
return new ResolvedTypeVarType(typeParameter, this.position);
}
final Package thePackage = context.resolvePackage(this.name);
if (thePackage != null) {
markers.add(Markers.semanticError(this.position, "type.generic.package.not_generic", thePackage.getName()));
return new PackageType(thePackage).atPosition(this.position);
}
return null;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class PostfixType method resolveType.
@Override
public IType resolveType(MarkerList markers, IContext context) {
final String unqualified = this.name.unqualified;
final IType argument = this.arguments.get(0);
if (unqualified.length() == 1) {
switch(unqualified.charAt(0)) {
case '?':
return NullableType.apply(argument).resolveType(markers, context);
case '!':
return new ImplicitNullableType(argument).resolveType(markers, context);
case '*':
return new ReferenceType(argument).resolveType(markers, context);
case '^':
return new ImplicitReferenceType(argument).resolveType(markers, context);
}
}
return super.resolveType(markers, context);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class CatchBlock method check.
@Override
public void check(MarkerList markers, IContext context) {
this.variable.check(markers, context);
final IType type = this.variable.getType();
if (!Types.isSuperType(Types.THROWABLE, type)) {
final Marker marker = Markers.semanticError(this.variable.getPosition(), "try.catch.type.not_throwable");
marker.addInfo(Markers.getSemantic("exception.type", type));
markers.add(marker);
}
context = context.push(this);
this.action.check(markers, context);
context.pop();
}
Aggregations