<commit_before>package wich.codegen;

import org.antlr.symtab.Scope;
import org.antlr.symtab.Type;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.stringtemplate.v4.STGroup;
import org.stringtemplate.v4.STGroupFile;
import wich.codegen.model.ArgDef;
import wich.codegen.model.AssignStat;
import wich.codegen.model.Block;
import wich.codegen.model.BlockStatement;
import wich.codegen.model.BooleanType;
import wich.codegen.model.CallStat;
import wich.codegen.model.CompositeModelObject;
import wich.codegen.model.ElementAssignStat;
import wich.codegen.model.File;
import wich.codegen.model.FloatType;
import wich.codegen.model.Func;
import wich.codegen.model.FuncBlock;
import wich.codegen.model.FuncCallVoid;
import wich.codegen.model.IfStat;
import wich.codegen.model.IntType;
import wich.codegen.model.MainBlock;
import wich.codegen.model.MainFunc;
import wich.codegen.model.OutputModelObject;
import wich.codegen.model.PrintBooleanStat;
import wich.codegen.model.PrintFloatStat;
import wich.codegen.model.PrintIntStat;
import wich.codegen.model.PrintNewLine;
import wich.codegen.model.PrintStringStat;
import wich.codegen.model.PrintVectorStat;
import wich.codegen.model.RefCountDEREF;
import wich.codegen.model.RefCountDEREFVector;
import wich.codegen.model.RefCountREF;
import wich.codegen.model.RefCountREFVector;
import wich.codegen.model.ReturnHeapVarStat;
import wich.codegen.model.ReturnStat;
import wich.codegen.model.ReturnVectorHeapVarStat;
import wich.codegen.model.Stat;
import wich.codegen.model.StringDecl;
import wich.codegen.model.expr.StringLiteral;
import wich.codegen.model.StringType;
import wich.codegen.model.StringVarDefStat;
import wich.codegen.model.VarDefStat;
import wich.codegen.model.VarInitStat;
import wich.codegen.model.VectorType;
import wich.codegen.model.VectorVarDefStat;
import wich.codegen.model.VoidType;
import wich.codegen.model.WhileStat;
import wich.codegen.model.WichType;
import wich.codegen.model.expr.BinaryOpExpr;
import wich.codegen.model.expr.BinaryPrimitiveOp;
import wich.codegen.model.expr.BinaryStringOp;
import wich.codegen.model.expr.BinaryVectorOp;
import wich.codegen.model.expr.Expr;
import wich.codegen.model.expr.FalseLiteral;
import wich.codegen.model.expr.FloatLiteral;
import wich.codegen.model.expr.FuncCall;
import wich.codegen.model.expr.HeapVarRef;
import wich.codegen.model.expr.IntLiteral;
import wich.codegen.model.expr.NegateExpr;
import wich.codegen.model.expr.NotExpr;
import wich.codegen.model.expr.StringIndexExpr;
import wich.codegen.model.expr.TrueLiteral;
import wich.codegen.model.expr.VarRef;
import wich.codegen.model.expr.VectorElement;
import wich.codegen.model.expr.VectorIndexExpr;
import wich.codegen.model.expr.VectorLiteral;
import wich.codegen.model.expr.promotion.FloatFromInt;
import wich.codegen.model.expr.promotion.StringFromFloat;
import wich.codegen.model.expr.promotion.StringFromInt;
import wich.codegen.model.expr.promotion.StringFromVector;
import wich.codegen.model.expr.promotion.VectorFromFloat;
import wich.codegen.model.expr.promotion.VectorFromInt;
import wich.parser.WichBaseVisitor;
import wich.parser.WichParser;
import wich.semantics.SymbolTable;
import wich.semantics.symbols.WBuiltInTypeSymbol;
import wich.semantics.symbols.WFunctionSymbol;
import wich.semantics.symbols.WString;
import wich.semantics.symbols.WVariableSymbol;
import wich.semantics.symbols.WVector;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static wich.parser.WichParser.FunctionContext;

public class CodeGenerator extends WichBaseVisitor<OutputModelObject> {
	protected int blockNumber = 0; // tracks block number within each method
	protected STGroup templates;
	protected final SymbolTable symtab;
	protected File currentFile;
	protected Scope currentScope;
	protected Block currentBlock;
	protected WFunctionSymbol currentFunction;

	protected List<StringDecl> strDecls = new ArrayList<>();
	protected Map<String, Integer> nameOccurrenceMap = new HashMap<>(); // tracks name occurrence across scopes

	protected static final String PROMO = "promo";

	public CodeGenerator(SymbolTable symtab) {
		this.templates = new STGroupFile("wich.stg");
		this.symtab = symtab;
	}

	public File generate(ParserRuleContext tree) {
		return (File)visit(tree);
	}

	// TODO: try to add aggregate value thing

	// V I S I T O R  M E T H O D S

