Show
Ignore:
Timestamp:
10/24/09 23:14:49 (4 weeks ago)
Author:
sukyoungryu
Message:

[self type idiom] Added more tests.
[type checker] Moved the inheritedMethods method from AbstractMethodChecker? to STypesUtil.

Location:
trunk/ProjectFortress/src/com/sun/fortress/scala_src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/AbstractMethodChecker.scala

    r4251 r4286  
    6767        checkObject(span, List(), name, extendsC, 
    6868                    walk(decls).asInstanceOf[List[Decl]]) 
    69         val inherited = inheritedMethods(extendsC) 
     69        val inherited = inheritedMethods(traits, extendsC).map(t => t.first.asInstanceOf[IdOrOp].getText) 
    7070        for ( d <- decls ; if d.isInstanceOf[FnDecl] ) { 
    7171          if ( NU.isFunctionalMethod(NU.getParams(d.asInstanceOf[FnDecl])) && 
     
    101101    } 
    102102    typeAnalyzer = oldTypeAnalyzer 
    103   } 
    104  
    105   def inheritedMethods(extendedTraits: List[TraitTypeWhere]) = { 
    106     // Return all of the methods from super-traits 
    107     def inheritedMethodsHelper(history: HierarchyHistory, 
    108                                extended_traits: List[TraitTypeWhere]) 
    109                                : Set[String] = { 
    110       var methods = new HashSet[String]() 
    111       var done = false 
    112       var h = history 
    113       for ( trait_ <- extended_traits ; if (! done) ) { 
    114         val type_ = trait_.getBaseType 
    115         if ( ! h.hasExplored(type_) ) { 
    116           h.explore(type_) 
    117           type_ match { 
    118             case ty@STraitType(_, name, _, params) => 
    119               toOption(traits.typeCons(name)) match { 
    120                 case Some(ti) => 
    121                   if ( ti.isInstanceOf[TraitIndex] ) { 
    122                     val trait_params = ti.staticParameters 
    123                     val trait_args = ty.getArgs 
    124                     // Instantiate methods with static args 
    125                     var collected = toSet(ti.asInstanceOf[TraitIndex].dottedMethods).map(t => t.first) 
    126                     collected ++= toSet(ti.asInstanceOf[TraitIndex].functionalMethods).map(t => t.first) 
    127                     for ( pair <- collected ; if pair.isInstanceOf[IdOrOp] ) { 
    128                       methods += pair.asInstanceOf[IdOrOp].getText 
    129                     } 
    130                     val paramsToArgs = new StaticTypeReplacer(trait_params, trait_args) 
    131                     val instantiated_extends_types = 
    132                       toList(ti.asInstanceOf[TraitIndex].extendsTypes).map( (t:TraitTypeWhere) => 
    133                             t.accept(paramsToArgs).asInstanceOf[TraitTypeWhere] ) 
    134                     val old_hist = h 
    135                     methods ++= inheritedMethodsHelper(h, instantiated_extends_types) 
    136                     h = old_hist 
    137                   } else done = true 
    138                 case _ => done = true 
    139               } 
    140             case _ => done = true 
    141           } 
    142         } 
    143       } 
    144       methods 
    145     } 
    146     inheritedMethodsHelper(new HierarchyHistory(), extendedTraits) 
    147103  } 
    148104 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/useful/STypesUtil.scala

    r4285 r4286  
    1919 
    2020import _root_.java.util.ArrayList 
     21import scala.collection.{Set => CSet} 
     22import edu.rice.cs.plt.tuple.Pair 
    2123import com.sun.fortress.compiler.GlobalEnvironment 
    2224import com.sun.fortress.compiler.Types 
     
    3739import com.sun.fortress.scala_src.typechecker.CnFalse 
    3840import com.sun.fortress.scala_src.typechecker.CnTrue 
     41import com.sun.fortress.scala_src.typechecker.TraitTable 
    3942import com.sun.fortress.scala_src.types.TypeAnalyzer 
    4043import com.sun.fortress.scala_src.useful.Lists._ 
     
    870873    case _ => addType(fn, arrow) 
    871874  } 
     875 
     876  def inheritedMethods(traits: TraitTable, 
     877                       extendedTraits: List[TraitTypeWhere]) = { 
     878    // Return all of the methods from super-traits 
     879    def inheritedMethodsHelper(history: HierarchyHistory, 
     880                               extended_traits: List[TraitTypeWhere]) 
     881                              : Set[Pair[IdOrOpOrAnonymousName, Function]] = { 
     882      var methods = Set[Pair[IdOrOpOrAnonymousName, Function]]() 
     883      var done = false 
     884      var h = history 
     885      for ( trait_ <- extended_traits ; if (! done) ) { 
     886        val type_ = trait_.getBaseType 
     887        if ( ! h.hasExplored(type_) ) { 
     888          h.explore(type_) 
     889          type_ match { 
     890            case ty@STraitType(_, name, _, params) => 
     891              toOption(traits.typeCons(name)) match { 
     892                case Some(ti) => 
     893                  if ( ti.isInstanceOf[TraitIndex] ) { 
     894                    val trait_params = ti.staticParameters 
     895                    val trait_args = ty.getArgs 
     896                    // Instantiate methods with static args 
     897                    var collected: Collection[Pair[IdOrOpOrAnonymousName, Function]] = 
     898                      toSet(ti.asInstanceOf[TraitIndex].dottedMethods).asInstanceOf[CSet[Pair[IdOrOpOrAnonymousName, Function]]] 
     899                    collected ++= 
     900                      toSet(ti.asInstanceOf[TraitIndex].functionalMethods).asInstanceOf[CSet[Pair[IdOrOpOrAnonymousName, Function]]] 
     901                    for ( pair <- collected ; if pair.first.isInstanceOf[IdOrOp] ) { 
     902                      methods += pair 
     903                    } 
     904                    val paramsToArgs = new StaticTypeReplacer(trait_params, trait_args) 
     905                    val instantiated_extends_types = 
     906                      toList(ti.asInstanceOf[TraitIndex].extendsTypes).map( (t:TraitTypeWhere) => 
     907                            t.accept(paramsToArgs).asInstanceOf[TraitTypeWhere] ) 
     908                    val old_hist = h 
     909                    methods ++= inheritedMethodsHelper(h, instantiated_extends_types) 
     910                    h = old_hist 
     911                  } else done = true 
     912                case _ => done = true 
     913              } 
     914            case _ => done = true 
     915          } 
     916        } 
     917      } 
     918      methods 
     919    } 
     920    inheritedMethodsHelper(new HierarchyHistory(), extendedTraits) 
     921  } 
     922 
    872923}