From 563e00ffc7a4920c0cdfcd64c76ec46f44f8e23c Mon Sep 17 00:00:00 2001 From: buraq Date: Tue, 17 Jun 2003 12:48:47 +0000 Subject: introduced inner class "Matcher" --- sources/scalac/transformer/TransMatch.java | 56 +++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/sources/scalac/transformer/TransMatch.java b/sources/scalac/transformer/TransMatch.java index ab3182c50e..57be549592 100644 --- a/sources/scalac/transformer/TransMatch.java +++ b/sources/scalac/transformer/TransMatch.java @@ -29,6 +29,53 @@ public class TransMatch extends OwnerTransformer { public static final Name MATCH_N = Name.fromString("match"); + /** 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 { + + /** owner of the code we create (input) + */ + public Symbol owner; + + /** the selector value (input) + */ + public Tree selector; + + /** type of the result of the whole match (input) + */ + public Type resultType; + + /** tree representing the matcher (output) + */ + public Tree tree; + + public int pos; + + //public HashMap varMap; + //public Tree[] stms; + + public Matcher(Symbol owner, + Tree root, + Type resultType) { + + assert( owner != null ) : "owner is null"; + assert owner != Symbol.NONE ; + this.owner = owner; + + assert root != null; + assert root.type != null; + this.selector = root; + + assert this.resultType != Type.NoType; + this.resultType = resultType; + + this.pos = root.pos; // for convenience only + + } + + } + Unit unit; /** type inference engine @@ -46,14 +93,15 @@ public class TransMatch extends OwnerTransformer { } protected Tree transform(Tree root, CaseDef[] cases, Type restpe) { - PatternMatcher pm = new PatternMatcher(unit, infer, currentOwner, root, restpe); - for (int i = 0; i < cases.length; i++) - pm.enter(cases[i]); + PatternMatcher pm = new PatternMatcher( unit, infer ); + Matcher matcher = new Matcher( currentOwner, root, restpe ); + + pm.construct( matcher, cases ); if (global.log()) { global.log("internal pattern matching structure"); pm.print(); } - return pm.toTree(); + return matcher.tree; } public Tree transform(Tree tree) { -- cgit v1.2.3