Skip to content
This repository was archived by the owner on Mar 28, 2018. It is now read-only.

Refactoring typechecker #3

Open
wants to merge 15 commits into
base: 2.11.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import scala.reflect.macros.blackbox.{Context => BlackboxContext}
import scala.reflect.macros.whitebox.{Context => WhiteboxContext}
import java.lang.reflect.{Constructor => jConstructor}

trait JavaReflectionRuntimes {
self: scala.tools.nsc.typechecker.Analyzer =>
trait JavaReflectionRuntime {
//self: scala.tools.nsc.typechecker.Analyzer =>
self: DefaultMacroRuntimes with util.Traces =>

trait JavaReflectionResolvers {
self: MacroRuntimeResolver =>
Expand Down
10 changes: 7 additions & 3 deletions src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package runtime

import scala.reflect.internal.Flags._
import scala.reflect.runtime.ReflectionUtils
import scala.tools.nsc.typechecker

trait MacroRuntimes extends JavaReflectionRuntimes {
self: scala.tools.nsc.typechecker.Analyzer =>
trait DefaultMacroRuntimes extends MacroRuntimes with JavaReflectionRuntime {
//self: scala.tools.nsc.typechecker.Analyzer =>
self: typechecker.Globals with
util.Traces with
typechecker.AnalyzerPlugins with
typechecker.Macros =>

import global._
import definitions._
Expand Down Expand Up @@ -48,7 +53,6 @@ trait MacroRuntimes extends JavaReflectionRuntimes {

/** Abstracts away resolution of macro runtimes.
*/
type MacroRuntime = MacroArgs => Any
class MacroRuntimeResolver(val macroDef: Symbol) extends JavaReflectionResolvers {
val binding = loadMacroImplBinding(macroDef).get
val isBundle = binding.isBundle
Expand Down
10 changes: 10 additions & 0 deletions src/compiler/scala/reflect/macros/runtime/MacroRuntimesApi.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package scala.reflect.macros.runtime

import scala.tools.nsc.typechecker

trait MacroRuntimes {
self: typechecker.Macros =>

// used externally
type MacroRuntime = MacroArgs => Any
}
6 changes: 3 additions & 3 deletions src/compiler/scala/reflect/macros/util/Helpers.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package scala.reflect.macros
package util

import scala.tools.nsc.typechecker.Analyzer
import scala.tools.nsc.Global

trait Helpers {
self: Analyzer =>

val global:Global
import global._
import definitions._

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/ant/Scalac.scala
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
val reporter = new ConsoleReporter(settings)
val compiler = newGlobal(settings, reporter) // compiles the actual code

try new compiler.Run compile (sourceFiles map (_.toString))
try compiler.newRun compile (sourceFiles map (_.toString))
catch {
case ex: Throwable =>
ex.printStackTrace()
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scala/tools/ant/sabbus/ForeignCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ForeignCompiler {
private lazy val nsc: Global = {
try {
val command = new CompilerCommand(args.toList, settings)
new Global(command.settings, reporter)
new DefaultGlobal(command.settings, reporter)
}
catch {
case ex @ FatalError(msg) =>
Expand All @@ -42,7 +42,7 @@ class ForeignCompiler {

def compile(files: Array[File]): Int = {
val command = new CompilerCommand(files.toList map (_.toString), settings)
(new nsc.Run) compile command.files
nsc.newRun compile command.files
reporter.ERROR.count << 16 | reporter.WARNING.count
}

Expand Down
10 changes: 7 additions & 3 deletions src/compiler/scala/tools/nsc/CompilationUnits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ package scala.tools.nsc
import scala.reflect.internal.util.{ SourceFile, NoSourceFile, FreshNameCreator }
import scala.collection.mutable
import scala.collection.mutable.{ LinkedHashSet, ListBuffer }
import scala.tools.nsc.symtab.SymbolTable
import scala.tools.nsc.backend.icode.ICodes

trait CompilationUnits { global: Global =>
trait CompilationUnits { global:SymbolTable =>

val icodes:ICodes

/** An object representing a missing compilation unit.
*/
object NoCompilationUnit extends CompilationUnit(NoSourceFile) {
Expand Down Expand Up @@ -131,8 +135,8 @@ trait CompilationUnits { global: Global =>

@deprecated("Call global.currentRun.reporting.deprecationWarning directly instead.", "2.11.2")
final def deprecationWarning(pos: Position, msg: String): Unit = currentRun.reporting.deprecationWarning(pos, msg)
@deprecated("Call global.currentRun.reporting.uncheckedWarning directly instead.", "2.11.2")
final def uncheckedWarning(pos: Position, msg: String): Unit = currentRun.reporting.uncheckedWarning(pos, msg)
//@deprecated("Call global.currentRun.reporting.uncheckedWarning directly instead.", "2.11.2")
//final def uncheckedWarning(pos: Position, msg: String): Unit = currentRun.reporting.uncheckedWarning(pos, msg)

@deprecated("This method will be removed. It does nothing.", "2.11.2")
final def comment(pos: Position, msg: String): Unit = {}
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/scala/tools/nsc/CompileServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class StandardCompileServer(fixPort: Int = 0) extends SocketServer(fixPort) {
import runtime.{ totalMemory, freeMemory, maxMemory }

/** Create a new compiler instance */
def newGlobal(settings: Settings, reporter: Reporter) =
new Global(settings, reporter) {
def newGlobal(settings: Settings, reporter: Reporter):Global =
new DefaultGlobal(settings, reporter) {
override def inform(pos: Position, msg: String) = out.println(msg)
}

Expand Down Expand Up @@ -146,7 +146,7 @@ class StandardCompileServer(fixPort: Int = 0) extends SocketServer(fixPort) {
compiler = newGlobal(newSettings, reporter)
}
val c = compiler
try new c.Run() compile command.files
try c.newRun() compile command.files
catch {
case ex @ FatalError(msg) =>
reporter.error(null, "fatal error: " + msg)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class Driver {
reporter.echo(command.usageMsg)
reporter.echo(compiler.pluginOptionsHelp)
} else {
val run = new compiler.Run()
val run = compiler.newRun()
run compile command.files
reporter.printSummary()
}
Expand Down
Loading