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