]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/pre/PreQuery.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / query / pre / PreQuery.java
1 package org.simantics.scl.compiler.elaboration.query.pre;
2
3 import java.util.ArrayList;
4
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;
15
16 import gnu.trove.map.hash.TObjectIntHashMap;
17 import gnu.trove.set.hash.THashSet;
18 import gnu.trove.set.hash.TIntHashSet;
19
20 /**
21  * Query classes that may exist before resolving
22  */
23 public abstract class PreQuery extends Query {
24
25     public ArrayList<Variable> extraVariables = new ArrayList<Variable>(2);
26     public ArrayList<Query> sideQueries = new ArrayList<Query>(2);
27         
28     @Override
29     public void collectFreeVariables(THashSet<Variable> vars) {
30         throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectFreeVariables.");
31     }
32     
33     @Override
34     public void checkType(TypingContext context) {
35         throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support checkType.");
36     }
37     
38     @Override
39     public void collectConstraints(ConstraintCollectionContext context) {
40         throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectConstraints.");
41     }
42     
43     @Override
44     public void collectRefs(TObjectIntHashMap<Object> allRefs,
45             TIntHashSet refs) {
46         throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectRefs.");
47     }
48     
49     @Override
50     public void collectVars(TObjectIntHashMap<Variable> allVars,
51             TIntHashSet vars) {
52         throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectVars.");
53     }
54     
55     @Override
56     public Query replace(ReplaceContext replaceContext) {
57         throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support replace.");
58     }
59     
60     @Override
61     final public void accept(QueryVisitor visitor) {
62         throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support accept.");
63     }
64     
65     protected Query withSideQueries(Query query) {
66         if(!sideQueries.isEmpty()) {
67             sideQueries.add(query);
68             query = new QConjunction(sideQueries.toArray(new Query[sideQueries.size()]));
69         }
70         if(!extraVariables.isEmpty())
71             query = new QExists(extraVariables.toArray(new Variable[extraVariables.size()]), query);
72         return query;
73     }
74     
75     @Override
76     public void forVariables(VariableProcedure procedure) {
77         throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support forVariables.");
78     }
79 }