mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-24 08:18:33 +00:00
Modify ParseArgs to return the InputArgList by value - there's no need for dynamic allocation/ownership here
The one caller that does anything other than keep this variable on the stack is the single use of DerivedArgList in Clang, which is a bit more interesting but can probably be cleaned up/simplified a bit further (have DerivedArgList take ownership of the InputArgList rather than needing to reference its Args indirectly) which I'll try to after this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240345 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -92,10 +92,6 @@ public:
|
||||
/// check for the presence of Arg instances for a particular Option
|
||||
/// and to iterate over groups of arguments.
|
||||
class ArgList {
|
||||
private:
|
||||
ArgList(const ArgList &) = delete;
|
||||
void operator=(const ArgList &) = delete;
|
||||
|
||||
public:
|
||||
typedef SmallVector<Arg*, 16> arglist_type;
|
||||
typedef arglist_type::iterator iterator;
|
||||
@@ -108,9 +104,21 @@ private:
|
||||
arglist_type Args;
|
||||
|
||||
protected:
|
||||
// Default ctor provided explicitly as it is not provided implicitly due to
|
||||
// the presence of the (deleted) copy ctor above.
|
||||
// Make the default special members protected so they won't be used to slice
|
||||
// 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
|
||||
// up the ownership here (delegate storage/ownership to the derived class so
|
||||
// it can be a container of unique_ptr) this would be simpler.
|
||||
ArgList(ArgList &&RHS) : Args(std::move(RHS.Args)) { RHS.Args.clear(); }
|
||||
ArgList &operator=(ArgList &&RHS) {
|
||||
Args = std::move(RHS.Args);
|
||||
RHS.Args.clear();
|
||||
return *this;
|
||||
}
|
||||
// Protect the dtor to ensure this type is never destroyed polymorphically.
|
||||
~ArgList() = default;
|
||||
|
||||
@@ -319,6 +327,19 @@ private:
|
||||
|
||||
public:
|
||||
InputArgList(const char* const *ArgBegin, const char* const *ArgEnd);
|
||||
// Default move operations implemented for the convenience of MSVC. Nothing
|
||||
// special here.
|
||||
InputArgList(InputArgList &&RHS)
|
||||
: ArgList(std::move(RHS)), ArgStrings(std::move(RHS.ArgStrings)),
|
||||
SynthesizedStrings(std::move(RHS.SynthesizedStrings)),
|
||||
NumInputArgStrings(RHS.NumInputArgStrings) {}
|
||||
InputArgList &operator=(InputArgList &&RHS) {
|
||||
ArgList::operator=(std::move(RHS));
|
||||
ArgStrings = std::move(RHS.ArgStrings);
|
||||
SynthesizedStrings = std::move(RHS.SynthesizedStrings);
|
||||
NumInputArgStrings = RHS.NumInputArgStrings;
|
||||
return *this;
|
||||
}
|
||||
~InputArgList();
|
||||
|
||||
const char *getArgString(unsigned Index) const override {
|
||||
|
||||
@@ -151,10 +151,9 @@ public:
|
||||
/// is the default and means exclude nothing.
|
||||
/// \return An InputArgList; on error this will contain all the options
|
||||
/// which could be parsed.
|
||||
InputArgList *ParseArgs(ArrayRef<const char *> Args,
|
||||
unsigned &MissingArgIndex, unsigned &MissingArgCount,
|
||||
unsigned FlagsToInclude = 0,
|
||||
unsigned FlagsToExclude = 0) const;
|
||||
InputArgList ParseArgs(ArrayRef<const char *> Args, unsigned &MissingArgIndex,
|
||||
unsigned &MissingArgCount, unsigned FlagsToInclude = 0,
|
||||
unsigned FlagsToExclude = 0) const;
|
||||
|
||||
/// \brief Render the help text for an option table.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user