<commit_before>/*
 * MRustC - Rust Compiler
 * - By <NAME> (Mutabah/thePowersGang)
 *
 * ast/ast.cpp
 * - Implementation of the various AST classes
 */
#include "ast.hpp"
#include "crate.hpp"
#include "types.hpp"
#include "expr.hpp"
#include "../common.hpp"
#include <iostream>
#include "../parse/parseerror.hpp"
#include <algorithm>

#include <parse/ttstream.hpp>
#include <parse/common.hpp>
#include <parse/interpolated_fragment.hpp>
#include <synext.hpp>   // Expand_ParseAndExpand_ExprVal

namespace AST {


namespace {
    ::std::vector<Attribute> clone_mivec(const ::std::vector<Attribute>& v) {
        ::std::vector<Attribute>    ri;
        ri.reserve(v.size());
        for(const auto& i : v)
            ri.push_back( i.clone() );
        return ri;
    }
}

AttributeList AttributeList::clone() const
{
    return AttributeList( clone_mivec(m_items) );
}

void AttributeList::push_back(Attribute i)
{
    m_items.push_back( ::std::move(i) );
}
const Attribute* AttributeList::get(const char *name) const
{
    for( auto& i : m_items ) {
        if(i.name() == name) {
            //i.mark_used();
            return &i;
        }
    }
    return 0;
}

::std::ostream& operator<<(::std::ostream& os, const AttributeList& x) {
    for(const auto& i : x.m_items) {
        os << "#[" << i << "]";
    }
    return os;
}
::std::ostream& operator<<(::std::ostream& os, const AttributeName& x) {
    if(x.elems.empty())
    {
        os << "<empty>";
    }
    else
    {
        for(const auto& i : x.elems)
        {
            if(&i != &x.elems.front())
                os << "::";
            os << i;
        }
    }
    return os;
}

Attribute::Attribute(const Attribute& x):
    m_span(x.m_span),
    m_name(x.m_name),
    m_is_used(x.m_is_used)
    , m_data(x.m_data.clone())
{
}
Attribute Attribute::clone() const
{
    return Attribute(*this);
}
void Attribute::fmt(std::ostream& os) const
{
    os << m_name;
    os << m_data;
}


std::string Attribute::parse_equals_string(const AST::Crate& crate, const AST::Module& mod) const
{
    TTStream    lex(this->m_span, ParseState(), this->data());
    lex.getTokenCheck(TOK_EQUAL);
    auto n = Expand_ParseAndExpand_ExprVal(crate, mod, lex);
<commit_msg>AST - (minor) Fix init-order warning<commit_after>/*
 * MRustC - Rust Compiler
 * - By <NAME> (Mutabah/thePowersGang)
 *
 * ast/ast.cpp
 * - Implementation of the various AST classes
 */
#include "ast.hpp"
#include "crate.hpp"
#include "types.hpp"
#include "expr.hpp"
#include "../common.hpp"
#include <iostream>
#include "../parse/parseerror.hpp"
#include <algorithm>

#include <parse/ttstream.hpp>
#include <parse/common.hpp>
#include <parse/interpolated_fragment.hpp>
#include <synext.hpp>   // Expand_ParseAndExpand_ExprVal

namespace AST {


namespace {
    ::std::vector<Attribute> clone_mivec(const ::std::vector<Attribute>& v) {
        ::std::vector<Attribute>    ri;
        ri.reserve(v.size());
        for(const auto& i : v)
            ri.push_back( i.clone() );
        return ri;
    }
}

AttributeList AttributeList::clone() const
{
    return AttributeList( clone_mivec(m_items) );
}

void AttributeList::push_back(Attribute i)
{
    m_items.push_back( ::std::move(i) );
}
const Attribute* AttributeList::get(const char *name) const
{
    for( auto& i : m_items ) {
        if(i.name() == name) {
            //i.mark_used();
            return &i;
        }
    }
    return 0;
}

::std::ostream& operator<<(::std::ostream& os, const AttributeList& x) {
    for(const auto& i : x.m_items) {
        os << "#[" << i << "]";
    }
    return os;
}
::std::ostream& operator<<(::std::ostream& os, const AttributeName& x) {
    if(x.elems.empty())
    {
        os << "<empty>";
    }
    else
    {
        for(const auto& i : x.elems)
        {
            if(&i != &x.elems.front())
                os << "::";
            os << i;
        }
    }
    return os;
}

Attribute::Attribute(const Attribute& x):
    m_span(x.m_span),
    m_name(x.m_name)
    , m_data(x.m_data.clone())
    , m_is_used(x.m_is_used)
{
}
Attribute Attribute::clone() const
{
    return Attribute(*this);
}
void Attribute::fmt(std::ostream& os) const
{
    os << m_name;
    os << m_data;
}


std::string Attribute::parse_equals_string(const AST::Crate& crate, const AST::Module& mod) const
{
    TTStream    lex(this->m_span, ParseState(), this->data());
    lex.getTokenCheck(TOK_EQUAL);
    auto n = Expand_ParseAndExpand_ExprVal(crate, mod, lex);

{'fraction_non_alphanumeric': 0.1693548387096774, 'fraction_numerical': 0.00044802867383512545, 'mean_word_length': 2.8591184096802076, 'pattern_counts': {'":': 2, '<': 65, '<?xml version=': 0, '>': 29, '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': '5747777', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1580, 'n_words': 320}