X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftypes%2FTUnion.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftypes%2FTUnion.java;h=e14ddb3052d5f30a57177753ec32fbc01b078fff;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TUnion.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TUnion.java new file mode 100644 index 000000000..e14ddb305 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/TUnion.java @@ -0,0 +1,167 @@ +package org.simantics.scl.compiler.types; + +import gnu.trove.map.hash.THashMap; +import gnu.trove.set.hash.THashSet; + +import java.util.ArrayList; + +import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.internal.types.TypeHashCodeContext; +import org.simantics.scl.compiler.internal.types.ast.TConAst; +import org.simantics.scl.compiler.internal.types.ast.TypeAst; +import org.simantics.scl.compiler.types.util.Polarity; +import org.simantics.scl.compiler.types.util.TypeUnparsingContext; + +public class TUnion extends Type { + public final Type[] effects; + + public TUnion(Type ... effects) { + if(NULL_CHECKS) { + for(Type effect : effects) + if(effect == null) + throw new InternalCompilerError(); + } + this.effects = effects; + } + + @Override + public Type replace(TVar var, Type replacement) { + for(int i=0;i 0) + b.append(","); + b.append(effects[i].toString(context)); + } + //b.append("#"); + return new TConAst(b.toString()); + } + + @Override + public void toName(TypeUnparsingContext context, StringBuilder b) { + boolean first = true; + for(Type effect : effects) { + if(first) + first = false; + else + b.append('_'); + effect.toName(context, b); + } + } + + @Override + public void updateHashCode(TypeHashCodeContext context) { + context.append(TypeHashCodeContext.UNION); + for(Type effect : effects) + effect.updateHashCode(context); + } + + @Override + public void collectFreeVars(ArrayList vars) { + for(Type effect : effects) + effect.collectFreeVars(vars); + } + + @Override + public void collectMetaVars(ArrayList vars) { + for(Type effect : effects) + effect.collectMetaVars(vars); + } + + @Override + public void collectMetaVars(THashSet vars) { + for(Type effect : effects) + effect.collectMetaVars(vars); + } + + @Override + public boolean isGround() { + for(Type effect : effects) + if(!effect.isGround()) + return false; + return true; + } + + @Override + public boolean containsMetaVars() { + for(Type effect : effects) + if(effect.containsMetaVars()) + return true; + return false; + } + + @Override + public int getClassId() { + return UNION_ID; + } + + @Override + public boolean contains(TMetaVar other) { + for(Type type : effects) + if(type.contains(other)) + return true; + return false; + } + + @Override + public Type convertMetaVarsToVars() { + for(int i=0;i vars) { + throw new UnsupportedOperationException(); + } + + @Override + public void collectConcreteEffects(ArrayList concreteEffects) { + for(Type effect : effects) + effect.collectConcreteEffects(concreteEffects); + } + + @Override + public Type head() { + throw new UnsupportedOperationException(); + } + + @Override + public Type copySkeleton(THashMap metaVarMap) { + return Types.NO_EFFECTS; + } +}