syntax: add PExpr:is_typed and PExpr::is_statement
authorJean Privat <jean@pryen.org>
Wed, 17 Jun 2009 20:38:07 +0000 (16:38 -0400)
committerJean Privat <jean@pryen.org>
Wed, 24 Jun 2009 19:47:33 +0000 (15:47 -0400)
Contracts are not enforced yet.
Update check_expr to profit from them.

Signed-off-by: Jean Privat <jean@pryen.org>

src/syntax/syntax_base.nit
src/syntax/typing.nit

index 259cf9a..aaa9439 100644 (file)
@@ -373,9 +373,12 @@ special Visitor
        # Require that the static type of n is known
        meth check_expr(n: PExpr): Bool
        do
-               # FIXME: The tc.error_count is a workaround since currently there is no way
-               # to distingate statements from buggy expressions: both have a null stype
-               if tc.error_count == 0 and n.stype == null then
+               if not n.is_typed then
+                       # An error occured in a sub node,
+                       # sillently cascade fail
+                       return false
+               else if tc.error_count == 0 and n.is_statement then # FIXME remove 'tc.error_count == 0'
+               #if tc.error_count == 0 and n.stype == null then
                        error(n, "Type error: expected expression.")
                        return false
                end
@@ -624,8 +627,17 @@ redef class AType
 end
 
 redef class PExpr
-       # Static type
-       # Is null for statement and for erronus expression
+       # Is the expression node correcly typed
+       # Return false if typed was not yet computed or
+       # if an error occured during the typing computation
+       meth is_typed: Bool is abstract
+
+       # Is the expression node a statement? (ie has no return value)
+       # require: is_typed
+       meth is_statement: Bool is abstract
+
+       # The static type of the expression
+       # require: is_typed and not is_statement
        meth stype: MMType is abstract
 end
 
index 2bf36f4..91e3043 100644 (file)
@@ -345,8 +345,14 @@ redef class PType
 end
 
 redef class PExpr
-       redef readable attr _stype: MMType
-       
+       redef readable attr _is_typed: Bool = true # FIXME: Switch to false once subclasses are adapted
+       redef meth is_statement: Bool do return _stype == null
+       redef meth stype
+       do
+               return _stype
+       end
+       attr _stype: MMType
+
        # Is the expression the implicit receiver
        meth is_implicit_self: Bool do return false