]> gerrit.simantics Code Review - simantics/platform.git/blob
652bc00b4809d8083652b3068afbf78f88bdc677
[simantics/platform.git] /
1 package org.simantics.scl.compiler.internal.elaboration.constraints2;
2
3 import gnu.trove.map.hash.THashMap;
4 import gnu.trove.procedure.TObjectObjectProcedure;
5
6 import org.simantics.scl.compiler.environment.Environment;
7 import org.simantics.scl.compiler.types.TCon;
8 import org.simantics.scl.compiler.types.TPred;
9 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
10
11 public class ConstraintSolver {
12     final Environment environment;
13     private final THashMap<TCon, ConstraintStore> constraintStores = 
14             new THashMap<TCon, ConstraintStore>();
15     
16     public ConstraintSolver(Environment environment) {
17         this.environment = environment;
18     }
19
20     private ConstraintStore getConstraintStore(TCon typeClass) {
21         ConstraintStore store = constraintStores.get(typeClass);
22         if(store == null) {
23             store = new ConstraintStore(this, typeClass);
24             constraintStores.put(typeClass, store);
25         }
26         return store;
27     }
28     
29     public ConstraintHandle addDemand(TPred pred, long location) {
30         return getConstraintStore(pred.typeClass).addConstraint(pred, location);
31     }
32     
33     public void print() {
34         final TypeUnparsingContext tuc = new TypeUnparsingContext();
35         constraintStores.forEachEntry(new TObjectObjectProcedure<TCon, ConstraintStore>() {
36             @Override
37             public boolean execute(TCon pred, ConstraintStore store) {
38                 store.print(tuc);
39                 return true;
40             }
41         });
42     }
43 }