Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup SourceFile API
  • Loading branch information
allanrenucci committed Jun 29, 2018
commit a437b74b4f32c37c4b76459ceb3201a80f97a711
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object CompilationUnit {

/** Make a compilation unit for top class `clsd` with the contends of the `unpickled` */
def mkCompilationUnit(clsd: ClassDenotation, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit =
mkCompilationUnit(new SourceFile(clsd.symbol.associatedFile, Seq()), unpickled, forceTrees)
mkCompilationUnit(SourceFile(clsd.symbol.associatedFile, Array.empty), unpickled, forceTrees)

/** Make a compilation unit, given picked bytes and unpickled tree */
def mkCompilationUnit(source: SourceFile, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class ReadTastyTreesFromClasses extends FrontEnd {
case unpickler: tasty.DottyUnpickler =>
if (cls.tree.isEmpty) None
else {
val source = SourceFile(cls.associatedFile, Array())
val unit = mkCompilationUnit(source, cls.tree, forceTrees = true)
val unit = mkCompilationUnit(cls, cls.tree, forceTrees = true)
unit.pickled += (cls -> unpickler.unpickler.bytes)
Some(unit)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class QuoteCompiler(directory: AbstractFile) extends Compiler {
val tree =
if (putInClass) inClass(exprUnit.expr)
else PickledQuotes.quotedExprToTree(exprUnit.expr)
val source = new SourceFile("", Seq())
val source = new SourceFile("", "")
CompilationUnit.mkCompilationUnit(source, tree, forceTrees = true)
case typeUnit: TypeCompilationUnit =>
assert(!putInClass)
val tree = PickledQuotes.quotedTypeToTree(typeUnit.tpe)
val source = new SourceFile("", Seq())
val source = new SourceFile("", "")
CompilationUnit.mkCompilationUnit(source, tree, forceTrees = true)
}
}
Expand Down
7 changes: 3 additions & 4 deletions compiler/src/dotty/tools/dotc/util/SourceFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ object ScriptSourceFile {

case class SourceFile(file: AbstractFile, content: Array[Char]) extends interfaces.SourceFile {

def this(_file: AbstractFile, codec: Codec) = this(_file, new String(_file.toByteArray, codec.charSet).toCharArray)
def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray)
def this(file: AbstractFile, cs: Seq[Char]) = this(file, cs.toArray)
def this(file: AbstractFile, codec: Codec) = this(file, new String(file.toByteArray, codec.charSet).toCharArray)
def this(name: String, content: String) = this(new VirtualFile(name), content.toCharArray)

/** Tab increment; can be overridden */
def tabInc = 8
Expand Down Expand Up @@ -150,7 +149,7 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) extends interfac
override def toString = file.toString
}

@sharable object NoSource extends SourceFile("<no source>", Nil) {
@sharable object NoSource extends SourceFile("<no source>", "") {
override def exists = false
override def atPos(pos: Position): SourcePosition = NoSourcePosition
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/repl/JLineTerminal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ final class JLineTerminal {

case ParseContext.COMPLETE =>
// Parse to find completions (typically after a Tab).
val source = new SourceFile("<completions>", line.toCharArray)
val source = new SourceFile("<completions>", line)
val scanner = new Scanner(source)(ctx.fresh.setReporter(Reporter.NoReporter))

// Looking for the current word being completed
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/repl/ParseResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object ParseResult {
@sharable private[this] val CommandExtract = """(:[\S]+)\s*(.*)""".r

private def parseStats(sourceCode: String)(implicit ctx: Context): List[untpd.Tree] = {
val source = new SourceFile("<console>", sourceCode.toCharArray)
val source = new SourceFile("<console>", sourceCode)
val parser = new Parser(source)
val stats = parser.blockStatSeq()
parser.accept(Tokens.EOF)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ReplDriver(settings: Array[String],
compiler
.typeCheck(expr, errorsAllowed = true)
.map { tree =>
val file = new SourceFile("<completions>", expr.toCharArray)
val file = new SourceFile("<completions>", expr)
val unit = new CompilationUnit(file)
unit.tpdTree = tree
implicit val ctx = state.run.runContext.fresh.setCompilationUnit(unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UntpdTreeMapTest extends DottyTest {
import untpd._

def parse(code: String): Tree = {
val (_, stats) = new Parser(new SourceFile("<meta>", code.toCharArray)).templateStatSeq()
val (_, stats) = new Parser(new SourceFile("<meta>", code)).templateStatSeq()
stats match { case List(stat) => stat; case stats => untpd.Thicket(stats) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object ModifiersParsingTest {
implicit val ctx: Context = (new ContextBase).initialCtx

implicit def parse(code: String): Tree = {
val (_, stats) = new Parser(new SourceFile("<meta>", code.toCharArray)).templateStatSeq()
val (_, stats) = new Parser(new SourceFile("<meta>", code)).templateStatSeq()
stats match { case List(stat) => stat; case stats => Thicket(stats) }
}

Expand Down