@@ -664,244 +664,6 @@ class TreePickler(pickler: TastyPickler) {
664664 withLength { pickleType(ann.symbol.typeRef); pickleTree(ann.tree) }
665665 }
666666
667- // ---- pickling untyped trees ----------------------------------
668-
669- def pickleUntyped (tree : untpd.Tree )(implicit ctx : Context ): Unit = {
670-
671- def pickleDummyRef (): Unit = writeNat(0 )
672-
673- def pickleDummyType (): Unit = writeByte(EMPTYTYPETREE )
674-
675- def pickleUnlessEmpty (tree : untpd.Tree ): Unit =
676- if (! tree.isEmpty) pickleUntyped(tree)
677-
678- def pickleTpt (tree : untpd.Tree ) = pickleUntyped(tree)(ctx.addMode(Mode .Type ))
679- def pickleTerm (tree : untpd.Tree ) = pickleUntyped(tree)(ctx.retractMode(Mode .Type ))
680-
681- def pickleAllParams (tree : untpd.DefDef ): Unit = {
682- pickleParams(tree.tparams)
683- for (vparams <- tree.vparamss) {
684- writeByte(PARAMS )
685- withLength { pickleParams(vparams) }
686- }
687- }
688-
689- def pickleParams (trees : List [untpd.Tree ]): Unit =
690- trees.foreach(pickleParam)
691-
692- def pickleParam (tree : untpd.Tree ): Unit = tree match {
693- case tree : untpd.ValDef => pickleDef(PARAM , tree, tree.tpt)
694- case tree : untpd.DefDef => pickleDef(PARAM , tree, tree.tpt, tree.rhs)
695- case tree : untpd.TypeDef => pickleDef(TYPEPARAM , tree, tree.rhs)
696- }
697-
698- def pickleParent (tree : untpd.Tree ): Unit = tree match {
699- case _ : untpd.Apply | _ : untpd.TypeApply => pickleUntyped(tree)
700- case _ => pickleTpt(tree)
701- }
702-
703- def pickleDef (tag : Int , tree : untpd.MemberDef , tpt : untpd.Tree , rhs : untpd.Tree = untpd.EmptyTree , pickleParams : => Unit = ()) = {
704- import untpd .modsDeco
705- writeByte(tag)
706- withLength {
707- pickleName(tree.name)
708- pickleParams
709- pickleTpt(tpt)
710- pickleUnlessEmpty(rhs)
711- pickleModifiers(tree.mods, tree.name.isTermName)
712- }
713- }
714-
715- def pickleModifiers (mods : untpd.Modifiers , isTerm : Boolean ): Unit = {
716- import Flags ._
717- var flags = mods.flags
718- val privateWithin = mods.privateWithin
719- if (! privateWithin.isEmpty) {
720- writeByte(if (flags is Protected ) PROTECTEDqualified else PRIVATEqualified )
721- pickleUntyped(untpd.Ident (privateWithin))
722- flags = flags &~ Protected
723- }
724- pickleFlags(flags, isTerm)
725- mods.annotations.foreach(pickleAnnotation)
726- }
727-
728- def pickleAnnotation (annotTree : untpd.Tree ) = {
729- writeByte(ANNOTATION )
730- withLength { pickleDummyType(); pickleUntyped(annotTree) }
731- }
732-
733- try tree match {
734- case Ident (name) =>
735- writeByte(if (name.isTypeName) TYPEREF else TERMREF )
736- pickleName(name)
737- pickleDummyType()
738- case This (qual) =>
739- writeByte(QUALTHIS )
740- pickleUntyped(qual)
741- case Select (qual, name) =>
742- writeByte(if (name.isTypeName) SELECTtpt else SELECT )
743- pickleName(name)
744- if (qual.isType) pickleTpt(qual) else pickleTerm(qual)
745- case Apply (fun, args) =>
746- writeByte(APPLY )
747- withLength {
748- pickleUntyped(fun)
749- args.foreach(pickleUntyped)
750- }
751- case untpd.Throw (exc) =>
752- writeByte(THROW )
753- pickleUntyped(exc)
754- case TypeApply (fun, args) =>
755- writeByte(TYPEAPPLY )
756- withLength {
757- pickleUntyped(fun)
758- args.foreach(pickleTpt)
759- }
760- case Literal (const) =>
761- pickleConstant(const)
762- case Super (qual, mix) =>
763- writeByte(SUPER )
764- withLength {
765- pickleUntyped(qual);
766- if (! mix.isEmpty) pickleUntyped(mix)
767- }
768- case New (tpt) =>
769- writeByte(NEW )
770- pickleTpt(tpt)
771- case Typed (expr, tpt) =>
772- writeByte(TYPED )
773- withLength { pickleUntyped(expr); pickleTpt(tpt) }
774- case NamedArg (name, arg) =>
775- writeByte(NAMEDARG )
776- pickleName(name)
777- pickleUntyped(arg)
778- case Assign (lhs, rhs) =>
779- writeByte(ASSIGN )
780- withLength { pickleUntyped(lhs); pickleUntyped(rhs) }
781- case Block (stats, expr) =>
782- writeByte(BLOCK )
783- withLength { pickleUntyped(expr); stats.foreach(pickleUntyped) }
784- case If (cond, thenp, elsep) =>
785- writeByte(IF )
786- withLength { pickleUntyped(cond); pickleUntyped(thenp); pickleUntyped(elsep) }
787- case Match (selector, cases) =>
788- writeByte(MATCH )
789- withLength { pickleUntyped(selector); cases.foreach(pickleUntyped) }
790- case CaseDef (pat, guard, rhs) =>
791- writeByte(CASEDEF )
792- withLength { pickleUntyped(pat); pickleUntyped(rhs); pickleUnlessEmpty(guard) }
793- case Return (expr, from) =>
794- writeByte(RETURN )
795- withLength { pickleDummyRef(); pickleUnlessEmpty(expr) }
796- case WhileDo (cond, body) =>
797- writeByte(WHILE )
798- withLength { pickleUntyped(cond); pickleUntyped(body) }
799- case Try (block, cases, finalizer) =>
800- writeByte(TRY )
801- withLength { pickleUntyped(block); cases.foreach(pickleUntyped); pickleUnlessEmpty(finalizer) }
802- case Bind (name, body) =>
803- writeByte(BIND )
804- withLength {
805- pickleName(name); pickleDummyType(); pickleUntyped(body)
806- }
807- case Alternative (alts) =>
808- writeByte(ALTERNATIVE )
809- withLength { alts.foreach(pickleUntyped) }
810- case tree : untpd.ValDef =>
811- pickleDef(VALDEF , tree, tree.tpt, tree.rhs)
812- case tree : untpd.DefDef =>
813- pickleDef(DEFDEF , tree, tree.tpt, tree.rhs, pickleAllParams(tree))
814- case tree : untpd.TypeDef =>
815- pickleDef(TYPEDEF , tree, tree.rhs)
816- case tree : untpd.ModuleDef =>
817- pickleDef(OBJECTDEF , tree, tree.impl)
818- case tree : untpd.Template =>
819- writeByte(TEMPLATE )
820- withLength {
821- tree.parents.foreach(pickleParent)
822- if (! tree.self.isEmpty) {
823- writeByte(SELFDEF ); pickleName(tree.self.name); pickleTpt(tree.self.tpt)
824- }
825- pickleUntyped(tree.constr)
826- tree.body.foreach(pickleUntyped)
827- }
828- case Import (expr, selectors) =>
829- writeByte(IMPORT )
830- withLength { pickleUntyped(expr); pickleSelectors(selectors) }
831- case tree : untpd.TypeTree =>
832- pickleDummyType()
833- case SingletonTypeTree (ref) =>
834- writeByte(SINGLETONtpt )
835- pickleTerm(ref)
836- case RefinedTypeTree (parent, refinements) =>
837- writeByte(REFINEDtpt )
838- withLength { pickleTpt(parent); refinements.foreach(pickleTerm) }
839- case AppliedTypeTree (tycon, args) =>
840- writeByte(APPLIEDtpt )
841- withLength { pickleTpt(tycon); args.foreach(pickleTpt) }
842- case AndTypeTree (tp1, tp2) =>
843- writeByte(ANDtpt )
844- withLength { pickleTpt(tp1); pickleTpt(tp2) }
845- case OrTypeTree (tp1, tp2) =>
846- writeByte(ORtpt )
847- withLength { pickleTpt(tp1); pickleTpt(tp2) }
848- case ByNameTypeTree (tp) =>
849- writeByte(BYNAMEtpt )
850- pickleTpt(tp)
851- case Annotated (tree, annot) =>
852- writeByte(ANNOTATEDtpt )
853- withLength { pickleTpt(tree); pickleTerm(annot) }
854- case MatchTypeTree (bound, selector, cases) =>
855- writeByte(MATCHtpt )
856- withLength {
857- if (! bound.isEmpty) pickleTpt(bound)
858- pickleTpt(selector)
859- cases.foreach(pickleUntyped)
860- }
861- case LambdaTypeTree (tparams, body) =>
862- writeByte(LAMBDAtpt )
863- withLength { pickleParams(tparams); pickleTpt(body) }
864- case TypeBoundsTree (lo, hi) =>
865- writeByte(TYPEBOUNDStpt )
866- withLength {
867- pickleTpt(lo);
868- if (hi ne lo) pickleTpt(hi)
869- }
870- case untpd.Function (args, body) =>
871- writeByte(FUNCTION )
872- withLength { pickleUntyped(body); args.foreach(pickleUntyped) }
873- case untpd.InfixOp (l, op, r) =>
874- writeByte(INFIXOP )
875- withLength { pickleUntyped(l); pickleUntyped(op); pickleUntyped(r) }
876- case untpd.Tuple (elems) =>
877- writeByte(TUPLE )
878- withLength { elems.foreach(pickleUntyped) }
879- case untpd.PatDef (mods, pats, tpt, rhs) =>
880- writeByte(PATDEF )
881- withLength {
882- pickleTpt(tpt)
883- pickleUntyped(rhs)
884- pats.foreach(pickleUntyped)
885- pickleModifiers(mods, isTerm = true )
886- }
887- case untpd.TypedSplice (splice) =>
888- writeByte(TYPEDSPLICE )
889- withLength { pickleTree(splice) }
890- case Thicket (trees) =>
891- if (trees.isEmpty) writeByte(EMPTYTREE )
892- else trees.foreach(pickleUntyped)
893- case _ =>
894- val tree1 = desugar(tree)
895- assert(tree1 `ne` tree, s " Cannot pickle untyped tree $tree" )
896- pickleUntyped(tree1)
897- }
898- catch {
899- case ex : AssertionError =>
900- println(i " error when pickling tree $tree" )
901- throw ex
902- }
903- }
904-
905667// ---- main entry points ---------------------------------------
906668
907669 def pickle (trees : List [Tree ])(implicit ctx : Context ) = {
0 commit comments