1 package org.simantics.scl.compiler.elaboration.query.pre;
3 import java.util.ArrayList;
5 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
6 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
7 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
8 import org.simantics.scl.compiler.elaboration.expressions.Variable;
9 import org.simantics.scl.compiler.elaboration.query.QConjunction;
10 import org.simantics.scl.compiler.elaboration.query.QExists;
11 import org.simantics.scl.compiler.elaboration.query.Query;
12 import org.simantics.scl.compiler.elaboration.query.QueryVisitor;
13 import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
15 import gnu.trove.map.hash.TObjectIntHashMap;
16 import gnu.trove.set.hash.TIntHashSet;
19 * Query classes that may exist before resolving
21 public abstract class PreQuery extends Query {
23 public ArrayList<Variable> extraVariables = new ArrayList<Variable>(2);
24 public ArrayList<Query> sideQueries = new ArrayList<Query>(2);
27 public void checkType(TypingContext context) {
28 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support checkType.");
32 public void collectConstraints(ConstraintCollectionContext context) {
33 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectConstraints.");
37 public void collectVars(TObjectIntHashMap<Variable> allVars,
39 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectVars.");
43 public Query replace(ReplaceContext replaceContext) {
44 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support replace.");
48 final public void accept(QueryVisitor visitor) {
49 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support accept.");
52 protected Query withSideQueries(Query query) {
53 if(!sideQueries.isEmpty()) {
54 sideQueries.add(query);
55 query = new QConjunction(sideQueries.toArray(new Query[sideQueries.size()]));
57 if(!extraVariables.isEmpty())
58 query = new QExists(extraVariables.toArray(new Variable[extraVariables.size()]), query);