1 package org.simantics.scl.compiler.types.util;
\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
7 public class TypeTree<T> {
\r
9 public static class Case<T> {
\r
10 public Type[] types;
\r
14 private static class Node<T> {
\r
16 Branch<T>[] branches;
\r
18 public Node(Case<T>[] cases) {
\r
20 this.branches = new Branch[cases[0].types.length];
\r
23 Branch<T> getBranch(int i) {
\r
29 private static class Branch<T> {
\r
31 public void improve(Iterator<T> iterator) {
\r
32 // TODO Auto-generated method stub
\r
38 public static class Iterator<T> {
\r
42 public Iterator(Node<T> node, Type[] scrutinee) {
\r
44 this.scrutinee = scrutinee;
\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
63 public TypeTree(Case<T>[] cases) {
\r
64 this.root = new Node<T>(cases);
\r
67 public Iterator<T> iterator(Type ... scrutinee) {
\r
68 return new Iterator<T>(root, scrutinee);
\r