<commit_before>package scala.meta
package internal.hosts.scalac
package contexts

import org.scalameta.contexts._
import org.scalameta.invariants._
import scala.meta.semantic.{Context => ScalametaSemanticContext}
import scala.meta.macros.{Context => ScalametaMacroContext}
import scala.meta.internal.hosts.scalac.contexts.{SemanticContext => ScalahostSemanticContext}
import scala.compat.Platform.EOL
import org.scalameta.reflection.mkGlobal
import scala.tools.nsc.reporters.StoreReporter
import scala.{meta => mapi}
import scala.meta.internal.{ast => m}

@context(translateExceptions = false)
class StandaloneContext(options: String) extends ScalahostSemanticContext(mkGlobal(options)) with ScalametaMacroContext {
  def define(code: String): mapi.Source = {
    val reporter: StoreReporter = g.reporter.require[StoreReporter]
    reporter.reset()
    val gunit = g.newCompilationUnit(code, "<scalahost>")
    val gtree = g.newUnitParser(gunit).parse()
    if (reporter.hasErrors) throw new StandaloneException("parse has failed:" + EOL + (reporter.infos map (_.msg) mkString EOL))
    val gtypedtree = {
      import g.{reporter => _, _}
      import analyzer._
      val run = new Run
      phase = run.namerPhase
      globalPhase = run.namerPhase
      val namer = newNamer(rootContext(gunit))
      namer.enterSym(gtree)
      phase = run.typerPhase
      globalPhase = run.typerPhase
      val typer = newTyper(rootContext(gunit))
      val typedpkg = typer.typed(gtree).require[Tree]
      for (workItem <- gunit.toCheck) workItem()
      if (reporter.hasErrors) throw new StandaloneException("typecheck has failed:" + EOL + (reporter.infos map (_.msg) mkString EOL))
      typedpkg.require[PackageDef]
    }
    val _ = toMtree.computeConverters // TODO: necessary because of macro expansion order
    toMtree(gtypedtree, classOf[mapi.Source])
  }
  val reporter = new StoreReporter()
  private[meta] def warning(msg: String): Unit = reporter.warning(g.NoPosition, msg)
  private[meta] def error(msg: String): Unit = reporter.error(g.NoPosition, msg)
  private[meta] def abort(msg: String): Nothing = { reporter.error(g.NoPosition, msg); sys.error(msg) }
  private[meta] def resources: Map[String, Array[Byte]] = Map()
}<commit_msg>StandaloneContext.abort now throws AbortMacroException<commit_after>package scala.meta
package internal.hosts.scalac
package contexts

import org.scalameta.contexts._
import org.scalameta.invariants._
import scala.meta.semantic.{Context => ScalametaSemanticContext}
import scala.meta.macros.{Context => ScalametaMacroContext}
import scala.meta.internal.hosts.scalac.contexts.{SemanticContext => ScalahostSemanticContext}
import scala.compat.Platform.EOL
import org.scalameta.reflection.mkGlobal
import scala.tools.nsc.reporters.StoreReporter
import scala.{meta => mapi}
import scala.meta.internal.{ast => m}
import scala.reflect.macros.runtime.AbortMacroException

@context(translateExceptions = false)
class StandaloneContext(options: String) extends ScalahostSemanticContext(mkGlobal(options)) with ScalametaMacroContext {
  def define(code: String): mapi.Source = {
    val reporter: StoreReporter = g.reporter.require[StoreReporter]
    reporter.reset()
    val gunit = g.newCompilationUnit(code, "<scalahost>")
    val gtree = g.newUnitParser(gunit).parse()
    if (reporter.hasErrors) throw new StandaloneException("parse has failed:" + EOL + (reporter.infos map (_.msg) mkString EOL))
    val gtypedtree = {
      import g.{reporter => _, _}
      import analyzer._
      val run = new Run
      phase = run.namerPhase
      globalPhase = run.namerPhase
      val namer = newNamer(rootContext(gunit))
      namer.enterSym(gtree)
      phase = run.typerPhase
      globalPhase = run.typerPhase
      val typer = newTyper(rootContext(gunit))
      val typedpkg = typer.typed(gtree).require[Tree]
      for (workItem <- gunit.toCheck) workItem()
      if (reporter.hasErrors) throw new StandaloneException("typecheck has failed:" + EOL + (reporter.infos map (_.msg) mkString EOL))
      typedpkg.require[PackageDef]
    }
    val _ = toMtree.computeConverters // TODO: necessary because of macro expansion order
    toMtree(gtypedtree, classOf[mapi.Source])
  }
  val reporter = new StoreReporter()
  private[meta] def warning(msg: String): Unit = reporter.warning(g.NoPosition, msg)
  private[meta] def error(msg: String): Unit = reporter.error(g.NoPosition, msg)
  private[meta] def abort(msg: String): Nothing = { reporter.error(g.NoPosition, msg); throw new AbortMacroException(g.NoPosition, msg) }
  private[meta] def resources: Map[String, Array[Byte]] = Map()
}
{'fraction_non_alphanumeric': 0.11055712117927596, 'fraction_numerical': 0.0, 'mean_word_length': 4.572463768115942, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '5221813', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1458, 'n_words': 324}