<commit_before>/*
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.

Author: <NAME>
*/
#include <iostream>
#include <sstream>
#include <set>
#include <string>
#include <memory>
#include <cstdlib>
#if defined(LEAN_EMSCRIPTEN)
#include <emscripten.h>
#endif
#ifndef _WINDOWS
// Support for pid
#include<unistd.h>
#endif
#include "util/debug.h"

namespace lean {
static volatile bool           g_has_violations     = false;
static volatile bool           g_enable_assertions  = true;
static std::set<std::string> * g_enabled_debug_tags = nullptr;

void initialize_debug() {
    // lazy initialization
}

void finalize_debug() {
    delete g_enabled_debug_tags;
}

bool has_violations() {
    return g_has_violations;
}
// LCOV_EXCL_START
void enable_assertions(bool f) {
    g_enable_assertions = f;
}

bool assertions_enabled() {
    return g_enable_assertions;
}

void notify_assertion_violation(const char * fileName, int line, const char * condition) {
    std::cerr << "LEAN ASSERTION VIOLATION\n";
    std::cerr << "File: " << fileName << "\n";
    std::cerr << "Line: " << line << "\n";
    std::cerr << condition << "\n";
    std::cerr.flush();
}

void enable_debug(char const * tag) {
    if (!g_enabled_debug_tags)
        g_enabled_debug_tags = new std::set<std::string>();
    g_enabled_debug_tags->insert(tag);
}

void disable_debug(char const * tag) {
    if (g_enabled_debug_tags)
        g_enabled_debug_tags->erase(tag);
}

bool is_debug_enabled(const char * tag) {
    return g_enabled_debug_tags && g_enabled_debug_tags->find(tag) != g_enabled_debug_tags->end();
}

static bool g_debug_dialog = true;

void enable_debug_dialog(bool flag) {
    g_debug_dialog = flag;
}

void invoke_debugger() {
#if defined(LEAN_EMSCRIPTEN)
    EM_ASM(debugger;);
    exit(1);
#else
    g_has_violations = true;
    if (!g_debug_dialog)
        exit(1);
    int * x = 0;
    for (;;) {
        if (std::cin.eof())
            exit(1);
        #ifdef _WINDOWS
        std::cerr << "(C)ontinue, (A)bort, (S)top\n";
        #else
        std::cerr << "(C)ontinue, (A)bort, (S)top, Invoke (G)DB\n";
        #endif
        char result;
        std::cin >> result;
        switch (result) {<commit_msg>feat(util/debug): throw exceptions for failed assertions in server mode<commit_after>/*
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.

Author: <NAME>
*/
#include <iostream>
#include <sstream>
#include <set>
#include <string>
#include <memory>
#include <cstdlib>
#if defined(LEAN_EMSCRIPTEN)
#include <emscripten.h>
#endif
#ifndef _WINDOWS
// Support for pid
#include<unistd.h>
#endif
#include "util/debug.h"

namespace lean {
static volatile bool           g_has_violations     = false;
static volatile bool           g_enable_assertions  = true;
static std::set<std::string> * g_enabled_debug_tags = nullptr;

void initialize_debug() {
    // lazy initialization
}

void finalize_debug() {
    delete g_enabled_debug_tags;
}

bool has_violations() {
    return g_has_violations;
}
// LCOV_EXCL_START
void enable_assertions(bool f) {
    g_enable_assertions = f;
}

bool assertions_enabled() {
    return g_enable_assertions;
}

void notify_assertion_violation(const char * fileName, int line, const char * condition) {
    std::cerr << "LEAN ASSERTION VIOLATION\n";
    std::cerr << "File: " << fileName << "\n";
    std::cerr << "Line: " << line << "\n";
    std::cerr << condition << "\n";
    std::cerr.flush();
}

void enable_debug(char const * tag) {
    if (!g_enabled_debug_tags)
        g_enabled_debug_tags = new std::set<std::string>();
    g_enabled_debug_tags->insert(tag);
}

void disable_debug(char const * tag) {
    if (g_enabled_debug_tags)
        g_enabled_debug_tags->erase(tag);
}

bool is_debug_enabled(const char * tag) {
    return g_enabled_debug_tags && g_enabled_debug_tags->find(tag) != g_enabled_debug_tags->end();
}

static bool g_debug_dialog = true;

void enable_debug_dialog(bool flag) {
    g_debug_dialog = flag;
}

void invoke_debugger() {
#if defined(LEAN_EMSCRIPTEN)
    EM_ASM(debugger;);
    exit(1);
#else
    g_has_violations = true;
    if (!g_debug_dialog) {
        throw unreachable_reached();
    }
    for (;;) {
        if (std::cin.eof())
            exit(1);
        #ifdef _WINDOWS
        std::cerr << "(C)ontinue, (A)bort, (S)top\n";
        #else
        std::cerr << "(C)ontinue, (A)bort, (S)top, Invoke (G)DB\n";
        #endif
        char result;
        std::cin >> result;
        switch (result) {
{'fraction_non_alphanumeric': 0.13395368967755897, 'fraction_numerical': 0.0038952607660679506, 'mean_word_length': 3.567193675889328, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 37, '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': '6568609', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1615, 'n_words': 374}