import java.util.ArrayList;
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.common.names.Names;
import org.simantics.scl.compiler.compilation.CompilationContext;
import org.simantics.scl.compiler.constants.NoRepConstant;
import org.simantics.scl.compiler.elaboration.chr.plan.PlanOp;
import org.simantics.scl.compiler.elaboration.chr.plan.PlanRealizer;
import org.simantics.scl.compiler.elaboration.chr.planning.QueryPlanningContext;
+import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
public Expression simplify(SimplificationContext simplificationContext) {
this.expression = expression.simplify(simplificationContext);
query.simplify(simplificationContext);
-
- CompilationContext compilationContext = simplificationContext.getCompilationContext();
- QueryPlanningContext context = new QueryPlanningContext(compilationContext, existentialVariables);
- if(query.createQueryPlan(context, null, -1, null))
- planOps = context.getPlanOps();
return this;
}
@Override
public IVal toVal(CompilationContext context, CodeWriter w) {
+ QueryPlanningContext queryContext = new QueryPlanningContext(context, existentialVariables);
+ if(query.createQueryPlan(queryContext, null, -1, null))
+ planOps = queryContext.getPlanOps();
+
IVal list = w.apply(location, context.getValue(Names.MList_create).getValue(), NoRepConstant.UNIT);
planOps.add(new PlanOp(location) {
@Override
public Expression accept(ExpressionTransformer transformer) {
return transformer.transform(this);
}
+
+ @Override
+ public Expression replace(ReplaceContext context) {
+ Variable[] newExistentialVariables = new Variable[existentialVariables.length];
+ for(int i=0;i<existentialVariables.length;++i) {
+ Variable newVariable = existentialVariables[i].copy();
+ context.varMap.put(existentialVariables[i], new EVariable(newVariable));
+ newExistentialVariables[i] = newVariable;
+ }
+ ECHRSelect copy = new ECHRSelect(expression.replace(context), query.replace(context));
+ copy.existentialVariables = newExistentialVariables;
+ copy.currentRuleset = currentRuleset;
+ copy.planOps = planOps;
+ if(planOps != null) {
+ copy.planOps = new ArrayList<PlanOp>(planOps.size());
+ throw new InternalCompilerError(location, "Copying of ECHRSelect is not supported.");
+ //for(PlanOp op : planOps)
+ // copy.planOps.add(op.replace(context));
+ }
+ return copy;
+ }
}