[vala] Eliminate unnecessary error check after try statements



commit 8eba62a86432c19e307b9ff2874511abd90223aa
Author: Jürg Billeter <j bitron ch>
Date:   Thu Mar 25 09:29:49 2010 +0100

    Eliminate unnecessary error check after try statements
    
    This fixes a C warning about missing return in non-void function.

 codegen/valaccodemodule.vala  |    4 ++--
 codegen/valagerrormodule.vala |    8 ++++----
 vala/valaflowanalyzer.vala    |    1 +
 vala/valatrystatement.vala    |    4 +++-
 4 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodemodule.vala b/codegen/valaccodemodule.vala
index 0355e0c..523ac08 100644
--- a/codegen/valaccodemodule.vala
+++ b/codegen/valaccodemodule.vala
@@ -431,7 +431,7 @@ public abstract class Vala.CCodeModule {
 		return next.get_array_size_cexpression (array_expr);
 	}
 
-	public virtual void add_simple_check (CodeNode node, CCodeFragment cfrag) {
-		next.add_simple_check (node, cfrag);
+	public virtual void add_simple_check (CodeNode node, CCodeFragment cfrag, bool always_fails = false) {
+		next.add_simple_check (node, cfrag, always_fails);
 	}
 }
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index 51c8132..1dc47fc 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -94,7 +94,7 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
 		var cassign = new CCodeAssignment (get_variable_cexpression ("_inner_error_"), (CCodeExpression) stmt.error_expression.ccodenode);
 		cfrag.append (new CCodeExpressionStatement (cassign));
 
-		head.add_simple_check (stmt, cfrag);
+		head.add_simple_check (stmt, cfrag, true);
 
 		stmt.ccodenode = cfrag;
 
@@ -188,7 +188,7 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
 		return false;
 	}
 
-	public override void add_simple_check (CodeNode node, CCodeFragment cfrag) {
+	public override void add_simple_check (CodeNode node, CCodeFragment cfrag, bool always_fails = false) {
 		current_method_inner_error = true;
 
 		var inner_error = get_variable_cexpression ("_inner_error_");
@@ -309,7 +309,7 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
 			cerror_handler = uncaught_error_statement (inner_error);
 		}
 
-		if (node is ThrowStatement) {
+		if (always_fails) {
 			// inner_error is always set, avoid unnecessary if statement
 			// eliminates C warnings
 			cfrag.append (cerror_handler);
@@ -364,7 +364,7 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
 
 		// check for errors not handled by this try statement
 		// may be handled by outer try statements or propagated
-		add_simple_check (stmt, cfrag);
+		add_simple_check (stmt, cfrag, !stmt.after_try_block_reachable);
 
 		stmt.ccodenode = cfrag;
 	}
diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala
index 193f610..9a04e1b 100644
--- a/vala/valaflowanalyzer.vala
+++ b/vala/valaflowanalyzer.vala
@@ -1001,6 +1001,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
 		if (after_try_block.get_predecessors ().size > 0) {
 			current_block = after_try_block;
 		} else {
+			stmt.after_try_block_reachable = false;
 			current_block = null;
 			unreachable_reported = false;
 		}
diff --git a/vala/valatrystatement.vala b/vala/valatrystatement.vala
index 4bf6e7a..540af3e 100644
--- a/vala/valatrystatement.vala
+++ b/vala/valatrystatement.vala
@@ -1,6 +1,6 @@
 /* valatrystatement.vala
  *
- * Copyright (C) 2007-2008  Jürg Billeter
+ * Copyright (C) 2007-2010  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
@@ -49,6 +49,8 @@ public class Vala.TryStatement : CodeNode, Statement {
 		}
 	}
 
+	public bool after_try_block_reachable { get; set; default = true; }
+
 	private Block _body;
 	private Block _finally_body;
 	private List<CatchClause> catch_clauses = new ArrayList<CatchClause> ();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]