<commit_before>package io.collap.bryg.compiler.ast.expression.bool;

import io.collap.bryg.compiler.ast.expression.Expression;
import io.collap.bryg.compiler.bytecode.BrygMethodVisitor;
import io.collap.bryg.compiler.context.Context;
import io.collap.bryg.exception.BrygJitException;
import bryg.org.objectweb.asm.Label;

import javax.annotation.Nullable;

import static bryg.org.objectweb.asm.Opcodes.IFEQ;

/**
 * This boolean expression evaluates an arbitrary expression, which must return a boolean, but is not required to be a
 * subtype of BooleanExpression.
 */
public class ExpressionBooleanExpression extends BooleanExpression {

    private Expression expression;

    public ExpressionBooleanExpression (Context context, Expression expression) {
        super (context);
        this.expression = expression;

        if (!expression.getType ().equals (Boolean.TYPE)) {
            throw new BrygJitException ("Expected a condition, but got an expression that does not return a boolean type",
                getLine ());
        }
    }

    @Override
    public void compile (Label nextFalse, @Nullable Label nextTrue, boolean lastExpressionInChain) {
        BrygMethodVisitor mv = context.getMethodVisitor ();

        expression.compile ();
        // -> boolean

        mv.visitJumpInsn (IFEQ, nextFalse); /* Jump to false label when the boolean value is 0. */

        super.compile (nextFalse, nextTrue, lastExpressionInChain);<commit_msg>Fix bug where the line of an ExpressionBooleanExpression is not set.<commit_after>package io.collap.bryg.compiler.ast.expression.bool;

import io.collap.bryg.compiler.ast.expression.Expression;
import io.collap.bryg.compiler.bytecode.BrygMethodVisitor;
import io.collap.bryg.compiler.context.Context;
import io.collap.bryg.exception.BrygJitException;
import bryg.org.objectweb.asm.Label;

import javax.annotation.Nullable;

import static bryg.org.objectweb.asm.Opcodes.IFEQ;

/**
 * This boolean expression evaluates an arbitrary expression, which must return a boolean, but is not required to be a
 * subtype of BooleanExpression.
 */
public class ExpressionBooleanExpression extends BooleanExpression {

    private Expression expression;

    public ExpressionBooleanExpression (Context context, Expression expression) {
        super (context);
        setLine (expression.getLine ());
        this.expression = expression;

        if (!expression.getType ().equals (Boolean.TYPE)) {
            throw new BrygJitException ("Expected a condition, but got an expression that does not return a boolean type",
                getLine ());
        }
    }

    @Override
    public void compile (Label nextFalse, @Nullable Label nextTrue, boolean lastExpressionInChain) {
        BrygMethodVisitor mv = context.getMethodVisitor ();

        expression.compile ();
        // -> boolean

        mv.visitJumpInsn (IFEQ, nextFalse); /* Jump to false label when the boolean value is 0. */

        super.compile (nextFalse, nextTrue, lastExpressionInChain);
{'fraction_non_alphanumeric': 0.08725945587259455, 'fraction_numerical': 0.0006635700066357001, 'mean_word_length': 3.5681818181818183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2566482', 'n_tokens_mistral': 816, 'n_tokens_neox': 791, 'n_words': 235}