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

Revision 2404, 3.6 KB (checked in by mspiegel, 16 months ago)

[static analysis] Another refactoring of Shell.java. Static phases are now declared in package com.sun.fortress.compiler.phases.

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>(),
47                        errors, Option.<Map<Pair<Node,Span>, TypeEnv>>none());
48    }
49   
50    public AnalyzeResult(Map<APIName, ApiIndex> apis,
51            Map<APIName, ComponentIndex> components,
52            Iterable<? extends StaticError> errors, Option<Map<Pair<Node,Span>, TypeEnv>> typeEnvAtNode) {
53        super(errors);
54        _apis = apis;
55        _components = components;
56        _typeEnvAtNode = typeEnvAtNode;
57    }
58   
59    /**
60     * A copying constructor, where every other field of the given result will be
61     * copied, except apis, components, and errors, which will be replaced by the
62     * given arguments. Use this constructor to implicitly copy fields that earlier
63     * passes populated that your pass wants to ignore. Using this constructor means
64     * that if new fields are added to this class in the future, your code will not
65     * need to call a different constructor.
66     */
67    public AnalyzeResult(AnalyzeResult result, Map<APIName, ApiIndex> apis,
68            Map<APIName, ComponentIndex> components,
69            Iterable<? extends StaticError> errors) {
70        super(errors);
71        _apis = apis;
72        _components = components;
73        _typeEnvAtNode = result._typeEnvAtNode;
74    }
75   
76    public Iterable<Api> apiIterator() {
77        return new ApiIterable(_apis);
78    }
79
80    public Iterable<Component> componentIterator() {
81        return new ComponentIterable(_components);
82    }
83   
84    public Map<APIName, ApiIndex> apis() { return _apis; }
85    public Map<APIName, ComponentIndex> components() { return _components; }
86   
87    /**
88     * @return A mapping from Nodes that declare variables to the TypeEnv that was
89     * in scope at that AST node. This map is not populated until type-checking and
90     * therefore will be None until then.
91     */
92    public Option<Map<Pair<Node,Span>, TypeEnv>> typeEnvAtNode() { return this._typeEnvAtNode; }
93}
Note: See TracBrowser for help on using the browser.