Changeset 3835

Show
Ignore:
Timestamp:
06/10/09 19:56:03 (8 months ago)
Author:
sukyoungryu
Message:

[type checker] Fixed small things in the Scala type checker. Matched some error messages from the Java type checker and the Scala type checker. Do not type check programs with syntax errors. Moved two tests from not_working_static_tests to compiler_tests.

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

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/compiler_tests/Compiled1.j.fss

    r3550 r3835  
    1616 ******************************************************************************) 
    1717 
    18 component DXXDoubleExponentiation 
     18component Compiled1.j 
    1919  export Executable 
    2020  run():() = () 
  • trunk/ProjectFortress/compiler_tests/Compiled1.k.fss

    r3550 r3835  
    1616 ******************************************************************************) 
    1717 
    18 component DXXExpThenSubscript 
     18component Compiled1.k 
    1919  export Executable 
    2020  run():() = () 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/StaticChecker.java

    r3829 r3835  
    222222                ConstraintUtil.useScalaFormulas(); 
    223223                STypeChecker typeChecker = STypeCheckerFactory.make(component, traitTable, typeEnv, typeAnalyzer); 
    224                 component_ast = typeChecker.check(component_ast); 
     224                component_ast = typeChecker.typecheck(component_ast); 
    225225                component = IndexBuilder.builder.buildComponentIndex((Component)component_ast, 
    226226                    System.currentTimeMillis()); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java

    r3829 r3835  
    432432                } 
    433433                else{ 
    434                     String err_message = "Two consecutive ^s"; 
     434                    String err_message = "Two consecutive ^s."; 
    435435                    StaticError err=TypeError.make(err_message, 
    436                                                                        new Span(NodeUtil.getSpan((ASTNode)exponent.unwrap()), 
    437                                                                                 NodeUtil.getSpan(that)).toString()); 
     436                                                   NodeUtil.getSpan(that).toString()); 
    438437                    return new TypeCheckerResult(that,err); 
    439438                } 
     
    446445                } 
    447446                else{ 
    448                     String err_message = "Exponentiation followed by subscripting is illegal"; 
     447                    String err_message = "Exponentiation followed by subscripting is illegal."; 
    449448                    StaticError err=TypeError.make(err_message, 
    450                                                                        new Span(NodeUtil.getSpan((ASTNode)exponent.unwrap()), 
    451                                                                                 NodeUtil.getSpan(that)).toString()); 
     449                                                   NodeUtil.getSpan(that).toString()); 
    452450                    exponent = Option.none(); 
    453451                    return new TypeCheckerResult(that,err); 
  • trunk/ProjectFortress/src/com/sun/fortress/exceptions/FortressException.java

    r3586 r3835  
    2323import java.util.ArrayList; 
    2424 
     25import edu.rice.cs.plt.tuple.Option; 
    2526import com.sun.fortress.interpreter.evaluator.Environment; 
    2627import com.sun.fortress.nodes_util.ErrorMsgMaker; 
     
    111112    public FortressException(Iterable<? extends StaticError> errors) { 
    112113        this.staticErrors = errors; 
     114    } 
     115 
     116    public Option<HasAt> getLoc() { 
     117        if ( this.where.isEmpty() ) 
     118            return Option.none(); 
     119        else return Option.wrap(this.where.get(0)); 
     120    } 
     121 
     122    public String getOriginalMessage() { 
     123        return super.getMessage(); 
    113124    } 
    114125 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/STypeChecker.scala

    r3834 r3835  
    4444import com.sun.fortress.exceptions.StaticError 
    4545import com.sun.fortress.exceptions.StaticError.errorMsg 
    46 import com.sun.fortress.exceptions.TypeError 
     46import com.sun.fortress.exceptions.ProgramError 
     47import com.sun.fortress.exceptions.ProgramError.error 
    4748import com.sun.fortress.nodes._ 
    4849import com.sun.fortress.nodes_util.NodeFactory 
     
    131132  protected def signal(hasAt:HasAt, msg:String) = 
    132133    errors.signal(msg, hasAt) 
     134 
     135  private def syntaxError(hasAt:HasAt, msg:String) = 
     136    error(hasAt, msg) 
    133137 
    134138  /** 
     
    642646  // ------------------------------------------------------------------------ 
    643647 
    644  
    645   def check(node:Node):Node = node match { 
     648  def typecheck(node:Node):Node = 
     649    try { check(node) } 
     650    catch { case e:ProgramError => 
     651              errors.errors = List[StaticError]() 
     652              errors.signal(e.getOriginalMessage, e.getLoc.unwrap) 
     653              node 
     654          } 
     655 
     656  private def check(node:Node):Node = node match { 
    646657    case SComponent(info, name, imports, decls, isNative, exports)  => 
    647658      SComponent(info, name, imports, 
     
    11431154          case SExponentiationMI(_,_,_) => exponent match { 
    11441155            case None => exponent = Some(item) 
    1145             case Some(e) => signal(item, "Two consecutive ^s.") 
     1156            case Some(e) => syntaxError(item, "Two consecutive ^s.") 
    11461157          } 
    11471158          case SSubscriptingMI(_,_,_,_) => exponent match { 
    11481159            case Some(e) => 
    1149               signal(item, "Exponentiation followed by subscripting is illegal.") 
     1160              syntaxError(item, "Exponentiation followed by subscripting is illegal.") 
    11501161            case None => 
    11511162          } 
     
    11691180        case SParenthesisDelimitedMI(_,e) => isArrows(checkExpr(e)) 
    11701181        case SNonParenthesisDelimitedMI(_,e) => isArrows(checkExpr(e)) 
    1171         case _ => 
     1182        case _ => false 
    11721183      } 
    11731184      def expectParenedExprItem(item: MathItem) = 
    11741185        if ( ! isParenedExprItem(item) ) 
    1175           signal(item, "Argument to function must be parenthesized.") 
     1186          syntaxError(item, "Argument to function must be parenthesized.") 
    11761187      def expectExprMI(item: MathItem) = 
    11771188        if ( ! isExprMI(item) ) 
    1178           signal(item, "Item at this location must be an expression, not an operator.") 
     1189          syntaxError(item, "Item at this location must be an expression, not an operator.") 
    11791190      // items is not an empty list. 
    11801191      def associateMathItems(first: Expr, 
     
    11881199        // find the left-most function 
    11891200        val (prefix, others) = items.span((e:MathItem) => 
    1190                                           !isFunctionItem(e).asInstanceOf[Boolean]) 
     1201                                          !isFunctionItem(e)) 
    11911202        others match { 
    11921203          case fn::arg::suffix => arg match { 
    11931204            // It is a static error if either the argument is not parenthesized, 
    11941205            case SNonParenthesisDelimitedMI(_,e) => 
    1195               signal(e, "Tightly juxtaposed expression should be parenthesized.") 
     1206              syntaxError(e, "Tightly juxtaposed expression should be parenthesized.") 
    11961207              (first, Nil) 
    11971208            case SParenthesisDelimitedMI(i,e) => { 
     
    12001211                case third::more => 
    12011212                  if ( ! isExprMI(third) ) 
    1202                     signal(third, "An expression is expected.") 
     1213                    syntaxError(third, "An expression is expected.") 
    12031214                case _ => 
    12041215              } 
     
    12271238              left.last.asInstanceOf[ExprMI].getExpr 
    12281239            else { 
    1229               signal(left.last, "An expression is expected.") 
     1240              syntaxError(left.last, "An expression is expected.") 
    12301241              first 
    12311242            } 
     
    12481259                                              toJavaList(sargs)) 
    12491260              case _ => 
    1250                 signal(item, "Non-expression element is expected.") 
     1261                syntaxError(item, "Non-expression element is expected.") 
    12511262                head 
    12521263            } 
     
    12891300            val newTail = tail.map( (e:MathItem) => 
    12901301                                    if ( ! isExprMI(e) ) { 
    1291                                       signal(e, "An expression is expected.") 
     1302                                      syntaxError(e, "An expression is expected.") 
    12921303                                      ExprFactory.makeVoidLiteralExpr(span) 
    12931304                                    } else e.asInstanceOf[ExprMI].getExpr )