]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java
(refs #7375) Replace collectRefs by CollectRefsVisitor
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / EMatch.java
old mode 100755 (executable)
new mode 100644 (file)
index d1a96d0..0ca1d54
@@ -2,18 +2,17 @@ package org.simantics.scl.compiler.elaboration.expressions;
 
 import java.util.ArrayList;
 
+import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
-import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.internal.codegen.references.IVal;
 import org.simantics.scl.compiler.internal.codegen.ssa.exits.Throw;
 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
 import org.simantics.scl.compiler.internal.elaboration.matching.PatternMatchingCompiler;
 import org.simantics.scl.compiler.internal.elaboration.matching.Row;
-import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
 import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.kinds.Kinds;
@@ -42,43 +41,36 @@ public class EMatch extends Expression {
         this.cases = cases;
     }
 
-       public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+    @Override
+    public void collectVars(TObjectIntHashMap<Variable> allVars,
+            TIntHashSet vars) {
         for(Expression s : scrutinee)
-            s.collectRefs(allRefs, refs);
-        for(Case case_ : cases)
-            case_.collectRefs(allRefs, refs);
-    }
-       
-       @Override
-       public void collectVars(TObjectIntHashMap<Variable> allVars,
-               TIntHashSet vars) {
-           for(Expression s : scrutinee)
             s.collectVars(allVars, vars);
-           for(Case case_ : cases)
+        for(Case case_ : cases)
             case_.collectVars(allVars, vars);
-       }
-       
-       @Override
-       protected void updateType() {
-           setType(cases[0].value.getType());
-       }
+    }
 
-       @Override
-       public IVal toVal(Environment env, CodeWriter w) {
-           ArrayList<Row> rows = new ArrayList<Row>(cases.length);
-           for(Case case_ : cases)
-               rows.add(new Row(case_.patterns, case_.value));
-           
-           IVal[] scrutineeVals = new IVal[scrutinee.length];
-           for(int i=0;i<scrutinee.length;++i)
-               scrutineeVals[i] = scrutinee[i].toVal(env, w);
-           
-           CodeWriter joinPoint = w.createBlock(getType());
-           CodeWriter failurePoint = w.createBlock(); // TODO generate only one failurePoint per function
-           PatternMatchingCompiler.split(w, env, scrutineeVals, joinPoint.getContinuation(), failurePoint.getContinuation(), rows);
-           failurePoint.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());
-           w.continueAs(joinPoint);
-           return w.getParameters()[0];
+    @Override
+    protected void updateType() {
+        setType(cases[0].value.getType());
+    }
+
+    @Override
+    public IVal toVal(CompilationContext context, CodeWriter w) {
+        ArrayList<Row> rows = new ArrayList<Row>(cases.length);
+        for(Case case_ : cases)
+            rows.add(new Row(case_.patterns, case_.value));
+
+        IVal[] scrutineeVals = new IVal[scrutinee.length];
+        for(int i=0;i<scrutinee.length;++i)
+            scrutineeVals[i] = scrutinee[i].toVal(context, w);
+
+        CodeWriter joinPoint = w.createBlock(getType());
+        CodeWriter failurePoint = w.createBlock(); // TODO generate only one failurePoint per function
+        PatternMatchingCompiler.split(w, context, scrutineeVals, joinPoint.getContinuation(), failurePoint.getContinuation(), rows);
+        failurePoint.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());
+        w.continueAs(joinPoint);
+        return w.getParameters()[0];
     }
 
     @Override
@@ -164,15 +156,6 @@ public class EMatch extends Expression {
         return this;
     }
 
-    @Override
-    public Expression decorate(ExpressionDecorator decorator) {
-        for(int i=0;i<scrutinee.length;++i)
-            scrutinee[i] = scrutinee[i].decorate(decorator);
-        for(Case case_ : cases)
-            case_.decorate(decorator);
-        return decorator.decorate(this);
-    }
-
     @Override
     public void collectEffects(THashSet<Type> effects) {
         for(Expression s : scrutinee)
@@ -196,14 +179,6 @@ public class EMatch extends Expression {
     public Case[] getCases() {
         return cases;
     }
-
-    @Override
-    public void forVariables(VariableProcedure procedure) {
-        for(Expression s : scrutinee)
-            s.forVariables(procedure);
-        for(Case case_ : cases)
-            case_.forVariables(procedure);
-    }
     
     @Override
     public Expression accept(ExpressionTransformer transformer) {