1 package org.simantics.scl.compiler.elaboration.expressions;
\r
3 import gnu.trove.map.hash.TObjectIntHashMap;
\r
4 import gnu.trove.set.hash.THashSet;
\r
5 import gnu.trove.set.hash.TIntHashSet;
\r
7 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
\r
8 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
\r
9 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
\r
10 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
\r
11 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
\r
12 import org.simantics.scl.compiler.elaboration.query.QExists;
\r
13 import org.simantics.scl.compiler.elaboration.query.Query;
\r
14 import org.simantics.scl.compiler.elaboration.query.compilation.EnforcingContext;
\r
15 import org.simantics.scl.compiler.errors.Locations;
\r
16 import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
\r
17 import org.simantics.scl.compiler.types.Type;
\r
18 import org.simantics.scl.compiler.types.Types;
\r
19 import org.simantics.scl.compiler.types.exceptions.MatchException;
\r
21 public class EEnforce extends SimplifiableExpression {
\r
25 public EEnforce(Query query) {
\r
29 public Query getQuery() {
\r
34 public void collectRefs(TObjectIntHashMap<Object> allRefs,
\r
36 query.collectRefs(allRefs, refs);
\r
40 public void collectVars(TObjectIntHashMap<Variable> allVars,
\r
42 query.collectVars(allVars, vars);
\r
46 public void collectEffects(THashSet<Type> effects) {
\r
47 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
\r
51 protected void updateType() throws MatchException {
\r
52 setType(Types.tupleConstructor(0));
\r
56 public Expression inferType(TypingContext context) {
\r
57 query.checkType(context);
\r
58 //context.declareEffect(location, query.getEffect(Query.W));
\r
59 return compile(context);
\r
62 public Expression compile(TypingContext context) {
\r
63 return query.generateEnforce(new EnforcingContext(context));
\r
67 public void collectFreeVariables(THashSet<Variable> vars) {
\r
68 query.collectFreeVariables(vars);
\r
72 public Expression simplify(SimplificationContext context) {
\r
73 /*query = query.simplify(context);
\r
74 return query.generateEnforce(context);*/
\r
75 throw new InternalCompilerError();
\r
79 public Expression resolve(TranslationContext context) {
\r
80 context.pushExistentialFrame();
\r
81 query = query.resolve(context);
\r
82 Variable[] variables = context.popExistentialFrame();
\r
83 if(variables.length > 0)
\r
84 query = new QExists(variables, query);
\r
89 public Expression decorate(ExpressionDecorator decorator) {
\r
90 return decorator.decorate(this);
\r
94 public void setLocationDeep(long loc) {
\r
95 if(location == Locations.NO_LOCATION) {
\r
97 query.setLocationDeep(loc);
\r
102 public void accept(ExpressionVisitor visitor) {
\r
103 visitor.visit(this);
\r
107 public void forVariables(VariableProcedure procedure) {
\r
108 query.forVariables(procedure);
\r
112 public Expression replace(ReplaceContext context) {
\r
113 return new EEnforce(query.replace(context));
\r
117 public Expression accept(ExpressionTransformer transformer) {
\r
118 return transformer.transform(this);
\r