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

package scala.tools.nsc.transform

import symtab._
import Flags._
import collection.mutable.{HashMap, ListBuffer}

abstract class AddInterfaces extends InfoTransform {
  import global._                  // the global environment
  import definitions._             // standard classes and methods
  import posAssigner.atPos         // for filling in tree positions

  /** <p>
   *    The phase sets <code>lateINTERFACE</code> for non-interface traits
   *    that now become interfaces.
   *  </p>
   *  <p>
   *    It sets <code>lateDEFERRED</code> for formerly concrete methods in
   *    such traits.
   *  </p>
   */
  override def phaseNewFlags: Long = lateDEFERRED | lateINTERFACE

  /** Type reference after erasure; to be defined in subclass
   *  <code>Erasure</code>.
   */
  def erasedTypeRef(sym: Symbol): Type

  /** Erasure type-map; to be defined in subclass
   *  <code>Erasure</code>.
   */
  def erasure: TypeMap

  /** A lazily constructed map that associates every non-interface trait with
   *  its implementation class.
   */
  private val implClassMap = new HashMap[Symbol, Symbol]

  /** A lazily constructed map that associates every concrete method in a non-interface
   *  trait that's currently compiled with its corresponding method in the trait's
   *  implementation class.
   */
  private val implMethodMap = new HashMap[Symbol, Symbol]

  override def newPhase(prev: scala.tools.nsc.Phase): StdPhase = {
    implClassMap.clear
    implMethodMap.clear
    super.newPhase(prev)
  }

  /** Is given trait member symbol a member of the trait's interface
   *  after this transform is performed? */
  private def isInterfaceMember(sym: Symbol): Boolean = {
    sym.isType ||
    { sym.info; // to set lateMETHOD flag if necessary
      sym.isMethod && !sym.isLabel && !(sym hasFlag (PRIVATE | BRIDGE)) &&
      !sym.isConstructor && !sym.isImplOnly
    }
  }

  /** Does symbol need an implementation method? */
  private def needsImplMethod(sym: Symbol): Boolean =
    sym.isMethod && isInterfaceMember(sym) &&
    (!(sym hasFlag (DEFERRED | SUPERACCESSOR)) || (sym hasFlag lateDEFERRED))

  def implClassPhase = currentRun.erasurePhase.next

  /** Return the implementation class of a trait; create a new one of one does not yet exist */
  def implClass(iface: Symbol): Symbol = implClassMap.get(iface) match {
    case Some(c) => c
    case None =>
      atPhase(implClassPhase) {
        val implName = nme.implClassName(iface.name)
        var impl = if (iface.owner.isClass) iface.owner.info.decl(implName) else NoSymbol
        if (impl == NoSymbol) {
          impl = iface.cloneSymbolImpl(iface.owner)
          impl.name = implName
          if (iface.owner.isClass)<commit_msg>Make sure the symbol for the implementation cla...<commit_after>/* NSC -- new Scala compiler
 * Copyright 2005-2009 LAMP/EPFL
 * @author <NAME>
 */
// $Id$

package scala.tools.nsc.transform

import symtab._
import Flags._
import collection.mutable.{HashMap, ListBuffer}

abstract class AddInterfaces extends InfoTransform {
  import global._                  // the global environment
  import definitions._             // standard classes and methods
  import posAssigner.atPos         // for filling in tree positions

  /** <p>
   *    The phase sets <code>lateINTERFACE</code> for non-interface traits
   *    that now become interfaces.
   *  </p>
   *  <p>
   *    It sets <code>lateDEFERRED</code> for formerly concrete methods in
   *    such traits.
   *  </p>
   */
  override def phaseNewFlags: Long = lateDEFERRED | lateINTERFACE

  /** Type reference after erasure; to be defined in subclass
   *  <code>Erasure</code>.
   */
  def erasedTypeRef(sym: Symbol): Type

  /** Erasure type-map; to be defined in subclass
   *  <code>Erasure</code>.
   */
  def erasure: TypeMap

  /** A lazily constructed map that associates every non-interface trait with
   *  its implementation class.
   */
  private val implClassMap = new HashMap[Symbol, Symbol]

  /** A lazily constructed map that associates every concrete method in a non-interface
   *  trait that's currently compiled with its corresponding method in the trait's
   *  implementation class.
   */
  private val implMethodMap = new HashMap[Symbol, Symbol]

  override def newPhase(prev: scala.tools.nsc.Phase): StdPhase = {
    implClassMap.clear
    implMethodMap.clear
    super.newPhase(prev)
  }

  /** Is given trait member symbol a member of the trait's interface
   *  after this transform is performed? */
  private def isInterfaceMember(sym: Symbol): Boolean = {
    sym.isType ||
    { sym.info; // to set lateMETHOD flag if necessary
      sym.isMethod && !sym.isLabel && !(sym hasFlag (PRIVATE | BRIDGE)) &&
      !sym.isConstructor && !sym.isImplOnly
    }
  }

  /** Does symbol need an implementation method? */
  private def needsImplMethod(sym: Symbol): Boolean =
    sym.isMethod && isInterfaceMember(sym) &&
    (!(sym hasFlag (DEFERRED | SUPERACCESSOR)) || (sym hasFlag lateDEFERRED))

  def implClassPhase = currentRun.erasurePhase.next

  /** Return the implementation class of a trait; create a new one of one does not yet exist */
  def implClass(iface: Symbol): Symbol = implClassMap.get(iface) match {
    case Some(c) => c
    case None =>
      atPhase(implClassPhase) {
        val implName = nme.implClassName(iface.name)
        var impl = if (iface.owner.isClass) iface.owner.info.decl(implName) else NoSymbol
        if (impl == NoSymbol) {
          impl = iface.cloneSymbolImpl(iface.owner)
          impl.name = implName
          impl.sourceFile = iface.sourceFile
          if (iface.owner.isClass)
{'fraction_non_alphanumeric': 0.1005586592178771, 'fraction_numerical': 0.002793296089385475, 'mean_word_length': 2.9619640387275243, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, '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': '5009663', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1660, 'n_words': 538}