This is an alternative implementation for D47540.
In this patch, I moved the code which produces the location part of a diagnostic message into a distinct place. I hope that this makes the overall code clearer because it simplifies other parts of the codebase.
The patch is primarily intended to demonstrate the approach and collect the feedback, which way we are going to go. The code is far from being perfect and has to be polished if this approach will be chosen.