package org.simantics.scl.compiler.elaboration.chr;
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.elaboration.chr.plan.PostCommitOp;
import org.simantics.scl.compiler.elaboration.chr.plan.PreCommitOp;
import org.simantics.scl.compiler.elaboration.chr.planning.QueryPlanningContext;
public class CHRQuery extends Symbol {
public CHRLiteral[] literals;
- public CHRQuery(CHRLiteral[] literals) {
+ public CHRQuery(long location, CHRLiteral[] literals) {
this.literals = literals;
+ this.location = location;
}
public void resolve(TranslationContext context) {
}
public boolean createQueryPlan(QueryPlanningContext context, Expression inputFact, int activeLiteralId, CHRConstraint initConstraint) {
- for(int i=0;i<literals.length;++i) {
- CHRLiteral literal = literals[i];
- if(i == activeLiteralId)
- context.activate(literal, inputFact, i);
- else
- context.add(literal, i);
+ try {
+ for(int i=0;i<literals.length;++i) {
+ CHRLiteral literal = literals[i];
+ if(i == activeLiteralId)
+ context.activate(literal, inputFact, i);
+ else
+ context.add(literal, i);
+ }
+ if(activeLiteralId == -1 && inputFact != null) {
+ context.addInitFact(initConstraint, inputFact);
+ }
+ return context.createQueryPlan();
+ } catch(Exception e) {
+ throw InternalCompilerError.injectLocation(location, e);
}
- if(activeLiteralId == -1 && inputFact != null) {
- context.addInitFact(initConstraint, inputFact);
- }
- return context.createQueryPlan();
}
public void simplify(SimplificationContext context) {
CHRLiteral[] newLiterals = new CHRLiteral[literals.length];
for(int i=0;i<literals.length;++i)
newLiterals[i] = literals[i].replace(context);
- return new CHRQuery(newLiterals);
+ return new CHRQuery(location, newLiterals);
}
}
}
public static CHRQuery convertCHRQuery(TranslationContext context, boolean isHead, ListQualifier[] lqs) {
+ long location = Locations.NO_LOCATION;
ArrayList<CHRLiteral> query = new ArrayList<CHRLiteral>(lqs.length);
for(ListQualifier qualifier : lqs) {
+ location = Locations.combine(location, qualifier.location);
CHRLiteral literal = convertListQualifier(context, isHead, qualifier);
if(literal != null)
query.add(literal);
}
- return new CHRQuery(query.toArray(new CHRLiteral[query.size()]));
+ return new CHRQuery(location, query.toArray(new CHRLiteral[query.size()]));
}
/*public static CHRRule convertCHRStatement(TranslationContext context, CHRStatement statement) {
package org.simantics.scl.compiler.tests;
+import org.junit.Ignore;
import org.junit.Test;
import org.simantics.scl.compiler.top.ValueNotFound;
@Test public void CHR11() { test(); }
@Test public void CHR12() { test(); }
@Test public void CHR13() { test(); }
+ @Ignore @Test public void CHR14() { test(); }
@Test public void CHRSelect1() { test(); }
@Test public void CHRSelect2() { test(); }
@Test public void CHRSelect3() { test(); }