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

// $Id$

package scala.tools.nsc.backend.icode

import compat.StringBuilder
import scala.collection.mutable.{Map, HashMap}
import scala.tools.nsc.symtab._


/** This class ...
 *
 *  @author  <NAME>
 *  @version 1.0
 */
// TODO:
// - switches with alternatives
abstract class GenICode extends SubComponent  {
  import global._
  import icodes._
  import icodes.opcodes._

  val phaseName = "icode"

  override def newPhase(prev: Phase) = new ICodePhase(prev)

  class ICodePhase(prev: Phase) extends StdPhase(prev) {

    override def description = "Generate ICode from the AST"

    var unit: CompilationUnit = _

    // We assume definitions are alread initialized
    val STRING = REFERENCE(definitions.StringClass)

    // this depends on the backend! should be changed.
    val ANY_REF_CLASS = REFERENCE(definitions.ObjectClass)

    val SCALA_ALL    = REFERENCE(definitions.AllClass)
    val SCALA_ALLREF = REFERENCE(definitions.AllRefClass)
    val THROWABLE    = REFERENCE(definitions.ThrowableClass)

    ///////////////////////////////////////////////////////////

    override def run: Unit = {
      scalaPrimitives.init
      classes.clear
      super.run
    }

    override def apply(unit: CompilationUnit): Unit = {
      this.unit = unit
      log("Generating icode for " + unit)
      gen(unit.body)
      this.unit = null
    }

    def gen(tree: Tree): Context = gen(tree, new Context())

    def gen(trees: List[Tree], ctx: Context): Context = {
      var ctx1 = ctx
      for (val t <- trees)
        ctx1 = gen(t, ctx1)

      ctx1
    }

    /////////////////// Code generation ///////////////////////

    def gen(tree: Tree, ctx: Context): Context = tree match {
      case EmptyTree => ctx

      case PackageDef(name, stats) =>
        gen(stats, ctx setPackage name)

      case ClassDef(mods, name, tparams, tpt, impl) =>
        log("Generating class: " + tree.symbol.fullNameString)
        ctx setClass (new IClass(tree.symbol) setCompilationUnit unit)
        addClassFields(ctx, tree.symbol);
        classes += tree.symbol -> ctx.clazz
        gen(impl, ctx)
        ctx setClass null

      // !! modules should be eliminated by refcheck... or not?
      case ModuleDef(mods, name, impl) =>
        abort("Modules should not reach backend!")

      case ValDef(mods, name, tpt, rhs) =>
        ctx // we use the symbol to add fields

      case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
        if (settings.debug.value)
          log("Entering method " + name)
        val m = new IMethod(tree.symbol)
        m.sourceFile = unit.source.toString()
        m.returnType = if (tree.symbol.isConstructor) UNIT
                       else toTypeKind(tree.symbol.info.resultType)
        ctx.clazz.addMethod(m)

        var ctx1 = ctx.enterMethod(m, tree.asInstanceOf[DefDef])
        addMethodParams(ctx1, vparamss)

        if (!m.isDeferred) {
          ctx1 = genLoad(rhs, ctx1, m.returnType);

          // reverse the order of the local variables, to match the source-order
          m.locals = m.locals.reverse

          rhs match {
            case Block(_, Return(_)) => ()
            case Return(_) => ()
            case _ => if (ctx1.bb.isEmpty)<commit_msg>Added assertion for concrete undefined methods<commit_after>/* NSC -- new Scala compiler
 * Copyright 2005-2006 LAMP/EPFL
 * @author  <NAME>
 */

// $Id$

package scala.tools.nsc.backend.icode

import compat.StringBuilder
import scala.collection.mutable.{Map, HashMap}
import scala.tools.nsc.symtab._


/** This class ...
 *
 *  @author  <NAME>
 *  @version 1.0
 */
// TODO:
// - switches with alternatives
abstract class GenICode extends SubComponent  {
  import global._
  import icodes._
  import icodes.opcodes._

  val phaseName = "icode"

  override def newPhase(prev: Phase) = new ICodePhase(prev)

  class ICodePhase(prev: Phase) extends StdPhase(prev) {

    override def description = "Generate ICode from the AST"

    var unit: CompilationUnit = _

    // We assume definitions are alread initialized
    val STRING = REFERENCE(definitions.StringClass)

    // this depends on the backend! should be changed.
    val ANY_REF_CLASS = REFERENCE(definitions.ObjectClass)

    val SCALA_ALL    = REFERENCE(definitions.AllClass)
    val SCALA_ALLREF = REFERENCE(definitions.AllRefClass)
    val THROWABLE    = REFERENCE(definitions.ThrowableClass)

    ///////////////////////////////////////////////////////////

    override def run: Unit = {
      scalaPrimitives.init
      classes.clear
      super.run
    }

    override def apply(unit: CompilationUnit): Unit = {
      this.unit = unit
      log("Generating icode for " + unit)
      gen(unit.body)
      this.unit = null
    }

    def gen(tree: Tree): Context = gen(tree, new Context())

    def gen(trees: List[Tree], ctx: Context): Context = {
      var ctx1 = ctx
      for (val t <- trees)
        ctx1 = gen(t, ctx1)

      ctx1
    }

    /////////////////// Code generation ///////////////////////

    def gen(tree: Tree, ctx: Context): Context = tree match {
      case EmptyTree => ctx

      case PackageDef(name, stats) =>
        gen(stats, ctx setPackage name)

      case ClassDef(mods, name, tparams, tpt, impl) =>
        log("Generating class: " + tree.symbol.fullNameString)
        ctx setClass (new IClass(tree.symbol) setCompilationUnit unit)
        addClassFields(ctx, tree.symbol);
        classes += tree.symbol -> ctx.clazz
        gen(impl, ctx)
        ctx setClass null

      // !! modules should be eliminated by refcheck... or not?
      case ModuleDef(mods, name, impl) =>
        abort("Modules should not reach backend!")

      case ValDef(mods, name, tpt, rhs) =>
        ctx // we use the symbol to add fields

      case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
        if (settings.debug.value)
          log("Entering method " + name)
        val m = new IMethod(tree.symbol)
        m.sourceFile = unit.source.toString()
        m.returnType = if (tree.symbol.isConstructor) UNIT
                       else toTypeKind(tree.symbol.info.resultType)
        ctx.clazz.addMethod(m)

        var ctx1 = ctx.enterMethod(m, tree.asInstanceOf[DefDef])
        addMethodParams(ctx1, vparamss)

        if (!m.isDeferred) {
          ctx1 = genLoad(rhs, ctx1, m.returnType);

          // reverse the order of the local variables, to match the source-order
          m.locals = m.locals.reverse

          rhs match {
            case Block(_, Return(_)) => ()
            case Return(_) => ()
            case EmptyTree =>
              error("Concrete method has no definition: " + tree)
            case _ => if (ctx1.bb.isEmpty)
{'fraction_non_alphanumeric': 0.1320112475950866, 'fraction_numerical': 0.005623797543288442, 'mean_word_length': 2.1892402076451156, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 28, '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': '5322591', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1973, 'n_words': 562}