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 public class EEnforce extends SimplifiableExpression {
19 public EEnforce(Query query) {
23 public Query getQuery() {
28 protected void updateType() throws MatchException {
29 setType(Types.tupleConstructor(0));
33 public Expression inferType(TypingContext context) {
34 query.checkType(context);
35 //context.declareEffect(location, query.getEffect(Query.W));
36 return compile(context);
39 public Expression compile(TypingContext context) {
40 return query.generateEnforce(new EnforcingContext(context));
44 public Expression simplify(SimplificationContext context) {
45 /*query = query.simplify(context);
46 return query.generateEnforce(context);*/
47 throw new InternalCompilerError();
51 public Expression resolve(TranslationContext context) {
52 context.pushExistentialFrame();
53 query = query.resolve(context);
54 Variable[] variables = context.popExistentialFrame();
55 if(variables.length > 0)
56 query = new QExists(variables, query);
61 public void setLocationDeep(long loc) {
62 if(location == Locations.NO_LOCATION) {
64 query.setLocationDeep(loc);
69 public void accept(ExpressionVisitor visitor) {
74 public Expression replace(ReplaceContext context) {
75 return new EEnforce(query.replace(context));
79 public Expression accept(ExpressionTransformer transformer) {
80 return transformer.transform(this);