Changeset 4304 for trunk/ProjectFortress

Show
Ignore:
Timestamp:
11/02/09 13:29:21 (3 weeks ago)
Author:
sukyoungryu
Message:

[abstract method checker] Replaced yet another copy of the old, wrong inheritedMethod with STypesUtil.inheritedMethod which is now augmented with the information of declaring traits of the inherited methods.

Location:
trunk/ProjectFortress
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/compiler_tests/AfterTypeChecking.test

    r4286 r4304  
    2525Compiled9.g Compiled9.j Compiled9.k Compiled9.l Compiled9.m Compiled9.o Compiled9.p Compiled9.t Compiled9.u Compiled9.y Compiled9.ab Compiled9.ac Compiled9.ah Compiled9.ai Compiled9.aj \ 
    2626Compiled10.Comprehensions3 Compiled10.l Compiled10.m Compiled10.r \ 
    27 Compiled11 Compiled12 
     27Compiled11 \ 
     28Compiled12 Compiled12.inherit.fss 
    2829typecheck 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/AbstractMethodChecker.scala

    r4289 r4304  
    2626import com.sun.fortress.compiler.index.ComponentIndex 
    2727import com.sun.fortress.compiler.index.{Functional => JavaFunctional} 
     28import com.sun.fortress.compiler.index.HasSelfType 
    2829import com.sun.fortress.compiler.index.TraitIndex 
    2930import com.sun.fortress.compiler.typechecker.StaticTypeReplacer 
     
    105106  } 
    106107 
    107   private def inheritedAbstractMethods(extended_traits: List[TraitTypeWhere]) = 
    108     inheritedAbstractMethodsHelper(new HierarchyHistory(), extended_traits) 
    109  
    110   private def inheritedAbstractMethodsHelper(hist: HierarchyHistory, 
    111                                              extended_traits: List[TraitTypeWhere]): 
    112                                             Map[IdOrOp, (TraitType, Set[FnDecl])] = { 
    113     var h = hist 
    114     var map = new HashMap[IdOrOp, (TraitType, Set[FnDecl])]() 
    115     for ( trait_ <- extended_traits ; if ! h.hasExplored(trait_.getBaseType) ) { 
    116       trait_.getBaseType match { 
    117         case ty@STraitType(info, name, args, params) => 
    118           h.explore(ty) 
    119           val tci = typeAnalyzer.traits.typeCons(name) 
    120           if ( tci.isSome && tci.unwrap.isInstanceOf[TraitIndex] ) { 
    121             val ti = tci.unwrap.asInstanceOf[TraitIndex] 
    122             map.put(name, (ty, collectAbstractMethods(name, toList(NU.getDecls(ti.ast))))) 
    123             val old_hist = h 
    124             map ++= inheritedAbstractMethodsHelper(h, toList(ti.extendsTypes)) 
    125             h = old_hist 
    126           } else error(NU.getSpan(trait_), 
    127                        "Trait types are expected in an extends clause but found " 
    128                        + ty.toStringVerbose + "\n" + tci.getClass) 
    129         case SAnyType(_) => 
    130         case ty => error(NU.getSpan(trait_), 
    131                          "Trait types are expected in an extends clause but found " 
    132                          + ty.toStringVerbose) 
     108  private def inheritedAbstractMethods(extended_traits: List[TraitTypeWhere]) = { 
     109    val inherited = inheritedMethods(typeAnalyzer.traits, extended_traits, 
     110                                     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))))) 
    133120      } 
    134121    } 
     
    144131                     } else if ( mods.isAbstract ) set += fd 
    145132                   case _ => }) 
    146       set 
     133    set 
    147134  } 
    148135 
     
    152139  private def implement(d: FnDecl, decls: List[Decl], ast: TraitType): Boolean = 
    153140    decls.exists( (decl: Decl) => decl match { 
    154                   case fd@SFnDecl(_,_,_,_,_) => implement(d, fd, ast) 
     141                  case fd:FnDecl => implement(d, fd, ast) 
    155142                  case _ => false 
    156143                } ) 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/OverloadingChecker.scala

    r4292 r4304  
    198198                                          toList(traitOrObject.extendsTypes), 
    199199                                          methods, typeAnalyzer) 
    200               .asInstanceOf[Set[JavaPair[IdOrOpOrAnonymousName, (JavaFunctional, StaticTypeReplacer)]]] 
     200              .asInstanceOf[Set[JavaPair[IdOrOpOrAnonymousName, (JavaFunctional, StaticTypeReplacer, TraitType)]]] 
     201              .map(p => { val t = p.second 
     202                          new JavaPair(p.first, (t._1, t._2)) }) 
    201203 
    202204            for ( f <- methods.map(x => x.first) ; if isDeclaredName(f) ) { 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/useful/STypesUtil.scala

    r4300 r4304  
    872872                               given: Set[(String, Type)]) 
    873873                              : Set[Pair[IdOrOpOrAnonymousName, 
    874                                          (Functional, StaticTypeReplacer)]] = { 
     874                                         (Functional, StaticTypeReplacer, TraitType)]] = { 
    875875      var allMethods = given 
    876876      // a set of inherited methods: 
    877877      // a set of pairs of method names and 
    878       //                   pairs of Functionals and static parameters substitutions 
    879       var methods = Set[Pair[IdOrOpOrAnonymousName, (Functional, StaticTypeReplacer)]]() 
     878      //                   triples of Functionals, static parameters substitutions, and declaring trait 
     879      var methods = Set[Pair[IdOrOpOrAnonymousName, (Functional, StaticTypeReplacer, TraitType)]]() 
    880880      var h = history 
    881881      for (trait_ <- extended_traits) { 
     
    902902                      val paramTy = paramsToArgs.replaceIn(new_pair._2) 
    903903                      if (!isOverride(fname, paramTy, allMethods, analyzer)) { 
    904                         methods += new Pair(method_name, (method_func, paramsToArgs)) 
     904                        methods += new Pair(method_name, (method_func, paramsToArgs, ty)) 
    905905                        allMethods += ((fname, paramTy)) 
    906906                      }