Skip to content

Commit 4cc5c83

Browse files
committed
Cleanup SourceFile API
1 parent bcce5c6 commit 4cc5c83

File tree

9 files changed

+12
-14
lines changed

9 files changed

+12
-14
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object CompilationUnit {
3737

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

4242
/** Make a compilation unit, given picked bytes and unpickled tree */
4343
def mkCompilationUnit(source: SourceFile, unpickled: Tree, forceTrees: Boolean)(implicit ctx: Context): CompilationUnit = {

compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class ReadTastyTreesFromClasses extends FrontEnd {
4343
case unpickler: tasty.DottyUnpickler =>
4444
if (cls.tree.isEmpty) None
4545
else {
46-
val source = SourceFile(cls.associatedFile, Array())
47-
val unit = mkCompilationUnit(source, cls.tree, forceTrees = true)
46+
val unit = mkCompilationUnit(cls, cls.tree, forceTrees = true)
4847
unit.pickled += (cls -> unpickler.unpickler.bytes)
4948
Some(unit)
5049
}

compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ class QuoteCompiler(directory: AbstractFile) extends Compiler {
6262
val tree =
6363
if (putInClass) inClass(exprUnit.expr)
6464
else PickledQuotes.quotedExprToTree(exprUnit.expr)
65-
val source = new SourceFile("", Seq())
65+
val source = new SourceFile("", "")
6666
CompilationUnit.mkCompilationUnit(source, tree, forceTrees = true)
6767
case typeUnit: TypeCompilationUnit =>
6868
assert(!putInClass)
6969
val tree = PickledQuotes.quotedTypeToTree(typeUnit.tpe)
70-
val source = new SourceFile("", Seq())
70+
val source = new SourceFile("", "")
7171
CompilationUnit.mkCompilationUnit(source, tree, forceTrees = true)
7272
}
7373
}

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ object ScriptSourceFile {
3737

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

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

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

153-
@sharable object NoSource extends SourceFile("<no source>", Nil) {
152+
@sharable object NoSource extends SourceFile("<no source>", "") {
154153
override def exists = false
155154
override def atPos(pos: Position): SourcePosition = NoSourcePosition
156155
}

compiler/src/dotty/tools/repl/JLineTerminal.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ final class JLineTerminal {
9595

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

101101
// Looking for the current word being completed

compiler/src/dotty/tools/repl/ParseResult.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ object ParseResult {
9999
@sharable private[this] val CommandExtract = """(:[\S]+)\s*(.*)""".r
100100

101101
private def parseStats(sourceCode: String)(implicit ctx: Context): List[untpd.Tree] = {
102-
val source = new SourceFile("<console>", sourceCode.toCharArray)
102+
val source = new SourceFile("<console>", sourceCode)
103103
val parser = new Parser(source)
104104
val stats = parser.blockStatSeq()
105105
parser.accept(Tokens.EOF)

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class ReplDriver(settings: Array[String],
156156
compiler
157157
.typeCheck(expr, errorsAllowed = true)
158158
.map { tree =>
159-
val file = new SourceFile("<completions>", expr.toCharArray)
159+
val file = new SourceFile("<completions>", expr)
160160
val unit = new CompilationUnit(file)
161161
unit.tpdTree = tree
162162
implicit val ctx = state.run.runContext.fresh.setCompilationUnit(unit)

compiler/test/dotty/tools/dotc/ast/UntypedTreeMapTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class UntpdTreeMapTest extends DottyTest {
1414
import untpd._
1515

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

compiler/test/dotty/tools/dotc/parsing/ModifiersParsingTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object ModifiersParsingTest {
1717
implicit val ctx: Context = (new ContextBase).initialCtx
1818

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

0 commit comments

Comments
 (0)