	@Override
	public OutputModelObject visitScript(@NotNull WichParser.ScriptContext ctx) {
		pushScope(symtab.getGlobalScope());<commit_msg>rm unused STGroupFile<commit_after>package wich.codegen;

import org.antlr.symtab.Scope;
import org.antlr.symtab.Type;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import wich.codegen.model.ArgDef;
import wich.codegen.model.AssignStat;
import wich.codegen.model.Block;
import wich.codegen.model.BlockStatement;
import wich.codegen.model.BooleanType;
import wich.codegen.model.CallStat;
import wich.codegen.model.CompositeModelObject;
import wich.codegen.model.ElementAssignStat;
import wich.codegen.model.File;
import wich.codegen.model.FloatType;
import wich.codegen.model.Func;
import wich.codegen.model.FuncBlock;
import wich.codegen.model.FuncCallVoid;
import wich.codegen.model.IfStat;
import wich.codegen.model.IntType;
import wich.codegen.model.MainBlock;
import wich.codegen.model.MainFunc;
import wich.codegen.model.OutputModelObject;
import wich.codegen.model.PrintBooleanStat;
import wich.codegen.model.PrintFloatStat;
import wich.codegen.model.PrintIntStat;
import wich.codegen.model.PrintNewLine;
import wich.codegen.model.PrintStringStat;
import wich.codegen.model.PrintVectorStat;
import wich.codegen.model.RefCountDEREF;
import wich.codegen.model.RefCountDEREFVector;
import wich.codegen.model.RefCountREF;
import wich.codegen.model.RefCountREFVector;
import wich.codegen.model.ReturnHeapVarStat;
import wich.codegen.model.ReturnStat;
import wich.codegen.model.ReturnVectorHeapVarStat;
import wich.codegen.model.Stat;
import wich.codegen.model.StringDecl;
import wich.codegen.model.StringType;
import wich.codegen.model.StringVarDefStat;
import wich.codegen.model.VarDefStat;
import wich.codegen.model.VarInitStat;
import wich.codegen.model.VectorType;
import wich.codegen.model.VectorVarDefStat;
import wich.codegen.model.VoidType;
import wich.codegen.model.WhileStat;
import wich.codegen.model.WichType;
import wich.codegen.model.expr.BinaryOpExpr;
import wich.codegen.model.expr.BinaryPrimitiveOp;
import wich.codegen.model.expr.BinaryStringOp;
import wich.codegen.model.expr.BinaryVectorOp;
import wich.codegen.model.expr.Expr;
import wich.codegen.model.expr.FalseLiteral;
import wich.codegen.model.expr.FloatLiteral;
import wich.codegen.model.expr.FuncCall;
import wich.codegen.model.expr.HeapVarRef;
import wich.codegen.model.expr.IntLiteral;
import wich.codegen.model.expr.NegateExpr;
import wich.codegen.model.expr.NotExpr;
import wich.codegen.model.expr.StringIndexExpr;
import wich.codegen.model.expr.StringLiteral;
import wich.codegen.model.expr.TrueLiteral;
import wich.codegen.model.expr.VarRef;
import wich.codegen.model.expr.VectorElement;
import wich.codegen.model.expr.VectorIndexExpr;
import wich.codegen.model.expr.VectorLiteral;
import wich.codegen.model.expr.promotion.FloatFromInt;
import wich.codegen.model.expr.promotion.StringFromFloat;
import wich.codegen.model.expr.promotion.StringFromInt;
import wich.codegen.model.expr.promotion.StringFromVector;
import wich.codegen.model.expr.promotion.VectorFromFloat;
import wich.codegen.model.expr.promotion.VectorFromInt;
import wich.parser.WichBaseVisitor;
import wich.parser.WichParser;
import wich.semantics.SymbolTable;
import wich.semantics.symbols.WBuiltInTypeSymbol;
import wich.semantics.symbols.WFunctionSymbol;
import wich.semantics.symbols.WString;
import wich.semantics.symbols.WVariableSymbol;
import wich.semantics.symbols.WVector;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static wich.parser.WichParser.FunctionContext;

public class CodeGenerator extends WichBaseVisitor<OutputModelObject> {
	protected int blockNumber = 0; // tracks block number within each method
	protected final SymbolTable symtab;
	protected File currentFile;
	protected Scope currentScope;
	protected Block currentBlock;
	protected WFunctionSymbol currentFunction;

	protected List<StringDecl> strDecls = new ArrayList<>();
	protected Map<String, Integer> nameOccurrenceMap = new HashMap<>(); // tracks name occurrence across scopes

	protected static final String PROMO = "promo";

	public CodeGenerator(SymbolTable symtab) {
		this.symtab = symtab;
	}

	public File generate(ParserRuleContext tree) {
		return (File)visit(tree);
	}

	// TODO: try to add aggregate value thing

	// V I S I T O R  M E T H O D S

	@Override
	public OutputModelObject visitScript(@NotNull WichParser.ScriptContext ctx) {
		pushScope(symtab.getGlobalScope());
{'fraction_non_alphanumeric': 0.09913983237759152, 'fraction_numerical': 0.0011027790030877812, 'mean_word_length': 6.296057924376508, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2630637', 'n_tokens_mistral': 2884, 'n_tokens_neox': 3006, 'n_words': 541}