|
1 |
| -package scala |
| 1 | +package scala.quoted |
2 | 2 |
|
3 |
| -package quoted { |
4 |
| - import scala.quoted.show.SyntaxHighlight |
| 3 | +import scala.quoted.show.SyntaxHighlight |
5 | 4 |
|
6 |
| - sealed trait Type[T <: AnyKind] { |
7 |
| - type `$splice` = T |
| 5 | +/** Quoted type (or kind) `T` |
| 6 | + * |
| 7 | + * Restriction: only the QuoteContext implementation is allowed to extend this trait. |
| 8 | + * Any other implementation will result in an undefined behavior. |
| 9 | + */ |
| 10 | +trait Type[T <: AnyKind] { |
| 11 | + type `$splice` = T |
8 | 12 |
|
9 |
| - /** Show a source code like representation of this type without syntax highlight */ |
10 |
| - def show(given qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain) |
| 13 | + /** Show a source code like representation of this type without syntax highlight */ |
| 14 | + def show(given qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain) |
11 | 15 |
|
12 |
| - /** Show a source code like representation of this type */ |
13 |
| - def show(syntaxHighlight: SyntaxHighlight)(given qctx: QuoteContext): String = qctx.show(this, syntaxHighlight) |
| 16 | + /** Show a source code like representation of this type */ |
| 17 | + def show(syntaxHighlight: SyntaxHighlight)(given qctx: QuoteContext): String = qctx.show(this, syntaxHighlight) |
14 | 18 |
|
| 19 | +} |
| 20 | + |
| 21 | +/** Some basic type tags, currently incomplete */ |
| 22 | +object Type { |
| 23 | + |
| 24 | + given UnitTag(given qctx: QuoteContext): Type[Unit] = { |
| 25 | + import qctx.tasty.{_, given} |
| 26 | + defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]] |
15 | 27 | }
|
16 | 28 |
|
17 |
| - /** Some basic type tags, currently incomplete */ |
18 |
| - object Type { |
19 |
| - |
20 |
| - given UnitTag(given qctx: QuoteContext): Type[Unit] = { |
21 |
| - import qctx.tasty.{_, given} |
22 |
| - defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]] |
23 |
| - } |
24 |
| - |
25 |
| - given BooleanTag(given qctx: QuoteContext): Type[Boolean] = { |
26 |
| - import qctx.tasty.{_, given} |
27 |
| - defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]] |
28 |
| - } |
29 |
| - |
30 |
| - given ByteTag(given qctx: QuoteContext): Type[Byte] = { |
31 |
| - import qctx.tasty.{_, given} |
32 |
| - defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]] |
33 |
| - } |
34 |
| - |
35 |
| - given CharTag(given qctx: QuoteContext): Type[Char] = { |
36 |
| - import qctx.tasty.{_, given} |
37 |
| - defn.CharType.seal.asInstanceOf[quoted.Type[Char]] |
38 |
| - } |
39 |
| - |
40 |
| - given ShortTag(given qctx: QuoteContext): Type[Short] = { |
41 |
| - import qctx.tasty.{_, given} |
42 |
| - defn.ShortType.seal.asInstanceOf[quoted.Type[Short]] |
43 |
| - } |
44 |
| - |
45 |
| - given IntTag(given qctx: QuoteContext): Type[Int] = { |
46 |
| - import qctx.tasty.{_, given} |
47 |
| - defn.IntType.seal.asInstanceOf[quoted.Type[Int]] |
48 |
| - } |
49 |
| - |
50 |
| - given LongTag(given qctx: QuoteContext): Type[Long] = { |
51 |
| - import qctx.tasty.{_, given} |
52 |
| - defn.LongType.seal.asInstanceOf[quoted.Type[Long]] |
53 |
| - } |
54 |
| - |
55 |
| - given FloatTag(given qctx: QuoteContext): Type[Float] = { |
56 |
| - import qctx.tasty.{_, given} |
57 |
| - defn.FloatType.seal.asInstanceOf[quoted.Type[Float]] |
58 |
| - } |
59 |
| - |
60 |
| - given DoubleTag(given qctx: QuoteContext): Type[Double] = { |
61 |
| - import qctx.tasty.{_, given} |
62 |
| - defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]] |
63 |
| - } |
| 29 | + given BooleanTag(given qctx: QuoteContext): Type[Boolean] = { |
| 30 | + import qctx.tasty.{_, given} |
| 31 | + defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]] |
| 32 | + } |
64 | 33 |
|
| 34 | + given ByteTag(given qctx: QuoteContext): Type[Byte] = { |
| 35 | + import qctx.tasty.{_, given} |
| 36 | + defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]] |
65 | 37 | }
|
66 | 38 |
|
67 |
| -} |
| 39 | + given CharTag(given qctx: QuoteContext): Type[Char] = { |
| 40 | + import qctx.tasty.{_, given} |
| 41 | + defn.CharType.seal.asInstanceOf[quoted.Type[Char]] |
| 42 | + } |
| 43 | + |
| 44 | + given ShortTag(given qctx: QuoteContext): Type[Short] = { |
| 45 | + import qctx.tasty.{_, given} |
| 46 | + defn.ShortType.seal.asInstanceOf[quoted.Type[Short]] |
| 47 | + } |
| 48 | + |
| 49 | + given IntTag(given qctx: QuoteContext): Type[Int] = { |
| 50 | + import qctx.tasty.{_, given} |
| 51 | + defn.IntType.seal.asInstanceOf[quoted.Type[Int]] |
| 52 | + } |
68 | 53 |
|
69 |
| -package internal { |
70 |
| - package quoted { |
71 |
| - |
72 |
| - /** An Type backed by a tree */ |
73 |
| - final class TreeType[Tree](val typeTree: Tree, val scopeId: Int) extends scala.quoted.Type[Any] { |
74 |
| - override def equals(that: Any): Boolean = that match { |
75 |
| - case that: TreeType[_] => typeTree == |
76 |
| - // TastyTreeExpr are wrappers around trees, therfore they are equals if their trees are equal. |
77 |
| - // All scopeId should be equal unless two different runs of the compiler created the trees. |
78 |
| - that.typeTree && scopeId == that.scopeId |
79 |
| - case _ => false |
80 |
| - } |
81 |
| - override def hashCode: Int = typeTree.hashCode |
82 |
| - override def toString: String = s"Type(<tasty tree>)" |
83 |
| - } |
| 54 | + given LongTag(given qctx: QuoteContext): Type[Long] = { |
| 55 | + import qctx.tasty.{_, given} |
| 56 | + defn.LongType.seal.asInstanceOf[quoted.Type[Long]] |
| 57 | + } |
84 | 58 |
|
| 59 | + given FloatTag(given qctx: QuoteContext): Type[Float] = { |
| 60 | + import qctx.tasty.{_, given} |
| 61 | + defn.FloatType.seal.asInstanceOf[quoted.Type[Float]] |
85 | 62 | }
|
| 63 | + |
| 64 | + given DoubleTag(given qctx: QuoteContext): Type[Double] = { |
| 65 | + import qctx.tasty.{_, given} |
| 66 | + defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]] |
| 67 | + } |
| 68 | + |
86 | 69 | }
|
0 commit comments