]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints2/ConstraintSolver.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / elaboration / constraints2 / ConstraintSolver.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints2/ConstraintSolver.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints2/ConstraintSolver.java
new file mode 100644 (file)
index 0000000..652bc00
--- /dev/null
@@ -0,0 +1,43 @@
+package org.simantics.scl.compiler.internal.elaboration.constraints2;
+
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectObjectProcedure;
+
+import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.types.TCon;
+import org.simantics.scl.compiler.types.TPred;
+import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+
+public class ConstraintSolver {
+    final Environment environment;
+    private final THashMap<TCon, ConstraintStore> constraintStores = 
+            new THashMap<TCon, ConstraintStore>();
+    
+    public ConstraintSolver(Environment environment) {
+        this.environment = environment;
+    }
+
+    private ConstraintStore getConstraintStore(TCon typeClass) {
+        ConstraintStore store = constraintStores.get(typeClass);
+        if(store == null) {
+            store = new ConstraintStore(this, typeClass);
+            constraintStores.put(typeClass, store);
+        }
+        return store;
+    }
+    
+    public ConstraintHandle addDemand(TPred pred, long location) {
+        return getConstraintStore(pred.typeClass).addConstraint(pred, location);
+    }
+    
+    public void print() {
+        final TypeUnparsingContext tuc = new TypeUnparsingContext();
+        constraintStores.forEachEntry(new TObjectObjectProcedure<TCon, ConstraintStore>() {
+            @Override
+            public boolean execute(TCon pred, ConstraintStore store) {
+                store.print(tuc);
+                return true;
+            }
+        });
+    }
+}