]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java
Fixed a bug related to the extent of variable frames (see test case)
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / EConstant.java
index 1bab4ff646da38ab5c03c0327fd5cf6abe3b5cc3..eb3f5ca4a74ff3e192c7647153f5f1d14cd36bcd 100644 (file)
@@ -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,10 +33,6 @@ 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 {
     public SCLValue value;
     Type[] typeParameters;
@@ -82,10 +81,10 @@ public class EConstant extends Expression {
             setType(Types.instantiate(getType(), type));
         return this;
     }
-
+    
     @Override
-    public void collectVars(TObjectIntHashMap<Variable> allVars,
-            TIntHashSet vars) {   
+    public Set<Variable> getFreeVariables() {
+        return Collections.emptySet();
     }
 
     public void toString(StringBuilder b, TypeUnparsingContext tuc) {
@@ -106,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<Variable> vars) {
+    public IVal toVal(CompilationContext context, CodeWriter w) {
+        IVal val = value.getValue();           
+        if(typeParameters.length > 0) {
+            val = val.createSpecialization(typeParameters);
+        }
+        return val;
     }
 
     @Override
@@ -151,10 +146,6 @@ public class EConstant extends Expression {
     public Expression resolveAsPattern(TranslationContext context) {
         return this;
     }
-       
-    @Override
-    public void removeFreeVariables(THashSet<Variable> vars) {     
-    }
 
     @Override
     public Expression replace(ReplaceContext context) {
@@ -200,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
@@ -270,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;
+    }
 }