<commit_before>package edu.colorado.plv.cuanto.scoot
package arithmetic

import soot._
import soot.dexpler.typing.UntypedConstant
import soot.jimple._
import soot.shimple.ShimpleExpr
import soot.shimple.toolkits.scalar.SEvaluator.MetaConstant

import scala.collection.immutable.HashMap

/** Implement an interpreter for soot objects that represent
  * arithemtic expressions
  */
object Interpreter {

  /** Interpreter for an arithmetic expression encoded as a series of
    * assignemnt statements.
    *
    * For now, there is a single variable ([[Builder.acc]]) being
    * updated, which is the value that should be returned */
  def denote(b: Body): Int = ???

  /** Interpreter component for evaluating an arithmetic expression
    * encoded as a single `Value`
    *
    * This has been deprecated because to make multi-operation
    * expressions, evaulation needs to be done over several assignment
    * statements (wrapped in a `Body`) */
  @deprecated
  def denote(v: Value, memory: HashMap[Local, Int]): Int = v match {
    // case e: IntConstant => e.value
    // case e: UnopExpr => uop(e)(denote(e.getOp))
    // case e: BinopExpr => bop(e)(denote(e.getOp1), denote(e.getOp2))
    case _value: Local => memory.getOrElse(_value, 0) // Uninitialized value of any variable is 0
    case _value: Constant => getConstantVal(_value)
    case _value: Expr => eval(_value, memory)
    case _value: Ref => ??? // Ignore
  }

  /** Interpret an arithmetic unary operator node, getting back a
    * function that performs the operation */
  def uop(op: UnopExpr): Int => Int = op match {
    case _: NegExpr => _ * -1
  }

  /** Interpret an arithemetic binary operator node, getting back a
    * function that performs the operation */
  def bop(op: BinopExpr): (Int, Int) => Int = op match {
    case _op: AddExpr => _ + _
    case _op: AndExpr => ???
    case _op: CmpExpr => ???
    case _op: CmpgExpr => ???
    case _op: CmplExpr => ???
    case _op: ConditionExpr => condop(_op) // TODO: if true: return 1, else: return 0
    case _op: DivExpr => _ / _
    case _op: MulExpr => _ * _
    case _op: OrExpr => ???
    case _op: RemExpr => ???
    case _op: ShlExpr => ???
    case _op: SubExpr => _ - _
    case _op: UshrExpr => ???<commit_msg>Fix bool/int case in arithmetic interpreter<commit_after>package edu.colorado.plv.cuanto.scoot
package arithmetic

import soot._
import soot.dexpler.typing.UntypedConstant
import soot.jimple._
import soot.shimple.ShimpleExpr
import soot.shimple.toolkits.scalar.SEvaluator.MetaConstant

import scala.collection.immutable.HashMap

/** Implement an interpreter for soot objects that represent
  * arithemtic expressions
  */
object Interpreter {

  /** Interpreter for an arithmetic expression encoded as a series of
    * assignemnt statements.
    *
    * For now, there is a single variable ([[Builder.acc]]) being
    * updated, which is the value that should be returned */
  def denote(b: Body): Int = ???

  /** Interpreter component for evaluating an arithmetic expression
    * encoded as a single `Value`
    *
    * This has been deprecated because to make multi-operation
    * expressions, evaulation needs to be done over several assignment
    * statements (wrapped in a `Body`) */
  @deprecated
  def denote(v: Value, memory: HashMap[Local, Int]): Int = v match {
    // case e: IntConstant => e.value
    // case e: UnopExpr => uop(e)(denote(e.getOp))
    // case e: BinopExpr => bop(e)(denote(e.getOp1), denote(e.getOp2))
    case _value: Local => memory.getOrElse(_value, 0) // Uninitialized value of any variable is 0
    case _value: Constant => getConstantVal(_value)
    case _value: Expr => eval(_value, memory)
    case _value: Ref => ??? // Ignore
  }

  /** Interpret an arithmetic unary operator node, getting back a
    * function that performs the operation */
  def uop(op: UnopExpr): Int => Int = op match {
    case _: NegExpr => _ * -1
  }

  def bool2Int(b: Boolean): Int = if (b) 1 else 0

  /** Interpret an arithemetic binary operator node, getting back a
    * function that performs the operation */
  def bop(op: BinopExpr): (Int, Int) => Int = op match {
    case _op: AddExpr => _ + _
    case _op: AndExpr => ???
    case _op: CmpExpr => ???
    case _op: CmpgExpr => ???
    case _op: CmplExpr => ???
    case _op: ConditionExpr =>
      (a: Int, b: Int) => bool2Int(condop(_op)(a,b))
    case _op: DivExpr => _ / _
    case _op: MulExpr => _ * _
    case _op: OrExpr => ???
    case _op: RemExpr => ???
    case _op: ShlExpr => ???
    case _op: SubExpr => _ - _
    case _op: UshrExpr => ???
{'fraction_non_alphanumeric': 0.11805706817686779, 'fraction_numerical': 0.003485079503376171, 'mean_word_length': 3.197440585009141, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 50, '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': '535319', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1442, 'n_words': 486}