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