summaryrefslogtreecommitdiff
path: root/include/llvm/Option
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Option')
-rw-r--r--include/llvm/Option/Arg.h15
-rw-r--r--include/llvm/Option/ArgList.h52
-rw-r--r--include/llvm/Option/OptSpecifier.h40
-rw-r--r--include/llvm/Option/OptTable.h19
-rw-r--r--include/llvm/Option/Option.h15
5 files changed, 87 insertions, 54 deletions
diff --git a/include/llvm/Option/Arg.h b/include/llvm/Option/Arg.h
index 99d329693de2e..c519a4a824c51 100644
--- a/include/llvm/Option/Arg.h
+++ b/include/llvm/Option/Arg.h
@@ -1,4 +1,4 @@
-//===--- Arg.h - Parsed Argument Classes ------------------------*- C++ -*-===//
+//===- Arg.h - Parsed Argument Classes --------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -21,7 +21,11 @@
#include <string>
namespace llvm {
+
+class raw_ostream;
+
namespace opt {
+
class ArgList;
/// \brief A concrete instance of a particular driver option.
@@ -29,9 +33,6 @@ class ArgList;
/// The Arg class encodes just enough information to be able to
/// derive the argument values efficiently.
class Arg {
- Arg(const Arg &) = delete;
- void operator=(const Arg &) = delete;
-
private:
/// \brief The option this argument is an instance of.
const Option Opt;
@@ -65,6 +66,8 @@ public:
const char *Value0, const Arg *BaseArg = nullptr);
Arg(const Option Opt, StringRef Spelling, unsigned Index,
const char *Value0, const char *Value1, const Arg *BaseArg = nullptr);
+ Arg(const Arg &) = delete;
+ Arg &operator=(const Arg &) = delete;
~Arg();
const Option &getOption() const { return Opt; }
@@ -89,6 +92,7 @@ public:
void claim() const { getBaseArg().Claimed = true; }
unsigned getNumValues() const { return Values.size(); }
+
const char *getValue(unsigned N = 0) const {
return Values[N];
}
@@ -122,6 +126,7 @@ public:
};
} // end namespace opt
+
} // end namespace llvm
-#endif
+#endif // LLVM_OPTION_ARG_H
diff --git a/include/llvm/Option/ArgList.h b/include/llvm/Option/ArgList.h
index 6a92dd01e911b..aaea68bf8e278 100644
--- a/include/llvm/Option/ArgList.h
+++ b/include/llvm/Option/ArgList.h
@@ -1,4 +1,4 @@
-//===--- ArgList.h - Argument List Management -------------------*- C++ -*-===//
+//===- ArgList.h - Argument List Management ---------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,7 +10,9 @@
#ifndef LLVM_OPTION_ARGLIST_H
#define LLVM_OPTION_ARGLIST_H
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
@@ -18,15 +20,21 @@
#include "llvm/Option/Arg.h"
#include "llvm/Option/OptSpecifier.h"
#include "llvm/Option/Option.h"
+#include <algorithm>
+#include <cstddef>
+#include <initializer_list>
+#include <iterator>
#include <list>
#include <memory>
#include <string>
+#include <utility>
#include <vector>
namespace llvm {
+
+class raw_ostream;
+
namespace opt {
-class ArgList;
-class Option;
/// arg_iterator - Iterates through arguments stored inside an ArgList.
template<typename BaseIter, unsigned NumOptSpecifiers = 0>
@@ -59,14 +67,14 @@ class arg_iterator {
}
}
- typedef std::iterator_traits<BaseIter> Traits;
+ using Traits = std::iterator_traits<BaseIter>;
public:
- typedef typename Traits::value_type value_type;
- typedef typename Traits::reference reference;
- typedef typename Traits::pointer pointer;
- typedef std::forward_iterator_tag iterator_category;
- typedef std::ptrdiff_t difference_type;
+ using value_type = typename Traits::value_type;
+ using reference = typename Traits::reference;
+ using pointer = typename Traits::pointer;
+ using iterator_category = std::forward_iterator_tag;
+ using difference_type = std::ptrdiff_t;
arg_iterator(
BaseIter Current, BaseIter End,
@@ -111,12 +119,12 @@ public:
/// and to iterate over groups of arguments.
class ArgList {
public:
- typedef SmallVector<Arg*, 16> arglist_type;
- typedef arg_iterator<arglist_type::iterator> iterator;
- typedef arg_iterator<arglist_type::const_iterator> const_iterator;
- typedef arg_iterator<arglist_type::reverse_iterator> reverse_iterator;
- typedef arg_iterator<arglist_type::const_reverse_iterator>
- const_reverse_iterator;
+ using arglist_type = SmallVector<Arg *, 16>;
+ using iterator = arg_iterator<arglist_type::iterator>;
+ using const_iterator = arg_iterator<arglist_type::const_iterator>;
+ using reverse_iterator = arg_iterator<arglist_type::reverse_iterator>;
+ using const_reverse_iterator =
+ arg_iterator<arglist_type::const_reverse_iterator>;
template<unsigned N> using filtered_iterator =
arg_iterator<arglist_type::const_iterator, N>;
@@ -127,7 +135,7 @@ private:
/// The internal list of arguments.
arglist_type Args;
- typedef std::pair<unsigned, unsigned> OptRange;
+ using OptRange = std::pair<unsigned, unsigned>;
static OptRange emptyRange() { return {-1u, 0u}; }
/// The first and last index of each different OptSpecifier ID.
@@ -142,6 +150,7 @@ protected:
// derived objects, but can still be used by derived objects to implement
// their own special members.
ArgList() = default;
+
// Explicit move operations to ensure the container is cleared post-move
// otherwise it could lead to a double-delete in the case of moving of an
// InputArgList which deletes the contents of the container. If we could fix
@@ -152,6 +161,7 @@ protected:
RHS.Args.clear();
RHS.OptRanges.clear();
}
+
ArgList &operator=(ArgList &&RHS) {
Args = std::move(RHS.Args);
RHS.Args.clear();
@@ -159,6 +169,7 @@ protected:
RHS.OptRanges.clear();
return *this;
}
+
// Protect the dtor to ensure this type is never destroyed polymorphically.
~ArgList() = default;
@@ -380,10 +391,12 @@ private:
public:
InputArgList(const char* const *ArgBegin, const char* const *ArgEnd);
+
InputArgList(InputArgList &&RHS)
: ArgList(std::move(RHS)), ArgStrings(std::move(RHS.ArgStrings)),
SynthesizedStrings(std::move(RHS.SynthesizedStrings)),
NumInputArgStrings(RHS.NumInputArgStrings) {}
+
InputArgList &operator=(InputArgList &&RHS) {
releaseMemory();
ArgList::operator=(std::move(RHS));
@@ -392,6 +405,7 @@ public:
NumInputArgStrings = RHS.NumInputArgStrings;
return *this;
}
+
~InputArgList() { releaseMemory(); }
const char *getArgString(unsigned Index) const override {
@@ -464,7 +478,6 @@ public:
append(MakePositionalArg(BaseArg, Opt, Value));
}
-
/// AddSeparateArg - Construct a new Positional arg for the given option
/// \p Id, with the provided \p Value and append it to the argument
/// list.
@@ -473,7 +486,6 @@ public:
append(MakeSeparateArg(BaseArg, Opt, Value));
}
-
/// AddJoinedArg - Construct a new Positional arg for the given option
/// \p Id, with the provided \p Value and append it to the argument list.
void AddJoinedArg(const Arg *BaseArg, const Option Opt,
@@ -481,7 +493,6 @@ public:
append(MakeJoinedArg(BaseArg, Opt, Value));
}
-
/// MakeFlagArg - Construct a new FlagArg for the given option \p Id.
Arg *MakeFlagArg(const Arg *BaseArg, const Option Opt) const;
@@ -504,6 +515,7 @@ public:
};
} // end namespace opt
+
} // end namespace llvm
-#endif
+#endif // LLVM_OPTION_ARGLIST_H
diff --git a/include/llvm/Option/OptSpecifier.h b/include/llvm/Option/OptSpecifier.h
index 0b2aaaec3afc8..84c3cf8ad534d 100644
--- a/include/llvm/Option/OptSpecifier.h
+++ b/include/llvm/Option/OptSpecifier.h
@@ -1,4 +1,4 @@
-//===--- OptSpecifier.h - Option Specifiers ---------------------*- C++ -*-===//
+//===- OptSpecifier.h - Option Specifiers -----------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,32 +10,30 @@
#ifndef LLVM_OPTION_OPTSPECIFIER_H
#define LLVM_OPTION_OPTSPECIFIER_H
-#include "llvm/Support/Compiler.h"
-
namespace llvm {
namespace opt {
- class Option;
- /// OptSpecifier - Wrapper class for abstracting references to option IDs.
- class OptSpecifier {
- unsigned ID;
+class Option;
+
+/// OptSpecifier - Wrapper class for abstracting references to option IDs.
+class OptSpecifier {
+ unsigned ID = 0;
- private:
- explicit OptSpecifier(bool) = delete;
+public:
+ OptSpecifier() = default;
+ explicit OptSpecifier(bool) = delete;
+ /*implicit*/ OptSpecifier(unsigned ID) : ID(ID) {}
+ /*implicit*/ OptSpecifier(const Option *Opt);
- public:
- OptSpecifier() : ID(0) {}
- /*implicit*/ OptSpecifier(unsigned ID) : ID(ID) {}
- /*implicit*/ OptSpecifier(const Option *Opt);
+ bool isValid() const { return ID != 0; }
- bool isValid() const { return ID != 0; }
+ unsigned getID() const { return ID; }
- unsigned getID() const { return ID; }
+ bool operator==(OptSpecifier Opt) const { return ID == Opt.getID(); }
+ bool operator!=(OptSpecifier Opt) const { return !(*this == Opt); }
+};
- bool operator==(OptSpecifier Opt) const { return ID == Opt.getID(); }
- bool operator!=(OptSpecifier Opt) const { return !(*this == Opt); }
- };
-}
-}
+} // end namespace opt
+} // end namespace llvm
-#endif
+#endif // LLVM_OPTION_OPTSPECIFIER_H
diff --git a/include/llvm/Option/OptTable.h b/include/llvm/Option/OptTable.h
index 8a323a255ca1b..e0169b927319f 100644
--- a/include/llvm/Option/OptTable.h
+++ b/include/llvm/Option/OptTable.h
@@ -1,4 +1,4 @@
-//===--- OptTable.h - Option Table ------------------------------*- C++ -*-===//
+//===- OptTable.h - Option Table --------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -11,12 +11,19 @@
#define LLVM_OPTION_OPTTABLE_H
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Option/OptSpecifier.h"
+#include <cassert>
+#include <string>
+#include <vector>
namespace llvm {
+
class raw_ostream;
+
namespace opt {
+
class Arg;
class ArgList;
class InputArgList;
@@ -53,12 +60,12 @@ private:
ArrayRef<Info> OptionInfos;
bool IgnoreCase;
- unsigned TheInputOptionID;
- unsigned TheUnknownOptionID;
+ unsigned TheInputOptionID = 0;
+ unsigned TheUnknownOptionID = 0;
/// The index of the first option which can be parsed (i.e., is not a
/// special option like 'input' or 'unknown', and is not an option group).
- unsigned FirstSearchableIndex;
+ unsigned FirstSearchableIndex = 0;
/// The union of all option prefixes. If an argument does not begin with
/// one of these, it is an input.
@@ -176,7 +183,9 @@ public:
void PrintHelp(raw_ostream &OS, const char *Name,
const char *Title, bool ShowHidden = false) const;
};
+
} // end namespace opt
+
} // end namespace llvm
-#endif
+#endif // LLVM_OPTION_OPTTABLE_H
diff --git a/include/llvm/Option/Option.h b/include/llvm/Option/Option.h
index 139f281b3c4ce..c08834f90598a 100644
--- a/include/llvm/Option/Option.h
+++ b/include/llvm/Option/Option.h
@@ -1,4 +1,4 @@
-//===--- Option.h - Abstract Driver Options ---------------------*- C++ -*-===//
+//===- Option.h - Abstract Driver Options -----------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -12,15 +12,23 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Option/OptSpecifier.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Support/ErrorHandling.h"
+#include <cassert>
+#include <string>
namespace llvm {
+
+class raw_ostream;
+
namespace opt {
+
class Arg;
class ArgList;
+
/// ArgStringList - Type used for constructing argv lists for subprocesses.
-typedef SmallVector<const char*, 16> ArgStringList;
+using ArgStringList = SmallVector<const char *, 16>;
/// Base flags for all options. Custom flags may be added after.
enum DriverFlag {
@@ -202,6 +210,7 @@ public:
};
} // end namespace opt
+
} // end namespace llvm
-#endif
+#endif // LLVM_OPTION_OPTION_H