summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2005-05-27 12:52:10 +0000
committerMartin Odersky <odersky@gmail.com>2005-05-27 12:52:10 +0000
commitce836de569deb5443bf90ae28baf7be16c49d5ac (patch)
treed45f74574a7fd3099c8dc203d601b7f69d2f2fce /sources
parent8c6e72f8ea83c5942d102ac3be29edc3d1e6d644 (diff)
downloadscala-ce836de569deb5443bf90ae28baf7be16c49d5ac.tar.gz
scala-ce836de569deb5443bf90ae28baf7be16c49d5ac.tar.bz2
scala-ce836de569deb5443bf90ae28baf7be16c49d5ac.zip
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/nsc/ast/TreeInfo.scala1
-rw-r--r--sources/scala/tools/nsc/ast/TreePrinters.scala3
-rw-r--r--sources/scala/tools/nsc/ast/Trees.scala17
-rwxr-xr-xsources/scala/tools/nsc/ast/parser/Parsers.scala2
-rw-r--r--sources/scala/tools/nsc/ast/parser/TreeBuilder.scala31
-rwxr-xr-xsources/scala/tools/nsc/typechecker/Typers.scala11
6 files changed, 35 insertions, 30 deletions
diff --git a/sources/scala/tools/nsc/ast/TreeInfo.scala b/sources/scala/tools/nsc/ast/TreeInfo.scala
index 249f68f0e0..f58908e246 100644
--- a/sources/scala/tools/nsc/ast/TreeInfo.scala
+++ b/sources/scala/tools/nsc/ast/TreeInfo.scala
@@ -138,6 +138,7 @@ abstract class TreeInfo {
def isSequenceValued(tree: Tree): boolean = tree match {
case Bind(_, body) => isSequenceValued(body)
case Sequence(_) => true
+ case Star(_) => true
case Alternative(ts) => ts exists isSequenceValued
case _ => false
}
diff --git a/sources/scala/tools/nsc/ast/TreePrinters.scala b/sources/scala/tools/nsc/ast/TreePrinters.scala
index 96aa8b26dc..20d77d7c64 100644
--- a/sources/scala/tools/nsc/ast/TreePrinters.scala
+++ b/sources/scala/tools/nsc/ast/TreePrinters.scala
@@ -164,6 +164,9 @@ abstract class TreePrinters {
case Alternative(trees) =>
printRow(trees, "(", "| ", ")")
+ case Star(elem) =>
+ print("("); print(elem); print(")*");
+
case Bind(name, t) =>
print("("); print(symName(tree, name)); print(" @ "); print(t); print(")");
diff --git a/sources/scala/tools/nsc/ast/Trees.scala b/sources/scala/tools/nsc/ast/Trees.scala
index 1e03eab863..6a8ce585e8 100644
--- a/sources/scala/tools/nsc/ast/Trees.scala
+++ b/sources/scala/tools/nsc/ast/Trees.scala
@@ -234,6 +234,10 @@ abstract class Trees: Global {
case class Alternative(trees: List[Tree])
extends TermTree;
+ /** Repetition of pattern, eliminated by TransMatch */
+ case class Star(elem: Tree)
+ extends TermTree;
+
/** Bind of a variable to a rhs pattern, eliminated by TransMatch */
case class Bind(name: Name, body: Tree)
extends DefTree;
@@ -377,6 +381,7 @@ abstract class Trees: Global {
case CaseDef(pat, guard, body) => (eliminated by transmatch)
case Sequence(trees) => (eliminated by transmatch)
case Alternative(trees) => (eliminated by transmatch)
+ case Star(elem) => (eliminated by transmatch)
case Bind(name, body) => (eliminated by transmatch)
case Function(vparams, body) => (eliminated by typecheck)
case Assign(lhs, rhs) =>
@@ -418,6 +423,7 @@ abstract class Trees: Global {
def CaseDef(tree: Tree, pat: Tree, guard: Tree, body: Tree): CaseDef;
def Sequence(tree: Tree, trees: List[Tree]): Sequence;
def Alternative(tree: Tree, trees: List[Tree]): Alternative;
+ def Star(tree: Tree, elem: Tree): Star;
def Bind(tree: Tree, name: Name, body: Tree): Bind;
def Function(tree: Tree, vparams: List[ValDef], body: Tree): Function;
def Assign(tree: Tree, lhs: Tree, rhs: Tree): Assign;
@@ -475,6 +481,8 @@ abstract class Trees: Global {
new Sequence(trees).copyAttrs(tree);
def Alternative(tree: Tree, trees: List[Tree]) =
new Alternative(trees).copyAttrs(tree);
+ def Star(tree: Tree, elem: Tree) =
+ new Star(elem).copyAttrs(tree);
def Bind(tree: Tree, name: Name, body: Tree) =
new Bind(name, body).copyAttrs(tree);
def Function(tree: Tree, vparams: List[ValDef], body: Tree) =
@@ -603,6 +611,11 @@ abstract class Trees: Global {
if ((trees0 == trees)) => t
case _ => copy.Alternative(tree, trees)
}
+ def Star(tree: Tree, elem: Tree) = tree match {
+ case t @ Star(elem0)
+ if ((elem0 == elem)) => t
+ case _ => copy.Star(tree, elem)
+ }
def Bind(tree: Tree, name: Name, body: Tree) = tree match {
case t @ Bind(name0, body0)
if ((name0 == name) && (body0 == body)) => t
@@ -767,6 +780,8 @@ abstract class Trees: Global {
copy.Sequence(tree, transformTrees(trees))
case Alternative(trees) =>
copy.Alternative(tree, transformTrees(trees))
+ case Star(elem) =>
+ copy.Star(tree, transform(elem))
case Bind(name, body) =>
copy.Bind(tree, name, transform(body))
case Function(vparams, body) =>
@@ -891,6 +906,8 @@ abstract class Trees: Global {
traverseTrees(trees)
case Alternative(trees) =>
traverseTrees(trees)
+ case Star(elem) =>
+ traverse(elem)
case Bind(name, body) =>
traverse(body)
case Function(vparams, body) =>
diff --git a/sources/scala/tools/nsc/ast/parser/Parsers.scala b/sources/scala/tools/nsc/ast/parser/Parsers.scala
index b104a0e819..e62c204b72 100755
--- a/sources/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/sources/scala/tools/nsc/ast/parser/Parsers.scala
@@ -974,7 +974,7 @@ abstract class Parsers: ParserPhase {
var top = simplePattern(seqOK);
if (seqOK && in.token == IDENTIFIER) {
if (in.name == STAR)
- return atPos(in.skipToken())(makeStar(top))
+ return atPos(in.skipToken())(Star(top))
else if (in.name == PLUS)
return atPos(in.skipToken())(makePlus(top))
else if (in.name == OPT)
diff --git a/sources/scala/tools/nsc/ast/parser/TreeBuilder.scala b/sources/scala/tools/nsc/ast/parser/TreeBuilder.scala
index 33215db36b..70b31cd2f6 100644
--- a/sources/scala/tools/nsc/ast/parser/TreeBuilder.scala
+++ b/sources/scala/tools/nsc/ast/parser/TreeBuilder.scala
@@ -19,9 +19,8 @@ abstract class TreeBuilder {
def freshName(): Name = freshName("x$");
private object patvarTransformer extends Transformer {
- private var boundVars: List[Name] = List(nme.WILDCARD);
override def transform(tree: Tree): Tree = tree match {
- case Ident(name) if (treeInfo.isVariableName(name) && !(boundVars exists (name.==))) =>
+ case Ident(name) if (treeInfo.isVariableName(name)) =>
atPos(tree.pos)(Bind(name, Ident(nme.WILDCARD)))
case Typed(id @ Ident(name), tpt) =>
Bind(name, atPos(tree.pos)(Typed(Ident(nme.WILDCARD), tpt))) setPos id.pos
@@ -32,11 +31,8 @@ abstract class TreeBuilder {
case Typed(expr, tpt) =>
copy.Typed(tree, transform(expr), tpt)
case Bind(name, body) =>
- boundVars = name :: boundVars;
- val body1 = transform(body);
- boundVars = boundVars.tail;
- copy.Bind(tree, name, body1)
- case Se quence(_) | Alternative(_) =>
+ copy.Bind(tree, name, transform(body))
+ case Sequence(_) | Alternative(_) | Star(_) =>
super.transform(tree)
case _ =>
tree
@@ -49,7 +45,7 @@ abstract class TreeBuilder {
def init: Traverser = { buf.clear; this }
override def traverse(tree: Tree): unit = tree match {
case Bind(name, tpe) =>
- if (buf.elements forall (name !=)) buf += name;
+ if ((name != nme.WILDCARD) && (buf.elements forall (name !=))) buf += name;
traverse(tpe)
case _ => super.traverse(tree)
}
@@ -211,22 +207,9 @@ abstract class TreeBuilder {
Sequence(for (val t <- ts; val e <- elements(t)) yield e)
}
- /** Create tree for the p* regex pattern, becomes z@( |(p,z)) */
- def makeStar(p: Tree): Tree = {
- val zname = freshName();
- Bind(zname,
- makeAlternative(List(
- Sequence(List()),
- makeSequence(List(p, Ident(zname))))))
- }
-
- /** Create tree for the p+ regex pattern, becomes z@(p,(z| )) */
- def makePlus(p: Tree): Tree = {
- val zname = freshName();
- Bind(zname,
- makeSequence(List(
- p, makeAlternative(List(Ident(zname), Sequence(List()))))))
- }
+ /** Create tree for the p+ regex pattern, becomes p p* */
+ def makePlus(p: Tree): Tree =
+ makeSequence(List(p, Star(p.duplicate)));
/** Create tree for the p? regex pattern, becomes (p| ) */
def makeOpt(p: Tree): Tree =
diff --git a/sources/scala/tools/nsc/typechecker/Typers.scala b/sources/scala/tools/nsc/typechecker/Typers.scala
index b5dbaab136..07cc5f37cc 100755
--- a/sources/scala/tools/nsc/typechecker/Typers.scala
+++ b/sources/scala/tools/nsc/typechecker/Typers.scala
@@ -897,15 +897,16 @@ abstract class Typers: Analyzer {
val alts1 = List.mapConserve(alts)(alt => typed(alt, mode, pt));
copy.Alternative(tree, alts1) setType pt
+ case Star(elem) =>
+ val elem1 = typed(elem, mode, pt);
+ copy.Star(tree, elem1) setType pt
+
case Bind(name, body) =>
var vble = tree.symbol;
- if (vble == NoSymbol) {
- vble = context.owner.newValue(tree.pos, name);
- if (vble.name != nme.WILDCARD) namer.enterInScope(vble);
- }
- vble.setInfo(pt);
+ if (vble == NoSymbol) vble = context.owner.newValue(tree.pos, name);
val body1 = typed(body, mode, pt);
vble.setInfo(if (treeInfo.isSequenceValued(body)) seqType(body1.tpe) else body1.tpe);
+ if (vble.name != nme.WILDCARD) namer.enterInScope(vble);
copy.Bind(tree, name, body1) setSymbol vble setType pt
case fun @ Function(_, _) =>