Skip to content

Commit

Permalink
Cleaned up the pattern matcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Zenger committed Aug 29, 2003
1 parent 79b7bfc commit 325b15e
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 278 deletions.
104 changes: 49 additions & 55 deletions sources/scalac/transformer/TransMatch.java
Expand Up @@ -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;

Expand All @@ -93,31 +93,25 @@ public void apply(Unit unit) {
}

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) {
Expand Down

0 comments on commit 325b15e

Please sign in to comment.