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%2FEConstant.java;h=eb3f5ca4a74ff3e192c7647153f5f1d14cd36bcd;hb=4c5ff8ec11947aae4d49106365819717cfa43209;hp=c5b4681a86d233e4ee87fa8fe5b152ae6aa7baeb;hpb=747231cca0974ca9ed5f78caa6517ee9dcb8e4fc;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java index c5b4681a8..eb3f5ca4a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java @@ -1,6 +1,8 @@ package org.simantics.scl.compiler.elaboration.expressions; import java.util.ArrayList; +import java.util.Collections; +import java.util.Set; import org.simantics.scl.compiler.common.names.Name; import org.simantics.scl.compiler.common.precedence.Precedence; @@ -13,6 +15,7 @@ import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.elaboration.errors.NotPatternException; import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType; import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchingLhs; +import org.simantics.scl.compiler.elaboration.java.DynamicConstructor; import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; @@ -30,12 +33,8 @@ import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.compiler.types.util.MultiFunction; import org.simantics.scl.compiler.types.util.TypeUnparsingContext; -import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; -import gnu.trove.set.hash.TIntHashSet; - public class EConstant extends Expression { - SCLValue value; + public SCLValue value; Type[] typeParameters; public EConstant(SCLValue value, Type ... typeParameters) { @@ -82,24 +81,18 @@ public class EConstant extends Expression { setType(Types.instantiate(getType(), type)); return this; } - - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - int id = allRefs.get(value); - if(id >= 0) - refs.add(id); + + @Override + public Set getFreeVariables() { + return Collections.emptySet(); } - - @Override - public void collectVars(TObjectIntHashMap allVars, - TIntHashSet vars) { - } - public void toString(StringBuilder b, TypeUnparsingContext tuc) { - Name name = value.getName(); - if(name.module.equals("Builtin") || name.module.equals("Prelude")) - b.append(name.name); - else - b.append(name); + public void toString(StringBuilder b, TypeUnparsingContext tuc) { + Name name = value.getName(); + if(name.module.equals("Builtin") || name.module.equals("Prelude")) + b.append(name.name); + else + b.append(name); /*for(Type type : typeParameters) { b.append(" <"); b.append(type.toString(tuc)); @@ -112,17 +105,13 @@ public class EConstant extends Expression { setType(Types.instantiate(value.getType(), typeParameters)); } - @Override - public IVal toVal(CompilationContext context, CodeWriter w) { - IVal val = value.getValue(); - if(typeParameters.length > 0) { - val = val.createSpecialization(typeParameters); - } - return val; - } - @Override - public void collectFreeVariables(THashSet vars) { + public IVal toVal(CompilationContext context, CodeWriter w) { + IVal val = value.getValue(); + if(typeParameters.length > 0) { + val = val.createSpecialization(typeParameters); + } + return val; } @Override @@ -157,10 +146,6 @@ public class EConstant extends Expression { public Expression resolveAsPattern(TranslationContext context) { return this; } - - @Override - public void removeFreeVariables(THashSet vars) { - } @Override public Expression replace(ReplaceContext context) { @@ -206,7 +191,7 @@ public class EConstant extends Expression { context.recursiveReferences.add(placeholder); return placeholder; } - else if(context.isInPattern()) { + else if(context.isInPattern() && value.getValue() != DynamicConstructor.INSTANCE /* HACK!! */) { /* This is little hackish code that handles the following kind of constructors: * data Thunk a = Thunk s (a -> s) * in @@ -236,11 +221,7 @@ public class EConstant extends Expression { @Override public boolean isEffectful() { - return false; - } - - @Override - public void collectEffects(THashSet effects) { + return false; } @Override @@ -258,10 +239,6 @@ public class EConstant extends Expression { public Precedence getPrecedence() { return value.getPrecedence(); } - - @Override - public void forVariables(VariableProcedure procedure) { - } @Override public boolean isPattern(int arity) { @@ -284,4 +261,9 @@ public class EConstant extends Expression { EConstant other = (EConstant)expression; return value == other.value && Types.equals(typeParameters, other.typeParameters); } + + @Override + public boolean isConstructorApplication() { + return true; + } }