Skip to content

Commit 1c18ed5

Browse files
committed
Make TreePickler untpd friendly
Some refactorings so that it will become easier to generate untyped trees
1 parent df62cc3 commit 1c18ed5

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class TreePickler(pickler: TastyPickler) {
536536
pickleTree(tp)
537537
case Annotated(tree, annot) =>
538538
writeByte(ANNOTATEDtpt)
539-
withLength { pickleTree(tree); pickleTree(annot.tree) }
539+
withLength { pickleTree(tree); pickleTree(annot) }
540540
case LambdaTypeTree(tparams, body) =>
541541
writeByte(LAMBDAtpt)
542542
withLength { pickleParams(tparams); pickleTree(body) }
@@ -577,15 +577,24 @@ class TreePickler(pickler: TastyPickler) {
577577

578578
def pickleModifiers(sym: Symbol)(implicit ctx: Context): Unit = {
579579
import Flags._
580-
val flags = sym.flags
580+
var flags = sym.flags
581581
val privateWithin = sym.privateWithin
582582
if (privateWithin.exists) {
583583
writeByte(if (flags is Protected) PROTECTEDqualified else PRIVATEqualified)
584584
pickleType(privateWithin.typeRef)
585+
flags = flags &~ Protected
585586
}
587+
if ((flags is ParamAccessor) && sym.isTerm && !sym.isSetter)
588+
flags = flags &~ ParamAccessor // we only generate a tag for parameter setters
589+
pickleFlags(flags, sym.isTerm)
590+
sym.annotations.foreach(pickleAnnotation(sym, _))
591+
}
592+
593+
def pickleFlags(flags: Flags.FlagSet, isTerm: Boolean)(implicit ctx: Context): Unit = {
594+
import Flags._
586595
if (flags is Private) writeByte(PRIVATE)
587-
if (flags is Protected) if (!privateWithin.exists) writeByte(PROTECTED)
588-
if ((flags is Final) && !(sym is Module)) writeByte(FINAL)
596+
if (flags is Protected) writeByte(PROTECTED)
597+
if (flags.is(Final, butNot = Module)) writeByte(FINAL)
589598
if (flags is Case) writeByte(CASE)
590599
if (flags is Override) writeByte(OVERRIDE)
591600
if (flags is Inline) writeByte(INLINE)
@@ -598,7 +607,7 @@ class TreePickler(pickler: TastyPickler) {
598607
if (flags is Synthetic) writeByte(SYNTHETIC)
599608
if (flags is Artifact) writeByte(ARTIFACT)
600609
if (flags is Scala2x) writeByte(SCALA2X)
601-
if (sym.isTerm) {
610+
if (isTerm) {
602611
if (flags is Implicit) writeByte(IMPLICIT)
603612
if (flags is Erased) writeByte(ERASED)
604613
if (flags.is(Lazy, butNot = Module)) writeByte(LAZY)
@@ -608,7 +617,7 @@ class TreePickler(pickler: TastyPickler) {
608617
if (flags is CaseAccessor) writeByte(CASEaccessor)
609618
if (flags is DefaultParameterized) writeByte(DEFAULTparameterized)
610619
if (flags is Stable) writeByte(STABLE)
611-
if ((flags is ParamAccessor) && sym.isSetter) writeByte(PARAMsetter)
620+
if (flags is ParamAccessor) writeByte(PARAMsetter)
612621
if (flags is Label) writeByte(LABEL)
613622
} else {
614623
if (flags is Sealed) writeByte(SEALED)
@@ -617,7 +626,6 @@ class TreePickler(pickler: TastyPickler) {
617626
if (flags is Covariant) writeByte(COVARIANT)
618627
if (flags is Contravariant) writeByte(CONTRAVARIANT)
619628
}
620-
sym.annotations.foreach(pickleAnnotation(sym, _))
621629
}
622630

623631
private def isUnpicklable(owner: Symbol, ann: Annotation)(implicit ctx: Context) = ann match {

0 commit comments

Comments
 (0)