- Timestamp:
- 11/03/09 15:19:06 (3 weeks ago)
- Location:
- trunk/ProjectFortress
- Files:
-
- 9 modified
-
compiler_tests/Compiled12.inherit.fss (modified) (3 diffs)
-
compiler_tests/Compiled12.inherit.test (modified) (1 diff)
-
src/com/sun/fortress/compiler/index/TraitIndex.java (modified) (2 diffs)
-
src/com/sun/fortress/scala_src/disambiguator/ExprDisambiguator.scala (modified) (1 diff)
-
src/com/sun/fortress/scala_src/typechecker/AbstractMethodChecker.scala (modified) (6 diffs)
-
src/com/sun/fortress/scala_src/typechecker/OverloadingChecker.scala (modified) (1 diff)
-
src/com/sun/fortress/scala_src/typechecker/impls/Common.scala (modified) (1 diff)
-
src/com/sun/fortress/scala_src/useful/STypesUtil.scala (modified) (7 diffs)
-
src/com/sun/fortress/scala_src/useful/Sets.scala (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/compiler_tests/Compiled12.inherit.fss
r4305 r4309 20 20 trait T comprises { U, V } 21 21 abstract getter asString(): String 22 abstract getter foo(): String 22 23 abstract m(t:T): T 23 24 abstract mv(v:V): T 25 abstract leaf(): T 24 26 end 25 27 26 28 object U extends T 27 29 getter asString(): String = "U" 30 getter foo(): String = "U" 28 31 m(t:T): T = t 29 32 mv(v:V): T = v 33 leaf(): T = self 30 34 end 31 35 32 36 trait V extends T comprises { W, X } 37 getter foo(): String = "V" 38 getter k(): String 33 39 m(t:T): T = t.mv(self) 34 40 mv(v:V): T = self … … 37 43 object W extends V 38 44 getter asString(): String = "W" 45 getter k(): String = "WW" 46 leaf(): T = self 39 47 end 40 48 41 49 object X extends V 42 50 getter asString(): String = "X" 51 getter k(): String = "XX" 52 leaf(): T = self 43 53 end 44 54 … … 53 63 println("W" X.m(W).asString) 54 64 println("X" X.m(X).asString) 65 println("U" U.foo) 66 println("V" W.foo) 67 println("V" X.foo) 68 println("U" U.leaf().asString) 69 println("W" W.leaf().asString) 70 println("X" X.leaf().asString) 55 71 end -
trunk/ProjectFortress/compiler_tests/Compiled12.inherit.test
r4305 r4309 26 26 XX\n\ 27 27 WW\n\ 28 XX\n\ 29 UU\n\ 30 VV\n\ 31 VV\n\ 32 UU\n\ 33 WW\n\ 28 34 XX\n -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/TraitIndex.java
r4259 r4309 45 45 46 46 public TraitIndex(TraitObjectDecl ast, Map<Id, Method> getters, Map<Id, Method> setters, Set<Coercion> coercions, Relation<IdOrOpOrAnonymousName, DeclaredMethod> dottedMethods, Relation<IdOrOpOrAnonymousName, FunctionalMethod> functionalMethods) { 47 _ast = ast;48 _getters = getters;49 _setters = setters;50 _coercions = coercions;51 _dottedMethods = dottedMethods;52 _functionalMethods = functionalMethods;47 _ast = ast; 48 _getters = getters; 49 _setters = setters; 50 _coercions = coercions; 51 _dottedMethods = dottedMethods; 52 _functionalMethods = functionalMethods; 53 53 } 54 54 55 55 public TraitObjectDecl ast() { 56 return _ast;56 return _ast; 57 57 } 58 58 59 59 public Option<Type> typeOfSelf() { 60 if (this.ast() instanceof TraitObjectDecl) {61 return ((TraitObjectDecl) this.ast()).getSelfType();62 }63 return Option.<Type>none();60 if (this.ast() instanceof TraitObjectDecl) { 61 return ((TraitObjectDecl) this.ast()).getSelfType(); 62 } 63 return Option.<Type>none(); 64 64 } 65 65 66 66 public List<StaticParam> staticParameters() { 67 return NodeUtil.getStaticParams(_ast);67 return NodeUtil.getStaticParams(_ast); 68 68 } 69 69 70 70 public List<Id> hiddenParameters() { 71 return Collections.emptyList();71 return Collections.emptyList(); 72 72 } 73 73 … … 78 78 */ 79 79 public Iterable<Pair<Type, Type>> typeConstraints() { 80 return IterUtil.empty();80 return IterUtil.empty(); 81 81 } 82 82 83 83 public List<TraitTypeWhere> extendsTypes() { 84 return NodeUtil.getExtendsClause(_ast);84 return NodeUtil.getExtendsClause(_ast); 85 85 } 86 86 87 87 public Map<Id, Method> getters() { 88 return _getters;88 return _getters; 89 89 } 90 90 91 91 public Map<Id, Method> setters() { 92 return _setters;92 return _setters; 93 93 } 94 94 95 95 public Set<Coercion> coercions() { 96 return _coercions;96 return _coercions; 97 97 } 98 98 99 99 public Relation<IdOrOpOrAnonymousName, DeclaredMethod> dottedMethods() { 100 return _dottedMethods;100 return _dottedMethods; 101 101 } 102 102 103 103 public Relation<IdOrOpOrAnonymousName, FunctionalMethod> functionalMethods() { 104 return _functionalMethods;104 return _functionalMethods; 105 105 } 106 106 -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/disambiguator/ExprDisambiguator.scala
r4296 r4309 911 911 {(res, t) => (res, t) match { 912 912 case ((accessors, methods), STraitTypeWhere(_, base, where)) 913 if ! hist.hasExplored(base) => 914 hist.explore(base) 913 if hist.explore(base) => 915 914 // Trait types or VarTypes can represent traits at this phase of compilation. 916 915 base match { -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/AbstractMethodChecker.scala
r4304 r4309 25 25 import com.sun.fortress.compiler.GlobalEnvironment 26 26 import com.sun.fortress.compiler.index.ComponentIndex 27 import com.sun.fortress.compiler.index.{DeclaredMethod => JavaDeclaredMethod} 28 import com.sun.fortress.compiler.index.FieldGetterOrSetterMethod 27 29 import com.sun.fortress.compiler.index.{Functional => JavaFunctional} 30 import com.sun.fortress.compiler.index.{FunctionalMethod => JavaFunctionalMethod} 28 31 import com.sun.fortress.compiler.index.HasSelfType 29 32 import com.sun.fortress.compiler.index.TraitIndex … … 70 73 walk(decls).asInstanceOf[List[Decl]]) 71 74 val inherited = inheritedMethods(traits, extendsC, Set(), typeAnalyzer) 72 .map(t => t. first.asInstanceOf[IdOrOp].getText)75 .map(t => t._1.asInstanceOf[IdOrOp].getText) 73 76 for ( d <- decls ; if d.isInstanceOf[FnDecl] ) { 74 77 if ( NU.isFunctionalMethod(NU.getParams(d.asInstanceOf[FnDecl])) && … … 92 95 typeAnalyzer = typeAnalyzer.extend(sparams, None) 93 96 val toCheck = inheritedAbstractMethods(extendsC) 94 for ( t <- toCheck.keySet ) { 95 for ( (owner, ds) <- toCheck.get(t) ) { 96 for ( d <- ds ) { 97 if ( ! implement(d, decls, owner) ) 98 error(span, 99 "The inherited abstract method " + d + " from the trait " + t + 100 "\n in the object " + name + 101 " is not defined in the component " + componentName + ".") 102 } 103 } 97 for ( (owner, d) <- toCheck ) { 98 if ( ! implement(d, decls, owner) ) { 99 error(span, 100 "The inherited abstract method " + d + " from the trait " + owner + 101 "\n in the object " + name + 102 " is not defined in the component " + componentName + ".") 103 } 104 104 } 105 105 typeAnalyzer = oldTypeAnalyzer 106 106 } 107 107 108 private def inheritedAbstractMethods(extended_traits: List[TraitTypeWhere]) = { 108 private def inheritedAbstractMethods(extended_traits: List[TraitTypeWhere]): 109 List[(TraitType, FnDecl)] = { 109 110 val inherited = inheritedMethods(typeAnalyzer.traits, extended_traits, 110 111 Set(), typeAnalyzer) 111 val map = new HashMap[IdOrOp, (TraitType, Set[FnDecl])]() 112 for (pair <- inherited) { 113 val (_, ftn) = (pair.first, pair.second) 114 val name = ftn._1.asInstanceOf[HasSelfType].declaringTrait 115 val tci = typeAnalyzer.traits.typeCons(name) 116 if ( tci.isSome && tci.unwrap.isInstanceOf[TraitIndex] ) { 117 val ti = tci.unwrap.asInstanceOf[TraitIndex] 118 map.put(name, (ftn._3, 119 collectAbstractMethods(name, toList(NU.getDecls(ti.ast))))) 112 var res = List[(TraitType, FnDecl)]() 113 for { 114 (_,(meth : HasSelfType, _, tt)) <- inherited 115 decl <- meth match { 116 case f : JavaFunctionalMethod => Some(f.ast()) 117 case m : JavaDeclaredMethod => Some(m.ast()) 118 case gs : FieldGetterOrSetterMethod if gs.fnDecl.isSome => 119 Some(gs.fnDecl.unwrap) 120 case o => System.err.println("inheritedAbstractMethods: skipped "+o) 121 None 120 122 } 121 } 122 map 123 SFnDecl(_,SFnHeader(_,mods,_,_,_,_,_,_),_,body,_) <- Some(decl) 124 if (mods.isAbstract || ! body.isDefined) 125 } res = ((tt,decl)) :: res 126 res 123 127 } 124 128 … … 127 131 decls.foreach( (d: Decl) => d match { 128 132 case fd@SFnDecl(_,SFnHeader(_,mods,_,_,_,_,_,_),_,body,_) => 129 if ( component.typeConses. keySet.contains(name) ) {133 if ( component.typeConses.containsKey(name) ) { 130 134 if ( ! body.isDefined ) set += fd 131 135 } else if ( mods.isAbstract ) set += fd … … 147 151 */ 148 152 private def implement(d: FnDecl, decl: FnDecl, t: TraitType): Boolean = { 153 // Quickly reject unmatched decls. Note that we're still doing an O(n^2) search here. 154 if (!NU.getName(d).asInstanceOf[IdOrOp].getText.equals( 155 NU.getName(decl).asInstanceOf[IdOrOp].getText)) 156 return false; 157 // Quickly reject unmatched modifiers. 158 if (!NU.getMods(d).containsAll(NU.getMods(decl))) 159 return false; 160 149 161 val tci = typeAnalyzer.traits.typeCons(t.getName) 150 162 var sparams = List[StaticParam]() … … 157 169 staticInstantiation(sparams zip sargs, ty).getOrElse(ty) 158 170 val result = 159 NU.getName(d).asInstanceOf[IdOrOp].getText.equals(NU.getName(decl).asInstanceOf[IdOrOp].getText) &&160 NU.getMods(d).containsAll(NU.getMods(decl)) &&161 171 ( typeAnalyzer.equivalent(subst(NU.getParamType(d).asInstanceOf[Type]), 162 172 subst(NU.getParamType(decl))).isTrue || -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/OverloadingChecker.scala
r4304 r4309 193 193 var methods = toSet(traitOrObject.dottedMethods) 194 194 .asInstanceOf[Set[JavaPair[IdOrOpOrAnonymousName, JavaFunctional]]] 195 .map(p => new JavaPair(p.first, (p.second, identity)))195 .map(p => (p.first, (p.second, identity))) 196 196 methods ++= 197 197 STypesUtil.inheritedMethods(typeAnalyzer.traits, 198 198 toList(traitOrObject.extendsTypes), 199 199 methods, typeAnalyzer) 200 .asInstanceOf[Set[JavaPair[IdOrOpOrAnonymousName, (JavaFunctional, StaticTypeReplacer, TraitType)]]] 201 .map(p => { val t = p.second 202 new JavaPair(p.first, (t._1, t._2)) }) 203 204 for ( f <- methods.map(x => x.first) ; if isDeclaredName(f) ) { 200 .asInstanceOf[Set[(IdOrOpOrAnonymousName, (JavaFunctional, StaticTypeReplacer, TraitType))]] 201 .map(p => (p._1,(p._2._1, p._2._2))) 202 203 for ( f <- methods.map(_._1) ; if isDeclaredName(f) ) { 205 204 var ss = Set[(JavaMethod, StaticTypeReplacer)]() 206 methods.filter(p => (p. first == f && p.second._1.isInstanceOf[JavaMethod]) &&207 p. second._1.asInstanceOf[JavaMethod].selfType.isSome)208 .foreach(ss += _. second.asInstanceOf[(JavaMethod, StaticTypeReplacer)])205 methods.filter(p => (p._1 == f && p._2._1.isInstanceOf[JavaMethod]) && 206 p._2._1.asInstanceOf[JavaMethod].selfType.isSome) 207 .foreach(ss += _._2.asInstanceOf[(JavaMethod, StaticTypeReplacer)]) 209 208 checkMethodOverloading(f, toMethodSig(ss)) 210 209 } 211 for ( f <- methods.map( x => x.first) ; if isDeclaredName(f) ) {210 for ( f <- methods.map(_._1) ; if isDeclaredName(f) ) { 212 211 var ss = Set[(JavaFunction, StaticTypeReplacer)]() 213 methods.filter(p => p. first == f && p.second._1.isInstanceOf[JavaFunction])214 .foreach(ss += _. second.asInstanceOf[(JavaFunction, StaticTypeReplacer)])212 methods.filter(p => p._1 == f && p._2._1.isInstanceOf[JavaFunction]) 213 .foreach(ss += _._2.asInstanceOf[(JavaFunction, StaticTypeReplacer)]) 215 214 checkFunctionOverloading(f, toFunctionalMethodSig(ss)) 216 215 } -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/impls/Common.scala
r4251 r4309 62 62 for ( trait_ <- extended_traits if (! done) ) { 63 63 val type_ = trait_.getBaseType 64 if ( ! h.hasExplored(type_) ) { 65 h.explore(type_) 64 if ( h.explore(type_) ) { 66 65 type_ match { 67 66 case ty@STraitType(_, name, _, _) => -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/useful/STypesUtil.scala
r4304 r4309 19 19 20 20 import _root_.java.util.ArrayList 21 import _root_.java.util.{Map => JMap} 21 22 import scala.collection.{Set => CSet} 22 23 import edu.rice.cs.plt.tuple.Pair … … 54 55 class HierarchyHistory { 55 56 var explored = Set[Type]() 56 def explore(t: Type) = explored += t 57 def hasExplored(t: Type) = explored.exists(_ == t) 57 def explore(t: Type): Boolean = 58 if (explored(t)) 59 false 60 else { 61 explored += t 62 true 63 } 64 def hasExplored(t: Type): Boolean = explored(t) 58 65 def copy = { 59 66 val h = new HierarchyHistory … … 864 871 def inheritedMethods(traits: TraitTable, 865 872 extendedTraits: List[TraitTypeWhere], 866 initial: Set[ Pair[IdOrOpOrAnonymousName,867 (Functional, StaticTypeReplacer) ]],873 initial: Set[(IdOrOpOrAnonymousName, 874 (Functional, StaticTypeReplacer))], 868 875 analyzer: TypeAnalyzer) = { 869 876 // Return all of the methods from super-traits … … 871 878 extended_traits: List[TraitTypeWhere], 872 879 given: Set[(String, Type)]) 873 : Set[ Pair[IdOrOpOrAnonymousName,874 (Functional, StaticTypeReplacer, TraitType) ]] = {880 : Set[(IdOrOpOrAnonymousName, 881 (Functional, StaticTypeReplacer, TraitType))] = { 875 882 var allMethods = given 876 883 // a set of inherited methods: 877 884 // a set of pairs of method names and 878 885 // triples of Functionals, static parameters substitutions, and declaring trait 879 var methods = Set[ Pair[IdOrOpOrAnonymousName, (Functional, StaticTypeReplacer, TraitType)]]()886 var methods = Set[(IdOrOpOrAnonymousName, (Functional, StaticTypeReplacer, TraitType))]() 880 887 var h = history 881 888 for (trait_ <- extended_traits) { 882 889 val type_ = trait_.getBaseType 883 if ( ! h.hasExplored(type_) ) { 884 h.explore(type_) 890 if ( h.explore(type_) ) { 885 891 type_ match { 886 892 case ty@STraitType(_, name, trait_args, params) => 887 893 toOption(traits.typeCons(name)) match { 888 case Some(ti) => 889 if ( ti.isInstanceOf[TraitIndex] ) { 894 case Some(ti : TraitIndex) => 890 895 val tindex = ti.asInstanceOf[TraitIndex] 891 896 // Instantiate methods with static args 892 897 val paramsToArgs = new StaticTypeReplacer(ti.staticParameters, 893 898 toJavaList(trait_args)) 894 var collected = toSet(tindex.dottedMethods) 895 .asInstanceOf[Collection[Pair[IdOrOpOrAnonymousName, Functional]]] 896 collected ++= toSet(tindex.functionalMethods) 897 .asInstanceOf[Collection[Pair[IdOrOpOrAnonymousName, Functional]]] 898 for ( pair <- collected ; if pair.first.isInstanceOf[IdOrOp] ) { 899 val (method_name, method_func) = (pair.first, pair.second) 899 var collected = toSet(tindex.dottedMethods).map(p => (p.first, p.second)) 900 .asInstanceOf[Collection[(IdOrOpOrAnonymousName, Functional)]] 901 collected ++= toSet(tindex.functionalMethods).map(p => (p.first, p.second)) 902 .asInstanceOf[Collection[(IdOrOpOrAnonymousName, Functional)]] 903 collected ++= toSet(tindex.getters.entrySet).map(e => (e.getKey, e.getValue)) 904 .asInstanceOf[Collection[(IdOrOpOrAnonymousName, Functional)]] 905 collected ++= toSet(tindex.setters.entrySet).map(e => (e.getKey, e.getValue)) 906 .asInstanceOf[Collection[(IdOrOpOrAnonymousName, Functional)]] 907 for ( (method_name : IdOrOp, method_func) <- collected ) { 900 908 val new_pair = toNameParamTy(method_name, method_func) 901 909 val fname = new_pair._1 902 910 val paramTy = paramsToArgs.replaceIn(new_pair._2) 903 911 if (!isOverride(fname, paramTy, allMethods, analyzer)) { 904 methods += new Pair(method_name, (method_func, paramsToArgs, ty))912 methods += ((method_name, (method_func, paramsToArgs, ty))) 905 913 allMethods += ((fname, paramTy)) 906 914 } … … 912 920 allMethods) 913 921 methods ++= inherited 914 allMethods ++= inherited.map(p => toNameParamTy(p. first, p.second._1))922 allMethods ++= inherited.map(p => toNameParamTy(p._1, p._2._1)) 915 923 h = old_hist 916 } else return methods917 924 case _ => return methods 918 925 } … … 924 931 } 925 932 inheritedMethodsHelper(new HierarchyHistory(), extendedTraits, 926 initial.map(p => toNameParamTy(p. first, p.second._1)))933 initial.map(p => toNameParamTy(p._1, p._2._1))) 927 934 } 928 935 … … 933 940 case _ => NF.makeVoidType(span) 934 941 } 935 (name.asInstanceOf[IdOrOp].getText, ty)942 (name.asInstanceOf[IdOrOp].getText, ty) 936 943 } 937 944 -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/useful/Sets.scala
r4211 r4309 23 23 24 24 object Sets { 25 25 26 26 /** Takes in any kind of collection. */ 27 27 def toJavaSet[T](elts: Collection[T]): JavaSet[T] = { … … 30 30 temp 31 31 } 32 32 33 33 /** Creates an immutable set. */ 34 34 def toSet[T](jset: JavaSet[T]): Set[T] =

