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