Search in sources :

Example 66 with IValue

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

the class MethodCall method resolveAlternative.

protected IValue resolveAlternative(MarkerList markers, IContext context, boolean report) {
    if (this.genericData != null && this.arguments == ArgumentList.EMPTY) {
        final IType parentType;
        if (this.receiver == null) {
            parentType = null;
        } else if (this.receiver.isClassAccess()) {
            parentType = this.receiver.getType();
        } else {
            return null;
        }
        final IType type = new NamedGenericType(this.position, parentType, this.name, this.genericData.getTypes()).resolveType(report ? markers : null, context);
        if (type == null) {
            return null;
        }
        return new ClassAccess(this.position, type);
    }
    final IValue access = new FieldAccess(this.position, this.receiver, this.name).resolveAccess(markers, context);
    if (access == null) {
        return null;
    }
    // Field or Class Access available, try to resolve an apply method
    final ApplyAccess call = new ApplyAccess(this.position, access, this.arguments);
    call.genericData = this.genericData;
    return call.resolveCall(markers, context, report);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) NamedGenericType(dyvilx.tools.compiler.ast.type.generic.NamedGenericType) IType(dyvilx.tools.compiler.ast.type.IType)

Example 67 with IValue

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

the class InfixCall method resolveCompound.

protected static IValue resolveCompound(MarkerList markers, IContext context, SourcePosition position, IValue lhs, Name name, ArgumentList arguments) {
    final IValue op = new InfixCall(position, lhs, name, arguments).resolveCall(markers, context, false);
    if (op == null) {
        return null;
    }
    final SideEffectHelper helper = new SideEffectHelper();
    final IValue assignment = lhs.toCompoundAssignment(op, position, markers, context, helper);
    if (assignment != null) {
        return helper.finish(assignment);
    }
    return null;
}
Also used : SideEffectHelper(dyvilx.tools.compiler.transform.SideEffectHelper) IValue(dyvilx.tools.compiler.ast.expression.IValue)

Example 68 with IValue

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

the class AbstractMethod method toString.

@Override
public void toString(@NonNull String indent, @NonNull StringBuilder buffer) {
    // Annotations and Modifiers
    super.toString(indent, buffer);
    // Name
    buffer.append("func ").append(this.name);
    // Type Parameters
    if (this.typeParameters != null) {
        this.typeParameters.toString(indent, buffer);
    }
    // Parameters
    final IType thisType = this.getThisType();
    this.parameters.toString(thisType == this.enclosingClass.getThisType() ? null : thisType, indent, buffer);
    // Exceptions
    if (this.exceptions != null && this.exceptions.size() > 0) {
        final String throwsIndent;
        if (Formatting.getBoolean("method.throws.newline")) {
            throwsIndent = Formatting.getIndent("method.throws.indent", indent);
            buffer.append('\n').append(throwsIndent).append("throws ");
        } else {
            throwsIndent = indent;
            buffer.append(" throws ");
        }
        Util.astToString(throwsIndent, this.exceptions.getTypes(), this.exceptions.size(), Formatting.getSeparator("method.throws", ','), buffer);
    }
    // Type Ascription
    if (this.type != null && this.type != Types.UNKNOWN) {
        Formatting.appendSeparator(buffer, "method.type_ascription", "->");
        this.type.toString(indent, buffer);
    }
    // Implementation
    final IValue value = this.getValue();
    if (value != null) {
        if (Util.formatStatementList(indent, buffer, value)) {
            return;
        }
        if (Formatting.getBoolean("method.declaration.space_before")) {
            buffer.append(' ');
        }
        buffer.append('=');
        String valuePrefix = Formatting.getIndent("method.declaration.indent", indent);
        if (Formatting.getBoolean("method.declaration.newline_after")) {
            buffer.append('\n').append(valuePrefix);
        } else if (Formatting.getBoolean("method.declaration.space_after")) {
            buffer.append(' ');
        }
        value.toString(indent, buffer);
    }
    if (Formatting.getBoolean("method.semicolon")) {
        buffer.append(';');
    }
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) IType(dyvilx.tools.compiler.ast.type.IType)

Example 69 with IValue

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

the class ImplicitReferenceType method convertFrom.

@Override
public IValue convertFrom(IValue value, IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    final IValue typedValue = value.withType(this.type, typeContext, markers, context);
    if (typedValue == null || !this.isConvertibleFrom(typedValue.getType())) {
        return null;
    }
    final IValue reference = typedValue.toReferenceValue(markers, context);
    if (reference != null) {
        return reference;
    }
    markers.add(Markers.semanticError(this.getPosition(), "reference.expression.invalid"));
    return typedValue;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue)

Example 70 with IValue

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

the class BindingIfStatement method checkCondition.

@Override
protected void checkCondition(MarkerList markers, IContext context) {
    final int size = this.variables.size();
    for (int i = 0; i < size; i++) {
        final IVariable var = this.variables.get(i);
        var.check(markers, this.varContext(i, context));
        final IValue value = getOptionalValue(var);
        final IType type = value.getType();
        if (value.isResolved() && type.isResolved() && !NullableType.isNullable(type)) {
            final Marker marker = Markers.semanticError(value.getPosition(), "if.binding.nonnull");
            marker.addInfo(Markers.getSemantic("value.type", type));
            markers.add(marker);
        }
    }
    super.checkCondition(markers, this.varContext(size, context));
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) IVariable(dyvilx.tools.compiler.ast.field.IVariable) Marker(dyvilx.tools.parsing.marker.Marker) 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