Changeset 3915
- Timestamp:
- 07/02/09 07:59:33 (7 months ago)
- Location:
- trunk/ProjectFortress/src/com/sun/fortress
- Files:
-
- 2 added
- 16 modified
- 3 moved
-
compiler/NamingCzar.java (modified) (1 diff)
-
compiler/index/Constructor.java (modified) (3 diffs)
-
compiler/index/DeclaredFunction.java (modified) (3 diffs)
-
compiler/index/DeclaredMethod.java (modified) (4 diffs)
-
compiler/index/FieldGetterMethod.java (modified) (4 diffs)
-
compiler/index/FieldSetterMethod.java (modified) (3 diffs)
-
compiler/index/Functional.java (modified) (3 diffs)
-
compiler/index/FunctionalMethod.java (modified) (3 diffs)
-
compiler/index/ParametricOperator.java (modified) (3 diffs)
-
compiler/phases/OverloadSet.java (modified) (1 diff)
-
compiler/typechecker/TypeChecker.java (modified) (3 diffs)
-
compiler/typechecker/TypeEnv.java (modified) (2 diffs)
-
scala_src/typechecker/OverloadingChecker.scala (modified) (3 diffs)
-
scala_src/typechecker/impls/Common.scala (modified) (1 diff)
-
scala_src/typechecker/impls/Functionals.scala (modified) (1 diff)
-
scala_src/typechecker/staticenv (added)
-
scala_src/typechecker/staticenv/KindEnv.scala (moved) (moved from trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/KindEnv.scala) (1 diff)
-
scala_src/typechecker/staticenv/STypeEnv.scala (moved) (moved from trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/STypeEnv.scala) (3 diffs)
-
scala_src/typechecker/staticenv/STypeEnvExtraction.scala (added)
-
scala_src/typechecker/staticenv/StaticEnv.scala (moved) (moved from trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/StaticEnv.scala) (1 diff)
-
scala_src/useful/STypesUtil.scala (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/src/com/sun/fortress/compiler/NamingCzar.java
r3912 r3915 599 599 600 600 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); 602 602 } 603 603 -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Constructor.java
r3764 r3915 39 39 import edu.rice.cs.plt.iter.IterUtil; 40 40 import edu.rice.cs.plt.lambda.Lambda; 41 import edu.rice.cs.plt.lambda.Thunk; 41 42 import edu.rice.cs.plt.tuple.Option; 42 43 … … 60 61 _throwsClause = throwsClause; 61 62 _where = where; 63 putThunk(new Thunk<Option<Type>>() { 64 @Override public Option<Type> value() { 65 return NI.nyi(); 66 } 67 }); 62 68 } 63 69 … … 117 123 118 124 @Override 119 public Type getReturnType() {120 // TODO Auto-generated method stub121 return NI.nyi();122 }123 124 @Override125 125 public Functional acceptNodeUpdateVisitor(final NodeUpdateVisitor v) { 126 126 -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/DeclaredFunction.java
r3764 r3915 37 37 import com.sun.fortress.useful.NI; 38 38 39 import edu.rice.cs.plt.lambda.SimpleBox; 39 40 import edu.rice.cs.plt.tuple.Option; 40 41 … … 42 43 private final FnDecl _ast; 43 44 44 public DeclaredFunction(FnDecl ast) { _ast = ast; } 45 public DeclaredFunction(FnDecl ast) { 46 _ast = ast; 47 putThunk(SimpleBox.make(NodeUtil.getReturnType(_ast))); 48 } 45 49 46 50 public FnDecl ast() { return _ast; } … … 98 102 99 103 @Override 100 public Type getReturnType() {101 return NodeUtil.getReturnType(_ast).unwrap();102 }103 104 @Override105 104 public Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor) { 106 105 return new DeclaredFunction((FnDecl)this._ast.accept(visitor)); -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/DeclaredMethod.java
r3366 r3915 21 21 import java.util.List; 22 22 23 import com.sun.fortress.compiler.Types; 23 24 import com.sun.fortress.compiler.typechecker.StaticTypeReplacer; 24 25 import com.sun.fortress.nodes.BaseType; … … 36 37 import com.sun.fortress.nodes_util.Span; 37 38 39 import edu.rice.cs.plt.lambda.SimpleBox; 38 40 import edu.rice.cs.plt.tuple.Option; 39 41 … … 46 48 _ast = ast; 47 49 _declaringTrait = declaringTrait; 50 putThunk(SimpleBox.make(NodeUtil.getReturnType(_ast))); 48 51 } 49 52 … … 93 96 94 97 @Override 95 public Type getReturnType() {96 return NodeUtil.getReturnType(_ast).unwrap();97 }98 99 @Override100 98 public Id getDeclaringTrait() { 101 99 return this._declaringTrait; -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FieldGetterMethod.java
r3366 r3915 21 21 import java.util.List; 22 22 23 import com.sun.fortress.compiler.Types; 23 24 import com.sun.fortress.nodes.ArrowType; 24 25 import com.sun.fortress.nodes.BaseType; … … 35 36 import com.sun.fortress.useful.NI; 36 37 38 import edu.rice.cs.plt.lambda.SimpleBox; 37 39 import edu.rice.cs.plt.tuple.Option; 38 40 … … 45 47 _ast = ast; 46 48 _declaringTrait = declaringTrait; 49 putThunk(SimpleBox.make(_ast.getIdType())); 47 50 } 48 51 … … 78 81 79 82 @Override 80 public Type getReturnType() {81 return _ast.getIdType().unwrap();82 }83 84 @Override85 83 public Id getDeclaringTrait() { 86 84 return this._declaringTrait; -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FieldSetterMethod.java
r3366 r3915 38 38 import com.sun.fortress.useful.NI; 39 39 40 import edu.rice.cs.plt.lambda.SimpleBox; 40 41 import edu.rice.cs.plt.tuple.Option; 41 42 … … 48 49 _ast = ast; 49 50 _declaringTrait = declaringTrait; 51 putThunk(SimpleBox.make(Option.<Type>some(Types.VOID))); 50 52 } 51 53 … … 86 88 87 89 @Override 88 public Type getReturnType() {89 return Types.VOID;90 }91 92 @Override93 90 public Id getDeclaringTrait() { 94 91 return this._declaringTrait; -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Functional.java
r3714 r3915 31 31 import com.sun.fortress.nodes_util.Span; 32 32 33 import edu.rice.cs.plt.lambda.LazyThunk; 34 import edu.rice.cs.plt.lambda.Thunk; 33 35 import edu.rice.cs.plt.tuple.Option; 34 36 … … 46 48 public abstract Span getSpan(); 47 49 48 public abstract Type getReturnType();49 50 50 public abstract List<StaticParam> staticParameters(); 51 51 … … 57 57 58 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 } 59 81 } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FunctionalMethod.java
r3764 r3915 38 38 import com.sun.fortress.useful.NI; 39 39 40 import edu.rice.cs.plt.lambda.SimpleBox; 40 41 import edu.rice.cs.plt.tuple.Option; 41 42 … … 51 52 _ast = ast; 52 53 _declaringTrait = declaringTrait; 54 putThunk(SimpleBox.make(NodeUtil.getReturnType(_ast))); 53 55 } 54 56 … … 109 111 110 112 @Override 111 public Type getReturnType() {112 return NodeUtil.getReturnType(_ast).unwrap();113 }114 115 @Override116 113 public Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor) { 117 114 return new FunctionalMethod((FnDecl)this.ast().accept(visitor), this._declaringTrait); -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/ParametricOperator.java
r3518 r3915 38 38 import com.sun.fortress.useful.NI; 39 39 40 import edu.rice.cs.plt.lambda.SimpleBox; 40 41 import edu.rice.cs.plt.tuple.Option; 41 42 … … 50 51 super(ast, declaringTrait); 51 52 _name = (Op)NodeUtil.getName(ast); 53 putThunk(SimpleBox.make(NodeUtil.getReturnType(_ast))); 52 54 } 53 55 … … 99 101 100 102 @Override 101 public Type getReturnType() {102 return NodeUtil.getReturnType(_ast).unwrap();103 }104 105 @Override106 103 public Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor) { 107 104 return new FunctionalMethod((FnDecl)this.ast().accept(visitor), this._declaringTrait); -
trunk/ProjectFortress/src/com/sun/fortress/compiler/phases/OverloadSet.java
r3906 r3915 87 87 } 88 88 public Type getReturnType() { 89 return tagF.getReturnType() ;89 return tagF.getReturnType().unwrap(); 90 90 } 91 91 public int hashCode() { -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java
r3863 r3915 606 606 if(getters.containsKey(thatFieldRef.getField())) { 607 607 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()); 609 609 } 610 610 else { … … 3472 3472 List<Type> ranges = CollectUtil.makeList(IterUtil.map(candidates, new Lambda<Method,Type>(){ 3473 3473 public Type value(Method arg0) { 3474 return arg0.getReturnType() ;3474 return arg0.getReturnType().unwrap(); 3475 3475 }})); 3476 3476 … … 4878 4878 4879 4879 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(); }})); 4881 4881 4882 4882 Type range = this.subtypeChecker.meet(ranges); -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeEnv.java
r3803 r3915 356 356 * compiler to distinguish them from other variants with the same _erased_ signature. 357 357 */ 358 // DONE 358 359 public final TypeEnv extend(LValue... entries) { 359 360 if (entries.length == 0) { return this; } 360 361 else { return new LValueTypeEnv(entries, this); } 361 362 } 362 363 // DONE 363 364 public final TypeEnv extendWithLValues(List<LValue> entries) { 364 365 if (entries.size() == 0) { return this; } 365 366 else { return new LValueTypeEnv(entries, this); } 366 367 } 367 368 // DONE 368 369 public final TypeEnv extend(LocalVarDecl decl) { 369 370 if (decl.getLhs().size() == 0) { return this; } 370 371 else { return new LocalVarTypeEnv(decl, this); } 371 372 } 372 373 // CALLED WITH CompilationUnitIndex.variables() 374 // DONE 373 375 public final TypeEnv extend(Map<Id, Variable> vars) { 374 376 if (vars.size() == 0) { return this; } 375 377 else { return new VarTypeEnv(vars, this); } 376 378 } 377 379 // DONE 378 380 public final TypeEnv extendWithFunctions(Relation<IdOrOpOrAnonymousName, ? extends Function> fns) { 379 381 if (fns.size() == 0) { return this; } 380 382 else { return new FnTypeEnv(fns, this); } 381 383 } 382 384 // UNNECESSARY 383 385 public final TypeEnv extendWithFnDecls(Relation<IdOrOpOrAnonymousName, FnDecl> fns) { 384 386 if (fns.size() == 0) { return this; } 385 387 else { return new FnDeclTypeEnv(fns, this); } 386 388 } 387 389 // DERIVED 388 390 public final TypeEnv extendWithMethods(Relation<IdOrOpOrAnonymousName, Method> methods) { 389 391 if (methods.size() == 0) { return this; } 390 392 else { return new MethodTypeEnv(methods, this); } 391 393 } 392 394 // DERIVED 393 395 public final TypeEnv extendWithParams(List<Param> params) { 394 396 if (params.size() == 0) { return this; } 395 397 else { return new ParamTypeEnv(params, this); } 396 398 } 397 399 // DERIVED 398 400 public final TypeEnv extendWithParams(scala.List<Param> params) { 399 401 return extendWithParams(toJavaList(params)); … … 408 410 return extendWithStaticParams(toJavaList(params)); 409 411 } 410 412 // DONE 411 413 public final TypeEnv extendWithTypeConses(Map<Id, TypeConsIndex> typeConses) { 412 414 if (typeConses.isEmpty()) { -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/OverloadingChecker.scala
r3877 r3915 117 117 if ( param.getIdType.isSome && 118 118 ! typeAnalyzer.equivalent(param.getIdType.unwrap, 119 getter.getReturnType ).isTrue )119 getter.getReturnType.unwrap).isTrue ) 120 120 error(span, 121 121 "The parameter type of a setter must be " + … … 144 144 var signatures = List[((JavaList[StaticParam],Type,Type),Span)]() 145 145 for ( f <- set ; if isDeclaredFunctional(f) ) { 146 val result = f.getReturnType 146 val result = f.getReturnType.unwrap 147 147 val param = paramsToType(f.parameters, f.getSpan) 148 148 val sparams = f.staticParameters … … 186 186 subtype(paramsToType(g.parameters, g.getSpan), 187 187 paramsToType(f.parameters, f.getSpan)) && 188 subtype(f.getReturnType , g.getReturnType)188 subtype(f.getReturnType.unwrap, g.getReturnType.unwrap) 189 189 190 190 private def subtype(sub_type: Type, super_type: Type): Boolean = -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/impls/Common.scala
r3902 r3915 177 177 val (arg, param) = argAndParam 178 178 (arg, param.getKind) match { 179 case (STypeArg(_, argType), SKindType(_)) =>179 case (STypeArg(_, argType), _:KindType) => 180 180 toList(param.getExtendsClause).forall((bound:Type) => 181 181 isSubtype(argType, bound, arg, 182 182 errorMsg(normalize(argType), " not a subtype of ", normalize(bound)))) 183 case ( SIntArg(_, _), SKindInt(_)) => true184 case ( SBoolArg(_, _), SKindBool(_)) => true185 case ( SDimArg(_, _), SKindDim(_)) => true186 case ( SOpArg(_, _), SKindOp(_)) => true187 case ( SUnitArg(_, _), SKindUnit(_)) => true188 case ( SIntArg(_, _), SKindNat(_)) => true183 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 189 189 case (_, _) => false 190 190 } -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/impls/Functionals.scala
r3905 r3915 328 328 val methods = findMethodsInTraitHierarchy(op.get, objType) 329 329 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))). 333 333 map(_.asInstanceOf[ArrowType]) 334 334 -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/KindEnv.scala
r3905 r3915 16 16 ******************************************************************************/ 17 17 18 package com.sun.fortress.scala_src.typechecker 18 package com.sun.fortress.scala_src.typechecker.staticenv 19 19 20 20 import com.sun.fortress.compiler.Types -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/STypeEnv.scala
r3905 r3915 16 16 ******************************************************************************/ 17 17 18 package com.sun.fortress.scala_src.typechecker 18 package com.sun.fortress.scala_src.typechecker.staticenv 19 19 20 import com.sun.fortress.exceptions.InterpreterBug.bug21 20 import com.sun.fortress.nodes._ 22 21 import com.sun.fortress.nodes_util.Modifiers 23 import com.sun.fortress.scala_src.useful.SExprUtil24 22 import scala.collection.immutable.EmptyMap 25 23 … … 64 62 65 63 /** Companion module for STypeEnv. */ 66 object STypeEnv extends StaticEnvCompanion[Type] {64 object STypeEnv extends StaticEnvCompanion[Type] with STypeEnvExtraction { 67 65 68 66 /** My type. */ … … 75 73 def make(node: Any): STypeEnv = 76 74 new NestedSTypeEnv(EmptySTypeEnv, extractEnvBindings(node)) 77 78 /** Extract out the bindings in node. */79 protected def extractEnvBindings(node: Any): Collection[TypeBinding] = null80 // node match {81 // case SParam =>82 // }83 84 // protected def extractFnDecls(node: Any): List[FnDecl] = null85 //86 // /**87 // * A type environment that stores types of named functionals. Return types88 // * might not always be given on functional declarations, so this type89 // * 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 in95 // * 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.Map103 // import scala.collection.mutable.Stack104 //105 // type TypeThunk = Function0[Option[Type]]106 // type UnambiguousName = Name107 //108 // /**109 // * Contains the function names that have been called thus far during the110 // * type checking of function bodies in this environment.111 // */112 // protected var callStack: Stack[Name] = new Stack113 //114 // /** Maps unsolved overloadings to their thunks. */115 // protected var unsolvedOverloadings: Map[UnambiguousName, TypeThunk] = Map.empty116 //117 // /** Maps solved overloadings to their thunks. */118 // protected var solvedOverloadings: Map[UnambiguousName, Type] = Map.empty119 //120 // /** */121 // protected var solved: Map[Name, Type] = Map.empty122 //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 () => t128 // case _ =>129 // }130 //131 // // Get relevant parts out of the decl.132 // val name = fnDecl.getHeader.getName133 // val unambiguousName = fnDecl.getUnambiguousName134 // val body = fnDecl.getBody.getOrElse(bug("No body on function."))135 //136 // // Capture the type checker at this point.137 // val checker = this.initialChecker138 // 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 += name148 //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 // }156 75 } 157 76 -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/StaticEnv.scala
r3905 r3915 16 16 ******************************************************************************/ 17 17 18 package com.sun.fortress.scala_src.typechecker 18 package com.sun.fortress.scala_src.typechecker.staticenv 19 19 20 20 import com.sun.fortress.nodes.Name 21 21 import com.sun.fortress.nodes.Type 22 import com.sun.fortress.nodes_util.Modifiers23 22 24 23 /** -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/useful/STypesUtil.scala
r3905 r3915 18 18 package com.sun.fortress.scala_src.useful 19 19 20 import _root_.java.util.ArrayList 20 21 import com.sun.fortress.compiler.GlobalEnvironment 21 22 import 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 23 import com.sun.fortress.compiler.index._ 28 24 import com.sun.fortress.compiler.typechecker.StaticTypeReplacer 29 25 import com.sun.fortress.compiler.typechecker.TypeAnalyzer … … 32 28 import com.sun.fortress.exceptions.TypeError 33 29 import com.sun.fortress.nodes._ 34 import com.sun.fortress.nodes_util.NodeFactory 35 import com.sun.fortress.nodes_util.NodeUtil 30 import com.sun.fortress.nodes_util.ExprFactory 31 import com.sun.fortress.nodes_util.{NodeFactory => NF} 32 import com.sun.fortress.nodes_util.{NodeUtil => NU} 36 33 import com.sun.fortress.scala_src.nodes._ 37 34 import com.sun.fortress.scala_src.useful.Lists._ … … 48 45 49 46 /** 50 * Return the arrow type of the given FnDecl .51 */ 52 def makeArrowFromF unction(f: FnDecl): ArrowType = {53 val returnType = f.getHeader.getReturnType. get54 val params = toList(f.getHeader.getParams).map(N odeUtil.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) 55 52 val argType = makeArgumentType(params) 56 53 val sparams = f.getHeader.getStaticParams 57 54 val where = f.getHeader.getWhereClause 58 55 val throws = f.getHeader.getThrowsClause 59 N odeFactory.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 68 65 /** 69 66 * 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) 85 103 } 86 104 } … … 93 111 case t :: Nil => t 94 112 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 } 98 161 } 99 162 … … 173 236 def staticParamBoundType(sparam: StaticParam): Option[Type] = 174 237 sparam.getKind match { 175 case SKindType(_) => Some(N odeFactory.makeIntersectionType(sparam.getExtendsClause))238 case SKindType(_) => Some(NF.makeIntersectionType(sparam.getExtendsClause)) 176 239 case _ => None 177 240 } … … 184 247 case SKindType(_) => { 185 248 // Create a new inference var type. 186 val t = N odeFactory.make_InferenceVarType(NodeUtil.getSpan(sparam))187 N odeFactory.makeTypeArg(NodeFactory.makeSpan(t), t)249 val t = NF.make_InferenceVarType(NU.getSpan(sparam)) 250 NF.makeTypeArg(NF.makeSpan(t), t) 188 251 } 189 252 case SKindInt(_) => NI.nyi()

