Skip to content

Commit e724058

Browse files
authored
Merge pull request #5713 from dotty-staging/refactor-sourcepos
Simplify Source Positions
2 parents b5331a3 + fc2e654 commit e724058

File tree

182 files changed

+2829
-2494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+2829
-2494
lines changed

compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import SymDenotations._
1212
import Contexts._
1313
import Types._
1414
import Symbols._
15-
import dotty.tools.dotc.util.Positions.Position
15+
import dotty.tools.dotc.util.SourcePosition
1616
import Decorators._
1717
import StdNames.nme
1818

@@ -47,10 +47,10 @@ object CollectEntryPoints{
4747
def hasJavaMainMethod(sym: Symbol): Boolean =
4848
(toDenot(sym).info member nme.main).alternatives exists(x => isJavaMainMethod(x.symbol))
4949

50-
def fail(msg: String, pos: Position = sym.pos) = {
51-
ctx.warning( sym.name +
52-
s" has a main method with parameter type Array[String], but ${toDenot(sym).fullName} will not be a runnable program.\n Reason: $msg",
53-
sourcePos(sym.pos)
50+
def fail(msg: String, pos: SourcePosition = sym.sourcePos) = {
51+
ctx.warning(
52+
i"""${sym.name} has a main method with parameter type Array[String], but ${sym.fullName} will not be a runnable program.
53+
|Reason: $msg""", sym.sourcePos
5454
// TODO: make this next claim true, if possible
5555
// by generating valid main methods as static in module classes
5656
// not sure what the jvm allows here
@@ -92,11 +92,11 @@ object CollectEntryPoints{
9292
fail("main methods cannot be generic.")
9393
case MethodTpe(paramNames, paramTypes, resultType) =>
9494
if (resultType :: paramTypes exists (_.typeSymbol.isAbstractType))
95-
fail("main methods cannot refer to type parameters or abstract types.", m.symbol.pos)
95+
fail("main methods cannot refer to type parameters or abstract types.", m.symbol.sourcePos)
9696
else
97-
isJavaMainMethod(m.symbol) || fail("main method must have exact signature (Array[String])Unit", m.symbol.pos)
97+
isJavaMainMethod(m.symbol) || fail("main method must have exact signature (Array[String])Unit", m.symbol.sourcePos)
9898
case tp =>
99-
fail(s"don't know what this is: $tp", m.symbol.pos)
99+
fail(s"don't know what this is: $tp", m.symbol.sourcePos)
100100
}
101101
}
102102
}

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import Types._
2121
import Symbols._
2222
import Phases._
2323

24-
import dotty.tools.dotc.util.Positions
24+
import dotty.tools.dotc.util
25+
import dotty.tools.dotc.util.Spans
2526
import Decorators._
2627
import tpd._
2728

@@ -41,7 +42,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
4142
type CompilationUnit = dotc.CompilationUnit
4243
type Constant = Constants.Constant
4344
type Literal = tpd.Literal
44-
type Position = Positions.Position
45+
type Position = Spans.Span
4546
type Name = Names.Name
4647
type ClassDef = tpd.TypeDef
4748
type TypeDef = tpd.TypeDef
@@ -77,7 +78,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
7778
type Closure = tpd.Closure
7879

7980
val NoSymbol: Symbol = Symbols.NoSymbol
80-
val NoPosition: Position = Positions.NoPosition
81+
val NoPosition: Position = Spans.NoSpan
8182
val EmptyTree: Tree = tpd.EmptyTree
8283

8384

@@ -380,16 +381,17 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
380381
ctx.requiredModule(className)
381382
}
382383

383-
384384
def debuglog(msg: => String): Unit = ctx.debuglog(msg)
385385
def informProgress(msg: String): Unit = ctx.informProgress(msg)
386386
def log(msg: => String): Unit = ctx.log(msg)
387-
def error(pos: Position, msg: String): Unit = ctx.error(msg, pos)
388-
def warning(pos: Position, msg: String): Unit = ctx.warning(msg, pos)
387+
def error(pos: Position, msg: String): Unit = ctx.error(msg, sourcePos(pos))
388+
def warning(pos: Position, msg: String): Unit = ctx.warning(msg, sourcePos(pos))
389389
def abort(msg: String): Nothing = {
390390
ctx.error(msg)
391391
throw new RuntimeException(msg)
392392
}
393+
def sourcePos(pos: Position)(implicit ctx: Context): util.SourcePosition =
394+
ctx.source.atSpan(pos)
393395

394396
def emitAsmp: Option[String] = None
395397

@@ -502,7 +504,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
502504
i"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName}
503505
|signature: $sig
504506
|if this is reproducible, please report bug at https://github.com/lampepfl/dotty/issues
505-
""".trim, sym.pos)
507+
""".trim, sym.sourcePos)
506508
}
507509
}
508510

@@ -587,7 +589,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
587589
implicit def treeHelper(a: Tree): TreeHelper = new TreeHelper {
588590
def symbol: Symbol = a.symbol
589591

590-
def pos: Position = a.pos
592+
def pos: Position = a.span
591593

592594
def isEmpty: Boolean = a.isEmpty
593595

@@ -809,7 +811,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
809811

810812
def moduleSuffix: String = "" // todo: validate that names already have $ suffix
811813
def outputDirectory: AbstractFile = DottyBackendInterface.this.outputDirectory
812-
def pos: Position = sym.pos
814+
def pos: Position = sym.span
813815

814816
def throwsAnnotations: List[Symbol] = Nil
815817

@@ -1105,7 +1107,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11051107
def _1: Type = field.tpe match {
11061108
case JavaArrayType(elem) => elem
11071109
case _ =>
1108-
ctx.error(s"JavaSeqArray with type ${field.tpe} reached backend: $field", field.pos)
1110+
error(field.span, s"JavaSeqArray with type ${field.tpe} reached backend: $field")
11091111
UnspecifiedErrorType
11101112
}
11111113
def _2: List[Tree] = field.elems

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
163163
else (dupClassSym, classSymbol)
164164
ctx.atPhase(ctx.typerPhase) { implicit ctx =>
165165
ctx.warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " +
166-
"Such classes will overwrite one another on case-insensitive filesystems.", cl1.pos)
166+
"Such classes will overwrite one another on case-insensitive filesystems.", cl1.sourcePos)
167167
}
168168
}
169169
}

0 commit comments

Comments
 (0)