<commit_before>/** Test harness for TexPHPUtil::DeserialisePHPObject().
 */
#include <iostream>
#include <memory>
#include <string>
#include <stdexcept>
#include <typeinfo>
#include <cstdlib>
#include <cstdio>
#include "Compiler.h"
#include "PHPUtil.h"
#include "util.h"


void Usage() {
    std::cerr << "usage: " << ::progname << " serialised_object_input_file\n";
    std::exit(EXIT_FAILURE);
}


void PrintString(const std::shared_ptr<PHPUtil::DataType> &string_candidate, const unsigned indent) {
    const PHPUtil::String * const string(dynamic_cast<PHPUtil::String *>(string_candidate.get()));
    if (unlikely(string == nullptr))
        Error("in PrintString: expected PHPUtil::String, found "
              + std::string(typeid(*string_candidate).name()) + " instead!");

    std::cout << std::string(indent, ' ') << "String: " << string->getName() << '(' << string->getValue() << ")\n";
}


void PrintInteger(const std::shared_ptr<PHPUtil::DataType> &integer_candidate, const unsigned indent) {
    const PHPUtil::Integer * const integer(dynamic_cast<PHPUtil::Integer *>(integer_candidate.get()));
    if (unlikely(integer == nullptr))
        Error("in PrintInteger: expected PHPUtil::Integer, found "
              + std::string(typeid(*integer_candidate).name()) + " instead!");

    std::cout << std::string(indent, ' ') << "Integer: " << integer->getName() << '(' << integer->getValue() << ")\n";
}


void PrintFloat(const std::shared_ptr<PHPUtil::DataType> &float_candidate, const unsigned indent) {
    const PHPUtil::Float * const flt(dynamic_cast<PHPUtil::Float *>(float_candidate.get()));
    if (unlikely(flt == nullptr))
        Error("in PrintFloat: expected PHPUtil::Float, found "
              + std::string(typeid(*float_candidate).name()) + " instead!");

    std::cout << std::string(indent, ' ') << "Float: " << flt->getName() << '(' << flt->getValue() << ")\n";
}


// Forward declaration:
void PrintObject(const std::shared_ptr<PHPUtil::DataType> &object_candidate, const unsigned indent);


void PrintArray(const std::shared_ptr<PHPUtil::DataType> &array_candidate, const unsigned indent) {
    const PHPUtil::Array * const array(dynamic_cast<PHPUtil::Array *>(array_candidate.get()));
    if (unlikely(array == nullptr))
        Error("in PrintArray: expected PHPUtil::Array, found " + std::string(typeid(*array_candidate).name())
              + " instead!");

    std::cout << std::string(indent, ' ') << "Array: " << array->getName() << "(size:" << array->size() << ")\n";

    for (auto entry(array->cbegin()); entry != array->cend(); ++entry) {
        std::cout << std::string(indent + 2, ' ') << "Index(" << entry->first << ")\n";
        switch (entry->second->getType()) {
        case PHPUtil::Type::OBJECT:
            PrintObject(entry->second, indent + 2);
            break;
        case PHPUtil::Type::ARRAY:
            PrintArray(entry->second, indent + 2);
            break;
        case PHPUtil::Type::STRING:
            PrintString(entry->second, indent + 2);
            break;
        case PHPUtil::Type::INTEGER:
            PrintInteger(entry->second, indent + 2);
            break;
        case PHPUtil::Type::FLOAT:
            PrintFloat(entry->second, indent + 2);
            break;
        }
    }
}


