Search in sources :

Example 56 with IValue

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

the class ICall method resolve.

@Override
default IValue resolve(MarkerList markers, IContext context) {
    final int wildcards = this.wildcardCount();
    if (wildcards > 0) {
        return this.toLambda(markers, context, wildcards);
    }
    this.resolveReceiver(markers, context);
    this.resolveArguments(markers, context);
    // Don't resolve and report an error if the receiver is not resolved
    IValue receiver = this.getReceiver();
    if (receiver != null && !receiver.isResolved()) {
        return this;
    }
    // Don't resolve and report an error if the arguments are not resolved
    if (!this.getArguments().isResolved()) {
        return this;
    }
    return this.resolveCall(markers, context, true);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue)

Example 57 with IValue

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

the class MethodAssignment method writeExpression.

@Override
public void writeExpression(MethodWriter writer, IType type) throws BytecodeException {
    if (Types.isVoid(type)) {
        super.writeExpression(writer, type);
        return;
    }
    final IValue expression = this.arguments.getFirst();
    final Variable receiverVar = new Variable(null, this.receiver.getType(), this.receiver);
    final Variable expressionVar = new Variable(null, expression.getType(), expression);
    receiverVar.writeInit(writer);
    expressionVar.writeInit(writer);
    this.method.writeCall(writer, new FieldAccess(receiverVar), new ArgumentList(new FieldAccess(expressionVar)), this.genericData, Types.VOID, this.lineNumber());
    expressionVar.writeGet(writer);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) Variable(dyvilx.tools.compiler.ast.field.Variable) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList)

Example 58 with IValue

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

the class MethodCall method resolveImplicitCall.

protected IValue resolveImplicitCall(MarkerList markers, IContext context) {
    final IValue implicit = context.resolveImplicit(null);
    if (implicit == null) {
        return null;
    }
    final IMethod method = ICall.resolveMethod(context, implicit, this.name, this.arguments);
    if (method == null) {
        return null;
    }
    this.receiver = implicit;
    return this.checkArguments(markers, context, method);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 59 with IValue

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

the class AbstractFieldAccess method resolve.

// make sure to consider Optional Chain Awareness when overriding this method
@Override
public IValue resolve(MarkerList markers, IContext context) {
    this.resolveReceiver(markers, context);
    if (this.field != null) {
        // to deal with capture correctly
        this.capture(markers, context);
        return OptionalChainAware.transform(this);
    }
    final IValue v = this.resolveAccess(markers, context);
    if (v != null) {
        // resolveAccess is Optional Chain Aware
        return v;
    }
    // Don't report an error if the receiver is not resolved
    if (this.receiver == null || this.receiver.isResolved()) {
        this.reportResolve(markers);
    }
    return OptionalChainAware.transform(this);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue)

Example 60 with IValue

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

the class IDataMember method checkAssign.

default IValue checkAssign(MarkerList markers, IContext context, SourcePosition position, IValue receiver, IValue newValue) {
    if (this.hasModifier(Modifiers.FINAL) && !context.isConstructor()) {
        markers.add(Markers.semanticError(position, this.getKind().getName() + ".assign.final", this.getName()));
    }
    final IType type = this.getType();
    final ITypeContext typeContext = receiver == null ? ITypeContext.NULL : receiver.getType();
    final TypeChecker.MarkerSupplier markerSupplier = (errorPosition, expected, actual) -> {
        final String kindName = this.getKind().getName();
        final Marker marker = Markers.semanticError(errorPosition, kindName + ".assign.type", this.getName());
        marker.addInfo(Markers.getSemantic(kindName + ".type", expected));
        marker.addInfo(Markers.getSemantic("value.type", actual));
        return marker;
    };
    return TypeChecker.convertValue(newValue, type, typeContext, markers, context, markerSupplier);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IValueConsumer(dyvilx.tools.compiler.ast.consumer.IValueConsumer) IContext(dyvilx.tools.compiler.ast.context.IContext) TypeChecker(dyvilx.tools.compiler.transform.TypeChecker) IType(dyvilx.tools.compiler.ast.type.IType) MemberKind(dyvilx.tools.compiler.ast.member.MemberKind) WriteableExpression(dyvilx.tools.compiler.ast.expression.WriteableExpression) IMember(dyvilx.tools.compiler.ast.member.IMember) Types(dyvilx.tools.compiler.ast.type.builtin.Types) Formatting(dyvilx.tools.compiler.config.Formatting) Marker(dyvilx.tools.parsing.marker.Marker) SourcePosition(dyvil.source.position.SourcePosition) Markers(dyvilx.tools.compiler.util.Markers) BytecodeException(dyvilx.tools.compiler.backend.exception.BytecodeException) MarkerList(dyvilx.tools.parsing.marker.MarkerList) NonNull(dyvil.annotation.internal.NonNull) Modifiers(dyvil.reflect.Modifiers) MethodWriter(dyvilx.tools.compiler.backend.MethodWriter) IClass(dyvilx.tools.compiler.ast.classes.IClass) TypeChecker(dyvilx.tools.compiler.transform.TypeChecker) Marker(dyvilx.tools.parsing.marker.Marker) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) 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