summaryrefslogtreecommitdiff
path: root/include/llvm/Support/CommandLine.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-06-10 13:44:06 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-06-10 13:44:06 +0000
commit7ab83427af0f77b59941ceba41d509d7d097b065 (patch)
treecc41c05b1db454e3d802f34df75e636ee922ad87 /include/llvm/Support/CommandLine.h
parentd288ef4c1788d3a951a7558c68312c2d320612b1 (diff)
Notes
Diffstat (limited to 'include/llvm/Support/CommandLine.h')
-rw-r--r--include/llvm/Support/CommandLine.h77
1 files changed, 46 insertions, 31 deletions
diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h
index ae32e20d6daba..771b0a8c26a98 100644
--- a/include/llvm/Support/CommandLine.h
+++ b/include/llvm/Support/CommandLine.h
@@ -21,18 +21,19 @@
#define LLVM_SUPPORT_COMMANDLINE_H
#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/iterator_range.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include <cassert>
#include <climits>
#include <cstddef>
+#include <functional>
#include <initializer_list>
#include <string>
#include <type_traits>
@@ -41,6 +42,7 @@
namespace llvm {
class StringSaver;
+class raw_ostream;
/// cl Namespace - This namespace contains all of the command line option
/// processing machinery. It is intentionally a short name to make qualified
@@ -64,12 +66,15 @@ bool ParseCommandLineOptions(int argc, const char *const *argv,
void ParseEnvironmentOptions(const char *progName, const char *envvar,
const char *Overview = "");
+// Function pointer type for printing version information.
+using VersionPrinterTy = std::function<void(raw_ostream &)>;
+
///===---------------------------------------------------------------------===//
/// SetVersionPrinter - Override the default (LLVM specific) version printer
/// used to print out the version when --version is given
/// on the command line. This allows other systems using the
/// CommandLine utilities to print their own version string.
-void SetVersionPrinter(void (*func)());
+void SetVersionPrinter(VersionPrinterTy func);
///===---------------------------------------------------------------------===//
/// AddExtraVersionPrinter - Add an extra printer to use in addition to the
@@ -78,7 +83,7 @@ void SetVersionPrinter(void (*func)());
/// which will be called after the basic LLVM version
/// printing is complete. Each can then add additional
/// information specific to the tool.
-void AddExtraVersionPrinter(void (*func)());
+void AddExtraVersionPrinter(VersionPrinterTy func);
// PrintOptionValues - Print option values.
// With -print-options print the difference between option values and defaults.
@@ -242,7 +247,7 @@ class Option {
// Out of line virtual function to provide home for the class.
virtual void anchor();
- int NumOccurrences; // The number of times specified
+ int NumOccurrences = 0; // The number of times specified
// Occurrences, HiddenFlag, and Formatting are all enum types but to avoid
// problems with signed enums in bitfields.
unsigned Occurrences : 3; // enum NumOccurrencesFlag
@@ -252,8 +257,8 @@ class Option {
unsigned HiddenFlag : 2; // enum OptionHidden
unsigned Formatting : 2; // enum FormattingFlags
unsigned Misc : 3;
- unsigned Position; // Position of last occurrence of the option
- unsigned AdditionalVals; // Greater than 0 for multi-valued option.
+ unsigned Position = 0; // Position of last occurrence of the option
+ unsigned AdditionalVals = 0; // Greater than 0 for multi-valued option.
public:
StringRef ArgStr; // The argument string itself (ex: "help", "o")
@@ -261,7 +266,7 @@ public:
StringRef ValueStr; // String describing what the value of this option is
OptionCategory *Category; // The Category this option belongs to
SmallPtrSet<SubCommand *, 4> Subs; // The subcommands this option belongs to.
- bool FullyInitialized; // Has addArguemnt been called?
+ bool FullyInitialized = false; // Has addArguemnt been called?
inline enum NumOccurrencesFlag getNumOccurrencesFlag() const {
return (enum NumOccurrencesFlag)Occurrences;
@@ -316,10 +321,8 @@ public:
protected:
explicit Option(enum NumOccurrencesFlag OccurrencesFlag,
enum OptionHidden Hidden)
- : NumOccurrences(0), Occurrences(OccurrencesFlag), Value(0),
- HiddenFlag(Hidden), Formatting(NormalFormatting), Misc(0), Position(0),
- AdditionalVals(0), Category(&GeneralCategory), FullyInitialized(false) {
- }
+ : Occurrences(OccurrencesFlag), Value(0), HiddenFlag(Hidden),
+ Formatting(NormalFormatting), Misc(0), Category(&GeneralCategory) {}
inline void setNumAdditionalVals(unsigned n) { AdditionalVals = n; }
@@ -447,8 +450,8 @@ struct GenericOptionValue {
protected:
GenericOptionValue() = default;
GenericOptionValue(const GenericOptionValue&) = default;
- ~GenericOptionValue() = default;
GenericOptionValue &operator=(const GenericOptionValue &) = default;
+ ~GenericOptionValue() = default;
private:
virtual void anchor();
@@ -461,7 +464,7 @@ template <class DataType> struct OptionValue;
template <class DataType, bool isClass>
struct OptionValueBase : public GenericOptionValue {
// Temporary storage for argument passing.
- typedef OptionValue<DataType> WrapperType;
+ using WrapperType = OptionValue<DataType>;
bool hasValue() const { return false; }
@@ -487,8 +490,8 @@ template <class DataType> class OptionValueCopy : public GenericOptionValue {
protected:
OptionValueCopy(const OptionValueCopy&) = default;
+ OptionValueCopy &operator=(const OptionValueCopy &) = default;
~OptionValueCopy() = default;
- OptionValueCopy &operator=(const OptionValueCopy&) = default;
public:
OptionValueCopy() = default;
@@ -519,13 +522,13 @@ public:
// Non-class option values.
template <class DataType>
struct OptionValueBase<DataType, false> : OptionValueCopy<DataType> {
- typedef DataType WrapperType;
+ using WrapperType = DataType;
protected:
OptionValueBase() = default;
OptionValueBase(const OptionValueBase&) = default;
+ OptionValueBase &operator=(const OptionValueBase &) = default;
~OptionValueBase() = default;
- OptionValueBase &operator=(const OptionValueBase&) = default;
};
// Top-level option class.
@@ -548,7 +551,7 @@ enum boolOrDefault { BOU_UNSET, BOU_TRUE, BOU_FALSE };
template <>
struct OptionValue<cl::boolOrDefault> final
: OptionValueCopy<cl::boolOrDefault> {
- typedef cl::boolOrDefault WrapperType;
+ using WrapperType = cl::boolOrDefault;
OptionValue() = default;
@@ -565,7 +568,7 @@ private:
template <>
struct OptionValue<std::string> final : OptionValueCopy<std::string> {
- typedef StringRef WrapperType;
+ using WrapperType = StringRef;
OptionValue() = default;
@@ -736,13 +739,15 @@ protected:
public:
OptionInfo(StringRef name, DataType v, StringRef helpStr)
: GenericOptionInfo(name, helpStr), V(v) {}
+
OptionValue<DataType> V;
};
SmallVector<OptionInfo, 8> Values;
public:
parser(Option &O) : generic_parser_base(O) {}
- typedef DataType parser_data_type;
+
+ using parser_data_type = DataType;
// Implement virtual functions needed by generic_parser_base
unsigned getNumOptions() const override { return unsigned(Values.size()); }
@@ -837,10 +842,10 @@ protected:
//
template <class DataType> class basic_parser : public basic_parser_impl {
public:
- basic_parser(Option &O) : basic_parser_impl(O) {}
+ using parser_data_type = DataType;
+ using OptVal = OptionValue<DataType>;
- typedef DataType parser_data_type;
- typedef OptionValue<DataType> OptVal;
+ basic_parser(Option &O) : basic_parser_impl(O) {}
protected:
~basic_parser() = default;
@@ -1292,6 +1297,7 @@ class opt : public Option,
enum ValueExpected getValueExpectedFlagDefault() const override {
return Parser.getValueExpectedFlagDefault();
}
+
void getExtraOptionNames(SmallVectorImpl<StringRef> &OptionNames) override {
return Parser.getExtraOptionNames(OptionNames);
}
@@ -1300,6 +1306,7 @@ class opt : public Option,
size_t getOptionWidth() const override {
return Parser.getOptionWidth(*this);
}
+
void printOptionInfo(size_t GlobalWidth) const override {
Parser.printOptionInfo(*this, GlobalWidth);
}
@@ -1384,16 +1391,18 @@ template <class DataType> class list_storage<DataType, bool> {
std::vector<DataType> Storage;
public:
- typedef typename std::vector<DataType>::iterator iterator;
+ using iterator = typename std::vector<DataType>::iterator;
iterator begin() { return Storage.begin(); }
iterator end() { return Storage.end(); }
- typedef typename std::vector<DataType>::const_iterator const_iterator;
+ using const_iterator = typename std::vector<DataType>::const_iterator;
+
const_iterator begin() const { return Storage.begin(); }
const_iterator end() const { return Storage.end(); }
- typedef typename std::vector<DataType>::size_type size_type;
+ using size_type = typename std::vector<DataType>::size_type;
+
size_type size() const { return Storage.size(); }
bool empty() const { return Storage.empty(); }
@@ -1401,8 +1410,9 @@ public:
void push_back(const DataType &value) { Storage.push_back(value); }
void push_back(DataType &&value) { Storage.push_back(value); }
- typedef typename std::vector<DataType>::reference reference;
- typedef typename std::vector<DataType>::const_reference const_reference;
+ using reference = typename std::vector<DataType>::reference;
+ using const_reference = typename std::vector<DataType>::const_reference;
+
reference operator[](size_type pos) { return Storage[pos]; }
const_reference operator[](size_type pos) const { return Storage[pos]; }
@@ -1453,6 +1463,7 @@ class list : public Option, public list_storage<DataType, StorageClass> {
enum ValueExpected getValueExpectedFlagDefault() const override {
return Parser.getValueExpectedFlagDefault();
}
+
void getExtraOptionNames(SmallVectorImpl<StringRef> &OptionNames) override {
return Parser.getExtraOptionNames(OptionNames);
}
@@ -1473,6 +1484,7 @@ class list : public Option, public list_storage<DataType, StorageClass> {
size_t getOptionWidth() const override {
return Parser.getOptionWidth(*this);
}
+
void printOptionInfo(size_t GlobalWidth) const override {
Parser.printOptionInfo(*this, GlobalWidth);
}
@@ -1592,6 +1604,7 @@ class bits : public Option, public bits_storage<DataType, Storage> {
enum ValueExpected getValueExpectedFlagDefault() const override {
return Parser.getValueExpectedFlagDefault();
}
+
void getExtraOptionNames(SmallVectorImpl<StringRef> &OptionNames) override {
return Parser.getExtraOptionNames(OptionNames);
}
@@ -1612,6 +1625,7 @@ class bits : public Option, public bits_storage<DataType, Storage> {
size_t getOptionWidth() const override {
return Parser.getOptionWidth(*this);
}
+
void printOptionInfo(size_t GlobalWidth) const override {
Parser.printOptionInfo(*this, GlobalWidth);
}
@@ -1824,9 +1838,9 @@ void TokenizeWindowsCommandLine(StringRef Source, StringSaver &Saver,
/// \brief String tokenization function type. Should be compatible with either
/// Windows or Unix command line tokenizers.
-typedef void (*TokenizerCallback)(StringRef Source, StringSaver &Saver,
- SmallVectorImpl<const char *> &NewArgv,
- bool MarkEOLs);
+using TokenizerCallback = void (*)(StringRef Source, StringSaver &Saver,
+ SmallVectorImpl<const char *> &NewArgv,
+ bool MarkEOLs);
/// \brief Expand response files on a command line recursively using the given
/// StringSaver and tokenization strategy. Argv should contain the command line
@@ -1880,6 +1894,7 @@ void ResetAllOptionOccurrences();
void ResetCommandLineParser();
} // end namespace cl
+
} // end namespace llvm
#endif // LLVM_SUPPORT_COMMANDLINE_H