<commit_before>/* vim: set sw=4 ts=4: */
/*
 * clay-bindgen.cpp
 * This program generates clay bindings for C source files. 
 * This file wraps around the "BindingsConverter" ASTConsumer which does all
 * conversion.
 */

#include <iostream>
#include <vector>
using namespace std;

#include "clang/Basic/Builtins.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Sema/ParseAST.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclGroup.h"
#include "llvm/ADT/Triple.h"

#include "InitHeaderSearch.h"
#include "PPContext.h"
#include "BindingsConverter.h"
using namespace clang;

int main(int argc, char* argv[]) {
    string filename;

    if(argc == 2) {
        filename = argv[1];
    }
    else {
        cerr << "clay-bindgen: Generates clay bindings for C libraries" << endl;
        cerr << "Usage: " << argv[0] << " <c-file-to-be-parsed>" <<  endl;
        return EXIT_FAILURE;
    }

    // Setup clang
    clang::TargetOptions targetOpts;
    targetOpts.Triple = LLVM_HOSTTRIPLE;

    // Create a preprocessor context
    PPContext context(targetOpts);  

    // Add header search directories
    InitHeaderSearch init(context.headers);
    llvm::Triple triple;
    init.AddDefaultSystemIncludePaths(context.opts,triple);
    init.Realize();

    // Add input file
    const FileEntry* file = context.fm.getFile(filename);
    if (!file) {
        cerr << "Failed to open \'" << argv[1] << "\'";
        return EXIT_FAILURE;
    }
    context.sm.createMainFileID(file, SourceLocation());

    BindingsConverter converter(cout);

    // Initialase ASTContext
    IdentifierTable identifierTable(context.opts);
    SelectorTable selectorTable;
    Builtin::Context builtins(*context.target);

    ASTContext astContext(context.opts, context.sm, *context.target, identifierTable,
            selectorTable, builtins);

    // Parse it
    ParseAST(context.pp, &converter, astContext);  // calls pp.EnterMainSourceFile() for us
    converter.generate();

    return 0;
}
<commit_msg>fix clay-bindgen for api breakage in clang.<commit_after>/* vim: set sw=4 ts=4: */
/*
 * clay-bindgen.cpp
 * This program generates clay bindings for C source files. 
 * This file wraps around the "BindingsConverter" ASTConsumer which does all
 * conversion.
 */

#include <iostream>
#include <vector>
using namespace std;

#include "clang/Basic/Builtins.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Sema/ParseAST.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclGroup.h"
#include "llvm/ADT/Triple.h"

#include "InitHeaderSearch.h"
#include "PPContext.h"
#include "BindingsConverter.h"
using namespace clang;

int main(int argc, char* argv[]) {
    string filename;

    if(argc == 2) {
        filename = argv[1];
    }
    else {
        cerr << "clay-bindgen: Generates clay bindings for C libraries" << endl;
        cerr << "Usage: " << argv[0] << " <c-file-to-be-parsed>" <<  endl;
        return EXIT_FAILURE;
    }

    // Setup clang
    clang::TargetOptions targetOpts;
    targetOpts.Triple = LLVM_HOSTTRIPLE;

    // Create a preprocessor context
    PPContext context(targetOpts);  

    // Add header search directories
    InitHeaderSearch init(context.headers);
    llvm::Triple triple;
    init.AddDefaultSystemIncludePaths(context.opts,triple);
    init.Realize();

    // Add input file
    const FileEntry* file = context.fm.getFile(filename);
    if (!file) {
        cerr << "Failed to open \'" << argv[1] << "\'";
        return EXIT_FAILURE;
    }
    context.sm.createMainFileID(file, SourceLocation());

    BindingsConverter converter(cout);

    // Initialase ASTContext
    IdentifierTable identifierTable(context.opts);
    SelectorTable selectorTable;
    Builtin::Context builtins(*context.target);

    ASTContext astContext(context.opts, context.sm, *context.target, identifierTable,
                          selectorTable, builtins, 0);

    // Parse it
    ParseAST(context.pp, &converter, astContext);  // calls pp.EnterMainSourceFile() for us
    converter.generate();

    return 0;
}

{'fraction_non_alphanumeric': 0.12789863734162085, 'fraction_numerical': 0.0035859431030360986, 'mean_word_length': 3.331262939958592, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 9, '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': '2742982', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1316, 'n_words': 317}