<commit_before>/* vim: set sw=4 ts=4: */
#ifndef PP_CONTEXT
#define PP_CONTEXT

#include <string>

#include "llvm/Config/config.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Path.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Version.h"
#include "clang/Basic/FileManager.h"

#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Preprocessor.h"

#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Frontend/DiagnosticOptions.h"
#include "clang/Frontend/FrontendOptions.h"
#include "clang/Frontend/PreprocessorOptions.h"
#include "clang/Frontend/HeaderSearchOptions.h"
#include "clang/Frontend/Utils.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/MacroBuilder.h"

using namespace clang;
using namespace llvm;
struct PPContext {
    // Takes ownership of client.
    PPContext(
        clang::TargetOptions targetOpts,
        clang::DiagnosticClient* client,
        clang::LangOptions langOpts,
        std::string const &isysroot,
        std::vector<std::string> const &frameworkDirs,
        std::vector<std::string> const &headerDirs
    ) : 
        diags(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), client),
        opts(langOpts),
        target(clang::TargetInfo::CreateTargetInfo(diags,targetOpts)),
        fm(FileSystemOptions()),
        headers(fm),
        sm(diags, fm),
        pp(diags, opts, *target, sm, headers)
        {
            diags.setSuppressSystemWarnings(true);

            HeaderSearchOptions hsOpts;
            llvm::sys::Path resourceDir(LLVM_LIBDIR);
            resourceDir.appendComponent("clang");
            resourceDir.appendComponent(CLANG_VERSION_STRING);

            hsOpts.ResourceDir = resourceDir.c_str();
            hsOpts.UseBuiltinIncludes = 1;
            hsOpts.UseStandardIncludes = 1;

            for (std::vector<std::string>::const_iterator i = frameworkDirs.begin();
                 i != frameworkDirs.end();
                 ++i)
                hsOpts.AddPath(*i, clang::frontend::Angled, true, true, false);

            for (std::vector<std::string>::const_iterator i = headerDirs.begin();
                 i != headerDirs.end();
                 ++i)
                hsOpts.AddPath(*i, clang::frontend::Angled, true, false, false);

            hsOpts.Sysroot = isysroot;

            InitializePreprocessor(pp, PreprocessorOptions(), hsOpts, FrontendOptions());
        }

    ~PPContext()
    {
        delete target;
    }


    clang::Diagnostic diags;
    clang::LangOptions opts;
    clang::TargetInfo* target;
    clang::FileManager fm;
    clang::HeaderSearch headers;
    clang::SourceManager sm;
    clang::Preprocessor pp;
};

#endif
<commit_msg>bindgen: use LLVM_LIBDIR only on non windows platforms<commit_after>/* vim: set sw=4 ts=4: */
#ifndef PP_CONTEXT
#define PP_CONTEXT

#include <string>

#include "llvm/Config/config.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Path.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Version.h"
#include "clang/Basic/FileManager.h"

#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Preprocessor.h"

#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Frontend/DiagnosticOptions.h"
#include "clang/Frontend/FrontendOptions.h"
#include "clang/Frontend/PreprocessorOptions.h"
#include "clang/Frontend/HeaderSearchOptions.h"
#include "clang/Frontend/Utils.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/MacroBuilder.h"

using namespace clang;
using namespace llvm;
struct PPContext {
    // Takes ownership of client.
    PPContext(
        clang::TargetOptions targetOpts,
        clang::DiagnosticClient* client,
        clang::LangOptions langOpts,
        std::string const &isysroot,
        std::vector<std::string> const &frameworkDirs,
        std::vector<std::string> const &headerDirs
    ) : 
        diags(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), client),
        opts(langOpts),
        target(clang::TargetInfo::CreateTargetInfo(diags,targetOpts)),
        fm(FileSystemOptions()),
        headers(fm),
        sm(diags, fm),
        pp(diags, opts, *target, sm, headers)
        {
            diags.setSuppressSystemWarnings(true);

            HeaderSearchOptions hsOpts;
#ifndef WIN32
            llvm::sys::Path resourceDir(LLVM_LIBDIR);
            resourceDir.appendComponent("clang");
            resourceDir.appendComponent(CLANG_VERSION_STRING);

            hsOpts.ResourceDir = resourceDir.c_str();
#endif
            hsOpts.UseBuiltinIncludes = 1;
            hsOpts.UseStandardIncludes = 1;

            for (std::vector<std::string>::const_iterator i = frameworkDirs.begin();
                 i != frameworkDirs.end();
                 ++i)
                hsOpts.AddPath(*i, clang::frontend::Angled, true, true, false);

            for (std::vector<std::string>::const_iterator i = headerDirs.begin();
                 i != headerDirs.end();
                 ++i)
                hsOpts.AddPath(*i, clang::frontend::Angled, true, false, false);

            hsOpts.Sysroot = isysroot;

            InitializePreprocessor(pp, PreprocessorOptions(), hsOpts, FrontendOptions());
        }

    ~PPContext()
    {
        delete target;
    }


    clang::Diagnostic diags;
    clang::LangOptions opts;
    clang::TargetInfo* target;
    clang::FileManager fm;
    clang::HeaderSearch headers;
    clang::SourceManager sm;
    clang::Preprocessor pp;
};

#endif

{'fraction_non_alphanumeric': 0.12731481481481483, 'fraction_numerical': 0.0017806267806267807, 'mean_word_length': 3.0910415149308084, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4916638', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1763, 'n_words': 310}