]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java
(refs #7866) Better error location for the NPE in compilation
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / chr / CHRQuery.java
index 2d97ab51819e4d271cea111e42050878da58c6a2..7bee6eae06b08a481652df67e5009d76629dfde4 100644 (file)
@@ -1,5 +1,6 @@
 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;
@@ -20,8 +21,9 @@ import gnu.trove.set.hash.TIntHashSet;
 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) {
@@ -48,17 +50,21 @@ public class CHRQuery extends Symbol {
     }
     
     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) {
@@ -84,6 +90,6 @@ public class CHRQuery extends Symbol {
         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);
     }
 }