Commit 8eba62a8 authored by Jürg Billeter's avatar Jürg Billeter

Eliminate unnecessary error check after try statements

This fixes a C warning about missing return in non-void function.
parent 9f07e88a
......@@ -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);
}
}
......@@ -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;
}
......
......@@ -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;
}
......
/* 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> ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment