From: Hannu Niemistö Date: Mon, 24 Jul 2017 11:19:26 +0000 (+0300) Subject: (refs #7375) Replaced collectFreeVariables method by a visitor X-Git-Tag: v1.31.0~264^2~33 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=6dfe20b0f514b91337fcac4de0267ffd8268be07;p=simantics%2Fplatform.git (refs #7375) Replaced collectFreeVariables method by a visitor Change-Id: I89817b8a075d6261b351fbbd70c40d9f9ccc59cc --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java index 2697ea08f..3cbebd49d 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java @@ -148,19 +148,6 @@ public class CHRLiteral extends Symbol { parameter.collectVars(allVars, vars); } - public void collectFreeVariables(THashSet vars) { - if(relation == SpecialCHRRelation.ASSIGN) { - parameters[1].collectFreeVariables(vars); - } - else { - for(Expression parameter : parameters) - parameter.collectFreeVariables(vars); - if(typeConstraintEvidenceParameters != null) - for(Expression parameter : typeConstraintEvidenceParameters) - parameter.collectFreeVariables(vars); - } - } - public void setLocationDeep(long loc) { if(location == Locations.NO_LOCATION) { this.location = loc; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java index 8bba6697d..5c0fdaea2 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java @@ -4,7 +4,6 @@ import org.simantics.scl.compiler.elaboration.chr.plan.PostCommitOp; import org.simantics.scl.compiler.elaboration.chr.plan.PreCommitOp; import org.simantics.scl.compiler.elaboration.chr.planning.QueryPlanningContext; import org.simantics.scl.compiler.elaboration.chr.relations.CHRConstraint; -import org.simantics.scl.compiler.elaboration.chr.relations.SpecialCHRRelation; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; @@ -40,15 +39,7 @@ public class CHRQuery extends Symbol { for(CHRLiteral literal : literals) literal.collectVars(allVars, vars); } - - public void collectFreeVariables(THashSet vars) { - for(CHRLiteral literal : literals) - literal.collectFreeVariables(vars); - for(CHRLiteral literal : literals) - if(literal.relation == SpecialCHRRelation.ASSIGN) - literal.parameters[0].removeFreeVariables(vars); - } - + public void setLocationDeep(long loc) { if(location == Locations.NO_LOCATION) { this.location = loc; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRule.java index 67b30b221..78224ebb0 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRule.java @@ -18,7 +18,6 @@ import org.simantics.scl.compiler.types.Types; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class CHRRule extends Symbol { @@ -69,11 +68,6 @@ public class CHRRule extends Symbol { body.collectVars(allVars, vars); } - public void collectFreeVariables(THashSet vars) { - head.collectFreeVariables(vars); - body.collectFreeVariables(vars); - } - public void setLocationDeep(long loc) { if(location == Locations.NO_LOCATION) { this.location = loc; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java index 805e781e7..2a4059522 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java @@ -136,13 +136,6 @@ public class CHRRuleset extends Symbol { rule.collectVars(allVars, vars); } - public void collectFreeVariables(THashSet vars) { - for(IncludeStatement include : includes) - include.value.collectFreeVariables(vars); - for(CHRRule rule : rules) - rule.collectFreeVariables(vars); - } - public void setLocationDeep(long loc) { if(location == Locations.NO_LOCATION) { this.location = loc; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqBasic.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqBasic.java index 8dcfe0863..71dcd0425 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqBasic.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqBasic.java @@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.errors.Locations; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EqBasic extends Equation { @@ -34,12 +33,6 @@ public class EqBasic extends Equation { } } - @Override - public void collectFreeVariables(THashSet vars) { - left.collectFreeVariables(vars); - right.collectFreeVariables(vars); - } - @Override public void checkType(TypingContext context) { left = left.inferType(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqGuard.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqGuard.java index 8b10872e9..aa66cd890 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqGuard.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/EqGuard.java @@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.errors.Locations; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EqGuard extends Equation { @@ -31,11 +30,6 @@ public class EqGuard extends Equation { } } - @Override - public void collectFreeVariables(THashSet vars) { - guard.collectFreeVariables(vars); - } - @Override public void checkType(TypingContext context) { guard = guard.checkIgnoredType(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/Equation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/Equation.java index 94283436a..5b4268691 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/Equation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/equation/Equation.java @@ -7,7 +7,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.internal.parsing.Symbol; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public abstract class Equation extends Symbol { @@ -15,7 +14,6 @@ public abstract class Equation extends Symbol { public abstract void setLocationDeep(long loc); - public abstract void collectFreeVariables(THashSet vars); public abstract void checkType(TypingContext context); public abstract void collectVars(TObjectIntHashMap allVars, TIntHashSet vars); public abstract void resolve(TranslationContext context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ASTExpression.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ASTExpression.java index 7e804c2a2..2858a579c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ASTExpression.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ASTExpression.java @@ -8,7 +8,6 @@ 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 abstract class ASTExpression extends SimplifiableExpression { @@ -20,11 +19,6 @@ public abstract class ASTExpression extends SimplifiableExpression { throw new InternalCompilerError(getClass().getSimpleName() + " does not support simplify."); } - @Override - final public void collectFreeVariables(THashSet vars) { - throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectFreeVariables."); - } - @Override final public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Case.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Case.java index c8f0eb893..2669b4733 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Case.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Case.java @@ -9,7 +9,6 @@ import org.simantics.scl.compiler.internal.parsing.Symbol; import org.simantics.scl.compiler.types.Type; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class Case extends Symbol { @@ -40,12 +39,6 @@ public class Case extends Symbol { value.collectVars(allVars, vars); } - public void collectFreeVariables(THashSet vars) { - value.collectFreeVariables(vars); - for(int i=patterns.length-1;i>=0;--i) - patterns[i].removeFreeVariables(vars); - } - public void resolve(TranslationContext context) { context.pushFrame(); for(int i=0;i vars) { - expression.collectFreeVariables(vars); - } - @Override public Expression simplify(SimplificationContext context) { expression = expression.simplify(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java index d52cc3f2e..0826bbbca 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java @@ -17,7 +17,6 @@ import org.simantics.scl.compiler.types.util.TypeUnparsingContext; import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EAmbiguous extends SimplifiableExpression { @@ -27,7 +26,7 @@ public class EAmbiguous extends SimplifiableExpression { boolean[] active; int activeCount; transient TypingContext context; - Expression resolvedExpression; + public Expression resolvedExpression; public abstract static class Alternative { public abstract Type getType(); @@ -163,10 +162,6 @@ public class EAmbiguous extends SimplifiableExpression { listenType(); return this; } - - @Override - public void collectFreeVariables(THashSet vars) { - } @Override public Expression resolve(TranslationContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java index d45e7fc8c..14366a4c9 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java @@ -33,7 +33,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds; import org.simantics.scl.compiler.types.util.MultiFunction; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EApply extends Expression { @@ -102,13 +101,6 @@ public class EApply extends Expression { effect = Types.simplifyFinalEffect(effect); return w.applyWithEffect(location, effect, type, functionVal, parameterVals); } - - @Override - public void collectFreeVariables(THashSet vars) { - function.collectFreeVariables(vars); - for(Expression parameter : parameters) - parameter.collectFreeVariables(vars); - } private void combineApplications() { if(function instanceof EApply) { @@ -186,13 +178,6 @@ public class EApply extends Expression { for(Expression parameter : this.parameters) parameters.add(parameter); } - - @Override - public void removeFreeVariables(THashSet vars) { - function.removeFreeVariables(vars); - for(Expression parameter : parameters) - parameter.removeFreeVariables(vars); - } @Override public Expression replace(ReplaceContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApplyType.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApplyType.java index df945eabb..f9426f21a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApplyType.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApplyType.java @@ -16,11 +16,10 @@ 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 EApplyType extends Expression { - Expression expression; + public Expression expression; Type parameter; public EApplyType(Expression expression, Type parameter) { @@ -65,11 +64,6 @@ public class EApplyType extends Expression { return val.createSpecialization(parameter); } - @Override - public void collectFreeVariables(THashSet vars) { - expression.collectFreeVariables(vars); - } - @Override public Expression simplify(SimplificationContext context) { expression = expression.simplify(context); @@ -85,11 +79,6 @@ public class EApplyType extends Expression { expression = expression.resolve(context); return this; } - - @Override - public void removeFreeVariables(THashSet vars) { - expression.removeFreeVariables(vars); - } @Override public Expression replace(ReplaceContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAsPattern.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAsPattern.java index 6d29526ea..59538d603 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAsPattern.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAsPattern.java @@ -13,7 +13,6 @@ 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 EAsPattern extends Expression { @@ -48,17 +47,6 @@ public class EAsPattern extends Expression { vars.add(id); pattern.collectVars(allVars, vars); } - - @Override - public void collectFreeVariables(THashSet vars) { - throw new InternalCompilerError(location, "Cannot collect free variables for a pattern."); - } - - @Override - public void removeFreeVariables(THashSet vars) { - vars.remove(var); - pattern.removeFreeVariables(vars); - } @Override public Expression simplify(SimplificationContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java index 2d3a7ce92..ce72e282a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java @@ -16,14 +16,13 @@ import org.simantics.scl.compiler.types.exceptions.UnificationException; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EBind extends SimplifiableExpression { public Expression pattern; public Expression value; public Expression in; - EVariable monadEvidence; + public EVariable monadEvidence; SCLValue bindFunction; Type monadType; Type valueContentType; @@ -110,13 +109,6 @@ public class EBind extends SimplifiableExpression { return simplified.simplify(context); } - @Override - public void collectFreeVariables(THashSet vars) { - in.collectFreeVariables(vars); - value.collectFreeVariables(vars); - pattern.removeFreeVariables(vars); - } - @Override public Expression resolve(TranslationContext context) { value = value.resolve(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBlock.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBlock.java index b7f943c07..ea47c57b2 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBlock.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBlock.java @@ -20,7 +20,7 @@ import org.simantics.scl.compiler.errors.Locations; public class EBlock extends ASTExpression { - ArrayList statements = new ArrayList(); + public ArrayList statements = new ArrayList(); boolean monadic; public EBlock() { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java index 121653993..e1495588a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java @@ -13,12 +13,11 @@ import org.simantics.scl.compiler.top.ExpressionInterpretationContext; 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; @@ -42,12 +41,6 @@ public class ECHRRuleset extends Expression { return in.toVal(context, w); } - @Override - public void collectFreeVariables(THashSet vars) { - ruleset.collectFreeVariables(vars); - in.collectFreeVariables(vars); - } - @Override public Expression resolve(TranslationContext context) { if(context.currentRuleset != null) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java index 7df6fb595..5d7b490e7 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java @@ -14,11 +14,10 @@ import org.simantics.scl.compiler.top.ExpressionInterpretationContext; 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 ECHRRulesetConstructor extends Expression { - CHRRuleset ruleset; + public CHRRuleset ruleset; public ECHRRulesetConstructor(CHRRuleset ruleset) { this.ruleset = ruleset; @@ -39,11 +38,6 @@ public class ECHRRulesetConstructor extends Expression { return ruleset.generateCode(w); } - @Override - public void collectFreeVariables(THashSet vars) { - ruleset.collectFreeVariables(vars); - } - @Override public Expression resolve(TranslationContext context) { context.pushFrame(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRSelect.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRSelect.java index d1873e4e6..71c4a43e0 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRSelect.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRSelect.java @@ -22,13 +22,12 @@ import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class ECHRSelect extends Expression { - CHRQuery query; - Variable[] existentialVariables; - Expression expression; + public CHRQuery query; + public Variable[] existentialVariables; + public Expression expression; private ArrayList planOps; private CHRRuleset currentRuleset; @@ -84,15 +83,6 @@ public class ECHRSelect extends Expression { return w.apply(location, context.getValue(Names.MList_freeze).getValue(), list); } - @Override - public void collectFreeVariables(THashSet vars) { - query.collectFreeVariables(vars); - expression.collectFreeVariables(vars); - if(existentialVariables != null) - for(Variable variable : existentialVariables) - vars.remove(variable); - } - @Override public Expression resolve(TranslationContext context) { currentRuleset = context.currentRuleset; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java index 1bab4ff64..9fcb4ca46 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java @@ -1,6 +1,8 @@ package org.simantics.scl.compiler.elaboration.expressions; import java.util.ArrayList; +import java.util.Collections; +import java.util.Set; import org.simantics.scl.compiler.common.names.Name; import org.simantics.scl.compiler.common.precedence.Precedence; @@ -31,7 +33,6 @@ import org.simantics.scl.compiler.types.util.MultiFunction; import org.simantics.scl.compiler.types.util.TypeUnparsingContext; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EConstant extends Expression { @@ -87,6 +88,11 @@ public class EConstant extends Expression { public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { } + + @Override + public Set getFreeVariables() { + return Collections.emptySet(); + } public void toString(StringBuilder b, TypeUnparsingContext tuc) { Name name = value.getName(); @@ -106,17 +112,13 @@ public class EConstant extends Expression { setType(Types.instantiate(value.getType(), typeParameters)); } - @Override - public IVal toVal(CompilationContext context, CodeWriter w) { - IVal val = value.getValue(); - if(typeParameters.length > 0) { - val = val.createSpecialization(typeParameters); - } - return val; - } - @Override - public void collectFreeVariables(THashSet vars) { + public IVal toVal(CompilationContext context, CodeWriter w) { + IVal val = value.getValue(); + if(typeParameters.length > 0) { + val = val.createSpecialization(typeParameters); + } + return val; } @Override @@ -151,10 +153,6 @@ public class EConstant extends Expression { public Expression resolveAsPattern(TranslationContext context) { return this; } - - @Override - public void removeFreeVariables(THashSet vars) { - } @Override public Expression replace(ReplaceContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEnforce.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEnforce.java index 9b0a13b20..3bd337963 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEnforce.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEnforce.java @@ -13,12 +13,11 @@ 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 EEnforce extends SimplifiableExpression { - Query query; + public Query query; public EEnforce(Query query) { this.query = query; @@ -50,11 +49,6 @@ public class EEnforce extends SimplifiableExpression { return query.generateEnforce(new EnforcingContext(context)); } - @Override - public void collectFreeVariables(THashSet vars) { - query.collectFreeVariables(vars); - } - @Override public Expression simplify(SimplificationContext context) { /*query = query.simplify(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java index d2d31713b..268cc2497 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EEquations.java @@ -11,7 +11,6 @@ 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 EEquations extends SimplifiableExpression { @@ -60,12 +59,6 @@ public class EEquations extends SimplifiableExpression { setType(Types.UNIT); } - @Override - public void collectFreeVariables(THashSet vars) { - for(Equation equation : equations) - equation.collectFreeVariables(vars); - } - @Override public void accept(ExpressionVisitor visitor) { visitor.visit(this); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java index 82c6d5d52..def408716 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java @@ -14,7 +14,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EError extends Expression { @@ -46,10 +45,6 @@ public class EError extends Expression { throw new UnsupportedOperationException(); } - @Override - public void collectFreeVariables(THashSet vars) { - } - @Override public Expression simplify(SimplificationContext context) { return this; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java index 213c30bf1..0321ae3fc 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java @@ -20,7 +20,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.compiler.types.util.TypeUnparsingContext; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EExternalConstant extends Expression { @@ -55,11 +54,6 @@ public class EExternalConstant extends Expression { return mw.getExternalConstant(value, getType()); } - @Override - public void collectFreeVariables(THashSet vars) { - } - - @Override public Expression simplify(SimplificationContext context) { return this; @@ -85,10 +79,6 @@ public class EExternalConstant extends Expression { return new EExternalConstant(value, getType().replace(context.tvarMap)); } - @Override - public void removeFreeVariables(THashSet vars) { - } - @Override public Expression inferType(TypingContext context) { return this; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java index c5ee9bc7a..668c05393 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java @@ -17,15 +17,14 @@ 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 EFieldAccess extends SimplifiableExpression { private static final Type VARIABLE = Types.con("Simantics/Variables", "Variable"); - Expression parent; - FieldAccessor accessor; + public Expression parent; + public FieldAccessor accessor; boolean lastAccessor = true; public EFieldAccess(Expression parent, FieldAccessor accessor) { @@ -112,12 +111,6 @@ public class EFieldAccess extends SimplifiableExpression { return this; } - @Override - public void collectFreeVariables(THashSet vars) { - parent.collectFreeVariables(vars); - accessor.collectFreeVariables(vars); - } - @Override public Expression simplify(SimplificationContext context) { // Simplify subexpressions diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EGetConstraint.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EGetConstraint.java index 95948d45c..a070ba8da 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EGetConstraint.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EGetConstraint.java @@ -8,12 +8,11 @@ import org.simantics.scl.compiler.types.TPred; 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 EGetConstraint extends SimplifiableExpression { TPred constraint; - EVariable evidence; + public EVariable evidence; public EGetConstraint(long loc, TPred constraint) { super(loc); @@ -42,12 +41,6 @@ public class EGetConstraint extends SimplifiableExpression { setType(constraint); } - @Override - public void collectFreeVariables(THashSet vars) { - if(evidence != null) - evidence.collectFreeVariables(vars); - } - @Override public Expression simplify(SimplificationContext context) { return evidence.simplify(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java index 7b56d22fa..a65748243 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java @@ -18,7 +18,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.runtime.tuple.Tuple0; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EIf extends Expression { @@ -75,14 +74,6 @@ public class EIf extends Expression { return w.getParameters()[0]; } - @Override - public void collectFreeVariables(THashSet vars) { - condition.collectFreeVariables(vars); - then_.collectFreeVariables(vars); - if(else_ != null) - else_.collectFreeVariables(vars); - } - @Override public Expression simplify(SimplificationContext context) { condition = condition.simplify(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIntegerLiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIntegerLiteral.java index a70e50160..fa4db7ff1 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIntegerLiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIntegerLiteral.java @@ -17,12 +17,11 @@ 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 EIntegerLiteral extends SimplifiableExpression { public String value; - EVariable constraint; + public EVariable constraint; public EIntegerLiteral(String value) { this.value = value; @@ -74,10 +73,6 @@ public class EIntegerLiteral extends SimplifiableExpression { throw new InternalCompilerError(); } - @Override - public void collectFreeVariables(THashSet vars) { - } - @Override public Expression simplify(SimplificationContext context) { try { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.java index 5aa77046e..bc3e925b0 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambda.java @@ -13,7 +13,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds; import org.simantics.scl.compiler.types.util.MultiFunction; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class ELambda extends SimplifiableExpression { @@ -98,12 +97,6 @@ public class ELambda extends SimplifiableExpression { return decomposeMatching().simplify(context); } - @Override - public void collectFreeVariables(THashSet vars) { - for(Case case_ : cases) - case_.collectFreeVariables(vars); - } - @Override public Expression resolve(TranslationContext context) { for(Case case_ : cases) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java index fec64d6d0..9aed4450e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java @@ -16,7 +16,6 @@ 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 ELambdaType extends Expression { @@ -45,11 +44,6 @@ public class ELambdaType extends Expression { return lambdaToVal(context, w); } - @Override - public void collectFreeVariables(THashSet vars) { - value.collectFreeVariables(vars); - } - @Override public Expression simplify(SimplificationContext context) { value = value.simplify(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java index 71ee13076..711953524 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java @@ -21,7 +21,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; /** @@ -118,15 +117,6 @@ public class ELet extends Expression { return result; } - @Override - public void collectFreeVariables(THashSet vars) { - in.collectFreeVariables(vars); - for(Assignment assign : assignments) - assign.value.collectFreeVariables(vars); - for(Assignment assign : assignments) - assign.pattern.removeFreeVariables(vars); - } - @Override public Expression resolve(TranslationContext context) { throw new InternalCompilerError("ELet should be already resolved."); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java index 102d64658..a6d79e817 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListComprehension.java @@ -11,7 +11,6 @@ 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 EListComprehension extends SimplifiableExpression { @@ -57,12 +56,6 @@ public class EListComprehension extends SimplifiableExpression { setType(Types.list(head.getType())); } - @Override - public void collectFreeVariables(THashSet vars) { - head.collectFreeVariables(vars); - qualifier.collectFreeVariables(vars); - } - @Override public Expression simplify(SimplificationContext context) { context.pushLocation(location); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java index 478d7b311..797dbc2e5 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java @@ -16,12 +16,11 @@ 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 EListLiteral extends SimplifiableExpression { - Expression[] components; + public Expression[] components; Type componentType; public EListLiteral(Expression[] components) { @@ -44,12 +43,6 @@ public class EListLiteral extends SimplifiableExpression { component.collectVars(allVars, vars); } - @Override - public void collectFreeVariables(THashSet vars) { - for(Expression component : components) - component.collectFreeVariables(vars); - } - @Override public Expression simplify(SimplificationContext context) { context.pushLocation(location); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java index 388fbb37a..3f65de3b6 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELiteral.java @@ -1,6 +1,8 @@ package org.simantics.scl.compiler.elaboration.expressions; import java.util.ArrayList; +import java.util.Collections; +import java.util.Set; import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.constants.Constant; @@ -18,7 +20,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.compiler.types.util.TypeUnparsingContext; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class ELiteral extends Expression { @@ -42,6 +43,11 @@ public class ELiteral extends Expression { public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { } + + @Override + public Set getFreeVariables() { + return Collections.emptySet(); + } public void toString(StringBuilder b, TypeUnparsingContext tuc) { b.append(value); @@ -57,11 +63,6 @@ public class ELiteral extends Expression { return value; } - @Override - public void collectFreeVariables(THashSet vars) { - } - - @Override public Expression simplify(SimplificationContext context) { return this; @@ -87,10 +88,6 @@ public class ELiteral extends Expression { return new ELiteral(value); } - @Override - public void removeFreeVariables(THashSet vars) { - } - @Override public IExpression toIExpression(ExpressionInterpretationContext target) { return new IConstant(value.realizeValue(target.localClassBuilder)); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java index 18f89ccdf..ba9cee65e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EMatch.java @@ -18,7 +18,6 @@ import org.simantics.scl.compiler.types.Types; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EMatch extends Expression { @@ -72,14 +71,6 @@ public class EMatch extends Expression { w.continueAs(joinPoint); return w.getParameters()[0]; } - - @Override - public void collectFreeVariables(THashSet vars) { - for(Expression s : scrutinee) - s.collectFreeVariables(vars); - for(Case case_ : cases) - case_.collectFreeVariables(vars); - } @Override public Expression simplify(SimplificationContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreLet.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreLet.java index c7624039e..1578928aa 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreLet.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreLet.java @@ -18,8 +18,8 @@ import gnu.trove.procedure.TObjectObjectProcedure; */ public class EPreLet extends ASTExpression { - List assignments; - Expression in; + public List assignments; + public Expression in; public EPreLet(List assignments, Expression in) { this.assignments = assignments; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreRuleset.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreRuleset.java index 41880a022..c287f3ba1 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreRuleset.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreRuleset.java @@ -10,8 +10,8 @@ import gnu.trove.map.hash.THashMap; public class EPreRuleset extends ASTExpression { - RuleStatement[] statements; - Expression in; + public RuleStatement[] statements; + public Expression in; public EPreRuleset(RuleStatement[] statements, Expression in) { this.statements = statements; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERealLiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERealLiteral.java index 5312c7543..8c861004c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERealLiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERealLiteral.java @@ -16,12 +16,11 @@ 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 ERealLiteral extends SimplifiableExpression { public String value; - EVariable constraint; + public EVariable constraint; public ERealLiteral(String value) { this.value = value; @@ -68,10 +67,6 @@ public class ERealLiteral extends SimplifiableExpression { protected void updateType() throws MatchException { throw new InternalCompilerError("TODO"); } - - @Override - public void collectFreeVariables(THashSet vars) { - } @Override public Expression simplify(SimplificationContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERuleset.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERuleset.java index e84e0500c..dadf52797 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERuleset.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERuleset.java @@ -43,13 +43,12 @@ import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.impl.Constants; import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class ERuleset extends SimplifiableExpression { LocalRelation[] relations; - DatalogRule[] rules; - Expression in; + public DatalogRule[] rules; + public Expression in; public ERuleset(LocalRelation[] relations, DatalogRule[] rules, Expression in) { this.relations = relations; @@ -129,18 +128,6 @@ public class ERuleset extends SimplifiableExpression { in = in.checkIgnoredType(context); return compile(context); } - - @Override - public void collectFreeVariables(THashSet vars) { - for(DatalogRule rule : rules) { - for(Expression parameter : rule.headParameters) - parameter.collectFreeVariables(vars); - rule.body.collectFreeVariables(vars); - for(Variable var : rule.variables) - vars.remove(var); - } - in.collectFreeVariables(vars); - } @Override public void collectVars(TObjectIntHashMap allVars, diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESelect.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESelect.java index 473c403da..09079377f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESelect.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESelect.java @@ -27,7 +27,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class ESelect extends SimplifiableExpression { @@ -35,9 +34,9 @@ public class ESelect extends SimplifiableExpression { private final Type ARRAY_LIST = Types.con("ArrayList", "T"); int selectVariant; - Expression expression; - Query query; - Variable[] variables; + public Expression expression; + public Query query; + public Variable[] variables; public ESelect(int selectVariant, Expression expression, Query query) { this.selectVariant = selectVariant; @@ -128,14 +127,6 @@ public class ESelect extends SimplifiableExpression { return loc(location, result); } - @Override - public void collectFreeVariables(THashSet vars) { - expression.collectFreeVariables(vars); - query.collectFreeVariables(vars); - for(Variable variable : variables) - vars.remove(variable); - } - @Override public Expression resolve(TranslationContext context) { context.pushExistentialFrame(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java index 9b3ee8df7..13c75db78 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLambda.java @@ -1,6 +1,7 @@ package org.simantics.scl.compiler.elaboration.expressions; import java.util.ArrayList; +import java.util.Set; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; import org.simantics.scl.compiler.compilation.CompilationContext; @@ -23,7 +24,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds; import org.simantics.scl.compiler.types.util.MultiFunction; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class ESimpleLambda extends Expression { @@ -66,21 +66,15 @@ public class ESimpleLambda extends Expression { return this; } - @Override - protected void updateType() throws MatchException { - setType(Types.functionE(Types.canonical(parameter.type), - effect, value.getType())); - } - - @Override - public IVal toVal(CompilationContext context, CodeWriter w) { - return lambdaToVal(context, w); + @Override + protected void updateType() throws MatchException { + setType(Types.functionE(Types.canonical(parameter.type), + effect, value.getType())); } @Override - public void collectFreeVariables(THashSet vars) { - value.collectFreeVariables(vars); - vars.remove(parameter); + public IVal toVal(CompilationContext context, CodeWriter w) { + return lambdaToVal(context, w); } @Override @@ -143,7 +137,7 @@ public class ESimpleLambda extends Expression { // Free variables; ExpressionInterpretationContext innerContext = context.createNewContext(); - THashSet freeVariables = cur.getFreeVariables(); + Set freeVariables = cur.getFreeVariables(); for(Variable parameter : parameters) freeVariables.remove(parameter); int i=0; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLet.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLet.java index e69a27121..4957b578d 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLet.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ESimpleLet.java @@ -16,13 +16,12 @@ 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 ESimpleLet extends Expression { - Variable variable; // may be null - Expression value; - Expression in; + public Variable variable; // may be null + public Expression value; + public Expression in; public ESimpleLet(Variable variable, Expression value, Expression in) { if(value == null) @@ -65,13 +64,6 @@ public class ESimpleLet extends Expression { return in.toVal(context, w); } - @Override - public void collectFreeVariables(THashSet vars) { - value.collectFreeVariables(vars); - in.collectFreeVariables(vars); - vars.remove(variable); - } - @Override public Expression simplify(SimplificationContext context) { value = value.simplify(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETransformation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETransformation.java index 761741658..e6f57ac86 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETransformation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETransformation.java @@ -15,7 +15,6 @@ 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 ETransformation extends SimplifiableExpression { @@ -39,11 +38,6 @@ public class ETransformation extends SimplifiableExpression { protected void updateType() throws MatchException { setType(Types.UNIT); } - - @Override - public void collectFreeVariables(THashSet vars) { - seed.collectFreeVariables(vars); - } @Override public Expression inferType(TypingContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java index 89caebad0..872da88f1 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java @@ -9,11 +9,10 @@ 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 ETypeAnnotation extends SimplifiableExpression { - Expression value; + public Expression value; Type type; TypeAst typeAst; @@ -39,11 +38,6 @@ public class ETypeAnnotation extends SimplifiableExpression { setType(type); } - @Override - public void collectFreeVariables(THashSet vars) { - value.collectFreeVariables(vars); - } - @Override public Expression simplify(SimplificationContext context) { return value.simplify(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java index aa2789282..fccc62e98 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EVariable.java @@ -1,6 +1,8 @@ package org.simantics.scl.compiler.elaboration.expressions; import java.util.ArrayList; +import java.util.Collections; +import java.util.Set; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; import org.simantics.scl.compiler.compilation.CompilationContext; @@ -21,7 +23,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds; import org.simantics.scl.compiler.types.util.TypeUnparsingContext; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EVariable extends Expression { @@ -53,24 +54,27 @@ public class EVariable extends Expression { if(id >= 0) vars.add(id); } + + @Override + public Set getFreeVariables() { + if(variable == null) + return Collections.emptySet(); + else + return Collections.singleton(variable); + } public void toString(StringBuilder b, TypeUnparsingContext tuc) { b.append(variable == null ? "???" : variable.toString()); } - @Override - protected void updateType() throws MatchException { - setType(variable.getType()); - } - - @Override - public IVal toVal(CompilationContext context, CodeWriter w) { - return variable.getVal(); + @Override + protected void updateType() throws MatchException { + setType(variable.getType()); } @Override - public void collectFreeVariables(THashSet vars) { - vars.add(variable); + public IVal toVal(CompilationContext context, CodeWriter w) { + return variable.getVal(); } @Override @@ -92,11 +96,6 @@ public class EVariable extends Expression { ArrayList parameters) { } - @Override - public void removeFreeVariables(THashSet vars) { - vars.remove(variable); - } - @Override public Expression resolveAsPattern(TranslationContext context) { return this; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EViewPattern.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EViewPattern.java index c0dfb5a75..f2a017edd 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EViewPattern.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EViewPattern.java @@ -13,7 +13,6 @@ import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.compiler.types.util.MultiFunction; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EViewPattern extends Expression { @@ -59,17 +58,6 @@ public class EViewPattern extends Expression { throw new InternalCompilerError(location, "EViewPattern.toVal should not be invoked."); } - @Override - public void collectFreeVariables(THashSet vars) { - throw new InternalCompilerError(location, "Cannot collect free variables for a pattern."); - } - - @Override - public void removeFreeVariables(THashSet vars) { - expression.collectFreeVariables(vars); - pattern.removeFreeVariables(vars); - } - @Override public Expression resolve(TranslationContext context) { context.getErrorLog().log("View pattern cannot occur only in patterns. Maybe you are missing '\\' in front of a lambda experssion?"); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EWhen.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EWhen.java index 9ea5ddb1e..55ea86baf 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EWhen.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EWhen.java @@ -17,14 +17,13 @@ import org.simantics.scl.compiler.types.exceptions.UnificationException; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EWhen extends SimplifiableExpression { public Query query; public Expression action; - Variable[] variables; + public Variable[] variables; public EWhen(Query query, Expression action) { this.query = query; @@ -83,14 +82,6 @@ public class EWhen extends SimplifiableExpression { } } - @Override - public void collectFreeVariables(THashSet vars) { - action.collectFreeVariables(vars); - query.collectFreeVariables(vars); - for(Variable var : variables) - vars.remove(var); - } - @Override public Expression resolve(TranslationContext context) { context.pushExistentialFrame(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java index 507d335e3..5b60dad42 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java @@ -1,6 +1,7 @@ package org.simantics.scl.compiler.elaboration.expressions; import java.util.ArrayList; +import java.util.Set; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; import org.simantics.scl.compiler.common.precedence.Precedence; @@ -15,8 +16,10 @@ import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType; import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchingLhs; import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor; import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectEffectsVisitor; +import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectFreeVariablesVisitor; import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectRefsVisitor; import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor; +import org.simantics.scl.compiler.elaboration.expressions.visitors.StandardExpressionVisitor; import org.simantics.scl.compiler.elaboration.query.QAtom; import org.simantics.scl.compiler.elaboration.relations.SCLRelation; import org.simantics.scl.compiler.internal.codegen.references.IVal; @@ -36,7 +39,6 @@ import org.simantics.scl.compiler.types.kinds.Kinds; import org.simantics.scl.compiler.types.util.Typed; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public abstract class Expression extends Symbol implements Typed { @@ -212,8 +214,6 @@ public abstract class Expression extends Symbol implements Typed { return new ELambdaType(vars, this); } - public abstract void collectFreeVariables(THashSet vars); - public Expression simplify(SimplificationContext context) { System.out.println("#############################"); System.out.println(this); @@ -246,10 +246,6 @@ public abstract class Expression extends Symbol implements Typed { context.getErrorLog().log(location, "Pattern was expected here."); return new EError(); } - - public void removeFreeVariables(THashSet vars) { - throw new InternalCompilerError(getClass().getSimpleName() + " is not a pattern."); - } public Expression checkTypeAsPattern(TypingContext context, Type requiredType) { if(context.isInPattern()) @@ -263,10 +259,10 @@ public abstract class Expression extends Symbol implements Typed { /** * Used during simplification and in toIExpression */ - public THashSet getFreeVariables() { - THashSet result = new THashSet(); - collectFreeVariables(result); - return result; + public Set getFreeVariables() { + CollectFreeVariablesVisitor visitor = new CollectFreeVariablesVisitor(); + accept(visitor); + return visitor.getFreeVariables(); } public static Expression[] concat(Expression[] a, Expression[] b) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/GuardedExpressionGroup.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/GuardedExpressionGroup.java index 62bbe45b9..90e13d750 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/GuardedExpressionGroup.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/GuardedExpressionGroup.java @@ -15,7 +15,6 @@ 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 { @@ -52,15 +51,6 @@ public class GuardedExpressionGroup extends Expression { //throw new InternalCompilerError("GuardedExpressionGroup should be handled in match compilation."); } - @Override - public void collectFreeVariables(THashSet 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) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/ExpressionAccessor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/ExpressionAccessor.java index 12c9a9170..2febc404f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/ExpressionAccessor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/ExpressionAccessor.java @@ -9,7 +9,6 @@ import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.types.Types; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class ExpressionAccessor extends FieldAccessor { @@ -20,11 +19,6 @@ public class ExpressionAccessor extends FieldAccessor { this.fieldName = fieldName; } - @Override - public void collectFreeVariables(THashSet vars) { - fieldName.collectFreeVariables(vars); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListAssignment.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListAssignment.java index 2477a4f5f..47aeef1a5 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListAssignment.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListAssignment.java @@ -1,5 +1,7 @@ package org.simantics.scl.compiler.elaboration.expressions.list; +import java.util.Set; + import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; @@ -10,7 +12,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.errors.Locations; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class ListAssignment extends ListQualifier { @@ -34,18 +35,12 @@ public class ListAssignment extends ListQualifier { value.collectVars(allVars, vars); } - @Override - public void collectFreeVariables(THashSet vars) { - value.collectFreeVariables(vars); - pattern.collectFreeVariables(vars); - } - @Override public CompiledQualifier compile(SimplificationContext context) { if(pattern instanceof EVariable) return new CompiledQualifier(context.singletonList(value), pattern); else { - THashSet variables = pattern.getFreeVariables(); + Set variables = pattern.getFreeVariables(); Variable[] variableArray = variables.toArray(new Variable[variables.size()]); Expression[] variableExps = new Expression[variableArray.length]; for(int i=0;i vars) { - value.collectFreeVariables(vars); - pattern.collectFreeVariables(vars); - } - @Override public CompiledQualifier compile(SimplificationContext context) { if(pattern instanceof EVariable) return new CompiledQualifier(value, pattern); else { - THashSet variables = pattern.getFreeVariables(); + Set variables = pattern.getFreeVariables(); Variable[] variableArray = variables.toArray(new Variable[variables.size()]); Expression[] variableExps = new Expression[variableArray.length]; for(int i=0;i vars) { - condition.collectFreeVariables(vars); - } - @Override public CompiledQualifier compile(SimplificationContext context) { return new CompiledQualifier( diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListQualifier.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListQualifier.java index 352c7514e..9365e6a87 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListQualifier.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListQualifier.java @@ -7,14 +7,12 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.internal.parsing.Symbol; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public abstract class ListQualifier extends Symbol { public abstract void checkType(TypingContext context); public abstract void collectVars(TObjectIntHashMap allVars, TIntHashSet vars); - public abstract void collectFreeVariables(THashSet vars); /** * Called in simplification. */ diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListSeq.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListSeq.java index 50de4a7dd..6bab8c91e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListSeq.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListSeq.java @@ -8,7 +8,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.errors.Locations; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class ListSeq extends ListQualifier { @@ -33,12 +32,6 @@ public class ListSeq extends ListQualifier { b.collectVars(allVars, vars); } - @Override - public void collectFreeVariables(THashSet vars) { - b.collectFreeVariables(vars); - a.collectFreeVariables(vars); - } - @Override public CompiledQualifier compile(SimplificationContext context) { CompiledQualifier cA = a.compile(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListThen.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListThen.java index 706611bbb..b8bd39566 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListThen.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListThen.java @@ -13,7 +13,6 @@ import org.simantics.scl.compiler.types.exceptions.UnificationException; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class ListThen extends ListQualifier { @@ -56,14 +55,6 @@ public class ListThen extends ListQualifier { by.collectVars(allVars, vars); } - @Override - public void collectFreeVariables(THashSet vars) { - left.collectFreeVariables(vars); - transformer.collectFreeVariables(vars); - if(by != null) - by.collectFreeVariables(vars); - } - @Override public CompiledQualifier compile(SimplificationContext context) { CompiledQualifier q = left.compile(context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java index aec3d84dc..118d4de1a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java @@ -7,7 +7,6 @@ import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess; import org.simantics.scl.compiler.elaboration.expressions.ELambda; import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda; import org.simantics.scl.compiler.elaboration.expressions.ETransformation; -import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisitor; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java new file mode 100644 index 000000000..04f6791ac --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectFreeVariablesVisitor.java @@ -0,0 +1,184 @@ +package org.simantics.scl.compiler.elaboration.expressions.visitors; + +import org.simantics.scl.compiler.elaboration.chr.CHRLiteral; +import org.simantics.scl.compiler.elaboration.chr.CHRQuery; +import org.simantics.scl.compiler.elaboration.chr.CHRRule; +import org.simantics.scl.compiler.elaboration.chr.relations.SpecialCHRRelation; +import org.simantics.scl.compiler.elaboration.expressions.Assignment; +import org.simantics.scl.compiler.elaboration.expressions.Case; +import org.simantics.scl.compiler.elaboration.expressions.EAsPattern; +import org.simantics.scl.compiler.elaboration.expressions.EBind; +import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect; +import org.simantics.scl.compiler.elaboration.expressions.ELet; +import org.simantics.scl.compiler.elaboration.expressions.ERuleset.DatalogRule; +import org.simantics.scl.compiler.elaboration.expressions.ESelect; +import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda; +import org.simantics.scl.compiler.elaboration.expressions.ESimpleLet; +import org.simantics.scl.compiler.elaboration.expressions.EVariable; +import org.simantics.scl.compiler.elaboration.expressions.EViewPattern; +import org.simantics.scl.compiler.elaboration.expressions.EWhen; +import org.simantics.scl.compiler.elaboration.expressions.Expression; +import org.simantics.scl.compiler.elaboration.expressions.Variable; +import org.simantics.scl.compiler.elaboration.expressions.list.ListAssignment; +import org.simantics.scl.compiler.elaboration.expressions.list.ListGenerator; +import org.simantics.scl.compiler.elaboration.query.QExists; + +import gnu.trove.set.hash.THashSet; + +public class CollectFreeVariablesVisitor extends StandardExpressionVisitor { + private THashSet freeVariables = new THashSet(); + + private StandardExpressionVisitor collectBoundVariablesVisitor = new StandardExpressionVisitor() { + @Override + public void visit(EVariable expression) { + if(expression.variable != null) + freeVariables.remove(expression.variable); + } + + + @Override + public void visit(EAsPattern expression) { + freeVariables.remove(expression.var); + expression.pattern.accept(this); + } + + @Override + public void visit(EViewPattern expression) { + expression.expression.accept(CollectFreeVariablesVisitor.this); + expression.pattern.accept(this); + } + }; + + @Override + public void visit(EVariable expression) { + if(expression.variable != null) + freeVariables.add(expression.variable); + } + + @Override + public void visit(EBind expression) { + if(expression.monadEvidence != null) + visit(expression.monadEvidence); + expression.in.accept(this); + expression.value.accept(this); + expression.pattern.accept(collectBoundVariablesVisitor); + } + + @Override + public void visit(Assignment assignment) { + assignment.value.accept(this); + assignment.pattern.accept(collectBoundVariablesVisitor); + } + + @Override + public void visit(ELet expression) { + expression.in.accept(this); + for(int i=expression.assignments.length-1;i>=0;--i) + visit(expression.assignments[i]); + } + + @Override + public void visit(Case case_) { + case_.value.accept(this); + for(Expression pattern : case_.patterns) + pattern.accept(collectBoundVariablesVisitor); + } + + @Override + public void visit(ESimpleLambda expression) { + expression.value.accept(this); + freeVariables.remove(expression.parameter); + } + + @Override + public void visit(ESimpleLet expression) { + expression.in.accept(this); + expression.value.accept(this); + freeVariables.remove(expression.variable); + } + + @Override + public void visit(ECHRSelect expression) { + expression.expression.accept(this); + visit(expression.query); + for(Variable variable : expression.existentialVariables) + freeVariables.remove(variable); + } + + @Override + public void visit(ESelect expression) { + expression.expression.accept(this); + expression.query.accept(this); + for(Variable variable : expression.variables) + freeVariables.remove(variable); + } + + @Override + public void visit(EWhen expression) { + expression.action.accept(this); + expression.query.accept(this); + for(Variable variable : expression.variables) + freeVariables.remove(variable); + } + + @Override + public void visit(DatalogRule rule) { + for(Expression parameter : rule.headParameters) + parameter.accept(this); + rule.body.accept(this); + for(Variable variable : rule.variables) + freeVariables.remove(variable); + } + + @Override + public void visit(ListGenerator qualifier) { + qualifier.pattern.accept(collectBoundVariablesVisitor); + qualifier.value.accept(this); + } + + @Override + public void visit(ListAssignment qualifier) { + qualifier.pattern.accept(collectBoundVariablesVisitor); + qualifier.value.accept(this); + } + + @Override + public void visit(CHRLiteral literal) { + if(literal.relation == SpecialCHRRelation.ASSIGN) { + literal.parameters[0].accept(collectBoundVariablesVisitor); + literal.parameters[1].accept(this); + } + else { + for(Expression parameter : literal.parameters) + parameter.accept(this); + if(literal.typeConstraintEvidenceParameters != null) + for(Expression parameter : literal.typeConstraintEvidenceParameters) + parameter.accept(this); + } + } + + @Override + public void visit(CHRQuery query) { + for(int i=query.literals.length-1;i>=0;--i) { + visit(query.literals[i]); + } + } + + @Override + public void visit(CHRRule rule) { + super.visit(rule); + for(Variable variable : rule.existentialVariables) + freeVariables.remove(variable); + } + + @Override + public void visit(QExists query) { + query.query.accept(this); + for(Variable variable : query.variables) + freeVariables.remove(variable); + } + + public THashSet getFreeVariables() { + return freeVariables; + } +} diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectRefsVisitor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectRefsVisitor.java index 366dc514b..5445f0892 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectRefsVisitor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectRefsVisitor.java @@ -2,7 +2,6 @@ package org.simantics.scl.compiler.elaboration.expressions.visitors; import org.simantics.scl.compiler.elaboration.expressions.EConstant; import org.simantics.scl.compiler.elaboration.expressions.ETransformation; -import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisitor; import org.simantics.scl.compiler.elaboration.query.QAtom; import org.simantics.scl.compiler.elaboration.relations.CompositeRelation; import org.simantics.scl.compiler.elaboration.relations.SCLRelation; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/ForVariablesUsesVisitor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/ForVariablesUsesVisitor.java index b4d1fd4fe..57befad98 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/ForVariablesUsesVisitor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/ForVariablesUsesVisitor.java @@ -2,7 +2,6 @@ package org.simantics.scl.compiler.elaboration.expressions.visitors; import org.simantics.scl.compiler.elaboration.expressions.EAsPattern; import org.simantics.scl.compiler.elaboration.expressions.EVariable; -import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisitor; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; public class ForVariablesUsesVisitor extends StandardExpressionVisitor { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionTransformer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/StandardExpressionTransformer.java similarity index 83% rename from bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionTransformer.java rename to bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/StandardExpressionTransformer.java index c489422a5..2a0ff5a06 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionTransformer.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/StandardExpressionTransformer.java @@ -1,4 +1,4 @@ -package org.simantics.scl.compiler.elaboration.expressions; +package org.simantics.scl.compiler.elaboration.expressions.visitors; import org.simantics.scl.compiler.elaboration.chr.CHRLiteral; import org.simantics.scl.compiler.elaboration.chr.CHRQuery; @@ -15,6 +15,58 @@ import org.simantics.scl.compiler.elaboration.equation.EqBasic; import org.simantics.scl.compiler.elaboration.equation.EqGuard; import org.simantics.scl.compiler.elaboration.equation.Equation; import org.simantics.scl.compiler.elaboration.equation.EquationVisitor; +import org.simantics.scl.compiler.elaboration.expressions.Assignment; +import org.simantics.scl.compiler.elaboration.expressions.Case; +import org.simantics.scl.compiler.elaboration.expressions.EAmbiguous; +import org.simantics.scl.compiler.elaboration.expressions.EApply; +import org.simantics.scl.compiler.elaboration.expressions.EApplyType; +import org.simantics.scl.compiler.elaboration.expressions.EAsPattern; +import org.simantics.scl.compiler.elaboration.expressions.EBinary; +import org.simantics.scl.compiler.elaboration.expressions.EBinaryRightSide; +import org.simantics.scl.compiler.elaboration.expressions.EBind; +import org.simantics.scl.compiler.elaboration.expressions.EBlock; +import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset; +import org.simantics.scl.compiler.elaboration.expressions.ECHRRulesetConstructor; +import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect; +import org.simantics.scl.compiler.elaboration.expressions.EConstant; +import org.simantics.scl.compiler.elaboration.expressions.ECoveringBranchPoint; +import org.simantics.scl.compiler.elaboration.expressions.EEnforce; +import org.simantics.scl.compiler.elaboration.expressions.EEquations; +import org.simantics.scl.compiler.elaboration.expressions.EError; +import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant; +import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess; +import org.simantics.scl.compiler.elaboration.expressions.EGetConstraint; +import org.simantics.scl.compiler.elaboration.expressions.EIf; +import org.simantics.scl.compiler.elaboration.expressions.EIntegerLiteral; +import org.simantics.scl.compiler.elaboration.expressions.ELambda; +import org.simantics.scl.compiler.elaboration.expressions.ELambdaType; +import org.simantics.scl.compiler.elaboration.expressions.ELet; +import org.simantics.scl.compiler.elaboration.expressions.EListComprehension; +import org.simantics.scl.compiler.elaboration.expressions.EListLiteral; +import org.simantics.scl.compiler.elaboration.expressions.ELiteral; +import org.simantics.scl.compiler.elaboration.expressions.EMatch; +import org.simantics.scl.compiler.elaboration.expressions.EPlaceholder; +import org.simantics.scl.compiler.elaboration.expressions.EPreLet; +import org.simantics.scl.compiler.elaboration.expressions.EPreRuleset; +import org.simantics.scl.compiler.elaboration.expressions.ERange; +import org.simantics.scl.compiler.elaboration.expressions.ERealLiteral; +import org.simantics.scl.compiler.elaboration.expressions.ERecord; +import org.simantics.scl.compiler.elaboration.expressions.ERuleset; +import org.simantics.scl.compiler.elaboration.expressions.ESelect; +import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda; +import org.simantics.scl.compiler.elaboration.expressions.ESimpleLet; +import org.simantics.scl.compiler.elaboration.expressions.EStringLiteral; +import org.simantics.scl.compiler.elaboration.expressions.ETransformation; +import org.simantics.scl.compiler.elaboration.expressions.ETypeAnnotation; +import org.simantics.scl.compiler.elaboration.expressions.EVar; +import org.simantics.scl.compiler.elaboration.expressions.EVariable; +import org.simantics.scl.compiler.elaboration.expressions.EViewPattern; +import org.simantics.scl.compiler.elaboration.expressions.EWhen; +import org.simantics.scl.compiler.elaboration.expressions.Expression; +import org.simantics.scl.compiler.elaboration.expressions.ExpressionTransformer; +import org.simantics.scl.compiler.elaboration.expressions.GuardedExpression; +import org.simantics.scl.compiler.elaboration.expressions.GuardedExpressionGroup; +import org.simantics.scl.compiler.elaboration.expressions.QueryTransformer; import org.simantics.scl.compiler.elaboration.expressions.accessor.ExpressionAccessor; import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement; import org.simantics.scl.compiler.elaboration.expressions.block.CHRStatement; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionVisitor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/StandardExpressionVisitor.java similarity index 78% rename from bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionVisitor.java rename to bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/StandardExpressionVisitor.java index 7ef827fb6..1d03d19c3 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/StandardExpressionVisitor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/StandardExpressionVisitor.java @@ -1,4 +1,4 @@ -package org.simantics.scl.compiler.elaboration.expressions; +package org.simantics.scl.compiler.elaboration.expressions.visitors; import org.simantics.scl.compiler.elaboration.chr.CHRLiteral; import org.simantics.scl.compiler.elaboration.chr.CHRQuery; @@ -15,7 +15,57 @@ import org.simantics.scl.compiler.elaboration.equation.EqBasic; import org.simantics.scl.compiler.elaboration.equation.EqGuard; import org.simantics.scl.compiler.elaboration.equation.Equation; import org.simantics.scl.compiler.elaboration.equation.EquationVisitor; +import org.simantics.scl.compiler.elaboration.expressions.Assignment; +import org.simantics.scl.compiler.elaboration.expressions.Case; +import org.simantics.scl.compiler.elaboration.expressions.EAmbiguous; +import org.simantics.scl.compiler.elaboration.expressions.EApply; +import org.simantics.scl.compiler.elaboration.expressions.EApplyType; +import org.simantics.scl.compiler.elaboration.expressions.EAsPattern; +import org.simantics.scl.compiler.elaboration.expressions.EBinary; +import org.simantics.scl.compiler.elaboration.expressions.EBinaryRightSide; +import org.simantics.scl.compiler.elaboration.expressions.EBind; +import org.simantics.scl.compiler.elaboration.expressions.EBlock; +import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset; +import org.simantics.scl.compiler.elaboration.expressions.ECHRRulesetConstructor; +import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect; +import org.simantics.scl.compiler.elaboration.expressions.EConstant; +import org.simantics.scl.compiler.elaboration.expressions.ECoveringBranchPoint; +import org.simantics.scl.compiler.elaboration.expressions.EEnforce; +import org.simantics.scl.compiler.elaboration.expressions.EEquations; +import org.simantics.scl.compiler.elaboration.expressions.EError; +import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant; +import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess; +import org.simantics.scl.compiler.elaboration.expressions.EGetConstraint; +import org.simantics.scl.compiler.elaboration.expressions.EIf; +import org.simantics.scl.compiler.elaboration.expressions.EIntegerLiteral; +import org.simantics.scl.compiler.elaboration.expressions.ELambda; +import org.simantics.scl.compiler.elaboration.expressions.ELambdaType; +import org.simantics.scl.compiler.elaboration.expressions.ELet; +import org.simantics.scl.compiler.elaboration.expressions.EListComprehension; +import org.simantics.scl.compiler.elaboration.expressions.EListLiteral; +import org.simantics.scl.compiler.elaboration.expressions.ELiteral; +import org.simantics.scl.compiler.elaboration.expressions.EMatch; +import org.simantics.scl.compiler.elaboration.expressions.EPlaceholder; +import org.simantics.scl.compiler.elaboration.expressions.EPreLet; +import org.simantics.scl.compiler.elaboration.expressions.ERange; +import org.simantics.scl.compiler.elaboration.expressions.ERealLiteral; +import org.simantics.scl.compiler.elaboration.expressions.ERecord; +import org.simantics.scl.compiler.elaboration.expressions.ERuleset; import org.simantics.scl.compiler.elaboration.expressions.ERuleset.DatalogRule; +import org.simantics.scl.compiler.elaboration.expressions.ESelect; +import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda; +import org.simantics.scl.compiler.elaboration.expressions.ESimpleLet; +import org.simantics.scl.compiler.elaboration.expressions.EStringLiteral; +import org.simantics.scl.compiler.elaboration.expressions.ETransformation; +import org.simantics.scl.compiler.elaboration.expressions.ETypeAnnotation; +import org.simantics.scl.compiler.elaboration.expressions.EVar; +import org.simantics.scl.compiler.elaboration.expressions.EVariable; +import org.simantics.scl.compiler.elaboration.expressions.EViewPattern; +import org.simantics.scl.compiler.elaboration.expressions.EWhen; +import org.simantics.scl.compiler.elaboration.expressions.Expression; +import org.simantics.scl.compiler.elaboration.expressions.ExpressionVisitor; +import org.simantics.scl.compiler.elaboration.expressions.GuardedExpression; +import org.simantics.scl.compiler.elaboration.expressions.GuardedExpressionGroup; import org.simantics.scl.compiler.elaboration.expressions.accessor.ExpressionAccessor; import org.simantics.scl.compiler.elaboration.expressions.accessor.FieldAccessorVisitor; import org.simantics.scl.compiler.elaboration.expressions.accessor.IdAccessor; @@ -372,17 +422,24 @@ EquationVisitor, StatementVisitor, CHRAstQueryVisitor { equation.accept(this); } + public void visit(CHRLiteral literal) { + for(Expression parameter : literal.parameters) + parameter.accept(this); + } + public void visit(CHRQuery query) { for(CHRLiteral literal : query.literals) - for(Expression parameter : literal.parameters) - parameter.accept(this); + visit(literal); + } + + public void visit(CHRRule rule) { + visit(rule.head); + visit(rule.body); } public void visit(CHRRuleset ruleset) { - for(CHRRule rule : ruleset.rules) { - visit(rule.head); - visit(rule.body); - } + for(CHRRule rule : ruleset.rules) + visit(rule); for(IncludeStatement include : ruleset.includes) include.value.accept(this); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAbstractCombiner.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAbstractCombiner.java index 459711a8d..e711d372c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAbstractCombiner.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAbstractCombiner.java @@ -13,7 +13,6 @@ import org.simantics.scl.compiler.elaboration.query.pre.QPreGuard; import org.simantics.scl.compiler.errors.Locations; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public abstract class QAbstractCombiner extends Query { @@ -22,11 +21,6 @@ public abstract class QAbstractCombiner extends Query { public QAbstractCombiner(Query[] queries) { this.queries = queries; } - - public void collectFreeVariables(THashSet vars) { - for(Query query : queries) - query.collectFreeVariables(vars); - } @Override public Query resolve(TranslationContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAbstractModifier.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAbstractModifier.java index 421bf833e..234c8b615 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAbstractModifier.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAbstractModifier.java @@ -6,7 +6,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.errors.Locations; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public abstract class QAbstractModifier extends Query { @@ -15,10 +14,6 @@ public abstract class QAbstractModifier extends Query { public QAbstractModifier(Query query) { this.query = query; } - - public void collectFreeVariables(THashSet vars) { - query.collectFreeVariables(vars); - } @Override public Query resolve(TranslationContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAtom.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAtom.java index c988aed56..208513b21 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAtom.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QAtom.java @@ -28,7 +28,6 @@ import org.simantics.scl.compiler.types.Types; import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class QAtom extends Query { @@ -47,12 +46,6 @@ public class QAtom extends Query { this.parameters = parameters; } - @Override - public void collectFreeVariables(THashSet vars) { - for(Expression parameter : parameters) - parameter.collectFreeVariables(vars); - } - @Override public void checkType(TypingContext context) { // Type parameters diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QExists.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QExists.java index 293c8bf70..2f9c0c507 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QExists.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QExists.java @@ -17,10 +17,9 @@ import org.simantics.scl.compiler.types.Types; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.THashMap; -import gnu.trove.set.hash.THashSet; public class QExists extends QAbstractModifier { - Variable[] variables; + public Variable[] variables; public QExists(Variable[] variables, Query query) { super(query); @@ -31,13 +30,6 @@ public class QExists extends QAbstractModifier { this(variables.toArray(new Variable[variables.size()]), query); } - @Override - public void collectFreeVariables(THashSet vars) { - super.collectFreeVariables(vars); - for(Variable variable : variables) - vars.remove(variable); - } - @Override public void checkType(TypingContext context) { for(Variable var : variables) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QIf.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QIf.java index d148339a4..85950c24a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QIf.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QIf.java @@ -11,7 +11,6 @@ import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.types.Types; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class QIf extends Query { @@ -25,13 +24,6 @@ public class QIf extends Query { this.elseQuery = elseQuery; } - @Override - public void collectFreeVariables(THashSet vars) { - condition.collectFreeVariables(vars); - thenQuery.collectFreeVariables(vars); - elseQuery.collectFreeVariables(vars); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { condition.collectVars(allVars, vars); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QMapping.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QMapping.java index 08d72563e..428ed922c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QMapping.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/QMapping.java @@ -13,7 +13,6 @@ import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.types.Type; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class QMapping extends Query { @@ -25,12 +24,6 @@ public class QMapping extends Query { this.parameters = parameters; } - @Override - public void collectFreeVariables(THashSet vars) { - for(Expression parameter : parameters) - parameter.collectFreeVariables(vars); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/Query.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/Query.java index 7b610756a..cea31bbe8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/Query.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/Query.java @@ -10,12 +10,12 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.elaboration.expressions.EError; import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.QueryTransformer; -import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisitor; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor; import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectRefsVisitor; import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor; +import org.simantics.scl.compiler.elaboration.expressions.visitors.StandardExpressionVisitor; import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext; import org.simantics.scl.compiler.elaboration.query.compilation.DerivateException; import org.simantics.scl.compiler.elaboration.query.compilation.DynamicProgrammingOrdering; @@ -31,13 +31,11 @@ import org.simantics.scl.compiler.internal.parsing.Symbol; import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public abstract class Query extends Symbol { public static final Query[] EMPTY_ARRAY = new Query[0]; - public abstract void collectFreeVariables(THashSet vars); public abstract void collectVars(TObjectIntHashMap allVars, TIntHashSet vars); public abstract void checkType(TypingContext context); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/pre/PreQuery.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/pre/PreQuery.java index 859690ec8..b7b9f964b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/pre/PreQuery.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/pre/PreQuery.java @@ -6,7 +6,6 @@ import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.elaboration.expressions.Variable; -import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; import org.simantics.scl.compiler.elaboration.query.QConjunction; import org.simantics.scl.compiler.elaboration.query.QExists; import org.simantics.scl.compiler.elaboration.query.Query; @@ -14,7 +13,6 @@ import org.simantics.scl.compiler.elaboration.query.QueryVisitor; import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; /** @@ -24,11 +22,6 @@ public abstract class PreQuery extends Query { public ArrayList extraVariables = new ArrayList(2); public ArrayList sideQueries = new ArrayList(2); - - @Override - public void collectFreeVariables(THashSet vars) { - throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectFreeVariables."); - } @Override public void checkType(TypingContext context) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/profiling/BranchPointInjector.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/profiling/BranchPointInjector.java index 6f3ff3be9..eed6d8555 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/profiling/BranchPointInjector.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/profiling/BranchPointInjector.java @@ -46,7 +46,6 @@ import org.simantics.scl.compiler.elaboration.expressions.EWhen; import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.GuardedExpression; import org.simantics.scl.compiler.elaboration.expressions.GuardedExpressionGroup; -import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionTransformer; import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement; import org.simantics.scl.compiler.elaboration.expressions.block.GuardStatement; import org.simantics.scl.compiler.elaboration.expressions.block.LetStatement; @@ -57,6 +56,7 @@ import org.simantics.scl.compiler.elaboration.expressions.list.ListGuard; import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier; import org.simantics.scl.compiler.elaboration.expressions.list.ListSeq; import org.simantics.scl.compiler.elaboration.expressions.list.ListThen; +import org.simantics.scl.compiler.elaboration.expressions.visitors.StandardExpressionTransformer; import org.simantics.scl.compiler.elaboration.query.QAlternative; import org.simantics.scl.compiler.elaboration.query.QAtom; import org.simantics.scl.compiler.elaboration.query.QConjunction; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ToplevelEffectDecorator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ToplevelEffectDecorator.java index da4ce4feb..491d88e41 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ToplevelEffectDecorator.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ToplevelEffectDecorator.java @@ -16,8 +16,8 @@ import org.simantics.scl.compiler.elaboration.expressions.ESelect; import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda; import org.simantics.scl.compiler.elaboration.expressions.EWhen; import org.simantics.scl.compiler.elaboration.expressions.Expression; -import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionTransformer; import org.simantics.scl.compiler.elaboration.expressions.Variable; +import org.simantics.scl.compiler.elaboration.expressions.visitors.StandardExpressionTransformer; import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.ErrorLog;