]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EAmbiguous.java
Fixed incorrect interaction of EAmbigious and TMetaVar.setRef
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / EAmbiguous.java
index 09cbcf25bf2557e5f48d82a04ae494455684008a..0afb14b89f42c92060710133ae34186d3551d07d 100644 (file)
@@ -16,9 +16,6 @@ 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;
@@ -27,7 +24,7 @@ public class EAmbiguous extends SimplifiableExpression {
     boolean[] active;
     int activeCount;
     transient TypingContext context;
-    Expression resolvedExpression;
+    public Expression resolvedExpression;
     
     public abstract static class Alternative {
         public abstract Type getType();
@@ -42,20 +39,6 @@ public class EAmbiguous extends SimplifiableExpression {
         this.activeCount = alternatives.length;
     }
 
-    @Override
-    public void collectRefs(TObjectIntHashMap<Object> allRefs,
-            TIntHashSet refs) {
-    }
-
-    @Override
-    public void collectVars(TObjectIntHashMap<Variable> allVars,
-            TIntHashSet vars) {
-    }
-
-    @Override
-    public void forVariables(VariableProcedure procedure) {
-    }
-
     @Override
     protected void updateType() throws MatchException {
         throw new InternalCompilerError();
@@ -73,7 +56,7 @@ public class EAmbiguous extends SimplifiableExpression {
         THashMap<TMetaVar,Type> unifications = new THashMap<TMetaVar,Type>(); 
         Type requiredType = getType();
         if(DEBUG)
-            System.out.println("EAmbigious.filterActive with " + requiredType);
+            System.out.println("EAmbigious.filterActive with " + requiredType.toStringSkeleton());
         for(int i=0;i<alternatives.length;++i)
             if(active[i]) {
                 unifications.clear();
@@ -93,7 +76,7 @@ public class EAmbiguous extends SimplifiableExpression {
         StringBuilder b = new StringBuilder();
         b.append("Expected <");
         requiredType.toString(new TypeUnparsingContext(), b);
-        b.append(">, but no alteratives match the type: ");
+        b.append(">, but no alternatives match the type: ");
         for(int i=0;i<alternatives.length;++i) {
             b.append("\n    ");
             b.append(alternatives[i]);
@@ -134,12 +117,12 @@ public class EAmbiguous extends SimplifiableExpression {
     
     private void listenType() {
         if(DEBUG)
-            System.out.println("EAmbigious.listenType " + getType());
+            System.out.println("EAmbigious.listenType " + getType().toStringSkeleton());
         new TypeListener() {
             @Override
             public void notifyAboutChange() {
                 if(DEBUG)
-                    System.out.println("EAmbigious.notifyAboutChange " + getType());
+                    System.out.println("EAmbigious.notifyAboutChange " + getType().toStringSkeleton());
                 Type requiredType = getType();
                 filterActive();
                 if(activeCount == 0) {
@@ -172,10 +155,6 @@ public class EAmbiguous extends SimplifiableExpression {
         listenType();
         return this;
     }
-    
-    @Override
-    public void collectFreeVariables(THashSet<Variable> vars) {
-    }
 
     @Override
     public Expression resolve(TranslationContext context) {
@@ -188,14 +167,9 @@ public class EAmbiguous extends SimplifiableExpression {
             location = loc;
     }
 
-    @Override
-    public void collectEffects(THashSet<Type> effects) {
-        // TODO Auto-generated method stub
-    }
-
     @Override
     public void accept(ExpressionVisitor visitor) {
-        // TODO Auto-generated method stub
+        visitor.visit(this);
     }
     
     @Override
@@ -203,14 +177,19 @@ public class EAmbiguous extends SimplifiableExpression {
         if(resolvedExpression != null)
             return resolvedExpression;
         else {
+            if(DEBUG)
+                System.out.println("EAmbigious.simplify: error");
             context.getErrorLog().log(location, getAmbiguousDescription(getType()));
             return this;
         }
     }
     
     public void assertResolved(ErrorLog errorLog) {
-        if(resolvedExpression == null)
+        if(resolvedExpression == null) {
+            if(DEBUG)
+                System.out.println("EAmbigious.assertResolved: error");
             errorLog.log(location, getAmbiguousDescription(getType()));
+        }
     }
     
     @Override