Search in sources :

Example 1 with Label

use of dyvilx.tools.compiler.ast.statement.control.Label in project Dyvil by Dyvil.

the class StatementList method add.

@Override
public void add(Name name, IValue value) {
    final int index = this.valueCount;
    this.add(value);
    final Label label = new Label(name, value);
    if (this.labels == null) {
        this.labels = new Label[index + 1];
        this.labels[index] = label;
        return;
    }
    if (index >= this.labels.length) {
        final Label[] temp = new Label[index + 1];
        System.arraycopy(this.labels, 0, temp, 0, this.labels.length);
        this.labels = temp;
    }
    this.labels[index] = label;
}
Also used : Label(dyvilx.tools.compiler.ast.statement.control.Label)

Example 2 with Label

use of dyvilx.tools.compiler.ast.statement.control.Label 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 3 with Label

use of dyvilx.tools.compiler.ast.statement.control.Label in project Dyvil by Dyvil.

the class StatementList method writeExpression.

@Override
public void writeExpression(MethodWriter writer, IType type) throws BytecodeException {
    int statementCount = this.valueCount - 1;
    if (statementCount < 0) {
        return;
    }
    dyvilx.tools.asm.Label start = new dyvilx.tools.asm.Label();
    dyvilx.tools.asm.Label end = new dyvilx.tools.asm.Label();
    writer.visitLabel(start);
    int localCount = writer.localCount();
    if (this.labels == null) {
        // Write all statements except the last one
        for (int i = 0; i < statementCount; i++) {
            this.values[i].writeExpression(writer, Types.VOID);
        }
        // Write the last expression
        this.values[statementCount].writeExpression(writer, type);
    } else {
        final int labelCount = this.labels.length;
        Label label;
        // Write all statements except the last one
        for (int i = 0; i < statementCount; i++) {
            if (i < labelCount && (label = this.labels[i]) != null) {
                writer.visitLabel(label.getTarget());
            }
            this.values[i].writeExpression(writer, Types.VOID);
        }
        // Write last expression (and label)
        if (statementCount < labelCount && (label = this.labels[statementCount]) != null) {
            writer.visitLabel(label.getTarget());
        }
        this.values[statementCount].writeExpression(writer, type);
    }
    writer.resetLocals(localCount);
    writer.visitLabel(end);
    if (this.variables == null) {
        return;
    }
    for (IVariable variable : this.variables) {
        variable.writeLocal(writer, start, end);
    }
}
Also used : IVariable(dyvilx.tools.compiler.ast.field.IVariable) Label(dyvilx.tools.compiler.ast.statement.control.Label)

Aggregations

Label (dyvilx.tools.compiler.ast.statement.control.Label)3 SourcePosition (dyvil.source.position.SourcePosition)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 IVariable (dyvilx.tools.compiler.ast.field.IVariable)1