<commit_before>#ifndef BFC_OPT_PROGRAM_VISITOR_HPP
#define BFC_OPT_PROGRAM_VISITOR_HPP

#include <stdexcept>
#include <string>
#include <vector>
#include "ast/visitor.hpp"
#include "opts/opt_seq_base_visitor"

namespace bfc {
namespace ast {

class opt_program_visitor : public visitor {
    
    using error = std::runtime_error;
    using string = std::string;
    using vector = std::vector<opt_seq_base_visitor>;

public:

    opt_program_visitor(vector vec) : opts(std::move(vec)) {}

    node result(void) {
        return opt_program;
    }

    status visit(program &node) {
        node res;
        for (const auto &elem : opts) {
            res.accept(elem);
            res = elem.result();
        }
            
  }
    }
    
    status visit(const program &node) {
        // TODO launch optimizations here
    }
    
    status visit(set &node) {
       throw create_type_err("SET");
    }
    
    status visit(const set &node) {
        throw create_type_err("SET);
    }
    
    status visit(add &node) {
        throw create_type_err("ADD");
    }<commit_msg>Update program visitor<commit_after>#ifndef BFC_OPT_PROGRAM_VISITOR_HPP
#define BFC_OPT_PROGRAM_VISITOR_HPP

#include <stdexcept>
#include <string>
#include <vector>
#include "ast/visitor.hpp"
#include "opts/opt_seq_base_visitor"

namespace bfc {
namespace ast {

class opt_program_visitor : public visitor {
    
    using error = std::runtime_error;
    using string = std::string;
    using vector = std::vector<opt_seq_base_visitor>;

public:

    opt_program_visitor(vector vec) : opts(std::move(vec)) {
        if (opts.empty()) {
            // add a single copying visitor
            opt_seq_base_visitor cpy;
            opts.push_back(cpy);
        }
    }

    node result(void) {
        return opt_program;
    }

    status visit(program &node) {
        node.accept(opts[0]);
        seq result =  opts[0].result();
        if(opts.size() > 1) {
            for (int i = 1; i < opts.size(); ++i) {
                result.accept(opts[i]);
                result = opts[i].result();
            }
        }
        opt_program.reset(new program(node.loc(), result);
    }
    
    status visit(const program &node) {
        node.accept(opts[0]);
        seq result =  opts[0].result();
        if(opts.size() > 1) {
            for (int i = 1; i < opts.size(); ++i) {
                result.accept(opts[i]);
                result = opts[i].result();
            }
        }
        opt_program.reset(new program(node.loc(), result);
    }
    
    status visit(set &node) {
       throw create_type_err("SET");
    }
    
    status visit(const set &node) {
        throw create_type_err("SET);
    }
    
    status visit(add &node) {
        throw create_type_err("ADD");
    }
{'fraction_non_alphanumeric': 0.12207418077061577, 'fraction_numerical': 0.0028808066258552397, 'mean_word_length': 2.222737819025522, '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': '2106974', 'n_tokens_mistral': 915, 'n_tokens_neox': 890, 'n_words': 188}