]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/GuardedExpressionGroup.java
(refs #7375) Replaced collectVars method by a visitor
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / GuardedExpressionGroup.java
index 890d11f8c7a2dc084611786332159f4a3ec48dd5..48283a887a2dc883ded12c0632faf800d434b097 100644 (file)
@@ -1,24 +1,19 @@
 package org.simantics.scl.compiler.elaboration.expressions;
 
+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.continuations.ICont;
 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.utils.ExpressionDecorator;
 import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
 public class GuardedExpressionGroup extends Expression {
     public GuardedExpression[] expressions;
 
@@ -26,52 +21,23 @@ public class GuardedExpressionGroup extends Expression {
         this.expressions = expressions;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-        for(GuardedExpression expression : expressions) {
-            for(Expression guard : expression.guards)
-                guard.collectRefs(allRefs, refs);
-            expression.value.collectRefs(allRefs, refs);
-        }
-    }
-
-    @Override
-    public void collectVars(TObjectIntHashMap<Variable> allVars,
-            TIntHashSet vars) {
-        for(GuardedExpression expression : expressions) {
-            for(Expression guard : expression.guards)
-                guard.collectVars(allVars, vars);
-            expression.value.collectVars(allVars, vars);
-        }
-    }
-
     @Override
     protected void updateType() throws MatchException {
         setType(expressions[0].value.getType());
     }
 
     @Override
-    public IVal toVal(Environment env, CodeWriter w) {
+    public IVal toVal(CompilationContext context, CodeWriter w) {
         CodeWriter success = w.createBlock(getType());
         IVal result = success.getParameters()[0];
         CodeWriter failure = w.createBlock();
-        compile(env, w, success.getContinuation(), failure.getContinuation());
+        compile(context, w, success.getContinuation(), failure.getContinuation());
         w.continueAs(success);
         failure.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());
         return result;
         //throw new InternalCompilerError("GuardedExpressionGroup should be handled in match compilation.");
     }
 
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        for(GuardedExpression expression : expressions) {
-            for(Expression guard : expression.guards)
-                guard.collectFreeVariables(vars);
-            expression.value.collectFreeVariables(vars);
-        }
-    }
-
     @Override
     public Expression simplify(SimplificationContext context) {
         for(GuardedExpression expression : expressions) {
@@ -102,7 +68,7 @@ public class GuardedExpressionGroup extends Expression {
         return this;
     }
     
-    public void compile(Environment env, CodeWriter firstWriter, ICont success,
+    public void compile(CompilationContext context, CodeWriter firstWriter, ICont success,
             ICont lastFailure) {
         // Create all code blocks
         CodeWriter[] writers = new CodeWriter[expressions.length];                
@@ -122,11 +88,11 @@ public class GuardedExpressionGroup extends Expression {
             
             for(Expression guard : expressions[i].guards) {
                 CodeWriter nextW = w.createBlock();
-                w.if_(guard.toVal(env, w), nextW.getContinuation(), failure);
+                w.if_(guard.toVal(context, w), nextW.getContinuation(), failure);
                 w = nextW;
             }
             
-            w.jump(success, expressions[i].value.toVal(env, w));
+            w.jump(success, expressions[i].value.toVal(context, w));
         }
     }
     
@@ -137,22 +103,6 @@ public class GuardedExpressionGroup extends Expression {
             newExpressions[i] = expressions[i].replace(context);
         return new GuardedExpressionGroup(newExpressions);            
     }
-
-    @Override
-    public Expression decorate(ExpressionDecorator decorator) {
-        for(GuardedExpression expression : expressions)
-            expression.decorate(decorator);
-        return decorator.decorate(this);
-    }
-
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        for(GuardedExpression ge : expressions) {
-            for(Expression guard : ge.guards)
-                guard.collectEffects(effects);
-            ge.value.collectEffects(effects);
-        }
-    }
     
     @Override
     public void setLocationDeep(long loc) {
@@ -168,12 +118,6 @@ public class GuardedExpressionGroup extends Expression {
         visitor.visit(this);
     }
 
-    @Override
-    public void forVariables(VariableProcedure procedure) {
-        for(GuardedExpression expression : expressions)
-            expression.forVariables(procedure);
-    }
-
     @Override
     public Expression accept(ExpressionTransformer transformer) {
         return transformer.transform(this);