Search in sources :

Example 26 with ArgumentList

use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.

the class Deprecation method getReasons.

private static Reason[] getReasons(ArgumentList arguments) {
    final IValue value = arguments.get(DEP_REASONS_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;
    }
    final Reason[] reasons = new Reason[size];
    for (int i = 0; i < size; i++) {
        final IValue element = values.get(i);
        assert element.valueTag() == IValue.ENUM_ACCESS;
        final EnumValue enumValue = (EnumValue) element;
        reasons[i] = Reason.valueOf(enumValue.getInternalName());
    }
    return reasons;
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) IValue(dyvilx.tools.compiler.ast.expression.IValue) EnumValue(dyvilx.tools.compiler.ast.expression.constant.EnumValue) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) Reason(dyvil.annotation.Deprecated.Reason)

Example 27 with ArgumentList

use of dyvilx.tools.compiler.ast.parameter.ArgumentList 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 28 with ArgumentList

use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.

the class Deprecation method checkDeprecation.

private static void checkDeprecation(IMember member, SourcePosition position, MarkerList markers) {
    Annotation annotation = member.getAnnotation(DEPRECATED_CLASS);
    if (annotation == null) {
        annotation = new ExternalAnnotation(DEPRECATED);
    }
    final ArgumentList arguments = annotation.getArguments();
    final MarkerLevel markerLevel = AnnotationUtil.getEnumValue(arguments, DEP_LEVEL_PARAM, MarkerLevel.class);
    if (markerLevel == null || markerLevel == MarkerLevel.IGNORE) {
        return;
    }
    String value = AnnotationUtil.getStringValue(arguments, DEP_VALUE_PARAM);
    final String description = AnnotationUtil.getStringValue(arguments, DEP_DESC_PARAM);
    final String since = AnnotationUtil.getStringValue(arguments, DEP_SINCE_PARAM);
    final String forRemoval = AnnotationUtil.getStringValue(arguments, DEP_UNTIL_PARAM);
    value = replaceMember(member, value);
    if (since != null) {
        value = value.replace("{since}", since);
    }
    if (forRemoval != null) {
        value = value.replace("{forRemoval}", forRemoval);
    }
    final Marker marker = Markers.withText(position, markerLevel, value);
    assert marker != null;
    // Description
    if (description != null && !description.isEmpty()) {
        marker.addInfo(Markers.getSemantic("deprecated.description", description));
    }
    // Since
    if (since != null && !since.isEmpty()) {
        marker.addInfo(Markers.getSemantic("deprecated.since", since));
    }
    if (forRemoval != null && !forRemoval.isEmpty()) {
        marker.addInfo(Markers.getSemantic("deprecated.forRemoval", forRemoval));
    }
    // Until
    // Reasons
    final Reason[] reasons = getReasons(arguments);
    if (reasons != null) {
        final int reasonCount = reasons.length;
        // more than one reason
        if (reasonCount == 1) {
            marker.addInfo(Markers.getSemantic("deprecated.reason", reasonName(reasons[0])));
        } else if (reasonCount > 0) {
            final StringBuilder builder = new StringBuilder(reasonName(reasons[0]));
            for (int i = 1; i < reasonCount; i++) {
                builder.append(", ").append(reasonName(reasons[i]));
            }
            marker.addInfo(Markers.getSemantic("deprecated.reasons", builder.toString()));
        }
    }
    // Replacements
    final String[] replacements = getReplacements(arguments);
    if (replacements != null) {
        for (String replacement : replacements) {
            marker.addInfo("\t\t" + replacement);
        }
        marker.addInfo(Markers.getSemantic("deprecated.replacements"));
    }
    markers.add(marker);
}
Also used : ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) MarkerLevel(dyvil.util.MarkerLevel) Marker(dyvilx.tools.parsing.marker.Marker) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) Reason(dyvil.annotation.Deprecated.Reason)

Example 29 with ArgumentList

use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.

the class ExpressionParser method parseApply.

/**
 * Parses an APPLY call, without parenthesis. It might be possible that {@code pm.reparse()} has to be called after
 * this method, depending on the token that is passed. E.g.:
 * <p>
 * <p>
 * <pre>
 * this 3
 * print "abc"
 * button { ... }
 * </pre>
 *
 * @param pm
 * 	the current parsing context manager
 * @param token
 * 	the first token of the expression that is a parameter to the APPLY method
 * @param call
 * 	the method or apply call
 */
private void parseApply(IParserManager pm, IToken token, ICall call) {
    if (token.type() != BaseSymbols.OPEN_CURLY_BRACKET) {
        final ArgumentList arguments = new ArgumentList(1);
        call.setArguments(arguments);
        pm.pushParser(new ExpressionParser(arguments).withFlags(this.flags | IGNORE_APPLY | IGNORE_OPERATOR));
        return;
    }
    if (this.hasFlag(IGNORE_CLOSURE)) {
        this.end(pm, false);
        return;
    }
    final ArgumentList arguments = new ArgumentList(1);
    call.setArguments(arguments);
    pm.pushParser(new StatementListParser(arguments, true));
}
Also used : ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList)

Example 30 with ArgumentList

use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.

the class ArrayLiteralParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    int type = token.type();
    switch(this.mode) {
        case OPEN_BRACKET:
            pm.pushParser(this.newExpressionParser(this.keys));
            this.mode = SEPARATOR | COLON;
            this.startPosition = token;
            if (type != BaseSymbols.OPEN_SQUARE_BRACKET) {
                pm.reparse();
                pm.report(token, "array.open_bracket");
            }
            return;
        case SEPARATOR | COLON:
            if (type == BaseSymbols.COLON) {
                this.mode = SEPARATOR;
                this.values = new ArgumentList(this.keys.size());
                pm.pushParser(this.newExpressionParser(this.values));
                return;
            }
        // Fallthrough
        case SEPARATOR:
            if (type == BaseSymbols.CLOSE_SQUARE_BRACKET) {
                pm.popParser();
                this.end(token);
                return;
            }
            this.mode = this.values != null ? COLON : SEPARATOR;
            pm.pushParser(this.newExpressionParser(this.keys));
            if (type != BaseSymbols.COMMA && type != BaseSymbols.SEMICOLON) {
                pm.report(token, "array.separator");
            }
            return;
        case COLON:
            if (type == BaseSymbols.CLOSE_SQUARE_BRACKET) {
                pm.popParser();
                this.end(token);
                return;
            }
            this.mode = SEPARATOR;
            pm.pushParser(this.newExpressionParser(this.values));
            if (type != BaseSymbols.COLON) {
                pm.reparse();
                pm.report(token, "array.map.colon");
            }
            return;
        case END:
    }
}
Also used : ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList)

Aggregations

ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)37 IValue (dyvilx.tools.compiler.ast.expression.IValue)17 IType (dyvilx.tools.compiler.ast.type.IType)10 SourcePosition (dyvil.source.position.SourcePosition)8 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)7 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)5 ArrayExpr (dyvilx.tools.compiler.ast.expression.ArrayExpr)5 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)5 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)5 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)4 ConstructorCall (dyvilx.tools.compiler.ast.expression.access.ConstructorCall)4 MarkerLevel (dyvil.util.MarkerLevel)3 MethodCall (dyvilx.tools.compiler.ast.expression.access.MethodCall)3 StringValue (dyvilx.tools.compiler.ast.expression.constant.StringValue)3 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)3 Marker (dyvilx.tools.parsing.marker.Marker)3 Reason (dyvil.annotation.Deprecated.Reason)2 Name (dyvil.lang.Name)2 IClass (dyvilx.tools.compiler.ast.classes.IClass)2