diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-06-13 19:31:46 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2021-06-13 19:37:19 +0000 |
commit | e8d8bef961a50d4dc22501cde4fb9fb0be1b2532 (patch) | |
tree | 94f04805f47bb7c59ae29690d8952b6074fff602 /contrib/llvm-project/llvm/lib/Support/CommandLine.cpp | |
parent | bb130ff39747b94592cb26d71b7cb097b9a4ea6b (diff) | |
parent | b60736ec1405bb0a8dd40989f67ef4c93da068ab (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/CommandLine.cpp | 70 |
1 files changed, 26 insertions, 44 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/CommandLine.cpp b/contrib/llvm-project/llvm/lib/Support/CommandLine.cpp index 12ef0d511b14..6d89481bf28a 100644 --- a/contrib/llvm-project/llvm/lib/Support/CommandLine.cpp +++ b/contrib/llvm-project/llvm/lib/Support/CommandLine.cpp @@ -464,7 +464,7 @@ void Option::addCategory(OptionCategory &C) { // must be explicitly added if you want multiple categories that include it. if (&C != &GeneralCategory && Categories[0] == &GeneralCategory) Categories[0] = &C; - else if (find(Categories, &C) == Categories.end()) + else if (!is_contained(Categories, &C)) Categories.push_back(&C); } @@ -531,11 +531,7 @@ Option *CommandLineParser::LookupOption(SubCommand &Sub, StringRef &Arg, // If we have an equals sign, remember the value. if (EqualPos == StringRef::npos) { // Look up the option. - auto I = Sub.OptionsMap.find(Arg); - if (I == Sub.OptionsMap.end()) - return nullptr; - - return I != Sub.OptionsMap.end() ? I->second : nullptr; + return Sub.OptionsMap.lookup(Arg); } // If the argument before the = is a valid option name and the option allows @@ -832,7 +828,7 @@ void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver, // Consume runs of whitespace. if (Token.empty()) { while (I != E && isWhitespace(Src[I])) { - // Mark the end of lines in response files + // Mark the end of lines in response files. if (MarkEOLs && Src[I] == '\n') NewArgv.push_back(nullptr); ++I; @@ -869,6 +865,9 @@ void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver, if (isWhitespace(C)) { if (!Token.empty()) NewArgv.push_back(Saver.save(StringRef(Token)).data()); + // Mark the end of lines in response files. + if (MarkEOLs && C == '\n') + NewArgv.push_back(nullptr); Token.clear(); continue; } @@ -880,9 +879,6 @@ void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver, // Append the last token after hitting EOF with no whitespace. if (!Token.empty()) NewArgv.push_back(Saver.save(StringRef(Token)).data()); - // Mark the end of response files - if (MarkEOLs) - NewArgv.push_back(nullptr); } /// Backslashes are interpreted in a rather complicated way in the Windows-style @@ -956,11 +952,11 @@ tokenizeWindowsCommandLineImpl(StringRef Src, StringSaver &Saver, ++I; StringRef NormalChars = Src.slice(Start, I); if (I >= E || isWhitespaceOrNull(Src[I])) { - if (I < E && Src[I] == '\n') - MarkEOL(); // No special characters: slice out the substring and start the next // token. Copy the string if the caller asks us to. AddToken(AlwaysCopy ? Saver.save(NormalChars) : NormalChars); + if (I < E && Src[I] == '\n') + MarkEOL(); } else if (Src[I] == '\"') { Token += NormalChars; State = QUOTED; @@ -1208,7 +1204,7 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, }; // Check for recursive response files. - if (std::any_of(FileStack.begin() + 1, FileStack.end(), IsEquivalent)) { + if (any_of(drop_begin(FileStack), IsEquivalent)) { // This file is recursive, so we leave it in the argument stream and // move on. AllExpanded = false; @@ -1251,6 +1247,22 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, return AllExpanded; } +bool cl::expandResponseFiles(int Argc, const char *const *Argv, + const char *EnvVar, StringSaver &Saver, + SmallVectorImpl<const char *> &NewArgv) { + auto Tokenize = Triple(sys::getProcessTriple()).isOSWindows() + ? cl::TokenizeWindowsCommandLine + : cl::TokenizeGNUCommandLine; + // The environment variable specifies initial options. + if (EnvVar) + if (llvm::Optional<std::string> EnvValue = sys::Process::GetEnv(EnvVar)) + Tokenize(*EnvValue, Saver, NewArgv, /*MarkEOLs=*/false); + + // Command line options can override the environment variable. + NewArgv.append(Argv + 1, Argv + Argc); + return ExpandResponseFiles(Saver, Tokenize, NewArgv); +} + bool cl::readConfigFile(StringRef CfgFile, StringSaver &Saver, SmallVectorImpl<const char *> &Argv) { SmallString<128> AbsPath; @@ -1271,36 +1283,6 @@ bool cl::readConfigFile(StringRef CfgFile, StringSaver &Saver, /*MarkEOLs*/ false, /*RelativeNames*/ true); } -/// ParseEnvironmentOptions - An alternative entry point to the -/// CommandLine library, which allows you to read the program's name -/// from the caller (as PROGNAME) and its command-line arguments from -/// an environment variable (whose name is given in ENVVAR). -/// -void cl::ParseEnvironmentOptions(const char *progName, const char *envVar, - const char *Overview) { - // Check args. - assert(progName && "Program name not specified"); - assert(envVar && "Environment variable name missing"); - - // Get the environment variable they want us to parse options out of. - llvm::Optional<std::string> envValue = sys::Process::GetEnv(StringRef(envVar)); - if (!envValue) - return; - - // Get program's "name", which we wouldn't know without the caller - // telling us. - SmallVector<const char *, 20> newArgv; - BumpPtrAllocator A; - StringSaver Saver(A); - newArgv.push_back(Saver.save(progName).data()); - - // Parse the value of the environment variable into a "command line" - // and hand it off to ParseCommandLineOptions(). - TokenizeGNUCommandLine(*envValue, Saver, newArgv); - int newArgc = static_cast<int>(newArgv.size()); - ParseCommandLineOptions(newArgc, &newArgv[0], StringRef(Overview)); -} - bool cl::ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview, raw_ostream *Errs, const char *EnvVar, @@ -2604,7 +2586,7 @@ void cl::HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *> Categories, SubCommand &Sub) { for (auto &I : Sub.OptionsMap) { for (auto &Cat : I.second->Categories) { - if (find(Categories, Cat) == Categories.end() && Cat != &GenericCategory) + if (!is_contained(Categories, Cat) && Cat != &GenericCategory) I.second->setHiddenFlag(cl::ReallyHidden); } } |