llvm.org GIT mirror llvm / 8a7a058
convert argname to StringRef, simplifying LookupOption. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82352 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
1 changed file(s) with 22 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
150150 /// LookupOption - Lookup the option specified by the specified option on the
151151 /// command line. If there is a value specified (after an equal sign) return
152152 /// that as well.
153 static Option *LookupOption(const char *&Arg, StringRef &Value,
154 StringMap &OptionsMap) {
155 while (*Arg == '-') ++Arg; // Eat leading dashes
156
157 const char *ArgEnd = Arg;
158 while (*ArgEnd && *ArgEnd != '=')
159 ++ArgEnd; // Scan till end of argument name.
160
153 static Option *LookupOption(StringRef &Arg, StringRef &Value,
154 const StringMap &OptionsMap) {
155 // Eat leading dashes.
156 while (!Arg.empty() && Arg[0] == '-')
157 Arg = Arg.substr(1);
158
159 // Reject all dashes.
160 if (Arg.empty()) return 0;
161
162 size_t EqualPos = Arg.find('=');
163
161164 // If we have an equals sign, remember the value.
162 if (*ArgEnd == '=')
163 Value = ArgEnd+1;
164
165 if (*Arg == 0) return 0;
165 if (EqualPos != StringRef::npos) {
166 Value = Arg.substr(EqualPos+1);
167 Arg = Arg.substr(0, EqualPos);
168 }
166169
167170 // Look up the option.
168 StringMap::iterator I =
169 OptionsMap.find(llvm::StringRef(Arg, ArgEnd-Arg));
171 StringMap::const_iterator I = OptionsMap.find(Arg);
170172 return I != OptionsMap.end() ? I->second : 0;
171173 }
172174
485487 for (int i = 1; i < argc; ++i) {
486488 Option *Handler = 0;
487489 StringRef Value;
488 const char *ArgName = "";
490 StringRef ArgName = "";
489491
490492 // If the option list changed, this means that some command line
491493 // option has just been registered or deregistered. This can occur in
550552 StringRef RealName(ArgName);
551553 if (RealName.size() > 1) {
552554 size_t Length = 0;
553 Option *PGOpt = getOptionPred(RealName, Length, isPrefixedOrGrouping,
554 Opts);
555 Option *PGOpt =
556 getOptionPred(RealName, Length, isPrefixedOrGrouping, Opts);
555557
556558 // If the option is a prefixed option, then the value is simply the
557559 // rest of the name... so fall through to later processing, by
558560 // setting up the argument name flags and value fields.
559 //
560561 if (PGOpt && PGOpt->getFormattingFlag() == cl::Prefix) {
561 Value = ArgName+Length;
562 assert(Opts.count(StringRef(ArgName, Length)) &&
563 Opts[StringRef(ArgName, Length)] == PGOpt);
562 Value = ArgName.substr(Length);
563 assert(Opts.count(ArgName.substr(0, Length)) &&
564 Opts[ArgName.substr(0, Length)] == PGOpt);
564565 Handler = PGOpt;
565566 } else if (PGOpt) {
566567 // This must be a grouped option... handle them now.