root/trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeNormalizer.java @ 3292

Revision 3292, 2.8 KB (checked in by EricAllen, 11 months ago)

Added a type normalizer to improve presentation of types in error messages.
Got the type checker working over more of our first 20 compiled programs.
Added corresponding tests to CompilerJUTests.

Line 
1/*******************************************************************************
2    Copyright 2009 Sun Microsystems, Inc.,
3    4150 Network Circle, Santa Clara, California 95054, U.S.A.
4    All rights reserved.
5
6    U.S. Government Rights - Commercial software.
7    Government users are subject to the Sun Microsystems, Inc. standard
8    license agreement and applicable provisions of the FAR and its supplements.
9
10    Use is subject to license terms.
11
12    This distribution may include materials developed by third parties.
13
14    Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
15    trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
16 ******************************************************************************/
17package com.sun.fortress.compiler.typechecker;
18import com.sun.fortress.nodes.*;
19import java.util.List;
20import edu.rice.cs.plt.tuple.Option;
21
22/**
23 * This class is responsible for simplifying types, to aid
24 * in error reporting, etc.
25 */
26public 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}
Note: See TracBrowser for help on using the browser.