Changeset 3915

Show
Ignore:
Timestamp:
07/02/09 07:59:33 (7 months ago)
Author:
jrhil47
Message:

[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.

Location:
trunk/ProjectFortress/src/com/sun/fortress
Files:
2 added
16 modified
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/NamingCzar.java

    r3912 r3915  
    599599 
    600600    public static String jvmSignatureFor(Function f, APIName ifNone) { 
    601         return jvmSignatureFor(f.parameters(), f.getReturnType(), ifNone); 
     601        return jvmSignatureFor(f.parameters(), f.getReturnType().unwrap(), ifNone); 
    602602    } 
    603603 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Constructor.java

    r3764 r3915  
    3939import edu.rice.cs.plt.iter.IterUtil; 
    4040import edu.rice.cs.plt.lambda.Lambda; 
     41import edu.rice.cs.plt.lambda.Thunk; 
    4142import edu.rice.cs.plt.tuple.Option; 
    4243 
     
    6061        _throwsClause = throwsClause; 
    6162        _where = where; 
     63        putThunk(new Thunk<Option<Type>>() { 
     64          @Override public Option<Type> value() { 
     65            return NI.nyi(); 
     66          } 
     67        }); 
    6268    } 
    6369 
     
    117123 
    118124        @Override 
    119         public Type getReturnType() { 
    120                 // TODO Auto-generated method stub 
    121                 return NI.nyi(); 
    122         } 
    123  
    124         @Override 
    125125        public Functional acceptNodeUpdateVisitor(final NodeUpdateVisitor v) { 
    126126 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/DeclaredFunction.java

    r3764 r3915  
    3737import com.sun.fortress.useful.NI; 
    3838 
     39import edu.rice.cs.plt.lambda.SimpleBox; 
    3940import edu.rice.cs.plt.tuple.Option; 
    4041 
     
    4243    private final FnDecl _ast; 
    4344 
    44     public DeclaredFunction(FnDecl ast) { _ast = ast; } 
     45    public DeclaredFunction(FnDecl ast) { 
     46      _ast = ast; 
     47      putThunk(SimpleBox.make(NodeUtil.getReturnType(_ast))); 
     48    } 
    4549 
    4650    public FnDecl ast() { return _ast; } 
     
    98102 
    99103        @Override 
    100         public Type getReturnType() { 
    101                 return NodeUtil.getReturnType(_ast).unwrap(); 
    102         } 
    103  
    104         @Override 
    105104        public Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor) { 
    106105                return new DeclaredFunction((FnDecl)this._ast.accept(visitor)); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/DeclaredMethod.java

    r3366 r3915  
    2121import java.util.List; 
    2222 
     23import com.sun.fortress.compiler.Types; 
    2324import com.sun.fortress.compiler.typechecker.StaticTypeReplacer; 
    2425import com.sun.fortress.nodes.BaseType; 
     
    3637import com.sun.fortress.nodes_util.Span; 
    3738 
     39import edu.rice.cs.plt.lambda.SimpleBox; 
    3840import edu.rice.cs.plt.tuple.Option; 
    3941 
     
    4648        _ast = ast; 
    4749        _declaringTrait = declaringTrait; 
     50        putThunk(SimpleBox.make(NodeUtil.getReturnType(_ast))); 
    4851    } 
    4952 
     
    9396 
    9497        @Override 
    95         public Type getReturnType() { 
    96                 return NodeUtil.getReturnType(_ast).unwrap(); 
    97         } 
    98  
    99         @Override 
    10098        public Id getDeclaringTrait() { 
    10199                return this._declaringTrait; 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FieldGetterMethod.java

    r3366 r3915  
    2121import java.util.List; 
    2222 
     23import com.sun.fortress.compiler.Types; 
    2324import com.sun.fortress.nodes.ArrowType; 
    2425import com.sun.fortress.nodes.BaseType; 
     
    3536import com.sun.fortress.useful.NI; 
    3637 
     38import edu.rice.cs.plt.lambda.SimpleBox; 
    3739import edu.rice.cs.plt.tuple.Option; 
    3840 
     
    4547        _ast = ast; 
    4648        _declaringTrait = declaringTrait; 
     49        putThunk(SimpleBox.make(_ast.getIdType())); 
    4750    } 
    4851 
     
    7881 
    7982        @Override 
    80         public Type getReturnType() { 
    81                 return _ast.getIdType().unwrap(); 
    82         } 
    83  
    84         @Override 
    8583        public Id getDeclaringTrait() { 
    8684                return this._declaringTrait; 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FieldSetterMethod.java

    r3366 r3915  
    3838import com.sun.fortress.useful.NI; 
    3939 
     40import edu.rice.cs.plt.lambda.SimpleBox; 
    4041import edu.rice.cs.plt.tuple.Option; 
    4142 
     
    4849        _ast = ast; 
    4950        _declaringTrait = declaringTrait; 
     51        putThunk(SimpleBox.make(Option.<Type>some(Types.VOID))); 
    5052    } 
    5153 
     
    8688 
    8789        @Override 
    88         public Type getReturnType() { 
    89                 return Types.VOID; 
    90         } 
    91  
    92         @Override 
    9390        public Id getDeclaringTrait() { 
    9491                return this._declaringTrait; 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Functional.java

    r3714 r3915  
    3131import com.sun.fortress.nodes_util.Span; 
    3232 
     33import edu.rice.cs.plt.lambda.LazyThunk; 
     34import edu.rice.cs.plt.lambda.Thunk; 
    3335import edu.rice.cs.plt.tuple.Option; 
    3436 
     
    4648    public abstract Span getSpan(); 
    4749 
    48     public abstract Type getReturnType(); 
    49  
    5050    public abstract List<StaticParam> staticParameters(); 
    5151 
     
    5757 
    5858    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    } 
    5981} 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FunctionalMethod.java

    r3764 r3915  
    3838import com.sun.fortress.useful.NI; 
    3939 
     40import edu.rice.cs.plt.lambda.SimpleBox; 
    4041import edu.rice.cs.plt.tuple.Option; 
    4142 
     
    5152        _ast = ast; 
    5253        _declaringTrait = declaringTrait; 
     54        putThunk(SimpleBox.make(NodeUtil.getReturnType(_ast))); 
    5355    } 
    5456 
     
    109111 
    110112        @Override 
    111         public Type getReturnType() { 
    112                 return NodeUtil.getReturnType(_ast).unwrap(); 
    113         } 
    114  
    115         @Override 
    116113        public Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor) { 
    117114                return new FunctionalMethod((FnDecl)this.ast().accept(visitor), this._declaringTrait); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/index/ParametricOperator.java

    r3518 r3915  
    3838import com.sun.fortress.useful.NI; 
    3939 
     40import edu.rice.cs.plt.lambda.SimpleBox; 
    4041import edu.rice.cs.plt.tuple.Option; 
    4142 
     
    5051        super(ast, declaringTrait); 
    5152        _name = (Op)NodeUtil.getName(ast); 
     53        putThunk(SimpleBox.make(NodeUtil.getReturnType(_ast))); 
    5254    } 
    5355 
     
    99101 
    100102        @Override 
    101         public Type getReturnType() { 
    102                 return NodeUtil.getReturnType(_ast).unwrap(); 
    103         } 
    104  
    105         @Override 
    106103        public Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor) { 
    107104                return new FunctionalMethod((FnDecl)this.ast().accept(visitor), this._declaringTrait); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/phases/OverloadSet.java

    r3906 r3915  
    8787        } 
    8888        public Type getReturnType() { 
    89             return tagF.getReturnType(); 
     89            return tagF.getReturnType().unwrap(); 
    9090        } 
    9191        public int hashCode() { 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java

    r3863 r3915  
    606606            if(getters.containsKey(thatFieldRef.getField())) { 
    607607                Method field=(Method)getters.get(thatFieldRef.getField()).instantiate(trait_static_params, trait_static_args); 
    608                 return Option.some(field.getReturnType()); 
     608                return Option.some(field.getReturnType().unwrap()); 
    609609            } 
    610610            else { 
     
    34723472            List<Type> ranges = CollectUtil.makeList(IterUtil.map(candidates, new Lambda<Method,Type>(){ 
    34733473                public Type value(Method arg0) { 
    3474                     return arg0.getReturnType(); 
     3474                    return arg0.getReturnType().unwrap(); 
    34753475                }})); 
    34763476 
     
    48784878 
    48794879        List<Type> ranges = CollectUtil.makeList(IterUtil.map(candidates, new Lambda<Method,Type>(){ 
    4880             public Type value(Method arg0) { return arg0.getReturnType(); }})); 
     4880            public Type value(Method arg0) { return arg0.getReturnType().unwrap(); }})); 
    48814881 
    48824882        Type range = this.subtypeChecker.meet(ranges); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeEnv.java

    r3803 r3915  
    356356     * compiler to distinguish them from other variants with the same _erased_ signature. 
    357357     */ 
     358    // DONE 
    358359    public final TypeEnv extend(LValue... entries) { 
    359360        if (entries.length == 0) { return this; } 
    360361        else { return new LValueTypeEnv(entries, this); } 
    361362    } 
    362  
     363    // DONE 
    363364    public final TypeEnv extendWithLValues(List<LValue> entries) { 
    364365        if (entries.size() == 0) { return this; } 
    365366        else { return new LValueTypeEnv(entries, this); } 
    366367    } 
    367  
     368    // DONE 
    368369    public final TypeEnv extend(LocalVarDecl decl) { 
    369370        if (decl.getLhs().size() == 0) { return this; } 
    370371        else { return new LocalVarTypeEnv(decl, this); } 
    371372    } 
    372  
     373    // CALLED WITH CompilationUnitIndex.variables() 
     374    // DONE 
    373375    public final TypeEnv extend(Map<Id, Variable> vars) { 
    374376        if (vars.size() == 0) { return this; } 
    375377        else { return new VarTypeEnv(vars, this); } 
    376378    } 
    377  
     379    // DONE 
    378380    public final TypeEnv extendWithFunctions(Relation<IdOrOpOrAnonymousName, ? extends Function> fns) { 
    379381        if (fns.size() == 0) { return this; } 
    380382        else { return new FnTypeEnv(fns, this); } 
    381383    } 
    382  
     384    // UNNECESSARY 
    383385    public final TypeEnv extendWithFnDecls(Relation<IdOrOpOrAnonymousName, FnDecl> fns) { 
    384386        if (fns.size() == 0) { return this; } 
    385387        else { return new FnDeclTypeEnv(fns, this); } 
    386388    } 
    387  
     389    // DERIVED 
    388390    public final TypeEnv extendWithMethods(Relation<IdOrOpOrAnonymousName, Method> methods) { 
    389391        if (methods.size() == 0) { return this; } 
    390392        else { return new MethodTypeEnv(methods, this); } 
    391393    } 
    392  
     394    // DERIVED 
    393395    public final TypeEnv extendWithParams(List<Param> params) { 
    394396        if (params.size() == 0) { return this; } 
    395397        else { return new ParamTypeEnv(params, this); } 
    396398    } 
    397  
     399    // DERIVED 
    398400    public final TypeEnv extendWithParams(scala.List<Param> params) { 
    399401        return extendWithParams(toJavaList(params)); 
     
    408410        return extendWithStaticParams(toJavaList(params)); 
    409411    } 
    410  
     412    // DONE 
    411413    public final TypeEnv extendWithTypeConses(Map<Id, TypeConsIndex> typeConses) { 
    412414        if (typeConses.isEmpty()) { 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/OverloadingChecker.scala

    r3877 r3915  
    117117                    if ( param.getIdType.isSome && 
    118118                         ! typeAnalyzer.equivalent(param.getIdType.unwrap, 
    119                                                    getter.getReturnType).isTrue ) 
     119                                                   getter.getReturnType.unwrap).isTrue ) 
    120120                        error(span, 
    121121                              "The parameter type of a setter must be " + 
     
    144144        var signatures = List[((JavaList[StaticParam],Type,Type),Span)]() 
    145145        for ( f <- set ; if isDeclaredFunctional(f) ) { 
    146             val result = f.getReturnType 
     146            val result = f.getReturnType.unwrap 
    147147            val param = paramsToType(f.parameters, f.getSpan) 
    148148            val sparams = f.staticParameters 
     
    186186        subtype(paramsToType(g.parameters, g.getSpan), 
    187187                paramsToType(f.parameters, f.getSpan)) && 
    188         subtype(f.getReturnType, g.getReturnType) 
     188        subtype(f.getReturnType.unwrap, g.getReturnType.unwrap) 
    189189 
    190190    private def subtype(sub_type: Type, super_type: Type): Boolean = 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/impls/Common.scala

    r3902 r3915  
    177177      val (arg, param) = argAndParam 
    178178      (arg, param.getKind) match { 
    179         case (STypeArg(_, argType), SKindType(_)) => 
     179        case (STypeArg(_, argType), _:KindType) => 
    180180            toList(param.getExtendsClause).forall((bound:Type) => 
    181181              isSubtype(argType, bound, arg, 
    182182                        errorMsg(normalize(argType), " not a subtype of ", normalize(bound)))) 
    183         case (SIntArg(_, _), SKindInt(_)) => true 
    184         case (SBoolArg(_, _), SKindBool(_)) => true 
    185         case (SDimArg(_, _), SKindDim(_)) => true 
    186         case (SOpArg(_, _), SKindOp(_)) => true 
    187         case (SUnitArg(_, _), SKindUnit(_)) => true 
    188         case (SIntArg(_, _), SKindNat(_)) => true 
     183        case (_:IntArg, _:KindInt) => true 
     184        case (_:BoolArg, _:KindBool) => true 
     185        case (_:DimArg, _:KindDim) => true 
     186        case (_:OpArg, _:KindOp) => true 
     187        case (_:UnitArg, _:KindUnit) => true 
     188        case (_:IntArg, _:KindNat) => true 
    189189        case (_, _) => false 
    190190      } 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/impls/Functionals.scala

    r3905 r3915  
    328328      val methods = findMethodsInTraitHierarchy(op.get, objType) 
    329329      val arrows = 
    330         if (sargs.isEmpty) methods.map(makeArrowFromFunction) 
    331         else methods. 
    332                flatMap(m => staticInstantiation(sargs, makeArrowFromFunction(m))). 
     330        if (sargs.isEmpty) methods.map(makeArrowFromFunctional) 
     331        else methods.flatMap(m => 
     332               staticInstantiation(sargs, makeArrowFromFunctional(m))). 
    333333               map(_.asInstanceOf[ArrowType]) 
    334334 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/KindEnv.scala

    r3905 r3915  
    1616 ******************************************************************************/ 
    1717 
    18 package com.sun.fortress.scala_src.typechecker 
     18package com.sun.fortress.scala_src.typechecker.staticenv 
    1919 
    2020import com.sun.fortress.compiler.Types 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/STypeEnv.scala

    r3905 r3915  
    1616 ******************************************************************************/ 
    1717 
    18 package com.sun.fortress.scala_src.typechecker 
     18package com.sun.fortress.scala_src.typechecker.staticenv 
    1919 
    20 import com.sun.fortress.exceptions.InterpreterBug.bug 
    2120import com.sun.fortress.nodes._ 
    2221import com.sun.fortress.nodes_util.Modifiers 
    23 import com.sun.fortress.scala_src.useful.SExprUtil 
    2422import scala.collection.immutable.EmptyMap 
    2523 
     
    6462 
    6563/** Companion module for STypeEnv. */ 
    66 object STypeEnv extends StaticEnvCompanion[Type] { 
     64object STypeEnv extends StaticEnvCompanion[Type] with STypeEnvExtraction { 
    6765   
    6866  /** My type. */ 
     
    7573  def make(node: Any): STypeEnv = 
    7674    new NestedSTypeEnv(EmptySTypeEnv, extractEnvBindings(node)) 
    77    
    78   /** Extract out the bindings in node. */ 
    79   protected def extractEnvBindings(node: Any): Collection[TypeBinding] = null 
    80 //    node match { 
    81 //      case SParam =>  
    82 //    } 
    83    
    84 //  protected def extractFnDecls(node: Any): List[FnDecl] = null 
    85 //   
    86 //  /** 
    87 //   * A type environment that stores types of named functionals. Return types 
    88 //   * might not always be given on functional declarations, so this type 
    89 //   * environment will lazily evaluate those types as needed. 
    90 //   *  
    91 //   * This class should only ever be instantiated by `STypeEnv`. 
    92 //   *  
    93 //   * @param parent A static environment that this one extends. 
    94 //   * @param fnDecls An immutable list of all the functional declarations in 
    95 //   *                scope for this type environment. 
    96 //   */ 
    97 //  protected class LazyFnTypeEnv(protected val parent: STypeEnv, 
    98 //                                protected val fnDecls: List[FnDecl], 
    99 //                                protected val initialChecker: STypeChecker) 
    100 //      extends STypeEnv(parent, Nil) { 
    101 //     
    102 //    import scala.collection.mutable.Map 
    103 //    import scala.collection.mutable.Stack 
    104 //     
    105 //    type TypeThunk = Function0[Option[Type]] 
    106 //    type UnambiguousName = Name 
    107 //     
    108 //    /** 
    109 //     * Contains the function names that have been called thus far during the 
    110 //     * type checking of function bodies in this environment. 
    111 //     */ 
    112 //    protected var callStack: Stack[Name] = new Stack 
    113 //     
    114 //    /** Maps unsolved overloadings to their thunks. */ 
    115 //    protected var unsolvedOverloadings: Map[UnambiguousName, TypeThunk] = Map.empty 
    116 //     
    117 //    /** Maps solved overloadings to their thunks. */ 
    118 //    protected var solvedOverloadings: Map[UnambiguousName, Type] = Map.empty 
    119 //     
    120 //    /**  */ 
    121 //    protected var solved: Map[Name, Type] = Map.empty 
    122 //     
    123 //    protected def makeThunk(fnDecl: FnDecl): TypeThunk = { 
    124 //       
    125 //      // If return type given, just thunk it. 
    126 //      fnDecl.getHeader.getReturnType match { 
    127 //        case Some(t) => return () => t 
    128 //        case _ => 
    129 //      } 
    130 //       
    131 //      // Get relevant parts out of the decl. 
    132 //      val name = fnDecl.getHeader.getName 
    133 //      val unambiguousName = fnDecl.getUnambiguousName 
    134 //      val body = fnDecl.getBody.getOrElse(bug("No body on function.")) 
    135 //       
    136 //      // Capture the type checker at this point. 
    137 //      val checker = this.initialChecker 
    138 //      def thunk: Option[Type] = { 
    139 //         
    140 //        // If we have already seen this name, then there is a cycle! 
    141 //        if (callStack.contains(name)) { 
    142 //          checker.signal(body, "Cyclical reference to function %s while checking body of function %s" 
    143 //                                   .format(name, this.callStack.top)) 
    144 //        } 
    145 //         
    146 //        // Add this name to the call stack. 
    147 //        this.callStack += name 
    148 //         
    149 //        // Extend the type checker with the params of this decl and check. 
    150 //        val newChecker = checker.extend(fnDecl) 
    151 //        SExprUtil.getType(newChecker.checkExpr(body)) 
    152 //      } 
    153 //      thunk _ 
    154 //    } 
    155 //  } 
    15675} 
    15776 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/StaticEnv.scala

    r3905 r3915  
    1616 ******************************************************************************/ 
    1717 
    18 package com.sun.fortress.scala_src.typechecker 
     18package com.sun.fortress.scala_src.typechecker.staticenv 
    1919 
    2020import com.sun.fortress.nodes.Name 
    2121import com.sun.fortress.nodes.Type 
    22 import com.sun.fortress.nodes_util.Modifiers 
    2322 
    2423/** 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/useful/STypesUtil.scala

    r3905 r3915  
    1818package com.sun.fortress.scala_src.useful 
    1919 
     20import _root_.java.util.ArrayList 
    2021import com.sun.fortress.compiler.GlobalEnvironment 
    2122import com.sun.fortress.compiler.Types 
    22 import com.sun.fortress.compiler.index.CompilationUnitIndex 
    23 import com.sun.fortress.compiler.index.DeclaredMethod 
    24 import com.sun.fortress.compiler.index.FieldGetterMethod 
    25 import com.sun.fortress.compiler.index.FieldSetterMethod 
    26 import com.sun.fortress.compiler.index.Method 
    27 import com.sun.fortress.compiler.index.TypeConsIndex 
     23import com.sun.fortress.compiler.index._ 
    2824import com.sun.fortress.compiler.typechecker.StaticTypeReplacer 
    2925import com.sun.fortress.compiler.typechecker.TypeAnalyzer 
     
    3228import com.sun.fortress.exceptions.TypeError 
    3329import com.sun.fortress.nodes._ 
    34 import com.sun.fortress.nodes_util.NodeFactory 
    35 import com.sun.fortress.nodes_util.NodeUtil 
     30import com.sun.fortress.nodes_util.ExprFactory 
     31import com.sun.fortress.nodes_util.{NodeFactory => NF} 
     32import com.sun.fortress.nodes_util.{NodeUtil => NU} 
    3633import com.sun.fortress.scala_src.nodes._ 
    3734import com.sun.fortress.scala_src.useful.Lists._ 
     
    4845 
    4946  /** 
    50    * Return the arrow type of the given FnDecl. 
    51    */ 
    52   def makeArrowFromFunction(f: FnDecl): ArrowType = { 
    53     val returnType = f.getHeader.getReturnType.get 
    54     val params = toList(f.getHeader.getParams).map(NodeUtil.getParamType) 
     47   * Return the arrow type of the given FnDecl node. 
     48   */ 
     49  def makeArrowFromFnDecl(f: FnDecl): ArrowType = { 
     50    val returnType = f.getHeader.getReturnType.unwrap 
     51    val params = toList(f.getHeader.getParams).map(NU.getParamType) 
    5552    val argType = makeArgumentType(params) 
    5653    val sparams = f.getHeader.getStaticParams 
    5754    val where = f.getHeader.getWhereClause 
    5855    val throws = f.getHeader.getThrowsClause 
    59     NodeFactory.makeArrowType(NodeUtil.getSpan(f), 
    60                               false, 
    61                               argType, 
    62                               returnType, 
    63                               NodeFactory.makeEffect(throws), 
    64                               sparams, 
    65                               where) 
    66   } 
    67  
     56    NF.makeArrowType(NU.getSpan(f), 
     57                     false, 
     58                     argType, 
     59                     returnType, 
     60                     NF.makeEffect(throws), 
     61                     sparams, 
     62                     where) 
     63  } 
     64   
    6865  /** 
    6966   * Return the arrow type of the given Method. 
    70    */ 
    71   def makeArrowFromFunction(m: Method): ArrowType = { 
    72     val returnType = m.getReturnType 
    73     val params = toList(m.parameters).map(NodeUtil.getParamType) 
    74     val argType = makeArgumentType(params) 
    75     m match { 
    76       case m:DeclaredMethod => makeArrowFromFunction(m.ast) 
    77       case g:FieldGetterMethod => 
    78         NodeFactory.makeArrowType(NodeUtil.getSpan(g.ast), 
    79                                   argType, 
    80                                   returnType) 
    81       case s:FieldSetterMethod => 
    82         NodeFactory.makeArrowType(NodeUtil.getSpan(s.ast), 
    83                                   argType, 
    84                                   returnType) 
     67   * @TODO Make sure that the getReturnType method in these indices works 
     68   * as it should. 
     69   */ 
     70  def makeArrowFromFunctional(f: Functional): ArrowType = f match { 
     71    case m:Method => 
     72      val returnType = m.getReturnType.unwrap 
     73      val params = toList(m.parameters).map(NU.getParamType) 
     74      val argType = makeArgumentType(params) 
     75      m match { 
     76        case m:DeclaredMethod => makeArrowFromFnDecl(m.ast) 
     77        case g:FieldGetterMethod => 
     78          NF.makeArrowType(NU.getSpan(g.ast), 
     79                           argType, 
     80                           returnType) 
     81        case s:FieldSetterMethod => 
     82          NF.makeArrowType(NU.getSpan(s.ast), 
     83                           argType, 
     84                           returnType) 
     85      } 
     86    case f:Function => f match { 
     87      case f:DeclaredFunction => makeArrowFromFnDecl(f.ast) 
     88      case f:FunctionalMethod => makeArrowFromFnDecl(f.ast) 
     89      case f:Constructor => 
     90        val argType = 
     91          makeArgumentType(toList(f.parameters).map(NU.getParamType)) 
     92        val returnType = f.getReturnType.unwrap 
     93        val sparams = f.staticParameters 
     94        val where = f.where 
     95        val throws = f.thrownTypes 
     96        NF.makeArrowType(NF.typeSpan, 
     97                         false, 
     98                         argType, 
     99                         returnType, 
     100                         NF.makeEffect(throws), 
     101                         sparams, 
     102                         where) 
    85103    } 
    86104  } 
     
    93111    case t :: Nil => t 
    94112    case _ => 
    95       val span1 = NodeUtil.getSpan(ts.head) 
    96       val span2 = NodeUtil.getSpan(ts.last) 
    97       NodeFactory.makeTupleType(NodeUtil.spanTwo(span1, span2), toJavaList(ts)) 
     113      val span1 = NU.getSpan(ts.head) 
     114      val span2 = NU.getSpan(ts.last) 
     115      NF.makeTupleType(NU.spanTwo(span1, span2), toJavaList(ts)) 
     116  } 
     117   
     118  /** 
     119   * Make a domain type from a list of parameters, including varargs and 
     120   * keyword types. Ported from `TypeEnv.domainFromParams`. 
     121   */ 
     122  def makeDomainType(ps: List[Param]): Type = { 
     123    val paramTypes = new ArrayList[Type](ps.length) 
     124    val keywordTypes = new ArrayList[KeywordType](ps.length) 
     125    var varargsType: Option[Type] = None 
     126    val span = ps match { 
     127      case Nil => NF.typeSpan 
     128      case _ => NU.spanTwo(NU.getSpan(ps.first), NU.getSpan(ps.last)) 
     129    } 
     130     
     131    // Extract out the appropriate parameter types. 
     132    ps.foreach(p => p match { 
     133      case SParam(_, _, _, _, _, Some(vaType)) => // Vararg 
     134        varargsType = Some(vaType) 
     135      case SParam(_, name, _, Some(idType), Some(expr), _) => // Keyword 
     136        keywordTypes.add(NF.makeKeywordType(name, idType)) 
     137      case SParam(_, _, _, Some(idType), _, _) => // Normal 
     138        paramTypes.add(idType) 
     139      case _ => bug("Parameter missing type")  
     140    }) 
     141    NF.makeDomain(span, paramTypes, toJavaOption(varargsType), keywordTypes) 
     142  } 
     143   
     144  /** 
     145   * Convert a static parameter to the corresponding static arg. Ported from 
     146   * `TypeEnv.staticParamsToArgs`. 
     147   */ 
     148  def staticParamToArg(p: StaticParam): StaticArg = { 
     149    val span = NU.getSpan(p) 
     150    (p.getName, p.getKind) match { 
     151      case (id:Id, _:KindBool) => NF.makeBoolArg(span, NF.makeBoolRef(span, id)) 
     152      case (id:Id, _:KindDim) => NF.makeDimArg(span, NF.makeDimRef(span, id)) 
     153      case (id:Id, _:KindInt) => NF.makeIntArg(span, NF.makeIntRef(span, id)) 
     154      case (id:Id, _:KindNat) => NF.makeIntArg(span, NF.makeIntRef(span, id)) 
     155      case (id:Id, _:KindType) => NF.makeTypeArg(span, NF.makeVarType(span, id)) 
     156      case (id:Id, _:KindUnit) => 
     157        NF.makeUnitArg(span, NF.makeUnitRef(span, false, id)) 
     158      case (op:Op, _:KindOp) => NF.makeOpArg(span, ExprFactory.makeOpRef(op)) 
     159      case _ => bug("Unexpected static parameter kind") 
     160    } 
    98161  } 
    99162 
     
    173236  def staticParamBoundType(sparam: StaticParam): Option[Type] = 
    174237    sparam.getKind match { 
    175       case SKindType(_) => Some(NodeFactory.makeIntersectionType(sparam.getExtendsClause)) 
     238      case SKindType(_) => Some(NF.makeIntersectionType(sparam.getExtendsClause)) 
    176239      case _ => None 
    177240    } 
     
    184247    case SKindType(_) => { 
    185248      // Create a new inference var type. 
    186       val t = NodeFactory.make_InferenceVarType(NodeUtil.getSpan(sparam)) 
    187       NodeFactory.makeTypeArg(NodeFactory.makeSpan(t), t) 
     249      val t = NF.make_InferenceVarType(NU.getSpan(sparam)) 
     250      NF.makeTypeArg(NF.makeSpan(t), t) 
    188251    } 
    189252    case SKindInt(_) => NI.nyi()