<commit_before>"""
Build token tree from matlab-code
"""

from antlr4 import *

import collection as col

class MatlabListener(ParseTreeListener):

    def enterProgram(self, ctx):
        ctx.program = col.Program()
        ctx.program["backend"] = "program"
        ctx.program["names"] = []

        includes = col.Includes(ctx.program)
        includes["backend"] = "program"
        includes["names"] = []

        i1 = col.Include(includes, "armadillo")
        i1["value"] = "#include <armadillo>"
        i1["backend"] = "program"

        i2 = col.Include(includes, "usingarma")
        i2["value"] = "using namespace arma;"
        i2["backend"] = "program"

        func = col.Func(ctx.program, "main")
        declares = col.Declares(func)
        returns = col.Returns(func)
        params = col.Params(func)

        func["backend"] = "func_return"
        declares["backend"] = "func_return"
        returns["backend"] = "func_return"
        params["backend"] = "func_return"

        declares["names"] = []
        returns["names"] = ["_retval"]
        params["names"] = ["argc", "argv"]

        var = col.Var(returns, "_retval")
        var.type("int")
        var["backend"] = "int"
        var.declare(var)

        argc = col.Var(params, "argc")
        argc.type("int")
        argc["backend"] = "int"

        argv = col.Var(params, "argv")
        argv.type("char")
        argv["backend"] = "char"
        argv["pointer"] = 2

        ctx.node = func

    def exitProgram(self, ctx):
        ctx.program["names"].append("main")
        cs = ctx.program.children
        ctx.program.children = cs[:1] + cs[2:] + cs[1:2]

        if len(ctx.node) != 4:
            block = col.Block(ctx.node)
            block["backend"] = "code_block"

        block = ctx.node[3]
        assign = col.Assign(block)
        var = col.Var(assign, "_retvar")
        var.type("int")
        i = col.Int(assign, "0")
        i.type("int")
        i["backend"] = "int"

    def enterFunction(self, ctx):
        program = ctx.parentCtx.node.program<commit_msg>Fixing ret_val vs ret_var problem<commit_after>"""
Build token tree from matlab-code
"""

from antlr4 import *

import collection as col

class MatlabListener(ParseTreeListener):

    def enterProgram(self, ctx):
        ctx.program = col.Program()
        ctx.program["backend"] = "program"
        ctx.program["names"] = []

        includes = col.Includes(ctx.program)
        includes["backend"] = "program"
        includes["names"] = []

        i1 = col.Include(includes, "armadillo")
        i1["value"] = "#include <armadillo>"
        i1["backend"] = "program"

        i2 = col.Include(includes, "usingarma")
        i2["value"] = "using namespace arma;"
        i2["backend"] = "program"

        func = col.Func(ctx.program, "main")
        declares = col.Declares(func)
        returns = col.Returns(func)
        params = col.Params(func)

        func["backend"] = "func_return"
        declares["backend"] = "func_return"
        returns["backend"] = "func_return"
        params["backend"] = "func_return"

        declares["names"] = []
        returns["names"] = ["_retval"]
        params["names"] = ["argc", "argv"]

        var = col.Var(returns, "_retval")
        var.type("int")
        var["backend"] = "int"
        var.declare(var)

        argc = col.Var(params, "argc")
        argc.type("int")
        argc["backend"] = "int"

        argv = col.Var(params, "argv")
        argv.type("char")
        argv["backend"] = "char"
        argv["pointer"] = 2

        ctx.node = func

    def exitProgram(self, ctx):
        ctx.program["names"].append("main")
        cs = ctx.program.children
        ctx.program.children = cs[:1] + cs[2:] + cs[1:2]

        if len(ctx.node) != 4:
            block = col.Block(ctx.node)
            block["backend"] = "code_block"

        block = ctx.node[3]
        assign = col.Assign(block)
        var = col.Var(assign, "_retval")
        var.type("int")
        i = col.Int(assign, "0")
        i.type("int")
        i["backend"] = "int"

    def enterFunction(self, ctx):
        program = ctx.parentCtx.node.program
{'fraction_non_alphanumeric': 0.16522157996146436, 'fraction_numerical': 0.0072254335260115606, 'mean_word_length': 2.206949806949807, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3496400', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1282, 'n_words': 257}