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.Type;
13 import org.simantics.scl.compiler.types.Types;
14 import org.simantics.scl.compiler.types.exceptions.MatchException;
16 import gnu.trove.map.hash.TObjectIntHashMap;
17 import gnu.trove.set.hash.THashSet;
18 import gnu.trove.set.hash.TIntHashSet;
20 public class EEnforce extends SimplifiableExpression {
24 public EEnforce(Query query) {
28 public Query getQuery() {
33 public void collectVars(TObjectIntHashMap<Variable> allVars,
35 query.collectVars(allVars, vars);
39 public void collectEffects(THashSet<Type> effects) {
40 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
44 protected void updateType() throws MatchException {
45 setType(Types.tupleConstructor(0));
49 public Expression inferType(TypingContext context) {
50 query.checkType(context);
51 //context.declareEffect(location, query.getEffect(Query.W));
52 return compile(context);
55 public Expression compile(TypingContext context) {
56 return query.generateEnforce(new EnforcingContext(context));
60 public void collectFreeVariables(THashSet<Variable> vars) {
61 query.collectFreeVariables(vars);
65 public Expression simplify(SimplificationContext context) {
66 /*query = query.simplify(context);
67 return query.generateEnforce(context);*/
68 throw new InternalCompilerError();
72 public Expression resolve(TranslationContext context) {
73 context.pushExistentialFrame();
74 query = query.resolve(context);
75 Variable[] variables = context.popExistentialFrame();
76 if(variables.length > 0)
77 query = new QExists(variables, query);
82 public void setLocationDeep(long loc) {
83 if(location == Locations.NO_LOCATION) {
85 query.setLocationDeep(loc);
90 public void accept(ExpressionVisitor visitor) {
95 public Expression replace(ReplaceContext context) {
96 return new EEnforce(query.replace(context));
100 public Expression accept(ExpressionTransformer transformer) {
101 return transformer.transform(this);