root/trunk/ProjectFortress/src/com/sun/fortress/compiler/index/DeclaredFunction.java @ 3764

Revision 3764, 3.1 KB (checked in by dr2chase, 6 months ago)

Mixed overloading working; some refactoring and cleanup in the naming czar; all the primitive Fortress types impls have a parent, FValue

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.IdOrOpOrAnonymousName;
28import com.sun.fortress.nodes.Node;
29import com.sun.fortress.nodes.NodeDepthFirstVisitor;
30import com.sun.fortress.nodes.NodeUpdateVisitor;
31import com.sun.fortress.nodes.Param;
32import com.sun.fortress.nodes.StaticArg;
33import com.sun.fortress.nodes.StaticParam;
34import com.sun.fortress.nodes.Type;
35import com.sun.fortress.nodes_util.Span;
36import com.sun.fortress.nodes_util.NodeUtil;
37import com.sun.fortress.useful.NI;
38
39import edu.rice.cs.plt.tuple.Option;
40
41public class DeclaredFunction extends Function {
42    private final FnDecl _ast;
43
44    public DeclaredFunction(FnDecl ast) { _ast = ast; }
45
46    public FnDecl ast() { return _ast; }
47
48    @Override
49    protected String mandatoryToString() {
50        return "function " + ast();
51    }
52   
53    @Override
54    protected IdOrOpOrAnonymousName mandatoryToUndecoratedName() {
55        return ast().getHeader().getName();
56    }
57
58    @Override
59    public Span getSpan() { return NodeUtil.getSpan(_ast); }
60
61        @Override
62        public Option<Expr> body() {
63                return _ast.accept(new NodeDepthFirstVisitor<Option<Expr>>(){
64                        @Override
65                        public Option<Expr> defaultCase(Node that) {
66                                return Option.none();
67                        }
68                        @Override
69                        public Option<Expr> forFnDecl(FnDecl that) {
70                            return that.getBody();
71                        }
72                });
73        }
74
75        @Override
76        public List<Param> parameters() {
77                return NodeUtil.getParams(_ast);
78        }
79
80        @Override
81        public List<StaticParam> staticParameters() {
82                return NodeUtil.getStaticParams(_ast);
83        }
84
85        @Override
86        public List<BaseType> thrownTypes() {
87                if( NodeUtil.getThrowsClause(_ast).isNone() )
88                        return Collections.emptyList();
89                else
90                        return Collections.unmodifiableList(NodeUtil.getThrowsClause(_ast).unwrap());
91        }
92
93        @Override
94        public Functional instantiate(List<StaticParam> params, List<StaticArg> args) {
95                // TODO Auto-generated method stub
96                return NI.nyi();
97        }
98
99        @Override
100        public Type getReturnType() {
101                return NodeUtil.getReturnType(_ast).unwrap();
102        }
103
104        @Override
105        public Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor) {
106                return new DeclaredFunction((FnDecl)this._ast.accept(visitor));
107        }
108
109 }
Note: See TracBrowser for help on using the browser.