import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
-import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.errors.Locations;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EqBasic extends Equation {
public Expression left;
public Expression right;
right = right.checkType(context, left.getType());
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- left.collectVars(allVars, vars);
- right.collectVars(allVars, vars);
- }
-
@Override
public void resolve(TranslationContext context) {
left = left.resolve(context);
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
-import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.errors.Locations;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EqGuard extends Equation {
public Expression guard;
guard = guard.checkIgnoredType(context);
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- guard.collectVars(allVars, vars);
- }
-
@Override
public void resolve(TranslationContext context) {
guard = guard.resolve(context);
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.internal.parsing.Symbol;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public abstract class Equation extends Symbol {
public static final Equation[] EMPTY_ARRAY = new Equation[0];
public abstract void setLocationDeep(long loc);
public abstract void checkType(TypingContext context);
- public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
public abstract void resolve(TranslationContext context);
public abstract void accept(EquationVisitor visitor);
public abstract Equation replace(ReplaceContext context);
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public abstract class ASTExpression extends SimplifiableExpression {
public ASTExpression() {
}
throw new InternalCompilerError(getClass().getSimpleName() + " does not support simplify.");
}
- @Override
- final public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectVars.");
- }
-
@Override
final protected void updateType() throws MatchException {
throw new InternalCompilerError(getClass().getSimpleName() + " does not support updateType.");
import org.simantics.scl.compiler.internal.parsing.Symbol;
import org.simantics.scl.compiler.types.Type;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class Case extends Symbol {
public Expression[] patterns;
public Expression value;
return lhs;
}
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- }
-
public void resolve(TranslationContext context) {
context.pushFrame();
for(int i=0;i<patterns.length;++i)
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public abstract class DecoratingExpression extends SimplifiableExpression {
public Expression expression;
super(loc);
this.expression = expression;
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- expression.collectVars(allVars, vars);
- }
@Override
protected void updateType() throws MatchException {
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
public class EAmbiguous extends SimplifiableExpression {
public static final boolean DEBUG = false;
this.activeCount = alternatives.length;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
-
@Override
protected void updateType() throws MatchException {
throw new InternalCompilerError();
import org.simantics.scl.compiler.types.kinds.Kinds;
import org.simantics.scl.compiler.types.util.MultiFunction;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EApply extends Expression {
public Expression function;
public Expression[] parameters;
public Expression[] getParameters() {
return parameters;
}
-
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- function.collectVars(allVars, vars);
- for(Expression parameter : parameters)
- parameter.collectVars(allVars, vars);
- }
-
- @Override
- protected void updateType() throws MatchException {
+
+ @Override
+ protected void updateType() throws MatchException {
MultiFunction mfun = Types.matchFunction(function.getType(), parameters.length);
/*for(int i=0;i<parameters.length;++i)
if(!Types.equals(parameters[i].getType(), mfun.parameterTypes[i]))
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EApplyType extends Expression {
public Expression expression;
Type parameter;
return parameter;
}
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- expression.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(Types.instantiate(expression.getType(), parameter));
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EAsPattern extends Expression {
public Variable var;
public Expression getPattern() {
return pattern;
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- int id = allVars.get(var);
- if(id >= 0)
- vars.add(id);
- pattern.collectVars(allVars, vars);
- }
@Override
public Expression simplify(SimplificationContext context) {
import org.simantics.scl.compiler.types.exceptions.UnificationException;
import org.simantics.scl.compiler.types.kinds.Kinds;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EBind extends SimplifiableExpression {
public Expression pattern;
public Expression value;
this.in = in;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- in.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(in.getType());
import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ECHRRuleset extends Expression {
public CHRRuleset ruleset;
public Expression in;
this.ruleset = ruleset;
this.in = in;
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- ruleset.collectVars(allVars, vars);
- in.collectVars(allVars, vars);
- }
@Override
protected void updateType() throws MatchException {
import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ECHRRulesetConstructor extends Expression {
public CHRRuleset ruleset;
this.ruleset = ruleset;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- ruleset.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given.");
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.kinds.Kinds;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ECHRSelect extends Expression {
public CHRQuery query;
public Variable[] existentialVariables;
this.query = query;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- query.collectVars(allVars, vars);
- expression.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(Types.list(expression.getType()));
import org.simantics.scl.compiler.types.util.MultiFunction;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EConstant extends Expression {
public SCLValue value;
Type[] typeParameters;
setType(Types.instantiate(getType(), type));
return this;
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
@Override
public Set<Variable> getFreeVariables() {
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EEnforce extends SimplifiableExpression {
public Query query;
return query;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- query.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(Types.tupleConstructor(0));
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EEquations extends SimplifiableExpression {
public Equation[] equations;
return transformer.transform(this);
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- for(Equation equation : equations)
- equation.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(Types.UNIT);
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.kinds.Kinds;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EError extends Expression {
public EError(long loc, Type type) {
this(loc, Types.metaVar(Kinds.STAR));
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
-
@Override
protected void updateType() throws MatchException {
setType(Types.metaVar(Kinds.STAR));
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EExternalConstant extends Expression {
Object value;
return value;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
-
public void toString(StringBuilder b, TypeUnparsingContext tuc) {
b.append(value);
}
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EFieldAccess extends SimplifiableExpression {
private static final Type VARIABLE = Types.con("Simantics/Variables", "Variable");
((EFieldAccess)parent).lastAccessor = false;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- parent.collectVars(allVars, vars);
- accessor.collectVars(allVars, vars);
- }
-
private boolean returnsValue() {
return accessor.accessSeparator == '#' && !accessor.isVariableId();
}
import org.simantics.scl.compiler.types.TPred;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EGetConstraint extends SimplifiableExpression {
TPred constraint;
public EVariable evidence;
this.constraint = constraint;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- if(evidence != null)
- evidence.collectVars(allVars, vars);
- }
-
@Override
public Expression inferType(TypingContext context) {
Variable variable = new Variable("evidence");
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.runtime.tuple.Tuple0;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EIf extends Expression {
public Expression condition;
public Expression then_;
this.else_ = else_;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> 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());
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EIntegerLiteral extends SimplifiableExpression {
public String value;
public EVariable constraint;
public EIntegerLiteral(String value) {
this.value = value;
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
public String getValue() {
return value;
import org.simantics.scl.compiler.types.kinds.Kinds;
import org.simantics.scl.compiler.types.util.MultiFunction;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ELambda extends SimplifiableExpression {
public Case[] cases;
Type effect = Types.NO_EFFECTS;
this(loc, new Case(new Expression[] {pat}, exp));
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(Case case_ : cases)
- case_.collectVars(allVars, vars);
- }
-
public Expression decomposeMatching() {
Expression[] patterns = cases[0].patterns;
int arity = patterns.length;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ELambdaType extends Expression {
public TVar[] parameters;
public Expression value;
this.value = value;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(Types.forAll(parameters, value.getType()));
this.in = in;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(Assignment assign : assignments)
- assign.value.collectVars(allVars, vars);
- in.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(in.getType());
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EListComprehension extends SimplifiableExpression {
public Expression head;
this.head = head;
this.qualifier = qualifier;
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- head.collectVars(allVars, vars);
- qualifier.collectVars(allVars, vars);
- }
@Override
public Expression checkBasicType(TypingContext context, Type requiredType) {
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EListLiteral extends SimplifiableExpression {
public Expression[] components;
public Expression[] getComponents() {
return components;
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(Expression component : components)
- component.collectVars(allVars, vars);
- }
@Override
public Expression simplify(SimplificationContext context) {
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ELiteral extends Expression {
Constant value;
public Constant getValue() {
return value;
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
@Override
public Set<Variable> getFreeVariables() {
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.kinds.Kinds;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EMatch extends Expression {
public Expression[] scrutinee;
this.cases = cases;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(Expression s : scrutinee)
- s.collectVars(allVars, vars);
- for(Case case_ : cases)
- case_.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() {
setType(cases[0].value.getType());
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ERealLiteral extends SimplifiableExpression {
public String value;
public EVariable constraint;
this.value = value;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
-
private Expression tryToConvertToPrimitive(ErrorLog errorLog, Type requiredType) {
if(requiredType.equals(Types.DOUBLE))
return new ELiteral(new DoubleConstant(Double.parseDouble(value)));
in = in.checkIgnoredType(context);
return compile(context);
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(DatalogRule rule : rules) {
- for(Expression parameter : rule.headParameters)
- parameter.collectVars(allVars, vars);
- rule.body.collectVars(allVars, vars);
- }
- in.collectVars(allVars, vars);
- }
@Override
public Expression resolve(TranslationContext context) {
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.kinds.Kinds;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ESelect extends SimplifiableExpression {
private final Type ARRAY_LIST = Types.con("ArrayList", "T");
this.query = query;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- expression.collectVars(allVars, vars);
- query.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(selectVariant==SCLTerminals.SELECT_FIRST
import org.simantics.scl.compiler.types.kinds.Kinds;
import org.simantics.scl.compiler.types.util.MultiFunction;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ESimpleLambda extends Expression {
public Variable parameter;
public Expression value;
this.effect = effect;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- }
-
public Expression decomposeMatching() {
value = value.decomposeMatching();
return this;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ESimpleLet extends Expression {
public Variable variable; // may be null
public Expression value;
this.in = in;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- in.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(in.getType());
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ETransformation extends SimplifiableExpression {
public static final Object TRANSFORMATION_RULES_TYPECHECKED = new Object();
this.seed = seed;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- seed.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(Types.UNIT);
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ETypeAnnotation extends SimplifiableExpression {
public Expression value;
Type type;
this.type = type;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(type);
import org.simantics.scl.compiler.types.kinds.Kinds;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EVariable extends Expression {
public static final EVariable[] EMPTY_ARRAY = new EVariable[0];
this.variable = variable;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- int id = allVars.get(variable);
- if(id >= 0)
- vars.add(id);
- }
-
@Override
public Set<Variable> getFreeVariables() {
if(variable == null)
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.util.MultiFunction;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EViewPattern extends Expression {
public Expression expression;
public Expression pattern;
this.expression = expression;
this.pattern = pattern;
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- expression.collectVars(allVars, vars);
- pattern.collectVars(allVars, vars);
- }
@Override
public Expression inferType(TypingContext context) {
import org.simantics.scl.compiler.types.exceptions.UnificationException;
import org.simantics.scl.compiler.types.kinds.Kinds;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EWhen extends SimplifiableExpression {
public Query query;
this.variables = variables;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- query.collectVars(allVars, vars);
- action.collectVars(allVars, vars);
- }
-
@Override
protected void updateType() throws MatchException {
setType(Types.UNIT);
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.CollectVarsVisitor;
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;
accept(new CollectRefsVisitor(allRefs, refs));
}
- public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
+ public final void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
+ accept(new CollectVarsVisitor(allVars, vars));
+ }
public final void forVariableUses(VariableProcedure procedure) {
accept(new ForVariablesUsesVisitor(procedure));
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class GuardedExpressionGroup extends Expression {
public GuardedExpression[] expressions;
this.expressions = expressions;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(GuardedExpression expression : expressions) {
- for(Expression guard : expression.guards)
- guard.collectVars(allVars, vars);
- expression.value.collectVars(allVars, vars);
- }
- }
-
@Override
protected void updateType() throws MatchException {
setType(expressions[0].value.getType());
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
-import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.types.Types;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ExpressionAccessor extends FieldAccessor {
public Expression fieldName;
this.fieldName = fieldName;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- fieldName.collectVars(allVars, vars);
- }
-
@Override
public void resolve(TranslationContext context) {
fieldName = fieldName.resolve(context);
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
-import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.internal.parsing.Symbol;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
public abstract class FieldAccessor extends Symbol {
public char accessSeparator;
this.accessSeparator = accessSeparator;
}
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
-
- public void collectFreeVariables(THashSet<Variable> vars) {
- }
-
public void simplify(SimplificationContext context) {
}
public void resolve(TranslationContext context) {
}
- public void checkType(TypingContext context) {
+ public void checkType(TypingContext context) {
}
public abstract Expression asExpression();
import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.errors.Locations;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ListAssignment extends ListQualifier {
public Expression pattern;
public Expression value;
pattern.checkTypeAsPattern(context, value.getType());
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- }
-
@Override
public CompiledQualifier compile(SimplificationContext context) {
if(pattern instanceof EVariable)
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.kinds.Kinds;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ListGenerator extends ListQualifier {
public Expression pattern;
public Expression value;
pattern.checkTypeAsPattern(context, componentType);
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- }
-
@Override
public CompiledQualifier compile(SimplificationContext context) {
if(pattern instanceof EVariable)
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
-import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.types.Types;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ListGuard extends ListQualifier {
public Expression condition;
condition.checkType(context, Types.BOOLEAN);
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- condition.collectVars(allVars, vars);
- }
-
@Override
public CompiledQualifier compile(SimplificationContext context) {
return new CompiledQualifier(
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.elaboration.expressions.Variable;
import org.simantics.scl.compiler.internal.parsing.Symbol;
-import gnu.trove.map.hash.TObjectIntHashMap;
-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);
/**
* Called in simplification.
*/
import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.errors.Locations;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ListSeq extends ListQualifier {
public ListQualifier a;
public ListQualifier b;
b.checkType(context);
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- a.collectVars(allVars, vars);
- b.collectVars(allVars, vars);
- }
-
@Override
public CompiledQualifier compile(SimplificationContext context) {
CompiledQualifier cA = a.compile(context);
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
-import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.types.TMetaVar;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.UnificationException;
import org.simantics.scl.compiler.types.kinds.Kinds;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class ListThen extends ListQualifier {
public ListQualifier left;
public Expression transformer;
}
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- left.collectVars(allVars, vars);
- transformer.collectVars(allVars, vars);
- if(by != null)
- by.collectVars(allVars, vars);
- }
-
@Override
public CompiledQualifier compile(SimplificationContext context) {
CompiledQualifier q = left.compile(context);
--- /dev/null
+package org.simantics.scl.compiler.elaboration.expressions.visitors;
+
+import org.simantics.scl.compiler.elaboration.expressions.EAsPattern;
+import org.simantics.scl.compiler.elaboration.expressions.EVariable;
+import org.simantics.scl.compiler.elaboration.expressions.Variable;
+
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.TIntHashSet;
+
+public class CollectVarsVisitor extends StandardExpressionVisitor {
+ private final TObjectIntHashMap<Variable> allVars;
+ private final TIntHashSet vars;
+
+ public CollectVarsVisitor(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
+ this.allVars = allVars;
+ this.vars = vars;
+ }
+
+ @Override
+ public void visit(EVariable expression) {
+ if(expression.variable != null) {
+ int id = allVars.get(expression.variable);
+ if(id >= 0)
+ vars.add(id);
+ }
+ }
+
+ @Override
+ public void visit(EAsPattern expression) {
+ int id = allVars.get(expression.var);
+ if(id >= 0)
+ vars.add(id);
+ expression.pattern.accept(this);
+ }
+}
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.scl.compiler.elaboration.expressions.EVar;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
-import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.elaboration.query.pre.QPreExists;
import org.simantics.scl.compiler.elaboration.query.pre.QPreGuard;
import org.simantics.scl.compiler.errors.Locations;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public abstract class QAbstractCombiner extends Query {
public Query[] queries;
query.checkType(context);
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- for(Query query : queries)
- query.collectVars(allVars, vars);
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
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.errors.Locations;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public abstract class QAbstractModifier extends Query {
public Query query;
query.checkType(context);
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- query.collectVars(allVars, vars);
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TIntObjectHashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
import gnu.trove.set.hash.TIntHashSet;
public class QAtom extends Query {
}
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(Expression parameter : parameters)
- parameter.collectVars(allVars, vars);
- }
-
@Override
public Query replace(ReplaceContext context) {
Type[] newTypeParameters;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
import org.simantics.scl.compiler.elaboration.expressions.QueryTransformer;
-import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
import org.simantics.scl.compiler.elaboration.query.compilation.UnsolvableQueryException;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.types.Types;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class QIf extends Query {
public Expression condition;
public Query thenQuery;
this.thenQuery = thenQuery;
this.elseQuery = elseQuery;
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- condition.collectVars(allVars, vars);
- thenQuery.collectVars(allVars, vars);
- elseQuery.collectVars(allVars, vars);
- }
-
+
@Override
public void checkType(TypingContext context) {
condition.checkType(context, Types.BOOLEAN);
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
import org.simantics.scl.compiler.elaboration.expressions.QueryTransformer;
-import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
import org.simantics.scl.compiler.elaboration.query.compilation.UnsolvableQueryException;
import org.simantics.scl.compiler.elaboration.rules.MappingRelation;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.types.Type;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
public class QMapping extends Query {
public final MappingRelation mappingRelation;
public final Expression[] parameters;
this.parameters = parameters;
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(Expression parameter : parameters)
- parameter.collectVars(allVars, vars);
- }
-
@Override
public void checkType(TypingContext context) {
// Check parameter types
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.CollectVarsVisitor;
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;
public abstract class Query extends Symbol {
public static final Query[] EMPTY_ARRAY = new Query[0];
- public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
public abstract void checkType(TypingContext context);
public Query resolve(TranslationContext context) {
public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
accept(new CollectRefsVisitor(allRefs, refs));
}
+
+ public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
+ accept(new CollectVarsVisitor(allVars, vars));
+ }
}
import org.simantics.scl.compiler.elaboration.query.QueryVisitor;
import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
/**
* Query classes that may exist before resolving
*/
throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectConstraints.");
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectVars.");
- }
-
@Override
public Query replace(ReplaceContext replaceContext) {
throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support replace.");