| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | package com.sun.fortress.compiler.index; |
|---|
| 19 | |
|---|
| 20 | import java.util.Collections; |
|---|
| 21 | import java.util.List; |
|---|
| 22 | |
|---|
| 23 | import com.sun.fortress.nodes.ArrowType; |
|---|
| 24 | import com.sun.fortress.nodes.BaseType; |
|---|
| 25 | import com.sun.fortress.nodes.Expr; |
|---|
| 26 | import com.sun.fortress.nodes.FnDecl; |
|---|
| 27 | import com.sun.fortress.nodes.IdOrOpOrAnonymousName; |
|---|
| 28 | import com.sun.fortress.nodes.Node; |
|---|
| 29 | import com.sun.fortress.nodes.NodeDepthFirstVisitor; |
|---|
| 30 | import com.sun.fortress.nodes.NodeUpdateVisitor; |
|---|
| 31 | import com.sun.fortress.nodes.Param; |
|---|
| 32 | import com.sun.fortress.nodes.StaticArg; |
|---|
| 33 | import com.sun.fortress.nodes.StaticParam; |
|---|
| 34 | import com.sun.fortress.nodes.Type; |
|---|
| 35 | import com.sun.fortress.nodes_util.Span; |
|---|
| 36 | import com.sun.fortress.nodes_util.NodeUtil; |
|---|
| 37 | import com.sun.fortress.useful.NI; |
|---|
| 38 | |
|---|
| 39 | import edu.rice.cs.plt.lambda.SimpleBox; |
|---|
| 40 | import edu.rice.cs.plt.tuple.Option; |
|---|
| 41 | |
|---|
| 42 | public class DeclaredFunction extends Function { |
|---|
| 43 | private final FnDecl _ast; |
|---|
| 44 | |
|---|
| 45 | public DeclaredFunction(FnDecl ast) { |
|---|
| 46 | _ast = ast; |
|---|
| 47 | putThunk(SimpleBox.make(NodeUtil.getReturnType(_ast))); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | public FnDecl ast() { return _ast; } |
|---|
| 51 | |
|---|
| 52 | @Override |
|---|
| 53 | protected String mandatoryToString() { |
|---|
| 54 | return "function " + ast(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | @Override |
|---|
| 58 | protected IdOrOpOrAnonymousName mandatoryToUndecoratedName() { |
|---|
| 59 | return ast().getHeader().getName(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | @Override |
|---|
| 63 | public Span getSpan() { return NodeUtil.getSpan(_ast); } |
|---|
| 64 | |
|---|
| 65 | @Override |
|---|
| 66 | public Option<Expr> body() { |
|---|
| 67 | return _ast.accept(new NodeDepthFirstVisitor<Option<Expr>>(){ |
|---|
| 68 | @Override |
|---|
| 69 | public Option<Expr> defaultCase(Node that) { |
|---|
| 70 | return Option.none(); |
|---|
| 71 | } |
|---|
| 72 | @Override |
|---|
| 73 | public Option<Expr> forFnDecl(FnDecl that) { |
|---|
| 74 | return that.getBody(); |
|---|
| 75 | } |
|---|
| 76 | }); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | @Override |
|---|
| 80 | public List<Param> parameters() { |
|---|
| 81 | return NodeUtil.getParams(_ast); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | @Override |
|---|
| 85 | public List<StaticParam> staticParameters() { |
|---|
| 86 | return NodeUtil.getStaticParams(_ast); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | @Override |
|---|
| 90 | public List<BaseType> thrownTypes() { |
|---|
| 91 | if( NodeUtil.getThrowsClause(_ast).isNone() ) |
|---|
| 92 | return Collections.emptyList(); |
|---|
| 93 | else |
|---|
| 94 | return Collections.unmodifiableList(NodeUtil.getThrowsClause(_ast).unwrap()); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | @Override |
|---|
| 98 | public Functional instantiate(List<StaticParam> params, List<StaticArg> args) { |
|---|
| 99 | |
|---|
| 100 | return NI.nyi(); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | @Override |
|---|
| 104 | public Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor) { |
|---|
| 105 | return new DeclaredFunction((FnDecl)this._ast.accept(visitor)); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | } |
|---|