1 package org.simantics.scl.compiler.elaboration.expressions;
3 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
4 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
5 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
6 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
7 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
8 import org.simantics.scl.compiler.elaboration.query.QExists;
9 import org.simantics.scl.compiler.elaboration.query.Query;
10 import org.simantics.scl.compiler.elaboration.query.compilation.EnforcingContext;
11 import org.simantics.scl.compiler.errors.Locations;
12 import org.simantics.scl.compiler.types.Types;
13 import org.simantics.scl.compiler.types.exceptions.MatchException;
15 import gnu.trove.map.hash.TObjectIntHashMap;
16 import gnu.trove.set.hash.THashSet;
17 import gnu.trove.set.hash.TIntHashSet;
19 public class EEnforce extends SimplifiableExpression {
23 public EEnforce(Query query) {
27 public Query getQuery() {
32 public void collectVars(TObjectIntHashMap<Variable> allVars,
34 query.collectVars(allVars, vars);
38 protected void updateType() throws MatchException {
39 setType(Types.tupleConstructor(0));
43 public Expression inferType(TypingContext context) {
44 query.checkType(context);
45 //context.declareEffect(location, query.getEffect(Query.W));
46 return compile(context);
49 public Expression compile(TypingContext context) {
50 return query.generateEnforce(new EnforcingContext(context));
54 public void collectFreeVariables(THashSet<Variable> vars) {
55 query.collectFreeVariables(vars);
59 public Expression simplify(SimplificationContext context) {
60 /*query = query.simplify(context);
61 return query.generateEnforce(context);*/
62 throw new InternalCompilerError();
66 public Expression resolve(TranslationContext context) {
67 context.pushExistentialFrame();
68 query = query.resolve(context);
69 Variable[] variables = context.popExistentialFrame();
70 if(variables.length > 0)
71 query = new QExists(variables, query);
76 public void setLocationDeep(long loc) {
77 if(location == Locations.NO_LOCATION) {
79 query.setLocationDeep(loc);
84 public void accept(ExpressionVisitor visitor) {
89 public Expression replace(ReplaceContext context) {
90 return new EEnforce(query.replace(context));
94 public Expression accept(ExpressionTransformer transformer) {
95 return transformer.transform(this);