forked from OSchip/llvm-project
Driver: Eliminate Arg subclasses, which are now unnecessary.
llvm-svn: 105762
This commit is contained in:
parent
8b77f73314
commit
35cbfeba8f
|
@ -10,13 +10,6 @@
|
|||
#ifndef CLANG_DRIVER_ARG_H_
|
||||
#define CLANG_DRIVER_ARG_H_
|
||||
|
||||
#include "llvm/Support/Casting.h"
|
||||
using llvm::isa;
|
||||
using llvm::cast;
|
||||
using llvm::cast_or_null;
|
||||
using llvm::dyn_cast;
|
||||
using llvm::dyn_cast_or_null;
|
||||
|
||||
#include "Util.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include <vector>
|
||||
|
@ -35,19 +28,10 @@ namespace driver {
|
|||
/// ArgList to provide efficient iteration over all instances of a
|
||||
/// particular option.
|
||||
class Arg {
|
||||
public:
|
||||
enum ArgClass {
|
||||
FlagClass = 0,
|
||||
PositionalClass,
|
||||
JoinedClass,
|
||||
SeparateClass,
|
||||
CommaJoinedClass,
|
||||
JoinedAndSeparateClass
|
||||
};
|
||||
Arg(const Arg &); // DO NOT IMPLEMENT
|
||||
void operator=(const Arg &); // DO NOT IMPLEMENT
|
||||
|
||||
private:
|
||||
ArgClass Kind;
|
||||
|
||||
/// The option this argument is an instance of.
|
||||
const Option *Opt;
|
||||
|
||||
|
@ -69,15 +53,14 @@ namespace driver {
|
|||
/// The argument values, as C strings.
|
||||
llvm::SmallVector<const char *, 2> Values;
|
||||
|
||||
protected:
|
||||
Arg(ArgClass Kind, const Option *Opt, unsigned Index,
|
||||
const Arg *BaseArg = 0);
|
||||
|
||||
public:
|
||||
Arg(const Arg &);
|
||||
virtual ~Arg();
|
||||
Arg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
|
||||
Arg(const Option *Opt, unsigned Index,
|
||||
const char *Value0, const Arg *BaseArg = 0);
|
||||
Arg(const Option *Opt, unsigned Index,
|
||||
const char *Value0, const char *Value1, const Arg *BaseArg = 0);
|
||||
~Arg();
|
||||
|
||||
ArgClass getKind() const { return Kind; }
|
||||
const Option &getOption() const { return *Opt; }
|
||||
unsigned getIndex() const { return Index; }
|
||||
|
||||
|
@ -126,85 +109,6 @@ namespace driver {
|
|||
std::string getAsString(const ArgList &Args) const;
|
||||
};
|
||||
|
||||
/// FlagArg - An argument with no value.
|
||||
class FlagArg : public Arg {
|
||||
public:
|
||||
FlagArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
|
||||
|
||||
static bool classof(const Arg *A) {
|
||||
return A->getKind() == Arg::FlagClass;
|
||||
}
|
||||
static bool classof(const FlagArg *) { return true; }
|
||||
};
|
||||
|
||||
/// PositionalArg - A simple positional argument.
|
||||
class PositionalArg : public Arg {
|
||||
public:
|
||||
PositionalArg(const Option *Opt, unsigned Index, const char *Value,
|
||||
const Arg *BaseArg = 0);
|
||||
|
||||
static bool classof(const Arg *A) {
|
||||
return A->getKind() == Arg::PositionalClass;
|
||||
}
|
||||
static bool classof(const PositionalArg *) { return true; }
|
||||
};
|
||||
|
||||
/// JoinedArg - A single value argument where the value is joined
|
||||
/// (suffixed) to the option.
|
||||
class JoinedArg : public Arg {
|
||||
public:
|
||||
JoinedArg(const Option *Opt, unsigned Index, const char *Value,
|
||||
const Arg *BaseArg = 0);
|
||||
|
||||
static bool classof(const Arg *A) {
|
||||
return A->getKind() == Arg::JoinedClass;
|
||||
}
|
||||
static bool classof(const JoinedArg *) { return true; }
|
||||
};
|
||||
|
||||
/// SeparateArg - An argument where one or more values follow the
|
||||
/// option specifier immediately in the argument vector.
|
||||
class SeparateArg : public Arg {
|
||||
public:
|
||||
SeparateArg(const Option *Opt, unsigned Index, const char *Value,
|
||||
const Arg *BaseArg = 0);
|
||||
|
||||
static bool classof(const Arg *A) {
|
||||
return A->getKind() == Arg::SeparateClass;
|
||||
}
|
||||
static bool classof(const SeparateArg *) { return true; }
|
||||
};
|
||||
|
||||
/// CommaJoinedArg - An argument with multiple values joined by
|
||||
/// commas and joined (suffixed) to the option specifier.
|
||||
///
|
||||
/// The key point of this arg is that it renders its values into
|
||||
/// separate arguments, which allows it to be used as a generic
|
||||
/// mechanism for passing arguments through to tools.
|
||||
class CommaJoinedArg : public Arg {
|
||||
public:
|
||||
CommaJoinedArg(const Option *Opt, unsigned Index, const char *Str,
|
||||
const Arg *BaseArg = 0);
|
||||
|
||||
static bool classof(const Arg *A) {
|
||||
return A->getKind() == Arg::CommaJoinedClass;
|
||||
}
|
||||
static bool classof(const CommaJoinedArg *) { return true; }
|
||||
};
|
||||
|
||||
/// JoinedAndSeparateArg - An argument with both joined and separate
|
||||
/// values.
|
||||
class JoinedAndSeparateArg : public Arg {
|
||||
public:
|
||||
JoinedAndSeparateArg(const Option *Opt, unsigned Index,
|
||||
const char *Value0, const char *Value1,
|
||||
const Arg *BaseArg = 0);
|
||||
|
||||
static bool classof(const Arg *A) {
|
||||
return A->getKind() == Arg::JoinedAndSeparateClass;
|
||||
}
|
||||
static bool classof(const JoinedAndSeparateArg *) { return true; }
|
||||
};
|
||||
} // end namespace driver
|
||||
} // end namespace clang
|
||||
|
||||
|
|
|
@ -16,12 +16,26 @@
|
|||
|
||||
using namespace clang::driver;
|
||||
|
||||
Arg::Arg(ArgClass _Kind, const Option *_Opt, unsigned _Index,
|
||||
const Arg *_BaseArg)
|
||||
: Kind(_Kind), Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
|
||||
Arg::Arg(const Option *_Opt, unsigned _Index, const Arg *_BaseArg)
|
||||
: Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
|
||||
Claimed(false), OwnsValues(false) {
|
||||
}
|
||||
|
||||
Arg::Arg(const Option *_Opt, unsigned _Index,
|
||||
const char *Value0, const Arg *_BaseArg)
|
||||
: Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
|
||||
Claimed(false), OwnsValues(false) {
|
||||
Values.push_back(Value0);
|
||||
}
|
||||
|
||||
Arg::Arg(const Option *_Opt, unsigned _Index,
|
||||
const char *Value0, const char *Value1, const Arg *_BaseArg)
|
||||
: Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
|
||||
Claimed(false), OwnsValues(false) {
|
||||
Values.push_back(Value0);
|
||||
Values.push_back(Value1);
|
||||
}
|
||||
|
||||
Arg::~Arg() {
|
||||
if (OwnsValues) {
|
||||
for (unsigned i = 0, e = Values.size(); i != e; ++i)
|
||||
|
@ -31,28 +45,19 @@ Arg::~Arg() {
|
|||
|
||||
void Arg::dump() const {
|
||||
llvm::errs() << "<";
|
||||
switch (Kind) {
|
||||
default:
|
||||
assert(0 && "Invalid kind");
|
||||
#define P(N) case N: llvm::errs() << #N; break
|
||||
P(FlagClass);
|
||||
P(PositionalClass);
|
||||
P(JoinedClass);
|
||||
P(SeparateClass);
|
||||
P(CommaJoinedClass);
|
||||
P(JoinedAndSeparateClass);
|
||||
#undef P
|
||||
}
|
||||
|
||||
llvm::errs() << " Opt:";
|
||||
Opt->dump();
|
||||
|
||||
llvm::errs() << " Index:" << Index;
|
||||
|
||||
if (isa<CommaJoinedArg>(this) || isa<SeparateArg>(this))
|
||||
llvm::errs() << " NumValues:" << getNumValues();
|
||||
llvm::errs() << " Values: [";
|
||||
for (unsigned i = 0, e = Values.size(); i != e; ++i) {
|
||||
if (i) llvm::errs() << ", ";
|
||||
llvm::errs() << "'" << Values[i] << "'";
|
||||
}
|
||||
|
||||
llvm::errs() << ">\n";
|
||||
llvm::errs() << "]>\n";
|
||||
}
|
||||
|
||||
std::string Arg::getAsString(const ArgList &Args) const {
|
||||
|
@ -114,59 +119,3 @@ void Arg::render(const ArgList &Args, ArgStringList &Output) const {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FlagArg::FlagArg(const Option *Opt, unsigned Index, const Arg *BaseArg)
|
||||
: Arg(FlagClass, Opt, Index, BaseArg) {
|
||||
}
|
||||
|
||||
PositionalArg::PositionalArg(const Option *Opt, unsigned Index,
|
||||
const char *Value0, const Arg *BaseArg)
|
||||
: Arg(PositionalClass, Opt, Index, BaseArg) {
|
||||
getValues().push_back(Value0);
|
||||
}
|
||||
|
||||
JoinedArg::JoinedArg(const Option *Opt, unsigned Index, const char *Value0,
|
||||
const Arg *BaseArg)
|
||||
: Arg(JoinedClass, Opt, Index, BaseArg) {
|
||||
getValues().push_back(Value0);
|
||||
}
|
||||
|
||||
CommaJoinedArg::CommaJoinedArg(const Option *Opt, unsigned Index,
|
||||
const char *Str, const Arg *BaseArg)
|
||||
: Arg(CommaJoinedClass, Opt, Index, BaseArg) {
|
||||
const char *Prev = Str;
|
||||
for (;; ++Str) {
|
||||
char c = *Str;
|
||||
|
||||
if (!c || c == ',') {
|
||||
if (Prev != Str) {
|
||||
char *Value = new char[Str - Prev + 1];
|
||||
memcpy(Value, Prev, Str - Prev);
|
||||
Value[Str - Prev] = '\0';
|
||||
getValues().push_back(Value);
|
||||
}
|
||||
|
||||
if (!c)
|
||||
break;
|
||||
|
||||
Prev = Str + 1;
|
||||
}
|
||||
}
|
||||
|
||||
setOwnsValues(true);
|
||||
}
|
||||
|
||||
SeparateArg::SeparateArg(const Option *Opt, unsigned Index, const char *Value0,
|
||||
const Arg *BaseArg)
|
||||
: Arg(SeparateClass, Opt, Index, BaseArg) {
|
||||
getValues().push_back(Value0);
|
||||
}
|
||||
|
||||
JoinedAndSeparateArg::JoinedAndSeparateArg(const Option *Opt, unsigned Index,
|
||||
const char *Value0,
|
||||
const char *Value1,
|
||||
const Arg *BaseArg)
|
||||
: Arg(JoinedAndSeparateClass, Opt, Index, BaseArg) {
|
||||
getValues().push_back(Value0);
|
||||
getValues().push_back(Value1);
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ const char *DerivedArgList::MakeArgString(llvm::StringRef Str) const {
|
|||
}
|
||||
|
||||
Arg *DerivedArgList::MakeFlagArg(const Arg *BaseArg, const Option *Opt) const {
|
||||
Arg *A = new FlagArg(Opt, BaseArgs.MakeIndex(Opt->getName()), BaseArg);
|
||||
Arg *A = new Arg(Opt, BaseArgs.MakeIndex(Opt->getName()), BaseArg);
|
||||
SynthesizedArgs.push_back(A);
|
||||
return A;
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ Arg *DerivedArgList::MakeFlagArg(const Arg *BaseArg, const Option *Opt) const {
|
|||
Arg *DerivedArgList::MakePositionalArg(const Arg *BaseArg, const Option *Opt,
|
||||
llvm::StringRef Value) const {
|
||||
unsigned Index = BaseArgs.MakeIndex(Value);
|
||||
Arg *A = new PositionalArg(Opt, Index, BaseArgs.getArgString(Index), BaseArg);
|
||||
Arg *A = new Arg(Opt, Index, BaseArgs.getArgString(Index), BaseArg);
|
||||
SynthesizedArgs.push_back(A);
|
||||
return A;
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ Arg *DerivedArgList::MakePositionalArg(const Arg *BaseArg, const Option *Opt,
|
|||
Arg *DerivedArgList::MakeSeparateArg(const Arg *BaseArg, const Option *Opt,
|
||||
llvm::StringRef Value) const {
|
||||
unsigned Index = BaseArgs.MakeIndex(Opt->getName(), Value);
|
||||
Arg *A = new SeparateArg(Opt, Index, BaseArgs.getArgString(Index), BaseArg);
|
||||
Arg *A = new Arg(Opt, Index, BaseArgs.getArgString(Index), BaseArg);
|
||||
SynthesizedArgs.push_back(A);
|
||||
return A;
|
||||
}
|
||||
|
@ -281,9 +281,9 @@ Arg *DerivedArgList::MakeSeparateArg(const Arg *BaseArg, const Option *Opt,
|
|||
Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option *Opt,
|
||||
llvm::StringRef Value) const {
|
||||
unsigned Index = BaseArgs.MakeIndex(Opt->getName() + Value.str());
|
||||
Arg *A = new JoinedArg(Opt, Index,
|
||||
BaseArgs.getArgString(Index) + strlen(Opt->getName()),
|
||||
BaseArg);
|
||||
Arg *A = new Arg(Opt, Index,
|
||||
BaseArgs.getArgString(Index) + strlen(Opt->getName()),
|
||||
BaseArg);
|
||||
SynthesizedArgs.push_back(A);
|
||||
return A;
|
||||
}
|
||||
|
|
|
@ -976,7 +976,7 @@ void Driver::BuildJobsForAction(Compilation &C,
|
|||
// just using Args was better?
|
||||
const Arg &Input = IA->getInputArg();
|
||||
Input.claim();
|
||||
if (isa<PositionalArg>(Input)) {
|
||||
if (Input.getOption().matches(options::OPT_INPUT)) {
|
||||
const char *Name = Input.getValue(C.getArgs());
|
||||
Result = InputInfo(Name, A->getType(), Name);
|
||||
} else
|
||||
|
|
|
@ -188,7 +188,7 @@ Arg *OptTable::ParseOneArg(const InputArgList &Args, unsigned &Index) const {
|
|||
|
||||
// Anything that doesn't start with '-' is an input, as is '-' itself.
|
||||
if (Str[0] != '-' || Str[1] == '\0')
|
||||
return new PositionalArg(TheInputOption, Index++, Str);
|
||||
return new Arg(TheInputOption, Index++, Str);
|
||||
|
||||
const Info *Start = OptionInfos + FirstSearchableIndex;
|
||||
const Info *End = OptionInfos + getNumOptions();
|
||||
|
@ -221,7 +221,7 @@ Arg *OptTable::ParseOneArg(const InputArgList &Args, unsigned &Index) const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
return new PositionalArg(TheUnknownOption, Index++, Str);
|
||||
return new Arg(TheUnknownOption, Index++, Str);
|
||||
}
|
||||
|
||||
InputArgList *OptTable::ParseArgs(const char **ArgBegin, const char **ArgEnd,
|
||||
|
|
|
@ -147,7 +147,7 @@ Arg *FlagOption::accept(const InputArgList &Args, unsigned &Index) const {
|
|||
if (strlen(getName()) != strlen(Args.getArgString(Index)))
|
||||
return 0;
|
||||
|
||||
return new FlagArg(this, Index++);
|
||||
return new Arg(this, Index++);
|
||||
}
|
||||
|
||||
JoinedOption::JoinedOption(OptSpecifier ID, const char *Name,
|
||||
|
@ -158,7 +158,7 @@ JoinedOption::JoinedOption(OptSpecifier ID, const char *Name,
|
|||
Arg *JoinedOption::accept(const InputArgList &Args, unsigned &Index) const {
|
||||
// Always matches.
|
||||
const char *Value = Args.getArgString(Index) + strlen(getName());
|
||||
return new JoinedArg(this, Index++, Value);
|
||||
return new Arg(this, Index++, Value);
|
||||
}
|
||||
|
||||
CommaJoinedOption::CommaJoinedOption(OptSpecifier ID, const char *Name,
|
||||
|
@ -169,13 +169,32 @@ CommaJoinedOption::CommaJoinedOption(OptSpecifier ID, const char *Name,
|
|||
|
||||
Arg *CommaJoinedOption::accept(const InputArgList &Args,
|
||||
unsigned &Index) const {
|
||||
// Always matches. We count the commas now so we can answer
|
||||
// getNumValues easily.
|
||||
// Always matches.
|
||||
const char *Str = Args.getArgString(Index) + strlen(getName());
|
||||
Arg *A = new Arg(this, Index++);
|
||||
|
||||
// Get the suffix string.
|
||||
// FIXME: Avoid strlen, and move to helper method?
|
||||
const char *Suffix = Args.getArgString(Index) + strlen(getName());
|
||||
return new CommaJoinedArg(this, Index++, Suffix);
|
||||
// Parse out the comma separated values.
|
||||
const char *Prev = Str;
|
||||
for (;; ++Str) {
|
||||
char c = *Str;
|
||||
|
||||
if (!c || c == ',') {
|
||||
if (Prev != Str) {
|
||||
char *Value = new char[Str - Prev + 1];
|
||||
memcpy(Value, Prev, Str - Prev);
|
||||
Value[Str - Prev] = '\0';
|
||||
A->getValues().push_back(Value);
|
||||
}
|
||||
|
||||
if (!c)
|
||||
break;
|
||||
|
||||
Prev = Str + 1;
|
||||
}
|
||||
}
|
||||
A->setOwnsValues(true);
|
||||
|
||||
return A;
|
||||
}
|
||||
|
||||
SeparateOption::SeparateOption(OptSpecifier ID, const char *Name,
|
||||
|
@ -193,7 +212,7 @@ Arg *SeparateOption::accept(const InputArgList &Args, unsigned &Index) const {
|
|||
if (Index > Args.getNumInputArgStrings())
|
||||
return 0;
|
||||
|
||||
return new SeparateArg(this, Index - 2, Args.getArgString(Index - 1));
|
||||
return new Arg(this, Index - 2, Args.getArgString(Index - 1));
|
||||
}
|
||||
|
||||
MultiArgOption::MultiArgOption(OptSpecifier ID, const char *Name,
|
||||
|
@ -213,8 +232,8 @@ Arg *MultiArgOption::accept(const InputArgList &Args, unsigned &Index) const {
|
|||
if (Index > Args.getNumInputArgStrings())
|
||||
return 0;
|
||||
|
||||
Arg *A = new SeparateArg(this, Index - 1 - NumArgs,
|
||||
Args.getArgString(Index - NumArgs));
|
||||
Arg *A = new Arg(this, Index - 1 - NumArgs,
|
||||
Args.getArgString(Index - NumArgs));
|
||||
for (unsigned i = 1; i != NumArgs; ++i)
|
||||
A->getValues().push_back(Args.getArgString(Index - NumArgs + i));
|
||||
return A;
|
||||
|
@ -233,7 +252,7 @@ Arg *JoinedOrSeparateOption::accept(const InputArgList &Args,
|
|||
// FIXME: Avoid strlen.
|
||||
if (strlen(getName()) != strlen(Args.getArgString(Index))) {
|
||||
const char *Value = Args.getArgString(Index) + strlen(getName());
|
||||
return new JoinedArg(this, Index++, Value);
|
||||
return new Arg(this, Index++, Value);
|
||||
}
|
||||
|
||||
// Otherwise it must be separate.
|
||||
|
@ -241,8 +260,7 @@ Arg *JoinedOrSeparateOption::accept(const InputArgList &Args,
|
|||
if (Index > Args.getNumInputArgStrings())
|
||||
return 0;
|
||||
|
||||
return new SeparateArg(this, Index - 2,
|
||||
Args.getArgString(Index - 1));
|
||||
return new Arg(this, Index - 2, Args.getArgString(Index - 1));
|
||||
}
|
||||
|
||||
JoinedAndSeparateOption::JoinedAndSeparateOption(OptSpecifier ID,
|
||||
|
@ -260,7 +278,6 @@ Arg *JoinedAndSeparateOption::accept(const InputArgList &Args,
|
|||
if (Index > Args.getNumInputArgStrings())
|
||||
return 0;
|
||||
|
||||
return new JoinedAndSeparateArg(this, Index - 2,
|
||||
Args.getArgString(Index-2)+strlen(getName()),
|
||||
Args.getArgString(Index-1));
|
||||
return new Arg(this, Index - 2, Args.getArgString(Index-2)+strlen(getName())
|
||||
, Args.getArgString(Index-1));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue