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

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