<commit_before>//===--- CompilerInvocation.cpp - CompilerInvocation methods --------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "swift/Frontend/Frontend.h"

#include "ArgsToFrontendOptionsConverter.h"
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/Basic/Platform.h"
#include "swift/Option/Options.h"
#include "swift/Option/SanitizerOptions.h"
#include "swift/Strings.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"

using namespace swift;
using namespace llvm::opt;

/// The path for Swift libraries in the OS on Darwin.
#define DARWIN_OS_LIBRARY_PATH "/usr/lib/swift"

static constexpr const char *const localeCodes[] = {
#define SUPPORTED_LOCALE(Code, Language) #Code,
#include "swift/AST/LocalizationLanguages.def"
};

swift::CompilerInvocation::CompilerInvocation() {
  setTargetTriple(llvm::sys::getDefaultTargetTriple());
}

void CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(
    StringRef mainExecutablePath, llvm::SmallString<128> &runtimeResourcePath) {
  runtimeResourcePath.assign(mainExecutablePath);
  llvm::sys::path::remove_filename(runtimeResourcePath); // Remove /swift
  llvm::sys::path::remove_filename(runtimeResourcePath); // Remove /bin
  llvm::sys::path::append(runtimeResourcePath, "lib", "swift");
}

void CompilerInvocation::setMainExecutablePath(StringRef Path) {
  llvm::SmallString<128> LibPath;
  computeRuntimeResourcePathFromExecutablePath(Path, LibPath);
  setRuntimeResourcePath(LibPath.str());

  llvm::SmallString<128> DiagnosticDocsPath(Path);
  llvm::sys::path::remove_filename(DiagnosticDocsPath); // Remove /swift
  llvm::sys::path::remove_filename(DiagnosticDocsPath); // Remove /bin
  llvm::sys::path::append(DiagnosticDocsPath, "share", "doc", "swift",
                          "diagnostics");
  DiagnosticOpts.DiagnosticDocumentationPath = std::string(DiagnosticDocsPath.str());

  // Compute the path of the YAML diagnostic messages directory files
  // in the toolchain.
  llvm::SmallString<128> DiagnosticMessagesDir(Path);
  llvm::sys::path::remove_filename(DiagnosticMessagesDir); // Remove /swift
  llvm::sys::path::remove_filename(DiagnosticMessagesDir); // Remove /bin
  llvm::sys::path::append(DiagnosticMessagesDir, "share", "swift");
  DiagnosticOpts.LocalizationPath = std::string(DiagnosticMessagesDir.str());
}

void CompilerInvocation::setDefaultPrebuiltCacheIfNecessary() {<commit_msg>[Frontend] Add missing `diagnostics` component to the default translations path<commit_after>//===--- CompilerInvocation.cpp - CompilerInvocation methods --------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "swift/Frontend/Frontend.h"

#include "ArgsToFrontendOptionsConverter.h"
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/Basic/Platform.h"
#include "swift/Option/Options.h"
#include "swift/Option/SanitizerOptions.h"
#include "swift/Strings.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"

using namespace swift;
using namespace llvm::opt;

/// The path for Swift libraries in the OS on Darwin.
#define DARWIN_OS_LIBRARY_PATH "/usr/lib/swift"

static constexpr const char *const localeCodes[] = {
#define SUPPORTED_LOCALE(Code, Language) #Code,
#include "swift/AST/LocalizationLanguages.def"
};

swift::CompilerInvocation::CompilerInvocation() {
  setTargetTriple(llvm::sys::getDefaultTargetTriple());
}

void CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(
    StringRef mainExecutablePath, llvm::SmallString<128> &runtimeResourcePath) {
  runtimeResourcePath.assign(mainExecutablePath);
  llvm::sys::path::remove_filename(runtimeResourcePath); // Remove /swift
  llvm::sys::path::remove_filename(runtimeResourcePath); // Remove /bin
  llvm::sys::path::append(runtimeResourcePath, "lib", "swift");
}

void CompilerInvocation::setMainExecutablePath(StringRef Path) {
  llvm::SmallString<128> LibPath;
  computeRuntimeResourcePathFromExecutablePath(Path, LibPath);
  setRuntimeResourcePath(LibPath.str());

  llvm::SmallString<128> DiagnosticDocsPath(Path);
  llvm::sys::path::remove_filename(DiagnosticDocsPath); // Remove /swift
  llvm::sys::path::remove_filename(DiagnosticDocsPath); // Remove /bin
  llvm::sys::path::append(DiagnosticDocsPath, "share", "doc", "swift",
                          "diagnostics");
  DiagnosticOpts.DiagnosticDocumentationPath = std::string(DiagnosticDocsPath.str());

  // Compute the path to the diagnostic translations in the toolchain/build.
  llvm::SmallString<128> DiagnosticMessagesDir(Path);
  llvm::sys::path::remove_filename(DiagnosticMessagesDir); // Remove /swift
  llvm::sys::path::remove_filename(DiagnosticMessagesDir); // Remove /bin
  llvm::sys::path::append(DiagnosticMessagesDir, "share", "swift", "diagnostics");
  DiagnosticOpts.LocalizationPath = std::string(DiagnosticMessagesDir.str());
}

void CompilerInvocation::setDefaultPrebuiltCacheIfNecessary() {
{'fraction_non_alphanumeric': 0.16181965881397237, 'fraction_numerical': 0.007148659626320065, 'mean_word_length': 5.035294117647059, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, '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': '5306556', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1801, 'n_words': 369}