root/trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BuildTraitEnvironment.java

Revision 4002, 5.0 KB (checked in by sukyoungryu, 4 months ago)

[copyright] Fixed copyright notices.

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 ******************************************************************************/
17
18package com.sun.fortress.interpreter.evaluator;
19
20import com.sun.fortress.interpreter.evaluator.types.FType;
21import com.sun.fortress.interpreter.evaluator.values.*;
22import com.sun.fortress.nodes.*;
23import com.sun.fortress.nodes_util.NodeUtil;
24
25import java.util.List;
26import java.util.Set;
27
28
29public class BuildTraitEnvironment extends BuildEnvironments {
30
31    Set<String> fields;
32
33    Environment methodEnvironment;
34
35    FType definer;
36
37    public BuildTraitEnvironment(Environment within, Environment methodEnvironment, FType definer, Set<String> fields) {
38        super(within);
39        this.definer = definer;
40        this.fields = fields;
41        this.methodEnvironment = methodEnvironment;
42    }
43
44    protected Simple_fcn newClosure(Environment e, Applicable x) {
45        return new TraitMethod(containing, methodEnvironment, x, definer);
46    }
47
48    protected GenericMethod newGenericClosure(Environment e, FnDecl x) {
49        return new GenericMethod(containing, methodEnvironment, x, definer, true);
50    }
51
52    /**
53     * Put a value, perhaps unconditionally depending on subtype's choice
54     *
55     * @param e
56     * @param name
57     * @param value
58     * @param ft
59     */
60    protected void putValue(Environment e, String name, FValue value, FType ft) {
61        e.putValueRaw(name, value, ft);
62    }
63
64    /**
65     * Put a value, perhaps unconditionally depending on subtype's choice
66     */
67    protected void putValue(Environment e, String name, FValue value) {
68        e.putValueRaw(name, value);
69    }
70
71    public Boolean forVarDecl(VarDecl x) {
72        if (fields != null) {
73            List<LValue> lhs = x.getLhs();
74            for (LValue lvb : lhs) {
75                Id name = lvb.getName();
76                String s = NodeUtil.nameString(name);
77                fields.add(s);
78            }
79        }
80        return null;
81    }
82
83    /*
84     * (non-Javadoc)
85     *
86     * @see com.sun.fortress.interpreter.nodes.NodeVisitor#forFnDecl(com.sun.fortress.interpreter.nodes.FnDecl)
87     */
88    @Override
89    public Boolean forFnDecl(FnDecl x) {
90        // This is called from BuildTraitEnvironment
91        switch (getPass()) {
92            case 1:
93                forFnDecl1(x);
94                break;
95            case 2:
96                forFnDecl2(x);
97                break;
98            case 3:
99                forFnDecl3(x);
100                break;
101            case 4:
102                forFnDecl4(x);
103                break;
104        }
105        return null;
106    }
107
108    private void forFnDecl1(FnDecl x) {
109        List<StaticParam> optStaticParams = NodeUtil.getStaticParams(x);
110        String fname = NodeUtil.nameAsMethod(x);
111
112        if (!optStaticParams.isEmpty()) {
113            // GENERIC
114
115            // TODO same treatment as regular functions.
116            FValue cl = newGenericClosure(containing, x);
117            // LINKER putOrOverloadOrShadowGeneric(x, containing, name, cl);
118            bindInto.putValue(fname, cl); // was "shadow"
119
120        } else {
121            // NOT GENERIC
122
123            Simple_fcn cl = newClosure(containing, x);
124            // LINKER putOrOverloadOrShadow(x, containing, name, cl);
125            bindInto.putValue(fname, cl); // was "shadow"
126        }
127    }
128
129    private void forFnDecl2(FnDecl x) {
130    }
131
132    protected void forFnDecl3(FnDecl x) {
133        List<StaticParam> staticParams = NodeUtil.getStaticParams(x);
134        String fname = NodeUtil.nameAsMethod(x);
135        if (!staticParams.isEmpty()) {
136            // GENERIC
137            // This blows up because the type is not instantiated.
138            //            {
139            //                // Why isn't this the right thing to do?
140            //                // FGenericFunction is (currently) excluded from this treatment.
141            //                FValue fcn = containing.getValue(fname);
142            //
143            //                if (fcn instanceof OverloadedFunction) {
144            //                    OverloadedFunction og = (OverloadedFunction) fcn;
145            //                    og.finishInitializing();
146            //
147            //                }
148            //            }
149
150        } else {
151            // NOT GENERIC
152            {
153                Fcn fcn = (Fcn) containing.getLeafValue(fname);
154                fcn.finishInitializing();
155            }
156        }
157    }
158
159    private void forFnDecl4(FnDecl x) {
160    }
161
162
163}
Note: See TracBrowser for help on using the browser.