Changeset 3877

Show
Ignore:
Timestamp:
06/19/09 20:52:17 (5 months ago)
Author:
sukyoungryu
Message:

[type checker] Implemented type checking of local variable declarations. Moved 10 tests from not_working_static_tests to compiler_tests.

Location:
trunk/ProjectFortress
Files:
4 added
4 modified
12 moved

Legend:

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

    r3875 r3877  
    1414#    trademarks of Sun Microsystems, Inc. in the U.S. and other countries. 
    1515 
    16 tests=Compiled1.ag Compiled1.ah Compiled1.ai Compiled1.aj Compiled1.ak Compiled1.as Compiled1.au Compiled1.av Compiled2.g Compiled2.t Compiled3.b Compiled3.c Compiled3.d Compiled3.e Compiled3.f Compiled3.h Compiled3.i Compiled3.j Compiled3.k Compiled3.m Compiled3.p Compiled3.q Compiled3.t Compiled3.v Compiled3.x Compiled5.e Compiled5.o Compiled5.q Compiled6 Compiled7 Compiled8 
     16tests=Compiled1.ag Compiled1.ah Compiled1.ai Compiled1.aj Compiled1.ak Compiled1.as Compiled1.au Compiled1.av Compiled2.g Compiled2.t Compiled3.b Compiled3.c Compiled3.d Compiled3.e Compiled3.f Compiled3.h Compiled3.i Compiled3.j Compiled3.k Compiled3.m Compiled3.p Compiled3.q Compiled3.t Compiled3.v Compiled3.x Compiled5.e Compiled5.o Compiled5.q Compiled5.ah Compiled5.ai Compiled5.aj Compiled5.ak Compiled5.al Compiled6 Compiled7 Compiled8 
    1717desugar 
  • trunk/ProjectFortress/compiler_tests/Compiled5.ac.fss

    r3550 r3877  
    1616 ******************************************************************************) 
    1717 
    18 component DXXEqualityTesting 
    1918  export Executable 
    2019 
     
    2726 
    2827  run():() = () 
    29  
    30 end 
  • trunk/ProjectFortress/compiler_tests/Compiled5.ad.fss

    r3550 r3877  
    1616 ******************************************************************************) 
    1717 
    18 component DXXChainTest1 
    1918  export Executable 
    2019 
     
    2524 
    2625  run():() = () 
    27 end 
  • trunk/ProjectFortress/compiler_tests/Compiled5.ae.fss

    r3550 r3877  
    1616 ******************************************************************************) 
    1717 
    18 component DXXChainTest2 
    1918  export Executable 
    2019 
     
    3029 
    3130  run():() = () 
    32 end 
  • trunk/ProjectFortress/compiler_tests/Compiled5.af.fss

    r3550 r3877  
    1616 ******************************************************************************) 
    1717 
    18  component DXXStaticParamFunctionCall 
    1918 export Executable 
    2019 
     
    2827 
    2928   run():() = ignore(foo(A)) 
    30  
    31  
    32  end 
  • trunk/ProjectFortress/compiler_tests/Compiled5.ag.fss

    r3775 r3877  
    1616 ******************************************************************************) 
    1717 
    18 component DXXInvertedAsExpr 
    1918export Executable 
    2019 
     
    2524  y:ZZ32 = x typed ZZ32 
    2625end 
    27  
    28 end 
  • trunk/ProjectFortress/compiler_tests/Compiled5.ah.fss

    r3775 r3877  
    1616 ******************************************************************************) 
    1717 
    18 component AsExpr 
    1918export Executable 
    2019 
     
    2524  y:Any = x typed Any 
    2625end 
    27  
    28 end 
  • trunk/ProjectFortress/compiler_tests/Compiled5.ai.fss

    r2688 r3877  
    1616 ******************************************************************************) 
    1717 
    18 component AsIf 
    1918  import MyOwnLiterals.{...} 
    2019  export AsIfInterface 
     
    2524 
    2625  foo():MyOwnZZ32 = (MyOwn0 asif MyOwnZZ32) 
    27  
    28 end 
  • trunk/ProjectFortress/compiler_tests/Compiled5.aj.fss

    r3550 r3877  
    1616 ******************************************************************************) 
    1717 
    18 component LocalVarRef 
    1918export Executable 
    2019 
     
    2928  () 
    3029end 
    31  
    32 end 
  • trunk/ProjectFortress/compiler_tests/Compiled5.ak.fss

    r3550 r3877  
    1616 ******************************************************************************) 
    1717 
    18 component GenericSingleton 
    1918export Executable 
    2019 
     
    2928  v3 = C[\Boolean\] 
    3029end 
    31  
    32 end 
  • trunk/ProjectFortress/compiler_tests/Compiled5.al.fss

    r3550 r3877  
    1616 ******************************************************************************) 
    1717 
    18 component SimpleObject 
    1918export Executable 
    2019 
     
    2827  p2 = Point(1.0, 1.0) 
    2928end 
    30  
    31 end 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/OverloadingChecker.scala

    r3875 r3877  
    261261     *    check comprises clauses 
    262262     *  - if "elements" are all tuple types 
    263      *    simplif "t" 
     263     *    simplify "t" 
    264264     */ 
    265265    private def reduce(t: Type, exclusionOracle: ExclusionOracle): Type = t match { 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/STypeChecker.scala

    r3875 r3877  
    119119  private def extend(ids: List[Id], types: List[Type]): STypeChecker = 
    120120    extend(ids.zip(types).map((p:(Id,Type)) => NodeFactory.makeLValue(p._1,p._2))) 
     121 
     122  private def extend(decl: LocalVarDecl): STypeChecker = 
     123    STypeCheckerFactory.make(current, traits, env.extend(decl), analyzer, errors) 
    121124 
    122125  private def extendWithFunctions(methods: Relation[IdOrOpOrAnonymousName, JavaFunctionalMethod]) = 
     
    11171120                 newLoc, false, withinDo, exprs) 
    11181121        case last::rest => 
    1119         val allButLast = rest.map((e: Expr) => checkExpr(e, Some(Types.VOID), 
    1120                                                          errorString("Non-last expression in a block"))) 
     1122          val allButLast = rest.map((e: Expr) => checkExpr(e, Some(Types.VOID), 
     1123                                                           errorString("Non-last expression in a block"))) 
    11211124          val lastExpr = checkExpr(last) 
    11221125          val newExprs = (lastExpr::allButLast).reverse 
     
    11241127                 newLoc, false, withinDo, newExprs) 
    11251128      } 
     1129    } 
     1130 
     1131    case d@SLocalVarDecl(SExprInfo(span,paren,_), body, lhs, rhs) => { 
     1132      val newRhs = rhs.map(checkExpr) 
     1133      val newLhs = newRhs match { 
     1134        case Some(e) => getType(e) match { 
     1135          case Some(typ@STupleType(_,elts,_,_)) => 
     1136            if ( lhs.size != elts.size ) { 
     1137              signal(expr, errorMsg("The size of right-hand side, ", typ, 
     1138                                    ", does not match with the size of left-hand side.")) 
     1139              return expr 
     1140            } 
     1141            lhs.zip(elts).map( (p:(LValue,Type)) => p._1 match { 
     1142                               case SLValue(i,n,m,None,mt) => 
     1143                                 SLValue(i,n,m,Some(p._2),mt) 
     1144                               case SLValue(i,n,m,Some(t),mt) => 
     1145                                 isSubtype(p._2, t, p._1, 
     1146                                           errorMsg("Right-hand side, ", p._2, 
     1147                                                    ", must be a subtype of left-hand side, ", 
     1148                                                    t, ".")) 
     1149                                 p._1 } ) 
     1150          case Some(typ) => lhs match { 
     1151            case List(SLValue(i,name,mods,Some(idType),mutable)) => 
     1152              isSubtype(typ, idType, expr, 
     1153                        errorMsg("Right-hand side, ", typ, 
     1154                                 ", must be a subtype of left-hand side, ", idType, ".")) 
     1155              lhs 
     1156            case List(SLValue(i,name,mods,None,mutable)) => 
     1157              List(SLValue(i,name,mods,Some(typ),mutable)) 
     1158            case _ => 
     1159              signal(expr, errorMsg("Right-hand side, ", typ, 
     1160                                    ", is not a tuple type but left-hand side ", 
     1161                                    "declares multiple variables.")) 
     1162              return expr 
     1163          } 
     1164          case _ => return expr 
     1165        } 
     1166        case _ => lhs 
     1167      } 
     1168 
     1169      // Extend typechecker with new bindings from the RHS types 
     1170      val newChecker = this.extend(d) 
     1171      // A LocalVarDecl is like a let. It has a body, and its type is the type of the body 
     1172      val newBody = body.map(newChecker.checkExpr) 
     1173      if (!haveTypes(newBody)) { return expr } 
     1174      newBody.foreach(e => isSubtype(getType(e).get, Types.VOID, e, 
     1175                                     errorString("Non-last expression in a block"))) 
     1176      val newType = body.size match { 
     1177        case 0 => Some(Types.VOID) 
     1178        case _ => getType(newBody.last) 
     1179      } 
     1180      SLocalVarDecl(SExprInfo(span,paren,newType), newBody, newLhs, newRhs) 
    11261181    } 
    11271182 
     
    16151670          case Some(ty) => 
    16161671            isSubtype(ty, Types.BOOLEAN, expr, 
    1617                       errorMsg("The chained expression ", expr, 
     1672                      errorMsg("The chained expression ", 
    16181673                               " should have type Boolean, but had type ", normalize(ty), ".")) 
    16191674          case _ => false 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/useful/SExprUtil.scala

    r3827 r3877  
    3838  def haveTypes(exprs: List[Expr]): Boolean = 
    3939    exprs.forall((e:Expr) => getType(e).isDefined) 
    40    
    41    
    42    
     40 
    4341  /** 
    4442   * Given an expression, return an identical expression with the given type 
     
    5149        case SExprInfo(a, b, _) if !swap => 
    5250          swap = true 
    53           SExprInfo(a, b, Some(typ))           
     51          SExprInfo(a, b, Some(typ)) 
    5452        case _ if(!swap) => super.walk(node) 
    5553        case _ => node 
     
    5856    adder(expr).asInstanceOf[Expr] 
    5957  } 
    60    
     58 
    6159  /** 
    6260   * Replaces the overloadings in a FunctionalRef with the given overloadings 
     
    6866    case _ => NI.nyi() 
    6967  } 
    70    
     68 
    7169  /** 
    7270   * Replaces the static args in a FunctionalRef with the given ones. 
     
    7876    case _ => NI.nyi() 
    7977  } 
    80    
    81    
     78 
     79 
    8280}