Skip to content

Commit 4e5cf82

Browse files
Merge pull request #4581 from dotty-staging/print-def-extractors
Improve string representation of Tasty extractors
2 parents a15cfad + b25311b commit 4e5cf82

7 files changed

+273
-273
lines changed

library/src/scala/tasty/util/ShowExtractors.scala

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -25,58 +25,58 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
2525

2626
def visitTree(x: Tree): Buffer = x match {
2727
case Term.Ident(name) =>
28-
this += "Ident(" += name += ")"
28+
this += "Term.Ident(\"" += name += "\")"
2929
case Term.Select(qualifier, name, signature) =>
30-
this += "Select(" += qualifier += ", " += name += ", " += signature += ")"
30+
this += "Term.Select(" += qualifier += ", \"" += name += "\", " += signature += ")"
3131
case Term.This(qual) =>
32-
this += "This(" += qual += ")"
32+
this += "Term.This(" += qual += ")"
3333
case Term.Super(qual, mix) =>
34-
this += "TypeApply(" += qual += ", " += mix += ")"
34+
this += "Term.TypeApply(" += qual += ", " += mix += ")"
3535
case Term.Apply(fun, args) =>
36-
this += "Apply(" += fun += ", " ++= args += ")"
36+
this += "Term.Apply(" += fun += ", " ++= args += ")"
3737
case Term.TypeApply(fun, args) =>
38-
this += "TypeApply(" += fun += ", " ++= args += ")"
38+
this += "Term.TypeApply(" += fun += ", " ++= args += ")"
3939
case Term.Literal(const) =>
40-
this += "Literal(" += const += ")"
40+
this += "Term.Literal(" += const += ")"
4141
case Term.New(tpt) =>
42-
this += "New(" += tpt += ")"
42+
this += "Term.New(" += tpt += ")"
4343
case Term.Typed(expr, tpt) =>
44-
this += "Typed(" += expr += ", " += tpt += ")"
44+
this += "Term.Typed(" += expr += ", " += tpt += ")"
4545
case Term.NamedArg(name, arg) =>
46-
this += "NamedArg(" += name += ", " += arg += ")"
46+
this += "Term.NamedArg(\"" += name += "\", " += arg += ")"
4747
case Term.Assign(lhs, rhs) =>
48-
this += "Assign(" += lhs += ", " += rhs += ")"
48+
this += "Term.Assign(" += lhs += ", " += rhs += ")"
4949
case Term.Block(stats, expr) =>
50-
this += "Block(" ++= stats += ", " += expr += ")"
50+
this += "Term.Block(" ++= stats += ", " += expr += ")"
5151
case Term.If(cond, thenp, elsep) =>
52-
this += "If(" += cond += ", " += thenp += ", " += elsep += ")"
52+
this += "Term.If(" += cond += ", " += thenp += ", " += elsep += ")"
5353
case Term.Lambda(meth, tpt) =>
54-
this += "Lambda(" += meth += ", " += tpt += ")"
54+
this += "Term.Lambda(" += meth += ", " += tpt += ")"
5555
case Term.Match(selector, cases) =>
56-
this += "Match(" += selector += ", " ++= cases += ")"
56+
this += "Term.Match(" += selector += ", " ++= cases += ")"
5757
case Term.Return(expr) =>
58-
this += "Return(" += expr += ")"
58+
this += "Term.Return(" += expr += ")"
5959
case Term.Try(block, handlers, finalizer) =>
60-
this += "Try(" += block += ", " ++= handlers += ", " += finalizer += ")"
60+
this += "Term.Try(" += block += ", " ++= handlers += ", " += finalizer += ")"
6161
case Term.Repeated(elems) =>
62-
this += "Repeated(" ++= elems += ")"
62+
this += "Term.Repeated(" ++= elems += ")"
6363
case Term.Inlined(call, bindings, expansion) =>
64-
this += "Inlined(" += call += ", " ++= bindings += ", " += expansion += ")"
64+
this += "Term.Inlined(" += call += ", " ++= bindings += ", " += expansion += ")"
6565
case ValDef(name, tpt, rhs) =>
66-
this += "ValDef(" += name += ", " += tpt += ", " += rhs += ")"
66+
this += "ValDef(\"" += name += "\", " += tpt += ", " += rhs += ")"
6767
case DefDef(name, typeParams, paramss, returnTpt, rhs) =>
68-
this += "DefDef(" += name += ", " ++= typeParams += ", " +++= paramss += ", " += returnTpt += ", " += rhs += ")"
68+
this += "DefDef(\"" += name += "\", " ++= typeParams += ", " +++= paramss += ", " += returnTpt += ", " += rhs += ")"
6969
case TypeDef(name, rhs) =>
70-
this += "TypeDef(" += name += ", " += rhs += ")"
70+
this += "TypeDef(\"" += name += "\", " += rhs += ")"
7171
case ClassDef(name, constr, parents, self, body) =>
72-
this += "ClassDef(" += name += ", " += constr += ", "
72+
this += "ClassDef(\"" += name += "\", " += constr += ", "
7373
visitList[Parent](parents, {
7474
case parent @ Term() => this += parent
7575
case parent @ TypeTree() => this += parent
7676
})
7777
this += ", " += self += ", " ++= body += ")"
7878
case PackageDef(name, members) =>
79-
this += "PackageDef(" += name += ", " ++= members += ")"
79+
this += "PackageDef(\"" += name += "\", " ++= members += ")"
8080
case Import(expr, selectors) =>
8181
this += "Import(" += expr += ", " ++= selectors += ")"
8282
case PackageClause(pid, stats) =>
@@ -85,25 +85,25 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
8585

8686
def visitTypeTree(x: TypeOrBoundsTree): Buffer = x match {
8787
case TypeTree.Synthetic() =>
88-
this += "Synthetic()"
88+
this += "TypeTree.Synthetic()"
8989
case TypeTree.TypeIdent(name) =>
90-
this += "TypeIdent(" += name += ")"
90+
this += "TypeTree.TypeIdent(\"" += name += "\")"
9191
case TypeTree.TypeSelect(qualifier, name) =>
92-
this += "TypeSelect(" += qualifier += ", " += name += ")"
92+
this += "TypeTree.TypeSelect(" += qualifier += ", \"" += name += "\")"
9393
case TypeTree.Singleton(ref) =>
94-
this += "Singleton(" += ref += ")"
94+
this += "TypeTree.Singleton(" += ref += ")"
9595
case TypeTree.And(left, right) =>
96-
this += "And(" += left += ", " += right += ")"
96+
this += "TypeTree.And(" += left += ", " += right += ")"
9797
case TypeTree.Or(left, right) =>
98-
this += "Or(" += left += ", " += right += ")"
98+
this += "TypeTree.Or(" += left += ", " += right += ")"
9999
case TypeTree.Refined(tpt, refinements) =>
100-
this += "Refined(" += tpt += ", " ++= refinements += ")"
100+
this += "TypeTree.Refined(" += tpt += ", " ++= refinements += ")"
101101
case TypeTree.Applied(tpt, args) =>
102-
this += "Applied(" += tpt += ", " ++= args += ")"
102+
this += "TypeTree.Applied(" += tpt += ", " ++= args += ")"
103103
case TypeTree.ByName(result) =>
104-
this += "ByName(" += result += ")"
104+
this += "TypeTree.ByName(" += result += ")"
105105
case TypeTree.Annotated(arg, annot) =>
106-
this += "Annotated(" += arg += ", " += annot += ")"
106+
this += "TypeTree.Annotated(" += arg += ", " += annot += ")"
107107
case TypeBoundsTree(lo, hi) =>
108108
this += "TypeBoundsTree(" += lo += ", " += hi += ")"
109109
}
@@ -115,90 +115,90 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
115115

116116
def visitPattern(x: Pattern): Buffer = x match {
117117
case Pattern.Value(v) =>
118-
this += "Value(" += v += ")"
118+
this += "Pattern.Value(" += v += ")"
119119
case Pattern.Bind(name, body) =>
120-
this += "Bind(" += name += ", " += body += ")"
120+
this += "Pattern.Bind(\"" += name += "\", " += body += ")"
121121
case Pattern.Unapply(fun, implicits, patterns) =>
122-
this += "Unapply(" += fun += ", " ++= implicits += ", " ++= patterns += ")"
122+
this += "Pattern.Unapply(" += fun += ", " ++= implicits += ", " ++= patterns += ")"
123123
case Pattern.Alternative(patterns) =>
124-
this += "Alternative(" ++= patterns += ")"
124+
this += "Pattern.Alternative(" ++= patterns += ")"
125125
case Pattern.TypeTest(tpt) =>
126-
this += "TypeTest(" += tpt += ")"
126+
this += "Pattern.TypeTest(" += tpt += ")"
127127
}
128128

129129
def visitConstant(x: Constant): Buffer = x match {
130-
case Constant.Unit() => this += "Unit()"
131-
case Constant.Null() => this += "Null()"
132-
case Constant.Boolean(value) => this += "Boolean(" += value += ")"
133-
case Constant.Byte(value) => this += "Byte(" += value += ")"
134-
case Constant.Short(value) => this += "Short(" += value += ")"
135-
case Constant.Char(value) => this += "Char(" += value += ")"
136-
case Constant.Int(value) => this += "Int(" += value.toString += ")"
137-
case Constant.Long(value) => this += "Long(" += value += ")"
138-
case Constant.Float(value) => this += "Float(" += value += ")"
139-
case Constant.Double(value) => this += "Double(" += value += ")"
140-
case Constant.String(value) => this += "String(" += value += ")"
130+
case Constant.Unit() => this += "Constant.Unit()"
131+
case Constant.Null() => this += "Constant.Null()"
132+
case Constant.Boolean(value) => this += "Constant.Boolean(" += value += ")"
133+
case Constant.Byte(value) => this += "Constant.Byte(" += value += ")"
134+
case Constant.Short(value) => this += "Constant.Short(" += value += ")"
135+
case Constant.Char(value) => this += "Constant.Char(" += value += ")"
136+
case Constant.Int(value) => this += "Constant.Int(" += value.toString += ")"
137+
case Constant.Long(value) => this += "Constant.Long(" += value += ")"
138+
case Constant.Float(value) => this += "Constant.Float(" += value += ")"
139+
case Constant.Double(value) => this += "Constant.Double(" += value += ")"
140+
case Constant.String(value) => this += "Constant.String(\"" += value += "\")"
141141
}
142142

143143
def visitType(x: TypeOrBounds): Buffer = x match {
144144
case Type.ConstantType(value) =>
145-
this += "ConstantType(" += value += ")"
145+
this += "Type.ConstantType(" += value += ")"
146146
case Type.SymRef(sym, qual) =>
147147
def visitName(sym: Definition): Buffer = sym match {
148-
case ValDef(name, _, _) => this += name
149-
case DefDef(name, _, _, _, _) => this += name
150-
case TypeDef(name, _) => this += name
151-
case ClassDef(name, _, _, _, _) => this += name
152-
case PackageDef(name, _) => this += name
148+
case ValDef(name, _, _) => this += "ValDef(\"" += name += "\", _, _)"
149+
case DefDef(name, _, _, _, _) => this += "DefDef(\"" += name += "\", _, _, _, _)"
150+
case TypeDef(name, _) => this += "TypeDef(\"" += name += "\", _)"
151+
case ClassDef(name, _, _, _, _) => this += "ClassDef(\"" += name += "\", _, _, _, _)"
152+
case PackageDef(name, _) => this += "PackageDef(\"" += name += "\", _)"
153153
case _ => this += "#"
154154
}
155-
this += "SymRef("
155+
this += "Type.SymRef("
156156
visitName(sym)
157157
this += ", " += qual += ")"
158158
case Type.TermRef(name, qual) =>
159-
this += "TermRef(" += name += ", " += qual += ")"
159+
this += "Type.TermRef(\"" += name += "\", " += qual += ")"
160160
case Type.TypeRef(name, qual) =>
161-
this += "TypeRef(" += name += ", " += qual += ")"
161+
this += "Type.TypeRef(\"" += name += "\", " += qual += ")"
162162
case Type.Refinement(parent, name, info) =>
163-
this += "Refinement(" += parent += ", " += name += ", " += info += ")"
163+
this += "Type.Refinement(" += parent += ", " += name += ", " += info += ")"
164164
case Type.AppliedType(tycon, args) =>
165-
this += "AppliedType(" += tycon += ", " ++= args += ")"
165+
this += "Type.AppliedType(" += tycon += ", " ++= args += ")"
166166
case Type.AnnotatedType(underlying, annot) =>
167-
this += "AnnotatedType(" += underlying += ", " += annot += ")"
167+
this += "Type.AnnotatedType(" += underlying += ", " += annot += ")"
168168
case Type.AndType(left, right) =>
169-
this += "AndType(" += left += ", " += right += ")"
169+
this += "Type.AndType(" += left += ", " += right += ")"
170170
case Type.OrType(left, right) =>
171-
this += "OrType(" += left += ", " += right += ")"
171+
this += "Type.OrType(" += left += ", " += right += ")"
172172
case Type.ByNameType(underlying) =>
173-
this += "ByNameType(" += underlying += ")"
173+
this += "Type.ByNameType(" += underlying += ")"
174174
case Type.ParamRef(binder, idx) =>
175-
this += "ParamRef(" += binder+= ", " += idx += ")"
175+
this += "Type.ParamRef(" += binder+= ", " += idx += ")"
176176
case Type.ThisType(tp) =>
177-
this += "ThisType(" += tp += ")"
177+
this += "Type.ThisType(" += tp += ")"
178178
case Type.RecursiveThis(binder) =>
179-
this += "RecursiveThis(" += binder += ")"
179+
this += "Type.RecursiveThis(" += binder += ")"
180180
case Type.MethodType(argNames, argTypes, resType) =>
181-
this += "MethodType(" ++= argNames += ", " ++= argTypes += ", " += resType += ")"
181+
this += "Type.MethodType(" ++= argNames += ", " ++= argTypes += ", " += resType += ")"
182182
case Type.PolyType(argNames, argBounds, resType) =>
183-
this += "PolyType(" ++= argNames += ", " ++= argBounds += ", " += resType += ")"
183+
this += "Type.PolyType(" ++= argNames += ", " ++= argBounds += ", " += resType += ")"
184184
case Type.TypeLambda(argNames, argBounds, resType) =>
185-
this += "TypeLambda(" ++= argNames += ", " ++= argBounds += ", " += resType += ")"
185+
this += "Type.TypeLambda(" ++= argNames += ", " ++= argBounds += ", " += resType += ")"
186186
case TypeBounds(lo, hi) =>
187187
this += "TypeBounds(" += lo += ", " += hi += ")"
188188
case NoPrefix() =>
189-
this += "NoPrefix"
189+
this += "NoPrefix()"
190190
}
191191

192192
def visitModifier(x: Modifier): Buffer = x match {
193-
case Modifier.Flags(flags) => this += "Flags(" += flags.toString += ")"
194-
case Modifier.QualifiedPrivate(tp) => this += "QualifiedPrivate(" += tp += ")"
195-
case Modifier.QualifiedProtected(tp) => this += "QualifiedProtected(" += tp += ")"
196-
case Modifier.Annotation(tree) => this += "Annotation(" += tree += ")"
193+
case Modifier.Flags(flags) => this += "Modifier.Flags(" += flags.toString += ")"
194+
case Modifier.QualifiedPrivate(tp) => this += "Modifier.QualifiedPrivate(" += tp += ")"
195+
case Modifier.QualifiedProtected(tp) => this += "Modifier.QualifiedProtected(" += tp += ")"
196+
case Modifier.Annotation(tree) => this += "Modifier.Annotation(" += tree += ")"
197197
}
198198

199199
def visitId(x: Id): Buffer = {
200200
val Id(name) = x
201-
this += "Id(" += name += ")"
201+
this += "Id(\"" += name += "\")"
202202
}
203203

204204
def visitSignature(sig: Signature): Buffer = {

0 commit comments

Comments
 (0)