X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FEListLiteral.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FEListLiteral.java;h=4cdcc6f847f237038bccf8732d3688ffce700a53;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java new file mode 100755 index 000000000..4cdcc6f84 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EListLiteral.java @@ -0,0 +1,181 @@ +package org.simantics.scl.compiler.elaboration.expressions; + +import gnu.trove.map.hash.TObjectIntHashMap; +import gnu.trove.set.hash.THashSet; +import gnu.trove.set.hash.TIntHashSet; + +import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; +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.elaboration.java.Builtins; +import org.simantics.scl.compiler.elaboration.java.ListConstructor; +import org.simantics.scl.compiler.errors.Locations; +import org.simantics.scl.compiler.internal.codegen.utils.Constants; +import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator; +import org.simantics.scl.compiler.internal.interpreted.IExpression; +import org.simantics.scl.compiler.internal.interpreted.IListLiteral; +import org.simantics.scl.compiler.top.ExpressionInterpretationContext; +import org.simantics.scl.compiler.types.Type; +import org.simantics.scl.compiler.types.Types; +import org.simantics.scl.compiler.types.exceptions.MatchException; + +public class EListLiteral extends SimplifiableExpression { + + Expression[] components; + Type componentType; + + public EListLiteral(Expression[] components) { + this.components = components; + } + + private EListLiteral(Expression[] components, Type componentType) { + this.components = components; + this.componentType = componentType; + } + + public Expression[] getComponents() { + return components; + } + + @Override + public void collectRefs(TObjectIntHashMap allRefs, + TIntHashSet refs) { + for(Expression component : components) + component.collectRefs(allRefs, refs); + } + + @Override + public void collectVars(TObjectIntHashMap allVars, + TIntHashSet vars) { + for(Expression component : components) + component.collectVars(allVars, vars); + } + + @Override + public void collectFreeVariables(THashSet vars) { + for(Expression component : components) + component.collectFreeVariables(vars); + } + + @Override + public Expression simplify(SimplificationContext context) { + context.pushLocation(location); + try { + for(int i=0;i 0) + result = new EApply(location, result, components); + return result; + } + else { + Expression result = new EApplyType(new ELiteral(location, new ListConstructor(components.length)), componentType); + result = new EApply(location, result, components); + return result; + } + } finally { + context.popLocation(); + } + } + + @Override + public Expression resolve(TranslationContext context) { + for(int i=0;i effects) { + for(Expression component : components) + component.collectEffects(effects); + } + + @Override + public void setLocationDeep(long loc) { + if(location == Locations.NO_LOCATION) { + location = loc; + for(Expression component : components) + component.setLocationDeep(loc); + } + } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public IExpression toIExpression(ExpressionInterpretationContext target) { + IExpression[] componentExpressions = new IExpression[components.length]; + for(int i=0;i