Skip to content

Commit ca8dc7a

Browse files
committed
Scanners added.
Moving Positions, Chars to new packages. Added Source positions. Added untyped trees module. Factored out behavior between typed and untyped trees.
1 parent e32fedb commit ca8dc7a

29 files changed

+1749
-134
lines changed

src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class ScalaSettings extends Settings.SettingGroup {
6666
val logFreeTypes = BooleanSetting("-Xlog-free-types", "Print a message when reification resorts to generating a free type.")
6767
val maxClassfileName = IntSetting("-Xmax-classfile-name", "Maximum filename length for generated classes", 255, 72 to 255)
6868
val Xmigration28 = BooleanSetting("-Xmigration", "Warn about constructs whose behavior may have changed between 2.7 and 2.8.")
69-
val nouescape = BooleanSetting("-Xno-uescape", "Disable handling of \\u unicode escapes.")
7069
val Xnojline = BooleanSetting("-Xnojline", "Do not use JLine for editing.")
7170
val Xverify = BooleanSetting("-Xverify", "Verify generic signatures in generated bytecode (asm backend only.)")
7271
val plugin = MultiStringSetting("-Xplugin", "file", "Load one or more plugins from files.")

src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package dotty.tools.dotc.core
1+
package dotty.tools.dotc
2+
package core
23

3-
import Symbols._, Types._, Positions._, Contexts._, Constants._, TypedTrees.tpd._
4+
import Symbols._, Types._, util.Positions._, Contexts._, Constants._, TypedTrees.tpd._
45

56
object Annotations {
67

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import Names._
88
import Phases._
99
import Types._
1010
import Symbols._
11-
import TypeComparers._, Printers._, NameOps._, SymDenotations._, Positions._
12-
import TypedTrees.tpd._
11+
import TypeComparers._, Printers._, NameOps._, SymDenotations._, util.Positions._
12+
import TypedTrees.tpd._, util.FreshNameCreator
1313
import config.Settings._
1414
import config.ScalaSettings
1515
import reporting._
@@ -172,7 +172,7 @@ object Contexts {
172172
/** The current source file; will be derived from current
173173
* compilation unit.
174174
*/
175-
def source = io.NoSource // for now
175+
def source = util.NoSource // for now
176176

177177
/** Does current phase use an erased types interpretation? */
178178
def erasedTypes: Boolean = phase.erasedTypes
@@ -289,6 +289,9 @@ object Contexts {
289289
/** The platform */
290290
val platform: Platform = new JavaPlatform
291291

292+
/** The standard fresh name creator */
293+
val fresh = new FreshNameCreator.Default
294+
292295
/** The loader that loads the members of _root_ */
293296
def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = platform.rootLoader(root)
294297

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package core
44

55
import Types._, Contexts._, Symbols._, Denotations._, SymDenotations._, StdNames._, Names._
6-
import Flags._, Scopes._, Decorators._, NameOps._, Positions._
6+
import Flags._, Scopes._, Decorators._, NameOps._, util.Positions._
77
import scala.annotation.{ switch, meta }
88
import scala.collection.{ mutable, immutable }
99
import PartialFunction._

src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package dotty.tools.dotc
22
package core
33

44
import java.security.MessageDigest
5-
import Chars.isOperatorPart
65
import scala.annotation.switch
76
import scala.io.Codec
87
import Names._, StdNames._, Contexts._, Symbols._, Flags._
98
import Decorators.StringDecorator
9+
import dotty.tools.dotc.util.Chars
10+
import Chars.isOperatorPart
1011

1112
object NameOps {
1213

src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ object StdNames {
240240
val SETTER_SUFFIX: N = encode("_=")
241241
val SKOLEM: N = "<skolem>"
242242
val SPECIALIZED_INSTANCE: N = "specInstance$"
243-
val STAR: N = "*"
244243
val THIS: N = "_$this"
245244
val HK_PARAM_PREFIX: N = "_$hk$"
246245

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,12 @@ object SymDenotations {
577577
final def symbolicRef(implicit ctx: Context): TypeRef =
578578
TypeRef.withSym(owner.thisType, symbol.asType)
579579

580+
/** The termref pointing to this termsymbol
581+
* @throws ClassCastException is this is not a term
582+
*/
583+
def termRef(implicit ctx: Context): TermRef =
584+
TermRef.withSym(owner.thisType, symbol.asTerm)
585+
580586
/** The variance of this type parameter as an Int, with
581587
* +1 = Covariant, -1 = Contravariant, 0 = Nonvariant, or not a type parameter
582588
*/

src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package core
1010
import java.io.IOException
1111
import scala.compat.Platform.currentTime
1212
import dotty.tools.io.{ ClassPath, AbstractFile }
13-
import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, Positions._, Names._
13+
import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, util.Positions._, Names._
1414
import StdNames._
1515
import Decorators.StringDecorator
1616
import pickling.ClassfileParser

src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Decorators._
1111
import Symbols._
1212
import Contexts._
1313
import SymDenotations._, util.Texts._
14-
import Types._, Annotations._, Positions._, StdNames._, Trees._, NameOps._
14+
import Types._, Annotations._, util.Positions._, StdNames._, Trees._, NameOps._
1515
import Denotations.{ Denotation, SingleDenotation, MultiDenotation }
1616
import collection.mutable
1717
import io.AbstractFile

src/dotty/tools/dotc/core/Trees.scala

Lines changed: 181 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package dotty.tools.dotc.core
1+
package dotty.tools.dotc
2+
package core
23

3-
import Types._, Names._, Flags._, Positions._, Contexts._, Constants._, SymDenotations._, Symbols._
4+
import Types._, Names._, Flags._, util.Positions._, Contexts._, Constants._, SymDenotations._, Symbols._
45
import Denotations._, StdNames._
56
import annotation.tailrec
67
import language.higherKinds
@@ -110,6 +111,7 @@ object Trees {
110111
override def getMessage: String = s"type of $tree is not assigned"
111112
}
112113

114+
type Untyped = Null
113115
type TypedTree = Tree[Type]
114116
type UntypedTree = Tree[Nothing]
115117

@@ -532,6 +534,9 @@ object Trees {
532534
extends NameTree[Nothing] with DefTree[Nothing] {
533535
type ThisTree[T] <: NameTree[T] with DefTree[T] with ModuleDef
534536
val pos = cpos union impl.pos
537+
def derivedModuleDef(mods: Modifiers[Nothing], name: TermName, impl: Template[Nothing]) =
538+
if (mods == this.mods && name == this.name && (impl eq this.impl)) this
539+
else ModuleDef(mods, name, impl)
535540
}
536541

537542
/** (vparams) => body */
@@ -541,6 +546,78 @@ object Trees {
541546
val pos = unionPos(cpos union body.pos, vparams)
542547
}
543548

549+
/** Something in parentheses */
550+
case class Parens(trees: List[Tree[Nothing]])(implicit cpos: Position) extends Tree[Nothing] {
551+
type ThisType[T] <: Parens
552+
val pos = unionPos(cpos, trees)
553+
}
554+
555+
// ----- Generic Tree Instances, inherited from `tpt` and `untpd`.
556+
557+
abstract class Instance[T] {
558+
559+
type Modifiers = Trees.Modifiers[T]
560+
type Tree = Trees.Tree[T]
561+
type TypTree = Trees.TypTree[T]
562+
type TermTree = Trees.TermTree[T]
563+
type PatternTree = Trees.PatternTree[T]
564+
type DenotingTree = Trees.DenotingTree[T]
565+
type ProxyTree = Trees.ProxyTree[T]
566+
type NameTree = Trees.NameTree[T]
567+
type RefTree = Trees.RefTree[T]
568+
type DefTree = Trees.DefTree[T]
569+
570+
type TreeCopier = Trees.TreeCopier[T]
571+
type TreeAccumulator[U] = Trees.TreeAccumulator[U, T]
572+
type TreeTransformer = Trees.TreeTransformer[T]
573+
574+
type Ident = Trees.Ident[T]
575+
type Select = Trees.Select[T]
576+
type This = Trees.This[T]
577+
type Super = Trees.Super[T]
578+
type Apply = Trees.Apply[T]
579+
type TypeApply = Trees.TypeApply[T]
580+
type Literal = Trees.Literal[T]
581+
type New = Trees.New[T]
582+
type Pair = Trees.Pair[T]
583+
type Typed = Trees.Typed[T]
584+
type NamedArg = Trees.NamedArg[T]
585+
type Assign = Trees.Assign[T]
586+
type Block = Trees.Block[T]
587+
type If = Trees.If[T]
588+
type Match = Trees.Match[T]
589+
type CaseDef = Trees.CaseDef[T]
590+
type Return = Trees.Return[T]
591+
type Try = Trees.Try[T]
592+
type Throw = Trees.Throw[T]
593+
type SeqLiteral = Trees.SeqLiteral[T]
594+
type TypeTree = Trees.TypeTree[T]
595+
type SingletonTypeTree = Trees.SingletonTypeTree[T]
596+
type SelectFromTypeTree = Trees.SelectFromTypeTree[T]
597+
type AndTypeTree = Trees.AndTypeTree[T]
598+
type OrTypeTree = Trees.OrTypeTree[T]
599+
type RefineTypeTree = Trees.RefineTypeTree[T]
600+
type AppliedTypeTree = Trees.AppliedTypeTree[T]
601+
type TypeBoundsTree = Trees.TypeBoundsTree[T]
602+
type Bind = Trees.Bind[T]
603+
type Alternative = Trees.Alternative[T]
604+
type UnApply = Trees.UnApply[T]
605+
type ValDef = Trees.ValDef[T]
606+
type DefDef = Trees.DefDef[T]
607+
type TypeDef = Trees.TypeDef[T]
608+
type Template = Trees.Template[T]
609+
type ClassDef = Trees.ClassDef[T]
610+
type Import = Trees.Import[T]
611+
type PackageDef = Trees.PackageDef[T]
612+
type Annotated = Trees.Annotated[T]
613+
type EmptyTree = Trees.EmptyTree[T]
614+
type SharedTree = Trees.SharedTree[T]
615+
616+
protected implicit def pos(implicit ctx: Context): Position = ctx.position
617+
618+
def defPos(sym: Symbol)(implicit ctx: Context) = ctx.position union sym.coord.toPosition
619+
}
620+
544621
// ----- Helper functions and classes ---------------------------------------
545622

546623
@tailrec final def unionPos(base: Position, trees: List[Tree[_]]): Position = trees match {
@@ -712,7 +789,7 @@ object Trees {
712789
}
713790
}
714791

715-
abstract class TreeTransformer[T, C] {
792+
abstract class FullTreeTransformer[T, C] {
716793
var sharedMemo: Map[SharedTree[T], SharedTree[T]] = Map()
717794

718795
def transform(tree: Tree[T], c: C): Tree[T] = tree match {
@@ -861,6 +938,107 @@ object Trees {
861938
def finishSharedTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
862939
}
863940

941+
abstract class TreeTransformer[T] {
942+
var sharedMemo: Map[SharedTree[T], SharedTree[T]] = Map()
943+
944+
def transform(tree: Tree[T]): Tree[T] = tree match {
945+
case Ident(name) =>
946+
tree
947+
case Select(qualifier, name) =>
948+
tree.derivedSelect(transform(qualifier), name)
949+
case This(qual) =>
950+
tree
951+
case Super(qual, mix) =>
952+
tree.derivedSuper(transform(qual), mix)
953+
case Apply(fun, args) =>
954+
tree.derivedApply(transform(fun), transform(args))
955+
case TypeApply(fun, args) =>
956+
tree.derivedTypeApply(transform(fun), transform(args))
957+
case Literal(const) =>
958+
tree
959+
case New(tpt) =>
960+
tree.derivedNew(transform(tpt))
961+
case Pair(left, right) =>
962+
tree.derivedPair(transform(left), transform(right))
963+
case Typed(expr, tpt) =>
964+
tree.derivedTyped(transform(expr), transform(tpt))
965+
case NamedArg(name, arg) =>
966+
tree.derivedNamedArg(name, transform(arg))
967+
case Assign(lhs, rhs) =>
968+
tree.derivedAssign(transform(lhs), transform(rhs))
969+
case Block(stats, expr) =>
970+
tree.derivedBlock(transform(stats), transform(expr))
971+
case If(cond, thenp, elsep) =>
972+
tree.derivedIf(transform(cond), transform(thenp), transform(elsep))
973+
case Match(selector, cases) =>
974+
tree.derivedMatch(transform(selector), transformSub(cases))
975+
case CaseDef(pat, guard, body) =>
976+
tree.derivedCaseDef(transform(pat), transform(guard), transform(body))
977+
case Return(expr, from) =>
978+
tree.derivedReturn(transform(expr), transformSub(from))
979+
case Try(block, catches, finalizer) =>
980+
tree.derivedTry(transform(block), transformSub(catches), transform(finalizer))
981+
case Throw(expr) =>
982+
tree.derivedThrow(transform(expr))
983+
case SeqLiteral(elemtpt, elems) =>
984+
tree.derivedSeqLiteral(transform(elemtpt), transform(elems))
985+
case TypeTree(original) =>
986+
tree.derivedTypeTree(transform(original))
987+
case SingletonTypeTree(ref) =>
988+
tree.derivedSingletonTypeTree(transform(ref))
989+
case SelectFromTypeTree(qualifier, name) =>
990+
tree.derivedSelectFromTypeTree(transform(qualifier), name)
991+
case AndTypeTree(left, right) =>
992+
tree.derivedAndTypeTree(transform(left), transform(right))
993+
case OrTypeTree(left, right) =>
994+
tree.derivedOrTypeTree(transform(left), transform(right))
995+
case RefineTypeTree(tpt, refinements) =>
996+
tree.derivedRefineTypeTree(transform(tpt), transformSub(refinements))
997+
case AppliedTypeTree(tpt, args) =>
998+
tree.derivedAppliedTypeTree(transform(tpt), transform(args))
999+
case TypeBoundsTree(lo, hi) =>
1000+
tree.derivedTypeBoundsTree(transform(lo), transform(hi))
1001+
case Bind(name, body) =>
1002+
tree.derivedBind(name, transform(body))
1003+
case Alternative(trees) =>
1004+
tree.derivedAlternative(transform(trees))
1005+
case UnApply(fun, args) =>
1006+
tree.derivedUnApply(transform(fun), transform(args))
1007+
case ValDef(mods, name, tpt, rhs) =>
1008+
tree.derivedValDef(mods, name, transform(tpt), transform(rhs))
1009+
case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
1010+
tree.derivedDefDef(mods, name, transformSub(tparams), vparamss mapConserve (transformSub(_)), transform(tpt), transform(rhs))
1011+
case TypeDef(mods, name, rhs) =>
1012+
tree.derivedTypeDef(mods, name, transform(rhs))
1013+
case Template(parents, self, body) =>
1014+
tree.derivedTemplate(transform(parents), transformSub(self), transform(body))
1015+
case ClassDef(mods, name, tparams, impl) =>
1016+
tree.derivedClassDef(mods, name, transformSub(tparams), transformSub(impl))
1017+
case Import(expr, selectors) =>
1018+
tree.derivedImport(transform(expr), selectors)
1019+
case PackageDef(pid, stats) =>
1020+
tree.derivedPackageDef(transformSub(pid), transform(stats))
1021+
case Annotated(annot, arg) =>
1022+
tree.derivedAnnotated(transform(annot), transform(arg))
1023+
case EmptyTree() =>
1024+
tree
1025+
case tree @ SharedTree(shared) =>
1026+
sharedMemo get tree match {
1027+
case Some(tree1) => tree1
1028+
case None =>
1029+
val tree1 = tree.derivedSharedTree(transform(shared))
1030+
sharedMemo = sharedMemo.updated(tree, tree1)
1031+
tree1
1032+
}
1033+
}
1034+
def transform(trees: List[Tree[T]]): List[Tree[T]] =
1035+
trees mapConserve (transform(_))
1036+
def transformSub(tree: Tree[T]): tree.ThisTree[T] =
1037+
transform(tree).asInstanceOf[tree.ThisTree[T]]
1038+
def transformSub[TT <: Tree[T]](trees: List[TT]): List[TT] =
1039+
transform(trees).asInstanceOf[List[TT]]
1040+
}
1041+
8641042
abstract class TreeAccumulator[T, U] extends ((T, Tree[U]) => T) {
8651043
var sharedMemo: Map[SharedTree[U], T] = Map()
8661044
def apply(x: T, tree: Tree[U]): T

0 commit comments

Comments
 (0)