root/trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FunctionalMethod.java @ 3915

Revision 3915, 3.5 KB (checked in by jrhil47, 5 months ago)

[index] Changed all Functional indices to store a thunk to get the return types, since during type checking the return types might need to be lazily evaluated. Also changed Functional indices to yield an Option for return types.
[type checker] Started implementing extraction of bindings from nodes for type environments.

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.compiler.index;
19
20import java.util.Collections;
21import java.util.List;
22
23import com.sun.fortress.nodes.ArrowType;
24import com.sun.fortress.nodes.BaseType;
25import com.sun.fortress.nodes.Expr;
26import com.sun.fortress.nodes.FnDecl;
27import com.sun.fortress.nodes.Id;
28import com.sun.fortress.nodes.IdOrOpOrAnonymousName;
29import com.sun.fortress.nodes.Node;
30import com.sun.fortress.nodes.NodeDepthFirstVisitor;
31import com.sun.fortress.nodes.NodeUpdateVisitor;
32import com.sun.fortress.nodes.Param;
33import com.sun.fortress.nodes.StaticArg;
34import com.sun.fortress.nodes.StaticParam;
35import com.sun.fortress.nodes.Type;
36import com.sun.fortress.nodes_util.NodeUtil;
37import com.sun.fortress.nodes_util.Span;
38import com.sun.fortress.useful.NI;
39
40import edu.rice.cs.plt.lambda.SimpleBox;
41import edu.rice.cs.plt.tuple.Option;
42
43/**
44 * Note that this is a {@link Function}, not a {@link Method}, despite the name
45 * (methods have distinct receivers).
46 */
47public class FunctionalMethod extends Function {
48    protected final FnDecl _ast;
49    protected final Id _declaringTrait;
50
51    public FunctionalMethod(FnDecl ast, Id declaringTrait) {
52        _ast = ast;
53        _declaringTrait = declaringTrait;
54        putThunk(SimpleBox.make(NodeUtil.getReturnType(_ast)));
55    }
56
57    public FnDecl ast() { return _ast; }
58
59    @Override
60    public Span getSpan() { return NodeUtil.getSpan(_ast); }
61   
62    protected String mandatoryToString() {
63        return "functionalMethod " + declaringTrait().toString() + "." + ast();
64    }
65
66    @Override
67    protected IdOrOpOrAnonymousName mandatoryToUndecoratedName() {
68        return ast().getHeader().getName();
69    }
70   
71    public Id declaringTrait() { return _declaringTrait; }
72
73        @Override
74        public Option<Expr> body() {
75                return _ast.accept(new NodeDepthFirstVisitor<Option<Expr>>(){
76                        @Override
77                        public Option<Expr> defaultCase(Node that) {
78                                return Option.none();
79                        }
80                        @Override
81                        public Option<Expr> forFnDecl(FnDecl that) {
82                            return that.getBody();
83                        }
84                });
85        }
86
87
88        @Override
89        public List<Param> parameters() {
90                return NodeUtil.getParams(_ast);
91        }
92
93        @Override
94        public List<StaticParam> staticParameters() {
95                return NodeUtil.getStaticParams(_ast);
96        }
97
98        @Override
99        public List<BaseType> thrownTypes() {
100                if(  NodeUtil.getThrowsClause(_ast).isSome() )
101                        return Collections.emptyList();
102                else
103                        return Collections.unmodifiableList(NodeUtil.getThrowsClause(_ast).unwrap());
104        }
105
106        @Override
107        public Functional instantiate(List<StaticParam> params, List<StaticArg> args) {
108                // TODO Auto-generated method stub
109                return NI.nyi();
110        }
111
112        @Override
113        public Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor) {
114                return new FunctionalMethod((FnDecl)this.ast().accept(visitor), this._declaringTrait);
115        }
116}
Note: See TracBrowser for help on using the browser.