<commit_before>//=======================================================================
// Copyright <NAME> 2011.
// 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 "assert.hpp"
#include "SymbolTable.hpp"

using namespace eddic;

//Global symbol table
SymbolTable eddic::symbols;

SymbolTable::SymbolTable(){
    reset();
}

void SymbolTable::reset(){
    functions.clear();
    structs.clear();
    
    //Add the standard functions to the function table
    defineStandardFunctions();
}

FunctionMap::const_iterator SymbolTable::begin(){
    return functions.cbegin();
}

FunctionMap::const_iterator SymbolTable::end(){
    return functions.cend();
}

void SymbolTable::addFunction(std::shared_ptr<Function> function){
    functions[function->mangledName] = function;
}

std::shared_ptr<Function> SymbolTable::getFunction(const std::string& function){
    return functions[function];
}

bool SymbolTable::exists(const std::string& function){
    return functions.find(function) != functions.end();
}

void SymbolTable::add_struct(std::shared_ptr<Struct> struct_){
    structs[struct_->name] = struct_;
}

std::shared_ptr<Struct> SymbolTable::get_struct(const std::string& struct_){
    return structs[struct_];
}

int SymbolTable::member_offset(std::shared_ptr<Struct> struct_, const std::string& member){
    int offset = 0;

    for(auto& m : struct_->members){
        if(m.name == member){
            return offset;
        }

        offset -= size(m.type);
    }

    ASSERT_PATH_NOT_TAKEN("The member is not part of the struct");
}

int SymbolTable::member_offset_reverse(std::shared_ptr<Struct> struct_, const std::string& member){
    int offset = -size_of_struct(struct_->name) + 8; 
    //member_offset(struct_, struct_->members.back().name);

    for(auto& m : struct_->members){
        if(m.name == member){
            return offset;
        }<commit_msg>Fix the offsets for member of structs for 32 bits<commit_after>//=======================================================================
// Copyright <NAME> 2011.
// 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 "assert.hpp"
#include "SymbolTable.hpp"

using namespace eddic;

//Global symbol table
SymbolTable eddic::symbols;

SymbolTable::SymbolTable(){
    reset();
}

void SymbolTable::reset(){
    functions.clear();
    structs.clear();
    
    //Add the standard functions to the function table
    defineStandardFunctions();
}

FunctionMap::const_iterator SymbolTable::begin(){
    return functions.cbegin();
}

FunctionMap::const_iterator SymbolTable::end(){
    return functions.cend();
}

void SymbolTable::addFunction(std::shared_ptr<Function> function){
    functions[function->mangledName] = function;
}

std::shared_ptr<Function> SymbolTable::getFunction(const std::string& function){
    return functions[function];
}

bool SymbolTable::exists(const std::string& function){
    return functions.find(function) != functions.end();
}

void SymbolTable::add_struct(std::shared_ptr<Struct> struct_){
    structs[struct_->name] = struct_;
}

std::shared_ptr<Struct> SymbolTable::get_struct(const std::string& struct_){
    return structs[struct_];
}

int SymbolTable::member_offset(std::shared_ptr<Struct> struct_, const std::string& member){
    int offset = 0;

    for(auto& m : struct_->members){
        if(m.name == member){
            return offset;
        }

        offset -= size(m.type);
    }

    ASSERT_PATH_NOT_TAKEN("The member is not part of the struct");
}

int SymbolTable::member_offset_reverse(std::shared_ptr<Struct> struct_, const std::string& member){
    int offset = -size_of_struct(struct_->name) + size(BaseType::INT); 
    //member_offset(struct_, struct_->members.back().name);

    for(auto& m : struct_->members){
        if(m.name == member){
            return offset;
        }
{'fraction_non_alphanumeric': 0.19799139167862267, 'fraction_numerical': 0.005978000956480153, 'mean_word_length': 4.5625, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, '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': '6570271', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1170, 'n_words': 267}