]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/util/TypeTree.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / types / util / TypeTree.java
1 package org.simantics.scl.compiler.types.util;
2
3 import org.simantics.scl.compiler.types.Skeletons;
4 import org.simantics.scl.compiler.types.TMetaVar;
5 import org.simantics.scl.compiler.types.Type;
6
7 public class TypeTree<T> {
8     
9     public static class Case<T> {
10         public Type[] types;
11         public T result;
12     }
13     
14     private static class Node<T> {
15         Case<T>[] cases;
16         Branch<T>[] branches;
17
18         public Node(Case<T>[] cases) {
19             this.cases = cases;
20             this.branches = new Branch[cases[0].types.length];
21         }
22         
23         Branch<T> getBranch(int i) {
24             // TODO
25             return null;
26         }
27     }
28     
29     private static class Branch<T> {
30
31         public void improve(Iterator<T> iterator) {
32             // TODO Auto-generated method stub
33             
34         }
35         
36     }
37     
38     public static class Iterator<T> {
39         Node<T> node;
40         Type[] scrutinee;
41         
42         public Iterator(Node<T> node, Type[] scrutinee) {
43             this.node = node;
44             this.scrutinee = scrutinee;
45         }
46         
47         public void improve() {
48             for(int i=0;i<scrutinee.length;++i) {
49                 Type type = scrutinee[i] = Skeletons.canonicalSkeleton(scrutinee[i]);
50                 if(!(type instanceof TMetaVar)) {
51                    Branch<T> branch = node.getBranch(i);
52                    if(branch != null) {
53                        branch.improve(this);
54                        --i;
55                    }
56                 }
57             }
58         }
59     }
60     
61     Node<T> root;
62     
63     public TypeTree(Case<T>[] cases) {
64         this.root = new Node<T>(cases);
65     }
66     
67     public Iterator<T> iterator(Type ... scrutinee) {
68         return new Iterator<T>(root, scrutinee);
69     }
70 }