[flang] Introduce DiagnosticConsumer classes in libflangFrontend
authorAndrzej Warzynski <andrzej.warzynski@arm.com>
Mon, 5 Oct 2020 16:42:00 +0000 (17:42 +0100)
committerAndrzej Warzynski <andrzej.warzynski@arm.com>
Mon, 5 Oct 2020 16:46:44 +0000 (17:46 +0100)
commit8d51d37e0628bde3eb5a3200507ba7135dfc2751
treec073fdb5ff90ef18ce5a922ef79cc9fd3a17a069
parent1dce692de1896412693f25a3afb4818883a611e7
[flang] Introduce DiagnosticConsumer classes in libflangFrontend

Currently Flang uses TextDiagnostic, TextDiagnosticPrinter &
TestDiagnosticBuffer classes from Clang (more specifically, from
libclangFrontend). This patch introduces simplified equivalents of these
classes in Flang (i.e. it removes the dependency on libclangFrontend).

Flang only needs these diagnostics classes for the compiler driver
diagnostics. This is unlike in Clang in which similar diagnostic classes
are used for e.g. Lexing/Parsing/Sema diagnostics. For this reason, the
implementations introduced here are relatively basic. We can extend them
in the future if this is required.

This patch also enhances how the diagnostics are printed. In particular,
this is the diagnostic that you'd get _before_  the changes introduced here
(no text formatting):

```
$ bin/flang-new
error: no input files
```

This is the diagnostic that you get _after_ the changes introduced here
(in terminals that support it, the text is formatted - bold + red):

```
$ bin/flang-new
flang-new: error: no input files
```

Tests are updated accordingly and options related to enabling/disabling
color diagnostics are flagged as supported by Flang.

Reviewed By: sameeranjoshi, CarolineConcatto

Differential Revision: https://reviews.llvm.org/D87774
19 files changed:
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/CompilerInvocation.h
flang/include/flang/Frontend/TextDiagnostic.h [new file with mode: 0644]
flang/include/flang/Frontend/TextDiagnosticBuffer.h [new file with mode: 0644]
flang/include/flang/Frontend/TextDiagnosticPrinter.h [new file with mode: 0644]
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/TextDiagnostic.cpp [new file with mode: 0644]
flang/lib/Frontend/TextDiagnosticBuffer.cpp [new file with mode: 0644]
flang/lib/Frontend/TextDiagnosticPrinter.cpp [new file with mode: 0644]
flang/test/Flang-Driver/driver-error-cc1.c
flang/test/Flang-Driver/driver-error-cc1.cpp
flang/test/Flang-Driver/driver-help.f90
flang/test/Flang-Driver/driver-version.f90
flang/test/Flang-Driver/missing-input.f90
flang/tools/flang-driver/driver.cpp
flang/tools/flang-driver/fc1_main.cpp
flang/unittests/Frontend/CompilerInstanceTest.cpp