aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/tpd.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-07-03 19:02:26 +0200
committerMartin Odersky <odersky@gmail.com>2014-07-17 11:02:00 +0200
commitdb88bf06958e33ae415ca227808ab1f3e48fed7f (patch)
treedef81047ef7f2bdf930e2a5561cfcd2403a61912 /src/dotty/tools/dotc/ast/tpd.scala
parentefe4f7e43652a303d16a5253f84316e547f45cca (diff)
downloaddotty-db88bf06958e33ae415ca227808ab1f3e48fed7f.tar.gz
dotty-db88bf06958e33ae415ca227808ab1f3e48fed7f.tar.bz2
dotty-db88bf06958e33ae415ca227808ab1f3e48fed7f.zip
Various cleanups and utility additions
- Some new functionality in tpd and in Symbols. - Added `sm` interpolator to print nicely. - Make use of nestedMap where possible. - Add IdentityDenotTransformer as a convencience class
Diffstat (limited to 'src/dotty/tools/dotc/ast/tpd.scala')
-rw-r--r--src/dotty/tools/dotc/ast/tpd.scala14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala
index 84e1118f9..f0151e1d3 100644
--- a/src/dotty/tools/dotc/ast/tpd.scala
+++ b/src/dotty/tools/dotc/ast/tpd.scala
@@ -204,11 +204,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
}
val (vparamss, rtp) = valueParamss(mtp)
val targs = tparams map (_.typeRef)
- val argss = vparamss map (_ map (vparam => Ident(vparam.termRef)))
+ val argss = vparamss.nestedMap(vparam => Ident(vparam.termRef))
ta.assignType(
untpd.DefDef(
Modifiers(sym), sym.name, tparams map TypeDef,
- vparamss map (_ map (ValDef(_))), TypeTree(rtp), rhsFn(targs)(argss)), sym)
+ vparamss.nestedMap(ValDef(_)), TypeTree(rtp), rhsFn(targs)(argss)), sym)
}
def TypeDef(sym: TypeSymbol)(implicit ctx: Context): TypeDef =
@@ -384,6 +384,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def changeOwner(from: Symbol, to: Symbol)(implicit ctx: Context): ThisTree =
new TreeTypeMap(ownerMap = (sym => if (sym == from) to else sym)).apply(tree)
+ def appliedToArg(arg: Tree)(implicit ctx: Context): Tree = appliedToArgs(arg :: Nil)
+
+ def appliedToArgs(args: List[Tree])(implicit ctx: Context): Tree =
+ if (args.isEmpty) tree else Apply(tree, args)
+
+ def appliedToArgss(argss: List[List[Tree]])(implicit ctx: Context): Tree =
+ ((tree: Tree) /: argss)(Apply(_, _))
+
def appliedToTypes(targs: List[Type])(implicit ctx: Context): Tree =
appliedToTypeTrees(targs map (TypeTree(_)))
@@ -395,7 +403,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def tpes: List[Type] = xs map (_.tpe)
}
- class TreeTypeMap(val typeMap: TypeMap = IdentityTypeMap, val ownerMap: Symbol => Symbol = identity _)(implicit ctx: Context) extends TreeMap {
+ class TreeTypeMap(val typeMap: Type => Type = IdentityTypeMap, val ownerMap: Symbol => Symbol = identity _)(implicit ctx: Context) extends TreeMap {
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = super.transform {
tree.withType(typeMap(tree.tpe)) match {
case bind: tpd.Bind =>