From 55a96155995465416118774add8ef09c30dbebda Mon Sep 17 00:00:00 2001 From: Andrzej Warzynski Date: Wed, 30 Jun 2021 10:57:48 +0000 Subject: [flang][driver] Refactor boolean options For boolean options, e.g. `-fxor-operator`/`-fno-xor-operator`, we ought to be using TableGen multi-classes. This way, we only have to write one definition to have both forms auto-generated. This patch refactors all of Flang's boolean options to use two new multi-classes: `OptInFC1FFOption` and `OptOutFC1FFOption`. These multi-classes are based on `OptInFFOption`/`OptOutFFOption`, respectively. I've also simplified the processing of the updated options in CompilerInvocation.cpp. With the new approach, "empty" help text (i.e. no `HelpText`) is now replaced with an empty string (i.e. HelpText<"">). When running flang-new --help, that's considered as non-empty help messages, which is then printed (that's controlled by `printHelp` from llvm/lib/Option/OptTable.cpp). This means that with this patch, flang-new --help will start printing e.g. -fno-backslash, even though there is no actual help text to print for this option (apart from the empty string ""). Tests are updated accordingly. Note that with this patch, both `-fxor-operator` and `-fno-xor-operator` (and other boolean options refactored here) remain available in `flang-new` and `flang-new -fc1`. In this respect, nothing changes. In a forthcoming patch, I will refine this so that `flang-new -fc1` only accepts `-ffoo` (`OptInFC1FFOption`) or `-fno-foo` (`OptOutCC1FFOption`). For clarity, `OptInFFOption`/`OptOutFFOption` are renamed as `OptInCC1FFOption`/`OptOutCC1FFOption`, respectively. Otherwise, this is an NFC from Clang's perspective. Differential Revision: https://reviews.llvm.org/D105881 --- flang/lib/Frontend/CompilerInvocation.cpp | 56 ++++++++++++++----------------- 1 file changed, 25 insertions(+), 31 deletions(-) (limited to 'flang/lib/Frontend/CompilerInvocation.cpp') diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index fb0a21e..68ff1671 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -277,32 +277,27 @@ static bool ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args, } } - if (const llvm::opt::Arg *arg = - args.getLastArg(clang::driver::options::OPT_fimplicit_none, - clang::driver::options::OPT_fno_implicit_none)) { - opts.features.Enable( - Fortran::common::LanguageFeature::ImplicitNoneTypeAlways, - arg->getOption().matches(clang::driver::options::OPT_fimplicit_none)); - } - if (const llvm::opt::Arg *arg = - args.getLastArg(clang::driver::options::OPT_fbackslash, - clang::driver::options::OPT_fno_backslash)) { - opts.features.Enable(Fortran::common::LanguageFeature::BackslashEscapes, - arg->getOption().matches(clang::driver::options::OPT_fbackslash)); - } - if (const llvm::opt::Arg *arg = - args.getLastArg(clang::driver::options::OPT_flogical_abbreviations, - clang::driver::options::OPT_fno_logical_abbreviations)) { - opts.features.Enable(Fortran::common::LanguageFeature::LogicalAbbreviations, - arg->getOption().matches( - clang::driver::options::OPT_flogical_abbreviations)); - } - if (const llvm::opt::Arg *arg = - args.getLastArg(clang::driver::options::OPT_fxor_operator, - clang::driver::options::OPT_fno_xor_operator)) { - opts.features.Enable(Fortran::common::LanguageFeature::XOROperator, - arg->getOption().matches(clang::driver::options::OPT_fxor_operator)); - } + // -f{no-}implicit-none + opts.features.Enable( + Fortran::common::LanguageFeature::ImplicitNoneTypeAlways, + args.hasFlag(clang::driver::options::OPT_fimplicit_none, + clang::driver::options::OPT_fno_implicit_none, false)); + + // -f{no-}backslash + opts.features.Enable(Fortran::common::LanguageFeature::BackslashEscapes, + args.hasFlag(clang::driver::options::OPT_fbackslash, + clang::driver::options::OPT_fno_backslash, false)); + + // -f{no-}logical-abbreviations + opts.features.Enable(Fortran::common::LanguageFeature::LogicalAbbreviations, + args.hasFlag(clang::driver::options::OPT_flogical_abbreviations, + clang::driver::options::OPT_fno_logical_abbreviations, false)); + + // -f{no-}xor-operator + opts.features.Enable(Fortran::common::LanguageFeature::XOROperator, + args.hasFlag(clang::driver::options::OPT_fxor_operator, + clang::driver::options::OPT_fno_xor_operator, false)); + if (args.hasArg( clang::driver::options::OPT_falternative_parameter_statement)) { opts.features.Enable(Fortran::common::LanguageFeature::OldStyleParameter); @@ -406,11 +401,10 @@ static bool parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args, res.SetModuleFileSuffix(moduleSuffix->getValue()); } - // -fno-analyzed-objects-for-unparse - if (args.hasArg( - clang::driver::options::OPT_fno_analyzed_objects_for_unparse)) { - res.SetUseAnalyzedObjectsForUnparse(false); - } + // -f{no-}analyzed-objects-for-unparse + res.SetUseAnalyzedObjectsForUnparse( + args.hasFlag(clang::driver::options::OPT_fanalyzed_objects_for_unparse, + clang::driver::options::OPT_fno_analyzed_objects_for_unparse, true)); return diags.getNumErrors() == numErrorsBefore; } -- cgit v1.1