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 collectRefs(TObjectIntHashMap<Object> allRefs,
46 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectRefs.");
50 public void collectVars(TObjectIntHashMap<Variable> allVars,
52 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectVars.");
56 public Query replace(ReplaceContext replaceContext) {
57 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support replace.");
61 final public void accept(QueryVisitor visitor) {
62 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support accept.");
65 protected Query withSideQueries(Query query) {
66 if(!sideQueries.isEmpty()) {
67 sideQueries.add(query);
68 query = new QConjunction(sideQueries.toArray(new Query[sideQueries.size()]));
70 if(!extraVariables.isEmpty())
71 query = new QExists(extraVariables.toArray(new Variable[extraVariables.size()]), query);