<commit_before>//=======================================================================
// Copyright <NAME> 2011-2013.
// 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 <memory>
#include <vector>
#include <string>
#include <algorithm>

#include "SemanticalException.hpp"
#include "Type.hpp"
#include "GlobalContext.hpp"
#include "FunctionContext.hpp"
#include "mangling.hpp"
#include "VisitorUtils.hpp"

#include "ast/structure_member_collection.hpp"
#include "ast/SourceFile.hpp"
#include "ast/TypeTransformer.hpp"

using namespace eddic;

void ast::StructureMemberCollectionPass::apply_struct(ast::Struct& struct_, bool indicator){
    if(indicator){
        return;
    }

    auto signature = context->get_struct(struct_.Content->struct_type->mangle());
    std::vector<std::string> names;

    for(auto& block : struct_.Content->blocks){
        if(auto* ptr = boost::get<ast::MemberDeclaration>(&block)){
            auto& member = *ptr;

            if(std::find(names.begin(), names.end(), member.Content->name) != names.end()){
                throw SemanticalException("The member " + member.Content->name + " has already been defined", member.Content->position);
            }

            names.push_back(member.Content->name);

            auto member_type = visit(ast::TypeTransformer(context), member.Content->type);
            signature->members.push_back(std::make_shared<Member>(member.Content->name, member_type));
        } else if(auto* ptr = boost::get<ast::ArrayDeclaration>(&block)){
            auto& member = *ptr;

            auto name = member.Content->arrayName;

            if(std::find(names.begin(), names.end(), name) != names.end()){
                throw SemanticalException("The member " + name + " has already been defined", member.Content->position);
            }

            names.push_back(name);

            auto data_member_type = visit(ast::TypeTransformer(context), member.Content->arrayType);

            if(data_member_type->is_array()){
                throw SemanticalException("Multidimensional arrays are not permitted", member.Content->position);
            }

            if(auto* ptr = boost::get<ast::Integer>(&member.Content->size)){
                signature->members.push_back(std::make_shared<Member>(name, new_array_type(data_member_type, ptr->value)));
            } else {
                throw SemanticalException("Only arrays of fixed size are supported", member.Content->position);
            }
        }
    }
}<commit_msg>Order member of the structure<commit_after>//=======================================================================
// Copyright <NAME> 2011-2013.
// 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 <memory>
#include <vector>
#include <string>
#include <algorithm>

#include "SemanticalException.hpp"
#include "Type.hpp"
#include "GlobalContext.hpp"
#include "FunctionContext.hpp"
#include "mangling.hpp"
#include "VisitorUtils.hpp"

#include "ast/structure_member_collection.hpp"
#include "ast/SourceFile.hpp"
#include "ast/TypeTransformer.hpp"

using namespace eddic;

void ast::StructureMemberCollectionPass::apply_struct(ast::Struct& struct_, bool indicator){
    if(indicator){
        return;
    }

    auto signature = context->get_struct(struct_.Content->struct_type->mangle());
    std::vector<std::string> names;

    for(auto& block : struct_.Content->blocks){
        if(auto* ptr = boost::get<ast::MemberDeclaration>(&block)){
            auto& member = *ptr;

            if(std::find(names.begin(), names.end(), member.Content->name) != names.end()){
                throw SemanticalException("The member " + member.Content->name + " has already been defined", member.Content->position);
            }

            names.push_back(member.Content->name);

            auto member_type = visit(ast::TypeTransformer(context), member.Content->type);
            signature->members.push_back(std::make_shared<Member>(member.Content->name, member_type));
        } else if(auto* ptr = boost::get<ast::ArrayDeclaration>(&block)){
            auto& member = *ptr;

            auto name = member.Content->arrayName;

            if(std::find(names.begin(), names.end(), name) != names.end()){
                throw SemanticalException("The member " + name + " has already been defined", member.Content->position);
            }

            names.push_back(name);

            auto data_member_type = visit(ast::TypeTransformer(context), member.Content->arrayType);

            if(data_member_type->is_array()){
                throw SemanticalException("Multidimensional arrays are not permitted", member.Content->position);
            }

            if(auto* ptr = boost::get<ast::Integer>(&member.Content->size)){
                signature->members.push_back(std::make_shared<Member>(name, new_array_type(data_member_type, ptr->value)));
            } else {
                throw SemanticalException("Only arrays of fixed size are supported", member.Content->position);
            }
        }
    }

    std::sort(signature->members.begin(), signature->members.end(), 
            [](const std::shared_ptr<Member>& lhs, const std::shared_ptr<Member>& rhs){
                if(lhs->type == CHAR || lhs->type == BOOL){
                    return false;
                } else if(rhs->type == CHAR || rhs->type == BOOL){
                    return true;
                } else {
                    return false;
                }
            });
}
{'fraction_non_alphanumeric': 0.18410686761431752, 'fraction_numerical': 0.004795341668093852, 'mean_word_length': 3.089635854341737, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 73, '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': '5987544', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1531, 'n_words': 312}