<commit_before>//
//  Mangler.cpp
//  EmojicodeCompiler
//
//  Created by <NAME> on 05/09/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

#include "Mangler.hpp"
#include "../Functions/Function.hpp"
#include "../Functions/Initializer.hpp"
#include "../Types/Class.hpp"
#include "../Types/ValueType.hpp"
#include "../Types/Type.hpp"
#include <sstream>

namespace EmojicodeCompiler {

void mangleIdentifier(std::stringstream &stream, const std::u32string &string) {
    bool first = true;
    for (auto ch : string) {
        if (first) {
            first = false;
        }
        else {
            stream << "_";
        }
        stream << std::hex << ch;
    }
}

void mangleTypeName(std::stringstream &stream, const Type &type) {
    switch (type.type()) {
        case TypeType::ValueType:
            stream << "vt_";
            break;
        case TypeType::Class:
            stream << "class_";
            break;
        case TypeType::Enum:
            stream << "enum_";
            break;
        default:
            stream << "ty_";
            break;
    }
    mangleIdentifier(stream, type.typeDefinition()->name());
}

std::string mangleClassMetaName(Class *klass) {
    std::stringstream stream;
    stream << "class_meta_";
    mangleIdentifier(stream, klass->name());
    return stream.str();
}

std::string mangleValueTypeMetaName(const Type &type) {
    std::stringstream stream;
    stream << "value_meta_";
    mangleIdentifier(stream, type.typeDefinition()->name());
    for (auto &arg : type.genericArguments()) {
        mangleTypeName(stream, arg);
    }
    return stream.str();
}

std::string mangleFunctionName(Function *function) {
    std::stringstream stream;
    if (function->owningType().type() != TypeType::NoReturn) {
        mangleTypeName(stream, function->owningType());
        if (isFullyInitializedCheckRequired(function->functionType())) {
            stream << ".init";
        }
        stream << ".";
    }
    else {
        stream << "fn_";
    }

    mangleIdentifier(stream, function->name());
    return stream.str();<commit_msg>📦 Include package name in mangled name<commit_after>//
//  Mangler.cpp
//  EmojicodeCompiler
//
//  Created by <NAME> on 05/09/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

#include "Mangler.hpp"
#include "../Functions/Function.hpp"
#include "../Functions/Initializer.hpp"
#include "../Types/Class.hpp"
#include "../Types/ValueType.hpp"
#include "../Types/Type.hpp"
#include "../Package/Package.hpp"
#include <sstream>

namespace EmojicodeCompiler {

void mangleIdentifier(std::stringstream &stream, const std::u32string &string) {
    bool first = true;
    for (auto ch : string) {
        if (first) {
            first = false;
        }
        else {
            stream << "_";
        }
        stream << std::hex << ch;
    }
}

void mangleTypeName(std::stringstream &stream, const Type &type) {
    stream << type.typePackage() << "_";
    switch (type.type()) {
        case TypeType::ValueType:
            stream << "vt_";
            break;
        case TypeType::Class:
            stream << "class_";
            break;
        case TypeType::Enum:
            stream << "enum_";
            break;
        default:
            stream << "ty_";
            break;
    }
    mangleIdentifier(stream, type.typeDefinition()->name());
}

std::string mangleClassMetaName(Class *klass) {
    std::stringstream stream;
    stream << klass->package()->name() << "_class_meta_";
    mangleIdentifier(stream, klass->name());
    return stream.str();
}

std::string mangleValueTypeMetaName(const Type &type) {
    std::stringstream stream;
    stream << type.typePackage() << "_value_meta_";
    mangleIdentifier(stream, type.typeDefinition()->name());
    for (auto &arg : type.genericArguments()) {
        mangleTypeName(stream, arg);
    }
    return stream.str();
}

std::string mangleFunctionName(Function *function) {
    std::stringstream stream;
    if (function->owningType().type() != TypeType::NoReturn) {
        mangleTypeName(stream, function->owningType());
        if (isFullyInitializedCheckRequired(function->functionType())) {
            stream << ".init";
        }
        stream << ".";
    }
    else {
        stream << "fn_";
    }

    mangleIdentifier(stream, function->name());
    return stream.str();
{'fraction_non_alphanumeric': 0.15409383624655013, 'fraction_numerical': 0.006439742410303588, 'mean_word_length': 2.5214574898785425, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 25, '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': '1546355', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1287, 'n_words': 277}