// `FactoryName`, return `None`.
static llvm::Optional<DurationScale>
getScaleForFactory(llvm::StringRef FactoryName) {
- static const std::unordered_map<std::string, DurationScale> ScaleMap(
- {{"Nanoseconds", DurationScale::Nanoseconds},
- {"Microseconds", DurationScale::Microseconds},
- {"Milliseconds", DurationScale::Milliseconds},
- {"Seconds", DurationScale::Seconds},
- {"Minutes", DurationScale::Minutes},
- {"Hours", DurationScale::Hours}});
-
- auto ScaleIter = ScaleMap.find(std::string(FactoryName));
- if (ScaleIter == ScaleMap.end())
- return llvm::None;
-
- return ScaleIter->second;
+ return llvm::StringSwitch<llvm::Optional<DurationScale>>(FactoryName)
+ .Case("Nanoseconds", DurationScale::Nanoseconds)
+ .Case("Microseconds", DurationScale::Microseconds)
+ .Case("Milliseconds", DurationScale::Milliseconds)
+ .Case("Seconds", DurationScale::Seconds)
+ .Case("Minutes", DurationScale::Minutes)
+ .Case("Hours", DurationScale::Hours)
+ .Default(llvm::None);
}
// Given either an integer or float literal, return its value.
"::std::ios_base::seek_dir", "::std::ios_base::streamoff",
"::std::ios_base::streampos"};
-static const llvm::StringMap<StringRef> ReplacementTypes = {
- {"io_state", "iostate"},
- {"open_mode", "openmode"},
- {"seek_dir", "seekdir"}};
+static llvm::Optional<const char *> getReplacementType(StringRef Type) {
+ return llvm::StringSwitch<llvm::Optional<const char *>>(Type)
+ .Case("io_state", "iostate")
+ .Case("open_mode", "openmode")
+ .Case("seek_dir", "seekdir")
+ .Default(llvm::None);
+}
void DeprecatedIosBaseAliasesCheck::registerMatchers(MatchFinder *Finder) {
auto IoStateDecl = typedefDecl(hasAnyName(DeprecatedTypes)).bind("TypeDecl");
const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>("TypeDecl");
StringRef TypeName = Typedef->getName();
- bool HasReplacement = ReplacementTypes.count(TypeName);
+ auto Replacement = getReplacementType(TypeName);
const auto *TL = Result.Nodes.getNodeAs<TypeLoc>("TypeLoc");
SourceLocation IoStateLoc = TL->getBeginLoc();
// Do not generate fixits for matches depending on template arguments and
// macro expansions.
- bool Fix = HasReplacement && !TL->getType()->isDependentType();
+ bool Fix = Replacement && !TL->getType()->isDependentType();
if (IoStateLoc.isMacroID()) {
IoStateLoc = SM.getSpellingLoc(IoStateLoc);
Fix = false;
SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1);
- if (HasReplacement) {
- auto FixName = ReplacementTypes.lookup(TypeName);
+ if (Replacement) {
+ auto FixName = *Replacement;
auto Builder = diag(IoStateLoc, "'std::ios_base::%0' is deprecated; use "
"'std::ios_base::%1' instead")
<< TypeName << FixName;
if (!Name.consume_front("vec_"))
return {};
- static const llvm::StringMap<StringRef> Mapping{
- // [simd.alg]
- {"max", "$std::max"},
- {"min", "$std::min"},
-
- // [simd.binary]
- {"add", "operator+ on $simd objects"},
- {"sub", "operator- on $simd objects"},
- {"mul", "operator* on $simd objects"},
- };
-
- auto It = Mapping.find(Name);
- if (It != Mapping.end())
- return It->second;
- return {};
+ return llvm::StringSwitch<StringRef>(Name)
+ // [simd.alg]
+ .Case("max", "$std::max")
+ .Case("min", "$std::min")
+ // [simd.binary]
+ .Case("add", "operator+ on $simd objects")
+ .Case("sub", "operator- on $simd objects")
+ .Case("mul", "operator* on $simd objects")
+ .Default({});
}
static StringRef TrySuggestX86(StringRef Name) {