Skip to content

Commit 19f89e7

Browse files
committed
Implement TASTy reflect constructors
1 parent 9ed0524 commit 19f89e7

File tree

12 files changed

+628
-42
lines changed

12 files changed

+628
-42
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,13 @@ object Trees {
974974
* so that they selectively retype themselves. Retyping needs a context.
975975
*/
976976
abstract class TreeCopier {
977-
def postProcess(tree: Tree, copied: untpd.Tree): copied.ThisTree[T]
978-
def postProcess(tree: Tree, copied: untpd.MemberDef): copied.ThisTree[T]
977+
protected def postProcess(tree: Tree, copied: untpd.Tree): copied.ThisTree[T]
978+
protected def postProcess(tree: Tree, copied: untpd.MemberDef): copied.ThisTree[T]
979979

980-
def finalize(tree: Tree, copied: untpd.Tree): copied.ThisTree[T] =
980+
protected def finalize(tree: Tree, copied: untpd.Tree): copied.ThisTree[T] =
981981
postProcess(tree, copied.withPos(tree.pos).withAttachmentsFrom(tree))
982982

983-
def finalize(tree: Tree, copied: untpd.MemberDef): copied.ThisTree[T] =
983+
protected def finalize(tree: Tree, copied: untpd.MemberDef): copied.ThisTree[T] =
984984
postProcess(tree, copied.withPos(tree.pos).withAttachmentsFrom(tree))
985985

986986
def Ident(tree: Tree)(name: Name): Ident = tree match {

compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dotty.tools.dotc.tastyreflect
22

3+
import dotty.tools.dotc.ast.tpd
34

45
trait CaseDefOpsImpl extends scala.tasty.reflect.CaseDefOps with CoreImpl with Helpers {
56

@@ -10,6 +11,11 @@ trait CaseDefOpsImpl extends scala.tasty.reflect.CaseDefOps with CoreImpl with H
1011
}
1112

1213
object CaseDef extends CaseDefModule {
14+
def apply(pat: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef = ???
15+
16+
def copy(original: CaseDef)(pat: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef =
17+
tpd.cpy.CaseDef(original)(pat, guard.getOrElse(tpd.EmptyTree), body)
18+
1319
def unapply(x: CaseDef): Some[(Pattern, Option[Term], Term)] = Some(x.pat, optional(x.guard), x.body)
1420
}
1521

compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ trait CoreImpl extends scala.tasty.reflect.Core {
2626
type Term = tpd.Tree
2727
val Term: TermCoreModuleImpl
2828
trait TermCoreModuleImpl extends TermCoreModule {
29-
type Ident = tpd.Ident
30-
type Select = tpd.Select
29+
type Ref = tpd.RefTree
30+
type Ident = tpd.Ident
31+
type Select = tpd.Select
3132
type Literal = tpd.Literal
3233
type This = tpd.This
3334
type New = tpd.New

compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala

+169-9
Large diffs are not rendered by default.

compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala

+9-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
2323
}
2424

2525
object IsTypeTree extends IsTypeTreeModule {
26-
def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] =
27-
if (x.isType) Some(x) else None
28-
def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree] =
29-
if (termOrTypeTree.isType) Some(termOrTypeTree) else None
26+
def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] = x match {
27+
case x: tpd.TypeBoundsTree => None
28+
case _ => if (x.isType) Some(x) else None
29+
}
30+
31+
def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree] = termOrTypeTree match {
32+
case _: tpd.TypeBoundsTree => None
33+
case _ => if (termOrTypeTree.isType) Some(termOrTypeTree) else None
34+
}
3035
}
3136

3237
object TypeTree extends TypeTreeModule with TypeTreeCoreModuleImpl {

library/src/scala/tasty/reflect/CaseDefOps.scala

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ trait CaseDefOps extends Core {
1313

1414
val CaseDef: CaseDefModule
1515
abstract class CaseDefModule {
16+
17+
def apply(pat: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef
18+
19+
def copy(original: CaseDef)(pat: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef
20+
1621
def unapply(x: CaseDef): Option[(Pattern, Option[Term], Term)]
1722
}
1823

library/src/scala/tasty/reflect/Core.scala

+11-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ package scala.tasty.reflect
1313
* | +- DefDef
1414
* | +- ValDef
1515
* |
16-
* +- Term --------+- Ident
17-
* +- Select
16+
* +- Term --------+- Ref -+- Ident
17+
* | +- Select
18+
* |
1819
* +- Literal
1920
* +- This
2021
* +- New
@@ -164,11 +165,14 @@ trait Core {
164165
/** Trees representing an expression in the source code */
165166
trait TermCoreModule {
166167

167-
/** Tree representing a reference to definition with a given name */
168-
type Ident <: Term
168+
/** Tree representing a reference to definition */
169+
type Ref <: Term
169170

170-
/** Tree representing a selection of definition with a given name on a given prefix */
171-
type Select <: Term
171+
/** Tree representing a reference to definition with a given name */
172+
type Ident <: Ref
173+
174+
/** Tree representing a selection of definition with a given name on a given prefix */
175+
type Select <: Ref
172176

173177
/** Tree representing a literal value in the source code */
174178
type Literal <: Term
@@ -316,7 +320,7 @@ trait Core {
316320
type TypeBoundsTree <: TypeOrBoundsTree
317321

318322
/** Type tree representing wildcard type bounds written in the source.
319-
* The wildcard type `_` (for example in in `List[_]`) will be a type tree that
323+
* The wildcard type `_` (for example in in `List[_]`) will be a type tree that
320324
* represents a type but has `TypeBound`a inside.
321325
*/
322326
type WildcardType <: TypeOrBoundsTree

0 commit comments

Comments
 (0)