1 //===--- OptTable.h - Option Table ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_DRIVER_OPTTABLE_H
11 #define CLANG_DRIVER_OPTTABLE_H
13 #include "clang/Basic/LLVM.h"
14 #include "clang/Driver/OptSpecifier.h"
20 DriverOption = (1 << 0),
21 HelpHidden = (1 << 1),
22 LinkerInput = (1 << 2),
23 NoArgumentUnused = (1 << 3),
25 RenderAsInput = (1 << 5),
26 RenderJoined = (1 << 6),
27 RenderSeparate = (1 << 7),
28 Unsupported = (1 << 8)
37 /// OptTable - Provide access to the Option info table.
39 /// The OptTable class provides a layer of indirection which allows Option
40 /// instance to be created lazily. In the common case, only a few options will
41 /// be needed at runtime; the OptTable class maintains enough information to
42 /// parse command lines without instantiating Options, while letting other
43 /// parts of the driver still use Option instances where convenient.
46 /// Info - Entry for a single option instance in the option data table.
54 unsigned short GroupID;
55 unsigned short AliasID;
59 /// The static option information table.
60 const Info *OptionInfos;
61 unsigned NumOptionInfos;
63 /// The lazily constructed options table, indexed by option::ID - 1.
64 mutable Option **Options;
66 /// Prebound input option instance.
67 const Option *TheInputOption;
69 /// Prebound unknown option instance.
70 const Option *TheUnknownOption;
72 /// The index of the first option which can be parsed (i.e., is not a
73 /// special option like 'input' or 'unknown', and is not an option group).
74 unsigned FirstSearchableIndex;
77 const Info &getInfo(OptSpecifier Opt) const {
78 unsigned id = Opt.getID();
79 assert(id > 0 && id - 1 < getNumOptions() && "Invalid Option ID.");
80 return OptionInfos[id - 1];
83 Option *CreateOption(unsigned id) const;
86 OptTable(const Info *_OptionInfos, unsigned _NumOptionInfos);
90 /// getNumOptions - Return the total number of option classes.
91 unsigned getNumOptions() const { return NumOptionInfos; }
93 /// getOption - Get the given \arg id's Option instance, lazily creating it
96 /// \return The option, or null for the INVALID option id.
97 const Option *getOption(OptSpecifier Opt) const {
98 unsigned id = Opt.getID();
102 assert((unsigned) (id - 1) < getNumOptions() && "Invalid ID.");
103 Option *&Entry = Options[id - 1];
105 Entry = CreateOption(id);
109 /// getOptionName - Lookup the name of the given option.
110 const char *getOptionName(OptSpecifier id) const {
111 return getInfo(id).Name;
114 /// getOptionKind - Get the kind of the given option.
115 unsigned getOptionKind(OptSpecifier id) const {
116 return getInfo(id).Kind;
119 /// getOptionGroupID - Get the group id for the given option.
120 unsigned getOptionGroupID(OptSpecifier id) const {
121 return getInfo(id).GroupID;
124 /// isOptionHelpHidden - Should the help for the given option be hidden by
126 bool isOptionHelpHidden(OptSpecifier id) const {
127 return getInfo(id).Flags & options::HelpHidden;
130 /// getOptionHelpText - Get the help text to use to describe this option.
131 const char *getOptionHelpText(OptSpecifier id) const {
132 return getInfo(id).HelpText;
135 /// getOptionMetaVar - Get the meta-variable name to use when describing
136 /// this options values in the help text.
137 const char *getOptionMetaVar(OptSpecifier id) const {
138 return getInfo(id).MetaVar;
141 /// ParseOneArg - Parse a single argument; returning the new argument and
144 /// \param [in] [out] Index - The current parsing position in the argument
145 /// string list; on return this will be the index of the next argument
148 /// \return - The parsed argument, or 0 if the argument is missing values
149 /// (in which case Index still points at the conceptual next argument string
151 Arg *ParseOneArg(const ArgList &Args, unsigned &Index) const;
153 /// ParseArgs - Parse an list of arguments into an InputArgList.
155 /// The resulting InputArgList will reference the strings in [ArgBegin,
156 /// ArgEnd), and their lifetime should extend past that of the returned
159 /// The only error that can occur in this routine is if an argument is
160 /// missing values; in this case \arg MissingArgCount will be non-zero.
162 /// \param ArgBegin - The beginning of the argument vector.
163 /// \param ArgEnd - The end of the argument vector.
164 /// \param MissingArgIndex - On error, the index of the option which could
166 /// \param MissingArgCount - On error, the number of missing options.
167 /// \return - An InputArgList; on error this will contain all the options
168 /// which could be parsed.
169 InputArgList *ParseArgs(const char* const *ArgBegin,
170 const char* const *ArgEnd,
171 unsigned &MissingArgIndex,
172 unsigned &MissingArgCount) const;
174 /// PrintHelp - Render the help text for an option table.
176 /// \param OS - The stream to write the help text to.
177 /// \param Name - The name to use in the usage line.
178 /// \param Title - The title to use in the usage line.
179 /// \param ShowHidden - Whether help-hidden arguments should be shown.
180 void PrintHelp(raw_ostream &OS, const char *Name,
181 const char *Title, bool ShowHidden = false) const;