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.TIntHashSet;
18 public class EEnforce extends SimplifiableExpression {
22 public EEnforce(Query query) {
26 public Query getQuery() {
31 public void collectVars(TObjectIntHashMap<Variable> allVars,
33 query.collectVars(allVars, vars);
37 protected void updateType() throws MatchException {
38 setType(Types.tupleConstructor(0));
42 public Expression inferType(TypingContext context) {
43 query.checkType(context);
44 //context.declareEffect(location, query.getEffect(Query.W));
45 return compile(context);
48 public Expression compile(TypingContext context) {
49 return query.generateEnforce(new EnforcingContext(context));
53 public Expression simplify(SimplificationContext context) {
54 /*query = query.simplify(context);
55 return query.generateEnforce(context);*/
56 throw new InternalCompilerError();
60 public Expression resolve(TranslationContext context) {
61 context.pushExistentialFrame();
62 query = query.resolve(context);
63 Variable[] variables = context.popExistentialFrame();
64 if(variables.length > 0)
65 query = new QExists(variables, query);
70 public void setLocationDeep(long loc) {
71 if(location == Locations.NO_LOCATION) {
73 query.setLocationDeep(loc);
78 public void accept(ExpressionVisitor visitor) {
83 public Expression replace(ReplaceContext context) {
84 return new EEnforce(query.replace(context));
88 public Expression accept(ExpressionTransformer transformer) {
89 return transformer.transform(this);