X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fquery%2Fpre%2FPreQuery.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fquery%2Fpre%2FPreQuery.java;h=049625f6b44917eca6ea66f854e9b06613c14885;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/pre/PreQuery.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/pre/PreQuery.java new file mode 100644 index 000000000..049625f6b --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/pre/PreQuery.java @@ -0,0 +1,80 @@ +package org.simantics.scl.compiler.elaboration.query.pre; + +import gnu.trove.map.hash.TObjectIntHashMap; +import gnu.trove.set.hash.THashSet; +import gnu.trove.set.hash.TIntHashSet; + +import java.util.ArrayList; + +import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; +import org.simantics.scl.compiler.elaboration.contexts.TypingContext; +import org.simantics.scl.compiler.elaboration.expressions.Variable; +import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure; +import org.simantics.scl.compiler.elaboration.query.QConjunction; +import org.simantics.scl.compiler.elaboration.query.QExists; +import org.simantics.scl.compiler.elaboration.query.Query; +import org.simantics.scl.compiler.elaboration.query.QueryVisitor; +import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext; +import org.simantics.scl.compiler.types.Type; + +/** + * Query classes that may exist before resolving + */ +public abstract class PreQuery extends Query { + + public ArrayList extraVariables = new ArrayList(2); + public ArrayList sideQueries = new ArrayList(2); + + @Override + public void collectFreeVariables(THashSet vars) { + throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectFreeVariables."); + } + + @Override + public void checkType(TypingContext context) { + throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support checkType."); + } + + @Override + public void collectConstraints(ConstraintCollectionContext context) { + throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectConstraints."); + } + + @Override + public void collectRefs(TObjectIntHashMap allRefs, + TIntHashSet refs) { + throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectRefs."); + } + + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { + throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectVars."); + } + + @Override + public Query replace(ReplaceContext replaceContext) { + throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support replace."); + } + + @Override + final public void accept(QueryVisitor visitor) { + throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support accept."); + } + + protected Query withSideQueries(Query query) { + if(!sideQueries.isEmpty()) { + sideQueries.add(query); + query = new QConjunction(sideQueries.toArray(new Query[sideQueries.size()])); + } + if(!extraVariables.isEmpty()) + query = new QExists(extraVariables.toArray(new Variable[extraVariables.size()]), query); + return query; + } + + @Override + public void forVariables(VariableProcedure procedure) { + throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support forVariables."); + } +}