Search in sources :

Example 6 with ArrayExpr

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

the class ArgumentList method checkVarargsValue.

protected static boolean checkVarargsValue(IValue[] values, int startIndex, int endIndex, IParameter param, GenericData genericData, MarkerList markers, IContext context) {
    final IValue value = values[startIndex];
    if (value.checkVarargs(true)) {
        values[startIndex] = convertValue(value, param, genericData, markers, context);
        return false;
    }
    final int count = endIndex - startIndex;
    final ArrayExpr arrayExpr = newArrayExpr(values, startIndex, count);
    final IValue converted = convertValue(arrayExpr, param, genericData, markers, context);
    values[startIndex] = converted;
    return true;
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) IValue(dyvilx.tools.compiler.ast.expression.IValue)

Example 7 with ArrayExpr

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

the class Intrinsics method readAnnotation.

public static IntrinsicData readAnnotation(IMethod method, Annotation annotation) {
    final ArgumentList arguments = annotation.getArguments();
    final IValue compilerCode = arguments.get(LazyFields.COMPILER_CODE);
    if (compilerCode != null && compilerCode.valueTag() == IValue.INT) {
        return new CompilerIntrinsic(compilerCode.intValue());
    }
    final IValue value = arguments.get(LazyFields.VALUE);
    if (value == null || value.valueTag() != IValue.ARRAY) {
        return null;
    }
    final ArrayExpr valueArray = (ArrayExpr) value;
    final ArgumentList values = valueArray.getValues();
    final int size = values.size();
    int insnCount = 0;
    int[] ints = new int[size];
    for (int i = 0; i < size; i++) {
        int opcode = values.get(i).intValue();
        ints[i] = opcode;
        insnCount++;
        if (Opcodes.isFieldOrMethodOpcode(opcode)) {
            ints[i + 1] = values.get(i + 1).intValue();
            ints[i + 2] = values.get(i + 2).intValue();
            ints[i + 3] = values.get(i + 3).intValue();
            i += 3;
        } else if (Opcodes.isJumpOpcode(opcode) || Opcodes.isLoadOpcode(opcode) || Opcodes.isStoreOpcode(opcode) || opcode == Opcodes.LDC || opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH) {
            ints[i + 1] = values.get(i + 1).intValue();
            i += 1;
        }
    }
    if (size > insnCount) {
        IValue stringValue = arguments.get(LazyFields.STRINGS);
        ArrayExpr strings = (ArrayExpr) stringValue;
        return readComplex(method, insnCount, ints, strings);
    }
    return new SimpleIntrinsicData(method, ints);
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) IValue(dyvilx.tools.compiler.ast.expression.IValue) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList)

Example 8 with ArrayExpr

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

the class EnumClassMetadata method createValuesArray.

private IValue createValuesArray() {
    final ArrayExpr arrayExpr = new ArrayExpr();
    arrayExpr.setElementType(this.theClass.getClassType());
    final ClassBody body = this.theClass.getBody();
    if (body != null) {
        final ArgumentList values = arrayExpr.getValues();
        for (IField enumConstant : body.enumConstants()) {
            values.add(new FieldAccess(enumConstant));
        }
    }
    return arrayExpr;
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) IField(dyvilx.tools.compiler.ast.field.IField) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Example 9 with ArrayExpr

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

the class AnnotationReader method visitArray.

@Override
public AnnotationVisitor visitArray(String key) {
    ArrayExpr valueList = new ArrayExpr();
    this.arguments.add(Name.fromRaw(key), valueList);
    return new AnnotationValueReader(valueList.getValues());
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr)

Example 10 with ArrayExpr

use of dyvilx.tools.compiler.ast.expression.ArrayExpr 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)

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