StringRef'ize clang::drive::Option::getName(), from Zach Wheeler!

llvm-svn: 134418
This commit is contained in:
Douglas Gregor 2011-07-05 16:56:25 +00:00
parent 9e66af44ad
commit 1cb4290b89
4 changed files with 15 additions and 14 deletions

View File

@ -11,6 +11,7 @@
#define CLANG_DRIVER_OPTION_H_ #define CLANG_DRIVER_OPTION_H_
#include "clang/Driver/OptSpecifier.h" #include "clang/Driver/OptSpecifier.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h" #include "llvm/Support/Casting.h"
using llvm::isa; using llvm::isa;
using llvm::cast; using llvm::cast;
@ -64,7 +65,7 @@ namespace driver {
OptSpecifier ID; OptSpecifier ID;
/// The option name. /// The option name.
const char *Name; llvm::StringRef Name;
/// Group this option is a member of, if any. /// Group this option is a member of, if any.
const OptionGroup *Group; const OptionGroup *Group;
@ -103,7 +104,7 @@ namespace driver {
unsigned getID() const { return ID.getID(); } unsigned getID() const { return ID.getID(); }
OptionClass getKind() const { return Kind; } OptionClass getKind() const { return Kind; }
const char *getName() const { return Name; } llvm::StringRef getName() const { return Name; }
const OptionGroup *getGroup() const { return Group; } const OptionGroup *getGroup() const { return Group; }
const Option *getAlias() const { return Alias; } const Option *getAlias() const { return Alias; }
@ -143,7 +144,7 @@ namespace driver {
/// getRenderName - Return the name to use when rendering this /// getRenderName - Return the name to use when rendering this
/// option. /// option.
const char *getRenderName() const { llvm::StringRef getRenderName() const {
return getUnaliasedOption()->getName(); return getUnaliasedOption()->getName();
} }

View File

@ -113,7 +113,7 @@ void Arg::render(const ArgList &Args, ArgStringList &Output) const {
break; break;
case Option::RenderSeparateStyle: case Option::RenderSeparateStyle:
Output.push_back(getOption().getName()); Output.push_back(getOption().getName().data());
for (unsigned i = 0, e = getNumValues(); i != e; ++i) for (unsigned i = 0, e = getNumValues(); i != e; ++i)
Output.push_back(getValue(Args, i)); Output.push_back(getValue(Args, i));
break; break;

View File

@ -287,9 +287,9 @@ Arg *DerivedArgList::MakeSeparateArg(const Arg *BaseArg, const Option *Opt,
Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option *Opt, Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option *Opt,
llvm::StringRef Value) const { llvm::StringRef Value) const {
unsigned Index = BaseArgs.MakeIndex(Opt->getName() + Value.str()); unsigned Index = BaseArgs.MakeIndex(Opt->getName().str() + Value.str());
Arg *A = new Arg(Opt, Index, Arg *A = new Arg(Opt, Index,
BaseArgs.getArgString(Index) + strlen(Opt->getName()), BaseArgs.getArgString(Index) + Opt->getName().size(),
BaseArg); BaseArg);
SynthesizedArgs.push_back(A); SynthesizedArgs.push_back(A);
return A; return A;

View File

@ -144,7 +144,7 @@ FlagOption::FlagOption(OptSpecifier ID, const char *Name,
Arg *FlagOption::accept(const ArgList &Args, unsigned &Index) const { Arg *FlagOption::accept(const ArgList &Args, unsigned &Index) const {
// Matches iff this is an exact match. // Matches iff this is an exact match.
// FIXME: Avoid strlen. // FIXME: Avoid strlen.
if (strlen(getName()) != strlen(Args.getArgString(Index))) if (getName().size() != strlen(Args.getArgString(Index)))
return 0; return 0;
return new Arg(getUnaliasedOption(), Index++); return new Arg(getUnaliasedOption(), Index++);
@ -157,7 +157,7 @@ JoinedOption::JoinedOption(OptSpecifier ID, const char *Name,
Arg *JoinedOption::accept(const ArgList &Args, unsigned &Index) const { Arg *JoinedOption::accept(const ArgList &Args, unsigned &Index) const {
// Always matches. // Always matches.
const char *Value = Args.getArgString(Index) + strlen(getName()); const char *Value = Args.getArgString(Index) + getName().size();
return new Arg(getUnaliasedOption(), Index++, Value); return new Arg(getUnaliasedOption(), Index++, Value);
} }
@ -170,7 +170,7 @@ CommaJoinedOption::CommaJoinedOption(OptSpecifier ID, const char *Name,
Arg *CommaJoinedOption::accept(const ArgList &Args, Arg *CommaJoinedOption::accept(const ArgList &Args,
unsigned &Index) const { unsigned &Index) const {
// Always matches. // Always matches.
const char *Str = Args.getArgString(Index) + strlen(getName()); const char *Str = Args.getArgString(Index) + getName().size();
Arg *A = new Arg(getUnaliasedOption(), Index++); Arg *A = new Arg(getUnaliasedOption(), Index++);
// Parse out the comma separated values. // Parse out the comma separated values.
@ -205,7 +205,7 @@ SeparateOption::SeparateOption(OptSpecifier ID, const char *Name,
Arg *SeparateOption::accept(const ArgList &Args, unsigned &Index) const { Arg *SeparateOption::accept(const ArgList &Args, unsigned &Index) const {
// Matches iff this is an exact match. // Matches iff this is an exact match.
// FIXME: Avoid strlen. // FIXME: Avoid strlen.
if (strlen(getName()) != strlen(Args.getArgString(Index))) if (getName().size() != strlen(Args.getArgString(Index)))
return 0; return 0;
Index += 2; Index += 2;
@ -225,7 +225,7 @@ MultiArgOption::MultiArgOption(OptSpecifier ID, const char *Name,
Arg *MultiArgOption::accept(const ArgList &Args, unsigned &Index) const { Arg *MultiArgOption::accept(const ArgList &Args, unsigned &Index) const {
// Matches iff this is an exact match. // Matches iff this is an exact match.
// FIXME: Avoid strlen. // FIXME: Avoid strlen.
if (strlen(getName()) != strlen(Args.getArgString(Index))) if (getName().size() != strlen(Args.getArgString(Index)))
return 0; return 0;
Index += 1 + NumArgs; Index += 1 + NumArgs;
@ -250,8 +250,8 @@ Arg *JoinedOrSeparateOption::accept(const ArgList &Args,
unsigned &Index) const { unsigned &Index) const {
// If this is not an exact match, it is a joined arg. // If this is not an exact match, it is a joined arg.
// FIXME: Avoid strlen. // FIXME: Avoid strlen.
if (strlen(getName()) != strlen(Args.getArgString(Index))) { if (getName().size() != strlen(Args.getArgString(Index))) {
const char *Value = Args.getArgString(Index) + strlen(getName()); const char *Value = Args.getArgString(Index) + getName().size();
return new Arg(this, Index++, Value); return new Arg(this, Index++, Value);
} }
@ -279,6 +279,6 @@ Arg *JoinedAndSeparateOption::accept(const ArgList &Args,
return 0; return 0;
return new Arg(getUnaliasedOption(), Index - 2, return new Arg(getUnaliasedOption(), Index - 2,
Args.getArgString(Index-2)+strlen(getName()), Args.getArgString(Index-2)+getName().size(),
Args.getArgString(Index-1)); Args.getArgString(Index-1));
} }