root/trunk/ProjectFortress/src/com/sun/fortress/compiler/AnalyzeResult.java @ 2399

Revision 2399, 3.8 KB (checked in by nbeckman, 16 months ago)

[typechecker] I have changed the typechecker so that it produces information necessary to Angelina's closure conversion. This is a mapping from Nodes that declare variables to the TypeEnv? objects that were in scope at the location of the declaration. I had to change some other parts of the Shell to pass this map onto her phase of compilation.

Line 
1/*******************************************************************************
2    Copyright 2008 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 ******************************************************************************/
17
18package com.sun.fortress.compiler;
19
20import java.util.HashMap;
21import java.util.Map;
22
23import com.sun.fortress.compiler.index.ApiIndex;
24import com.sun.fortress.compiler.index.ComponentIndex;
25import com.sun.fortress.compiler.typechecker.TypeEnv;
26import com.sun.fortress.exceptions.StaticError;
27import com.sun.fortress.nodes.APIName;
28import com.sun.fortress.nodes.Api;
29import com.sun.fortress.nodes.Component;
30import com.sun.fortress.nodes.Node;
31import com.sun.fortress.nodes_util.Span;
32
33import edu.rice.cs.plt.tuple.Option;
34import edu.rice.cs.plt.tuple.Pair;
35
36
37public final class AnalyzeResult extends StaticPhaseResult {   
38
39    private final Map<APIName, ApiIndex> _apis;
40    private final Map<APIName, ComponentIndex> _components;
41   
42    // Fields that will not exist after every phase of compilation
43    private final Option<Map<Pair<Node,Span>, TypeEnv>> _typeEnvAtNode;
44   
45    public AnalyzeResult(Iterable<? extends StaticError> errors) {
46        this(new HashMap<APIName, ApiIndex>(), new HashMap<APIName, ComponentIndex>(), errors);
47    }
48
49    public AnalyzeResult(Map<APIName, ApiIndex> apis,
50                         Map<APIName, ComponentIndex> components,
51                         Iterable<? extends StaticError> errors) {
52        super(errors);
53        _apis = apis;
54        _components = components;
55        _typeEnvAtNode = Option.none();
56    }
57   
58    public AnalyzeResult(Map<APIName, ApiIndex> apis,
59            Map<APIName, ComponentIndex> components,
60            Iterable<? extends StaticError> errors, Map<Pair<Node,Span>, TypeEnv> typeEnvAtNode) {
61        super(errors);
62        _apis = apis;
63        _components = components;
64        _typeEnvAtNode = Option.some(typeEnvAtNode);
65    }
66   
67    /**
68     * A copying constructor, where every other field of the given result will be
69     * copied, except apis, components, and errors, which will be replaced by the
70     * given arguments. Use this constructor to implicitly copy fields that earlier
71     * passes populated that your pass wants to ignore. Using this constructor means
72     * that if new fields are added to this class in the future, your code will not
73     * need to call a different constructor.
74     */
75    public AnalyzeResult(AnalyzeResult result, Map<APIName, ApiIndex> apis,
76            Map<APIName, ComponentIndex> components,
77            Iterable<? extends StaticError> errors) {
78        super(errors);
79        _apis = apis;
80        _components = components;
81        _typeEnvAtNode = result._typeEnvAtNode;
82    }
83   
84    public Iterable<Api> apiIterator() {
85        return new ApiIterable(_apis);
86    }
87
88    public Iterable<Component> componentIterator() {
89        return new ComponentIterable(_components);
90    }
91   
92    public Map<APIName, ApiIndex> apis() { return _apis; }
93    public Map<APIName, ComponentIndex> components() { return _components; }
94   
95    /**
96     * @return A mapping from Nodes that declare variables to the TypeEnv that was
97     * in scope at that AST node. This map is not populated until type-checking and
98     * therefore will be None until then.
99     */
100    public Option<Map<Pair<Node,Span>, TypeEnv>> typeEnvAtNode() { return this._typeEnvAtNode; }
101}
Note: See TracBrowser for help on using the browser.