<commit_before>#include <algorithm>
#include <cctype>
#include <llvm/Support/ErrorOr.h>
#include <llvm/Support/Program.h>
#include "utility.h"

using namespace delta;

bool delta::treatWarningsAsErrors;

void delta::skipWhitespace(llvm::StringRef& string) {
    string = string.drop_while([](unsigned char c) { return std::isspace(c); });
}

llvm::StringRef delta::readWord(llvm::StringRef& string) {
    auto word = string.take_while([](unsigned char c) { return std::isgraph(c); });
    string = string.drop_front(word.size());
    return word;
}

llvm::StringRef delta::readLine(llvm::StringRef& string) {
    auto word = string.take_while([](unsigned char c) { return c != '\n'; });
    string = string.drop_front(std::min(word.size() + 1, string.size()));
    return word;
}

std::string delta::readLineFromFile(SourceLocation location) {
    std::ifstream file(location.file);

    while (--location.line) {
        file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    }

    std::string lineContent;
    std::getline(file, lineContent);
    return lineContent;
}

void delta::printDiagnostic(SourceLocation location, llvm::StringRef type,
                            llvm::raw_ostream::Colors color, llvm::StringRef message) {
    if (llvm::outs().has_colors()) {
        llvm::outs().changeColor(llvm::raw_ostream::SAVEDCOLOR, true);
    }

    if (location.file && *location.file) {
        llvm::outs() << location.file;
        if (location.isValid()) {
            llvm::outs() << ':' << location.line << ':' << location.column;
        }
        llvm::outs() << ": ";
    }

    printColored(type, color);
    printColored(": ", color);
    printColored(message, llvm::raw_ostream::SAVEDCOLOR);

    if (location.file && *location.file && location.isValid()) {
        auto line = readLineFromFile(location);
        llvm::outs() << '\n' << line << '\n';

        for (char ch : line.substr(0, location.column - 1)) {
            llvm::outs() << (ch != '\t' ? ' ' : '\t');
        }
        printColored('^', llvm::raw_ostream::GREEN);
    }

    llvm::outs() << '\n';
}

void CompileError::print() const {
    printDiagnostic(location, "error", llvm::raw_ostream::RED, message);

    for (auto& note : notes) {
        printDiagnostic(note.getLocation(), "note", llvm::raw_ostream::BLACK, note.getMessage());
    }

    llvm::outs().flush();
}

std::string delta::getCCompilerPath() {
    for (const char* compiler : { "cc", "gcc", "clang" }) {
        if (auto path = llvm::sys::findProgramByName(compiler)) {<commit_msg>Add MSVC compiler to list of C compilers<commit_after>#include <algorithm>
#include <cctype>
#include <llvm/Support/ErrorOr.h>
#include <llvm/Support/Program.h>
#include "utility.h"

using namespace delta;

bool delta::treatWarningsAsErrors;

void delta::skipWhitespace(llvm::StringRef& string) {
    string = string.drop_while([](unsigned char c) { return std::isspace(c); });
}

llvm::StringRef delta::readWord(llvm::StringRef& string) {
    auto word = string.take_while([](unsigned char c) { return std::isgraph(c); });
    string = string.drop_front(word.size());
    return word;
}

llvm::StringRef delta::readLine(llvm::StringRef& string) {
    auto word = string.take_while([](unsigned char c) { return c != '\n'; });
    string = string.drop_front(std::min(word.size() + 1, string.size()));
    return word;
}

std::string delta::readLineFromFile(SourceLocation location) {
    std::ifstream file(location.file);

    while (--location.line) {
        file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    }

    std::string lineContent;
    std::getline(file, lineContent);
    return lineContent;
}

void delta::printDiagnostic(SourceLocation location, llvm::StringRef type,
                            llvm::raw_ostream::Colors color, llvm::StringRef message) {
    if (llvm::outs().has_colors()) {
        llvm::outs().changeColor(llvm::raw_ostream::SAVEDCOLOR, true);
    }

    if (location.file && *location.file) {
        llvm::outs() << location.file;
        if (location.isValid()) {
            llvm::outs() << ':' << location.line << ':' << location.column;
        }
        llvm::outs() << ": ";
    }

    printColored(type, color);
    printColored(": ", color);
    printColored(message, llvm::raw_ostream::SAVEDCOLOR);

    if (location.file && *location.file && location.isValid()) {
        auto line = readLineFromFile(location);
        llvm::outs() << '\n' << line << '\n';

        for (char ch : line.substr(0, location.column - 1)) {
            llvm::outs() << (ch != '\t' ? ' ' : '\t');
        }
        printColored('^', llvm::raw_ostream::GREEN);
    }

    llvm::outs() << '\n';
}

void CompileError::print() const {
    printDiagnostic(location, "error", llvm::raw_ostream::RED, message);

    for (auto& note : notes) {
        printDiagnostic(note.getLocation(), "note", llvm::raw_ostream::BLACK, note.getMessage());
    }

    llvm::outs().flush();
}

std::string delta::getCCompilerPath() {
    for (const char* compiler : { "cc", "gcc", "clang", "cl.exe" }) {
        if (auto path = llvm::sys::findProgramByName(compiler)) {
{'fraction_non_alphanumeric': 0.18369332554971785, 'fraction_numerical': 0.0011675423234092236, 'mean_word_length': 3.5729537366548043, 'pattern_counts': {'":': 4, '<': 57, '<?xml version=': 0, '>': 13, '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': '4003389', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1622, 'n_words': 316}