Search in sources :

Example 11 with Annotation

use of dyvilx.tools.compiler.ast.attribute.annotation.Annotation in project Dyvil by Dyvil.

the class TypeParameter method computeReifiedKind.

protected void computeReifiedKind() {
    if (this.reifiedKind != null) {
        return;
    }
    final Annotation reifiedAnnotation = this.getAnnotation(Types.REIFIED_CLASS);
    if (reifiedAnnotation != null) {
        final IParameter parameter = Types.REIFIED_CLASS.getParameters().get(0);
        this.reifiedKind = AnnotationUtil.getEnumValue(reifiedAnnotation.getArguments(), parameter, Reified.Type.class);
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) CovariantTypeVarType(dyvilx.tools.compiler.ast.type.typevar.CovariantTypeVarType) IType(dyvilx.tools.compiler.ast.type.IType) Types.isSuperType(dyvilx.tools.compiler.ast.type.builtin.Types.isSuperType) IntersectionType(dyvilx.tools.compiler.ast.type.compound.IntersectionType) ElementType(java.lang.annotation.ElementType) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation)

Example 12 with Annotation

use of dyvilx.tools.compiler.ast.attribute.annotation.Annotation in project Dyvil by Dyvil.

the class ArrayExpr method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    final IType elementType;
    final Mutability mutability;
    final ArrayType arrayType = type.extract(ArrayType.class);
    if (arrayType == null) {
        final Annotation annotation;
        if ((annotation = type.getAnnotation(LazyFields.ARRAY_CONVERTIBLE)) != null) {
            return new LiteralConversion(this, annotation, this.values).withType(type, typeContext, markers, context);
        }
        if (type.getTheClass() != Types.OBJECT_CLASS) {
            return null;
        }
        // Compute element type from scratch
        elementType = this.getElementType();
        mutability = Mutability.IMMUTABLE;
    } else {
        // If the type is an array type, get it's element type
        elementType = arrayType.getElementType();
        mutability = type.getMutability();
    }
    final int size = this.values.size();
    if (size == 0) {
        this.elementType = elementType.getConcreteType(ITypeContext.DEFAULT);
        this.arrayType = new ArrayType(this.elementType, mutability);
        return this;
    }
    for (int i = 0; i < size; i++) {
        final IValue value = TypeChecker.convertValue(this.values.get(i), elementType, typeContext, markers, context, LazyFields.ELEMENT_MARKER_SUPPLIER);
        this.values.set(i, value);
    }
    this.elementType = null;
    final int typecode = elementType.getTypecode();
    if (typecode < 0) {
        // local element type is an object type, so we infer the reference version of the computed element type
        this.elementType = this.getElementType().getObjectType();
    } else if (typecode != this.getElementType().getTypecode()) {
        // local element type is a primitive type, but a different one from the computed element type,
        // so we infer the local one
        this.elementType = elementType;
    }
    // else: the above call to this.getElementType() has set this.elementType already
    this.arrayType = new ArrayType(this.elementType, mutability);
    return this;
}
Also used : ArrayType(dyvilx.tools.compiler.ast.type.compound.ArrayType) Mutability(dyvilx.tools.compiler.ast.type.Mutability) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) IType(dyvilx.tools.compiler.ast.type.IType)

Example 13 with Annotation

use of dyvilx.tools.compiler.ast.attribute.annotation.Annotation in project Dyvil by Dyvil.

the class ColonOperator method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    final Annotation annotation = type.getAnnotation(LazyFields.COLON_CONVERTIBLE);
    if (annotation != null) {
        return new LiteralConversion(this, annotation, new ArgumentList(this.left, this.right)).withType(type, typeContext, markers, context);
    }
    if (!Types.isSuperClass(type, TupleType.getTupleClass(2).getClassType())) {
        return null;
    }
    // reset type
    this.type = null;
    final IType leftType = Types.resolveTypeSafely(type, LazyFields.KEY_PARAMETER);
    final IType rightType = Types.resolveTypeSafely(type, LazyFields.VALUE_PARAMETER);
    this.left = TypeChecker.convertValue(this.left, leftType, typeContext, markers, context, TypeChecker.markerSupplier("colon_operator.left.type"));
    this.right = TypeChecker.convertValue(this.right, rightType, typeContext, markers, context, TypeChecker.markerSupplier("colon_operator.right.type"));
    return this;
}
Also used : ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) IType(dyvilx.tools.compiler.ast.type.IType)

Example 14 with Annotation

use of dyvilx.tools.compiler.ast.attribute.annotation.Annotation in project Dyvil by Dyvil.

the class AttributeList method read.

public static AttributeList read(DataInput in) throws IOException {
    final int flags = in.readInt();
    final int annotations = in.readShort();
    final AttributeList list = new AttributeList(annotations);
    list.flags = flags;
    list.size = annotations;
    for (int i = 0; i < annotations; i++) {
        final Annotation annotation = new ExternalAnnotation();
        list.data[i] = annotation;
        annotation.read(in);
    }
    return list;
}
Also used : ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation)

Example 15 with Annotation

use of dyvilx.tools.compiler.ast.attribute.annotation.Annotation in project Dyvil by Dyvil.

the class AttributeList method getAnnotation.

public Annotation getAnnotation(IClass type) {
    for (int i = 0; i < this.size; i++) {
        final Attribute attribute = this.data[i];
        final IType attributeType = attribute.getType();
        if (attributeType != null && attributeType.getTheClass() == type) {
            return (Annotation) attribute;
        }
    }
    return null;
}
Also used : Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)25 IType (dyvilx.tools.compiler.ast.type.IType)10 ExternalAnnotation (dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation)9 CodeAnnotation (dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation)6 AnnotationParser (dyvilx.tools.compiler.parser.annotation.AnnotationParser)6 Name (dyvil.lang.Name)4 IValue (dyvilx.tools.compiler.ast.expression.IValue)4 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)4 AnnotationExpr (dyvilx.tools.compiler.ast.expression.AnnotationExpr)3 IToken (dyvilx.tools.parsing.token.IToken)3 Modifier (dyvilx.tools.compiler.ast.attribute.modifiers.Modifier)2 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)2 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)2 ElementType (java.lang.annotation.ElementType)2 Reason (dyvil.annotation.Deprecated.Reason)1 Modifiers (dyvil.reflect.Modifiers)1 MarkerLevel (dyvil.util.MarkerLevel)1 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)1 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1