Skip to content

Commit 469fefe

Browse files
committed
Factor desugarIdent functionality
1 parent 6bd882e commit 469fefe

File tree

6 files changed

+18
-43
lines changed

6 files changed

+18
-43
lines changed

compiler/sjs/backend/sjs/JSCodeGen.scala

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -850,21 +850,6 @@ class JSCodeGen()(implicit ctx: Context) {
850850
}
851851
} // end of genStatOrExpr()
852852

853-
// !!! DUPLICATE code with DottyBackendInterface
854-
private def desugarIdent(i: Ident): Option[Select] = {
855-
i.tpe match {
856-
case TermRef(prefix: TermRef, name) =>
857-
Some(tpd.ref(prefix).select(i.symbol))
858-
case TermRef(prefix: ThisType, name) =>
859-
Some(tpd.This(prefix.cls).select(i.symbol))
860-
/*case TermRef(NoPrefix, name) =>
861-
if (i.symbol is Method) Some(This(i.symbol.topLevelClass).select(i.symbol)) // workaround #342 todo: remove after fixed
862-
else None*/
863-
case _ =>
864-
None
865-
}
866-
}
867-
868853
private def qualifierOf(fun: Tree): Tree = fun match {
869854
case fun: Ident =>
870855
fun.tpe match {

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
444444
def desugarIdent(i: Ident): Option[tpd.Select] = {
445445
var found = desugared.get(i.tpe)
446446
if (found == null) {
447-
i.tpe match {
448-
case TermRef(prefix: TermRef, _) =>
449-
found = tpd.ref(prefix).select(i.symbol)
450-
case TermRef(prefix: ThisType, _) =>
451-
found = tpd.This(prefix.cls).select(i.symbol)
452-
case TermRef(NoPrefix, _) =>
453-
if (i.symbol is Flags.Method) found = This(i.symbol.topLevelClass).select(i.symbol) // workaround #342 todo: remove after fixed
454-
case _ =>
455-
}
447+
found = tpd.desugarIdent(i).orNull
456448
if (found != null) desugared.put(i.tpe, found)
457449
}
458450
if (found == null) None else Some(found)

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -829,13 +829,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
829829
val setter = tree.symbol.setter
830830
assert(setter.exists, tree.symbol.showLocated)
831831
val qual = tree match {
832-
case id: Ident =>
833-
id.tpe match {
834-
case TermRef(prefix: TermRef, _) =>
835-
ref(prefix)
836-
case TermRef(prefix: ThisType, _) =>
837-
This(prefix.cls)
838-
}
832+
case id: Ident => desugarIdentPrefix(id)
839833
case Select(qual, _) => qual
840834
}
841835
qual.select(setter).appliedTo(rhs)
@@ -1017,5 +1011,21 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
10171011
val encoding = ctx.settings.encoding.value
10181012
if (file != null && file.exists) new SourceFile(file, Codec(encoding)) else NoSource
10191013
}
1014+
1015+
/** Desugar identifier into a select node. Return None if not possible */
1016+
def desugarIdent(tree: Ident)(implicit ctx: Context): Option[Select] = {
1017+
val qual = desugarIdentPrefix(tree)
1018+
if (qual.isEmpty) None
1019+
else Some(qual.select(tree.symbol))
1020+
}
1021+
1022+
private def desugarIdentPrefix(tree: Ident)(implicit ctx: Context): Tree = tree.tpe match {
1023+
case TermRef(prefix: TermRef, _) =>
1024+
ref(prefix)
1025+
case TermRef(prefix: ThisType, _) =>
1026+
This(prefix.cls)
1027+
case _ =>
1028+
EmptyTree
1029+
}
10201030
}
10211031

compiler/src/dotty/tools/dotc/transform/localopt/ConstantFold.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import core.Symbols._
66
import core.Types._
77
import typer.ConstFold
88
import ast.Trees._
9-
import Simplify.desugarIdent
109

1110
/** Various constant folding.
1211
*

compiler/src/dotty/tools/dotc/transform/localopt/InlineCaseIntrinsics.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import core.Flags._
1010
import core.TypeApplications.noBounds
1111
import ast.Trees._
1212
import transform.SymUtils._
13-
import Simplify.desugarIdent
1413
import dotty.tools.dotc.ast.tpd
1514

1615
/** Inline case class specific methods using desugarings assumptions.

compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,6 @@ class Simplify extends MiniPhase with IdentityDenotTransformer {
149149

150150
object Simplify {
151151
import tpd._
152-
// TODO: This function is duplicated in jvm/DottyBackendInterface.scala, let's factor these out!
153-
def desugarIdent(i: Ident)(implicit ctx: Context): Option[Select] = {
154-
i.tpe match {
155-
case TermRef(prefix: TermRef, _) =>
156-
Some(ref(prefix).select(i.symbol))
157-
case TermRef(prefix: ThisType, _) =>
158-
Some(This(prefix.cls).select(i.symbol))
159-
case _ => None
160-
}
161-
}
162152

163153
/** Is this tree mutable, or java.lang.System.{in, out, err}? These three
164154
* System members are the only static final fields that are mutable.

0 commit comments

Comments
 (0)