<commit_before>const OS = require("os");
const CompileError = require("./compileerror");
const CompilerSupplier = require("./compilerSupplier");
const semver = require("semver");

async function run(rawSources, options) {
  // Nothing to compile? Bail.
  if (Object.keys(rawSources).length === 0) {
    return [[], []];
  }

  // Ensure sources have operating system independent paths
  // i.e., convert backslashes to forward slashes; things like C: are left intact.
  const { sources, targets, originalSourcePaths } = collectSources(
    rawSources,
    options.compilationTargets
  );

  const defaultSelectors = {
    "": ["legacyAST", "ast"],
    "*": [
      "abi",
      "metadata",
      "evm.bytecode.object",
      "evm.bytecode.sourceMap",
      "evm.deployedBytecode.object",
      "evm.deployedBytecode.sourceMap",
      "userdoc",
      "devdoc"
    ]
  };

  // Specify compilation targets
  // Each target uses defaultSelectors, defaulting to single target `*` if targets are unspecified
  const outputSelection = {};

  targets.length
    ? targets.forEach(key => (outputSelection[key] = defaultSelectors))
    : (outputSelection["*"] = defaultSelectors);

  const solcStandardInput = {
    language: "Solidity",
    sources: {},
    settings: {
      evmVersion: options.compilers.solc.settings.evmVersion,
      optimizer: options.compilers.solc.settings.optimizer,
      outputSelection
    }
  };

  Object.keys(sources).forEach(file_path => {
    solcStandardInput.sources[file_path] = {
      content: sources[file_path]
    };
  });

  // Load solc module only when compilation is actually required.
  const supplier = new CompilerSupplier(options.compilers.solc);
  const solc = await supplier.load();

  const result = solc.compile(JSON.stringify(solcStandardInput));

  const standardOutput = JSON.parse(result);

  let errors = standardOutput.errors || [];
  let warnings = [];

  if (options.strict !== true) {
    warnings = errors.filter(error => error.severity === "warning");

    errors = errors.filter(error => error.severity !== "warning");

    if (options.quiet !== true && warnings.length > 0) {
      options.logger.log(
        OS.EOL + "    > compilation warnings encountered:" + OS.EOL
      );
      options.logger.log(
        warnings.map(warning => warning.formattedMessage).join()
      );
    }
  }

  if (errors.length > 0) {
    options.logger.log("");
    errors = errors.map(error => error.formattedMessage).join();
    if (errors.includes("requires different compiler version")) {
      const contractSolcVer = errors.match(/pragma solidity[^;]*/gm)[0];
      const configSolcVer =
        options.compilers.solc.version || semver.valid(solc.version());
      errors = errors.concat(
        `\nError: Truffle is currently using solc ${configSolcVer}, but one or more of your contracts specify "${contractSolcVer}".\nPlease update your truffle config or pragma statement(s).\n(See https://truffleframework.com/docs/truffle/reference/configuration#compiler-configuration for information on\nconfiguring Truffle to use a specific solc compiler version.)`
      );
    }
    throw new CompileError(errors);
  }

  var files = [];
  Object.keys(standardOutput.sources).forEach(filename => {
    var source = standardOutput.sources[filename];
    files[source.id] = originalSourcePaths[filename];
  });

  var returnVal = {};

  // This block has comments in it as it's being prepared for solc > 0.4.10
  Object.entries(standardOutput.contracts).forEach(entry => {
    const [sourcePath, filesContracts] = entry;

    Object.entries(filesContracts).forEach(entry => {
      var [contractName, contract] = entry;

      // All source will have a key, but only the compiled source will have
      // the evm output.
      if (!Object.keys(contract.evm).length) return;

      var contract_definition = {
        contract_name: contractName,
        sourcePath: originalSourcePaths[sourcePath], // Save original source path, not modified ones
        source: sources[sourcePath],
        sourceMap: contract.evm.bytecode.sourceMap,
        deployedSourceMap: contract.evm.deployedBytecode.sourceMap,
        legacyAST: standardOutput.sources[sourcePath].legacyAST,
        ast: standardOutput.sources[sourcePath].ast,
        abi: contract.abi,
        metadata: contract.metadata,
        bytecode: "0x" + contract.evm.bytecode.object,
        deployedBytecode: "0x" + contract.evm.deployedBytecode.object,
        unlinked_binary: "0x" + contract.evm.bytecode.object, // deprecated
        compiler: {
          name: "solc",
          version: solc.version()
        },
        devdoc: contract.devdoc,
        userdoc: contract.userdoc<commit_msg>Rename variables for compiler input/output<commit_after>const OS = require("os");
const CompileError = require("./compileerror");
const CompilerSupplier = require("./compilerSupplier");
const semver = require("semver");

async function run(rawSources, options) {
  // Nothing to compile? Bail.
  if (Object.keys(rawSources).length === 0) {
    return [[], []];
  }

  // Ensure sources have operating system independent paths
  // i.e., convert backslashes to forward slashes; things like C: are left intact.
  const { sources, targets, originalSourcePaths } = collectSources(
    rawSources,
    options.compilationTargets
  );

  const defaultSelectors = {
    "": ["legacyAST", "ast"],
    "*": [
      "abi",
      "metadata",
      "evm.bytecode.object",
      "evm.bytecode.sourceMap",
      "evm.deployedBytecode.object",
      "evm.deployedBytecode.sourceMap",
      "userdoc",
      "devdoc"
    ]
  };

  // Specify compilation targets
  // Each target uses defaultSelectors, defaulting to single target `*` if targets are unspecified
  const outputSelection = {};

  targets.length
    ? targets.forEach(key => (outputSelection[key] = defaultSelectors))
    : (outputSelection["*"] = defaultSelectors);

  const compilerInput = {
    language: "Solidity",
    sources: {},
    settings: {
      evmVersion: options.compilers.solc.settings.evmVersion,
      optimizer: options.compilers.solc.settings.optimizer,
      outputSelection
    }
  };

  Object.keys(sources).forEach(file_path => {
    compilerInput.sources[file_path] = {
      content: sources[file_path]
    };
  });

  // Load solc module only when compilation is actually required.
  const supplier = new CompilerSupplier(options.compilers.solc);
  const solc = await supplier.load();

  const result = solc.compile(JSON.stringify(compilerInput));

  const compilerOutput = JSON.parse(result);

  let errors = compilerOutput.errors || [];
  let warnings = [];

  if (options.strict !== true) {
    warnings = errors.filter(error => error.severity === "warning");

    errors = errors.filter(error => error.severity !== "warning");

    if (options.quiet !== true && warnings.length > 0) {
      options.logger.log(
        OS.EOL + "    > compilation warnings encountered:" + OS.EOL
      );
      options.logger.log(
        warnings.map(warning => warning.formattedMessage).join()
      );
    }
  }

  if (errors.length > 0) {
    options.logger.log("");
    errors = errors.map(error => error.formattedMessage).join();
    if (errors.includes("requires different compiler version")) {
      const contractSolcVer = errors.match(/pragma solidity[^;]*/gm)[0];
      const configSolcVer =
        options.compilers.solc.version || semver.valid(solc.version());
      errors = errors.concat(
        `\nError: Truffle is currently using solc ${configSolcVer}, but one or more of your contracts specify "${contractSolcVer}".\nPlease update your truffle config or pragma statement(s).\n(See https://truffleframework.com/docs/truffle/reference/configuration#compiler-configuration for information on\nconfiguring Truffle to use a specific solc compiler version.)`
      );
    }
    throw new CompileError(errors);
  }

  var files = [];
  Object.keys(compilerOutput.sources).forEach(filename => {
    var source = compilerOutput.sources[filename];
    files[source.id] = originalSourcePaths[filename];
  });

  var returnVal = {};

  // This block has comments in it as it's being prepared for solc > 0.4.10
  Object.entries(compilerOutput.contracts).forEach(entry => {
    const [sourcePath, filesContracts] = entry;

    Object.entries(filesContracts).forEach(entry => {
      var [contractName, contract] = entry;

      // All source will have a key, but only the compiled source will have
      // the evm output.
      if (!Object.keys(contract.evm).length) return;

      var contract_definition = {
        contract_name: contractName,
        sourcePath: originalSourcePaths[sourcePath], // Save original source path, not modified ones
        source: sources[sourcePath],
        sourceMap: contract.evm.bytecode.sourceMap,
        deployedSourceMap: contract.evm.deployedBytecode.sourceMap,
        legacyAST: compilerOutput.sources[sourcePath].legacyAST,
        ast: compilerOutput.sources[sourcePath].ast,
        abi: contract.abi,
        metadata: contract.metadata,
        bytecode: "0x" + contract.evm.bytecode.object,
        deployedBytecode: "0x" + contract.evm.deployedBytecode.object,
        unlinked_binary: "0x" + contract.evm.bytecode.object, // deprecated
        compiler: {
          name: "solc",
          version: solc.version()
        },
        devdoc: contract.devdoc,
        userdoc: contract.userdoc
{'fraction_non_alphanumeric': 0.12549144618000213, 'fraction_numerical': 0.002337689937307406, 'mean_word_length': 3.24346257889991, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 2, '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': '4111120', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2681, 'n_words': 625}