summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorFrançois Garillot <francois@garillot.net>2013-09-24 10:21:10 +0200
committerFrançois Garillot <francois@garillot.net>2013-09-24 10:21:10 +0200
commit710401d8aec814d95b25ca2104036aa414a5db35 (patch)
treee6374925f1719b65ceb51202aacfb6257754ff6f /src/reflect
parent7d570b54c3c895bc8948adeca2e463d135e38feb (diff)
downloadscala-710401d8aec814d95b25ca2104036aa414a5db35.tar.gz
scala-710401d8aec814d95b25ca2104036aa414a5db35.tar.bz2
scala-710401d8aec814d95b25ca2104036aa414a5db35.zip
Revert "Merge pull request #2957 from paulp/pr/parser-improvements"
This reverts commit 884e1ce762d98b29594146d37b85384581d9ba96, reversing changes made to f6fcc4431f272c707d49de68add532c452dd4b0f.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/TreeGen.scala67
-rw-r--r--src/reflect/scala/reflect/internal/TreeInfo.scala7
-rw-r--r--src/reflect/scala/reflect/internal/util/Position.scala5
3 files changed, 41 insertions, 38 deletions
diff --git a/src/reflect/scala/reflect/internal/TreeGen.scala b/src/reflect/scala/reflect/internal/TreeGen.scala
index a9f2807e9f..c8ae4df13d 100644
--- a/src/reflect/scala/reflect/internal/TreeGen.scala
+++ b/src/reflect/scala/reflect/internal/TreeGen.scala
@@ -280,7 +280,7 @@ abstract class TreeGen extends macros.TreeBuilder {
/** Builds a tuple */
def mkTuple(elems: List[Tree]): Tree =
- if (elems.isEmpty) mkUnit()
+ if (elems.isEmpty) Literal(Constant(()))
else Apply(
Select(mkAttributedRef(TupleClass(elems.length).caseModule), nme.apply),
elems)
@@ -326,7 +326,8 @@ abstract class TreeGen extends macros.TreeBuilder {
* body
* }
*/
- def mkTemplate(parents: List[Tree], self: ValDef, constrMods: Modifiers, vparamss: List[List[ValDef]], body: List[Tree], superPos: Position = NoPosition): Template = {
+ def mkTemplate(parents: List[Tree], self: ValDef, constrMods: Modifiers,
+ vparamss: List[List[ValDef]], body: List[Tree], superPos: Position = NoPosition): Template = {
/* Add constructor to template */
// create parameters for <init> as synthetic trees.
@@ -397,42 +398,52 @@ abstract class TreeGen extends macros.TreeBuilder {
* @param npos the position of the new
* @param cpos the position of the anonymous class starting with parents
*/
- def mkNew(parents: List[Tree], self: ValDef, stats: List[Tree], npos: Position, cpos: Position): Tree = {
- def enclosingPos = wrappingPos(cpos, parents ::: List(self) ::: stats)
- def upos = cpos union npos
- def anonTemplate = atPos(cpos)(mkTemplate(parents, self, NoMods, ListOfNil, stats, cpos))
- def anonClass = atPos(anonTemplate.pos.makeTransparent)(ClassDef(Modifiers(FINAL), tpnme.ANON_CLASS_NAME, Nil, anonTemplate))
- def anonNew = atPos(npos)(New(Ident(tpnme.ANON_CLASS_NAME) setPos cpos.focus, Nil))
-
- // `Parsers.template` no longer differentiates tpts and their argss
- // e.g. `C()` will be represented as a single tree Apply(Ident(C), Nil)
- // instead of parents = Ident(C), argss = Nil as before
- // this change works great for things that are actually templates
- // but in this degenerate case we need to perform postprocessing
- parents match {
- case Nil => mkNew(List(scalaAnyRefConstr), self, stats, npos, cpos)
- case treeInfo.AppliedArgs(callee, argss) :: Nil if stats.isEmpty => atPos(upos)(New(callee, argss))
- case _ => atPos(upos)(mkBlock(anonClass :: anonNew :: Nil))
+ def mkNew(parents: List[Tree], self: ValDef, stats: List[Tree],
+ npos: Position, cpos: Position): Tree =
+ if (parents.isEmpty)
+ mkNew(List(scalaAnyRefConstr), self, stats, npos, cpos)
+ else if (parents.tail.isEmpty && stats.isEmpty) {
+ // `Parsers.template` no longer differentiates tpts and their argss
+ // e.g. `C()` will be represented as a single tree Apply(Ident(C), Nil)
+ // instead of parents = Ident(C), argss = Nil as before
+ // this change works great for things that are actually templates
+ // but in this degenerate case we need to perform postprocessing
+ val app = treeInfo.dissectApplied(parents.head)
+ atPos(npos union cpos) { New(app.callee, app.argss) }
+ } else {
+ val x = tpnme.ANON_CLASS_NAME
+ atPos(npos union cpos) {
+ Block(
+ List(
+ atPos(cpos) {
+ ClassDef(
+ Modifiers(FINAL), x, Nil,
+ mkTemplate(parents, self, NoMods, ListOfNil, stats, cpos.focus))
+ }),
+ atPos(npos) {
+ New(
+ Ident(x) setPos npos.focus,
+ Nil)
+ }
+ )
+ }
}
- }
/** Create a tree representing the function type (argtpes) => restpe */
def mkFunctionTypeTree(argtpes: List[Tree], restpe: Tree): Tree =
AppliedTypeTree(rootScalaDot(newTypeName("Function" + argtpes.length)), argtpes ::: List(restpe))
- def mkUnit() = Literal(Constant(()))
-
/** Create block of statements `stats` */
- def mkBlock(stats: List[Tree]): Tree = stats match {
- case stats if stats.isEmpty || !stats.last.isTerm => mkBlock(stats :+ mkUnit())
- case stat :: Nil => stat
- case stats => Block(stats.init, stats.last)
- }
+ def mkBlock(stats: List[Tree]): Tree =
+ if (stats.isEmpty) Literal(Constant(()))
+ else if (!stats.last.isTerm) Block(stats, Literal(Constant(())))
+ else if (stats.length == 1) stats.head
+ else Block(stats.init, stats.last)
def mkTreeOrBlock(stats: List[Tree]) = stats match {
- case Nil => EmptyTree
+ case Nil => EmptyTree
case head :: Nil => head
- case _ => gen.mkBlock(stats)
+ case _ => gen.mkBlock(stats)
}
/** Create a tree representing an assignment <lhs = rhs> */
diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala
index 1b763b8632..34fe0afb1a 100644
--- a/src/reflect/scala/reflect/internal/TreeInfo.scala
+++ b/src/reflect/scala/reflect/internal/TreeInfo.scala
@@ -773,13 +773,6 @@ abstract class TreeInfo {
unapply(dissectApplied(tree))
}
- object AppliedArgs {
- def unapply(tree: Tree): Some[(Tree, List[List[Tree]])] = tree match {
- case Apply(AppliedArgs(fn, argss), args) => Some((fn, argss :+ args))
- case _ => Some((tree, Nil))
- }
- }
-
/** Locates the synthetic Apply node corresponding to an extractor's call to
* unapply (unwrapping nested Applies) and returns the fun part of that Apply.
*/
diff --git a/src/reflect/scala/reflect/internal/util/Position.scala b/src/reflect/scala/reflect/internal/util/Position.scala
index d62ab40a9d..8e7df28167 100644
--- a/src/reflect/scala/reflect/internal/util/Position.scala
+++ b/src/reflect/scala/reflect/internal/util/Position.scala
@@ -197,11 +197,10 @@ private[util] trait InternalPositionImpl {
}
def showDebug: String = toString
def show = (
- if (isOpaqueRange && start != point) s"[$point/$start:$end]"
- else if (isOpaqueRange) s"[$start:$end]"
+ if (isOpaqueRange) s"[$start:$end]"
else if (isTransparent) s"<$start:$end>"
else if (isDefined) s"[$point]"
- else "[X]"
+ else "[NoPosition]"
)
private def asOffset(point: Int): Position = Position.offset(source, point)