<commit_before>package ch.usi.inf.l3.sana.primj.symbols

import ch.usi.inf.l3.sana
import sana.tiny.types.Type
import sana.primj.types.VoidType
import sana.tiny.symbols.{Symbol, TermSymbol, TypeSymbol}
import sana.tiny.modifiers.Flags
import sana.tiny.modifiers.Ops.noflags
import sana.tiny.names.{Name, noname}





case object ProgramSymbol extends Symbol {
  decls = decls + SymbolUtils.standardDefinitions

  var name: Name = noname
  var mods: Flags = noflags
  var tpe: Option[Type] = None
  var owner: Option[Symbol] = None
}

case class VariableSymbol(var mods: Flags, var name: Name,
  var tpe: Option[Type], var owner: Option[Symbol])
  extends TermSymbol {

  override def declare(symbol: Symbol): Unit = ???
  override def delete(symbol: Symbol): Unit = ???
  override def defines(symbol: Symbol): Boolean =
    owner.map(_.defines(symbol)).getOrElse(false)
  override def getSymbol(name: Name,
    p: Symbol => Boolean): Option[Symbol] =
    owner.flatMap(_.getSymbol(name, p))
}

case class MethodSymbol(var mods: Flags, var name: Name,
  var params: List[Symbol],
  var tpe: Option[Type],
  var owner: Option[Symbol])
  extends TermSymbol


case class ScopeSymbol(var owner: Option[Symbol]) extends Symbol {
  var name: Name = noname
  var mods: Flags = noflags
  var tpe: Option[Type] = None
}

case object VoidSymbol extends TypeSymbol {
  def tpe: Option[Type] = Some(VoidType)
  def owner: Option[Symbol] = None
  def mods: Flags = noflags
  def name: Name = Name("void")
<commit_msg>Implement toString, equals & hashCode<commit_after>package ch.usi.inf.l3.sana.primj.symbols

import ch.usi.inf.l3.sana
import sana.tiny.types.Type
import sana.primj.types.VoidType
import sana.tiny.symbols.{Symbol, TermSymbol, TypeSymbol}
import sana.tiny.modifiers.Flags
import sana.tiny.modifiers.Ops.noflags
import sana.tiny.names.{Name, noname}





case object ProgramSymbol extends Symbol {
  decls = decls ++ SymbolUtils.standardDefinitions

  var name: Name = noname
  var mods: Flags = noflags
  var tpe: Option[Type] = None
  var owner: Option[Symbol] = None
}

case class VariableSymbol(var mods: Flags, var name: Name,
  var tpe: Option[Type], var owner: Option[Symbol])
  extends TermSymbol {

  override def declare(symbol: Symbol): Unit = ???
  override def delete(symbol: Symbol): Unit = ???
  override def defines(symbol: Symbol): Boolean =
    owner.map(_.defines(symbol)).getOrElse(false)
  override def getSymbol(name: Name,
    p: Symbol => Boolean): Option[Symbol] =
    owner.flatMap(_.getSymbol(name, p))

  override def equals(other: Any): Boolean = other match {
    case null                 => false
    case that: VariableSymbol =>
      this.mods == that.mods &&
        this.name == that.name &&
        this.tpe == that.tpe
    case _                    =>
      false
  }
  override def toString(): String = s"Variable symbol $name"
  override def hashCode(): Int = name.hashCode * 43 +
    tpe.hashCode * mods.hashCode
}

case class MethodSymbol(var mods: Flags, var name: Name,
  var params: List[Symbol],
  var tpe: Option[Type],
  var owner: Option[Symbol])
  extends TermSymbol {

  override def equals(other: Any): Boolean = other match {
    case null                 => false
    case that: MethodSymbol   =>
      this.name == that.name &&
        this.tpe == that.tpe
    case _                    =>
      false
  }
  override def toString(): String = s"Method symbol: $name"
  override def hashCode(): Int = name.hashCode * 43 + tpe.hashCode
}


case class ScopeSymbol(var owner: Option[Symbol]) extends Symbol {
  var name: Name = noname
  var mods: Flags = noflags
  var tpe: Option[Type] = None

  override def equals(other: Any): Boolean = other match {
    case null                 => false
    case that: ScopeSymbol    =>
      this.name == that.name &&
        this.tpe == that.tpe
    case _                    =>
      false
  }
  override def toString(): String = s"Scope symbol"
  override def hashCode(): Int = name.hashCode * 43 + tpe.hashCode
}

case object VoidSymbol extends TypeSymbol {
  def tpe: Option[Type] = Some(VoidType)
  def owner: Option[Symbol] = None
  def mods: Flags = noflags
  def name: Name = Name("void")

{'fraction_non_alphanumeric': 0.1121986154213416, 'fraction_numerical': 0.0023872045834328003, 'mean_word_length': 3.324045407636739, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '5313882', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1329, 'n_words': 392}