awarzynski created this revision. Herald added a subscriber: dang. awarzynski requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
For boolean options, e.g. `-fxor-operator/-fno-xor-operator`, we ought to be using TableGen multiclasses. 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 the `BoolFOption` multiclass. >From what I can see, `BoolFOption` does not support `DocString` and one of our boolean options did specify a `DocString`. As we don't use these fields in Flang just yet, deleting it seemed like the right approach at this stage. We still have the "help" text to provides a brief description. This patch also defines a dummy `KeyPathAndMacro` to be used by Flang. Again, we don't use this field on Flang just yet, so we defined this dummy instance to avoid creating new TableGen multiclasses for boolean options. With the new approach, "empty" help text is now replaced with an empty string. When running `flang-new --help`, that's considered as non-empty help messages, which is then printed. 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 emtpy string ""). Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D105881 Files: clang/include/clang/Driver/Options.td flang/lib/Frontend/CompilerInvocation.cpp flang/test/Driver/driver-help-hidden.f90 flang/test/Driver/driver-help.f90
Index: flang/test/Driver/driver-help.f90 =================================================================== --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -40,7 +40,12 @@ ! HELP-NEXT: Specify where to find the compiled intrinsic modules ! HELP-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations +! HELP-NEXT: -fno-backslash ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics +! HELP-NEXT: -fno-implicit-none +! HELP-NEXT: -fno-logical-abbreviations +! HELP-NEXT: Disable logical abbreviations +! HELP-NEXT: -fno-xor-operator Disable .XOR. as a synonym of .NEQV. ! HELP-NEXT: -fopenacc Enable OpenACC ! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. @@ -68,6 +73,8 @@ ! HELP-FC1-NEXT: -E Only run the preprocessor ! HELP-FC1-NEXT: -falternative-parameter-statement ! HELP-FC1-NEXT: Enable the old style PARAMETER statement +! HELP-FC1-NEXT: -fanalyzed-objects-for-unparse +! HELP-FC1-NEXT: Use the analyzed objects when unparsing ! HELP-FC1-NEXT: -fbackslash Specify that backslash in string introduces an escape character ! HELP-FC1-NEXT: -fdebug-dump-all Dump symbols and the parse tree after the semantic checks ! HELP-FC1-NEXT: -fdebug-dump-parse-tree-no-sema @@ -103,6 +110,11 @@ ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations ! HELP-FC1-NEXT: -fno-analyzed-objects-for-unparse ! HELP-FC1-NEXT: Do not use the analyzed objects when unparsing +! HELP-FC1-NEXT: -fno-backslash +! HELP-FC1-NEXT: -fno-implicit-none +! HELP-FC1-NEXT: -fno-logical-abbreviations +! HELP-FC1-NEXT: Disable logical abbreviations +! HELP-FC1-NEXT: -fno-xor-operator Disable .XOR. as a synonym of .NEQV. ! HELP-FC1-NEXT: -fopenacc Enable OpenACC ! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. Index: flang/test/Driver/driver-help-hidden.f90 =================================================================== --- flang/test/Driver/driver-help-hidden.f90 +++ flang/test/Driver/driver-help-hidden.f90 @@ -40,7 +40,12 @@ ! CHECK-NEXT: Specify where to find the compiled intrinsic modules ! CHECK-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations +! CHECK-NEXT: -fno-backslash ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics +! CHECK-NEXT: -fno-implicit-none +! CHECK-NEXT: -fno-logical-abbreviations +! CHECK-NEXT: Disable logical abbreviations +! CHECK-NEXT: -fno-xor-operator Disable .XOR. as a synonym of .NEQV. ! CHECK-NEXT: -fopenacc Enable OpenACC ! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. Index: flang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- flang/lib/Frontend/CompilerInvocation.cpp +++ flang/lib/Frontend/CompilerInvocation.cpp @@ -277,33 +277,27 @@ } } - 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); @@ -404,11 +398,10 @@ 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; } Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -243,6 +243,7 @@ def clang_ignored_gcc_optimization_f_Group : OptionGroup< "<clang_ignored_gcc_optimization_f_Group>">, Group<f_Group>, Flags<[Ignored]>; +class EmptyKPM<string base> : KeyPathAndMacro<"", "", ""> {} class DiagnosticOpts<string base> : KeyPathAndMacro<"DiagnosticOpts->", base, "DIAG_"> {} class LangOpts<string base> @@ -4481,28 +4482,28 @@ HelpText<"Set the default real kind to an 8 byte wide type">; def flarge_sizes : Flag<["-"],"flarge-sizes">, Group<f_Group>, HelpText<"Use INTEGER(KIND=8) for the result type in size-related intrinsics">; -def fbackslash : Flag<["-"], "fbackslash">, Group<f_Group>, - HelpText<"Specify that backslash in string introduces an escape character">, - DocBrief<[{Change the interpretation of backslashes in string literals from -a single backslash character to "C-style" escape characters.}]>; -def fno_backslash : Flag<["-"], "fno-backslash">, Group<f_Group>; -def fxor_operator : Flag<["-"], "fxor-operator">, Group<f_Group>, - HelpText<"Enable .XOR. as a synonym of .NEQV.">; -def fno_xor_operator : Flag<["-"], "fno-xor-operator">, Group<f_Group>; -def flogical_abbreviations : Flag<["-"], "flogical-abbreviations">, Group<f_Group>, - HelpText<"Enable logical abbreviations">; -def fno_logical_abbreviations : Flag<["-"], "fno-logical-abbreviations">, Group<f_Group>; -def fimplicit_none : Flag<["-"], "fimplicit-none">, Group<f_Group>, - HelpText<"No implicit typing allowed unless overridden by IMPLICIT statements">; -def fno_implicit_none : Flag<["-"], "fno-implicit-none">, Group<f_Group>; def falternative_parameter_statement : Flag<["-"], "falternative-parameter-statement">, Group<f_Group>, HelpText<"Enable the old style PARAMETER statement">; def fintrinsic_modules_path : Separate<["-"], "fintrinsic-modules-path">, Group<f_Group>, MetaVarName<"<dir>">, HelpText<"Specify where to find the compiled intrinsic modules">, DocBrief<[{This option specifies the location of pre-compiled intrinsic modules, if they are not in the default location expected by the compiler.}]>; +defm backslash : BoolFOption<"backslash", EmptyKPM<"None">, DefaultFalse, + PosFlag<SetTrue, [], "Specify that backslash in string introduces an escape character">, + NegFlag<SetFalse, []>>; +defm xor_operator : BoolFOption<"xor-operator", EmptyKPM<"None">, DefaultFalse, + PosFlag<SetTrue, [], "Enable">, NegFlag<SetFalse, [], "Disable">, + BothFlags<[], " .XOR. as a synonym of .NEQV.">>; +defm logical_abbreviations : BoolFOption<"logical-abbreviations", EmptyKPM<"None">, DefaultFalse, + PosFlag<SetTrue, [], "Enable ">, + NegFlag<SetFalse, [], "Disable ">, + BothFlags<[], "logical abbreviations">>; +defm implicit_none : BoolFOption<"implicit-none", EmptyKPM<"None">, DefaultFalse, + PosFlag<SetTrue, [], "No implicit typing allowed unless overridden by IMPLICIT statements">, + NegFlag<SetFalse, []>>; } + def J : JoinedOrSeparate<["-"], "J">, Flags<[RenderJoined, FlangOption, FC1Option, FlangOnlyOption]>, Group<gfortran_Group>, @@ -4555,12 +4556,11 @@ def module_suffix : Separate<["-"], "module-suffix">, Group<f_Group>, MetaVarName<"<suffix>">, HelpText<"Use <suffix> as the suffix for module files (the default value is `.mod`)">; -def fanalyzed_objects_for_unparse : Flag<["-"], - "fanalyzed-objects-for-unparse">, Group<f_Group>; -def fno_analyzed_objects_for_unparse : Flag<["-"], - "fno-analyzed-objects-for-unparse">, Group<f_Group>, - HelpText<"Do not use the analyzed objects when unparsing">; +defm analyzed_objects_for_unparse : BoolFOption<"analyzed-objects-for-unparse", EmptyKPM<"">, DefaultTrue, + PosFlag<SetTrue, [], "Use ">, + NegFlag<SetFalse, [], "Do not use ">, + BothFlags<[], "the analyzed objects when unparsing">>; } //===----------------------------------------------------------------------===//
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits