X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=inline;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fscl%2FAbstractExpressionCompilationRequest.java;h=1bcd918771f3db8520507e6893b2de2376d61164;hb=e969d0489ce09f8e8414cdcf7db5f8f01a5bebcf;hp=b12d0258ede32c4c48e60c287c35250496fa5c77;hpb=66a5745bfefb159ce9d959bc29cbf148614e6fae;p=simantics%2Fplatform.git
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java
index b12d0258e..1bcd91877 100644
--- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java
+++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java
@@ -1,12 +1,11 @@
package org.simantics.db.layer0.scl;
-import gnu.trove.map.hash.THashMap;
-
import java.util.ArrayList;
import java.util.List;
import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.RuntimeDatabaseException;
import org.simantics.db.request.Read;
@@ -36,6 +35,10 @@ import org.simantics.scl.compiler.types.util.MultiFunction;
import org.simantics.scl.runtime.SCLContext;
import org.simantics.scl.runtime.function.Function1;
import org.simantics.utils.datastructures.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.map.hash.THashMap;
/**
*
This is a base implementation for compiling expressions stored into
@@ -62,6 +65,8 @@ import org.simantics.utils.datastructures.Pair;
public abstract class AbstractExpressionCompilationRequest
implements Read> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractExpressionCompilationRequest.class);
+
protected static final Type RESOURCE = Types.con("Simantics/DB", "Resource");
protected static final Type VARIABLE = Types.con("Simantics/Variables", "Variable");
protected static Name PROPERTY_VALUE = Name.create("Simantics/Variables", "propertyValue");
@@ -99,7 +104,7 @@ implements Read> {
return DEFAULT_EXPECTED_EFFECT;
}
- private ExpressionEvaluator prepareEvaluator(final ReadGraph graph, final CompilationContext context, Type expectedType) throws DatabaseException {
+ protected ExpressionEvaluator prepareEvaluator(final ReadGraph graph, final CompilationContext context, Type expectedType) throws DatabaseException {
final Variable contextVariable = new Variable("context", getContextVariableType());
LocalEnvironment localEnvironment = new AbstractLocalEnvironment() {
THashMap> precalculatedVariables = new THashMap>();
@@ -142,13 +147,21 @@ implements Read> {
protected boolean parseAsBlock() {
return false;
}
+
+ /*
+ * Override this to provide location information in compilation error situations.
+ */
+ protected String getContextDescription(ReadGraph graph) throws DatabaseException {
+ return toString();
+ }
- private Function1 eval(ExpressionEvaluator evaluator, ReadGraph graph) throws DatabaseException {
+ @SuppressWarnings("unchecked")
+ protected Function1 eval(ExpressionEvaluator evaluator, ReadGraph graph) throws DatabaseException {
Object oldGraph = SCLContext.getCurrent().put("graph", graph);
try {
return (Function1)evaluator.eval();
} catch(RuntimeDatabaseException e) {
- e.printStackTrace();
+ LOGGER.error("Failed to evaluate SCL expression", e);
if(e.getCause() instanceof DatabaseException)
throw (DatabaseException)e.getCause();
else
@@ -157,17 +170,20 @@ implements Read> {
StringBuilder b = new StringBuilder();
b.append("Couldn't compile '");
b.append(evaluator.getExpressionText());
+ b.append("' in ");
+ b.append(getContextDescription(graph));
b.append("':\n");
StringBuilder b2 = new StringBuilder();
for(CompilationError error : e.getErrors()) {
b2.append(error.description);
b2.append('\n');
}
- System.err.println(b.toString() + b2.toString());
- throw new SCLDatabaseException(b.toString()+b2.toString(), b2.toString(), e.getErrors());
+ SCLDatabaseException exception = new SCLDatabaseException(b.toString()+b2.toString(), b2.toString(), e.getErrors());
+ LOGGER.info(exception.getMessage(), exception);
+ throw exception;
} catch(Throwable e) {
// Should not happen!
- e.printStackTrace();
+ LOGGER.error("This error should never happen", e);
throw new RuntimeException(e);
} finally {
SCLContext.getCurrent().put("graph", oldGraph);
@@ -186,12 +202,11 @@ implements Read> {
return concreteEffects;
} catch(MatchException e) {
// Should not happen!
- e.printStackTrace();
+ LOGGER.error("Failed to get expression effects", e);
throw new RuntimeException(e);
}
}
- @SuppressWarnings("unchecked")
@Override
public Function1 perform(final ReadGraph graph) throws DatabaseException {
CompilationContext context = getCompilationContext(graph);
@@ -225,10 +240,15 @@ implements Read> {
else
return base;
}
-
- protected static String resolveExpectedValueType(ReadGraph graph, org.simantics.db.layer0.variable.Variable context) throws DatabaseException {
+
+ protected static String resolveExpectedValueType(ReadGraph graph, Resource predicate) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
- String valueType = graph.getPossibleRelatedValue(context.getPredicateResource(graph), L0.RequiresValueType, Bindings.STRING);
- return valueType;
+ return graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING);
}
+
+ @Override
+ public abstract int hashCode();
+
+ @Override
+ public abstract boolean equals(Object obj);
}