]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java
(refs #7375) Replaced collectFreeVariables method by a visitor
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / ECHRRuleset.java
index be447b7a270808ca7e68a626822ca7780d7fd496..e1495588adecf3cd8e5142da1b3be98f5f39913e 100644 (file)
@@ -1,69 +1,63 @@
 package org.simantics.scl.compiler.elaboration.expressions;
 
+import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
 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.writer.CodeWriter;
-import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
 import org.simantics.scl.compiler.internal.interpreted.IExpression;
 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
-import org.simantics.scl.compiler.types.Type;
 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 ECHRRuleset extends Expression {
-    CHRRuleset ruleset;
-    Expression in;
+    public CHRRuleset ruleset;
+    public Expression in;
     
     public ECHRRuleset(CHRRuleset ruleset, Expression in) {
         this.ruleset = ruleset;
         this.in = in;
     }
     
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
-        ruleset.collectRefs(allRefs, refs);
-        in.collectRefs(allRefs, refs);
-    }
     @Override
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         ruleset.collectVars(allVars, vars);
         in.collectVars(allVars, vars);
     }
-    @Override
-    public void forVariables(VariableProcedure procedure) {
-        ruleset.forVariables(procedure);
-        in.forVariables(procedure);
-    }
+
     @Override
     protected void updateType() throws MatchException {
         setType(in.getType());
     }
+
     @Override
-    public IVal toVal(Environment env, CodeWriter w) {
+    public IVal toVal(CompilationContext context, CodeWriter w) {
         ruleset.generateCode(w);
-        return in.toVal(env, w);
-    }
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-        ruleset.collectFreeVariables(vars);
-        in.collectFreeVariables(vars);
+        return in.toVal(context, w);
     }
+
     @Override
     public Expression resolve(TranslationContext context) {
+        if(context.currentRuleset != null) {
+            context.getErrorLog().log(location, "Current version of SCL compiler does not support nested rulesets.");
+            return this;
+        }
+        context.currentRuleset = ruleset;
+        
         context.pushFrame();
         context.pushCHRConstraintFrame();
         ruleset.resolve(context);
         in = in.resolve(context);
         context.popCHRConstraintFrame(ruleset.constraints);
         context.popFrame();
+        
+        context.currentRuleset = null;
+        
         return this;
     }
     @Override
@@ -74,16 +68,7 @@ public class ECHRRuleset extends Expression {
             in.setLocationDeep(loc);
         }
     }
-    @Override
-    public Expression decorate(ExpressionDecorator decorator) {
-        in = in.decorate(decorator);
-        return this;
-    }
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        ruleset.collectEffects(effects);
-        in.collectEffects(effects);
-    }
+    
     @Override
     public void accept(ExpressionVisitor visitor) {
         visitor.visit(this);