Search in sources :

Example 11 with IValue

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

the class OptionalChainAware method newVar.

/**
 * Creates a new variable for use in binding if statements. The lhs automatically gets wrapped in an optional unwrap
 * operator.
 */
static Variable newVar(SourcePosition position, IValue lhs) {
    final IValue value = new OptionalUnwrapOperator(lhs, true);
    final Variable var = new Variable(position, null, value.getType(), AttributeList.of(Modifiers.FINAL));
    var.setValue(value);
    return var;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) Variable(dyvilx.tools.compiler.ast.field.Variable)

Example 12 with IValue

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

the class ConstructorCall method resolveArrayConstructor.

private void resolveArrayConstructor(MarkerList markers, IContext context, ArrayType arrayType) {
    final IType elementType = arrayType.getElementType();
    if (elementType.hasTag(IType.TYPE_VAR)) {
        markers.add(Markers.semanticError(this.position, "constructor.access.array.typevar", elementType));
    }
    final int len = this.arguments.size();
    final int dims = 1 + getDimensions(arrayType.getElementType());
    if (len > dims) {
        final Marker marker = Markers.semanticError(this.position, "constructor.access.array.length");
        marker.addInfo(Markers.getSemantic("type.dimensions", dims));
        marker.addInfo(Markers.getSemantic("constructor.access.array.count", len));
        markers.add(marker);
        return;
    }
    for (int i = 0; i < len; i++) {
        final IValue value = this.arguments.get(i, null);
        final IValue typed = TypeChecker.convertValue(value, Types.INT, ITypeContext.DEFAULT, markers, context, TypeChecker.markerSupplier("constructor.access.array.type"));
        this.arguments.set(i, null, typed);
    }
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 13 with IValue

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

the class ICall method toLambda.

default IValue toLambda(MarkerList markers, IContext context, int wildcards) {
    SourcePosition position = this.getPosition();
    final IParameter[] parameters = new IParameter[wildcards];
    for (int i = 0; i < wildcards; i++) {
        parameters[i] = new CodeParameter(null, position, Name.fromRaw("wildcard$" + i), Types.UNKNOWN, new AttributeList());
    }
    int parIndex = 0;
    final IValue receiver = this.getReceiver();
    if (receiver != null && receiver.isPartialWildcard()) {
        this.setReceiver(receiver.withLambdaParameter(parameters[parIndex++]));
    }
    final ArgumentList arguments = this.getArguments();
    for (int i = 0, size = arguments.size(); i < size; i++) {
        final IValue argument = arguments.get(i, null);
        if (argument.isPartialWildcard()) {
            arguments.set(i, null, argument.withLambdaParameter(parameters[parIndex++]));
        }
    }
    final LambdaExpr lambdaExpr = new LambdaExpr(position, parameters, wildcards);
    lambdaExpr.setImplicitParameters(true);
    lambdaExpr.setValue(this);
    return lambdaExpr.resolve(markers, context);
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) SourcePosition(dyvil.source.position.SourcePosition) LambdaExpr(dyvilx.tools.compiler.ast.expression.LambdaExpr) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter)

Example 14 with IValue

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

the class CaptureParameter method getDefaultValue.

@Override
public IValue getDefaultValue(IContext context) {
    final IValue access = new FieldAccess(this.variable) {

        @Override
        public void writeExpression(MethodWriter writer, IType type) throws BytecodeException {
            this.field.writeGetRaw(writer, this.receiver, this.lineNumber());
        }
    }.resolve(MarkerList.BLACKHOLE, context);
    // ensures proper capture
    access.checkTypes(MarkerList.BLACKHOLE, context);
    return access;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) BytecodeException(dyvilx.tools.compiler.backend.exception.BytecodeException) MethodWriter(dyvilx.tools.compiler.backend.MethodWriter) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) IType(dyvilx.tools.compiler.ast.type.IType)

Example 15 with IValue

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

the class VarargsOperator method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    final IValue typed = this.value.withType(type, typeContext, markers, context);
    if (typed == null) {
        return null;
    }
    this.value = typed;
    return this;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue)

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