<commit_before>//=======================================================================
// Copyright <NAME> 2011-2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================

#include <iostream>

#include "ast/Printer.hpp"

#include "variant.hpp"
#include "assert.hpp"
#include "VisitorUtils.hpp"
#include "Variable.hpp"

using namespace eddic;

namespace {

struct DebugVisitor : public boost::static_visitor<> {
    mutable int level = 0;

    std::string indent() const {
        std::string acc = "";
        for(int i = 0; i < level; ++i){
            acc += "    ";
        }
        return acc;
    }

    template<typename Container>
    void print_each_sub(Container& container) const {
        level++;
        visit_each(*this, container);    
        level--;
    }

    template<typename Container>
    void print_each_sub(Container& container, const std::string& title) const {
        std::cout << indent() << title << std::endl; 
        print_each_sub(container);
    }

    template<typename Container>
    void print_each_sub_non_variant(Container& container) const {
        level++;
        visit_each_non_variant(*this, container);    
        level--;
    }

    template<typename Container>
    void print_each_sub_non_variant(Container& container, const std::string& title) const {
        std::cout << indent() << title << std::endl; 
        print_each_sub_non_variant(container);
    }

    template<typename Container>
    void print_sub(Container& container) const {
        level++;
        visit(*this, container);    
        level--;
    }

    void print_template_list(const std::vector<ast::Type>& template_types) const {
        if(!template_types.empty()){
            std::cout << "<";

            std::cout << to_string(template_types[0]);

            for(std::size_t i = 1; i < template_types.size(); ++i){
                std::cout << ", " << to_string(template_types[i]);
            }

            std::cout << ">"; 
        }
    }

    void print_template_list(const std::vector<std::string>& template_types) const {
        if(!template_types.empty()){
            std::cout << "<";

            std::cout << template_types[0];

            for(std::size_t i = 1; i < template_types.size(); ++i){
                std::cout << ", " << template_types[i];
            }

            std::cout << ">"; 
        }
    }

    template<typename Container>
    void print_sub(Container& container, const std::string& title) const {
        std::cout << indent() << title << std::endl; 
        print_sub(container);
    }

    void operator()(ast::SourceFile& program) const {
        print_each_sub(program.Content->blocks, "SourceFile");
    }

    void operator()(ast::Import& import) const {
        std::cout << indent() << "include \"" << import.file << "\"" << std::endl;
    }

    void operator()(ast::StandardImport& import) const {
        std::cout << indent() << "include <" << import.header << ">" << std::endl;
    }
    
    void operator()(ast::TemplateStruct& declaration) const {
        std::cout << indent() << "Template Struct";
        print_template_list(declaration.Content->template_types);
        std::cout << declaration.Content->name << std::endl; 
        std::cout << std::endl;
    }
    
    void operator()(ast::TemplateFunctionDeclaration& declaration) const {
        std::cout << indent() << "Template Function";
        print_template_list(declaration.Content->template_types);
        std::cout << declaration.Content->functionName << std::endl; 
        std::cout << std::endl;
    }

    void operator()(ast::FunctionDeclaration& declaration) const {
        std::cout << indent() << "Function " << declaration.Content->functionName << std::endl; 
        
        std::cout << indent() << "Parameters:" << std::endl; 
        level++;
        for(auto& param : declaration.Content->parameters){
            std::cout << indent() << param.parameterName << " : " << to_string(param.parameterType) << std::endl; 
        }
        level--;
        
        print_each_sub(declaration.Content->instructions, "Instructions:");
        std::cout << std::endl;
    }
    
    void operator()(ast::Constructor& declaration) const {
        std::cout << indent() << "Constructor" << std::endl; 
        
        std::cout << indent() << "Parameters:" << std::endl; 
        level++;
        for(auto& param : declaration.Content->parameters){
            std::cout << indent() << param.parameterName << std::endl; 
        }
        level--;
        
        print_each_sub(declaration.Content->instructions, "Instructions:");
    }
    
    void operator()(ast::Destructor& declaration) const {
        std::cout << indent() << "Destructor" << std::endl; 
        print_each_sub(declaration.Content->instructions, "Instructions:");
    }

