D-Programming-Language/dmd — pull request #3077 by CyberShadow (2014-01-09 21:02:58+00:00)
Title: Track column numbers, add `-columns` to display them in diagnostics

This commit adds tracking of column numbers in most places where the compiler is already tracking line numbers, includes them in JSON output, as well as introduces a new compiler switch (`-columns`) which enables their display in diagnostic messages.

Rationale:

- Column information can be helpful in identifying the source of compilation errors, especially in long lines (as is common with e.g. chained UFCS calls).
- IDEs will benefit the most from this change. Most IDEs and some graphical text editors are capable of parsing compiler output and allowing the user to navigate directly to the source code position causing the diagnostic messages. Some of them even overlay markers on top of the source code, to indicate the exact positions where compilation errors occurred.
- Some debugging formats support column information (e.g. DWARF has `DW_AT_decl_column`). This patch doesn't add support for that though.
- Other compiler backends/toolchains already have ways to make use of column information. Recent GCC versions will display columns in diagnostic messages by default, as well as reproduce the source code line and print a caret pointing out the exact location of the error. In fact, because this information was not being tracked by the DMD frontend, GDC currently deviates from the standard diagnostic output of the GCC toolchain by forcibly enabling the options `-fno-show-column` and `-fno-diagnostics-show-caret`. (Possibly some of this also applies to LDC, haven't checked.)

The compiler switch was added because:
- Changing the diagnostic output format at this point is likely to break lots of tools
- IDEs can opt in to the new format by transparently adding a switch to the compiler command line
- Users running the compiler directly from the command line are less likely to make use of the column number
- It would break all the `fail_compilation` tests :)