From: Hannu Niemistö Date: Mon, 24 Jul 2017 08:15:12 +0000 (+0300) Subject: (refs #7375) Replace collectRefs by CollectRefsVisitor X-Git-Tag: v1.31.0~264^2~37^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F51%2F751%2F1;p=simantics%2Fplatform.git (refs #7375) Replace collectRefs by CollectRefsVisitor Change-Id: I77bf548a062bb365f43284778845678fb50341d5 --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java index 58bb98a41..52b8692d8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java @@ -408,7 +408,7 @@ public class TypeChecking { for(TransformationRule rule : module.getRules()) for(Query[] queries : rule.sections.values()) for(Query query : queries) - query.collectRefs(allRefs, refs); + query.collectRefs(allRefs, refs); } @Override 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 e8bb00a6e..2697ea08f 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 @@ -112,14 +112,6 @@ public class CHRLiteral extends Symbol { } } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - for(Expression parameter : parameters) - parameter.collectRefs(allRefs, refs); - if(typeConstraintEvidenceParameters != null) - for(Expression parameter : typeConstraintEvidenceParameters) - parameter.collectRefs(allRefs, refs); - } - public void checkType(TypingContext context) { if(relation == SpecialCHRRelation.EXECUTE) { if(parameters.length != 1) 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 777dc9f6c..8bba6697d 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 @@ -31,11 +31,6 @@ public class CHRQuery extends Symbol { literal.resolve(context); } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - for(CHRLiteral literal : literals) - literal.collectRefs(allRefs, refs); - } - public void checkType(TypingContext context) { for(CHRLiteral literal : literals) literal.checkType(context); 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 31d0ec48c..67b30b221 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 @@ -57,11 +57,6 @@ public class CHRRule extends Symbol { existentialVariables = context.popExistentialFrame(); } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - head.collectRefs(allRefs, refs); - body.collectRefs(allRefs, refs); - } - public void checkType(TypingContext context) { for(Variable variable : existentialVariables) variable.setType(Types.metaVar(Kinds.STAR)); 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 9eca12aa9..805e781e7 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 @@ -122,13 +122,6 @@ public class CHRRuleset extends Symbol { }*/ } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - for(IncludeStatement include : includes) - include.value.collectRefs(allRefs, refs); - for(CHRRule rule : rules) - rule.collectRefs(allRefs, refs); - } - public void checkType(TypingContext context) { for(IncludeStatement include : includes) include.value = include.value.checkType(context, include.ruleset.runtimeRulesetType); 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 67608de2d..08b1a0726 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 @@ -53,12 +53,6 @@ public class EqBasic extends Equation { right = right.checkType(context, left.getType()); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - left.collectRefs(allRefs, refs); - right.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { left.collectVars(allVars, vars); 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 2e434b461..5dac9fce4 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 @@ -48,11 +48,6 @@ public class EqGuard extends Equation { guard = guard.checkIgnoredType(context); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - guard.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { guard.collectVars(allVars, vars); 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 dcf11a3e6..ca4102c96 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 @@ -4,7 +4,6 @@ import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; 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.internal.parsing.Symbol; import org.simantics.scl.compiler.types.Type; @@ -20,7 +19,6 @@ public abstract class Equation extends Symbol { public abstract void collectFreeVariables(THashSet vars); public abstract void collectEffects(THashSet effects); public abstract void checkType(TypingContext context); - public abstract void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs); public abstract void collectVars(TObjectIntHashMap allVars, TIntHashSet vars); public abstract void resolve(TranslationContext context); public abstract void accept(EquationVisitor visitor); 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 4a65459b8..fa54f8ab2 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 @@ -25,12 +25,6 @@ public abstract class ASTExpression extends SimplifiableExpression { throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectFreeVariables."); } - @Override - final public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectRefs."); - } - @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 54be27b3c..c8f0eb893 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 @@ -35,10 +35,6 @@ public class Case extends Symbol { return lhs; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - value.collectRefs(allRefs, refs); - } - public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { value.collectVars(allVars, vars); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/DecoratingExpression.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/DecoratingExpression.java index 9b6c2645c..796a41c69 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/DecoratingExpression.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/DecoratingExpression.java @@ -26,11 +26,6 @@ public abstract class DecoratingExpression extends SimplifiableExpression { super(loc); this.expression = expression; } - - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - expression.collectRefs(allRefs, refs); - } @Override public void collectVars(TObjectIntHashMap allVars, 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 73c4fa3a0..2b5c813a1 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 @@ -42,11 +42,6 @@ public class EAmbiguous extends SimplifiableExpression { this.activeCount = alternatives.length; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 375039e0b..4065f463a 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 @@ -76,13 +76,6 @@ public class EApply extends Expression { return parameters; } - - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - function.collectRefs(allRefs, refs); - for(Expression parameter : parameters) - parameter.collectRefs(allRefs, refs); - } - public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { function.collectVars(allVars, vars); for(Expression parameter : parameters) 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 cd54a44d6..f441a1be5 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 @@ -50,21 +50,17 @@ public class EApplyType extends Expression { return parameter; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - expression.collectRefs(allRefs, refs); + public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { + expression.collectVars(allVars, vars); } - - public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { - expression.collectVars(allVars, vars); - } - @Override - protected void updateType() throws MatchException { - setType(Types.instantiate(expression.getType(), parameter)); - } - - @Override - public IVal toVal(CompilationContext context, CodeWriter w) { + @Override + protected void updateType() throws MatchException { + setType(Types.instantiate(expression.getType(), parameter)); + } + + @Override + public IVal toVal(CompilationContext context, CodeWriter w) { IVal val = expression.toVal(context, w); return val.createSpecialization(parameter); } 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 1a4a5bbd0..98c54844c 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 @@ -40,12 +40,6 @@ public class EAsPattern extends Expression { return pattern; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - pattern.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 b4d824caa..3bec2aaa1 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 @@ -43,12 +43,6 @@ public class EBind extends SimplifiableExpression { this.value = value; this.in = in; } - - @Override - public void collectRefs(final TObjectIntHashMap allRefs, final TIntHashSet refs) { - value.collectRefs(allRefs, refs); - in.collectRefs(allRefs, refs); - } @Override public void collectVars(TObjectIntHashMap allVars, 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 d23b2e4ce..a8ad1480d 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 @@ -26,30 +26,29 @@ public class ECHRRuleset extends Expression { this.in = in; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - ruleset.collectRefs(allRefs, refs); - in.collectRefs(allRefs, refs); - } @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { ruleset.collectVars(allVars, vars); in.collectVars(allVars, vars); } + @Override protected void updateType() throws MatchException { setType(in.getType()); } + @Override public IVal toVal(CompilationContext context, CodeWriter w) { ruleset.generateCode(w); 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 25ae61345..734fd71b4 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 @@ -24,27 +24,27 @@ public class ECHRRulesetConstructor extends Expression { public ECHRRulesetConstructor(CHRRuleset ruleset) { this.ruleset = ruleset; } - - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - ruleset.collectRefs(allRefs, refs); - } + @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { ruleset.collectVars(allVars, vars); } + @Override protected void updateType() throws MatchException { throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given."); } + @Override public IVal toVal(CompilationContext context, CodeWriter w) { 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 6b4a7fe86..fbaff1200 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 @@ -38,12 +38,6 @@ public class ECHRSelect extends Expression { this.query = query; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - query.collectRefs(allRefs, refs); - expression.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { query.collectVars(allVars, vars); 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 037144a4c..4a2e07f43 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 @@ -35,7 +35,7 @@ import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class EConstant extends Expression { - SCLValue value; + public SCLValue value; Type[] typeParameters; public EConstant(SCLValue value, Type ... typeParameters) { @@ -83,23 +83,17 @@ public class EConstant extends Expression { return this; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - int id = allRefs.get(value); - if(id >= 0) - refs.add(id); + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - } - public void toString(StringBuilder b, TypeUnparsingContext tuc) { - Name name = value.getName(); - if(name.module.equals("Builtin") || name.module.equals("Prelude")) - b.append(name.name); - else - b.append(name); + public void toString(StringBuilder b, TypeUnparsingContext tuc) { + Name name = value.getName(); + if(name.module.equals("Builtin") || name.module.equals("Prelude")) + b.append(name.name); + else + b.append(name); /*for(Type type : typeParameters) { b.append(" <"); b.append(type.toString(tuc)); 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 49d010bce..bfaf699ed 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 @@ -29,12 +29,6 @@ public class EEnforce extends SimplifiableExpression { return query; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - query.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 dd1a7e415..bffb7f026 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 @@ -49,12 +49,6 @@ public class EEquations extends SimplifiableExpression { return transformer.transform(this); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - for(Equation equation : equations) - equation.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { for(Equation equation : equations) 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 c7ea89b30..b3f4f6488 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 @@ -24,28 +24,25 @@ public class EError extends Expression { setType(type); } - public EError() { + public EError() { } public EError(long loc) { this(loc, Types.metaVar(Kinds.STAR)); } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - } - @Override - protected void updateType() throws MatchException { - setType(Types.metaVar(Kinds.STAR)); - } - - @Override - public IVal toVal(CompilationContext context, CodeWriter w) { + @Override + protected void updateType() throws MatchException { + setType(Types.metaVar(Kinds.STAR)); + } + + @Override + public IVal toVal(CompilationContext context, CodeWriter w) { throw new UnsupportedOperationException(); } 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 611e96d36..0b5678f99 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 @@ -35,27 +35,24 @@ public class EExternalConstant extends Expression { return value; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { } - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - } - - public void toString(StringBuilder b, TypeUnparsingContext tuc) { + public void toString(StringBuilder b, TypeUnparsingContext tuc) { b.append(value); } - @Override - protected void updateType() throws MatchException { - throw new InternalCompilerError("EExternalConstants must have explicitly defined type."); - } - - @Override - public IVal toVal(CompilationContext context, CodeWriter w) { - ModuleWriter mw = w.getModuleWriter(); - return mw.getExternalConstant(value, getType()); + @Override + protected void updateType() throws MatchException { + throw new InternalCompilerError("EExternalConstants must have explicitly defined type."); + } + + @Override + public IVal toVal(CompilationContext context, CodeWriter w) { + ModuleWriter mw = w.getModuleWriter(); + return mw.getExternalConstant(value, getType()); } @Override 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 0bc8a4317..0a4d0ee16 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 @@ -35,13 +35,6 @@ public class EFieldAccess extends SimplifiableExpression { ((EFieldAccess)parent).lastAccessor = false; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - parent.collectRefs(allRefs, refs); - accessor.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 5f9a1eb59..8534f4624 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 @@ -20,11 +20,6 @@ public class EGetConstraint extends SimplifiableExpression { super(loc); this.constraint = constraint; } - - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - } @Override public void collectVars(TObjectIntHashMap allVars, 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 418ba69c9..ea64ac034 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 @@ -39,29 +39,22 @@ public class EIf extends Expression { this.else_ = else_; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - condition.collectRefs(allRefs, refs); - then_.collectRefs(allRefs, refs); - if(else_ != null) - else_.collectRefs(allRefs, refs); - } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - condition.collectVars(allVars, vars); + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { + condition.collectVars(allVars, vars); then_.collectVars(allVars, vars); if(else_ != null) else_.collectVars(allVars, vars); - } + } - @Override - protected void updateType() throws MatchException { - setType(then_.getType()); - } - - @Override - public IVal toVal(CompilationContext context, CodeWriter w) { + @Override + protected void updateType() throws MatchException { + setType(then_.getType()); + } + + @Override + public IVal toVal(CompilationContext context, CodeWriter w) { IVal conditionVal = condition.toVal(context, w); CodeWriter joinPoint = w.createBlock(getType()); CodeWriter thenBlock = w.createBlock(); 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 0b5d1a16d..856dcd371 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 @@ -28,11 +28,6 @@ public class EIntegerLiteral extends SimplifiableExpression { this.value = value; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 5138ec596..51b1f909e 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 @@ -37,20 +37,15 @@ public class ELambda extends SimplifiableExpression { this(loc, new Case(new Expression[] {pat}, exp)); } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { for(Case case_ : cases) - case_.collectRefs(allRefs, refs); - } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - for(Case case_ : cases) case_.collectVars(allVars, vars); - } + } - public Expression decomposeMatching() { - Expression[] patterns = cases[0].patterns; + public Expression decomposeMatching() { + Expression[] patterns = cases[0].patterns; int arity = patterns.length; // Simple 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 d413b8c35..b06f7b770 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 @@ -30,22 +30,18 @@ public class ELambdaType extends Expression { this.value = value; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - value.collectRefs(allRefs, refs); + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { + value.collectVars(allVars, vars); } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - value.collectVars(allVars, vars); - } - - @Override - protected void updateType() throws MatchException { - setType(Types.forAll(parameters, value.getType())); - } - @Override + @Override + protected void updateType() throws MatchException { + setType(Types.forAll(parameters, value.getType())); + } + + @Override public IVal toVal(CompilationContext context, CodeWriter w) { return lambdaToVal(context, w); } 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 5bde43500..7b7338a78 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 @@ -36,13 +36,6 @@ public class ELet extends Expression { this.assignments = assignments; this.in = in; } - - @Override - public void collectRefs(final TObjectIntHashMap allRefs, final TIntHashSet refs) { - for(Assignment assign : assignments) - assign.value.collectRefs(allRefs, refs); - in.collectRefs(allRefs, refs); - } @Override public void collectVars(TObjectIntHashMap allVars, 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 fa21346f1..a06100dd7 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 @@ -31,13 +31,6 @@ public class EListComprehension extends SimplifiableExpression { this.qualifier = qualifier; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - head.collectRefs(allRefs, refs); - qualifier.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 5c2a0d9d4..d2a1d3509 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 @@ -36,13 +36,6 @@ public class EListLiteral extends SimplifiableExpression { public Expression[] getComponents() { return components; } - - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - for(Expression component : components) - component.collectRefs(allRefs, refs); - } @Override public void collectVars(TObjectIntHashMap allVars, 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 d2a671a1d..14bd02344 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 @@ -39,25 +39,22 @@ public class ELiteral extends Expression { return value; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { } - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - } - - public void toString(StringBuilder b, TypeUnparsingContext tuc) { + public void toString(StringBuilder b, TypeUnparsingContext tuc) { b.append(value); } - - @Override - protected void updateType() throws MatchException { - setType(value.getType()); - } - @Override - public IVal toVal(CompilationContext context, CodeWriter w) { + @Override + protected void updateType() throws MatchException { + setType(value.getType()); + } + + @Override + public IVal toVal(CompilationContext context, CodeWriter w) { return value; } 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 4ad8135c4..0ca1d5442 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 @@ -41,43 +41,36 @@ public class EMatch extends Expression { this.cases = cases; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { for(Expression s : scrutinee) - s.collectRefs(allRefs, refs); - for(Case case_ : cases) - case_.collectRefs(allRefs, refs); - } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - for(Expression s : scrutinee) s.collectVars(allVars, vars); - for(Case case_ : cases) + for(Case case_ : cases) case_.collectVars(allVars, vars); - } - - @Override - protected void updateType() { - setType(cases[0].value.getType()); - } + } + + @Override + protected void updateType() { + setType(cases[0].value.getType()); + } + + @Override + public IVal toVal(CompilationContext context, CodeWriter w) { + ArrayList rows = new ArrayList(cases.length); + for(Case case_ : cases) + rows.add(new Row(case_.patterns, case_.value)); + + IVal[] scrutineeVals = new IVal[scrutinee.length]; + for(int i=0;i rows = new ArrayList(cases.length); - for(Case case_ : cases) - rows.add(new Row(case_.patterns, case_.value)); - - IVal[] scrutineeVals = new IVal[scrutinee.length]; - for(int i=0;i allRefs, - TIntHashSet refs) { - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 41d43dd06..1a133b6f9 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 @@ -141,18 +141,7 @@ public class ERuleset extends SimplifiableExpression { } in.collectFreeVariables(vars); } - - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - for(DatalogRule rule : rules) { - for(Expression parameter : rule.headParameters) - parameter.collectRefs(allRefs, refs); - rule.body.collectRefs(allRefs, refs); - } - in.collectRefs(allRefs, refs); - } - + @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { @@ -163,7 +152,7 @@ public class ERuleset extends SimplifiableExpression { } in.collectVars(allVars, vars); } - + @Override public void collectEffects(THashSet effects) { throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects."); 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 42fdc6f10..ce4d66bd7 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 @@ -45,13 +45,6 @@ public class ESelect extends SimplifiableExpression { this.query = query; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - expression.collectRefs(allRefs, refs); - query.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 0038dbf38..8f59b3b44 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 @@ -55,17 +55,13 @@ public class ESimpleLambda extends Expression { this.effect = effect; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - value.collectRefs(allRefs, refs); + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { + value.collectVars(allVars, vars); } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - value.collectVars(allVars, vars); - } - public Expression decomposeMatching() { + public Expression decomposeMatching() { value = value.decomposeMatching(); return this; } 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 1a084b366..422bbea11 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 @@ -45,28 +45,23 @@ public class ESimpleLet extends Expression { this.in = in; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - value.collectRefs(allRefs, refs); - in.collectRefs(allRefs, refs); + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { + value.collectVars(allVars, vars); + in.collectVars(allVars, vars); } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - value.collectVars(allVars, vars); - in.collectVars(allVars, vars); - } @Override protected void updateType() throws MatchException { setType(in.getType()); } - - @Override - public IVal toVal(CompilationContext context, CodeWriter w) { - IVal valueVal = value.toVal(context, w); - if(variable != null) - variable.setVal(valueVal); + + @Override + public IVal toVal(CompilationContext context, CodeWriter w) { + IVal valueVal = value.toVal(context, w); + if(variable != null) + variable.setVal(valueVal); return in.toVal(context, w); } 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 3e8f61b03..346e46cd3 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 @@ -30,17 +30,6 @@ public class ETransformation extends SimplifiableExpression { this.seed = seed; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - { - int ref = allRefs.get(TRANSFORMATION_RULES_TYPECHECKED); - if(ref >= 0) - refs.add(ref); - } - seed.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 6452812fc..10c8e6f7a 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 @@ -28,20 +28,16 @@ public class ETypeAnnotation extends SimplifiableExpression { this.type = type; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - value.collectRefs(allRefs, refs); + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { + value.collectVars(allVars, vars); } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - value.collectVars(allVars, vars); - } - @Override - protected void updateType() throws MatchException { - setType(type); - } + @Override + protected void updateType() throws MatchException { + setType(type); + } @Override public void collectFreeVariables(THashSet vars) { 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 669867ff6..44c03a2ac 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 @@ -46,18 +46,15 @@ public class EVariable extends Expression { this.variable = variable; } - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { + int id = allVars.get(variable); + if(id >= 0) + vars.add(id); } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - int id = allVars.get(variable); - if(id >= 0) - vars.add(id); - } - public void toString(StringBuilder b, TypeUnparsingContext tuc) { + public void toString(StringBuilder b, TypeUnparsingContext tuc) { b.append(variable == null ? "???" : variable.toString()); } 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 2561e63b9..a2a0a02c5 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 @@ -26,12 +26,6 @@ public class EViewPattern extends Expression { this.pattern = pattern; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - expression.collectRefs(allRefs, refs); - pattern.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { expression.collectVars(allVars, vars); 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 9cdb6eab2..a9fd0367b 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 @@ -43,13 +43,6 @@ public class EWhen extends SimplifiableExpression { this.variables = variables; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - query.collectRefs(allRefs, refs); - action.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 da3afdbfa..221bc8067 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 @@ -14,6 +14,7 @@ import org.simantics.scl.compiler.elaboration.errors.NotPatternException; 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.CollectRefsVisitor; import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor; import org.simantics.scl.compiler.elaboration.query.QAtom; import org.simantics.scl.compiler.elaboration.relations.SCLRelation; @@ -103,23 +104,23 @@ public abstract class Expression extends Symbol implements Typed { expression = new ESimpleLet(location, null, expression, new ELiteral(NoRepConstant.PUNIT)); return expression; } - - /** - * Checks the type of the expression against the given type. Adds type - * applications and lambdas if needed. - */ - public final Expression checkType(TypingContext context, Type requiredType) { - //System.out.println("checkType: " + this + " :: " + requiredType); - if(!context.isInPattern()) { - requiredType = Types.canonical(requiredType); - if(requiredType instanceof TForAll) { + + /** + * Checks the type of the expression against the given type. Adds type + * applications and lambdas if needed. + */ + public final Expression checkType(TypingContext context, Type requiredType) { + //System.out.println("checkType: " + this + " :: " + requiredType); + if(!context.isInPattern()) { + requiredType = Types.canonical(requiredType); + if(requiredType instanceof TForAll) { TForAll forAll = (TForAll)requiredType; TVar var = forAll.var; TVar newVar = Types.var(var.getKind()); requiredType = Types.canonical(forAll.type).replace(var, newVar); return new ELambdaType(new TVar[] {newVar}, checkType(context, requiredType)); } - while(requiredType instanceof TFun) { + while(requiredType instanceof TFun) { TFun fun = (TFun)requiredType; if(fun.domain instanceof TPred) { // No need to canonicalize ArrayList constraints = new ArrayList(2); @@ -143,7 +144,7 @@ public abstract class Expression extends Symbol implements Typed { context.pushEffectUpperBound(location, fun.effect); Expression expr = checkType(context, fun.range); context.popEffectUpperBound(); - + // Wrap Variable var = new Variable("punit", Types.PUNIT); return new ESimpleLambda(location, var, fun.effect, expr); @@ -151,14 +152,17 @@ public abstract class Expression extends Symbol implements Typed { else break; } - } - return checkBasicType(context, requiredType); - } + } + return checkBasicType(context, requiredType); + } + + public final void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { + accept(new CollectRefsVisitor(allRefs, refs)); + } - public abstract void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs); - public abstract void collectVars(TObjectIntHashMap allVars, TIntHashSet vars); + public abstract void collectVars(TObjectIntHashMap allVars, TIntHashSet vars); - public void forVariableUses(VariableProcedure procedure) { + public final void forVariableUses(VariableProcedure procedure) { accept(new ForVariablesUsesVisitor(procedure)); } 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 07fbc50a6..1e2cd05c4 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 @@ -25,16 +25,6 @@ public class GuardedExpressionGroup extends Expression { this.expressions = expressions; } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - for(GuardedExpression expression : expressions) { - for(Expression guard : expression.guards) - guard.collectRefs(allRefs, refs); - expression.value.collectRefs(allRefs, refs); - } - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 e4cdd0937..12c9a9170 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 @@ -25,12 +25,6 @@ public class ExpressionAccessor extends FieldAccessor { fieldName.collectFreeVariables(vars); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - fieldName.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/FieldAccessor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/FieldAccessor.java index aaf80610a..21c892ce4 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/FieldAccessor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/accessor/FieldAccessor.java @@ -18,10 +18,6 @@ public abstract class FieldAccessor extends Symbol { this.accessSeparator = accessSeparator; } - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - } - 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 a0073b889..1283cc059 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 @@ -29,12 +29,6 @@ public class ListAssignment extends ListQualifier { pattern.checkTypeAsPattern(context, value.getType()); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - value.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGenerator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGenerator.java index c7f89ba76..db12689c8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGenerator.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGenerator.java @@ -33,12 +33,6 @@ public class ListGenerator extends ListQualifier { pattern.checkTypeAsPattern(context, componentType); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - value.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGuard.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGuard.java index c9e29ca5b..2fe49150f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGuard.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/list/ListGuard.java @@ -25,12 +25,6 @@ public class ListGuard extends ListQualifier { condition.checkType(context, Types.BOOLEAN); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - condition.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 048b525f7..47c9cf6d8 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 @@ -14,7 +14,6 @@ import gnu.trove.set.hash.TIntHashSet; public abstract class ListQualifier extends Symbol { public abstract void checkType(TypingContext context); - public abstract void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs); public abstract void collectVars(TObjectIntHashMap allVars, TIntHashSet vars); public abstract void collectFreeVariables(THashSet vars); /** 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 5d633d8d0..a802a80ac 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 @@ -26,13 +26,6 @@ public class ListSeq extends ListQualifier { a.checkType(context); b.checkType(context); } - - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - a.collectRefs(allRefs, refs); - b.collectRefs(allRefs, refs); - } @Override public void collectVars(TObjectIntHashMap allVars, 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 451493ba3..e1061564f 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 @@ -47,15 +47,6 @@ public class ListThen extends ListQualifier { } } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - left.collectRefs(allRefs, refs); - transformer.collectRefs(allRefs, refs); - if(by != null) - by.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 new file mode 100644 index 000000000..366dc514b --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectRefsVisitor.java @@ -0,0 +1,56 @@ +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; + +import gnu.trove.map.hash.TObjectIntHashMap; +import gnu.trove.set.hash.TIntHashSet; + +public class CollectRefsVisitor extends StandardExpressionVisitor { + private final TObjectIntHashMap allRefs; + private final TIntHashSet refs; + + public CollectRefsVisitor(TObjectIntHashMap allRefs, TIntHashSet refs) { + this.allRefs = allRefs; + this.refs = refs; + } + + @Override + public void visit(ETransformation expression) { + { + int ref = allRefs.get(ETransformation.TRANSFORMATION_RULES_TYPECHECKED); + if(ref >= 0) + refs.add(ref); + } + super.visit(expression); + } + + @Override + public void visit(EConstant expression) { + int id = allRefs.get(expression.value); + if(id >= 0) + refs.add(id); + } + + @Override + public void visit(QAtom query) { + collectRelationRefs(query.relation); + super.visit(query); + } + + private void collectRelationRefs(SCLRelation relation) { + if(relation instanceof CompositeRelation) { + for(SCLRelation subrelation : ((CompositeRelation) relation).getSubrelations()) + collectRelationRefs(subrelation); + } + else { + int id = allRefs.get(relation); + if(id >= 0) + refs.add(id); + } + } +} 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 52a59585f..459711a8d 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 @@ -74,12 +74,6 @@ public abstract class QAbstractCombiner extends Query { query.checkType(context); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - for(Query query : queries) - query.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { for(Query query : queries) 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 2b6c67711..421bf833e 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 @@ -31,12 +31,6 @@ public abstract class QAbstractModifier extends Query { query.checkType(context); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - query.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 7a20ae3c5..c988aed56 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 @@ -147,27 +147,6 @@ public class QAtom extends Query { } } - private static void collectRefs(SCLRelation relation, TObjectIntHashMap allRefs, - TIntHashSet refs) { - if(relation instanceof CompositeRelation) { - for(SCLRelation subrelation : ((CompositeRelation) relation).getSubrelations()) - collectRefs(subrelation, allRefs, refs); - } - else { - int id = allRefs.get(relation); - if(id >= 0) - refs.add(id); - } - } - - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - collectRefs(relation, allRefs, refs); - for(Expression parameter : parameters) - parameter.collectRefs(allRefs, refs); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { 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 719f474b6..d148339a4 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 @@ -32,13 +32,6 @@ public class QIf extends Query { elseQuery.collectFreeVariables(vars); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - condition.collectRefs(allRefs, refs); - thenQuery.collectRefs(allRefs, refs); - elseQuery.collectRefs(allRefs, refs); - } - @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 12da9da3b..08d72563e 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 @@ -31,13 +31,6 @@ public class QMapping extends Query { parameter.collectFreeVariables(vars); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - for(Expression parameter : parameters) - parameter.collectRefs(allRefs, refs); - } - @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 0b804caf3..7b610756a 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 @@ -14,6 +14,7 @@ import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisi 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.query.compilation.ConstraintCollectionContext; import org.simantics.scl.compiler.elaboration.query.compilation.DerivateException; @@ -37,7 +38,6 @@ public abstract class Query extends Symbol { public static final Query[] EMPTY_ARRAY = new Query[0]; public abstract void collectFreeVariables(THashSet vars); - public abstract void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs); public abstract void collectVars(TObjectIntHashMap allVars, TIntHashSet vars); public abstract void checkType(TypingContext context); @@ -159,4 +159,7 @@ public abstract class Query extends Symbol { public void forVariables(VariableProcedure procedure) { accept(new ForVariablesUsesVisitor(procedure)); } + public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { + accept(new CollectRefsVisitor(allRefs, refs)); + } } 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 dc398f857..859690ec8 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 @@ -40,12 +40,6 @@ public abstract class PreQuery extends Query { throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectConstraints."); } - @Override - public void collectRefs(TObjectIntHashMap allRefs, - TIntHashSet refs) { - throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectRefs."); - } - @Override public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) {