[Vala] improved static exception checking



Hi,

I had a few ideas about how to improve on the exception checking in
semanticanalyser.vala.

1) Finish adding exception propagation to more AST node types, e.g.
SwitchSection, try/catch blocks, etc

2) Separate all exception checking into a new code visitor, and run
exception checking after the semantic analyzer. This would allow for
better separation of concerns and make the code easier to read.

3) Report unhandled exceptions at the source, rather than at the top
of the containing method. This can be implemented as follows (or
something similar):

public ErrorChecker : CodeVisitor {
    private ArrayList<DataType> expected_errors = new ArrayList<DataType>();

    ...


    public void visit_method (Method m) {
        var old_expected_errors = expected_errors;

        expected_errors = m.get_expected_errors ();
        m.accept_children (this);

        expected_errors = old_expected_errors;
    }

    ...

    private boolean error_is_expected (DataType err_type) {
        foreach (DataType expected_type in expected_errors) {
            if (error_type.compatible (expected_type)) {
                return true;
            }
        }
        return false;
    }

    ....

    public void visit_expression (Expression e) {
        if (e.tree_can_fail) {
            foreach (DataType err in e.get_error_types ()) {
                if (!error_is_expected(err)) {
                    Report.error (e.source_reference, "unhandled
error: %s", err.to_string());
                }
        }
    }

    ...

}



Thoughts> If there is positive feedback on these ideas, I'll start
work on implementing them.

Also, attached is a patch that does some minor refactoring.


Cheers,
Jared Moore

Attachment: exceptionsrefactor.patch
Description: Text Data



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