1 package org.simantics.scl.compiler.elaboration.query.pre;
3 import gnu.trove.map.hash.TObjectIntHashMap;
4 import gnu.trove.set.hash.THashSet;
5 import gnu.trove.set.hash.TIntHashSet;
7 import java.util.ArrayList;
9 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
10 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
11 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
12 import org.simantics.scl.compiler.elaboration.expressions.Variable;
13 import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
14 import org.simantics.scl.compiler.elaboration.query.QConjunction;
15 import org.simantics.scl.compiler.elaboration.query.QExists;
16 import org.simantics.scl.compiler.elaboration.query.Query;
17 import org.simantics.scl.compiler.elaboration.query.QueryVisitor;
18 import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
19 import org.simantics.scl.compiler.types.Type;
22 * Query classes that may exist before resolving
24 public abstract class PreQuery extends Query {
26 public ArrayList<Variable> extraVariables = new ArrayList<Variable>(2);
27 public ArrayList<Query> sideQueries = new ArrayList<Query>(2);
30 public void collectFreeVariables(THashSet<Variable> vars) {
31 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectFreeVariables.");
35 public void checkType(TypingContext context) {
36 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support checkType.");
40 public void collectConstraints(ConstraintCollectionContext context) {
41 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectConstraints.");
45 public void collectRefs(TObjectIntHashMap<Object> allRefs,
47 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectRefs.");
51 public void collectVars(TObjectIntHashMap<Variable> allVars,
53 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectVars.");
57 public Query replace(ReplaceContext replaceContext) {
58 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support replace.");
62 final public void accept(QueryVisitor visitor) {
63 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support accept.");
66 protected Query withSideQueries(Query query) {
67 if(!sideQueries.isEmpty()) {
68 sideQueries.add(query);
69 query = new QConjunction(sideQueries.toArray(new Query[sideQueries.size()]));
71 if(!extraVariables.isEmpty())
72 query = new QExists(extraVariables.toArray(new Variable[extraVariables.size()]), query);
77 public void forVariables(VariableProcedure procedure) {
78 throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support forVariables.");