root/trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Functional.java
@
3915
| Revision 3915, 2.8 KB (checked in by jrhil47, 5 months ago) |
|---|
| 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 | |
| 18 | package com.sun.fortress.compiler.index; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
| 22 | import com.sun.fortress.nodes.ArrowType; |
| 23 | import com.sun.fortress.nodes.BaseType; |
| 24 | import com.sun.fortress.nodes.Expr; |
| 25 | import com.sun.fortress.nodes.Node; |
| 26 | import com.sun.fortress.nodes.NodeUpdateVisitor; |
| 27 | import com.sun.fortress.nodes.Param; |
| 28 | import com.sun.fortress.nodes.StaticArg; |
| 29 | import com.sun.fortress.nodes.StaticParam; |
| 30 | import com.sun.fortress.nodes.Type; |
| 31 | import com.sun.fortress.nodes_util.Span; |
| 32 | |
| 33 | import edu.rice.cs.plt.lambda.LazyThunk; |
| 34 | import edu.rice.cs.plt.lambda.Thunk; |
| 35 | import edu.rice.cs.plt.tuple.Option; |
| 36 | |
| 37 | /** Comprises {@link Function} and {@link Method}. */ |
| 38 | public abstract class Functional { |
| 39 | |
| 40 | //public abstract Node ast(); |
| 41 | /** |
| 42 | * Returns a version of this Functional, with params replaced with args. |
| 43 | * The contract of this method requires |
| 44 | * that all implementing subtypes must return their own type, rather than a supertype. |
| 45 | */ |
| 46 | public abstract Functional instantiate(List<StaticParam> params, List<StaticArg> args); |
| 47 | |
| 48 | public abstract Span getSpan(); |
| 49 | |
| 50 | public abstract List<StaticParam> staticParameters(); |
| 51 | |
| 52 | public abstract List<Param> parameters(); |
| 53 | |
| 54 | public abstract List<BaseType> thrownTypes(); |
| 55 | |
| 56 | public abstract Option<Expr> body(); |
| 57 | |
| 58 | public abstract Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor); |
| 59 | |
| 60 | // Lazy return type inference ----- |
| 61 | |
| 62 | /** |
| 63 | * Thunks are used to lazily get the return type of Functionals, as return |
| 64 | * types may not be available for functionals in the current program during |
| 65 | * type checking. |
| 66 | */ |
| 67 | protected Option<Thunk<Option<Type>>> _thunk = Option.none(); |
| 68 | |
| 69 | public void putThunk(Thunk<Option<Type>> thunk) { |
| 70 | _thunk = Option.<Thunk<Option<Type>>>some(LazyThunk.make(thunk)); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Evaluate the thunk to get a return type. Then replace the thunk with one |
| 75 | * that simply gets back the previously evaluated return type. |
| 76 | */ |
| 77 | public Option<Type> getReturnType() { |
| 78 | if (_thunk.isNone()) return Option.none(); |
| 79 | return _thunk.unwrap().value(); |
| 80 | } |
| 81 | } |
Note: See TracBrowser
for help on using the browser.

