@@ -4,7 +4,7 @@ package core
44package tasty
55
66import ast .Trees ._
7- import ast .{untpd , tpd }
7+ import ast .{untpd , tpd , desugar }
88import TastyFormat ._
99import Contexts ._ , Symbols ._ , Types ._ , Names ._ , Constants ._ , Decorators ._ , Annotations ._ , StdNames .tpnme , NameOps ._
1010import collection .mutable
@@ -546,6 +546,10 @@ class TreePickler(pickler: TastyPickler) {
546546 pickleTree(lo);
547547 if (hi ne lo) pickleTree(hi)
548548 }
549+ case tpd.UntypedSplice (splice) =>
550+ // println(i"UNTYPED: $splice")
551+ writeByte(UNTYPEDSPLICE )
552+ withLength { pickleUntyped(splice); pickleType(tree.tpe) }
549553 case Hole (idx, args) =>
550554 writeByte(HOLE )
551555 withLength {
@@ -643,6 +647,211 @@ class TreePickler(pickler: TastyPickler) {
643647 withLength { pickleType(ann.symbol.typeRef); pickleTree(ann.tree) }
644648 }
645649
650+ // ---- pickling untyped trees ----------------------------------
651+
652+ def pickleUntyped (tree : untpd.Tree )(implicit ctx : Context ): Unit = {
653+ try desugar(tree) match {
654+ case Ident (name) =>
655+ writeByte(if (name.isTypeName) TYPEREF else TERMREF )
656+ pickleName(name)
657+ pickleDummyType()
658+ case This (qual) =>
659+ writeByte(QUALTHIS )
660+ pickleUntyped(qual)
661+ case Select (qual, name) =>
662+ writeByte(if (name.isTypeName) SELECTtpt else SELECT )
663+ pickleName(name)
664+ pickleUntyped(qual)
665+ case Apply (fun, args) =>
666+ writeByte(APPLY )
667+ withLength {
668+ pickleUntyped(fun)
669+ args.foreach(pickleUntyped)
670+ }
671+ case untpd.Throw (exc) =>
672+ writeByte(THROW )
673+ pickleUntyped(exc)
674+ case TypeApply (fun, args) =>
675+ writeByte(TYPEAPPLY )
676+ withLength {
677+ pickleUntyped(fun)
678+ args.foreach(pickleUntyped)
679+ }
680+ case Literal (const) =>
681+ pickleConstant(const)
682+ case Super (qual, mix) =>
683+ writeByte(SUPER )
684+ withLength {
685+ pickleUntyped(qual);
686+ if (! mix.isEmpty) pickleUntyped(mix)
687+ }
688+ case New (tpt) =>
689+ writeByte(NEW )
690+ pickleUntyped(tpt)
691+ case Typed (expr, tpt) =>
692+ writeByte(TYPED )
693+ withLength { pickleUntyped(expr); pickleUntyped(tpt) }
694+ case NamedArg (name, arg) =>
695+ writeByte(NAMEDARG )
696+ pickleName(name)
697+ pickleUntyped(arg)
698+ case Assign (lhs, rhs) =>
699+ writeByte(ASSIGN )
700+ withLength { pickleUntyped(lhs); pickleUntyped(rhs) }
701+ case Block (stats, expr) =>
702+ writeByte(BLOCK )
703+ withLength { pickleUntyped(expr); stats.foreach(pickleUntyped) }
704+ case If (cond, thenp, elsep) =>
705+ writeByte(IF )
706+ withLength { pickleUntyped(cond); pickleUntyped(thenp); pickleUntyped(elsep) }
707+ case Match (selector, cases) =>
708+ writeByte(MATCH )
709+ withLength { pickleUntyped(selector); cases.foreach(pickleUntyped) }
710+ case CaseDef (pat, guard, rhs) =>
711+ writeByte(CASEDEF )
712+ withLength { pickleUntyped(pat); pickleUntyped(rhs); pickleUntypedUnlessEmpty(guard) }
713+ case Return (expr, from) =>
714+ writeByte(RETURN )
715+ withLength { pickleDummyRef(); pickleUntypedUnlessEmpty(expr) }
716+ case Try (block, cases, finalizer) =>
717+ writeByte(TRY )
718+ withLength { pickleUntyped(block); cases.foreach(pickleUntyped); pickleUntypedUnlessEmpty(finalizer) }
719+ case Bind (name, body) =>
720+ writeByte(BIND )
721+ withLength {
722+ pickleName(name); pickleDummyType(); pickleUntyped(body)
723+ }
724+ case Alternative (alts) =>
725+ writeByte(ALTERNATIVE )
726+ withLength { alts.foreach(pickleUntyped) }
727+ case tree : untpd.ValDef =>
728+ pickleUntypedDef(VALDEF , tree, tree.tpt, tree.rhs)
729+ case tree : untpd.DefDef =>
730+ pickleUntypedDef(DEFDEF , tree, tree.tpt, tree.rhs, pickleAllUntypedParams(tree))
731+ case tree : untpd.TypeDef =>
732+ pickleUntypedDef(TYPEDEF , tree, tree.rhs)
733+ case tree : untpd.ModuleDef =>
734+ pickleUntypedDef(OBJECTDEF , tree, tree.impl)
735+ case tree : untpd.Template =>
736+ writeByte(TEMPLATE )
737+ tree.parents.foreach(pickleUntyped)
738+ if (! tree.self.isEmpty) {
739+ writeByte(SELFDEF ); pickleName(tree.self.name); pickleUntyped(tree.self.tpt)
740+ }
741+ pickleUntyped(tree.constr)
742+ tree.body.foreach(pickleUntyped)
743+ case Import (expr, selectors) =>
744+ writeByte(IMPORT )
745+ withLength { pickleUntyped(expr); pickleSelectors(selectors) }
746+ case tree : untpd.TypeTree =>
747+ pickleDummyType()
748+ case SingletonTypeTree (ref) =>
749+ writeByte(SINGLETONtpt )
750+ pickleUntyped(ref)
751+ case RefinedTypeTree (parent, refinements) =>
752+ writeByte(REFINEDtpt )
753+ withLength { pickleUntyped(parent); refinements.foreach(pickleUntyped) }
754+ case AppliedTypeTree (tycon, args) =>
755+ writeByte(APPLIEDtpt )
756+ withLength { pickleUntyped(tycon); args.foreach(pickleUntyped) }
757+ case AndTypeTree (tp1, tp2) =>
758+ writeByte(ANDtpt )
759+ withLength { pickleUntyped(tp1); pickleUntyped(tp2) }
760+ case OrTypeTree (tp1, tp2) =>
761+ writeByte(ORtpt )
762+ withLength { pickleUntyped(tp1); pickleUntyped(tp2) }
763+ case ByNameTypeTree (tp) =>
764+ writeByte(BYNAMEtpt )
765+ pickleUntyped(tp)
766+ case Annotated (tree, annot) =>
767+ writeByte(ANNOTATEDtpt )
768+ withLength { pickleUntyped(tree); pickleUntyped(annot) }
769+ case LambdaTypeTree (tparams, body) =>
770+ writeByte(LAMBDAtpt )
771+ withLength { pickleUntypedParams(tparams); pickleUntyped(body) }
772+ case TypeBoundsTree (lo, hi) =>
773+ writeByte(TYPEBOUNDStpt )
774+ withLength {
775+ pickleUntyped(lo);
776+ if (hi ne lo) pickleUntyped(hi)
777+ }
778+ case untpd.Function (args, body) =>
779+ writeByte(FUNCTION )
780+ withLength { pickleUntyped(body); args.foreach(pickleUntyped) }
781+ case untpd.InfixOp (l, op, r) =>
782+ writeByte(INFIXOP )
783+ withLength { pickleUntyped(l); pickleUntyped(op); pickleUntyped(r) }
784+ case Thicket (trees) =>
785+ trees.foreach(pickleUntyped)
786+ case untpd.TypedSplice (splice) =>
787+ writeByte(TYPEDSPLICE )
788+ withLength { pickleTree(splice) }
789+ }
790+ catch {
791+ case ex : AssertionError =>
792+ println(i " error when pickling tree $tree" )
793+ throw ex
794+ }
795+ }
796+
797+ def pickleUntypedUnlessEmpty (tree : untpd.Tree )(implicit ctx : Context ): Unit =
798+ if (! tree.isEmpty) pickleUntyped(tree)
799+
800+ def pickleAllUntypedParams (tree : untpd.DefDef )(implicit ctx : Context ): Unit = {
801+ pickleUntypedParams(tree.tparams)
802+ for (vparams <- tree.vparamss) {
803+ writeByte(PARAMS )
804+ withLength { pickleUntypedParams(vparams) }
805+ }
806+ }
807+
808+ def pickleUntypedParams (trees : List [untpd.Tree ])(implicit ctx : Context ): Unit =
809+ trees.foreach(pickleUntypedParam)
810+
811+ def pickleUntypedDef (tag : Int , tree : untpd.MemberDef , tpt : untpd.Tree , rhs : untpd.Tree = untpd.EmptyTree , pickleParams : => Unit = ())(implicit ctx : Context ) = {
812+ import untpd .modsDeco
813+ writeByte(tag)
814+ withLength {
815+ pickleName(tree.name)
816+ pickleParams
817+ pickleUntyped(tpt)
818+ pickleUntypedUnlessEmpty(rhs)
819+ pickleUntypedModifiers(tree.mods)
820+ }
821+ }
822+
823+ def pickleUntypedParam (tree : untpd.Tree )(implicit ctx : Context ): Unit = tree match {
824+ case tree : untpd.ValDef => pickleUntypedDef(PARAM , tree, tree.tpt)
825+ case tree : untpd.DefDef => pickleUntypedDef(PARAM , tree, tree.tpt, tree.rhs)
826+ case tree : untpd.TypeDef => pickleUntypedDef(TYPEPARAM , tree, tree.rhs)
827+ }
828+
829+ def pickleUntypedModifiers (mods : untpd.Modifiers )(implicit ctx : Context ): Unit = {
830+ import Flags ._
831+ var flags = mods.flags
832+ val privateWithin = mods.privateWithin
833+ if (! privateWithin.isEmpty) {
834+ writeByte(if (flags is Protected ) PROTECTEDqualified else PRIVATEqualified )
835+ pickleUntyped(untpd.Ident (privateWithin))
836+ flags = flags &~ Protected
837+ }
838+ mods.annotations.foreach(pickleUntypedAnnotation)
839+ }
840+
841+ def pickleUntypedAnnotation (annotTree : untpd.Tree )(implicit ctx : Context ) = {
842+ writeByte(ANNOTATION )
843+ withLength { pickleDummyType(); pickleUntyped(annotTree) }
844+ }
845+
846+ def pickleDummyRef (): Unit = writeNat(0 )
847+
848+ def pickleDummyType (): Unit = {
849+ writeByte(SHAREDtype )
850+ pickleDummyRef()
851+ }
852+
853+ // ---- main entry points ---------------------------------------
854+
646855 def pickle (trees : List [Tree ])(implicit ctx : Context ) = {
647856 trees.foreach(tree => if (! tree.isEmpty) pickleTree(tree))
648857 def missing = forwardSymRefs.keysIterator.map(_.showLocated).toList
0 commit comments