Open
Description
Consider parseShowColorsArgs
from flang/lib/Frontend/CompilerInvocation.cpp and clang/lib/Frontend/CompilerInvocation.cpp. The function has been copied almost verbatim except:
- Flang doesn't rely on
using namespace llvm::opt;
- whitespace
showColors
andvalue
follows a different case convention- variable named
opt
instead ofO
- default argument different, comment about it
Using copy->paste->edit like this tedious and error-prone. Any bugs in the Clang driver code will need to be fixed manually a second time in Flang. Due to the syntax changes that have no impact on code generation, this won't be as trivial because the patch to Flang will have to use the new variable names.
This code should be properly abstracted and reused.
Furthermore, Flang should follow https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly.
< static bool parseShowColorsArgs(const llvm::opt::ArgList &args,
< bool defaultColor = true) {
< // Color diagnostics default to auto ("on" if terminal supports) in the
< // compiler driver `flang-new` but default to off in the frontend driver
< // `flang-new -fc1`, needing an explicit OPT_fdiagnostics_color.
---
> static bool parseShowColorsArgs(const ArgList &Args, bool DefaultColor) {
> // Color diagnostics default to auto ("on" if terminal supports) in the driver
> // but default to off in cc1, needing an explicit OPT_fdiagnostics_color.
12,27c10,24
< } showColors = defaultColor ? Colors_Auto : Colors_Off;
<
< for (auto *a : args) {
< const llvm::opt::Option &opt = a->getOption();
< if (opt.matches(clang::driver::options::OPT_fcolor_diagnostics)) {
< showColors = Colors_On;
< } else if (opt.matches(clang::driver::options::OPT_fno_color_diagnostics)) {
< showColors = Colors_Off;
< } else if (opt.matches(clang::driver::options::OPT_fdiagnostics_color_EQ)) {
< llvm::StringRef value(a->getValue());
< if (value == "always")
< showColors = Colors_On;
< else if (value == "never")
< showColors = Colors_Off;
< else if (value == "auto")
< showColors = Colors_Auto;
---
> } ShowColors = DefaultColor ? Colors_Auto : Colors_Off;
> for (auto *A : Args) {
> const Option &O = A->getOption();
> if (O.matches(options::OPT_fcolor_diagnostics)) {
> ShowColors = Colors_On;
> } else if (O.matches(options::OPT_fno_color_diagnostics)) {
> ShowColors = Colors_Off;
> } else if (O.matches(options::OPT_fdiagnostics_color_EQ)) {
> StringRef Value(A->getValue());
> if (Value == "always")
> ShowColors = Colors_On;
> else if (Value == "never")
> ShowColors = Colors_Off;
> else if (Value == "auto")
> ShowColors = Colors_Auto;
30,32c27,28
<
< return showColors == Colors_On ||
< (showColors == Colors_Auto &&
---
> return ShowColors == Colors_On ||
> (ShowColors == Colors_Auto &&