Search in sources :

Example 16 with IType

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;
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Example 17 with IType

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;
}
Also used : TypeVarType(dyvilx.tools.compiler.ast.type.typevar.TypeVarType) IType(dyvilx.tools.compiler.ast.type.IType)

Example 18 with IType

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);
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Example 19 with IType

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;
}
Also used : LambdaExpr(dyvilx.tools.compiler.ast.expression.LambdaExpr) IType(dyvilx.tools.compiler.ast.type.IType)

Example 20 with IType

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);
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IType (dyvilx.tools.compiler.ast.type.IType)159 IClass (dyvilx.tools.compiler.ast.classes.IClass)26 Marker (dyvilx.tools.parsing.marker.Marker)23 IValue (dyvilx.tools.compiler.ast.expression.IValue)21 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)13 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)11 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)10 SourcePosition (dyvil.source.position.SourcePosition)9 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)9 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)9 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)9 TypeList (dyvilx.tools.compiler.ast.type.TypeList)7 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)6 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)6 IVariable (dyvilx.tools.compiler.ast.field.IVariable)6 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)6 MethodWriter (dyvilx.tools.compiler.backend.MethodWriter)6 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)5 Name (dyvil.lang.Name)4