void PrintObject(const std::shared_ptr<PHPUtil::DataType> &object_candidate, const unsigned indent = 0) {
    const PHPUtil::Object * const object(dynamic_cast<PHPUtil::Object *>(object_candidate.get()));
    if (unlikely(object == nullptr))
        Error("in PrintObject: expected PHPUtil::Object, found " + std::string(typeid(*object_candidate).name())
              + " instead!");

    std::cout << std::string(indent, ' ') << "Object: ";
    const std::string &name(object->getName());
    std::cout << (name.empty() ? "*top level*" : name) << '(' << object->getClass() << ")\n";

    for (auto entry(object->cbegin()); entry != object->cend(); ++entry) {
        switch (entry->second->getType()) {
        case PHPUtil::Type::OBJECT:
            PrintObject(entry->second, indent + 2);
            break;
        case PHPUtil::Type::ARRAY:
            PrintArray(entry->second, indent + 2);
            break;
        case PHPUtil::Type::STRING:<commit_msg>Adpated for a newer compiler version.<commit_after>/** Test harness for TexPHPUtil::DeserialisePHPObject().
 */
#include <iostream>
#include <memory>
#include <string>
#include <stdexcept>
#include <typeinfo>
#include <cstdlib>
#include <cstdio>
#include "Compiler.h"
#include "PHPUtil.h"
#include "util.h"


void Usage() {
    std::cerr << "usage: " << ::progname << " serialised_object_input_file\n";
    std::exit(EXIT_FAILURE);
}


void PrintString(const std::shared_ptr<PHPUtil::DataType> &string_candidate, const unsigned indent) {
    const PHPUtil::String * const string(dynamic_cast<PHPUtil::String *>(string_candidate.get()));
    if (unlikely(string == nullptr))
        Error("in PrintString: expected PHPUtil::String, found "
              + std::string(typeid(string_candidate).name()) + " instead!");

    std::cout << std::string(indent, ' ') << "String: " << string->getName() << '(' << string->getValue() << ")\n";
}


void PrintInteger(const std::shared_ptr<PHPUtil::DataType> &integer_candidate, const unsigned indent) {
    const PHPUtil::Integer * const integer(dynamic_cast<PHPUtil::Integer *>(integer_candidate.get()));
    if (unlikely(integer == nullptr))
        Error("in PrintInteger: expected PHPUtil::Integer, found "
              + std::string(typeid(integer_candidate).name()) + " instead!");

    std::cout << std::string(indent, ' ') << "Integer: " << integer->getName() << '(' << integer->getValue() << ")\n";
}


void PrintFloat(const std::shared_ptr<PHPUtil::DataType> &float_candidate, const unsigned indent) {
    const PHPUtil::Float * const flt(dynamic_cast<PHPUtil::Float *>(float_candidate.get()));
    if (unlikely(flt == nullptr))
        Error("in PrintFloat: expected PHPUtil::Float, found "
              + std::string(typeid(float_candidate).name()) + " instead!");

    std::cout << std::string(indent, ' ') << "Float: " << flt->getName() << '(' << flt->getValue() << ")\n";
}


// Forward declaration:
void PrintObject(const std::shared_ptr<PHPUtil::DataType> &object_candidate, const unsigned indent);


void PrintArray(const std::shared_ptr<PHPUtil::DataType> &array_candidate, const unsigned indent) {
    const PHPUtil::Array * const array(dynamic_cast<PHPUtil::Array *>(array_candidate.get()));
    if (unlikely(array == nullptr))
        Error("in PrintArray: expected PHPUtil::Array, found " + std::string(typeid(array_candidate).name())
              + " instead!");

    std::cout << std::string(indent, ' ') << "Array: " << array->getName() << "(size:" << array->size() << ")\n";

    for (auto entry(array->cbegin()); entry != array->cend(); ++entry) {
        std::cout << std::string(indent + 2, ' ') << "Index(" << entry->first << ")\n";
        switch (entry->second->getType()) {
        case PHPUtil::Type::OBJECT:
            PrintObject(entry->second, indent + 2);
            break;
        case PHPUtil::Type::ARRAY:
            PrintArray(entry->second, indent + 2);
            break;
        case PHPUtil::Type::STRING:
            PrintString(entry->second, indent + 2);
            break;
        case PHPUtil::Type::INTEGER:
            PrintInteger(entry->second, indent + 2);
            break;
        case PHPUtil::Type::FLOAT:
            PrintFloat(entry->second, indent + 2);
            break;
        }
    }
}


void PrintObject(const std::shared_ptr<PHPUtil::DataType> &object_candidate, const unsigned indent = 0) {
    const PHPUtil::Object * const object(dynamic_cast<PHPUtil::Object *>(object_candidate.get()));
    if (unlikely(object == nullptr))
        Error("in PrintObject: expected PHPUtil::Object, found " + std::string(typeid(object_candidate).name())
              + " instead!");

    std::cout << std::string(indent, ' ') << "Object: ";
    const std::string &name(object->getName());
    std::cout << (name.empty() ? "*top level*" : name) << '(' << object->getClass() << ")\n";

    for (auto entry(object->cbegin()); entry != object->cend(); ++entry) {
        switch (entry->second->getType()) {
        case PHPUtil::Type::OBJECT:
            PrintObject(entry->second, indent + 2);
            break;
        case PHPUtil::Type::ARRAY:
            PrintArray(entry->second, indent + 2);
            break;
        case PHPUtil::Type::STRING:
{'fraction_non_alphanumeric': 0.18310357016613643, 'fraction_numerical': 0.0021208907741251328, 'mean_word_length': 3.630660120021822, 'pattern_counts': {'":': 0, '<': 187, '<?xml version=': 0, '>': 91, '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': '2855274', 'n_tokens_mistral': 2518, 'n_tokens_neox': 2553, 'n_words': 516}