llvm.org GIT mirror llvm / 1ee21dc
Merge changes to clang's Driver code into LLVM's Option library This is in preparation for switching the clang driver over to using LLVM's Option library. Richard Smith introduced most of these changes to the clang driver in r167638. Reviewers: espindola on IRC Differential Revision: http://llvm-reviews.chandlerc.com/D970 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183925 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 7 years ago
4 changed file(s) with 45 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
221221 /// negation are present, the last one wins.
222222 bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default=true) const;
223223
224 /// hasFlag - Given an option \p Pos, an alias \p PosAlias and its negative
225 /// form \p Neg, return true if the option or its alias is present, false if
226 /// the negation is present, and \p Default if none of the options are
227 /// given. If multiple options are present, the last one wins.
228 bool hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,
229 bool Default = true) const;
230
224231 /// AddLastArg - Render only the last argument match \p Id0, if present.
225232 void AddLastArg(ArgStringList &Output, OptSpecifier Id0) const;
233 void AddLastArg(ArgStringList &Output, OptSpecifier Id0,
234 OptSpecifier Id1) const;
226235
227236 /// AddAllArgs - Render all arguments matching the given ids.
228237 void AddAllArgs(ArgStringList &Output, OptSpecifier Id0,
9898 return getInfo(id).GroupID;
9999 }
100100
101 /// \brief Should the help for the given option be hidden by default.
102 bool isOptionHelpHidden(OptSpecifier id) const;
103
104101 /// \brief Get the help text to use to describe this option.
105102 const char *getOptionHelpText(OptSpecifier id) const {
106103 return getInfo(id).HelpText;
150147 /// \param OS - The stream to write the help text to.
151148 /// \param Name - The name to use in the usage line.
152149 /// \param Title - The title to use in the usage line.
153 /// \param ShowHidden - Whether help-hidden arguments should be shown.
150 /// \param FlagsToInclude - If non-zero, only include options with any
151 /// of these flags set.
152 /// \param FlagsToExclude - Exclude options with any of these flags set.
153 void PrintHelp(raw_ostream &OS, const char *Name,
154 const char *Title, unsigned FlagsToInclude,
155 unsigned FlagsToExclude) const;
156
154157 void PrintHelp(raw_ostream &OS, const char *Name,
155158 const char *Title, bool ShowHidden = false) const;
156159 };
205205 return Default;
206206 }
207207
208 bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,
209 bool Default) const {
210 if (Arg *A = getLastArg(Pos, PosAlias, Neg))
211 return A->getOption().matches(Pos) || A->getOption().matches(PosAlias);
212 return Default;
213 }
214
208215 StringRef ArgList::getLastArgValue(OptSpecifier Id,
209216 StringRef Default) const {
210217 if (Arg *A = getLastArg(Id))
220227
221228 void ArgList::AddLastArg(ArgStringList &Output, OptSpecifier Id) const {
222229 if (Arg *A = getLastArg(Id)) {
230 A->claim();
231 A->render(*this, Output);
232 }
233 }
234
235 void ArgList::AddLastArg(ArgStringList &Output, OptSpecifier Id0,
236 OptSpecifier Id1) const {
237 if (Arg *A = getLastArg(Id0, Id1)) {
223238 A->claim();
224239 A->render(*this, Output);
225240 }
157157 return Option(0, 0);
158158 assert((unsigned) (id - 1) < getNumOptions() && "Invalid ID.");
159159 return Option(&getInfo(id), this);
160 }
161
162 bool OptTable::isOptionHelpHidden(OptSpecifier id) const {
163 return getInfo(id).Flags & HelpHidden;
164160 }
165161
166162 static bool isInput(const llvm::StringSet<> &Prefixes, StringRef Arg) {
345341 return getOptionHelpGroup(Opts, GroupID);
346342 }
347343
348 void OptTable::PrintHelp(raw_ostream &OS, const char *Name,
349 const char *Title, bool ShowHidden) const {
344 void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
345 bool ShowHidden) const {
346 PrintHelp(OS, Name, Title, /*Include*/ 0, /*Exclude*/
347 (ShowHidden ? 0 : HelpHidden));
348 }
349
350
351 void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
352 unsigned FlagsToInclude,
353 unsigned FlagsToExclude) const {
350354 OS << "OVERVIEW: " << Title << "\n";
351355 OS << '\n';
352356 OS << "USAGE: " << Name << " [options] \n";
365369 if (getOptionKind(Id) == Option::GroupClass)
366370 continue;
367371
368 if (!ShowHidden && isOptionHelpHidden(Id))
372 unsigned Flags = getInfo(Id).Flags;
373 if (FlagsToInclude && !(Flags & FlagsToInclude))
374 continue;
375 if (Flags & FlagsToExclude)
369376 continue;
370377
371378 if (const char *Text = getOptionHelpText(Id)) {