Skip to content

Commit 167b516

Browse files
committed
Merge branch 'master' into tasty-scalatest-assert
2 parents 99523c7 + 4e5cf82 commit 167b516

File tree

21 files changed

+458
-315
lines changed

21 files changed

+458
-315
lines changed

compiler/src/dotty/tools/dotc/tasty/TastyImpl.scala

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import dotty.tools.dotc.util.SourcePosition
1313

1414
import scala.quoted
1515
import scala.reflect.ClassTag
16+
import scala.tasty.util.{Show, ShowExtractors}
1617

1718
object TastyImpl extends scala.tasty.Tasty {
1819

@@ -26,6 +27,15 @@ object TastyImpl extends scala.tasty.Tasty {
2627
def toTasty(implicit ctx: Context): TypeTree = PickledQuotes.quotedTypeToTree(x)
2728
}
2829

30+
// ===== Show =====================================================
31+
32+
def defaultShow: Show[this.type] = showExtractors
33+
34+
def showExtractors: Show[this.type] = new ShowExtractors(this)
35+
36+
// TODO
37+
// def showSourceCode: Show[this.type] = ???
38+
2939
// ===== Contexts =================================================
3040

3141
type Context = Contexts.Context
@@ -55,8 +65,9 @@ object TastyImpl extends scala.tasty.Tasty {
5565

5666
type Tree = tpd.Tree
5767

58-
def TreeDeco(t: Tree): AbstractTree = new AbstractTree {
59-
def pos(implicit ctx: Context): Position = t.pos
68+
def TreeDeco(tree: Tree): AbstractTree = new AbstractTree {
69+
def show(implicit ctx: Context, s: Show[TastyImpl.this.type]): String = s.showTree(tree)
70+
def pos(implicit ctx: Context): Position = tree.pos
6071
}
6172

6273
type PackageClause = tpd.PackageDef
@@ -482,8 +493,9 @@ object TastyImpl extends scala.tasty.Tasty {
482493

483494
type TypeOrBoundsTree = tpd.Tree
484495

485-
def TypeOrBoundsTreeDeco(x: TypeOrBoundsTree): AbstractTypeOrBoundsTree = new AbstractTypeOrBoundsTree {
486-
def tpe(implicit ctx: Context): Type = x.tpe.stripTypeVar
496+
def TypeOrBoundsTreeDeco(tpt: TypeOrBoundsTree): AbstractTypeOrBoundsTree = new AbstractTypeOrBoundsTree {
497+
def show(implicit ctx: Context, s: Show[TastyImpl.this.type]): String = s.showTypeOrBoundsTree(tpt)
498+
def tpe(implicit ctx: Context): Type = tpt.tpe.stripTypeVar
487499
}
488500

489501
// ----- TypeTrees ------------------------------------------------
@@ -592,6 +604,10 @@ object TastyImpl extends scala.tasty.Tasty {
592604

593605
type TypeOrBounds = Types.Type
594606

607+
def TypeOrBoundsDeco(tpe: Types.Type): AbstractTypeOrBounds = new AbstractTypeOrBounds {
608+
def show(implicit ctx: Context, s: Show[TastyImpl.this.type]): String = s.showTypeOrBounds(tpe)
609+
}
610+
595611
// ----- Types ----------------------------------------------------
596612

597613
type Type = Types.Type
@@ -789,8 +805,9 @@ object TastyImpl extends scala.tasty.Tasty {
789805

790806
type Constant = Constants.Constant
791807

792-
def ConstantDeco(x: Constant): AbstractConstant = new AbstractConstant {
793-
def value: Any = x.value
808+
def ConstantDeco(const: Constant): AbstractConstant = new AbstractConstant {
809+
def show(implicit ctx: Context, s: Show[TastyImpl.this.type]): String = s.showConstant(const)
810+
def value: Any = const.value
794811
}
795812

796813
def constantClassTag: ClassTag[Constant] = implicitly[ClassTag[Constant]]

library/src/scala/tasty/Tasty.scala

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package scala.tasty
22

33
import scala.reflect.ClassTag
4+
import scala.tasty.util.Show
45

5-
abstract class Tasty {
6+
abstract class Tasty { tasty =>
67

78
// ===== Quotes ===================================================
89

@@ -16,14 +17,23 @@ abstract class Tasty {
1617
}
1718
implicit def QuotedTypeDeco[T](x: quoted.Type[T]): AbstractQuotedType
1819

20+
// ===== Show =====================================================
21+
22+
implicit def defaultShow: Show[tasty.type]
23+
24+
def showExtractors: Show[tasty.type]
25+
26+
// TODO
27+
// def showSourceCode: Show[tasty.type]
28+
1929
// ===== Contexts =================================================
2030

2131
type Context
2232

2333
trait AbstractContext {
2434
def owner: Definition
2535
}
26-
implicit def ContextDeco(x: Context): AbstractContext
36+
implicit def ContextDeco(ctx: Context): AbstractContext
2737

2838
// ===== Id =======================================================
2939

@@ -43,8 +53,10 @@ abstract class Tasty {
4353

4454
type Tree
4555

46-
trait AbstractTree extends Positioned
47-
implicit def TreeDeco(t: Tree): AbstractTree
56+
trait AbstractTree extends Positioned {
57+
def show(implicit ctx: Context, s: Show[tasty.type]): String
58+
}
59+
implicit def TreeDeco(tree: Tree): AbstractTree
4860

4961
type PackageClause <: Tree
5062

@@ -337,9 +349,10 @@ abstract class Tasty {
337349
type TypeOrBoundsTree
338350

339351
trait AbstractTypeOrBoundsTree {
352+
def show(implicit ctx: Context, s: Show[tasty.type]): String
340353
def tpe(implicit ctx: Context): TypeOrBounds
341354
}
342-
implicit def TypeOrBoundsTreeDeco(x: TypeOrBoundsTree): AbstractTypeOrBoundsTree
355+
implicit def TypeOrBoundsTreeDeco(tpt: TypeOrBoundsTree): AbstractTypeOrBoundsTree
343356

344357

345358
// ----- TypeTrees ------------------------------------------------
@@ -432,6 +445,11 @@ abstract class Tasty {
432445
def tpe(implicit ctx: Context): Type
433446
}
434447

448+
trait AbstractTypeOrBounds {
449+
def show(implicit ctx: Context, s: Show[tasty.type]): String
450+
}
451+
implicit def TypeOrBoundsDeco(tpe: TypeOrBounds): AbstractTypeOrBounds
452+
435453
// ----- Types ----------------------------------------------------
436454

437455
type Type <: TypeOrBounds
@@ -578,9 +596,10 @@ abstract class Tasty {
578596

579597
type Constant
580598
trait AbstractConstant {
599+
def show(implicit ctx: Context, s: Show[tasty.type]): String
581600
def value: Any
582601
}
583-
implicit def ConstantDeco(x: Constant): AbstractConstant
602+
implicit def ConstantDeco(const: Constant): AbstractConstant
584603

585604
implicit def constantClassTag: ClassTag[Constant]
586605

library/src/scala/tasty/Universe.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scala.tasty
22

33
trait Universe {
4-
implicit val tasty: Tasty
4+
val tasty: Tasty
55
implicit val context: tasty.Context
66
}
77

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package scala.tasty.util
2+
3+
import scala.tasty.Tasty
4+
5+
abstract class Show[T <: Tasty with Singleton](val tasty: T) {
6+
7+
def showTree(tree: tasty.Tree)(implicit ctx: tasty.Context): String
8+
9+
def showTypeOrBoundsTree(tpt: tasty.TypeOrBoundsTree)(implicit ctx: tasty.Context): String
10+
11+
def showTypeOrBounds(tpe: tasty.TypeOrBounds)(implicit ctx: tasty.Context): String
12+
13+
def showConstant(const: tasty.Constant)(implicit ctx: tasty.Context): String
14+
15+
}

0 commit comments

Comments
 (0)