<commit_before>/* NSC -- new Scala compiler
 * Copyright 2005-2010 LAMP/EPFL
 * @author  <NAME>
 */

package scala.tools.nsc
package typechecker


import java.lang.ArithmeticException

/** This class ...
 *
 *  @author <NAME>
 *  @version 1.0
 */
abstract class ConstantFolder {

  val global: Global
  import global._
  import definitions._

  /** If tree is a constant operation, replace with result. */
  def apply(tree: Tree): Tree = fold(tree, tree match {
    case Apply(Select(Literal(x), op), List(Literal(y))) => foldBinop(op, x, y)
    case Select(Literal(x), op) => foldUnop(op, x)
    case _ => null
  })

  /** If tree is a constant value that can be converted to type `pt', perform
   *  the conversion.
   *
   *  @param tree ...
   *  @param pt ...
   */
  def apply(tree: Tree, pt: Type): Tree = fold(tree, tree.tpe match {
    case ConstantType(x) => x convertTo pt
    case _ => null
  })

  private def fold(tree: Tree, compX: => Constant): Tree =
    try {
      val x = compX
      if ((x ne null) && x.tag != UnitTag) tree setType ConstantType(x)
      else tree
    } catch {
      case _: ArithmeticException => tree   // the code will crash at runtime,
                                           // but that is better than the
                                           // compiler itself crashing
    }

  private def foldUnop(op: Name, x: Constant): Constant = (op, x.tag) match {
    case (nme.UNARY_!, BooleanTag) => Constant(!x.booleanValue)

    case (nme.UNARY_~ , IntTag    ) => Constant(~x.intValue)
    case (nme.UNARY_~ , LongTag   ) => Constant(~x.longValue)

    case (nme.UNARY_+ , IntTag    ) => Constant(+x.intValue)
    case (nme.UNARY_+ , LongTag   ) => Constant(+x.longValue)<commit_msg>Solved problem that -3.0 is not recognized as a...<commit_after>/* NSC -- new Scala compiler
 * Copyright 2005-2010 LAMP/EPFL
 * @author  <NAME>
 */

package scala.tools.nsc
package typechecker


import java.lang.ArithmeticException

/** This class ...
 *
 *  @author <NAME>
 *  @version 1.0
 */
abstract class ConstantFolder {

  val global: Global
  import global._
  import definitions._

  /** If tree is a constant operation, replace with result. */
  def apply(tree: Tree): Tree = fold(tree, tree match {
    case Apply(Select(Literal(x), op), List(Literal(y))) => foldBinop(op, x, y)
    case Select(Literal(x), op) => foldUnop(op, x)
    case _ => null
  })

  /** If tree is a constant value that can be converted to type `pt', perform
   *  the conversion.
   *
   *  @param tree ...
   *  @param pt ...
   */
  def apply(tree: Tree, pt: Type): Tree = fold(apply(tree), tree.tpe match {
    case ConstantType(x) => x convertTo pt
    case _ => null
  })

  private def fold(tree: Tree, compX: => Constant): Tree =
    try {
      val x = compX
      if ((x ne null) && x.tag != UnitTag) tree setType ConstantType(x)
      else tree
    } catch {
      case _: ArithmeticException => tree   // the code will crash at runtime,
                                           // but that is better than the
                                           // compiler itself crashing
    }

  private def foldUnop(op: Name, x: Constant): Constant = (op, x.tag) match {
    case (nme.UNARY_!, BooleanTag) => Constant(!x.booleanValue)

    case (nme.UNARY_~ , IntTag    ) => Constant(~x.intValue)
    case (nme.UNARY_~ , LongTag   ) => Constant(~x.longValue)

    case (nme.UNARY_+ , IntTag    ) => Constant(+x.intValue)
    case (nme.UNARY_+ , LongTag   ) => Constant(+x.longValue)
{'fraction_non_alphanumeric': 0.13255416191562144, 'fraction_numerical': 0.006271379703534778, 'mean_word_length': 2.361111111111111, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3631747', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1092, 'n_words': 345}