    void operator()(ast::Struct& struct_) const {
        std::cout << indent() << "Structure declaration: " << struct_.Content->name;

        print_template_list(struct_.Content->template_types);

        std::cout << std::endl;
        
        level++;
        
        print_each_sub_non_variant(struct_.Content->members, "Members");
        print_each_sub_non_variant(struct_.Content->constructors, "Constructors");
        print_each_sub_non_variant(struct_.Content->destructors, "Destructors");
        print_each_sub_non_variant(struct_.Content->functions, "Functions");
        print_each_sub_non_variant(struct_.Content->template_functions, "Template Functions");
        <commit_msg>Add support for printing array members<commit_after>//=======================================================================
// Copyright <NAME> 2011-2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================

#include <iostream>

#include "ast/Printer.hpp"

#include "variant.hpp"
#include "assert.hpp"
#include "VisitorUtils.hpp"
#include "Variable.hpp"

using namespace eddic;

namespace {

struct DebugVisitor : public boost::static_visitor<> {
    mutable int level = 0;

    std::string indent() const {
        std::string acc = "";
        for(int i = 0; i < level; ++i){
            acc += "    ";
        }
        return acc;
    }

    template<typename Container>
    void print_each_sub(Container& container) const {
        level++;
        visit_each(*this, container);    
        level--;
    }

    template<typename Container>
    void print_each_sub(Container& container, const std::string& title) const {
        std::cout << indent() << title << std::endl; 
        print_each_sub(container);
    }

    template<typename Container>
    void print_each_sub_non_variant(Container& container) const {
        level++;
        visit_each_non_variant(*this, container);    
        level--;
    }

    template<typename Container>
    void print_each_sub_non_variant(Container& container, const std::string& title) const {
        std::cout << indent() << title << std::endl; 
        print_each_sub_non_variant(container);
    }

    template<typename Container>
    void print_sub(Container& container) const {
        level++;
        visit(*this, container);    
        level--;
    }

    void print_template_list(const std::vector<ast::Type>& template_types) const {
        if(!template_types.empty()){
            std::cout << "<";

            std::cout << to_string(template_types[0]);

            for(std::size_t i = 1; i < template_types.size(); ++i){
                std::cout << ", " << to_string(template_types[i]);
            }

            std::cout << ">"; 
        }
    }

    void print_template_list(const std::vector<std::string>& template_types) const {
        if(!template_types.empty()){
            std::cout << "<";

            std::cout << template_types[0];

            for(std::size_t i = 1; i < template_types.size(); ++i){
                std::cout << ", " << template_types[i];
            }

            std::cout << ">"; 
        }
    }

    template<typename Container>
    void print_sub(Container& container, const std::string& title) const {
        std::cout << indent() << title << std::endl; 
        print_sub(container);
    }

    void operator()(ast::SourceFile& program) const {
        print_each_sub(program.Content->blocks, "SourceFile");
    }

    void operator()(ast::Import& import) const {
        std::cout << indent() << "include \"" << import.file << "\"" << std::endl;
    }

    void operator()(ast::StandardImport& import) const {
        std::cout << indent() << "include <" << import.header << ">" << std::endl;
    }
    
    void operator()(ast::TemplateStruct& declaration) const {
        std::cout << indent() << "Template Struct";
        print_template_list(declaration.Content->template_types);
        std::cout << declaration.Content->name << std::endl; 
        std::cout << std::endl;
    }
    
    void operator()(ast::TemplateFunctionDeclaration& declaration) const {
        std::cout << indent() << "Template Function";
        print_template_list(declaration.Content->template_types);
        std::cout << declaration.Content->functionName << std::endl; 
        std::cout << std::endl;
    }

    void operator()(ast::FunctionDeclaration& declaration) const {
        std::cout << indent() << "Function " << declaration.Content->functionName << std::endl; 
        
        std::cout << indent() << "Parameters:" << std::endl; 
        level++;
        for(auto& param : declaration.Content->parameters){
            std::cout << indent() << param.parameterName << " : " << to_string(param.parameterType) << std::endl; 
        }
        level--;
        
        print_each_sub(declaration.Content->instructions, "Instructions:");
        std::cout << std::endl;
    }
    
    void operator()(ast::Constructor& declaration) const {
        std::cout << indent() << "Constructor" << std::endl; 
        
        std::cout << indent() << "Parameters:" << std::endl; 
        level++;
        for(auto& param : declaration.Content->parameters){
            std::cout << indent() << param.parameterName << std::endl; 
        }
        level--;
        
        print_each_sub(declaration.Content->instructions, "Instructions:");
    }
    
    void operator()(ast::Destructor& declaration) const {
        std::cout << indent() << "Destructor" << std::endl; 
        print_each_sub(declaration.Content->instructions, "Instructions:");
    }

    void operator()(ast::Struct& struct_) const {
        std::cout << indent() << "Structure declaration: " << struct_.Content->name;

        print_template_list(struct_.Content->template_types);

        std::cout << std::endl;
        
        level++;
        
        print_each_sub_non_variant(struct_.Content->members, "Members");
        print_each_sub_non_variant(struct_.Content->arrays, "Arrays");
        print_each_sub_non_variant(struct_.Content->constructors, "Constructors");
        print_each_sub_non_variant(struct_.Content->destructors, "Destructors");
        print_each_sub_non_variant(struct_.Content->functions, "Functions");
        print_each_sub_non_variant(struct_.Content->template_functions, "Template Functions");
        
{'fraction_non_alphanumeric': 0.17323452484742807, 'fraction_numerical': 0.0034873583260680036, 'mean_word_length': 2.7683968462549275, 'pattern_counts': {'":': 0, '<': 309, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4359675', 'n_tokens_mistral': 3248, 'n_tokens_neox': 3123, 'n_words': 611}