Search in sources :

Example 11 with ArrayExpr

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

the class Deprecation method getReplacements.

private static String[] getReplacements(ArgumentList arguments) {
    IValue value = arguments.get(DEP_REPLACE_PARAM);
    if (value == null) {
        return null;
    }
    assert value.valueTag() == IValue.ARRAY;
    final ArrayExpr array = (ArrayExpr) value;
    final ArgumentList values = array.getValues();
    final int size = values.size();
    if (size == 0) {
        return null;
    }
    String[] replacements = new String[size];
    for (int i = 0; i < size; i++) {
        IValue element = values.get(i);
        assert element.valueTag() == IValue.STRING;
        replacements[i] = element.stringValue();
    }
    return replacements;
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) IValue(dyvilx.tools.compiler.ast.expression.IValue) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList)

Example 12 with ArrayExpr

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

the class ArgumentList method resolveMissing.

protected void resolveMissing(IParameter param, GenericData genericData, SourcePosition position, MarkerList markers, IContext context) {
    if (this == EMPTY) {
        // cannot infer missing arguments if the argument list is EMPTY (i.e. not denoted)
        final Marker marker = Markers.semanticError(position, "method.access.argument.empty", param.getName());
        marker.addInfo(Markers.getSemantic("method.access.argument.empty.info"));
        markers.add(marker);
        return;
    }
    if (param.isVarargs()) {
        // varargs parameter
        final IValue value = convertValue(new ArrayExpr(position, EMPTY), param, genericData, markers, context);
        this.add(param.getLabel(), value);
        return;
    }
    if (!param.isImplicit()) {
        if (this.resolveDefault(param, context)) {
            return;
        }
        markers.add(Markers.semanticError(position, "method.access.argument.missing", param.getName()));
        return;
    }
    // implicit parameter, possibly default
    final IType type;
    if (genericData != null) {
        genericData.lockAvailable();
        type = param.getCovariantType().getConcreteType(genericData);
    } else {
        type = param.getCovariantType();
    }
    final IValue implicit = context.resolveImplicit(type);
    if (implicit != null) {
        // make sure to resolve and type-check the implicit value
        // (implicit values should be only field accesses, but might need some capture or "this<Outer" resolution)
        final IValue value = convertValue(implicit.resolve(markers, context), param, genericData, markers, context);
        this.add(param.getLabel(), value);
        return;
    }
    // default resolution only if implicit resolution fails
    if (this.resolveDefault(param, context)) {
        return;
    }
    markers.add(Markers.semanticError(position, "method.access.argument.implicit", param.getName(), type));
    return;
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) IValue(dyvilx.tools.compiler.ast.expression.IValue) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

ArrayExpr (dyvilx.tools.compiler.ast.expression.ArrayExpr)12 IValue (dyvilx.tools.compiler.ast.expression.IValue)7 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)5 IType (dyvilx.tools.compiler.ast.type.IType)2 Reason (dyvil.annotation.Deprecated.Reason)1 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)1 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 MapExpr (dyvilx.tools.compiler.ast.expression.MapExpr)1 EnumValue (dyvilx.tools.compiler.ast.expression.constant.EnumValue)1 IField (dyvilx.tools.compiler.ast.field.IField)1 INamed (dyvilx.tools.compiler.ast.member.INamed)1 Marker (dyvilx.tools.parsing.marker.Marker)1 ElementType (java.lang.annotation.ElementType)1