Changeset 3921 for trunk/ProjectFortress
- Timestamp:
- 07/06/09 08:26:38 (5 months ago)
- Location:
- trunk/ProjectFortress/src/com/sun/fortress
- Files:
-
- 8 modified
-
compiler/StaticChecker.java (modified) (2 diffs)
-
compiler/index/Functional.java (modified) (1 diff)
-
compiler/typechecker/constraints/ConstraintUtil.java (modified) (6 diffs)
-
scala_src/typechecker/STypeChecker.scala (modified) (1 diff)
-
scala_src/typechecker/staticenv/KindEnv.scala (modified) (3 diffs)
-
scala_src/typechecker/staticenv/STypeEnv.scala (modified) (4 diffs)
-
scala_src/typechecker/staticenv/STypeEnvExtraction.scala (modified) (2 diffs)
-
scala_src/typechecker/staticenv/StaticEnv.scala (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/src/com/sun/fortress/compiler/StaticChecker.java
r3894 r3921 234 234 } else { 235 235 TypeEnv typeEnv = typeCheckEnv(component, env); 236 ConstraintUtil.useScalaFormulas();237 236 STypeChecker typeChecker = STypeCheckerFactory.make(component, traitTable, typeEnv, typeAnalyzer); 238 237 component_ast = typeChecker.typeCheck(component_ast); … … 276 275 boolean postInference) { 277 276 TypeEnv typeEnv = typeCheckEnv(component, env); 278 ConstraintUtil.useJavaFormulas();279 277 TypeChecker typeChecker = new TypeChecker(traitTable, typeEnv, 280 278 component, postInference); -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Functional.java
r3915 r3921 73 73 /** 74 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. 75 * that simply gets back the previously evaluated return type. After type 76 * checking, the result of this method will always be Some(type). 76 77 */ 77 78 public Option<Type> getReturnType() { -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/constraints/ConstraintUtil.java
r3813 r3921 18 18 package com.sun.fortress.compiler.typechecker.constraints; 19 19 20 import com.sun.fortress.Shell; 20 21 import com.sun.fortress.compiler.typechecker.constraints.JavaConstraintUtil; 21 22 import com.sun.fortress.scala_src.typechecker.ScalaConstraintUtil; … … 29 30 public class ConstraintUtil { 30 31 31 private static boolean java = true;32 33 public static void useJavaFormulas(){34 java = true;35 }36 37 public static void useScalaFormulas(){38 java = false;39 }40 41 public static void setJava(Boolean _java){42 java = _java;43 }44 45 32 public static ConstraintFormula trueFormula() { 46 if( java)33 if(!Shell.getScala()) 47 34 return JavaConstraintUtil.trueFormula(); 48 35 else … … 50 37 } 51 38 public static ConstraintFormula falseFormula() { 52 if( java)39 if(!Shell.getScala()) 53 40 return JavaConstraintUtil.falseFormula(); 54 41 else … … 57 44 58 45 public static ConstraintFormula upperBound(_InferenceVarType ivar, Type type, SubtypeHistory h) { 59 if( java)46 if(!Shell.getScala()) 60 47 return JavaConstraintUtil.upperBound(ivar,type,h); 61 48 else … … 64 51 65 52 public static ConstraintFormula lowerBound(_InferenceVarType ivar, Type type, SubtypeHistory h) { 66 if( java)53 if(!Shell.getScala()) 67 54 return JavaConstraintUtil.lowerBound(ivar,type,h); 68 55 else … … 80 67 81 68 public static ConstraintFormula fromBoolean(Boolean bool){ 82 if( java)69 if(!Shell.getScala()) 83 70 return JavaConstraintUtil.fromBoolean(bool); 84 71 else -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/STypeChecker.scala
r3902 r3921 226 226 * Return the conditions for subtype <: supertype to hold. 227 227 */ 228 protected def checkSubtype(subtype: Type, supertype: Type): ScalaConstraint = 229 analyzer.subtype(subtype, supertype).asInstanceOf[ScalaConstraint] 228 protected def checkSubtype(subtype: Type, supertype: Type): ScalaConstraint = { 229 val constraint = analyzer.subtype(subtype, supertype) 230 if (!constraint.isInstanceOf[ScalaConstraint]) { 231 bug("Not a ScalaConstraint.") 232 } 233 constraint.asInstanceOf[ScalaConstraint] 234 } 230 235 231 236 protected def equivalentTypes(t1: Type, t2: Type): Boolean = -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/KindEnv.scala
r3915 r3921 35 35 type EnvBinding = KindBinding 36 36 37 /** Extend me with the immediate bindings of the given node. */38 def extendWith(node: Any): KindEnv =39 new NestedKindEnv(this, KindEnv.extractEnvBindings(node))40 41 37 /** 42 38 * Get the type of the given variable name, if it is bound. The resulting … … 63 59 */ 64 60 class NestedKindEnv protected (protected val parent: KindEnv, 65 _bindings: Collection[KindBinding])61 _bindings: Iterable[KindBinding]) 66 62 extends KindEnv with NestedStaticEnv[StaticParam] { 67 63 … … 80 76 type EnvBinding = KindBinding 81 77 82 /** New kind environment with empty parent and the node's bindings. */ 83 def make(node: Any): KindEnv = 84 new NestedKindEnv(EmptyKindEnv, extractEnvBindings(node)) 78 def empty():KindEnv = EmptyKindEnv 85 79 86 80 /** Extract out the bindings in node. */ 87 protected def extractEnvBindings(node: Any) : Collection[KindBinding] = null 81 protected def extractEnvBindings(node: Node) : Iterable[KindBinding] = Nil 82 protected def extractEnvBindings(node: Any) : Iterable[KindBinding] = Nil 88 83 } 89 84 -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/STypeEnv.scala
r3915 r3921 36 36 37 37 /** Extend me with the immediate bindings of the given node. */ 38 def extendWith(node: Any): STypeEnv =39 new NestedSTypeEnv(this, STypeEnv.extractEnvBindings(node))40 38 41 39 /** Same as `lookup`. */ … … 53 51 */ 54 52 class NestedSTypeEnv protected (protected val parent: STypeEnv, 55 _bindings: Collection[TypeBinding])53 _bindings: Iterable[TypeBinding]) 56 54 extends STypeEnv with NestedStaticEnv[Type] { 57 55 … … 62 60 63 61 /** Companion module for STypeEnv. */ 64 object STypeEnv extends StaticEnvCompanion[Type] with STypeEnvExtraction { 62 object STypeEnv extends StaticEnvCompanion[Type] 63 with STypeEnvExtraction { 65 64 66 65 /** My type. */ … … 70 69 type EnvBinding = TypeBinding 71 70 72 /** New type environment with empty parent and the node's bindings. */ 73 def make(node: Any): STypeEnv = 74 new NestedSTypeEnv(EmptySTypeEnv, extractEnvBindings(node)) 71 def empty(): STypeEnv = EmptySTypeEnv 72 75 73 } 76 74 -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/STypeEnvExtraction.scala
r3915 r3921 33 33 import edu.rice.cs.plt.collect.Relation 34 34 35 trait STypeEnvExtraction { self: STypeEnv.type => 35 36 /** 37 * Provides the functionality for extracting type bindings from nodes and 38 * indices to create type environments. 39 */ 40 trait STypeEnvExtraction { self: STypeEnv.type => 36 41 37 42 /** Extract out the bindings in node. */ 38 def extractEnvBindings(node: Any): Collection[TypeBinding] = { 39 def recur(node: Any) = extractEnvBindings(node) 40 (node match { 41 43 def extractEnvBindings(node: Node): Iterable[TypeBinding] = { 44 def recur(node: Node) = extractEnvBindings(node) 45 (node match{ 42 46 case SBinding(_, name, mods, Some(typ)) => 43 47 TypeBinding(name, typ, mods, false) … … 50 54 case SLValue(_, name, mods, Some(typ), mutable) => 51 55 TypeBinding(name, typ, mods, mutable) 52 56 53 57 case SLocalVarDecl(_, _, lValues, _) => lValues.map(recur) 54 55 case v:DeclaredVariable => recur(v.ast) 56 57 // Type erasure makes us put all JMap cases in one. 58 case m:JMap[_, _] => toMap(m).flatMap(xv => 59 xv match { 60 61 // Match Map[Id, Variable] 62 case (x:Id, v:DeclaredVariable) => recur(v) 63 case (x:Id, v:SingletonVariable) => 64 recur(NF.makeLValue(x, v.declaringTrait)) 65 case (x:Id, v:ParamVariable) => recur(v.ast) 66 67 // Bind object names to their types. 68 case (x:Id, v:ObjectTraitIndex) => 69 val decl = v.ast 70 val params = toOption(NU.getParams(decl)) 71 val sparams = NU.getStaticParams(decl) 72 val objType = params match { 73 case None if sparams.isEmpty => 74 // Just a single trait type. 75 NF.makeTraitType(x) 76 case None => 77 // A generic trait type. 78 NF.makeGenericSingletonType(x, sparams) 79 case Some(params) if sparams.isEmpty => 80 // Arrow type for basic constructor. 81 NF.makeArrowType(NU.getSpan(x), 82 STypesUtil.makeDomainType(toList(params)), 83 NF.makeTraitType(x)) 84 case Some(params) => 85 // Generic arrow type for constructor. 86 val sargs = toList(sparams).map(STypesUtil.staticParamToArg) 87 NF.makeArrowType(NU.getSpan(decl), 88 false, 89 STypesUtil.makeDomainType(toList(params)), 90 NF.makeTraitType(x, toJavaList(sargs)), 91 NF.emptyEffect, // TODO: Change this? 92 sparams, 93 NU.getWhereClause(decl)) 94 } 95 List(TypeBinding(x, objType, Modifiers.None, false)) 96 }) 97 98 // Matches all, but must be [IdOrOpOrAnonymousName, ? <: Functional] 99 case r:Relation[IdOrOpOrAnonymousName, Functional] => 100 val fnNames = toSet(r.firstSet) 101 102 // For each name, intersect together all of its overloading types. 103 fnNames.flatMap(x => x match { 104 105 // Make sure this is actually a name. 106 case x: IdOrOpOrAnonymousName => 107 val fns: Set[Functional] = toSet(r.matchFirst(x).asInstanceOf[JSet[Functional]]) 108 val oTypes = 109 fns.map(STypesUtil.makeArrowFromFunctional(_).asInstanceOf[Type]) 110 val fnType = NF.makeIntersectionType(oTypes) 111 Some(TypeBinding(x, fnType, Modifiers.None, false)) 112 113 // case _ => None 114 }) 115 116 case xs:Iterable[_] => xs.flatMap(recur) 117 58 118 59 case _ => Nil 119 120 }) match { // Guarantee that a Collection is returned. 121 case bs:Collection[TypeBinding] => bs 60 }) match{ 61 case bs:Iterable[TypeBinding] => bs 122 62 case b:TypeBinding => List(b) 123 63 } 124 64 } 65 66 // def extractEnvBindings(m: JMap[Id, Variable]): Iterable[TypeBinding] = toMap(m).flatMap(xv =>{ 67 // xv match{ 68 // case (x:Id, v:DeclaredVariable) => extractEnvBindings(v.ast) 69 // case (x:Id, v:SingletonVariable) => 70 // extractEnvBindings(NF.makeLValue(x, v.declaringTrait)) 71 // case (x:Id, v:ParamVariable) => extractEnvBindings(v.ast) 72 // } 73 // }) 74 75 // def extractEnvBindings(m: JMap[Id, TypeConsIndex]): Iterable[TypeBinding] = toMap(m).flatMap(xv => { 76 // xv match { 77 // // Bind object names to their types. 78 // case (x:Id, v:ObjectTraitIndex) => 79 // val decl = v.ast 80 // val params = toOption(NU.getParams(decl)) 81 // val sparams = NU.getStaticParams(decl) 82 // val objType = params match { 83 // case None if sparams.isEmpty => 84 // // Just a single trait type. 85 // NF.makeTraitType(x) 86 // case None => 87 // // A generic trait type. 88 // NF.makeGenericSingletonType(x, sparams) 89 // case Some(params) if sparams.isEmpty => 90 // // Arrow type for basic constructor. 91 // NF.makeArrowType(NU.getSpan(x), 92 // STypesUtil.makeDomainType(toList(params)), 93 // NF.makeTraitType(x)) 94 // case Some(params) => 95 // // Generic arrow type for constructor. 96 // val sargs = toList(sparams).map(STypesUtil.staticParamToArg) 97 // NF.makeArrowType(NU.getSpan(decl), 98 // false, 99 // STypesUtil.makeDomainType(toList(params)), 100 // NF.makeTraitType(x, toJavaList(sargs)), 101 // NF.emptyEffect, // TODO: Change this? 102 // sparams, 103 // NU.getWhereClause(decl)) 104 // } 105 // List(TypeBinding(x, objType, Modifiers.None, false)) 106 // } 107 // }) 108 109 def extractEnvBindings(r: Relation[IdOrOpOrAnonymousName, Functional]): Iterable[TypeBinding] = { 110 val fnNames = toSet(r.firstSet) 111 // For each name, intersect together all of its overloading types. 112 fnNames.flatMap(x => { 113 val fns: Set[Functional] = toSet(r.matchFirst(x).asInstanceOf[JSet[Functional]]) 114 val oTypes = 115 fns.map(STypesUtil.makeArrowFromFunctional(_).asInstanceOf[Type]) 116 val fnType = NF.makeIntersectionType(oTypes) 117 Some(TypeBinding(x, fnType, Modifiers.None, false)) 118 }) 119 } 120 121 def make(comp: CompilationUnitIndex): STypeEnv = { 122 EmptySTypeEnv//.extendWith(comp.functions) 123 // .extendWith(comp.variables) 124 //.extendWith(comp.typeConses) 125 } 125 126 } -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/StaticEnv.scala
r3915 r3921 18 18 package com.sun.fortress.scala_src.typechecker.staticenv 19 19 20 import _root_.java.util.{Map => JMap} 20 21 import com.sun.fortress.nodes.Name 22 import com.sun.fortress.nodes.Node 21 23 import com.sun.fortress.nodes.Type 24 import edu.rice.cs.plt.collect.Relation 22 25 23 26 /** … … 25 28 * variable names to some value. Each static environment contains 26 29 */ 27 trait StaticEnv[T] extends Collection[StaticBinding[T]] {30 trait StaticEnv[T] extends Iterable[StaticBinding[T]] { 28 31 29 32 /** Define Env as the type of the implementing class. */ … … 41 44 * `node` combined. 42 45 */ 43 def extendWith(node: Any): Env 46 44 47 45 48 /** … … 61 64 */ 62 65 def getType(x: Name): Option[Type] 66 67 /** Not in Iterable, but specify size. */ 68 def size: Int 63 69 64 70 /** Make the type on `Collection.elements` more specific. */ … … 123 129 /** 124 130 * Extracts all the _immediate_ bindings for this kind of environment from the 125 * given node. If `node` is a collection of nodes, then this method returns 126 * the concatenation of all bindings found therein. Any bindings located 127 * further inside the node will not be extracted. 131 * given node. Any bindings located further inside the node will not be 132 * extracted. 128 133 * 129 * @param node A node or collection of nodesin which to extract bindings.134 * @param node A node in which to extract bindings. 130 135 * @return A collection of all the bindings extracted in the given node. 131 136 */ 132 protected def extractEnvBindings(node: Any): Collection[EnvBinding] 137 protected def extractEnvBindings(node: Node): Iterable[EnvBinding] 138 139 /** 140 * Extracts all the _immediate_ bindings for this kind of environment from the 141 * given nodes. Any bindings located further inside the nodes will not be 142 * extracted. This overloading simply flatMaps the other overloading for 143 * convenience. 144 * 145 * @param nodes A collection of nodes in which to extract bindings. 146 * @return A collection of all the bindings extracted in the given node. 147 */ 148 protected def extractEnvBindings(nodes: Iterable[Node]) 149 : Iterable[EnvBinding] = 150 nodes.flatMap(extractEnvBindings) 133 151 134 152 /** … … 139 157 * @return A new instance of Env containing these bindings. 140 158 */ 141 def make(node: Any): Env 159 def empty(): Env 160 142 161 } 143 162

