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.expressions.VariableProcedure;
10 import org.simantics.scl.compiler.elaboration.query.QConjunction;
11 import org.simantics.scl.compiler.elaboration.query.QExists;
12 import org.simantics.scl.compiler.elaboration.query.Query;
13 import org.simantics.scl.compiler.elaboration.query.QueryVisitor;
14 import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
16 import gnu.trove.map.hash.TObjectIntHashMap;
17 import gnu.trove.set.hash.THashSet;
18 import gnu.trove.set.hash.TIntHashSet;
21 * Query classes that may exist before resolving
23 public abstract class PreQuery extends Query {
25 public ArrayList<Variable> extraVariables = new ArrayList<Variable>(2);
26 public ArrayList<Query> sideQueries = new ArrayList<Query>(2);
29 public void collectFreeVariables(THashSet<Variable> vars) {
30 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectFreeVariables.");
34 public void checkType(TypingContext context) {
35 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support checkType.");
39 public void collectConstraints(ConstraintCollectionContext context) {
40 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectConstraints.");
44 public void collectVars(TObjectIntHashMap<Variable> allVars,
46 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectVars.");
50 public Query replace(ReplaceContext replaceContext) {
51 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support replace.");
55 final public void accept(QueryVisitor visitor) {
56 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support accept.");
59 protected Query withSideQueries(Query query) {
60 if(!sideQueries.isEmpty()) {
61 sideQueries.add(query);
62 query = new QConjunction(sideQueries.toArray(new Query[sideQueries.size()]));
64 if(!extraVariables.isEmpty())
65 query = new QExists(extraVariables.toArray(new Variable[extraVariables.size()]), query);