Search in sources :

Example 36 with IValue

use of dyvilx.tools.compiler.ast.expression.IValue 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 37 with IValue

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

the class StatementList method resolve.

@Override
public IValue resolve(MarkerList markers, IContext context) {
    if (this.valueCount <= 0) {
        return this;
    }
    context = context.push(this);
    // Resolve and check all values
    final int lastIndex = this.valueCount - 1;
    for (int i = 0; i < this.valueCount; i++) {
        final IValue resolvedValue = this.values[i] = this.values[i].resolve(markers, context);
        final int valueTag = resolvedValue.valueTag();
        if (valueTag == IValue.VARIABLE) {
            this.addVariable((VariableStatement) resolvedValue, markers, context);
            continue;
        }
        if (valueTag == IValue.MEMBER_STATEMENT) {
            this.addMethod((MemberStatement) resolvedValue, markers);
            continue;
        }
        if (i == lastIndex) {
            break;
        }
        if (!resolvedValue.isStatement()) {
            final IValue applyStatementCall = resolveApplyStatement(markers, context, resolvedValue);
            if (applyStatementCall != null) {
                this.values[i] = applyStatementCall;
                continue;
            }
        }
        this.values[i] = IStatement.checkStatement(markers, context, resolvedValue, "statementlist.statement");
    }
    context.pop();
    return this;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue)

Example 38 with IValue

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

the class StatementList method toString.

@Override
public void toString(String prefix, StringBuilder buffer) {
    if (this.valueCount == 0) {
        if (Formatting.getBoolean("statement.empty.newline")) {
            buffer.append('{').append('\n').append(prefix).append('}');
        } else if (Formatting.getBoolean("statement.empty.space_between")) {
            buffer.append("{ }");
        } else {
            buffer.append("{}");
        }
        return;
    }
    buffer.append('{').append('\n');
    String indentedPrefix = Formatting.getIndent("statement.indent", prefix);
    int prevLine = 0;
    Label label;
    for (int i = 0; i < this.valueCount; i++) {
        IValue value = this.values[i];
        SourcePosition pos = value.getPosition();
        buffer.append(indentedPrefix);
        if (pos != null) {
            if (pos.startLine() - prevLine > 1 && i > 0) {
                buffer.append('\n').append(indentedPrefix);
            }
            prevLine = pos.endLine();
        }
        if (this.labels != null && i < this.labels.length && (label = this.labels[i]) != null) {
            buffer.append("label ");
            buffer.append(label.name);
            if (Formatting.getBoolean("label.separator.space_before")) {
                buffer.append(' ');
            }
            buffer.append(':');
            if (Formatting.getBoolean("label.separator.newline_after")) {
                buffer.append('\n').append(indentedPrefix);
            } else if (Formatting.getBoolean("label.separator.newline_after")) {
                buffer.append(' ');
            }
        }
        value.toString(indentedPrefix, buffer);
        if (Formatting.getBoolean("statement.semicolon")) {
            buffer.append(';');
        }
        buffer.append('\n');
    }
    buffer.append(prefix).append('}');
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) SourcePosition(dyvil.source.position.SourcePosition) Label(dyvilx.tools.compiler.ast.statement.control.Label)

Example 39 with IValue

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

the class UnapplyPattern method withType.

@Override
public Pattern withType(IType type, MarkerList markers) {
    // PatternType.unapply(_ : MatchedType)
    final IClass matchClass = this.type.getTheClass();
    if (matchClass == null) {
        return null;
    }
    final MethodCall methodCall = new MethodCall(this.position, new ClassAccess(this.type), Names.unapply, new ArgumentList(new DummyValue(type)));
    final IValue resolvedCall = methodCall.resolveCall(MarkerList.BLACKHOLE, matchClass, false);
    return resolvedCall != null && this.withMethod(type, resolvedCall, markers) ? this : null;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) ClassAccess(dyvilx.tools.compiler.ast.expression.access.ClassAccess) IClass(dyvilx.tools.compiler.ast.classes.IClass) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) MethodCall(dyvilx.tools.compiler.ast.expression.access.MethodCall) DummyValue(dyvilx.tools.compiler.ast.expression.DummyValue)

Example 40 with IValue

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

the class MultiImport method resolveImplicit.

@Override
public IValue resolveImplicit(IType type) {
    IValue candidate = null;
    for (int i = 0; i < this.importCount; i++) {
        final IValue value = this.imports[i].asContext().resolveImplicit(type);
        if (value == null) {
            continue;
        }
        if (candidate != null) {
            // ambiguous
            return null;
        }
        candidate = value;
    }
    return candidate;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue)

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