summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorVladimirNik <vladimir.nikolaev9@gmail.com>2014-02-14 23:39:30 +0400
committerVladimirNik <vladimir.nikolaev9@gmail.com>2014-02-20 01:23:26 +0400
commit81e7caa3c930987a589ad070022444bc4b163de1 (patch)
tree18de5bf5223203c5bf83ced837e7fc50b09db30c /src/reflect
parent109774b0ba8f088c4b4ae503df66a23ce0869cba (diff)
downloadscala-81e7caa3c930987a589ad070022444bc4b163de1.tar.gz
scala-81e7caa3c930987a589ad070022444bc4b163de1.tar.bz2
scala-81e7caa3c930987a589ad070022444bc4b163de1.zip
move methods for typechecked trees processing to TreeInfo
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Printers.scala6
-rw-r--r--src/reflect/scala/reflect/internal/ReificationSupport.scala60
-rw-r--r--src/reflect/scala/reflect/internal/TreeInfo.scala61
3 files changed, 65 insertions, 62 deletions
diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala
index a45b401902..5aea8354b0 100644
--- a/src/reflect/scala/reflect/internal/Printers.scala
+++ b/src/reflect/scala/reflect/internal/Printers.scala
@@ -830,7 +830,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
printImport(imp, resolveSelect(expr))
case t @ Template(parents, self, tbody) =>
- val body = build.unattributedTemplBody(t)
+ val body = treeInfo.untypecheckedTemplBody(t)
val printedParents =
currentParent map {
case _: CompoundTypeTree => parents
@@ -900,7 +900,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
}
case bl @ Block(stats, expr) =>
- printBlock(build.unattributedBlockBody(bl), expr)
+ printBlock(treeInfo.untypecheckedBlockBody(bl), expr)
case Match(selector, cases) =>
/* Insert braces if match is inner
@@ -995,7 +995,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
if (tree.hasExistingSymbol && tree.symbol.isPackage) print(tree.symbol.fullName)
else printThis(th, printedName(qual))
- // remove this.this from constructor invocation
+ // remove this prefix from constructor invocation in typechecked trees: this.this -> this
case Select(This(_), name @ nme.CONSTRUCTOR) => print(printedName(name))
case Select(qual: New, name) =>
diff --git a/src/reflect/scala/reflect/internal/ReificationSupport.scala b/src/reflect/scala/reflect/internal/ReificationSupport.scala
index 375605bf7f..7ce3f3d7f5 100644
--- a/src/reflect/scala/reflect/internal/ReificationSupport.scala
+++ b/src/reflect/scala/reflect/internal/ReificationSupport.scala
@@ -233,70 +233,12 @@ trait ReificationSupport { self: SymbolTable =>
case _ => None
}
}
-
- private[internal] def detectAttributedTree(tree: Tree) =
- tree.hasExistingSymbol || tree.exists {
- case dd: DefDef => dd.mods.hasAccessorFlag || dd.mods.isSynthetic // for untypechecked trees
- case md: MemberDef => md.hasExistingSymbol
- case _ => false
- }
-
- private[internal] def unattributedTemplBody(templ: Template) =
- unattributedTreeBody(templ, templ.body)
-
- private[internal] def unattributedBlockBody(block: Block) =
- unattributedTreeBody(block, block.stats)
-
- // recover template body to parsed state
- private[internal] def unattributedTreeBody(tree: Tree, tbody: List[Tree]) = {
- def filterBody(body: List[Tree]) = body filter {
- case _: ValDef | _: TypeDef => true
- // keep valdef or getter for val/var
- case dd: DefDef if dd.mods.hasAccessorFlag => !nme.isSetterName(dd.name) && !tbody.exists{
- case vd: ValDef => dd.name == vd.name.dropLocal
- case _ => false
- }
- case md: MemberDef => !md.mods.isSynthetic
- case tree => true
- }
-
- def lazyValDefRhs(body: Tree) =
- body match {
- case Block(List(Assign(_, rhs)), _) => rhs
- case _ => body
- }
-
- def recoverBody(body: List[Tree]) = body map {
- case vd @ ValDef(vmods, vname, _, vrhs) if nme.isLocalName(vname) =>
- tbody find {
- case dd: DefDef => dd.name == vname.dropLocal
- case _ => false
- } map { dd =>
- val DefDef(dmods, dname, _, _, _, drhs) = dd
- // get access flags from DefDef
- val vdMods = (vmods &~ Flags.AccessFlags) | (dmods & Flags.AccessFlags).flags
- // for most cases lazy body should be taken from accessor DefDef
- val vdRhs = if (vmods.isLazy) lazyValDefRhs(drhs) else vrhs
- copyValDef(vd)(mods = vdMods, name = dname, rhs = vdRhs)
- } getOrElse (vd)
- // for abstract and some lazy val/vars
- case dd @ DefDef(mods, name, _, _, tpt, rhs) if mods.hasAccessorFlag =>
- // transform getter mods to field
- val vdMods = (if (!mods.hasStableFlag) mods | Flags.MUTABLE else mods &~ Flags.STABLE) &~ Flags.ACCESSOR
- ValDef(vdMods, name, tpt, rhs)
- case tree => tree
- }
-
- if (detectAttributedTree(tree)) {
- recoverBody(filterBody(tbody))
- } else tbody
- }
// undo gen.mkTemplate
protected object UnMkTemplate {
def unapply(templ: Template): Option[(List[Tree], ValDef, Modifiers, List[List[ValDef]], List[Tree], List[Tree])] = {
val Template(parents, selfType, _) = templ
- val tbody = unattributedTemplBody(templ)
+ val tbody = treeInfo.untypecheckedTemplBody(templ)
def result(ctorMods: Modifiers, vparamss: List[List[ValDef]], edefs: List[Tree], body: List[Tree]) =
Some((parents, selfType, ctorMods, vparamss, edefs, body))
diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala
index b7df2e82cb..b52ff2da04 100644
--- a/src/reflect/scala/reflect/internal/TreeInfo.scala
+++ b/src/reflect/scala/reflect/internal/TreeInfo.scala
@@ -405,6 +405,67 @@ abstract class TreeInfo {
case _ => false
}
+ /** Does the tree have a structure similar to typechecked trees? */
+ private[internal] def detectTypecheckedTree(tree: Tree) =
+ tree.hasExistingSymbol || tree.exists {
+ case dd: DefDef => dd.mods.hasAccessorFlag || dd.mods.isSynthetic // for untypechecked trees
+ case md: MemberDef => md.hasExistingSymbol
+ case _ => false
+ }
+
+ /** Recover template body to parsed state */
+ private[internal] def untypecheckedTemplBody(templ: Template) =
+ untypecheckedTreeBody(templ, templ.body)
+
+ /** Recover block body to parsed state */
+ private[internal] def untypecheckedBlockBody(block: Block) =
+ untypecheckedTreeBody(block, block.stats)
+
+ /** Recover tree body to parsed state */
+ private[internal] def untypecheckedTreeBody(tree: Tree, tbody: List[Tree]) = {
+ def filterBody(body: List[Tree]) = body filter {
+ case _: ValDef | _: TypeDef => true
+ // keep valdef or getter for val/var
+ case dd: DefDef if dd.mods.hasAccessorFlag => !nme.isSetterName(dd.name) && !tbody.exists {
+ case vd: ValDef => dd.name == vd.name.dropLocal
+ case _ => false
+ }
+ case md: MemberDef => !md.mods.isSynthetic
+ case tree => true
+ }
+
+ def lazyValDefRhs(body: Tree) =
+ body match {
+ case Block(List(Assign(_, rhs)), _) => rhs
+ case _ => body
+ }
+
+ def recoverBody(body: List[Tree]) = body map {
+ case vd @ ValDef(vmods, vname, _, vrhs) if nme.isLocalName(vname) =>
+ tbody find {
+ case dd: DefDef => dd.name == vname.dropLocal
+ case _ => false
+ } map { dd =>
+ val DefDef(dmods, dname, _, _, _, drhs) = dd
+ // get access flags from DefDef
+ val vdMods = (vmods &~ Flags.AccessFlags) | (dmods & Flags.AccessFlags).flags
+ // for most cases lazy body should be taken from accessor DefDef
+ val vdRhs = if (vmods.isLazy) lazyValDefRhs(drhs) else vrhs
+ copyValDef(vd)(mods = vdMods, name = dname, rhs = vdRhs)
+ } getOrElse (vd)
+ // for abstract and some lazy val/vars
+ case dd @ DefDef(mods, name, _, _, tpt, rhs) if mods.hasAccessorFlag =>
+ // transform getter mods to field
+ val vdMods = (if (!mods.hasStableFlag) mods | Flags.MUTABLE else mods &~ Flags.STABLE) &~ Flags.ACCESSOR
+ ValDef(vdMods, name, tpt, rhs)
+ case tree => tree
+ }
+
+ if (detectTypecheckedTree(tree)) {
+ recoverBody(filterBody(tbody))
+ } else tbody
+ }
+
/** The first constructor definitions in `stats` */
def firstConstructor(stats: List[Tree]): Tree = stats find {
case x: DefDef => nme.isConstructorName(x.name)