mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-08 03:46:02 +03:00
Implement FlagParser using llvm:🆑:generic_parser_base.
This approach is easier and requires less code. With some template foo the BoolOrDefaultAdapter is not required. This solutions applies to previous LLVM versions, too.
This commit is contained in:
parent
cbb4d6d5b3
commit
4db0123bb7
5 changed files with 127 additions and 96 deletions
|
@ -18,39 +18,6 @@
|
|||
|
||||
namespace opts {
|
||||
|
||||
#if LDC_LLVM_VER < 307
|
||||
bool FlagParser::parse(cl::Option &O, llvm::StringRef ArgName, llvm::StringRef Arg, bool &Val) {
|
||||
// Make a std::string out of it to make comparisons easier
|
||||
// (and avoid repeated conversion)
|
||||
llvm::StringRef argname = ArgName;
|
||||
|
||||
typedef std::vector<std::pair<std::string, bool> >::iterator It;
|
||||
for (It I = switches.begin(), E = switches.end(); I != E; ++I) {
|
||||
llvm::StringRef name = I->first;
|
||||
if (name == argname
|
||||
|| (name.size() < argname.size()
|
||||
&& argname.substr(0, name.size()) == name
|
||||
&& argname[name.size()] == '=')) {
|
||||
|
||||
if (!cl::parser<bool>::parse(O, ArgName, Arg, Val)) {
|
||||
Val = (Val == I->second);
|
||||
return false;
|
||||
}
|
||||
// Invalid option value
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FlagParser::getExtraOptionNames(llvm::SmallVectorImpl<const char*> &Names) {
|
||||
typedef std::vector<std::pair<std::string, bool> >::iterator It;
|
||||
for (It I = switches.begin() + 1, E = switches.end(); I != E; ++I) {
|
||||
Names.push_back(I->first.data());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
MultiSetter::MultiSetter(bool invert, bool* p, ...) {
|
||||
this->invert = invert;
|
||||
if (p) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue