Search in sources :

Example 21 with IValue

use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.

the class SideEffectHelper method processArguments.

public ArgumentList processArguments(ArgumentList arguments) {
    final ArgumentList copy = arguments.copy();
    for (int i = 0, count = arguments.size(); i < count; i++) {
        final IValue value = arguments.get(i, null);
        copy.set(i, null, this.processValue(value));
    }
    return copy;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList)

Example 22 with IValue

use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.

the class TypeChecker method convertValueDirect.

private static IValue convertValueDirect(IValue value, IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    final IValue typedValue = value.withType(type, typeContext, markers, context);
    if (typedValue != null) {
        return typedValue;
    }
    final IValue converted1 = type.convertFrom(value, value.getType(), typeContext, markers, context);
    if (converted1 != null) {
        return converted1;
    }
    final IValue converted2 = value.getType().convertTo(value, type, typeContext, markers, context);
    if (converted2 != null) {
        return converted2;
    }
    final IMethod converter = IContext.resolveImplicits(context, value, type).getBestMember();
    if (converter == null) {
        return null;
    }
    return new LiteralConversion(value, converter);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) LiteralConversion(dyvilx.tools.compiler.ast.expression.LiteralConversion) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 23 with IValue

use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.

the class AnnotationMetadata method readRetention.

private void readRetention() {
    final Annotation retention = this.theClass.getAnnotation(Annotation.LazyFields.RETENTION_CLASS);
    if (retention == null) {
        return;
    }
    final IValue value = retention.getArguments().get(0, Names.value);
    if (!(value instanceof EnumValue)) {
        return;
    }
    try {
        final String name = ((EnumValue) value).getName().qualified;
        this.retention = RetentionPolicy.valueOf(name);
    } catch (IllegalArgumentException ignored) {
    // Problematic RetentionPolicy annotation - do not handle this
    }
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) EnumValue(dyvilx.tools.compiler.ast.expression.constant.EnumValue) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation)

Example 24 with IValue

use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.

the class AnnotationMetadata method readTargets.

private void readTargets() {
    final Annotation target = this.theClass.getAnnotation(Annotation.LazyFields.TARGET_CLASS);
    if (target == null) {
        return;
    }
    this.targets = EnumSet.noneOf(ElementType.class);
    final IValue argument = target.getArguments().get(0, Names.value);
    if (!(argument instanceof ArrayExpr)) {
        return;
    }
    final ArgumentList values = ((ArrayExpr) argument).getValues();
    final int size = values.size();
    for (int i = 0; i < size; i++) {
        final INamed value = (INamed) values.get(i);
        try {
            this.targets.add(ElementType.valueOf(value.getName().qualified));
        } catch (IllegalArgumentException ignored) {
        // Problematic Target annotation - do not handle this
        }
    }
}
Also used : ElementType(java.lang.annotation.ElementType) ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) IValue(dyvilx.tools.compiler.ast.expression.IValue) INamed(dyvilx.tools.compiler.ast.member.INamed) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation)

Example 25 with IValue

use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.

the class CaseClassMetadata method createUnapplyMethod.

private CodeMethod createUnapplyMethod() {
    // static final func unapply<TypeParams...>(value: This) -> (T...)
    final SourcePosition position = this.theClass.position();
    final AttributeList attributes = AttributeList.of(Modifiers.PUBLIC | Modifiers.STATIC_FINAL | Modifiers.GENERATED);
    final IType type = this.getUnapplyReturnType();
    final CodeMethod unapply = new CodeMethod(this.theClass, Names.unapply, type, attributes);
    unapply.setPosition(position);
    unapply.getTypeParameters().addAll(this.theClass.getTypeParameters());
    final CodeParameter parameter = new CodeParameter(unapply, position, Names.value, this.theClass.getThisType());
    unapply.getParameters().add(parameter);
    // = (value.classParams...)
    final TupleExpr tupleExpr = new TupleExpr(position);
    final ArgumentList arguments = tupleExpr.getValues();
    for (IParameter param : this.theClass.getParameters()) {
        // value
        final FieldAccess thisAccess = new FieldAccess(position, null, parameter);
        // value.classParam
        final IValue fieldAccess;
        if (param.isOverride()) {
            // if the class parameter is marked as 'override', we have to resolve it from a super-class
            // the easiest way to do this is by name
            fieldAccess = new FieldAccess(position, thisAccess, param.getName());
        } else {
            fieldAccess = new FieldAccess(position, thisAccess, param);
        }
        arguments.add(fieldAccess);
    }
    unapply.setValue(tupleExpr);
    return unapply;
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) CodeMethod(dyvilx.tools.compiler.ast.method.CodeMethod) AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) SourcePosition(dyvil.source.position.SourcePosition) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter) TupleExpr(dyvilx.tools.compiler.ast.expression.TupleExpr) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IValue (dyvilx.tools.compiler.ast.expression.IValue)79 IType (dyvilx.tools.compiler.ast.type.IType)20 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)17 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)11 SourcePosition (dyvil.source.position.SourcePosition)10 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)9 ArrayExpr (dyvilx.tools.compiler.ast.expression.ArrayExpr)7 Marker (dyvilx.tools.parsing.marker.Marker)7 IMethod (dyvilx.tools.compiler.ast.method.IMethod)6 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)5 IContext (dyvilx.tools.compiler.ast.context.IContext)5 MethodCall (dyvilx.tools.compiler.ast.expression.access.MethodCall)5 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)5 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)4 IClass (dyvilx.tools.compiler.ast.classes.IClass)4 Variable (dyvilx.tools.compiler.ast.field.Variable)4 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)4 CombiningContext (dyvilx.tools.compiler.ast.context.CombiningContext)3 IVariable (dyvilx.tools.compiler.ast.field.IVariable)3 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)3