Branch visitors for detecting and mutating branches.

This PR replaces #547. The branch has been renamed to correspond to the name of the main file this adds.  I have addressed most of the comments that were still open in #547, and made some modifications that are dependent on PR #551.

Oops, that was left over from a previous version, where the scope contained bools.