summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2009-01-16 22:54:19 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2009-01-16 22:54:19 +0000
commit7059d47a6e1a378232dce3e47b51434dec0ea608 (patch)
tree85bc2cbde9cdf86e45d9b58c9921c5049e774514 /include
parent01bbc3e3346e58be4924363b3127ea4254919dbb (diff)
downloadllvm-7059d47a6e1a378232dce3e47b51434dec0ea608.tar.gz
llvm-7059d47a6e1a378232dce3e47b51434dec0ea608.tar.bz2
llvm-7059d47a6e1a378232dce3e47b51434dec0ea608.tar.xz
Support for multi-valued options in CommandLine
Makes possible to specify options that take multiple arguments (a-la -sectalign on Darwin). See documentation for details. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62372 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Support/CommandLine.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h
index b7de038f50..e7f5a02b77 100644
--- a/include/llvm/Support/CommandLine.h
+++ b/include/llvm/Support/CommandLine.h
@@ -155,6 +155,7 @@ class Option {
int NumOccurrences; // The number of times specified
int Flags; // Flags for the argument
unsigned Position; // Position of last occurrence of the option
+ unsigned AdditionalVals;// Greater than 0 for multi-valued option.
Option *NextRegistered; // Singly linked list of registered options.
public:
const char *ArgStr; // The argument string itself (ex: "help", "o")
@@ -179,6 +180,7 @@ public:
return Flags & MiscMask;
}
inline unsigned getPosition() const { return Position; }
+ inline unsigned getNumAdditionalVals() const { return AdditionalVals; }
// hasArgStr - Return true if the argstr != ""
bool hasArgStr() const { return ArgStr[0] != 0; }
@@ -206,11 +208,14 @@ public:
protected:
explicit Option(unsigned DefaultFlags)
: NumOccurrences(0), Flags(DefaultFlags | NormalFormatting), Position(0),
- NextRegistered(0), ArgStr(""), HelpStr(""), ValueStr("") {
+ AdditionalVals(0), NextRegistered(0),
+ ArgStr(""), HelpStr(""), ValueStr("") {
assert(getNumOccurrencesFlag() != 0 &&
getOptionHiddenFlag() != 0 && "Not all default flags specified!");
}
+ inline void setNumAdditionalVals(unsigned n)
+ { AdditionalVals = n; }
public:
// addArgument - Register this argument with the commandline system.
//
@@ -231,7 +236,7 @@ public:
// addOccurrence - Wrapper around handleOccurrence that enforces Flags
//
bool addOccurrence(unsigned pos, const char *ArgName,
- const std::string &Value);
+ const std::string &Value, bool MultiArg = false);
// Prints option name followed by message. Always returns true.
bool error(std::string Message, const char *ArgName = 0);
@@ -1000,6 +1005,10 @@ public:
return Positions[optnum];
}
+ void setNumAdditionalVals(unsigned n) {
+ Option::setNumAdditionalVals(n);
+ }
+
// One option...
template<class M0t>
explicit list(const M0t &M0) : Option(ZeroOrMore | NotHidden) {
@@ -1065,6 +1074,16 @@ public:
}
};
+// multi_arg - Modifier to set the number of additional values.
+struct multi_val {
+ unsigned AdditionalVals;
+ explicit multi_val(unsigned N) : AdditionalVals(N) {}
+
+ template <typename D, typename S, typename P>
+ void apply(list<D, S, P> &L) const { L.setNumAdditionalVals(AdditionalVals); }
+};
+
+
//===----------------------------------------------------------------------===//
// bits_storage class