diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2021-01-13 12:50:19 +0100 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2021-01-15 08:42:59 +0100 |
commit | b6575bfd0eeb5a364dd2e4f4a2e461679da1f8a9 (patch) | |
tree | 0766754e3883676bcf614c4eab1cc6c58fa77129 /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | 1a49944b59dbbfd62bd860b564919087f274a5bf (diff) | |
download | llvm-b6575bfd0eeb5a364dd2e4f4a2e461679da1f8a9.zip llvm-b6575bfd0eeb5a364dd2e4f4a2e461679da1f8a9.tar.gz llvm-b6575bfd0eeb5a364dd2e4f4a2e461679da1f8a9.tar.bz2 |
[clang][cli] Specify KeyPath prefixes via TableGen classes
It turns out we need to handle `LangOptions` separately from the rest of the options. `LangOptions` used to be conditionally parsed only when `!(DashX.getFormat() == InputKind::Precompiled || DashX.getLanguage() == Language::LLVM_IR)` and we need to restore this order (for more info, see D94682).
We could do this similarly to how `DiagnosticOptions` are handled: via a counterpart to the `IsDiag` mix-in (e.g. `IsLang`). These mix-ins would prefix the option key path with the appropriate `CompilerInvocation::XxxOpts` member. However, this solution would be problematic, as we'd now have two kinds of options (`Lang` and `Diag`) with seemingly incomplete key paths in the same file. To understand what `CompilerInvocation` member an option affects, one would need to read the whole option definition and notice the `IsDiag` or `IsLang` class.
Instead, this patch introduces more robust way to handle different kinds of options separately: via the `KeyPathAndMacroPrefix` class. We have one specialization of that class per `CompilerInvocation` member (e.g. `LangOpts`, `DiagnosticOpts`, etc.). Now, instead of specifying a key path with `"LangOpts->UndefPrefixes"`, we use `LangOpts<"UndefPrefixes">`. This keeps the readability intact (you don't have to look for the `IsLang` mix-in, the key path is complete on its own) and allows us to specify a custom macro prefix within `LangOpts`.
Reviewed By: Bigcheese
Differential Revision: https://reviews.llvm.org/D94676
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 6d5b4a8..37d7f6f 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1404,6 +1404,9 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, Diags = &*IgnoringDiags; } + // The key paths of diagnostic options defined in Options.td start with + // "DiagnosticOpts->". Let's provide the expected variable name and type. + DiagnosticOptions *DiagnosticOpts = &Opts; bool Success = true; #define DIAG_OPTION_WITH_MARSHALLING( \ @@ -1412,7 +1415,7 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, \ MERGER, EXTRACTOR, TABLE_INDEX) \ PARSE_OPTION_WITH_MARSHALLING(Args, *Diags, Success, ID, FLAGS, PARAM, \ - SHOULD_PARSE, Opts.KEYPATH, DEFAULT_VALUE, \ + SHOULD_PARSE, KEYPATH, DEFAULT_VALUE, \ IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \ MERGER, TABLE_INDEX) #include "clang/Driver/Options.inc" @@ -3153,15 +3156,7 @@ void CompilerInvocation::generateCC1CommandLine( IMPLIED_CHECK, IMPLIED_VALUE, DENORMALIZER, \ EXTRACTOR, TABLE_INDEX) -#define DIAG_OPTION_WITH_MARSHALLING( \ - PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, \ - DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, \ - MERGER, EXTRACTOR, TABLE_INDEX) \ - GENERATE_OPTION_WITH_MARSHALLING( \ - Args, SA, KIND, FLAGS, SPELLING, ALWAYS_EMIT, \ - this->DiagnosticOpts->KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, \ - IMPLIED_VALUE, DENORMALIZER, EXTRACTOR, TABLE_INDEX) +#define DIAG_OPTION_WITH_MARSHALLING OPTION_WITH_MARSHALLING #include "clang/Driver/Options.inc" |