]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Accept pre- and postconditions for constructors
authorMarc-André Lureau <marcandre.lureau@gmail.com>
Sun, 17 Jan 2010 15:35:46 +0000 (16:35 +0100)
committerJürg Billeter <j@bitron.ch>
Wed, 20 Jan 2010 08:44:23 +0000 (09:44 +0100)
Fixes bug 607110.

vala/valacreationmethod.vala
vala/valaparser.vala

index 8469e1778240e5340861c250d1eba0a86a75a02d..8bcaecfa1539b04091f1dbeef1d2a46082a5778f 100644 (file)
@@ -80,6 +80,14 @@ public class Vala.CreationMethod : Method {
                        error_type.accept (visitor);
                }
 
+               foreach (Expression precondition in get_preconditions ()) {
+                       precondition.accept (visitor);
+               }
+
+               foreach (Expression postcondition in get_postconditions ()) {
+                       postcondition.accept (visitor);
+               }
+
                if (body != null) {
                        body.accept (visitor);
                }
@@ -153,6 +161,14 @@ public class Vala.CreationMethod : Method {
                        error_type.check (analyzer);
                }
 
+               foreach (Expression precondition in get_preconditions ()) {
+                       precondition.check (analyzer);
+               }
+
+               foreach (Expression postcondition in get_postconditions ()) {
+                       postcondition.check (analyzer);
+               }
+
                if (body != null) {
                        body.check (analyzer);
 
index 5a29d139ff642dd657d380b263e32b553745299e..4b3c7fde7fa4d9b76e919c90bb7e34f9d5580606 100644 (file)
@@ -2991,6 +2991,16 @@ public class Vala.Parser : CodeVisitor {
                                method.add_error_type (parse_type ());
                        } while (accept (TokenType.COMMA));
                }
+               while (accept (TokenType.REQUIRES)) {
+                       expect (TokenType.OPEN_PARENS);
+                       method.add_precondition (parse_expression ());
+                       expect (TokenType.CLOSE_PARENS);
+               }
+               while (accept (TokenType.ENSURES)) {
+                       expect (TokenType.OPEN_PARENS);
+                       method.add_postcondition (parse_expression ());
+                       expect (TokenType.CLOSE_PARENS);
+               }
                method.access = access;
                set_attributes (method, attrs);
                if (!accept (TokenType.SEMICOLON)) {