summaryrefslogtreecommitdiff
path: root/sources/scalac/transformer/TransMatch.java
diff options
context:
space:
mode:
authorMatthias Zenger <mzenger@gmail.com>2003-08-29 15:10:31 +0000
committerMatthias Zenger <mzenger@gmail.com>2003-08-29 15:10:31 +0000
commit325b15e759799b5d5da72f00606e7d7875c211d8 (patch)
tree9c04750a1791fc157574e98499b46edb821bdb6b /sources/scalac/transformer/TransMatch.java
parent79b7bfc473ad18a2ff6efb5c3d10d22adb4f9f0e (diff)
downloadscala-325b15e759799b5d5da72f00606e7d7875c211d8.tar.gz
scala-325b15e759799b5d5da72f00606e7d7875c211d8.tar.bz2
scala-325b15e759799b5d5da72f00606e7d7875c211d8.zip
Cleaned up the pattern matcher.
Diffstat (limited to 'sources/scalac/transformer/TransMatch.java')
-rw-r--r--sources/scalac/transformer/TransMatch.java104
1 files changed, 49 insertions, 55 deletions
diff --git a/sources/scalac/transformer/TransMatch.java b/sources/scalac/transformer/TransMatch.java
index e558d88ce8..94f3ec3b31 100644
--- a/sources/scalac/transformer/TransMatch.java
+++ b/sources/scalac/transformer/TransMatch.java
@@ -32,49 +32,49 @@ public class TransMatch extends OwnerTransformer {
/** container. classes AlgebraicMatcher and SequenceMatcher get input and store their results in here.
* resembles the 'Memento' design pattern, could also be named 'Liaison'
*/
- public static class Matcher {
+ public static class Matcher {
- /** owner of the code we create (input)
- */
- public Symbol owner;
+ /** owner of the code we create (input)
+ */
+ public Symbol owner;
- /** the selector value (input)
- */
- public Tree selector;
+ /** the selector value (input)
+ */
+ public Tree selector;
- /** type of the result of the whole match (input)
- */
- public Type resultType;
+ /** type of the result of the whole match (input)
+ */
+ public Type resultType;
- /** tree representing the matcher (output)
- */
- public Tree tree;
+ /** tree representing the matcher (output)
+ */
+ public Tree tree;
- public int pos;
+ public int pos;
- public HashMap varMap; // needed in LeftTracerInScala
- public Tree[] stms; // needed in LeftTracerInScala
+ public HashMap varMap; // needed in LeftTracerInScala
+ public Tree[] stms; // needed in LeftTracerInScala
- public Matcher(Symbol owner,
- Tree root,
- Type resultType) {
+ public Matcher(Symbol owner,
+ Tree root,
+ Type resultType) {
- assert( owner != null ) : "owner is null";
- assert owner != Symbol.NONE ;
- this.owner = owner;
+ assert( owner != null ) : "owner is null";
+ assert owner != Symbol.NONE ;
+ this.owner = owner;
- assert root != null;
- assert root.type != null;
- this.selector = root;
+ assert root != null;
+ assert root.type != null;
+ this.selector = root;
- assert this.resultType != Type.NoType;
- this.resultType = resultType;
+ assert this.resultType != Type.NoType;
+ this.resultType = resultType;
- this.pos = root.pos; // for convenience only
+ this.pos = root.pos; // for convenience only
- }
+ }
- }
+ }
Unit unit;
@@ -93,31 +93,25 @@ public class TransMatch extends OwnerTransformer {
}
protected Tree transform(Tree root, CaseDef[] cases, Type restpe) {
- boolean containsReg = false;
- int i = 0;
- Matcher matcher;
-
- while(( !containsReg )&&( i < cases.length ))
- containsReg |= TestRegTraverser.apply( cases[ i++ ] );
-
- if( containsReg )
- {
- AlgebraicMatcher am = new AlgebraicMatcher( unit, infer );
- matcher = new Matcher( currentOwner, root, restpe );
- am.construct( matcher, cases );
- }
- else
- {
- PatternMatcher pm = new PatternMatcher( unit, infer );
- matcher = new Matcher( currentOwner, root, restpe );
-
- pm.construct( matcher, cases );
- if (global.log()) {
- global.log("internal pattern matching structure");
- pm.print();
- }
- }
- return matcher.tree;
+ boolean containsReg = false;
+ int i = 0;
+ while(!containsReg && (i < cases.length))
+ containsReg = TestRegTraverser.apply(cases[i++]);
+ if (containsReg) {
+ AlgebraicMatcher am = new AlgebraicMatcher( unit, infer );
+ Matcher matcher = new Matcher( currentOwner, root, restpe );
+ am.construct( matcher, cases );
+ return matcher.tree;
+ } else {
+ PatternMatcher pm = new PatternMatcher(unit, infer, root,
+ currentOwner, restpe);
+ pm.enter(cases);
+ if (global.log()) {
+ global.log("internal pattern matching structure");
+ pm.print();
+ }
+ return pm.toTree();
+ }
}
public Tree transform(Tree tree) {