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

Revision 1800, 2.9 kB (checked in by dr2chase, 4 months ago)

Replaced references to BetterEnv? with references to Environment

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
18 package com.sun.fortress.interpreter.evaluator.values;
19
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Set;
23
24 import com.sun.fortress.interpreter.evaluator.Environment;
25 import com.sun.fortress.interpreter.evaluator.types.FType;
26 import com.sun.fortress.nodes_util.NodeFactory;
27 import com.sun.fortress.useful.BATreeEC;
28 import com.sun.fortress.useful.HasAt;
29
30
31 public class OverloadedMethod extends OverloadedFunction implements Method {
32
33     BATreeEC<List<FValue>, List<FType>, MethodClosure> mcache =
34         new BATreeEC<List<FValue>, List<FType>, MethodClosure>(FValue.asTypesList);
35
36
37     public OverloadedMethod(String fnName, Environment within) {
38         super(NodeFactory.makeId(fnName), within);
39         // TODO Auto-generated constructor stub
40     }
41
42     public OverloadedMethod(String fnName, Set<? extends Simple_fcn> ssf,
43             Environment within) {
44         super(NodeFactory.makeId(fnName), ssf, within);
45         // TODO Auto-generated constructor stub
46     }
47
48     // ??? This appears to be for debugging purposes???
49     static int lastBest;
50
51     /** We separate out getApplicableMethod so that overloaded
52      *  functional method invocations can perform end-to-end caching
53      *  of the applicable method.
54      */
55     public MethodClosure getApplicableMethod(List<FValue> args, HasAt loc,
56             Environment envForInference) {
57         MethodClosure best_f = mcache.get(args);
58         if (best_f == null) {
59             List<Overload>  someOverloads = overloads;
60             int best = bestMatchIndex(args, loc, envForInference, someOverloads);
61             lastBest = best;
62
63             best_f = ((MethodClosure)someOverloads.get(best).getFn());
64             mcache.syncPut(args, best_f);
65         }
66         return best_f;
67     }
68
69     public FValue applyMethod(List<FValue> args, FObject selfValue,
70                               HasAt loc, Environment envForInference) {
71         Method best_f = getApplicableMethod(args,loc,envForInference);
72         return best_f.applyMethod(args, selfValue, loc, envForInference);
73     }
74
75     public void bless() {
76         overloads = pendingOverloads;
77         pendingOverloads = new ArrayList<Overload>();
78         super.bless();
79     }
80
81
82 }
Note: See TracBrowser for help on using the browser.