<commit_before>function same (me, sub)
    me.n_tracks = sub.n_tracks
    me.n_asyncs = sub.n_asyncs
    me.n_emits  = sub.n_emits
end

function MAX_all (me, t)
    t = t or me
    me.n_tracks = 0
    me.n_asyncs = 0
    me.n_emits  = 0
    for _, sub in ipairs(t) do
        me.n_tracks = MAX(me.n_tracks, sub.n_tracks)
        me.n_emits  = MAX(me.n_emits,  sub.n_emits)
        -- TODO: ADD_all
        me.n_asyncs = me.n_asyncs + sub.n_asyncs
    end
end

function ADD_all (me, t)
    t = t or me
    me.n_tracks = 0
    me.n_asyncs = 0
    me.n_emits  = 0
    for _, sub in ipairs(t) do
        me.n_tracks = me.n_tracks + sub.n_tracks
        me.n_emits  = me.n_emits  + sub.n_emits
        me.n_asyncs = me.n_asyncs + sub.n_asyncs
    end
end

local STMTS = {
    Block=true, Nothing=true,
    Dcl_var=true, Dcl_int=true, Dcl_ext=true,
    Dcl_pure=true, Dcl_det=true,
    SetExp=true, SetBlock=true, SetStmt=true,
    Return=true, Async=true, Host=true,
    ParEver=true, ParOr=true, ParAnd=true, Loop=true,
    Break=true, If=true,
    Do=true, Finalize=true,
    CallStmt=true, AwaitN=true,
    AwaitExt=true, AwaitInt=true, AwaitT=true,
    EmitExtS=true,  EmitInt=true,  EmitT=true,
}

F = {
    Node_pre = function (me)
        me.n_tracks = 1
        me.n_asyncs = 0
        me.n_emits  = 0

        if STMTS[me.id] then
            me.isStmt = true
        end
    end,
    Node = function (me)
        if (not F[me.id]) and _ISNODE(me[#me]) then
            same(me, me[#me])
        end
    end,

    Block = MAX_all,

    Finalize = function (me)
        _AST.n_fins = (_AST.n_fins or 0) + 1
        for stmt in _ITER(pred_prio) do
            stmt.fins[#stmt.fins+1] = me
        end
        MAX_all(me)
    end,

    Async = function (me)
        me.n_asyncs = 1
        ASR(not _ITER'Finalize'(), me, 'invalid inside a finalizer')
    end,

    If = function (me)
        local c, t, f = unpack(me)
        f = f or c
        MAX_all(me, {t,f})
    end,

    ParEver = ADD_all,
    ParAnd  = ADD_all,
    ParOr   = ADD_all,<commit_msg>(-) finalize bug<commit_after>function same (me, sub)
    me.n_tracks = sub.n_tracks
    me.n_asyncs = sub.n_asyncs
    me.n_emits  = sub.n_emits
end

function MAX_all (me, t)
    t = t or me
    me.n_tracks = 0
    me.n_asyncs = 0
    me.n_emits  = 0
    for _, sub in ipairs(t) do
        me.n_tracks = MAX(me.n_tracks, sub.n_tracks)
        me.n_emits  = MAX(me.n_emits,  sub.n_emits)
        -- TODO: ADD_all
        me.n_asyncs = me.n_asyncs + sub.n_asyncs
    end
end

function ADD_all (me, t)
    t = t or me
    me.n_tracks = 0
    me.n_asyncs = 0
    me.n_emits  = 0
    for _, sub in ipairs(t) do
        me.n_tracks = me.n_tracks + sub.n_tracks
        me.n_emits  = me.n_emits  + sub.n_emits
        me.n_asyncs = me.n_asyncs + sub.n_asyncs
    end
end

local STMTS = {
    Block=true, Nothing=true,
    Dcl_var=true, Dcl_int=true, Dcl_ext=true,
    Dcl_pure=true, Dcl_det=true,
    SetExp=true, SetBlock=true, SetStmt=true,
    Return=true, Async=true, Host=true,
    ParEver=true, ParOr=true, ParAnd=true, Loop=true,
    Break=true, If=true,
    Do=true, Finalize=true,
    CallStmt=true, AwaitN=true,
    AwaitExt=true, AwaitInt=true, AwaitT=true,
    EmitExtS=true,  EmitInt=true,  EmitT=true,
}

_AST.n_fins = 0

F = {
    Node_pre = function (me)
        me.n_tracks = 1
        me.n_asyncs = 0
        me.n_emits  = 0

        if STMTS[me.id] then
            me.isStmt = true
        end
    end,
    Node = function (me)
        if (not F[me.id]) and _ISNODE(me[#me]) then
            same(me, me[#me])
        end
    end,

    Block = MAX_all,

    Finalize = function (me)
        _AST.n_fins = _AST.n_fins + 1
        for stmt in _ITER(pred_prio) do
            stmt.fins[#stmt.fins+1] = me
        end
        MAX_all(me)
    end,

    Async = function (me)
        me.n_asyncs = 1
        ASR(not _ITER'Finalize'(), me, 'invalid inside a finalizer')
    end,

    If = function (me)
        local c, t, f = unpack(me)
        f = f or c
        MAX_all(me, {t,f})
    end,

    ParEver = ADD_all,
    ParAnd  = ADD_all,
    ParOr   = ADD_all,
{'fraction_non_alphanumeric': 0.11563636363636363, 'fraction_numerical': 0.006303030303030303, 'mean_word_length': 2.0138787436084735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6553530', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1736, 'n_words': 377}