From 29f0184781ced02fb6658fab3eb120d9707672d3 Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Tue, 5 Feb 2008 18:59:17 +0000 Subject: [PATCH] build control flow graph for property accessors 2008-02-05 Juerg Billeter * vala/valacfgbuilder.vala, vala/valapropertyaccessor.vala: build control flow graph for property accessors svn path=/trunk/; revision=976 --- ChangeLog | 5 +++++ vala/valacfgbuilder.vala | 37 ++++++++++++++++++++++++++++++++----- vala/valapropertyaccessor.vala | 8 ++++++-- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44c16e6..a8bbe66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2008-02-05 Jürg Billeter + * vala/valacfgbuilder.vala, vala/valapropertyaccessor.vala: build + control flow graph for property accessors + +2008-02-05 Jürg Billeter + * gee/hashmap.vala, gee/readonlycollection.vala, gee/readonlylist.vala, gee/readonlymap.vala, gee/readonlyset.vala: remove unreachable return statements diff --git a/vala/valacfgbuilder.vala b/vala/valacfgbuilder.vala index 470b47a..99812f8 100644 --- a/vala/valacfgbuilder.vala +++ b/vala/valacfgbuilder.vala @@ -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 jump_stack = new ArrayList (); 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) { diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala index d23e968..0c78df3 100644 --- a/vala/valapropertyaccessor.vala +++ b/vala/valapropertyaccessor.vala @@ -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. */ -- 2.7.4