From 9afb9275cc762ae935ef7f0e8946a934e6e70545 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 17 Jun 2009 16:38:07 -0400 Subject: [PATCH] syntax: add PExpr:is_typed and PExpr::is_statement Contracts are not enforced yet. Update check_expr to profit from them. Signed-off-by: Jean Privat --- src/syntax/syntax_base.nit | 22 +++++++++++++++++----- src/syntax/typing.nit | 10 ++++++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/syntax/syntax_base.nit b/src/syntax/syntax_base.nit index 259cf9a..aaa9439 100644 --- a/src/syntax/syntax_base.nit +++ b/src/syntax/syntax_base.nit @@ -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 diff --git a/src/syntax/typing.nit b/src/syntax/typing.nit index 2bf36f4..91e3043 100644 --- a/src/syntax/typing.nit +++ b/src/syntax/typing.nit @@ -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 -- 1.7.9.5