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.Type;
import gnu.trove.map.hash.TObjectIntHashMap;
import gnu.trove.set.hash.THashSet;
right.collectFreeVariables(vars);
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- left.collectEffects(effects);
- right.collectEffects(effects);
- }
-
@Override
public void checkType(TypingContext context) {
left = left.inferType(context);
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.elaboration.expressions.VariableProcedure;
import org.simantics.scl.compiler.errors.Locations;
-import org.simantics.scl.compiler.types.Type;
import gnu.trove.map.hash.TObjectIntHashMap;
import gnu.trove.set.hash.THashSet;
guard.collectFreeVariables(vars);
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- guard.collectEffects(effects);
- }
-
@Override
public void checkType(TypingContext context) {
guard = guard.checkIgnoredType(context);
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 org.simantics.scl.compiler.types.Type;
import gnu.trove.map.hash.TObjectIntHashMap;
import gnu.trove.set.hash.THashSet;
public abstract void setLocationDeep(long loc);
public abstract void collectFreeVariables(THashSet<Variable> vars);
- public abstract void collectEffects(THashSet<Type> effects);
public abstract void checkType(TypingContext context);
public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
public abstract void resolve(TranslationContext context);
throw new InternalCompilerError(getClass().getSimpleName() + " does not support updateType.");
}
- @Override
- final public void collectEffects(THashSet<Type> effects) {
- throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectEffects.");
- }
-
@Override
public void accept(ExpressionVisitor visitor) {
throw new InternalCompilerError(getClass().getSimpleName() + " does not support accept.");
public int getFunctionDefinitionPatternArity() throws NotPatternException {
return expression.getFunctionDefinitionPatternArity();
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- expression.collectEffects(effects);
- }
@Override
public void setLocationDeep(long loc) {
location = loc;
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- // TODO Auto-generated method stub
- }
-
@Override
public void accept(ExpressionVisitor visitor) {
- // TODO Auto-generated method stub
+ visitor.visit(this);
}
@Override
public class EApply extends Expression {
public Expression function;
public Expression[] parameters;
- Type effect = Types.NO_EFFECTS;
+ public Type effect = Types.NO_EFFECTS;
public EApply(Expression function, Expression ... parameters) {
this.function = function;
return function.isConstructorApplication();
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- effects.add(effect);
- function.collectEffects(effects);
- for(Expression parameter : parameters)
- parameter.collectEffects(effects);
- }
-
@Override
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
public boolean isEffectful() {
return expression.isEffectful();
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- expression.collectEffects(effects);
- }
@Override
public void setLocationDeep(long loc) {
return result;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- pattern.collectEffects(effects);
- }
@Override
public void setLocationDeep(long loc) {
return this;
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- pattern.collectEffects(effects);
- value.collectEffects(effects);
- in.collectEffects(effects);
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
import org.simantics.scl.compiler.internal.interpreted.IExpression;
import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
-import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.MatchException;
import gnu.trove.map.hash.TObjectIntHashMap;
in.setLocationDeep(loc);
}
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- ruleset.collectEffects(effects);
- in.collectEffects(effects);
- }
+
@Override
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
import org.simantics.scl.compiler.internal.interpreted.IExpression;
import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
-import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.MatchException;
import gnu.trove.map.hash.TObjectIntHashMap;
}
}
@Override
- public void collectEffects(THashSet<Type> effects) {
- ruleset.collectEffects(effects);
- }
- @Override
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
}
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.codegen.references.IVal;
import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
-import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.kinds.Kinds;
}
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- expression.collectEffects(effects);
- query.collectQueryEffects(effects);
- effects.add(Types.PROC);
- }
-
@Override
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
@Override
public boolean isEffectful() {
- return false;
- }
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
+ return false;
}
@Override
import org.simantics.scl.compiler.elaboration.query.Query;
import org.simantics.scl.compiler.elaboration.query.compilation.EnforcingContext;
import org.simantics.scl.compiler.errors.Locations;
-import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
TIntHashSet vars) {
query.collectVars(allVars, vars);
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
- }
@Override
protected void updateType() throws MatchException {
equation.collectFreeVariables(vars);
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- for(Equation equation : equations)
- equation.collectEffects(effects);
- }
-
@Override
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
public Expression inferType(TypingContext context) {
return this;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- }
@Override
public void setLocationDeep(long loc) {
public Expression inferType(TypingContext context) {
return this;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- }
@Override
public void setLocationDeep(long loc) {
accessor.resolve(context);
return this;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- // FIXME
- effects.add(Types.READ_GRAPH);
- }
@Override
public void setLocationDeep(long loc) {
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.types.TPred;
-import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.MatchException;
import gnu.trove.map.hash.TObjectIntHashMap;
return this;
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
public boolean isEffectful() {
return condition.isEffectful() || then_.isEffectful() || (else_ != null && else_.isEffectful());
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- condition.collectEffects(effects);
- then_.collectEffects(effects);
- if(else_ != null)
- else_.collectEffects(effects);
- }
@Override
public void setLocationDeep(long loc) {
public boolean isEffectful() {
return false;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- }
@Override
public void setLocationDeep(long loc) {
public boolean isEffectful() {
return false;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- for(Case case_ : cases) {
- for(Expression pattern : case_.patterns)
- pattern.collectEffects(effects);
- case_.value.collectEffects(effects);
- }
- }
@Override
public void accept(ExpressionVisitor visitor) {
import org.simantics.scl.compiler.internal.interpreted.IExpression;
import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
import org.simantics.scl.compiler.types.TVar;
-import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
public Expression inferType(TypingContext context) {
throw new InternalCompilerError("Should not type check " + getClass().getSimpleName() + ".");
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- }
@Override
public void setLocationDeep(long loc) {
in = in.checkIgnoredType(context);
return this;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- for(Assignment assignment : assignments) {
- assignment.pattern.collectEffects(effects);
- assignment.value.collectEffects(effects);
- }
- in.collectEffects(effects);
- }
@Override
public void setLocationDeep(long loc) {
return this;
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- head.collectEffects(effects);
- qualifier.collectEffects(effects);
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
return this;
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- for(Expression component : components)
- component.collectEffects(effects);
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
import org.simantics.scl.compiler.internal.interpreted.IConstant;
import org.simantics.scl.compiler.internal.interpreted.IExpression;
import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
-import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
public Expression inferType(TypingContext context) {
return this;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- }
@Override
public void setLocationDeep(long loc) {
setType(Types.UNIT);
return this;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- for(Expression s : scrutinee)
- s.collectEffects(effects);
- for(Case case_ : cases) {
- for(Expression pattern : case_.patterns)
- pattern.collectEffects(effects);
- case_.value.collectEffects(effects);
- }
- }
@Override
public void accept(ExpressionVisitor visitor) {
copy.setType(getType().replace(context.tvarMap));
return copy;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- }
@Override
public void setLocationDeep(long loc) {
}
in.collectVars(allVars, vars);
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
- }
@Override
public Expression resolve(TranslationContext context) {
expression.collectVars(allVars, vars);
query.collectVars(allVars, vars);
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
- }
@Override
protected void updateType() throws MatchException {
return false;
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
in = in.checkIgnoredType(context);
return this;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- value.collectEffects(effects);
- in.collectEffects(effects);
- }
@Override
public void accept(ExpressionVisitor visitor) {
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.elaboration.transformations.TransformationBuilder;
import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
-import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
}
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- effects.add(Types.PROC);
- //seed.collectEffects(Query.RW, effects); // FIXME
- }
-
@Override
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
return value.checkType(context, type);
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- value.collectEffects(effects);
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
return false;
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION)
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.codegen.references.IVal;
import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
-import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.util.MultiFunction;
}
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- expression.collectEffects(effects);
- }
-
@Override
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
package org.simantics.scl.compiler.elaboration.expressions;
-import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
query.collectVars(allVars, vars);
action.collectVars(allVars, vars);
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
- }
@Override
protected void updateType() throws MatchException {
import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType;
import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchingLhs;
import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectEffectsVisitor;
import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectRefsVisitor;
import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor;
import org.simantics.scl.compiler.elaboration.query.QAtom;
return false;
}
- public abstract void collectEffects(THashSet<Type> effects);
-
public Type getEffect() {
- THashSet<Type> effects = new THashSet<Type>();
- collectEffects(effects);
- return Types.union(effects.toArray(new Type[effects.size()]));
+ CollectEffectsVisitor visitor = new CollectEffectsVisitor();
+ accept(visitor);
+ return visitor.getCombinedEffect();
}
public abstract void accept(ExpressionVisitor visitor);
public interface ExpressionVisitor {
+ void visit(EAmbiguous eAmbiguous);
void visit(EApply expression);
void visit(EApplyType expression);
void visit(EAsPattern expression);
newExpressions[i] = expressions[i].replace(context);
return new GuardedExpressionGroup(newExpressions);
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- for(GuardedExpression ge : expressions) {
- for(Expression guard : ge.guards)
- guard.collectEffects(effects);
- ge.value.collectEffects(effects);
- }
- }
@Override
public void setLocationDeep(long loc) {
public void visit(CHRAstNegation query) {
query.subquery.accept(this);
}
+
+ @Override
+ public void visit(EAmbiguous expression) {
+ if(expression.resolvedExpression != null)
+ expression.resolvedExpression.accept(this);
+ }
}
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.Type;
import gnu.trove.map.hash.TObjectIntHashMap;
import gnu.trove.set.hash.THashSet;
pattern = pattern.resolveAsPattern(context);
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- pattern.collectEffects(effects);
- value.collectEffects(effects);
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
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.Types;
import org.simantics.scl.compiler.types.kinds.Kinds;
value = value.resolve(context);
pattern = pattern.resolveAsPattern(context);
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- pattern.collectEffects(effects);
- value.collectEffects(effects);
- }
-
+
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
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.Type;
import org.simantics.scl.compiler.types.Types;
import gnu.trove.map.hash.TObjectIntHashMap;
@Override
public void resolve(TranslationContext context) {
- condition = condition.resolve(context);
+ condition = condition.resolve(context);
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- condition.collectEffects(effects);
- }
-
+
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
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 org.simantics.scl.compiler.types.Type;
import gnu.trove.map.hash.TObjectIntHashMap;
import gnu.trove.set.hash.THashSet;
*/
public abstract CompiledQualifier compile(SimplificationContext context);
public abstract void resolve(TranslationContext context);
- public abstract void collectEffects(THashSet<Type> effects);
public abstract void setLocationDeep(long loc);
public abstract void accept(ListQualifierVisitor visitor);
public abstract ListQualifier accept(ListQualifierTransformer transformer);
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.Type;
import gnu.trove.map.hash.TObjectIntHashMap;
import gnu.trove.set.hash.THashSet;
b.resolve(context);
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- a.collectEffects(effects);
- b.collectEffects(effects);
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
by = by.resolve(context);
}
- @Override
- public void collectEffects(THashSet<Type> effects) {
- left.collectEffects(effects);
- transformer.collectEffects(effects);
- if(by != null)
- by.collectEffects(effects);
- }
-
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
import org.simantics.scl.compiler.elaboration.chr.relations.CHRConstraint;
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;
}
b.append('"');
}
+
+ @Override
+ public void visit(EAmbiguous eAmbiguous) {
+ b.append("EAmbigious");
+ }
}
--- /dev/null
+package org.simantics.scl.compiler.elaboration.expressions.visitors;
+
+import org.simantics.scl.compiler.elaboration.expressions.EApply;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect;
+import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess;
+import org.simantics.scl.compiler.elaboration.expressions.ELambda;
+import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda;
+import org.simantics.scl.compiler.elaboration.expressions.ETransformation;
+import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisitor;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+
+import gnu.trove.set.hash.THashSet;
+
+public class CollectEffectsVisitor extends StandardExpressionVisitor {
+ public final THashSet<Type> effects = new THashSet<Type>();
+
+ @Override
+ public void visit(EApply expression) {
+ effects.add(expression.effect);
+ super.visit(expression);
+ }
+
+ @Override
+ public void visit(ECHRRuleset expression) {
+ effects.add(Types.PROC);
+ super.visit(expression);
+ }
+
+ @Override
+ public void visit(ECHRSelect expression) {
+ effects.add(Types.PROC);
+ super.visit(expression);
+ }
+
+ @Override
+ public void visit(EFieldAccess expression) {
+ // FIXME
+ effects.add(Types.READ_GRAPH);
+ super.visit(expression);
+ }
+
+ @Override
+ public void visit(ETransformation expression) {
+ // FIXME
+ effects.add(Types.PROC);
+ super.visit(expression);
+ }
+
+ @Override
+ public void visit(ELambda expression) {
+ }
+
+ @Override
+ public void visit(ESimpleLambda expression) {
+ }
+
+ public Type getCombinedEffect() {
+ return Types.union(effects.toArray(new Type[effects.size()]));
+ }
+}