<commit_before>//
//  Reporter.c
//  Emojicode
//
//  Created by <NAME> on 06.11.15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include "utf8.h"
#include "Lexer.hpp"
#include "Procedure.hpp"
#include "Class.hpp"
#include "EmojicodeCompiler.hpp"

enum ReturnManner {
    Return,
    NoReturn,
    CanReturnNothingness
};

void reportDocumentation(const Token *documentationToken) {
    if (!documentationToken) {
        return;
    }
    
    const char *d = documentationToken->value.utf8CString();
    printf("\"documentation\":");
    printJSONStringToFile(d, stdout);
    putc(',', stdout);
    delete [] d;
}

void reportType(const char *key, Type type, bool last, TypeContext tc) {
    auto returnTypeName = type.toString(tc, false).c_str();
    
    if (key) {
        printf("\"%s\": {\"package\": \"%s\", \"name\": \"%s\", \"optional\": %s}%s",
               key, type.typePackage(), returnTypeName, type.optional ? "true" : "false", last ? "" : ",");
    }
    else {
        printf("{\"package\": \"%s\", \"name\": \"%s\", \"optional\": %s}%s",
               type.typePackage(), returnTypeName, type.optional ? "true" : "false", last ? "" : ",");
    }
}

void reportGenericArguments(std::map<EmojicodeString, Type> map, std::vector<Type> constraints,
                            size_t superCount, TypeContext tc) {
    printf("\"genericArguments\": [");
    
    auto gans = std::vector<EmojicodeString>(map.size());
    for (auto it : map) {
        gans[it.second.reference - superCount] = it.first;
    }
    
    auto reported = false;
    
    for (size_t i = 0; i < gans.size(); i++) {
        auto gan = gans[i];
        auto utf8 = gan.utf8CString();
        if (reported) {
            printf(",");
        }
        printf("{\"name\": ");
        printJSONStringToFile(utf8, stdout);
        printf(",");
        reportType("constraint", constraints[i], true, tc);
        printf("}%s", i + 1 == gans.size() ? "" : ",");
        delete [] utf8;
        reported = true;
    }
    
    printf("],");
}

void reportProcedureInformation(Procedure *p, ReturnManner returnm, bool last, TypeContext tc) {
    ecCharToCharStack(p->name, nameString);
    
    printf("{");
    printf("\"name\": \"%s\",", nameString);
    
    if (returnm == Return) {
        reportType("returnType", p->returnType, false, tc);<commit_msg>🤕 Fix Generic Argument Reporter<commit_after>//
//  Reporter.c
//  Emojicode
//
//  Created by <NAME> on 06.11.15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include "utf8.h"
#include "Lexer.hpp"
#include "Procedure.hpp"
#include "Class.hpp"
#include "EmojicodeCompiler.hpp"

enum ReturnManner {
    Return,
    NoReturn,
    CanReturnNothingness
};

void reportDocumentation(const Token *documentationToken) {
    if (!documentationToken) {
        return;
    }
    
    const char *d = documentationToken->value.utf8CString();
    printf("\"documentation\":");
    printJSONStringToFile(d, stdout);
    putc(',', stdout);
    delete [] d;
}

void reportType(const char *key, Type type, bool last, TypeContext tc) {
    auto returnTypeName = type.toString(tc, false).c_str();
    
    if (key) {
        printf("\"%s\": {\"package\": \"%s\", \"name\": \"%s\", \"optional\": %s}%s",
               key, type.typePackage(), returnTypeName, type.optional ? "true" : "false", last ? "" : ",");
    }
    else {
        printf("{\"package\": \"%s\", \"name\": \"%s\", \"optional\": %s}%s",
               type.typePackage(), returnTypeName, type.optional ? "true" : "false", last ? "" : ",");
    }
}

void reportGenericArguments(std::map<EmojicodeString, Type> map, std::vector<Type> constraints,
                            size_t superCount, TypeContext tc) {
    printf("\"genericArguments\": [");
    
    auto gans = std::vector<EmojicodeString>(map.size());
    for (auto it : map) {
        gans[it.second.reference - superCount] = it.first;
    }
    
    auto reported = false;
    
    for (size_t i = 0; i < gans.size(); i++) {
        auto gan = gans[i];
        auto utf8 = gan.utf8CString();
        if (reported) {
            printf(",");
        }
        printf("{\"name\": ");
        printJSONStringToFile(utf8, stdout);
        printf(",");
        reportType("constraint", constraints[i], true, tc);
        printf("}");
        delete [] utf8;
        reported = true;
    }
    
    printf("],");
}

void reportProcedureInformation(Procedure *p, ReturnManner returnm, bool last, TypeContext tc) {
    ecCharToCharStack(p->name, nameString);
    
    printf("{");
    printf("\"name\": \"%s\",", nameString);
    
    if (returnm == Return) {
        reportType("returnType", p->returnType, false, tc);
{'fraction_non_alphanumeric': 0.18453244868339208, 'fraction_numerical': 0.00725689404934688, 'mean_word_length': 2.6080777860882574, 'pattern_counts': {'":': 22, '<': 23, '<?xml version=': 0, '>': 27, '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': '5500078', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1566, 'n_words': 356}