diff options
-rw-r--r-- | src/dotty/tools/dotc/ast/Trees.scala | 156 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/TypedTrees.scala | 165 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/UntypedTrees.scala | 74 |
3 files changed, 189 insertions, 206 deletions
diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala index 5836b0863..74f792220 100644 --- a/src/dotty/tools/dotc/ast/Trees.scala +++ b/src/dotty/tools/dotc/ast/Trees.scala @@ -717,80 +717,20 @@ object Trees { type SharedTree = Trees.SharedTree[T] type Thicket = Trees.Thicket[T] - def Ident(name: Name)(implicit ctx: Context): Ident = new Ident(name) - def BackquotedIdent(name: Name)(implicit ctx: Context): BackquotedIdent = new BackquotedIdent(name) - def Select(qualifier: Tree, name: Name)(implicit ctx: Context): Select = new Select(qualifier, name) - def SelectWithSig(qualifier: Tree, name: Name, sig: Signature)(implicit ctx: Context): Select = new SelectWithSig(qualifier, name, sig) - def This(qual: TypeName)(implicit ctx: Context): This = new This(qual) - def Super(qual: Tree, mix: TypeName)(implicit ctx: Context): Super = new Super(qual, mix) - def Apply(fun: Tree, args: List[Tree])(implicit ctx: Context): Apply = new Apply(fun, args) - def TypeApply(fun: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = new TypeApply(fun, args) - def Literal(const: Constant)(implicit ctx: Context): Literal = new Literal(const) - def New(tpt: Tree)(implicit ctx: Context): New = new New(tpt) - def Pair(left: Tree, right: Tree)(implicit ctx: Context): Pair = new Pair(left, right) - def Typed(expr: Tree, tpt: Tree)(implicit ctx: Context): Typed = new Typed(expr, tpt) - def NamedArg(name: Name, arg: Tree)(implicit ctx: Context): NamedArg = new NamedArg(name, arg) - def Assign(lhs: Tree, rhs: Tree)(implicit ctx: Context): Assign = new Assign(lhs, rhs) - def Block(stats: List[Tree], expr: Tree)(implicit ctx: Context): Block = new Block(stats, expr) - def If(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = new If(cond, thenp, elsep) - def Closure(env: List[Tree], meth: RefTree)(implicit ctx: Context): Closure = new Closure(env, meth) - def Match(selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match = new Match(selector, cases) - def CaseDef(pat: Tree, guard: Tree, body: Tree)(implicit ctx: Context): CaseDef = new CaseDef(pat, guard, body) - def Return(expr: Tree, from: Tree)(implicit ctx: Context): Return = new Return(expr, from) - def Try(expr: Tree, handler: Tree, finalizer: Tree)(implicit ctx: Context): Try = new Try(expr, handler, finalizer) - def Throw(expr: Tree)(implicit ctx: Context): Throw = new Throw(expr) - def SeqLiteral(elems: List[Tree])(implicit ctx: Context): SeqLiteral = new SeqLiteral(elems) - def TypeTree(original: Tree)(implicit ctx: Context): TypeTree = new TypeTree(original) - def TypeTree() = new TypeTree(EmptyTree) - def SingletonTypeTree(ref: Tree)(implicit ctx: Context): SingletonTypeTree = new SingletonTypeTree(ref) - def SelectFromTypeTree(qualifier: Tree, name: Name)(implicit ctx: Context): SelectFromTypeTree = new SelectFromTypeTree(qualifier, name) - def AndTypeTree(left: Tree, right: Tree)(implicit ctx: Context): AndTypeTree = new AndTypeTree(left, right) - def OrTypeTree(left: Tree, right: Tree)(implicit ctx: Context): OrTypeTree = new OrTypeTree(left, right) - def RefinedTypeTree(tpt: Tree, refinements: List[Tree])(implicit ctx: Context): RefinedTypeTree = new RefinedTypeTree(tpt, refinements) - def AppliedTypeTree(tpt: Tree, args: List[Tree])(implicit ctx: Context): AppliedTypeTree = new AppliedTypeTree(tpt, args) - def TypeBoundsTree(lo: Tree, hi: Tree)(implicit ctx: Context): TypeBoundsTree = new TypeBoundsTree(lo, hi) - def Bind(name: Name, body: Tree)(implicit ctx: Context): Bind = new Bind(name, body) - def Alternative(trees: List[Tree])(implicit ctx: Context): Alternative = new Alternative(trees) - def UnApply(fun: Tree, args: List[Tree])(implicit ctx: Context): UnApply = new UnApply(fun, args) - def ValDef(mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree)(implicit ctx: Context): ValDef = new ValDef(mods, name, tpt, rhs) - def DefDef(mods: Modifiers, name: TermName, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree)(implicit ctx: Context): DefDef = new DefDef(mods, name, tparams, vparamss, tpt, rhs) - def TypeDef(mods: Modifiers, name: TypeName, rhs: Tree)(implicit ctx: Context): TypeDef = new TypeDef(mods, name, rhs) - def Template(constr: DefDef, parents: List[Tree], self: ValDef, body: List[Tree])(implicit ctx: Context): Template = new Template(constr, parents, self, body) - def Import(expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = new Import(expr, selectors) - def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = new PackageDef(pid, stats) - def Annotated(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated = new Annotated(annot, arg) - def SharedTree(shared: Tree)(implicit ctx: Context): SharedTree = new SharedTree(shared) - def Thicket(trees: List[Tree])(implicit ctx: Context): Thicket = new Thicket(trees) - val EmptyTree: Thicket = genericEmptyTree val EmptyValDef: ValDef = genericEmptyValDef + // ----- Auxiliary creation methods ------------------ + def Modifiers(flags: FlagSet = EmptyFlags, privateWithin: TypeName = tpnme.EMPTY, annotations: List[Tree] = Nil) = new Modifiers(flags, privateWithin, annotations) - // ----- Auxiliary creation methods ------------------ - - // def TypeTree(tpe: Type): TypeTree = TypeTree().withType(tpe) todo: move to untpd/tpd - - /** new tpt(args1)...(args_n) - */ - def New(tpt: Tree, argss: List[List[Tree]])(implicit ctx: Context): Tree = - ((Select(New(tpt), nme.CONSTRUCTOR): Tree) /: argss)(Apply(_, _)) - - def Block(stat: Tree, expr: Tree)(implicit ctx: Context): Block = - Block(stat :: Nil, expr) - - def Apply(fn: Tree, arg: Tree)(implicit ctx: Context): Apply = - Apply(fn, arg :: Nil) - - def AppliedTypeTree(tpt: Tree, arg: Tree)(implicit ctx: Context): AppliedTypeTree = - AppliedTypeTree(tpt, arg :: Nil) - - def Thicket()(implicit ctx: Context): Thicket = EmptyTree - def Thicket(x1: Tree, x2: Tree)(implicit ctx: Context): Thicket = Thicket(x1 :: x2 :: Nil) - def Thicket(x1: Tree, x2: Tree, x3: Tree)(implicit ctx: Context): Thicket = Thicket(x1 :: x2 :: x3 :: Nil) - def flatTree(xs: List[Tree])(implicit ctx: Context): Tree = flatten(xs) match { + def Thicket(trees: List[Tree]): Thicket = new Thicket(trees) + def Thicket(): Thicket = EmptyTree + def Thicket(x1: Tree, x2: Tree): Thicket = Thicket(x1 :: x2 :: Nil) + def Thicket(x1: Tree, x2: Tree, x3: Tree): Thicket = Thicket(x1 :: x2 :: x3 :: Nil) + def flatTree(xs: List[Tree]): Tree = flatten(xs) match { case x :: Nil => x case _ => Thicket(xs) } @@ -845,169 +785,169 @@ object Trees { private def copyAttrs(t: untpd.Tree, tree: Tree): t.ThisTree[T] = t.withType(tree.typeOpt).withPos(tree.pos).asInstanceOf[t.ThisTree[T]] - def Ident(tree: Tree, name: Name)(implicit ctx: Context): Ident = tree match { + def Ident(tree: Tree, name: Name): Ident = tree match { case tree: BackquotedIdent => if (name == tree.name) tree else finalize(tree, new BackquotedIdent(name)) case tree: Ident if (name == tree.name) => tree case _ => finalize(tree, untpd.Ident(name)) } - def Select(tree: Tree, qualifier: Tree, name: Name)(implicit ctx: Context): Select = tree match { + def Select(tree: Tree, qualifier: Tree, name: Name): Select = tree match { case tree: SelectWithSig => if ((qualifier eq tree.qualifier) && (name == tree.name) ) tree else finalize(tree, new SelectWithSig(qualifier, name, tree.sig)) case tree: Select if (qualifier eq tree.qualifier) && (name == tree.name) => tree case _ => finalize(tree, untpd.Select(qualifier, name)) } - def This(tree: Tree, qual: TypeName)(implicit ctx: Context): This = tree match { + def This(tree: Tree, qual: TypeName): This = tree match { case tree: This if (qual == tree.qual) => tree case _ => finalize(tree, untpd.This(qual)) } - def Super(tree: Tree, qual: Tree, mix: TypeName)(implicit ctx: Context): Super = tree match { + def Super(tree: Tree, qual: Tree, mix: TypeName): Super = tree match { case tree: Super if (qual eq tree.qual) && (mix == tree.mix) => tree case _ => finalize(tree, untpd.Super(qual, mix)) } - def Apply(tree: Tree, fun: Tree, args: List[Tree])(implicit ctx: Context): Apply = tree match { + def Apply(tree: Tree, fun: Tree, args: List[Tree]): Apply = tree match { case tree: Apply if (fun eq tree.fun) && (args eq tree.args) => tree case _ => finalize(tree, untpd.Apply(fun, args)) } - def TypeApply(tree: Tree, fun: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = tree match { + def TypeApply(tree: Tree, fun: Tree, args: List[Tree]): TypeApply = tree match { case tree: TypeApply if (fun eq tree.fun) && (args eq tree.args) => tree - case _ => inst.TypeApply(fun, args).withPos(tree) + case _ => finalize(tree, untpd.TypeApply(fun, args)) } - def Literal(tree: Tree, const: Constant)(implicit ctx: Context): Literal = tree match { + def Literal(tree: Tree, const: Constant): Literal = tree match { case tree: Literal if (const == tree.const) => tree case _ => finalize(tree, untpd.Literal(const)) } - def New(tree: Tree, tpt: Tree)(implicit ctx: Context): New = tree match { + def New(tree: Tree, tpt: Tree): New = tree match { case tree: New if (tpt eq tree.tpt) => tree case _ => finalize(tree, untpd.New(tpt)) } - def Pair(tree: Tree, left: Tree, right: Tree)(implicit ctx: Context): Pair = tree match { + def Pair(tree: Tree, left: Tree, right: Tree): Pair = tree match { case tree: Pair if (left eq tree.left) && (right eq tree.right) => tree case _ => finalize(tree, untpd.Pair(left, right)) } - def Typed(tree: Tree, expr: Tree, tpt: Tree)(implicit ctx: Context): Typed = tree match { + def Typed(tree: Tree, expr: Tree, tpt: Tree): Typed = tree match { case tree: Typed if (expr eq tree.expr) && (tpt eq tree.tpt) => tree case _ => finalize(tree, untpd.Typed(expr, tpt)) } - def NamedArg(tree: Tree, name: Name, arg: Tree)(implicit ctx: Context): NamedArg = tree match { + def NamedArg(tree: Tree, name: Name, arg: Tree): NamedArg = tree match { case tree: NamedArg if (name == tree.name) && (arg eq tree.arg) => tree case _ => finalize(tree, untpd.NamedArg(name, arg)) } - def Assign(tree: Tree, lhs: Tree, rhs: Tree)(implicit ctx: Context): Assign = tree match { + def Assign(tree: Tree, lhs: Tree, rhs: Tree): Assign = tree match { case tree: Assign if (lhs eq tree.lhs) && (rhs eq tree.rhs) => tree case _ => finalize(tree, untpd.Assign(lhs, rhs)) } - def Block(tree: Tree, stats: List[Tree], expr: Tree)(implicit ctx: Context): Block = tree match { + def Block(tree: Tree, stats: List[Tree], expr: Tree): Block = tree match { case tree: Block if (stats eq tree.stats) && (expr eq tree.expr) => tree case _ => finalize(tree, untpd.Block(stats, expr)) } - def If(tree: Tree, cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = tree match { + def If(tree: Tree, cond: Tree, thenp: Tree, elsep: Tree): If = tree match { case tree: If if (cond eq tree.cond) && (thenp eq tree.thenp) && (elsep eq tree.elsep) => tree case _ => finalize(tree, untpd.If(cond, thenp, elsep)) } - def Closure(tree: Tree, env: List[Tree], meth: RefTree)(implicit ctx: Context): Closure = tree match { + def Closure(tree: Tree, env: List[Tree], meth: RefTree): Closure = tree match { case tree: Closure if (env eq tree.env) && (meth eq tree.meth) => tree case _ => finalize(tree, untpd.Closure(env, meth)) } - def Match(tree: Tree, selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match = tree match { + def Match(tree: Tree, selector: Tree, cases: List[CaseDef]): Match = tree match { case tree: Match if (selector eq tree.selector) && (cases eq tree.cases) => tree case _ => finalize(tree, untpd.Match(selector, cases)) } - def CaseDef(tree: Tree, pat: Tree, guard: Tree, body: Tree)(implicit ctx: Context): CaseDef = tree match { + def CaseDef(tree: Tree, pat: Tree, guard: Tree, body: Tree): CaseDef = tree match { case tree: CaseDef if (pat eq tree.pat) && (guard eq tree.guard) && (body eq tree.body) => tree case _ => finalize(tree, untpd.CaseDef(pat, guard, body)) } - def Return(tree: Tree, expr: Tree, from: Tree)(implicit ctx: Context): Return = tree match { + def Return(tree: Tree, expr: Tree, from: Tree): Return = tree match { case tree: Return if (expr eq tree.expr) && (from eq tree.from) => tree case _ => finalize(tree, untpd.Return(expr, from)) } - def Try(tree: Tree, expr: Tree, handler: Tree, finalizer: Tree)(implicit ctx: Context): Try = tree match { + def Try(tree: Tree, expr: Tree, handler: Tree, finalizer: Tree): Try = tree match { case tree: Try if (expr eq tree.expr) && (handler eq tree.handler) && (finalizer eq tree.finalizer) => tree case _ => finalize(tree, untpd.Try(expr, handler, finalizer)) } - def Throw(tree: Tree, expr: Tree)(implicit ctx: Context): Throw = tree match { + def Throw(tree: Tree, expr: Tree): Throw = tree match { case tree: Throw if (expr eq tree.expr) => tree case _ => finalize(tree, untpd.Throw(expr)) } - def SeqLiteral(tree: Tree, elems: List[Tree])(implicit ctx: Context): SeqLiteral = tree match { + def SeqLiteral(tree: Tree, elems: List[Tree]): SeqLiteral = tree match { case tree: SeqLiteral if (elems eq tree.elems) => tree case _ => finalize(tree, untpd.SeqLiteral(elems)) } - def SingletonTypeTree(tree: Tree, ref: Tree)(implicit ctx: Context): SingletonTypeTree = tree match { + def SingletonTypeTree(tree: Tree, ref: Tree): SingletonTypeTree = tree match { case tree: SingletonTypeTree if (ref eq tree.ref) => tree case _ => finalize(tree, untpd.SingletonTypeTree(ref)) } - def SelectFromTypeTree(tree: Tree, qualifier: Tree, name: Name)(implicit ctx: Context): SelectFromTypeTree = tree match { + def SelectFromTypeTree(tree: Tree, qualifier: Tree, name: Name): SelectFromTypeTree = tree match { case tree: SelectFromTypeTree if (qualifier eq tree.qualifier) && (name == tree.name) => tree case _ => finalize(tree, untpd.SelectFromTypeTree(qualifier, name)) } - def AndTypeTree(tree: Tree, left: Tree, right: Tree)(implicit ctx: Context): AndTypeTree = tree match { + def AndTypeTree(tree: Tree, left: Tree, right: Tree): AndTypeTree = tree match { case tree: AndTypeTree if (left eq tree.left) && (right eq tree.right) => tree case _ => finalize(tree, untpd.AndTypeTree(left, right)) } - def OrTypeTree(tree: Tree, left: Tree, right: Tree)(implicit ctx: Context): OrTypeTree = tree match { + def OrTypeTree(tree: Tree, left: Tree, right: Tree): OrTypeTree = tree match { case tree: OrTypeTree if (left eq tree.left) && (right eq tree.right) => tree case _ => finalize(tree, untpd.OrTypeTree(left, right)) } - def RefinedTypeTree(tree: Tree, tpt: Tree, refinements: List[Tree])(implicit ctx: Context): RefinedTypeTree = tree match { + def RefinedTypeTree(tree: Tree, tpt: Tree, refinements: List[Tree]): RefinedTypeTree = tree match { case tree: RefinedTypeTree if (tpt eq tree.tpt) && (refinements eq tree.refinements) => tree case _ => finalize(tree, untpd.RefinedTypeTree(tpt, refinements)) } - def AppliedTypeTree(tree: Tree, tpt: Tree, args: List[Tree])(implicit ctx: Context): AppliedTypeTree = tree match { + def AppliedTypeTree(tree: Tree, tpt: Tree, args: List[Tree]): AppliedTypeTree = tree match { case tree: AppliedTypeTree if (tpt eq tree.tpt) && (args eq tree.args) => tree case _ => finalize(tree, untpd.AppliedTypeTree(tpt, args)) } - def TypeBoundsTree(tree: Tree, lo: Tree, hi: Tree)(implicit ctx: Context): TypeBoundsTree = tree match { + def TypeBoundsTree(tree: Tree, lo: Tree, hi: Tree): TypeBoundsTree = tree match { case tree: TypeBoundsTree if (lo eq tree.lo) && (hi eq tree.hi) => tree case _ => finalize(tree, untpd.TypeBoundsTree(lo, hi)) } - def Bind(tree: Tree, name: Name, body: Tree)(implicit ctx: Context): Bind = tree match { + def Bind(tree: Tree, name: Name, body: Tree): Bind = tree match { case tree: Bind if (name eq tree.name) && (body eq tree.body) => tree case _ => finalize(tree, untpd.Bind(name, body)) } - def Alternative(tree: Tree, trees: List[Tree])(implicit ctx: Context): Alternative = tree match { + def Alternative(tree: Tree, trees: List[Tree]): Alternative = tree match { case tree: Alternative if (trees eq tree.trees) => tree case _ => finalize(tree, untpd.Alternative(trees)) } - def UnApply(tree: Tree, fun: Tree, args: List[Tree])(implicit ctx: Context): UnApply = tree match { + def UnApply(tree: Tree, fun: Tree, args: List[Tree]): UnApply = tree match { case tree: UnApply if (fun eq tree.fun) && (args eq tree.args) => tree case _ => finalize(tree, untpd.UnApply(fun, args)) } - def ValDef(tree: Tree, mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree)(implicit ctx: Context): ValDef = tree match { + def ValDef(tree: Tree, mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree): ValDef = tree match { case tree: ValDef if (mods == tree.mods) && (name == tree.name) && (tpt eq tree.tpt) && (rhs eq tree.rhs) => tree case _ => finalize(tree, untpd.ValDef(mods, name, tpt, rhs)) } - def DefDef(tree: Tree, mods: Modifiers, name: TermName, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree)(implicit ctx: Context): DefDef = tree match { + def DefDef(tree: Tree, mods: Modifiers, name: TermName, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): DefDef = tree match { case tree: DefDef if (mods == tree.mods) && (name == tree.name) && (tparams eq tree.tparams) && (vparamss eq tree.vparamss) && (tpt eq tree.tpt) && (rhs eq tree.rhs) => tree case _ => finalize(tree, untpd.DefDef(mods, name, tparams, vparamss, tpt, rhs)) } - def TypeDef(tree: Tree, mods: Modifiers, name: TypeName, rhs: Tree, tparams: List[untpd.TypeDef] = Nil)(implicit ctx: Context): TypeDef = tree match { + def TypeDef(tree: Tree, mods: Modifiers, name: TypeName, rhs: Tree, tparams: List[untpd.TypeDef] = Nil): TypeDef = tree match { case tree: TypeDef if (mods == tree.mods) && (name == tree.name) && (rhs eq tree.rhs) && (tparams eq tree.tparams) => tree case _ => finalize(tree, untpd.TypeDef(mods, name, tparams, rhs)) } - def Template(tree: Tree, constr: DefDef, parents: List[Tree], self: ValDef, body: List[Tree])(implicit ctx: Context): Template = tree match { + def Template(tree: Tree, constr: DefDef, parents: List[Tree], self: ValDef, body: List[Tree]): Template = tree match { case tree: Template if (constr eq tree.constr) && (parents eq tree.parents) && (self eq tree.self) && (body eq tree.body) => tree case _ => finalize(tree, untpd.Template(constr, parents, self, body)) } - def Import(tree: Tree, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match { + def Import(tree: Tree, expr: Tree, selectors: List[untpd.Tree]): Import = tree match { case tree: Import if (expr eq tree.expr) && (selectors eq tree.selectors) => tree case _ => finalize(tree, untpd.Import(expr, selectors)) } - def PackageDef(tree: Tree, pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = tree match { + def PackageDef(tree: Tree, pid: RefTree, stats: List[Tree]): PackageDef = tree match { case tree: PackageDef if (pid eq tree.pid) && (stats eq tree.stats) => tree case _ => finalize(tree, untpd.PackageDef(pid, stats)) } - def Annotated(tree: Tree, annot: Tree, arg: Tree)(implicit ctx: Context): Annotated = tree match { + def Annotated(tree: Tree, annot: Tree, arg: Tree): Annotated = tree match { case tree: Annotated if (annot eq tree.annot) && (arg eq tree.arg) => tree case _ => finalize(tree, untpd.Annotated(annot, arg)) } - def SharedTree(tree: Tree, shared: Tree)(implicit ctx: Context): SharedTree = tree match { + def SharedTree(tree: Tree, shared: Tree): SharedTree = tree match { case tree: SharedTree if (shared eq tree.shared) => tree case _ => finalize(tree, untpd.SharedTree(shared)) } - def Thicket(tree: Tree, trees: List[Tree])(implicit ctx: Context): Thicket = tree match { + def Thicket(tree: Tree, trees: List[Tree]): Thicket = tree match { case tree: Thicket if (trees eq tree.trees) => tree case _ => finalize(tree, untpd.Thicket(trees)) } diff --git a/src/dotty/tools/dotc/ast/TypedTrees.scala b/src/dotty/tools/dotc/ast/TypedTrees.scala index e4488ac79..cea799116 100644 --- a/src/dotty/tools/dotc/ast/TypedTrees.scala +++ b/src/dotty/tools/dotc/ast/TypedTrees.scala @@ -14,28 +14,23 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { if (sym.privateWithin.exists) sym.privateWithin.asType.name else tpnme.EMPTY, sym.annotations map (_.tree)) - override def Ident(name: Name)(implicit ctx: Context): Ident = unsupported("Ident") - override def BackquotedIdent(name: Name)(implicit ctx: Context): BackquotedIdent = unsupported("BackquotedIdent") - def Ident(tp: NamedType)(implicit ctx: Context): Ident = - super.Ident(tp.name).withType(tp.underlyingIfRepeated).checked + untpd.Ident(tp.name).withType(tp.underlyingIfRepeated).checked - override def Select(qualifier: Tree, name: Name)(implicit ctx: Context): Select = + def Select(qualifier: Tree, name: Name)(implicit ctx: Context): Select = Select(qualifier, NamedType(qualifier.tpe, name)) def Select(pre: Tree, tp: NamedType)(implicit ctx: Context): Select = - super.Select(pre, tp.name).withType(tp).checked + untpd.Select(pre, tp.name).withType(tp).checked - override def SelectWithSig(qualifier: Tree, name: Name, sig: Signature)(implicit ctx: Context) = - super.SelectWithSig(qualifier, name, sig) + def SelectWithSig(qualifier: Tree, name: Name, sig: Signature)(implicit ctx: Context) = + untpd.SelectWithSig(qualifier, name, sig) .withType(TermRef.withSig(qualifier.tpe, name.asTermName, sig)) - override def This(qual: TypeName)(implicit ctx: Context): This = unsupported("This") - def This(cls: ClassSymbol)(implicit ctx: Context): This = - super.This(cls.name).withType(cls.thisType).checked + untpd.This(cls.name).withType(cls.thisType).checked - override def Super(qual: Tree, mix: TypeName)(implicit ctx: Context): Super = { + def Super(qual: Tree, mix: TypeName)(implicit ctx: Context): Super = { val owntype = if (mix.isEmpty) ctx.glb(qual.tpe.parents) else { @@ -43,10 +38,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { check(mixParents.length == 1) mixParents.head } - super.Super(qual, mix).withType(SuperType(qual.tpe, owntype)).checked + untpd.Super(qual, mix).withType(SuperType(qual.tpe, owntype)).checked } - override def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = { + def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = { val owntype = fn.tpe.widen match { case fntpe @ MethodType(pnames, ptypes) => check(sameLength(ptypes, args), s"${fn.show}: ${fntpe.show} to ${args.map(_.show).mkString(", ")}") @@ -55,10 +50,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { check(false) ErrorType } - super.Apply(fn, args).withType(owntype).checked + untpd.Apply(fn, args).withType(owntype).checked } - override def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = { + def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = { val owntype = fn.tpe.widen match { case fntpe @ PolyType(pnames) => check(sameLength(pnames, args)) @@ -67,32 +62,32 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { check(false) ErrorType } - super.TypeApply(fn, args).withType(owntype).checked + untpd.TypeApply(fn, args).withType(owntype).checked } - override def Literal(const: Constant)(implicit ctx: Context): Literal = - super.Literal(const).withType(const.tpe).checked + def Literal(const: Constant)(implicit ctx: Context): Literal = + untpd.Literal(const).withType(const.tpe).checked - override def New(tpt: Tree)(implicit ctx: Context): New = - super.New(tpt).withType(tpt.tpe).checked + def New(tpt: Tree)(implicit ctx: Context): New = + untpd.New(tpt).withType(tpt.tpe).checked def New(tp: Type)(implicit ctx: Context): New = New(TypeTree(tp)) - override def Pair(left: Tree, right: Tree)(implicit ctx: Context): Pair = - super.Pair(left, right).withType(defn.PairType.appliedTo(left.tpe, right.tpe)).checked + def Pair(left: Tree, right: Tree)(implicit ctx: Context): Pair = + untpd.Pair(left, right).withType(defn.PairType.appliedTo(left.tpe, right.tpe)).checked - override def Typed(expr: Tree, tpt: Tree)(implicit ctx: Context): Typed = - super.Typed(expr, tpt).withType(tpt.tpe).checked + def Typed(expr: Tree, tpt: Tree)(implicit ctx: Context): Typed = + untpd.Typed(expr, tpt).withType(tpt.tpe).checked - override def NamedArg(name: Name, arg: Tree)(implicit ctx: Context) = - super.NamedArg(name, arg).withType(arg.tpe).checked + def NamedArg(name: Name, arg: Tree)(implicit ctx: Context) = + untpd.NamedArg(name, arg).withType(arg.tpe).checked - override def Assign(lhs: Tree, rhs: Tree)(implicit ctx: Context): Assign = - super.Assign(lhs, rhs).withType(defn.UnitType).checked + def Assign(lhs: Tree, rhs: Tree)(implicit ctx: Context): Assign = + untpd.Assign(lhs, rhs).withType(defn.UnitType).checked - override def Block(stats: List[Tree], expr: Tree)(implicit ctx: Context): Block = { + def Block(stats: List[Tree], expr: Tree)(implicit ctx: Context): Block = { lazy val locals = localSyms(stats).toSet - val blk = super.Block(stats, expr) + val blk = untpd.Block(stats, expr) def widen(tp: Type): Type = tp match { case tp: TermRef if locals contains tp.symbol => widen(tp.info) @@ -104,17 +99,17 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def maybeBlock(stats: List[Tree], expr: Tree)(implicit ctx: Context): Tree = if (stats.isEmpty) expr else Block(stats, expr) - override def If(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = - super.If(cond, thenp, elsep).withType(thenp.tpe | elsep.tpe).checked + def If(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = + untpd.If(cond, thenp, elsep).withType(thenp.tpe | elsep.tpe).checked - override def Closure(env: List[Tree], meth: RefTree)(implicit ctx: Context): Closure = { + def Closure(env: List[Tree], meth: RefTree)(implicit ctx: Context): Closure = { val ownType = meth.tpe.widen match { case mt @ MethodType(_, formals) => assert(!mt.isDependent) val formals1 = formals mapConserve (_.underlyingIfRepeated) defn.FunctionType(formals1, mt.resultType) } - super.Closure(env, meth).withType(ownType).checked + untpd.Closure(env, meth).withType(ownType).checked } /** A function def @@ -135,90 +130,82 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { Closure(Nil, Ident(TermRef.withSym(NoPrefix, meth)))) } - override def Match(selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match = - super.Match(selector, cases).withType(ctx.lub(cases map (_.body.tpe))).checked + def Match(selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match = + untpd.Match(selector, cases).withType(ctx.lub(cases map (_.body.tpe))).checked - override def CaseDef(pat: Tree, guard: Tree, body: Tree)(implicit ctx: Context): CaseDef = - super.CaseDef(pat, guard, body).withType(body.tpe).checked + def CaseDef(pat: Tree, guard: Tree, body: Tree)(implicit ctx: Context): CaseDef = + untpd.CaseDef(pat, guard, body).withType(body.tpe).checked - override def Return(expr: Tree, from: Tree)(implicit ctx: Context): Return = - super.Return(expr, from).withType(defn.NothingType).checked + def Return(expr: Tree, from: Tree)(implicit ctx: Context): Return = + untpd.Return(expr, from).withType(defn.NothingType).checked - override def Try(block: Tree, handler: Tree, finalizer: Tree)(implicit ctx: Context): Try = - super.Try(block, handler, finalizer).withType(block.tpe | handler.tpe).checked + def Try(block: Tree, handler: Tree, finalizer: Tree)(implicit ctx: Context): Try = + untpd.Try(block, handler, finalizer).withType(block.tpe | handler.tpe).checked - override def Throw(expr: Tree)(implicit ctx: Context): Throw = - super.Throw(expr).withType(defn.NothingType).checked + def Throw(expr: Tree)(implicit ctx: Context): Throw = + untpd.Throw(expr).withType(defn.NothingType).checked - override def SeqLiteral(elems: List[Tree])(implicit ctx: Context): SeqLiteral = + def SeqLiteral(elems: List[Tree])(implicit ctx: Context): SeqLiteral = SeqLiteral(defn.SeqClass.typeConstructor.appliedTo( ctx.lub(elems map (_.tpe)) :: Nil), elems) // TODO: Split into Java/Scala eq literals def SeqLiteral(tpe: Type, elems: List[Tree])(implicit ctx: Context): SeqLiteral = - super.SeqLiteral(elems).withType(tpe).checked + untpd.SeqLiteral(elems).withType(tpe).checked - override def TypeTree(): TypeTree = unsupported("TypeTree()") - - override def TypeTree(original: Tree)(implicit ctx: Context): TypeTree = + def TypeTree(original: Tree)(implicit ctx: Context): TypeTree = TypeTree(original.tpe, original) def TypeTree(tp: Type, original: Tree = EmptyTree)(implicit ctx: Context): TypeTree = - super.TypeTree(original).withType(tp).checked + untpd.TypeTree(original).withType(tp).checked - override def SingletonTypeTree(ref: Tree)(implicit ctx: Context): SingletonTypeTree = - super.SingletonTypeTree(ref).withType(ref.tpe).checked + def SingletonTypeTree(ref: Tree)(implicit ctx: Context): SingletonTypeTree = + untpd.SingletonTypeTree(ref).withType(ref.tpe).checked - override def SelectFromTypeTree(qualifier: Tree, name: Name)(implicit ctx: Context): SelectFromTypeTree = + def SelectFromTypeTree(qualifier: Tree, name: Name)(implicit ctx: Context): SelectFromTypeTree = SelectFromTypeTree(qualifier, NamedType(qualifier.tpe, name)) def SelectFromTypeTree(qualifier: Tree, tp: NamedType)(implicit ctx: Context): SelectFromTypeTree = - super.SelectFromTypeTree(qualifier, tp.name).withType(tp).checked + untpd.SelectFromTypeTree(qualifier, tp.name).withType(tp).checked - override def AndTypeTree(left: Tree, right: Tree)(implicit ctx: Context): AndTypeTree = - super.AndTypeTree(left, right).withType(left.tpe & right.tpe).checked + def AndTypeTree(left: Tree, right: Tree)(implicit ctx: Context): AndTypeTree = + untpd.AndTypeTree(left, right).withType(left.tpe & right.tpe).checked - override def OrTypeTree(left: Tree, right: Tree)(implicit ctx: Context): OrTypeTree = - super.OrTypeTree(left, right).withType(left.tpe | right.tpe).checked + def OrTypeTree(left: Tree, right: Tree)(implicit ctx: Context): OrTypeTree = + untpd.OrTypeTree(left, right).withType(left.tpe | right.tpe).checked - override def RefinedTypeTree(tpt: Tree, refinements: List[Tree])(implicit ctx: Context): RefinedTypeTree = { + def RefinedTypeTree(tpt: Tree, refinements: List[Tree])(implicit ctx: Context): RefinedTypeTree = { def refineType(tp: Type, refinement: Symbol): Type = RefinedType(tp, refinement.name, refinement.info) - super.RefinedTypeTree(tpt, refinements) + untpd.RefinedTypeTree(tpt, refinements) .withType((tpt.tpe /: (refinements map (_.symbol)))(refineType)).checked } def refineType(tp: Type, refinement: Symbol)(implicit ctx: Context): Type = RefinedType(tp, refinement.name, refinement.info) - override def AppliedTypeTree(tpt: Tree, args: List[Tree])(implicit ctx: Context): AppliedTypeTree = - super.AppliedTypeTree(tpt, args).withType(tpt.tpe.appliedTo(args map (_.tpe))).checked - - override def TypeBoundsTree(lo: Tree, hi: Tree)(implicit ctx: Context): TypeBoundsTree = - super.TypeBoundsTree(lo, hi).withType(TypeBounds(lo.tpe, hi.tpe)).checked + def AppliedTypeTree(tpt: Tree, args: List[Tree])(implicit ctx: Context): AppliedTypeTree = + untpd.AppliedTypeTree(tpt, args).withType(tpt.tpe.appliedTo(args map (_.tpe))).checked - override def Bind(name: Name, body: Tree)(implicit ctx: Context): Bind = unsupported("Bind") + def TypeBoundsTree(lo: Tree, hi: Tree)(implicit ctx: Context): TypeBoundsTree = + untpd.TypeBoundsTree(lo, hi).withType(TypeBounds(lo.tpe, hi.tpe)).checked def Bind(sym: TermSymbol, body: Tree)(implicit ctx: Context): Bind = - super.Bind(sym.name, body).withType(refType(sym)).checked + untpd.Bind(sym.name, body).withType(refType(sym)).checked - override def Alternative(trees: List[Tree])(implicit ctx: Context): Alternative = - super.Alternative(trees).withType(ctx.lub(trees map (_.tpe))).checked + def Alternative(trees: List[Tree])(implicit ctx: Context): Alternative = + untpd.Alternative(trees).withType(ctx.lub(trees map (_.tpe))).checked - override def UnApply(fun: Tree, args: List[Tree])(implicit ctx: Context): UnApply = { + def UnApply(fun: Tree, args: List[Tree])(implicit ctx: Context): UnApply = { val owntype = fun.tpe.widen match { case MethodType(_, paramType :: Nil) => paramType case _ => check(false); ErrorType } - super.UnApply(fun, args).withType(owntype).checked + untpd.UnApply(fun, args).withType(owntype).checked } - override def ValDef(mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree)(implicit ctx: Context): ValDef = unsupported("ValDef") - def ValDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): ValDef = - super.ValDef(Modifiers(sym), sym.name, TypeTree(sym.info), rhs).withType(refType(sym)).checked - - override def DefDef(mods: Modifiers, name: TermName, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree)(implicit ctx: Context): DefDef = unsupported("DefDef") + untpd.ValDef(Modifiers(sym), sym.name, TypeTree(sym.info), rhs).withType(refType(sym)).checked def DefDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): DefDef = DefDef(sym, Function.const(rhs) _) @@ -243,16 +230,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { } val (vparamss, rtp) = valueParamss(mtp) val argss = vparamss map (_ map (vparam => Ident(vparam.symRef))) - super.DefDef( + untpd.DefDef( Modifiers(sym), sym.name, tparams map TypeDef, vparamss map (_ map (ValDef(_))), TypeTree(rtp), rhsFn(argss)) .withType(refType(sym)).checked } - override def TypeDef(mods: Modifiers, name: TypeName, rhs: Tree)(implicit ctx: Context): TypeDef = unsupported("TypeDef") - def TypeDef(sym: TypeSymbol)(implicit ctx: Context): TypeDef = - super.TypeDef(Modifiers(sym), sym.name, TypeTree(sym.info)) + untpd.TypeDef(Modifiers(sym), sym.name, TypeTree(sym.info)) .withType(refType(sym)).checked def ClassDef(cls: ClassSymbol, typeParams: List[TypeSymbol], constr: DefDef, body: List[Tree])(implicit ctx: Context): TypeDef = { @@ -271,22 +256,22 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { val findLocalDummy = new FindLocalDummyAccumulator(cls) val localDummy = ((NoSymbol: Symbol) /: body)(findLocalDummy) .orElse(ctx.newLocalDummy(cls)) - val impl = super.Template(constr, parents, selfType, rest) + val impl = untpd.Template(constr, parents, selfType, rest) .withType(refType(localDummy)).checked - super.TypeDef(Modifiers(cls), cls.name, impl) // !!! todo: revise + untpd.TypeDef(Modifiers(cls), cls.name, impl) // !!! todo: revise .withType(refType(cls)).checked } - override def Import(expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = - super.Import(expr, selectors).withType(refType(ctx.newImportSymbol(SharedTree(expr)))).checked + def Import(expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = + untpd.Import(expr, selectors).withType(refType(ctx.newImportSymbol(SharedTree(expr)))).checked - override def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = - super.PackageDef(pid, stats).withType(refType(pid.symbol)).checked + def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = + untpd.PackageDef(pid, stats).withType(refType(pid.symbol)).checked - override def Annotated(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated = - super.Annotated(annot, arg).withType(AnnotatedType(Annotation(annot), arg.tpe)).checked + def Annotated(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated = + untpd.Annotated(annot, arg).withType(AnnotatedType(Annotation(annot), arg.tpe)).checked - override def SharedTree(tree: Tree)(implicit ctx: Context): SharedTree = + def SharedTree(tree: Tree)(implicit ctx: Context): SharedTree = Trees.SharedTree(tree).withType(tree.tpe) diff --git a/src/dotty/tools/dotc/ast/UntypedTrees.scala b/src/dotty/tools/dotc/ast/UntypedTrees.scala index f8a03385e..22e8ab56e 100644 --- a/src/dotty/tools/dotc/ast/UntypedTrees.scala +++ b/src/dotty/tools/dotc/ast/UntypedTrees.scala @@ -4,7 +4,7 @@ package ast import core._ import util.Positions._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._ -import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._ +import Denotations._, SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._ import Decorators._ import language.higherKinds import collection.mutable.ListBuffer @@ -45,18 +45,76 @@ object untpd extends Trees.Instance[Untyped] with TreeInfo[Untyped] { override def withName(name: Name)(implicit ctx: Context) = cpy.PolyTypeDef(this, mods, name.toTypeName, tparams, rhs) } -// ------ Additional creation methods for untyped only ----------------- + // ------ Creation methods for untyped only ----------------- - def Literal(const: Constant) = new Literal(const) + def Ident(name: Name): Ident = new Ident(name) + def BackquotedIdent(name: Name): BackquotedIdent = new BackquotedIdent(name) + def Select(qualifier: Tree, name: Name): Select = new Select(qualifier, name) + def SelectWithSig(qualifier: Tree, name: Name, sig: Signature): Select = new SelectWithSig(qualifier, name, sig) + def This(qual: TypeName): This = new This(qual) + def Super(qual: Tree, mix: TypeName): Super = new Super(qual, mix) + def Apply(fun: Tree, args: List[Tree]): Apply = new Apply(fun, args) + def TypeApply(fun: Tree, args: List[Tree]): TypeApply = new TypeApply(fun, args) + def Literal(const: Constant): Literal = new Literal(const) + def New(tpt: Tree): New = new New(tpt) + def Pair(left: Tree, right: Tree): Pair = new Pair(left, right) + def Typed(expr: Tree, tpt: Tree): Typed = new Typed(expr, tpt) + def NamedArg(name: Name, arg: Tree): NamedArg = new NamedArg(name, arg) + def Assign(lhs: Tree, rhs: Tree): Assign = new Assign(lhs, rhs) + def Block(stats: List[Tree], expr: Tree): Block = new Block(stats, expr) + def If(cond: Tree, thenp: Tree, elsep: Tree): If = new If(cond, thenp, elsep) + def Closure(env: List[Tree], meth: RefTree): Closure = new Closure(env, meth) + def Match(selector: Tree, cases: List[CaseDef]): Match = new Match(selector, cases) + def CaseDef(pat: Tree, guard: Tree, body: Tree): CaseDef = new CaseDef(pat, guard, body) + def Return(expr: Tree, from: Tree): Return = new Return(expr, from) + def Try(expr: Tree, handler: Tree, finalizer: Tree): Try = new Try(expr, handler, finalizer) + def Throw(expr: Tree): Throw = new Throw(expr) + def SeqLiteral(elems: List[Tree]): SeqLiteral = new SeqLiteral(elems) + def TypeTree(original: Tree): TypeTree = new TypeTree(original) + def TypeTree() = new TypeTree(EmptyTree) + def SingletonTypeTree(ref: Tree): SingletonTypeTree = new SingletonTypeTree(ref) + def SelectFromTypeTree(qualifier: Tree, name: Name): SelectFromTypeTree = new SelectFromTypeTree(qualifier, name) + def AndTypeTree(left: Tree, right: Tree): AndTypeTree = new AndTypeTree(left, right) + def OrTypeTree(left: Tree, right: Tree): OrTypeTree = new OrTypeTree(left, right) + def RefinedTypeTree(tpt: Tree, refinements: List[Tree]): RefinedTypeTree = new RefinedTypeTree(tpt, refinements) + def AppliedTypeTree(tpt: Tree, args: List[Tree]): AppliedTypeTree = new AppliedTypeTree(tpt, args) + def TypeBoundsTree(lo: Tree, hi: Tree): TypeBoundsTree = new TypeBoundsTree(lo, hi) + def Bind(name: Name, body: Tree): Bind = new Bind(name, body) + def Alternative(trees: List[Tree]): Alternative = new Alternative(trees) + def UnApply(fun: Tree, args: List[Tree]): UnApply = new UnApply(fun, args) + def ValDef(mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree): ValDef = new ValDef(mods, name, tpt, rhs) + def DefDef(mods: Modifiers, name: TermName, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): DefDef = new DefDef(mods, name, tparams, vparamss, tpt, rhs) + def TypeDef(mods: Modifiers, name: TypeName, rhs: Tree): TypeDef = new TypeDef(mods, name, rhs) + def Template(constr: DefDef, parents: List[Tree], self: ValDef, body: List[Tree]): Template = new Template(constr, parents, self, body) + def Import(expr: Tree, selectors: List[untpd.Tree]): Import = new Import(expr, selectors) + def PackageDef(pid: RefTree, stats: List[Tree]): PackageDef = new PackageDef(pid, stats) + def Annotated(annot: Tree, arg: Tree): Annotated = new Annotated(annot, arg) + def SharedTree(shared: Tree): SharedTree = new SharedTree(shared) - def TypeTree(tpe: Type)(implicit ctx: Context): TypedSplice = TypedSplice(TypeTree().withType(tpe)) + // ------ Additional creation methods for untyped only ----------------- - def TypeDef(mods: Modifiers, name: TypeName, tparams: List[TypeDef], rhs: Tree)(implicit ctx: Context): TypeDef = - if (tparams.isEmpty) TypeDef(mods, name, rhs) else new PolyTypeDef(mods, name, tparams, rhs) + // def TypeTree(tpe: Type): TypeTree = TypeTree().withType(tpe) todo: move to untpd/tpd + + /** new tpt(args1)...(args_n) + */ + def New(tpt: Tree, argss: List[List[Tree]]): Tree = + ((Select(New(tpt), nme.CONSTRUCTOR): Tree) /: argss)(Apply(_, _)) + + def Block(stat: Tree, expr: Tree): Block = + Block(stat :: Nil, expr) + + def Apply(fn: Tree, arg: Tree): Apply = + Apply(fn, arg :: Nil) -// ------ Untyped tree values and creation methods --------------------- + def AppliedTypeTree(tpt: Tree, arg: Tree): AppliedTypeTree = + AppliedTypeTree(tpt, arg :: Nil) + + def TypeTree(tpe: Type): TypedSplice = TypedSplice(TypeTree().withType(tpe)) + + def TypeDef(mods: Modifiers, name: TypeName, tparams: List[TypeDef], rhs: Tree): TypeDef = + if (tparams.isEmpty) TypeDef(mods, name, rhs) else new PolyTypeDef(mods, name, tparams, rhs) - def unitLiteral(implicit ctx: Context) = Literal(Constant()) + def unitLiteral = Literal(Constant()) def ref(tp: NamedType)(implicit ctx: Context): Tree = TypedSplice(tpd.ref(tp)) |