[vala] Do not declare result variable if it is unused
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Do not declare result variable if it is unused
- Date: Wed, 16 Sep 2009 12:23:02 +0000 (UTC)
commit 4cdf4417a4422182f5336a3c181e7940fdedc341
Author: Jürg Billeter <j bitron ch>
Date: Wed Sep 16 14:15:29 2009 +0200
Do not declare result variable if it is unused
codegen/valaccodebasemodule.vala | 9 ++++++---
codegen/valaccodemethodmodule.vala | 9 ++++++---
2 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9f5611d..5063d38 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1517,9 +1517,12 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
if (acc.readable && !returns_real_struct) {
- var cdecl = new CCodeDeclaration (acc.value_type.get_cname ());
- cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
- function.block.prepend_statement (cdecl);
+ // do not declare result variable if exit block is known to be unreachable
+ if (acc.exit_block == null || acc.exit_block.get_predecessors ().size > 0) {
+ var cdecl = new CCodeDeclaration (acc.value_type.get_cname ());
+ cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
+ function.block.prepend_statement (cdecl);
+ }
}
if (current_method_inner_error) {
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 3125e74..2eb974b 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -492,9 +492,12 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
}
if (!(m.return_type is VoidType) && !m.return_type.is_real_struct_type () && !m.coroutine) {
- var cdecl = new CCodeDeclaration (m.return_type.get_cname ());
- cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
- cinit.append (cdecl);
+ // do not declare result variable if exit block is known to be unreachable
+ if (m.exit_block == null || m.exit_block.get_predecessors ().size > 0) {
+ var cdecl = new CCodeDeclaration (m.return_type.get_cname ());
+ cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
+ cinit.append (cdecl);
+ }
}
if (inner_error) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]