parameter.collectVars(allVars, vars);
}
- public void collectFreeVariables(THashSet<Variable> 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;
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;
for(CHRLiteral literal : literals)
literal.collectVars(allVars, vars);
}
-
- public void collectFreeVariables(THashSet<Variable> 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;
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 {
body.collectVars(allVars, vars);
}
- public void collectFreeVariables(THashSet<Variable> vars) {
- head.collectFreeVariables(vars);
- body.collectFreeVariables(vars);
- }
-
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
this.location = loc;
rule.collectVars(allVars, vars);
}
- public void collectFreeVariables(THashSet<Variable> 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;
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 {
}
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- left.collectFreeVariables(vars);
- right.collectFreeVariables(vars);
- }
-
@Override
public void checkType(TypingContext context) {
left = left.inferType(context);
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 {
}
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- guard.collectFreeVariables(vars);
- }
-
@Override
public void checkType(TypingContext context) {
guard = guard.checkIgnoredType(context);
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 {
public abstract void setLocationDeep(long loc);
- public abstract void collectFreeVariables(THashSet<Variable> vars);
public abstract void checkType(TypingContext context);
public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
public abstract void resolve(TranslationContext context);
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 {
throw new InternalCompilerError(getClass().getSimpleName() + " does not support simplify.");
}
- @Override
- final public void collectFreeVariables(THashSet<Variable> vars) {
- throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectFreeVariables.");
- }
-
@Override
final public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
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 {
value.collectVars(allVars, vars);
}
- public void collectFreeVariables(THashSet<Variable> 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<patterns.length;++i)
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 DecoratingExpression extends SimplifiableExpression {
setType(expression.getType());
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- expression.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
expression = expression.simplify(context);
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 {
boolean[] active;
int activeCount;
transient TypingContext context;
- Expression resolvedExpression;
+ public Expression resolvedExpression;
public abstract static class Alternative {
public abstract Type getType();
listenType();
return this;
}
-
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- }
@Override
public Expression resolve(TranslationContext context) {
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 {
effect = Types.simplifyFinalEffect(effect);
return w.applyWithEffect(location, effect, type, functionVal, parameterVals);
}
-
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- function.collectFreeVariables(vars);
- for(Expression parameter : parameters)
- parameter.collectFreeVariables(vars);
- }
private void combineApplications() {
if(function instanceof EApply) {
for(Expression parameter : this.parameters)
parameters.add(parameter);
}
-
- @Override
- public void removeFreeVariables(THashSet<Variable> vars) {
- function.removeFreeVariables(vars);
- for(Expression parameter : parameters)
- parameter.removeFreeVariables(vars);
- }
@Override
public Expression replace(ReplaceContext context) {
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) {
return val.createSpecialization(parameter);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- expression.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
expression = expression.simplify(context);
expression = expression.resolve(context);
return this;
}
-
- @Override
- public void removeFreeVariables(THashSet<Variable> vars) {
- expression.removeFreeVariables(vars);
- }
@Override
public Expression replace(ReplaceContext context) {
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 {
vars.add(id);
pattern.collectVars(allVars, vars);
}
-
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- throw new InternalCompilerError(location, "Cannot collect free variables for a pattern.");
- }
-
- @Override
- public void removeFreeVariables(THashSet<Variable> vars) {
- vars.remove(var);
- pattern.removeFreeVariables(vars);
- }
@Override
public Expression simplify(SimplificationContext context) {
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;
return simplified.simplify(context);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- in.collectFreeVariables(vars);
- value.collectFreeVariables(vars);
- pattern.removeFreeVariables(vars);
- }
-
@Override
public Expression resolve(TranslationContext context) {
value = value.resolve(context);
public class EBlock extends ASTExpression {
- ArrayList<Statement> statements = new ArrayList<Statement>();
+ public ArrayList<Statement> statements = new ArrayList<Statement>();
boolean monadic;
public EBlock() {
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;
return in.toVal(context, w);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- ruleset.collectFreeVariables(vars);
- in.collectFreeVariables(vars);
- }
-
@Override
public Expression resolve(TranslationContext context) {
if(context.currentRuleset != null) {
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;
return ruleset.generateCode(w);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- ruleset.collectFreeVariables(vars);
- }
-
@Override
public Expression resolve(TranslationContext context) {
context.pushFrame();
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<PlanOp> planOps;
private CHRRuleset currentRuleset;
return w.apply(location, context.getValue(Names.MList_freeze).getValue(), list);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> 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;
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;
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 {
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
}
+
+ @Override
+ public Set<Variable> getFreeVariables() {
+ return Collections.emptySet();
+ }
public void toString(StringBuilder b, TypeUnparsingContext tuc) {
Name name = value.getName();
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<Variable> vars) {
+ public IVal toVal(CompilationContext context, CodeWriter w) {
+ IVal val = value.getValue();
+ if(typeParameters.length > 0) {
+ val = val.createSpecialization(typeParameters);
+ }
+ return val;
}
@Override
public Expression resolveAsPattern(TranslationContext context) {
return this;
}
-
- @Override
- public void removeFreeVariables(THashSet<Variable> vars) {
- }
@Override
public Expression replace(ReplaceContext context) {
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;
return query.generateEnforce(new EnforcingContext(context));
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- query.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
/*query = query.simplify(context);
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 {
setType(Types.UNIT);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- for(Equation equation : equations)
- equation.collectFreeVariables(vars);
- }
-
@Override
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
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 {
throw new UnsupportedOperationException();
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- }
-
@Override
public Expression simplify(SimplificationContext context) {
return this;
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 {
return mw.getExternalConstant(value, getType());
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- }
-
-
@Override
public Expression simplify(SimplificationContext context) {
return this;
return new EExternalConstant(value, getType().replace(context.tvarMap));
}
- @Override
- public void removeFreeVariables(THashSet<Variable> vars) {
- }
-
@Override
public Expression inferType(TypingContext context) {
return this;
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) {
return this;
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- parent.collectFreeVariables(vars);
- accessor.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
// Simplify subexpressions
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);
setType(constraint);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- if(evidence != null)
- evidence.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
return evidence.simplify(context);
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 {
return w.getParameters()[0];
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- condition.collectFreeVariables(vars);
- then_.collectFreeVariables(vars);
- if(else_ != null)
- else_.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
condition = condition.simplify(context);
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;
throw new InternalCompilerError();
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- }
-
@Override
public Expression simplify(SimplificationContext context) {
try {
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 {
return decomposeMatching().simplify(context);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- for(Case case_ : cases)
- case_.collectFreeVariables(vars);
- }
-
@Override
public Expression resolve(TranslationContext context) {
for(Case case_ : cases)
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 {
return lambdaToVal(context, w);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- value.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
value = value.simplify(context);
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;
/**
return result;
}
- @Override
- public void collectFreeVariables(THashSet<Variable> 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.");
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 {
setType(Types.list(head.getType()));
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- head.collectFreeVariables(vars);
- qualifier.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
context.pushLocation(location);
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) {
component.collectVars(allVars, vars);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- for(Expression component : components)
- component.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
context.pushLocation(location);
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;
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 {
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
}
+
+ @Override
+ public Set<Variable> getFreeVariables() {
+ return Collections.emptySet();
+ }
public void toString(StringBuilder b, TypeUnparsingContext tuc) {
b.append(value);
return value;
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- }
-
-
@Override
public Expression simplify(SimplificationContext context) {
return this;
return new ELiteral(value);
}
- @Override
- public void removeFreeVariables(THashSet<Variable> vars) {
- }
-
@Override
public IExpression toIExpression(ExpressionInterpretationContext target) {
return new IConstant(value.realizeValue(target.localClassBuilder));
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 {
w.continueAs(joinPoint);
return w.getParameters()[0];
}
-
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- for(Expression s : scrutinee)
- s.collectFreeVariables(vars);
- for(Case case_ : cases)
- case_.collectFreeVariables(vars);
- }
@Override
public Expression simplify(SimplificationContext context) {
*/
public class EPreLet extends ASTExpression {
- List<LetStatement> assignments;
- Expression in;
+ public List<LetStatement> assignments;
+ public Expression in;
public EPreLet(List<LetStatement> assignments, Expression in) {
this.assignments = assignments;
public class EPreRuleset extends ASTExpression {
- RuleStatement[] statements;
- Expression in;
+ public RuleStatement[] statements;
+ public Expression in;
public EPreRuleset(RuleStatement[] statements, Expression in) {
this.statements = statements;
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;
protected void updateType() throws MatchException {
throw new InternalCompilerError("TODO");
}
-
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- }
@Override
public Expression simplify(SimplificationContext context) {
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;
in = in.checkIgnoredType(context);
return compile(context);
}
-
- @Override
- public void collectFreeVariables(THashSet<Variable> 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<Variable> allVars,
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 {
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;
return loc(location, result);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- expression.collectFreeVariables(vars);
- query.collectFreeVariables(vars);
- for(Variable variable : variables)
- vars.remove(variable);
- }
-
@Override
public Expression resolve(TranslationContext context) {
context.pushExistentialFrame();
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;
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 {
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<Variable> vars) {
- value.collectFreeVariables(vars);
- vars.remove(parameter);
+ public IVal toVal(CompilationContext context, CodeWriter w) {
+ return lambdaToVal(context, w);
}
@Override
// Free variables;
ExpressionInterpretationContext innerContext = context.createNewContext();
- THashSet<Variable> freeVariables = cur.getFreeVariables();
+ Set<Variable> freeVariables = cur.getFreeVariables();
for(Variable parameter : parameters)
freeVariables.remove(parameter);
int i=0;
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)
return in.toVal(context, w);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- value.collectFreeVariables(vars);
- in.collectFreeVariables(vars);
- vars.remove(variable);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
value = value.simplify(context);
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 {
protected void updateType() throws MatchException {
setType(Types.UNIT);
}
-
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- seed.collectFreeVariables(vars);
- }
@Override
public Expression inferType(TypingContext context) {
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;
setType(type);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- value.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
return value.simplify(context);
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;
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 {
if(id >= 0)
vars.add(id);
}
+
+ @Override
+ public Set<Variable> 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<Variable> vars) {
- vars.add(variable);
+ public IVal toVal(CompilationContext context, CodeWriter w) {
+ return variable.getVal();
}
@Override
ArrayList<Expression> parameters) {
}
- @Override
- public void removeFreeVariables(THashSet<Variable> vars) {
- vars.remove(variable);
- }
-
@Override
public Expression resolveAsPattern(TranslationContext context) {
return this;
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 {
throw new InternalCompilerError(location, "EViewPattern.toVal should not be invoked.");
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- throw new InternalCompilerError(location, "Cannot collect free variables for a pattern.");
- }
-
- @Override
- public void removeFreeVariables(THashSet<Variable> 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?");
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;
}
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- action.collectFreeVariables(vars);
- query.collectFreeVariables(vars);
- for(Variable var : variables)
- vars.remove(var);
- }
-
@Override
public Expression resolve(TranslationContext context) {
context.pushExistentialFrame();
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;
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;
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 {
return new ELambdaType(vars, this);
}
- public abstract void collectFreeVariables(THashSet<Variable> vars);
-
public Expression simplify(SimplificationContext context) {
System.out.println("#############################");
System.out.println(this);
context.getErrorLog().log(location, "Pattern was expected here.");
return new EError();
}
-
- public void removeFreeVariables(THashSet<Variable> vars) {
- throw new InternalCompilerError(getClass().getSimpleName() + " is not a pattern.");
- }
public Expression checkTypeAsPattern(TypingContext context, Type requiredType) {
if(context.isInPattern())
/**
* Used during simplification and in toIExpression
*/
- public THashSet<Variable> getFreeVariables() {
- THashSet<Variable> result = new THashSet<Variable>();
- collectFreeVariables(result);
- return result;
+ public Set<Variable> getFreeVariables() {
+ CollectFreeVariablesVisitor visitor = new CollectFreeVariablesVisitor();
+ accept(visitor);
+ return visitor.getFreeVariables();
}
public static Expression[] concat(Expression[] a, Expression[] b) {
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 {
//throw new InternalCompilerError("GuardedExpressionGroup should be handled in match compilation.");
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- for(GuardedExpression expression : expressions) {
- for(Expression guard : expression.guards)
- guard.collectFreeVariables(vars);
- expression.value.collectFreeVariables(vars);
- }
- }
-
@Override
public Expression simplify(SimplificationContext context) {
for(GuardedExpression expression : expressions) {
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 {
this.fieldName = fieldName;
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- fieldName.collectFreeVariables(vars);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
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;
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 {
value.collectVars(allVars, vars);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> 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<Variable> variables = pattern.getFreeVariables();
+ Set<Variable> variables = pattern.getFreeVariables();
Variable[] variableArray = variables.toArray(new Variable[variables.size()]);
Expression[] variableExps = new Expression[variableArray.length];
for(int i=0;i<variableArray.length;++i)
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;
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 ListGenerator extends ListQualifier {
value.collectVars(allVars, vars);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- value.collectFreeVariables(vars);
- pattern.collectFreeVariables(vars);
- }
-
@Override
public CompiledQualifier compile(SimplificationContext context) {
if(pattern instanceof EVariable)
return new CompiledQualifier(value, pattern);
else {
- THashSet<Variable> variables = pattern.getFreeVariables();
+ Set<Variable> variables = pattern.getFreeVariables();
Variable[] variableArray = variables.toArray(new Variable[variables.size()]);
Expression[] variableExps = new Expression[variableArray.length];
for(int i=0;i<variableArray.length;++i)
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 ListGuard extends ListQualifier {
condition.collectVars(allVars, vars);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- condition.collectFreeVariables(vars);
- }
-
@Override
public CompiledQualifier compile(SimplificationContext context) {
return new CompiledQualifier(
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<Variable> allVars, TIntHashSet vars);
- public abstract void collectFreeVariables(THashSet<Variable> vars);
/**
* Called in simplification.
*/
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 {
b.collectVars(allVars, vars);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- b.collectFreeVariables(vars);
- a.collectFreeVariables(vars);
- }
-
@Override
public CompiledQualifier compile(SimplificationContext context) {
CompiledQualifier cA = a.compile(context);
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 {
by.collectVars(allVars, vars);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- left.collectFreeVariables(vars);
- transformer.collectFreeVariables(vars);
- if(by != null)
- by.collectFreeVariables(vars);
- }
-
@Override
public CompiledQualifier compile(SimplificationContext context) {
CompiledQualifier q = left.compile(context);
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;
--- /dev/null
+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<Variable> freeVariables = new THashSet<Variable>();
+
+ 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<Variable> getFreeVariables() {
+ return freeVariables;
+ }
+}
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 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 {
-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;
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;
-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;
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;
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);
}
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 {
public QAbstractCombiner(Query[] queries) {
this.queries = queries;
}
-
- public void collectFreeVariables(THashSet<Variable> vars) {
- for(Query query : queries)
- query.collectFreeVariables(vars);
- }
@Override
public Query resolve(TranslationContext context) {
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 {
public QAbstractModifier(Query query) {
this.query = query;
}
-
- public void collectFreeVariables(THashSet<Variable> vars) {
- query.collectFreeVariables(vars);
- }
@Override
public Query resolve(TranslationContext context) {
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 {
this.parameters = parameters;
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- for(Expression parameter : parameters)
- parameter.collectFreeVariables(vars);
- }
-
@Override
public void checkType(TypingContext context) {
// Type parameters
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);
this(variables.toArray(new Variable[variables.size()]), query);
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- super.collectFreeVariables(vars);
- for(Variable variable : variables)
- vars.remove(variable);
- }
-
@Override
public void checkType(TypingContext context) {
for(Variable var : variables)
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 {
this.elseQuery = elseQuery;
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- condition.collectFreeVariables(vars);
- thenQuery.collectFreeVariables(vars);
- elseQuery.collectFreeVariables(vars);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
condition.collectVars(allVars, vars);
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 {
this.parameters = parameters;
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- for(Expression parameter : parameters)
- parameter.collectFreeVariables(vars);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
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;
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<Variable> vars);
public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
public abstract void checkType(TypingContext context);
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;
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;
/**
public ArrayList<Variable> extraVariables = new ArrayList<Variable>(2);
public ArrayList<Query> sideQueries = new ArrayList<Query>(2);
-
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectFreeVariables.");
- }
@Override
public void checkType(TypingContext context) {
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;
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;
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;