build control flow graph for property accessors
authorJuerg Billeter <j@bitron.ch>
Tue, 5 Feb 2008 18:59:17 +0000 (18:59 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Tue, 5 Feb 2008 18:59:17 +0000 (18:59 +0000)
2008-02-05  Juerg Billeter  <j@bitron.ch>

* vala/valacfgbuilder.vala, vala/valapropertyaccessor.vala: build
  control flow graph for property accessors

svn path=/trunk/; revision=976

ChangeLog
vala/valacfgbuilder.vala
vala/valapropertyaccessor.vala

index 44c16e6..a8bbe66 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2008-02-05  Jürg Billeter  <j@bitron.ch>
 
+       * vala/valacfgbuilder.vala, vala/valapropertyaccessor.vala: build
+         control flow graph for property accessors
+
+2008-02-05  Jürg Billeter  <j@bitron.ch>
+
        * gee/hashmap.vala, gee/readonlycollection.vala, gee/readonlylist.vala,
          gee/readonlymap.vala, gee/readonlyset.vala: remove unreachable
          return statements
index 470b47a..99812f8 100644 (file)
@@ -63,7 +63,6 @@ public class Vala.CFGBuilder : CodeVisitor {
        private CodeContext context;
        private BasicBlock current_block;
        private bool unreachable_reported;
-       private Method current_method;
        private Gee.List<JumpTarget> jump_stack = new ArrayList<JumpTarget> ();
 
        public CFGBuilder () {
@@ -111,9 +110,6 @@ public class Vala.CFGBuilder : CodeVisitor {
                        return;
                }
 
-               var old_method = current_method;
-               current_method = m;
-
                m.entry_block = new BasicBlock.entry ();
                m.exit_block = new BasicBlock.exit ();
 
@@ -136,8 +132,39 @@ public class Vala.CFGBuilder : CodeVisitor {
 
                        current_block.connect (m.exit_block);
                }
+       }
+
+       public override void visit_property (Property! prop) {
+               prop.accept_children (this);
+       }
+
+       public override void visit_property_accessor (PropertyAccessor! acc) {
+               if (acc.body == null) {
+                       return;
+               }
+
+               acc.entry_block = new BasicBlock.entry ();
+               acc.exit_block = new BasicBlock.exit ();
+
+               current_block = new BasicBlock ();
+               acc.entry_block.connect (current_block);
 
-               current_method = old_method;
+               jump_stack.add (new JumpTarget.return_target (acc.exit_block));
+
+               acc.accept_children (this);
+
+               jump_stack.remove_at (jump_stack.size - 1);
+
+               if (current_block != null) {
+                       // end of property accessor body reachable
+
+                       if (acc.readable) {
+                               Report.error (acc.source_reference, "missing return statement at end of property getter body");
+                               acc.error = true;
+                       }
+
+                       current_block.connect (acc.exit_block);
+               }
        }
 
        public override void visit_block (Block! b) {
index d23e968..0c78df3 100644 (file)
@@ -1,6 +1,6 @@
 /* valapropertyaccessor.vala
  *
- * Copyright (C) 2006-2007  Jürg Billeter
+ * Copyright (C) 2006-2008  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -51,7 +51,11 @@ public class Vala.PropertyAccessor : CodeNode {
         * The accessor body.
         */
        public Block body { get; set; }
-       
+
+       public BasicBlock entry_block { get; set; }
+
+       public BasicBlock exit_block { get; set; }
+
        /**
         * Represents the generated value parameter in a set accessor.
         */