Skip to content

Commit 8d1b226

Browse files
committed
Implement TASTy reflect constructors
1 parent 3e555e9 commit 8d1b226

File tree

11 files changed

+579
-111
lines changed

11 files changed

+579
-111
lines changed

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ trait CaseDefOpsImpl extends scala.tasty.reflect.CaseDefOps with CoreImpl with H
1010
}
1111

1212
object CaseDef extends CaseDefExtractor {
13+
def apply(pat: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef = ???
14+
15+
def copy(original: CaseDef)(pat: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef = ???
16+
1317
def unapply(x: CaseDef): Some[(Pattern, Option[Term], Term)] = Some(x.pat, optional(x.guard), x.body)
1418
}
1519

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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 160 additions & 29 deletions
Large diffs are not rendered by default.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ trait CaseDefOps extends Core {
1313

1414
val CaseDef: CaseDefExtractor
1515
abstract class CaseDefExtractor {
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)]
22+
1723
}
1824

1925

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

Lines changed: 11 additions & 7 deletions
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)