| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | package com.sun.fortress.compiler.typechecker; |
|---|
| 18 | import com.sun.fortress.nodes.*; |
|---|
| 19 | import java.util.List; |
|---|
| 20 | import edu.rice.cs.plt.tuple.Option; |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | public class TypeNormalizer extends NodeUpdateVisitor { |
|---|
| 27 | public static Type normalize(Type t) { |
|---|
| 28 | return (Type)t.accept(new TypeNormalizer()); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | public Node forIntersectionTypeOnly(IntersectionType that, |
|---|
| 32 | TypeInfo info_result, |
|---|
| 33 | List<Type> elements_result) |
|---|
| 34 | { |
|---|
| 35 | if (elements_result.size() == 1) { |
|---|
| 36 | return elements_result.get(0); |
|---|
| 37 | } else { |
|---|
| 38 | return super.forIntersectionTypeOnly(that, |
|---|
| 39 | info_result, |
|---|
| 40 | elements_result); |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | public Node forUnionTypeOnly(UnionType that, |
|---|
| 45 | TypeInfo info_result, |
|---|
| 46 | List<Type> elements_result) |
|---|
| 47 | { |
|---|
| 48 | if (elements_result.size() == 1) { |
|---|
| 49 | return elements_result.get(0); |
|---|
| 50 | } else { |
|---|
| 51 | return super.forUnionTypeOnly(that, |
|---|
| 52 | info_result, |
|---|
| 53 | elements_result); |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | public Node forTupleTypeOnly(TupleType that, |
|---|
| 58 | TypeInfo info_result, |
|---|
| 59 | List<Type> elements_result, |
|---|
| 60 | Option<Type> varargs_result, |
|---|
| 61 | List<KeywordType> keywords_result) |
|---|
| 62 | { |
|---|
| 63 | if (varargs_result.isNone() && |
|---|
| 64 | keywords_result.size() == 0 && |
|---|
| 65 | elements_result.size() == 1) |
|---|
| 66 | { |
|---|
| 67 | return elements_result.get(0); |
|---|
| 68 | } |
|---|
| 69 | else { |
|---|
| 70 | return super.forTupleTypeOnly(that, info_result, elements_result, |
|---|
| 71 | varargs_result, keywords_result); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | } |
|---|