1 package org.simantics.scl.compiler.elaboration.chr.planning.items;
3 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
4 import org.simantics.scl.compiler.common.names.Names;
5 import org.simantics.scl.compiler.elaboration.chr.plan.CheckOp;
6 import org.simantics.scl.compiler.elaboration.chr.plan.IterateListOp;
7 import org.simantics.scl.compiler.elaboration.chr.planning.PrePlanItem;
8 import org.simantics.scl.compiler.elaboration.chr.planning.QueryPlanningContext;
9 import org.simantics.scl.compiler.elaboration.expressions.EApply;
10 import org.simantics.scl.compiler.elaboration.expressions.EConstant;
11 import org.simantics.scl.compiler.elaboration.expressions.EVariable;
12 import org.simantics.scl.compiler.elaboration.expressions.Expression;
14 import gnu.trove.set.hash.TIntHashSet;
16 public class MemberPrePlanItem extends PrePlanItem {
17 public Expression expression1, expression2;
18 public TIntHashSet variableSet1, variableSet2;
20 public MemberPrePlanItem(Expression expression1, Expression expression2, TIntHashSet variableSet1, TIntHashSet variableSet2, int secondaryPriority) {
21 super(secondaryPriority);
22 this.expression1 = expression1;
23 this.expression2 = expression2;
24 this.variableSet1 = variableSet1;
25 this.variableSet2 = variableSet2;
26 updatePrimaryPriority();
29 private void updatePrimaryPriority() {
30 if(variableSet2.isEmpty()) {
31 if(variableSet1.isEmpty())
34 primaryPriority = 2.0;
39 public void initializeListeners(QueryPlanningContext context) {
40 context.listen(variableSet1, this);
41 context.listen(variableSet2, this);
45 public void variableSolved(QueryPlanningContext context, int variableId) {
46 variableSet1.remove(variableId);
47 variableSet2.remove(variableId);
48 updatePrimaryPriority();
49 context.priorityQueue.adjust(this);
53 public void generate(QueryPlanningContext context) {
54 if(!variableSet2.isEmpty())
55 throw new InternalCompilerError("Unsolvable query.");
56 if(variableSet1.isEmpty())
57 context.addPlanOp(new CheckOp(location,
59 new EConstant(context.getCompilationContext().getValue(Names.Prelude_elem)),
63 context.addPlanOp(new IterateListOp(location, ((EVariable)expression1).getVariable(), expression2));
64 context.bind(variableSet1);