From 11fbe8b66618b153653678cf4c0b752e792bfaa1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 20 Feb 2013 09:16:06 +0100 Subject: Moved TypeTrees defs into nested object tpd. Reason: We need normal trees to do efficient pattern matching. So if we want to both pattern match and create trees we need to import Trees._ and TypedTrees.tpd. Then typed tree construction needs to be prefixed with tpd, e.g. tpd.Select(pre, name). --- src/dotty/tools/dotc/core/Annotations.scala | 2 +- .../tools/dotc/core/PluggableTransformers.scala | 11 +- src/dotty/tools/dotc/core/TypedTrees.scala | 492 +++++++++++---------- .../tools/dotc/core/pickling/ClassfileParser.scala | 2 +- src/dotty/tools/dotc/core/pickling/UnPickler.scala | 2 +- 5 files changed, 257 insertions(+), 252 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/core/Annotations.scala b/src/dotty/tools/dotc/core/Annotations.scala index c91d0c409..2ced6cb8a 100644 --- a/src/dotty/tools/dotc/core/Annotations.scala +++ b/src/dotty/tools/dotc/core/Annotations.scala @@ -1,6 +1,6 @@ package dotty.tools.dotc.core -import Symbols._, Types._, Positions._, Contexts._, Constants._, TypedTrees._ +import Symbols._, Types._, Positions._, Contexts._, Constants._, TypedTrees.tpd._ object Annotations { diff --git a/src/dotty/tools/dotc/core/PluggableTransformers.scala b/src/dotty/tools/dotc/core/PluggableTransformers.scala index b0b2ca134..3e3ee7df1 100644 --- a/src/dotty/tools/dotc/core/PluggableTransformers.scala +++ b/src/dotty/tools/dotc/core/PluggableTransformers.scala @@ -84,19 +84,22 @@ object PluggableTransformers { } } -import PluggableTransformers._, Types._, TypedTrees._ +import PluggableTransformers._, Types._, Trees._, Contexts._, TypedTrees.tpd class ExampleTransformer extends PluggableTransformer[Type] { - class ExamplePlugin extends Plugin { + object ExamplePlugin extends Plugin { override def processIdent = { case tree @ Ident(x) if x.isTypeName => tree.derivedSelect(tree, x) - case tree => tree + case tree => tpd.Ident(???) } override def processSelect = { tree => if (tree.isType) tree.derivedIdent(tree.name) - else EmptyTree + else tpd.EmptyTree } } + override def transform(tree: tpd.Tree, ctx: Context) = + super.transform(tree, ctx) + } \ No newline at end of file diff --git a/src/dotty/tools/dotc/core/TypedTrees.scala b/src/dotty/tools/dotc/core/TypedTrees.scala index c8e468107..eabd2911b 100644 --- a/src/dotty/tools/dotc/core/TypedTrees.scala +++ b/src/dotty/tools/dotc/core/TypedTrees.scala @@ -6,288 +6,290 @@ import SymDenotations._, Symbols._, StdNames._, Annotations._ object TypedTrees { - type Modifiers = Trees.Modifiers[Type] - type Tree = Trees.Tree[Type] - type TypTree = Trees.TypTree[Type] - type TermTree = Trees.TermTree[Type] - type SymTree = Trees.SymTree[Type] - type ProxyTree = Trees.ProxyTree[Type] - type NameTree = Trees.NameTree[Type] - type RefTree = Trees.RefTree[Type] - type DefTree = Trees.DefTree[Type] - - type TreeCopier = Trees.TreeCopier[Type] - type TreeAccumulator[T] = Trees.TreeAccumulator[T, Type] - type TreeTransformer[C] = Trees.TreeTransformer[Type, C] - - type Ident = Trees.Ident[Type] - type Select = Trees.Select[Type] - type This = Trees.This[Type] - type Super = Trees.Super[Type] - type Apply = Trees.Apply[Type] - type TypeApply = Trees.TypeApply[Type] - type Literal = Trees.Literal[Type] - type New = Trees.New[Type] - type Pair = Trees.Pair[Type] - type Typed = Trees.Typed[Type] - type NamedArg = Trees.NamedArg[Type] - type Assign = Trees.Assign[Type] - type Function = Trees.Function[Type] - type Block = Trees.Block[Type] - type If = Trees.If[Type] - type Match = Trees.Match[Type] - type CaseDef = Trees.CaseDef[Type] - type Return = Trees.Return[Type] - type Try = Trees.Try[Type] - type Throw = Trees.Throw[Type] - type ArrayValue = Trees.ArrayValue[Type] - type TypeTree = Trees.TypeTree[Type] - type SingletonTypeTree = Trees.SingletonTypeTree[Type] - type SelectFromTypeTree = Trees.SelectFromTypeTree[Type] - type AndTypeTree = Trees.AndTypeTree[Type] - type OrTypeTree = Trees.OrTypeTree[Type] - type RefineTypeTree = Trees.RefineTypeTree[Type] - type AppliedTypeTree = Trees.AppliedTypeTree[Type] - type TypeBoundsTree = Trees.TypeBoundsTree[Type] - type Bind = Trees.Bind[Type] - type Alternative = Trees.Alternative[Type] - type UnApply = Trees.UnApply[Type] - type ValDef = Trees.ValDef[Type] - type DefDef = Trees.DefDef[Type] - type TypeDef = Trees.TypeDef[Type] - type Template = Trees.Template[Type] - type ClassDef = Trees.ClassDef[Type] - type Import = Trees.Import[Type] - type PackageDef = Trees.PackageDef[Type] - type Annotated = Trees.Annotated[Type] - type EmptyTree = Trees.EmptyTree[Type] - type Shared = Trees.Shared[Type] - - private implicit def pos(implicit ctx: Context): Position = ctx.position - - def defPos(sym: Symbol)(implicit ctx: Context) = ctx.position union sym.coord.toPosition - - def Modifiers(sym: Symbol)(implicit ctx: Context): Modifiers = Trees.Modifiers[Type]( - sym.flags & ModifierFlags, - if (sym.privateWithin.exists) sym.privateWithin.asType.name else tpnme.EMPTY, - sym.annotations map (_.tree)) - - val Ident = Trees.Ident - def Ident(tp: NamedType)(implicit ctx: Context): Ident = - Trees.Ident(tp.name).withType(tp) - - def Select(pre: Tree, tp: NamedType)(implicit ctx: Context): Select = - Trees.Select(pre, tp.name).withType(tp) - - def This(cls: ClassSymbol)(implicit ctx: Context): This = - Trees.This(cls.name).withType(cls.thisType) - - def Super(qual: Tree, mixin: Symbol = NoSymbol)(implicit ctx: Context): Super = { - val cls = qual.tpe.typeSymbol - val (owntype, mix) = - if (mixin.exists) (mixin.typeConstructor, mixin.asType.name) - else (ctx.glb(cls.info.parents), tpnme.EMPTY) - Trees.Super(qual, mix).withType(SuperType(qual.tpe, owntype)) - } - - def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = { - val fntpe @ MethodType(pnames, ptypes) = fn.tpe - assert(sameLength(ptypes, args)) - Trees.Apply(fn, args).withType(fntpe.instantiate(args map (_.tpe))) - } - - def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = { - val fntpe @ PolyType(pnames) = fn.tpe - assert(sameLength(pnames, args)) - Trees.TypeApply(fn, args).withType(fntpe.instantiate(args map (_.tpe))) - } - - def Literal(const: Constant)(implicit ctx: Context): Literal = - Trees.Literal(const).withType(const.tpe) - - def New(tp: Type)(implicit ctx: Context): New = - Trees.New(TypeTree(tp)) - - def Pair(left: Tree, right: Tree)(implicit ctx: Context): Pair = - Trees.Pair(left, right).withType(defn.PairType.appliedTo(left.tpe, right.tpe)) - - def Typed(expr: Tree, tpt: Tree)(implicit ctx: Context): Typed = - Trees.Typed(expr, tpt).withType(tpt.tpe) - - def NamedArg(name: Name, arg: Tree)(implicit ctx: Context) = - Trees.NamedArg(name, arg).withType(arg.tpe) - - def Assign(lhs: Tree, rhs: Tree)(implicit ctx: Context): Assign = - Trees.Assign(lhs, rhs).withType(defn.UnitType) + object tpd { + + type Modifiers = Trees.Modifiers[Type] + type Tree = Trees.Tree[Type] + type TypTree = Trees.TypTree[Type] + type TermTree = Trees.TermTree[Type] + type SymTree = Trees.SymTree[Type] + type ProxyTree = Trees.ProxyTree[Type] + type NameTree = Trees.NameTree[Type] + type RefTree = Trees.RefTree[Type] + type DefTree = Trees.DefTree[Type] + + type TreeCopier = Trees.TreeCopier[Type] + type TreeAccumulator[T] = Trees.TreeAccumulator[T, Type] + type TreeTransformer[C] = Trees.TreeTransformer[Type, C] + + type Ident = Trees.Ident[Type] + type Select = Trees.Select[Type] + type This = Trees.This[Type] + type Super = Trees.Super[Type] + type Apply = Trees.Apply[Type] + type TypeApply = Trees.TypeApply[Type] + type Literal = Trees.Literal[Type] + type New = Trees.New[Type] + type Pair = Trees.Pair[Type] + type Typed = Trees.Typed[Type] + type NamedArg = Trees.NamedArg[Type] + type Assign = Trees.Assign[Type] + type Function = Trees.Function[Type] + type Block = Trees.Block[Type] + type If = Trees.If[Type] + type Match = Trees.Match[Type] + type CaseDef = Trees.CaseDef[Type] + type Return = Trees.Return[Type] + type Try = Trees.Try[Type] + type Throw = Trees.Throw[Type] + type ArrayValue = Trees.ArrayValue[Type] + type TypeTree = Trees.TypeTree[Type] + type SingletonTypeTree = Trees.SingletonTypeTree[Type] + type SelectFromTypeTree = Trees.SelectFromTypeTree[Type] + type AndTypeTree = Trees.AndTypeTree[Type] + type OrTypeTree = Trees.OrTypeTree[Type] + type RefineTypeTree = Trees.RefineTypeTree[Type] + type AppliedTypeTree = Trees.AppliedTypeTree[Type] + type TypeBoundsTree = Trees.TypeBoundsTree[Type] + type Bind = Trees.Bind[Type] + type Alternative = Trees.Alternative[Type] + type UnApply = Trees.UnApply[Type] + type ValDef = Trees.ValDef[Type] + type DefDef = Trees.DefDef[Type] + type TypeDef = Trees.TypeDef[Type] + type Template = Trees.Template[Type] + type ClassDef = Trees.ClassDef[Type] + type Import = Trees.Import[Type] + type PackageDef = Trees.PackageDef[Type] + type Annotated = Trees.Annotated[Type] + type EmptyTree = Trees.EmptyTree[Type] + type Shared = Trees.Shared[Type] + + private implicit def pos(implicit ctx: Context): Position = ctx.position + + def defPos(sym: Symbol)(implicit ctx: Context) = ctx.position union sym.coord.toPosition + + def Modifiers(sym: Symbol)(implicit ctx: Context): Modifiers = Trees.Modifiers[Type]( + sym.flags & ModifierFlags, + if (sym.privateWithin.exists) sym.privateWithin.asType.name else tpnme.EMPTY, + sym.annotations map (_.tree)) + + def Ident(tp: NamedType)(implicit ctx: Context): Ident = + Trees.Ident(tp.name).withType(tp) + + def Select(pre: Tree, tp: NamedType)(implicit ctx: Context): Select = + Trees.Select(pre, tp.name).withType(tp) + + def This(cls: ClassSymbol)(implicit ctx: Context): This = + Trees.This(cls.name).withType(cls.thisType) + + def Super(qual: Tree, mixin: Symbol = NoSymbol)(implicit ctx: Context): Super = { + val cls = qual.tpe.typeSymbol + val (owntype, mix) = + if (mixin.exists) (mixin.typeConstructor, mixin.asType.name) + else (ctx.glb(cls.info.parents), tpnme.EMPTY) + Trees.Super(qual, mix).withType(SuperType(qual.tpe, owntype)) + } - def Function(vparams: List[ValDef], body: Tree)(implicit ctx: Context): Function = - Trees.Function(vparams, body) - .withType(defn.FunctionType(vparams map (_.tpt.tpe), body.tpe)) + def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = { + val fntpe @ MethodType(pnames, ptypes) = fn.tpe + assert(sameLength(ptypes, args)) + Trees.Apply(fn, args).withType(fntpe.instantiate(args map (_.tpe))) + } - def Block(stats: List[Tree], expr: Tree)(implicit ctx: Context): Block = - Trees.Block(stats, expr).withType(expr.tpe) // !!! need to make sure that type does not refer to locals + def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = { + val fntpe @ PolyType(pnames) = fn.tpe + assert(sameLength(pnames, args)) + Trees.TypeApply(fn, args).withType(fntpe.instantiate(args map (_.tpe))) + } - def If(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = - Trees.If(cond, thenp, elsep).withType(thenp.tpe | elsep.tpe) + def Literal(const: Constant)(implicit ctx: Context): Literal = + Trees.Literal(const).withType(const.tpe) - def Match(selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match = - Trees.Match(selector, cases).withType(ctx.lub(cases map (_.body.tpe))) + def New(tp: Type)(implicit ctx: Context): New = + Trees.New(TypeTree(tp)) - def CaseDef(pat: Tree, guard: Tree, body: Tree)(implicit ctx: Context): CaseDef = - Trees.CaseDef(pat, guard, body).withType(body.tpe) + def Pair(left: Tree, right: Tree)(implicit ctx: Context): Pair = + Trees.Pair(left, right).withType(defn.PairType.appliedTo(left.tpe, right.tpe)) - def Return(expr: Tree, from: Ident)(implicit ctx: Context): Return = - Trees.Return(expr, from).withType(defn.NothingType) + def Typed(expr: Tree, tpt: Tree)(implicit ctx: Context): Typed = + Trees.Typed(expr, tpt).withType(tpt.tpe) - def Throw(expr: Tree)(implicit ctx: Context): Throw = - Trees.Throw(expr).withType(defn.NothingType) + def NamedArg(name: Name, arg: Tree)(implicit ctx: Context) = + Trees.NamedArg(name, arg).withType(arg.tpe) - def ArrayValue(elemtpt: Tree, elems: List[Tree])(implicit ctx: Context): ArrayValue = - Trees.ArrayValue(elemtpt, elems).withType(defn.ArrayType.appliedTo(elemtpt.tpe)) + def Assign(lhs: Tree, rhs: Tree)(implicit ctx: Context): Assign = + Trees.Assign(lhs, rhs).withType(defn.UnitType) - def TypeTree(tp: Type, original: Tree = EmptyTree)(implicit ctx: Context): TypeTree = - Trees.TypeTree(original).withType(tp) + def Function(vparams: List[ValDef], body: Tree)(implicit ctx: Context): Function = + Trees.Function(vparams, body) + .withType(defn.FunctionType(vparams map (_.tpt.tpe), body.tpe)) - def SingletonTypeTree(ref: Tree)(implicit ctx: Context): SingletonTypeTree = - Trees.SingletonTypeTree(ref).withType(ref.tpe) + def Block(stats: List[Tree], expr: Tree)(implicit ctx: Context): Block = + Trees.Block(stats, expr).withType(expr.tpe) // !!! need to make sure that type does not refer to locals - def SelectFromTypeTree(qualifier: Tree, name: TypeName)(implicit ctx: Context): SelectFromTypeTree = - Trees.SelectFromTypeTree(qualifier, name).withType(TypeRef(qualifier.tpe, name)) + def If(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = + Trees.If(cond, thenp, elsep).withType(thenp.tpe | elsep.tpe) - def AndTypeTree(left: Tree, right: Tree)(implicit ctx: Context): AndTypeTree = - Trees.AndTypeTree(left, right).withType(left.tpe & right.tpe) + def Match(selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match = + Trees.Match(selector, cases).withType(ctx.lub(cases map (_.body.tpe))) - def OrTypeTree(left: Tree, right: Tree)(implicit ctx: Context): OrTypeTree = - Trees.OrTypeTree(left, right).withType(left.tpe | right.tpe) + def CaseDef(pat: Tree, guard: Tree, body: Tree)(implicit ctx: Context): CaseDef = + Trees.CaseDef(pat, guard, body).withType(body.tpe) - def RefineTypeTree(tpt: Tree, refinements: List[DefTree])(implicit ctx: Context): RefineTypeTree = { - def refineType(tp: Type, refinement: Symbol): Type = - RefinedType(tp, refinement.name, refinement.info) - Trees.RefineTypeTree(tpt, refinements) - .withType((tpt.tpe /: (refinements map (_.symbol)))(refineType)) - } + def Return(expr: Tree, from: Ident)(implicit ctx: Context): Return = + Trees.Return(expr, from).withType(defn.NothingType) - def refineType(tp: Type, refinement: Symbol)(implicit ctx: Context): Type = - RefinedType(tp, refinement.name, refinement.info) + def Throw(expr: Tree)(implicit ctx: Context): Throw = + Trees.Throw(expr).withType(defn.NothingType) - def AppliedTypeTree(tpt: Tree, args: List[Tree])(implicit ctx: Context): AppliedTypeTree = - Trees.AppliedTypeTree(tpt, args).withType(tpt.tpe.appliedTo(args map (_.tpe))) + def ArrayValue(elemtpt: Tree, elems: List[Tree])(implicit ctx: Context): ArrayValue = + Trees.ArrayValue(elemtpt, elems).withType(defn.ArrayType.appliedTo(elemtpt.tpe)) - def TypeBoundsTree(lo: Tree, hi: Tree)(implicit ctx: Context): TypeBoundsTree = - Trees.TypeBoundsTree(lo, hi).withType(TypeBounds(lo.tpe, hi.tpe)) + def TypeTree(tp: Type, original: Tree = EmptyTree)(implicit ctx: Context): TypeTree = + Trees.TypeTree(original).withType(tp) - def Bind(sym: Symbol, body: Tree)(implicit ctx: Context): Bind = - Trees.Bind(sym.name, body)(defPos(sym)).withType(sym.info) + def SingletonTypeTree(ref: Tree)(implicit ctx: Context): SingletonTypeTree = + Trees.SingletonTypeTree(ref).withType(ref.tpe) - def Alternative(trees: List[Tree])(implicit ctx: Context): Alternative = - Trees.Alternative(trees).withType(ctx.lub(trees map (_.tpe))) + def SelectFromTypeTree(qualifier: Tree, name: TypeName)(implicit ctx: Context): SelectFromTypeTree = + Trees.SelectFromTypeTree(qualifier, name).withType(TypeRef(qualifier.tpe, name)) - def UnApply(fun: Tree, args: List[Tree])(implicit ctx: Context): UnApply = - Trees.UnApply(fun, args).withType(fun.tpe match { - case MethodType(_, paramTypes) => paramTypes.head - }) + def AndTypeTree(left: Tree, right: Tree)(implicit ctx: Context): AndTypeTree = + Trees.AndTypeTree(left, right).withType(left.tpe & right.tpe) - def refType(sym: Symbol)(implicit ctx: Context) = NamedType(sym.owner.thisType, sym) + def OrTypeTree(left: Tree, right: Tree)(implicit ctx: Context): OrTypeTree = + Trees.OrTypeTree(left, right).withType(left.tpe | right.tpe) - def ValDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): ValDef = - Trees.ValDef(Modifiers(sym), sym.name, TypeTree(sym.info), rhs)(defPos(sym)) - .withType(refType(sym)) + def RefineTypeTree(tpt: Tree, refinements: List[DefTree])(implicit ctx: Context): RefineTypeTree = { + def refineType(tp: Type, refinement: Symbol): Type = + RefinedType(tp, refinement.name, refinement.info) + Trees.RefineTypeTree(tpt, refinements) + .withType((tpt.tpe /: (refinements map (_.symbol)))(refineType)) + } - def DefDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): DefDef = { + def refineType(tp: Type, refinement: Symbol)(implicit ctx: Context): Type = + RefinedType(tp, refinement.name, refinement.info) - val (tparams, mtp) = sym.info match { - case tp: PolyType => - def paramBounds(trefs: List[TypeRef]): List[Type] = - tp.paramBounds map new InstPolyMap(tp, trefs) - val tparams = ctx.newTypeParams(sym, tp.paramNames, EmptyFlags, paramBounds) - (tparams, tp.instantiate(tparams map (_.typeConstructor))) - case tp => (Nil, tp) + def AppliedTypeTree(tpt: Tree, args: List[Tree])(implicit ctx: Context): AppliedTypeTree = + Trees.AppliedTypeTree(tpt, args).withType(tpt.tpe.appliedTo(args map (_.tpe))) + + def TypeBoundsTree(lo: Tree, hi: Tree)(implicit ctx: Context): TypeBoundsTree = + Trees.TypeBoundsTree(lo, hi).withType(TypeBounds(lo.tpe, hi.tpe)) + + def Bind(sym: Symbol, body: Tree)(implicit ctx: Context): Bind = + Trees.Bind(sym.name, body)(defPos(sym)).withType(sym.info) + + def Alternative(trees: List[Tree])(implicit ctx: Context): Alternative = + Trees.Alternative(trees).withType(ctx.lub(trees map (_.tpe))) + + def UnApply(fun: Tree, args: List[Tree])(implicit ctx: Context): UnApply = + Trees.UnApply(fun, args).withType(fun.tpe match { + case MethodType(_, paramTypes) => paramTypes.head + }) + + def refType(sym: Symbol)(implicit ctx: Context) = NamedType(sym.owner.thisType, sym) + + def ValDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): ValDef = + Trees.ValDef(Modifiers(sym), sym.name, TypeTree(sym.info), rhs)(defPos(sym)) + .withType(refType(sym)) + + def DefDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): DefDef = { + + val (tparams, mtp) = sym.info match { + case tp: PolyType => + def paramBounds(trefs: List[TypeRef]): List[Type] = + tp.paramBounds map new InstPolyMap(tp, trefs) + val tparams = ctx.newTypeParams(sym, tp.paramNames, EmptyFlags, paramBounds) + (tparams, tp.instantiate(tparams map (_.typeConstructor))) + case tp => (Nil, tp) + } + + def valueParamss(tp: Type): (List[List[TermSymbol]], Type) = tp match { + case tp @ MethodType(paramNames, paramTypes) => + def valueParam(name: TermName, info: Type): TermSymbol = + ctx.newSymbol(sym, name, TermParam, info) + val params = (paramNames, paramTypes).zipped.map(valueParam) + val (paramss, rtp) = valueParamss(tp.instantiate(params map (_.typeConstructor))) + (params :: paramss, rtp) + case tp => (Nil, tp) + } + val (vparamss, rtp) = valueParamss(mtp) + + Trees.DefDef( + Modifiers(sym), sym.name, tparams map TypeDef, + vparamss map (_ map (ValDef(_))), TypeTree(rtp), rhs)(defPos(sym)) + .withType(refType(sym)) } - def valueParamss(tp: Type): (List[List[TermSymbol]], Type) = tp match { - case tp @ MethodType(paramNames, paramTypes) => - def valueParam(name: TermName, info: Type): TermSymbol = - ctx.newSymbol(sym, name, TermParam, info) - val params = (paramNames, paramTypes).zipped.map(valueParam) - val (paramss, rtp) = valueParamss(tp.instantiate(params map (_.typeConstructor))) - (params :: paramss, rtp) - case tp => (Nil, tp) + def TypeDef(sym: TypeSymbol)(implicit ctx: Context): TypeDef = + Trees.TypeDef(Modifiers(sym), sym.name, TypeTree(sym.info))(defPos(sym)) + .withType(refType(sym)) + + def ClassDef(cls: ClassSymbol, typeParams: List[TypeSymbol], body: List[Tree])(implicit ctx: Context): ClassDef = { + val parents = cls.info.parents map (TypeTree(_)) + val selfType = + if (cls.selfType eq cls.typeConstructor) EmptyValDef + else ValDef(ctx.newSelfSym(cls)) + def isOwnTypeParamAccessor(stat: Tree) = + stat.symbol.owner == cls && (stat.symbol is TypeParam) + val (tparamAccessors, rest) = body partition isOwnTypeParamAccessor + val tparams = + (typeParams map TypeDef) ++ + (tparamAccessors collect { + case td: TypeDef if !(typeParams contains td.symbol) => td + }) + val findLocalDummy = new FindLocalDummyAccumulator(cls) + val localDummy = ((NoSymbol: Symbol) /: body)(findLocalDummy) + .orElse(ctx.newLocalDummy(cls)) + val impl = Trees.Template(parents, selfType, rest) + .withType(refType(localDummy)) + Trees.ClassDef(Modifiers(cls), cls.name, tparams, impl)(defPos(cls)) + .withType(refType(cls)) } - val (vparamss, rtp) = valueParamss(mtp) - - Trees.DefDef( - Modifiers(sym), sym.name, tparams map TypeDef, - vparamss map (_ map (ValDef(_))), TypeTree(rtp), rhs)(defPos(sym)) - .withType(refType(sym)) - } - - def TypeDef(sym: TypeSymbol)(implicit ctx: Context): TypeDef = - Trees.TypeDef(Modifiers(sym), sym.name, TypeTree(sym.info))(defPos(sym)) - .withType(refType(sym)) - - def ClassDef(cls: ClassSymbol, typeParams: List[TypeSymbol], body: List[Tree])(implicit ctx: Context): ClassDef = { - val parents = cls.info.parents map (TypeTree(_)) - val selfType = - if (cls.selfType eq cls.typeConstructor) EmptyValDef - else ValDef(ctx.newSelfSym(cls)) - def isOwnTypeParamAccessor(stat: Tree) = - stat.symbol.owner == cls && (stat.symbol is TypeParam) - val (tparamAccessors, rest) = body partition isOwnTypeParamAccessor - val tparams = - (typeParams map TypeDef) ++ - (tparamAccessors collect { - case td: TypeDef if !(typeParams contains td.symbol) => td - }) - val findLocalDummy = new FindLocalDummyAccumulator(cls) - val localDummy = ((NoSymbol: Symbol) /: body)(findLocalDummy) - .orElse(ctx.newLocalDummy(cls)) - val impl = Trees.Template(parents, selfType, rest) - .withType(refType(localDummy)) - Trees.ClassDef(Modifiers(cls), cls.name, tparams, impl)(defPos(cls)) - .withType(refType(cls)) - } - def Import(expr: Tree, selectors: List[Trees.UntypedTree])(implicit ctx: Context): Import = - Trees.Import(expr, selectors).withType(refType(ctx.newImportSymbol(expr))) + def Import(expr: Tree, selectors: List[Trees.UntypedTree])(implicit ctx: Context): Import = + Trees.Import(expr, selectors).withType(refType(ctx.newImportSymbol(expr))) - def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = - Trees.PackageDef(pid, stats).withType(refType(pid.symbol)) + def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = + Trees.PackageDef(pid, stats).withType(refType(pid.symbol)) - def Annotated(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated = - Trees.Annotated(annot, arg).withType(AnnotatedType(List(Annotation(annot)), arg.tpe)) + def Annotated(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated = + Trees.Annotated(annot, arg).withType(AnnotatedType(List(Annotation(annot)), arg.tpe)) - val EmptyTree: Tree = Trees.EmptyTree[Type] + val EmptyTree: Tree = Trees.EmptyTree[Type] - val EmptyValDef: ValDef = Trees.EmptyValDef[Type] + val EmptyValDef: ValDef = Trees.EmptyValDef[Type] - def Shared(tree: Tree): Shared = - Trees.Shared(tree).withType(tree.tpe) + def Shared(tree: Tree): Shared = + Trees.Shared(tree).withType(tree.tpe) - // ----------------------------------------------------------------------------- + // ----------------------------------------------------------------------------- - def New(tp: Type, args: List[Tree])(implicit ctx: Context): Apply = - Apply( - Select( - New(tp), - TermRef(tp.normalizedPrefix, tp.typeSymbol.primaryConstructor.asTerm)), - args) + def New(tp: Type, args: List[Tree])(implicit ctx: Context): Apply = + Apply( + Select( + New(tp), + TermRef(tp.normalizedPrefix, tp.typeSymbol.primaryConstructor.asTerm)), + args) - def ModuleDef(sym: TermSymbol, body: List[Tree])(implicit ctx: Context): ValDef = { - val modcls = sym.moduleClass.asClass - val clsdef = ClassDef(modcls, Nil, body) - val rhs = Block(List(clsdef), New(modcls.typeConstructor)) - ValDef(sym, rhs) - } + def ModuleDef(sym: TermSymbol, body: List[Tree])(implicit ctx: Context): ValDef = { + val modcls = sym.moduleClass.asClass + val clsdef = ClassDef(modcls, Nil, body) + val rhs = Block(List(clsdef), New(modcls.typeConstructor)) + ValDef(sym, rhs) + } - private class FindLocalDummyAccumulator(cls: ClassSymbol)(implicit ctx: Context) extends TreeAccumulator[Symbol] { - def apply(sym: Symbol, tree: Tree) = - if (sym.exists) sym - else if (tree.isDef) { - val owner = tree.symbol.owner - if (owner.isLocalDummy && owner.owner == cls) owner - else if (owner == cls) foldOver(sym, tree) - else sym - } else foldOver(sym, tree) + private class FindLocalDummyAccumulator(cls: ClassSymbol)(implicit ctx: Context) extends TreeAccumulator[Symbol] { + def apply(sym: Symbol, tree: Tree) = + if (sym.exists) sym + else if (tree.isDef) { + val owner = tree.symbol.owner + if (owner.isLocalDummy && owner.owner == cls) owner + else if (owner == cls) foldOver(sym, tree) + else sym + } else foldOver(sym, tree) + } } } diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala index d131fe8f8..2f370fbdd 100644 --- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala @@ -5,7 +5,7 @@ package pickling import Contexts._, Symbols._, Types._, Names._, StdNames._, NameOps._, Scopes._, Decorators._ import SymDenotations._, UnPickler._, Constants._, Annotations._, Positions._ -import TypedTrees._ +import TypedTrees.tpd._ import java.io.{ File, IOException } import java.lang.Integer.toHexString import scala.collection.{ mutable, immutable } diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 7a06b098e..b12054570 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -9,7 +9,7 @@ import java.lang.Double.longBitsToDouble import Contexts._, Symbols._, Types._, Scopes._, SymDenotations._, Names._ import StdNames._, Denotations._, NameOps._, Flags._, Constants._, Annotations._ -import Positions._, TypedTrees._ +import Positions._, TypedTrees.tpd._ import io.AbstractFile import scala.reflect.internal.pickling.PickleFormat._ import scala.collection.{ mutable, immutable } -- cgit v1.2.3