X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FEAmbiguous.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FEAmbiguous.java;h=6121a57b19d66d4480bc5eec74b1da13bff55b33;hp=0000000000000000000000000000000000000000;hb=9a175feb652b2b7bba7afa540831b9076be3c10e;hpb=0b72d3e4ec886838314ffeba0fa201e32c0aae3e diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java new file mode 100644 index 000000000..6121a57b1 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java @@ -0,0 +1,227 @@ +package org.simantics.scl.compiler.elaboration.expressions; + +import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; +import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; +import org.simantics.scl.compiler.elaboration.contexts.TypingContext; +import org.simantics.scl.compiler.errors.ErrorLog; +import org.simantics.scl.compiler.errors.Locations; +import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; +import org.simantics.scl.compiler.types.Skeletons; +import org.simantics.scl.compiler.types.TMetaVar; +import org.simantics.scl.compiler.types.Type; +import org.simantics.scl.compiler.types.Types; +import org.simantics.scl.compiler.types.exceptions.MatchException; +import org.simantics.scl.compiler.types.exceptions.UnificationException; +import org.simantics.scl.compiler.types.util.TypeListener; +import org.simantics.scl.compiler.types.util.TypeUnparsingContext; + +import gnu.trove.map.hash.THashMap; +import gnu.trove.map.hash.TObjectIntHashMap; +import gnu.trove.set.hash.THashSet; +import gnu.trove.set.hash.TIntHashSet; + +public class EAmbiguous extends SimplifiableExpression { + public static final boolean DEBUG = false; + + Alternative[] alternatives; + boolean[] active; + int activeCount; + transient TypingContext context; + Expression resolvedExpression; + + public abstract static class Alternative { + public abstract Type getType(); + public abstract Expression realize(); + } + + public EAmbiguous(Alternative[] alternatives) { + this.alternatives = alternatives; + this.active = new boolean[alternatives.length]; + for(int i=0;i allRefs, + TIntHashSet refs) { + } + + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { + } + + @Override + public void forVariables(VariableProcedure procedure) { + } + + @Override + protected void updateType() throws MatchException { + throw new InternalCompilerError(); + } + + private Type getCommonSkeleton() { + Type[] types = new Type[activeCount]; + for(int i=0,j=0;i unifications = new THashMap(); + Type requiredType = getType(); + if(DEBUG) + System.out.println("EAmbigious.filterActive with " + requiredType); + for(int i=0;i, but no alteratives match the type: "); + for(int i=0;i, but multiple values match the type: "); + for(int i=0;i vars) { + } + + @Override + public Expression resolve(TranslationContext context) { + throw new InternalCompilerError("EAmbiguousConstant should not exist in resolve phase."); + } + + @Override + public void setLocationDeep(long loc) { + if(location == Locations.NO_LOCATION) + location = loc; + } + + @Override + public Expression decorate(ExpressionDecorator decorator) { + return this; + } + + @Override + public void collectEffects(THashSet effects) { + // TODO Auto-generated method stub + } + + @Override + public void accept(ExpressionVisitor visitor) { + // TODO Auto-generated method stub + } + + @Override + public Expression simplify(SimplificationContext context) { + if(resolvedExpression != null) + return resolvedExpression; + else { + context.getErrorLog().log(location, getAmbiguousDescription(getType())); + return this; + } + } + + public void assertResolved(ErrorLog errorLog) { + if(resolvedExpression == null) + errorLog.log(location, getAmbiguousDescription(getType())); + } + + @Override + public Expression accept(ExpressionTransformer transformer) { + return transformer.transform(this); + } + +}