<commit_before>package de.peeeq.wurstscript.translation.imtojass;

import static de.peeeq.wurstscript.jassAst.JassAst.JassStatements;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtExitwhen;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtIf;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtLoop;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtReturn;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtReturnVoid;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtSet;

import java.util.List;

import de.peeeq.wurstscript.jassAst.JassAst;
import de.peeeq.wurstscript.jassAst.JassExpr;
import de.peeeq.wurstscript.jassAst.JassExprFunctionCall;
import de.peeeq.wurstscript.jassAst.JassFunction;
import de.peeeq.wurstscript.jassAst.JassStatement;
import de.peeeq.wurstscript.jassAst.JassStatements;
import de.peeeq.wurstscript.jassAst.JassVar;
import de.peeeq.wurstscript.jassIm.ImExitwhen;
import de.peeeq.wurstscript.jassIm.ImExpr;
import de.peeeq.wurstscript.jassIm.ImIf;
import de.peeeq.wurstscript.jassIm.ImLoop;
import de.peeeq.wurstscript.jassIm.ImNoExpr;
import de.peeeq.wurstscript.jassIm.ImReturn;
import de.peeeq.wurstscript.jassIm.ImSet;
import de.peeeq.wurstscript.jassIm.ImSetArray;
import de.peeeq.wurstscript.jassIm.ImSetArrayMulti;
import de.peeeq.wurstscript.jassIm.ImSetArrayTuple;
import de.peeeq.wurstscript.jassIm.ImSetTuple;
import de.peeeq.wurstscript.jassIm.ImStmt;
import de.peeeq.wurstscript.jassIm.ImStmts;

public class StatementTranslation {


	public static void translate(ImExitwhen imExitwhen, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		stmts.add(JassStmtExitwhen(imExitwhen.getCondition().translate(translator)));
	}

	public static void translate(ImIf imIf, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		JassExpr cond = imIf.getCondition().translate(translator);
		JassStatements thenBlock = JassStatements(); 
		imIf.getThenBlock().translate(thenBlock, f, translator);
		JassStatements elseBlock = JassStatements();
		imIf.getElseBlock().translate(elseBlock, f, translator);
		stmts.add(JassStmtIf(cond, thenBlock, elseBlock));
	}


	public static void translate(ImLoop imLoop, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		JassStatements body = JassStatements();
		imLoop.getBody().translate(body, f, translator);
		stmts.add(JassStmtLoop(body));
	}

	public static void translate(ImReturn imReturn, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		if (imReturn.getReturnValue() instanceof ImNoExpr) {
			stmts.add(JassStmtReturnVoid());
		} else {
			ImExpr e = (ImExpr) imReturn.getReturnValue();
			JassExpr returnValue = e.translate(translator);
			stmts.add(JassStmtReturn(returnValue));
		}
	}

	public static void translate(ImSet imSet, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		JassVar vars = translator.getJassVarFor(imSet.getLeft());
		JassExpr exprs = imSet.getRight().translate(translator);
		stmts.add(JassStmtSet(vars.getName(), exprs));
	}

	public static void translate(ImExpr imExpr, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		JassExpr expr = imExpr.translate(translator);
		if (expr instanceof JassExprFunctionCall) {
			JassExprFunctionCall fc = (JassExprFunctionCall) expr;
			stmts.add(JassAst.JassStmtCall(fc.getFuncName(), fc.getArguments().copy()));
		}
	}

	

	public static void translate(ImSetArray imSet, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		JassVar leftVar = translator.getJassVarFor(imSet.getLeft());
		JassExpr right = imSet.getRight().translate(translator);
		stmts.add(JassAst.JassStmtSetArray(leftVar.getName(), imSet.getIndex().translate(translator), right));			
	}
	
	public static void translate(ImSetArrayTuple imSet, List<JassStatement> stmts, JassFunction f,
			ImToJassTranslator translator) {
		throw new Error("tuples should be eliminated in earlier phase");
	}

	public static void translate(ImSetTuple imSet, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		throw new Error("tuples should be eliminated in earlier phase");<commit_msg>fixed bug in intermediate->jass translation<commit_after>package de.peeeq.wurstscript.translation.imtojass;

import static de.peeeq.wurstscript.jassAst.JassAst.JassStatements;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtExitwhen;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtIf;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtLoop;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtReturn;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtReturnVoid;
import static de.peeeq.wurstscript.jassAst.JassAst.JassStmtSet;

import java.util.List;

import org.eclipse.jdt.annotation.NonNull;

import de.peeeq.wurstscript.jassAst.JassAst;
import de.peeeq.wurstscript.jassAst.JassExpr;
import de.peeeq.wurstscript.jassAst.JassExprFunctionCall;
import de.peeeq.wurstscript.jassAst.JassFunction;
import de.peeeq.wurstscript.jassAst.JassStatement;
import de.peeeq.wurstscript.jassAst.JassStatements;
import de.peeeq.wurstscript.jassAst.JassVar;
import de.peeeq.wurstscript.jassIm.ImExitwhen;
import de.peeeq.wurstscript.jassIm.ImExpr;
import de.peeeq.wurstscript.jassIm.ImIf;
import de.peeeq.wurstscript.jassIm.ImLoop;
import de.peeeq.wurstscript.jassIm.ImNoExpr;
import de.peeeq.wurstscript.jassIm.ImReturn;
import de.peeeq.wurstscript.jassIm.ImSet;
import de.peeeq.wurstscript.jassIm.ImSetArray;
import de.peeeq.wurstscript.jassIm.ImSetArrayMulti;
import de.peeeq.wurstscript.jassIm.ImSetArrayTuple;
import de.peeeq.wurstscript.jassIm.ImSetTuple;
import de.peeeq.wurstscript.jassIm.ImStmt;
import de.peeeq.wurstscript.jassIm.ImStmts;

public class StatementTranslation {


	public static void translate(ImExitwhen imExitwhen, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		stmts.add(JassStmtExitwhen(imExitwhen.getCondition().translate(translator)));
	}

	public static void translate(ImIf imIf, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		JassExpr cond = imIf.getCondition().translate(translator);
		JassStatements thenBlock = JassStatements(); 
		imIf.getThenBlock().translate(thenBlock, f, translator);
		JassStatements elseBlock = JassStatements();
		imIf.getElseBlock().translate(elseBlock, f, translator);
		stmts.add(JassStmtIf(cond, thenBlock, elseBlock));
	}


	public static void translate(ImLoop imLoop, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		JassStatements body = JassStatements();
		imLoop.getBody().translate(body, f, translator);
		stmts.add(JassStmtLoop(body));
	}

	public static void translate(ImReturn imReturn, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		if (imReturn.getReturnValue() instanceof ImNoExpr) {
			stmts.add(JassStmtReturnVoid());
		} else {
			ImExpr e = (ImExpr) imReturn.getReturnValue();
			JassExpr returnValue = e.translate(translator);
			stmts.add(JassStmtReturn(returnValue));
		}
	}

	public static void translate(ImSet imSet, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		JassVar vars = translator.getJassVarFor(imSet.getLeft());
		JassExpr exprs = imSet.getRight().translate(translator);
		stmts.add(JassStmtSet(vars.getName(), exprs));
	}

	public static void translate(ImExpr imExpr, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		JassExpr expr = imExpr.translate(translator);
		// only add the function calls from this expression, the rest can not have any side effects
		expr.accept(new JassExpr.DefaultVisitor() {
			@Override
			public void visit(JassExprFunctionCall fc) {
				stmts.add(JassAst.JassStmtCall(fc.getFuncName(), fc.getArguments().copy()));
			}
		});
	}

	

	public static void translate(ImSetArray imSet, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		JassVar leftVar = translator.getJassVarFor(imSet.getLeft());
		JassExpr right = imSet.getRight().translate(translator);
		stmts.add(JassAst.JassStmtSetArray(leftVar.getName(), imSet.getIndex().translate(translator), right));			
	}
	
	public static void translate(ImSetArrayTuple imSet, List<JassStatement> stmts, JassFunction f,
			ImToJassTranslator translator) {
		throw new Error("tuples should be eliminated in earlier phase");
	}

	public static void translate(ImSetTuple imSet, List<JassStatement> stmts, JassFunction f, ImToJassTranslator translator) {
		throw new Error("tuples should be eliminated in earlier phase");
{'fraction_non_alphanumeric': 0.1033329489101603, 'fraction_numerical': 0.0, 'mean_word_length': 6.4694229112833765, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, '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': '6444857', 'n_tokens_mistral': 3245, 'n_tokens_neox': 3141, 'n_words': 530}