use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class AnnotatedType method resolveType.
@Override
public IType resolveType(MarkerList markers, IContext context) {
if (this.type == null) {
markers.add(Markers.semanticError(this.annotation.getPosition(), "type.annotated.invalid"));
this.type = Types.UNKNOWN;
} else {
this.type = this.type.resolveType(markers, context);
}
this.annotation.resolveTypes(markers, context);
if (!this.annotation.getType().isResolved()) {
return this;
}
switch(this.annotation.getTypeDescriptor()) {
case AnnotationUtil.DYVIL_TYPE_INTERNAL:
// @DyvilType annotation
final String desc = this.annotation.getArguments().getFirst().stringValue();
return ClassFormat.extendedToType(desc).resolveType(markers, context);
// duplicate in IType
case AnnotationUtil.NULLABLE_INTERNAL:
if (this.type.useNonNullAnnotation()) {
return NullableType.apply(this.type);
}
}
final IType customType = this.type.withAnnotation(this.annotation);
return customType != null ? customType : this;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class ArrayType method getConcreteType.
@Override
public IType getConcreteType(ITypeContext context) {
IType concrete = this.type.getConcreteType(context);
final TypeVarType typeVar = this.type.extract(TypeVarType.class);
if (typeVar != null && concrete.isPrimitive() && !typeVar.getTypeVariable().isAny()) {
concrete = concrete.getObjectType();
}
if (concrete != null && concrete != this.type) {
return new ArrayType(concrete, this.mutability);
}
return this;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class BinaryType method getConcreteType.
@Override
public IType getConcreteType(ITypeContext context) {
final IType left = this.left.getConcreteType(context);
final IType right = this.right.getConcreteType(context);
if (left == this.left && right == this.right) {
return this;
}
return this.combine(left, right);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class LambdaType method wrapLambda.
public LambdaExpr wrapLambda(IValue value) {
IType returnType = value.getType();
final LambdaExpr lambdaExpr = new LambdaExpr(value.getPosition(), null, 0);
lambdaExpr.setImplicitParameters(true);
lambdaExpr.setMethod(this.getFunctionalMethod());
lambdaExpr.setValue(value);
lambdaExpr.inferReturnType(this, returnType);
return lambdaExpr;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class LambdaType method toString.
@Override
public void toString(String prefix, StringBuilder buffer) {
final IType parameterType;
final int parameterTypeTag;
final int size = this.arguments.size();
if (size == 2 && (parameterTypeTag = (parameterType = this.arguments.get(0)).typeTag()) != TUPLE && parameterTypeTag != LAMBDA && !Formatting.getBoolean("lambda.single.wrap")) {
// Single Parameter Type that is neither a Lambda Type nor a Tuple Type
parameterType.toString(prefix, buffer);
if (Formatting.getBoolean("lambda.arrow.space_before")) {
buffer.append(' ');
}
} else if (size > 1) {
buffer.append('(');
if (Formatting.getBoolean("lambda.open_paren.space_after")) {
buffer.append(' ');
}
Util.astToString(prefix, this.arguments.getTypes(), size - 1, Formatting.getSeparator("lambda.separator", ','), buffer);
if (Formatting.getBoolean("lambda.close_paren.space_before")) {
buffer.append(' ');
}
buffer.append(')');
if (Formatting.getBoolean("lambda.arrow.space_before")) {
buffer.append(' ');
}
} else if (Formatting.getBoolean("lambda.empty.wrap")) {
buffer.append("()");
if (Formatting.getBoolean("lambda.arrow.space_before")) {
buffer.append(' ');
}
}
buffer.append("->");
if (Formatting.getBoolean("lambda.arrow.space_after")) {
buffer.append(' ');
}
this.arguments.get(size - 1).toString("", buffer);
}
Aggregations